diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2010-12-29 22:50:31 +0000 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2010-12-29 22:50:31 +0000 |
commit | e985efa83458e1cc9c2bcb12e3cc10b6526c3399 (patch) | |
tree | 8311cb525c9d452d62d88280e6cca854496f9c42 /nslcd/common.c | |
parent | 4e9224817ee303404b804a1a51f2f9c9a49164e4 (diff) | |
parent | ed6bc27721075adf0215ad8b856fcdcf7b98b9b7 (diff) |
merge changes from trunk
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd-solaris@1349 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'nslcd/common.c')
-rw-r--r-- | nslcd/common.c | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/nslcd/common.c b/nslcd/common.c index d88bb60..dc25bed 100644 --- a/nslcd/common.c +++ b/nslcd/common.c @@ -35,6 +35,7 @@ #include "nslcd.h" #include "common.h" #include "log.h" +#include "attmap.h" /* simple wrapper around snptintf() to return non-0 in case of any failure (but always keep string 0-terminated) */ @@ -51,25 +52,21 @@ int mysnprintf(char *buffer,size_t buflen,const char *format, ...) return ((res<0)||(((size_t)res)>=buflen)); } -const char *get_userpassword(MYLDAP_ENTRY *entry,const char *attr) +const char *get_userpassword(MYLDAP_ENTRY *entry,const char *attr,char *buffer,size_t buflen) { - const char **values; - int i; - /* get the entries */ - values=myldap_get_values(entry,attr); - if ((values==NULL)||(values[0]==NULL)) + const char *tmpvalue; + /* get the value */ + tmpvalue=attmap_get_value(entry,attr,buffer,buflen); + if (tmpvalue==NULL) return NULL; /* go over the entries and return the remainder of the value if it starts with {crypt} or crypt$ */ - for (i=0;values[i]!=NULL;i++) - { - if (strncasecmp(values[i],"{crypt}",7)==0) - return values[i]+7; - if (strncasecmp(values[i],"crypt$",6)==0) - return values[i]+6; - } + if (strncasecmp(tmpvalue,"{crypt}",7)==0) + return tmpvalue+7; + if (strncasecmp(tmpvalue,"crypt$",6)==0) + return tmpvalue+6; /* just return the first value completely */ - return values[0]; + return tmpvalue; /* TODO: support more password formats e.g. SMD5 (which is $1$ but in a different format) (any code for this is more than welcome) */ @@ -100,13 +97,20 @@ int isvalidname(const char *name) if (i>=LOGIN_NAME_MAX) return 0; #endif /* LOGIN_NAME_MAX */ - if ( ! ( ( (i!=0) && (name[i]=='-') ) || - ( (i!=0) && (name[i]=='\\') && name[i+1]!='\0' ) || - (name[i]>='@' && name[i] <= 'Z') || - (name[i]>='a' && name[i] <= 'z') || - (name[i]>='0' && name[i] <= '9') || - name[i]=='.' || name[i]=='_' || name[i]=='$' || name[i]==' ') ) - return 0; + /* characters supported everywhere in the name */ + if ( (name[i]>='@' && name[i] <= 'Z') || + (name[i]>='a' && name[i] <= 'z') || + (name[i]>='0' && name[i] <= '9') || + name[i]=='.' || name[i]=='_' || name[i]=='$' ) + continue; + /* characters that may be anywhere except as first character */ + if ( i>0 && ( name[i]=='-' || name[i]=='~' ) ) + continue; + /* characters that may not be the first or last character */ + if ( ( i>0 && name[i+1]!='\0' ) && ( name[i]=='\\' || name[i]==' ') ) + continue; + /* anything else is bad */ + return 0; } /* no test failed so it must be good */ return -1; |