From 6c2b57e33df882f17fa4cf8dfc6a50f45af7e1c6 Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Sun, 20 Apr 2008 19:50:00 +0000 Subject: add checks for valid user and group names in incoming requests and for data returned from LDAP git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-ldapd@689 ef36b2f9-881f-0410-afb5-c4e39611909c --- nslcd/group.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 74 insertions(+), 20 deletions(-) (limited to 'nslcd/group.c') diff --git a/nslcd/group.c b/nslcd/group.c index d8a8d5d..10238e0 100644 --- a/nslcd/group.c +++ b/nslcd/group.c @@ -141,9 +141,45 @@ static void group_init(void) group_attrs[5]=NULL; } +/* + Checks to see if the specified name is a valid group name. + + This test is based on the definition from POSIX (IEEE Std 1003.1, 2004, + 3.189 Group Name and 3.276 Portable Filename Character Set): + 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 group names valid if they only contain characters from + the set [A-Za-z0-9._-] where the hyphen should not be used as first + character. +*/ +static int isvalidgroupname(const char *name) +{ + int i; + if ((name==NULL)||(name[0]=='\0')) + return 0; + /* check first character */ + if ( ! ( (name[0]>='A' && name[0] <= 'Z') || + (name[0]>='a' && name[0] <= 'a') || + (name[0]>='0' && name[0] <= '9') || + name[0]=='.' || name[0]=='_' ) ) + return 0; + /* check other characters */ + for (i=1;name[i]!='\0';i++) + { + if ( ! ( (name[0]>='A' && name[0] <= 'Z') || + (name[0]>='a' && name[0] <= 'a') || + (name[0]>='0' && name[0] <= '9') || + name[0]=='.' || name[0]=='_' || name[0]=='-') ) + return 0; + } + /* no test failed so it must be good */ + return -1; +} + static int do_write_group( - TFILE *fp,const char **names,gid_t gids[],int numgids,const char *passwd, - SET *members) + TFILE *fp,MYLDAP_ENTRY *entry,const char **names,gid_t gids[],int numgids, + const char *passwd,SET *members) { int32_t tmpint32; int i,j; @@ -159,21 +195,31 @@ static int do_write_group( } /* write entries for all names and gids */ for (i=0;names[i]!=NULL;i++) - for (j=0;j