summaryrefslogtreecommitdiff
path: root/nslcd/common.c
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2008-06-13 20:55:10 +0000
committerArthur de Jong <arthur@arthurdejong.org>2008-06-13 20:55:10 +0000
commit8fc785087daefbff19f35cd4e89e30a6d90f3374 (patch)
treea7103a69396f5a398630e97ae89b0267a0ed63b9 /nslcd/common.c
parent0d860441e3ff58b4faa033073235ad9c3b9a87c7 (diff)
combine isvalidusername() and isvalidgroupname() into isvalidname() because they are similar enough and we just want to check to see if it is a reasonable name (e.g. not a DN)
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-ldapd@759 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'nslcd/common.c')
-rw-r--r--nslcd/common.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/nslcd/common.c b/nslcd/common.c
index a181dca..840be1c 100644
--- a/nslcd/common.c
+++ b/nslcd/common.c
@@ -73,6 +73,38 @@ const char *get_userpassword(MYLDAP_ENTRY *entry,const char *attr)
(any code for this is more than welcome) */
}
+/*
+ Checks to see if the specified name seems to be a valid user or group name.
+
+ This test is based on the definition from POSIX (IEEE Std 1003.1, 2004,
+ 3.426 User Name, 3.189 Group Name and 3.276 Portable Filename Character Set):
+ http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html#tag_03_426
+ http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html#tag_03_189
+ http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html#tag_03_276
+
+ The standard defines user names valid if they contain characters from
+ the set [A-Za-z0-9._-] where the hyphen should not be used as first
+ character. As an extension this test allows the at '@' and dolar '$' signs.
+*/
+int isvalidname(const char *name)
+{
+ int i;
+ if ((name==NULL)||(name[0]=='\0'))
+ return 0;
+ /* check characters */
+ for (i=0;name[i]!='\0';i++)
+ {
+ if ( ! ( ( (i!=0) && (name[i]=='-') ) ||
+ (name[i]>='@' && name[i] <= 'Z') ||
+ (name[i]>='a' && name[i] <= 'z') ||
+ (name[i]>='0' && name[i] <= '9') ||
+ name[i]=='.' || name[i]=='_' || name[i]=='$') )
+ return 0;
+ }
+ /* no test failed so it must be good */
+ return -1;
+}
+
/* this writes a single address to the stream */
int write_address(TFILE *fp,const char *addr)
{