diff options
-rw-r--r-- | common/nslcd-prot.c | 2 | ||||
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | nslcd/cfg.h | 3 | ||||
-rw-r--r-- | nslcd/common.h | 2 | ||||
-rw-r--r-- | nslcd/myldap.c | 4 | ||||
-rw-r--r-- | nslcd/nslcd.c | 4 | ||||
-rw-r--r-- | nslcd/pam.c | 15 | ||||
-rw-r--r-- | nslcd/passwd.c | 39 |
8 files changed, 38 insertions, 35 deletions
diff --git a/common/nslcd-prot.c b/common/nslcd-prot.c index 102a6df..f2d6adf 100644 --- a/common/nslcd-prot.c +++ b/common/nslcd-prot.c @@ -66,7 +66,7 @@ TFILE *nslcd_client_open() strncpy(addr.sun_path,NSLCD_SOCKET,sizeof(addr.sun_path)); addr.sun_path[sizeof(addr.sun_path)-1]='\0'; /* connect to the socket */ - if (connect(sock,(struct sockaddr *)&addr,(socklen_t)sizeof(struct sockaddr_un))<0) + if (connect(sock,(struct sockaddr *)&addr,(socklen_t)(sizeof(addr.sun_family)+strlen(addr.sun_path)))<0) { (void)close(sock); return NULL; diff --git a/configure.ac b/configure.ac index d55ede8..2d96f6d 100644 --- a/configure.ac +++ b/configure.ac @@ -430,7 +430,7 @@ then nss_ldap_so_LINK="\$(CCLD) \$(AM_CFLAGS) \$(CFLAGS) \$(nss_ldap_so_LDFLAGS) \$(LDFLAGS) -o \$@" case "$target_os" in solaris*) - if test "$ac_cv_prog_gcc" = yes + if test "x$GCC" = xyes then nss_ldap_so_LINK="/usr/ccs/bin/ld -Bdirect -z nodelete -Bdynamic -M \$(srcdir)/exports.solaris -G -o \$@" else @@ -485,7 +485,7 @@ then pam_ldap_so_LINK="\$(CCLD) \$(AM_CFLAGS) \$(CFLAGS) \$(pam_ldap_so_LDFLAGS) \$(LDFLAGS) -o \$@" case "$target_os" in solaris*) - if test "$ac_cv_prog_gcc" = yes + if test "x$GCC" = xyes then pam_ldap_so_LINK="/usr/ccs/bin/ld -Bdirect -z nodelete -Bdynamic -M \$(srcdir)/pam_ldap.map -G -o \$@" else diff --git a/nslcd/cfg.h b/nslcd/cfg.h index bf7ca48..de43956 100644 --- a/nslcd/cfg.h +++ b/nslcd/cfg.h @@ -133,8 +133,7 @@ struct ldap_config int ldc_restart; /* set to a greater than 0 to enable handling of paged results with the specified size */ int ldc_pagesize; - /* the users for which no initgroups() searches should be done - Note: because we use a set here comparisons will be case-insensitive */ + /* the users for which no initgroups() searches should be done */ SET *ldc_nss_initgroups_ignoreusers; /* the search that should be performed to do autorisation checks */ char *ldc_pam_authz_search; diff --git a/nslcd/common.h b/nslcd/common.h index c2bab4d..a7cc18a 100644 --- a/nslcd/common.h +++ b/nslcd/common.h @@ -83,7 +83,7 @@ MUST_USE int isvalidname(const char *name); /* Perform an LDAP lookup to translate the DN into a uid. This function either returns NULL or a strdup()ed string. */ -MUST_USE char *lookup_dn2uid(MYLDAP_SESSION *session,const char *dn,int *rcp); +MUST_USE char *lookup_dn2uid(MYLDAP_SESSION *session,const char *dn,int *rcp,char *buf,size_t buflen); /* transforms the DN info a uid doing an LDAP lookup if needed */ MUST_USE char *dn2uid(MYLDAP_SESSION *session,const char *dn,char *buf,size_t buflen); diff --git a/nslcd/myldap.c b/nslcd/myldap.c index 902adbc..92f0154 100644 --- a/nslcd/myldap.c +++ b/nslcd/myldap.c @@ -638,8 +638,6 @@ static int do_open(MYLDAP_SESSION *session) int rc; int sd=-1; struct timeval tv; - /* check if the idle time for the connection has expired */ - myldap_session_check(session); /* if the connection is still there (ie. ldap_unbind() wasn't called) then we can return the cached connection */ if (session->ld!=NULL) @@ -937,6 +935,8 @@ MYLDAP_SEARCH *myldap_search( /* log the call */ log_log(LOG_DEBUG,"myldap_search(base=\"%s\", filter=\"%s\")", base,filter); + /* check if the idle time for the connection has expired */ + myldap_session_check(session); /* allocate a new search entry */ search=myldap_search_new(session,base,scope,filter,attrs); /* find a place in the session where we can register our search */ diff --git a/nslcd/nslcd.c b/nslcd/nslcd.c index 86a5d1a..83d4e95 100644 --- a/nslcd/nslcd.c +++ b/nslcd/nslcd.c @@ -297,7 +297,7 @@ static int create_socket(void) strncpy(addr.sun_path,NSLCD_SOCKET,sizeof(addr.sun_path)); addr.sun_path[sizeof(addr.sun_path)-1]='\0'; /* bind to the named socket */ - if (bind(sock,(struct sockaddr *)&addr,sizeof(struct sockaddr_un))) + if (bind(sock,(struct sockaddr *)&addr,(sizeof(addr.sun_family)+strlen(addr.sun_path)))) { log_log(LOG_ERR,"bind() to "NSLCD_SOCKET" failed: %s", strerror(errno)); @@ -308,7 +308,7 @@ static int create_socket(void) /* close the file descriptor on exit */ if (fcntl(sock,F_SETFD,FD_CLOEXEC)<0) { - log_log(LOG_ERR,"fctnl(F_SETFL,O_NONBLOCK) failed: %s",strerror(errno)); + log_log(LOG_ERR,"fctnl(F_SETFL,FD_CLOEXEC) failed: %s",strerror(errno)); if (close(sock)) log_log(LOG_WARNING,"problem closing socket: %s",strerror(errno)); exit(EXIT_FAILURE); diff --git a/nslcd/pam.c b/nslcd/pam.c index 35bf8d8..0467280 100644 --- a/nslcd/pam.c +++ b/nslcd/pam.c @@ -47,7 +47,7 @@ static int try_bind(const char *userdn,const char *password) { MYLDAP_SESSION *session; - char *username; + char buffer[256]; int rc; /* set up a new connection */ session=myldap_create_session(); @@ -56,9 +56,8 @@ static int try_bind(const char *userdn,const char *password) /* set up credentials for the session */ myldap_set_credentials(session,userdn,password); /* perform search for own object (just to do any kind of search) */ - username=lookup_dn2uid(session,userdn,&rc); - if (username!=NULL) - free(username); + if ((lookup_dn2uid(session,userdn,&rc,buffer,sizeof(buffer))==NULL)&&(rc==LDAP_SUCCESS)) + rc=LDAP_LOCAL_ERROR; /* close the session */ myldap_session_close(session); /* handle the results */ @@ -404,7 +403,7 @@ static int try_pwmod(const char *binddn,const char *userdn, const char *oldpassword,const char *newpassword) { MYLDAP_SESSION *session; - char *username; + char buffer[256]; int rc; /* set up a new connection */ session=myldap_create_session(); @@ -413,11 +412,7 @@ static int try_pwmod(const char *binddn,const char *userdn, /* set up credentials for the session */ myldap_set_credentials(session,binddn,oldpassword); /* perform search for own object (just to do any kind of search) */ - username=lookup_dn2uid(session,userdn,&rc); - if (username!=NULL) - free(username); - /* perform actual password modification */ - if (rc==LDAP_SUCCESS) + if ((lookup_dn2uid(session,userdn,&rc,buffer,sizeof(buffer))!=NULL)&&(rc==LDAP_SUCCESS)) { /* if doing password modification as admin, don't pass old password along */ if ((nslcd_cfg->ldc_rootpwmoddn!=NULL)&&(strcmp(binddn,nslcd_cfg->ldc_rootpwmoddn)==0)) diff --git a/nslcd/passwd.c b/nslcd/passwd.c index da26d88..a0b61d7 100644 --- a/nslcd/passwd.c +++ b/nslcd/passwd.c @@ -140,14 +140,14 @@ struct dn2uid_cache_entry /* Perform an LDAP lookup to translate the DN into a uid. This function either returns NULL or a strdup()ed string. */ -char *lookup_dn2uid(MYLDAP_SESSION *session,const char *dn,int *rcp) +char *lookup_dn2uid(MYLDAP_SESSION *session,const char *dn,int *rcp,char *buf,size_t buflen) { MYLDAP_SEARCH *search; MYLDAP_ENTRY *entry; static const char *attrs[2]; int rc=LDAP_SUCCESS; const char **values; - char *uid; + char *uid=NULL; if (rcp==NULL) rcp=&rc; /* we have to look up the entry */ @@ -169,10 +169,12 @@ char *lookup_dn2uid(MYLDAP_SESSION *session,const char *dn,int *rcp) /* get uid (just use first one) */ values=myldap_get_values(entry,attmap_passwd_uid); /* check the result for presence and validity */ - if ((values!=NULL)&&(values[0]!=NULL)&&isvalidname(values[0])) - uid=strdup(values[0]); - else - uid=NULL; + if ((values!=NULL)&&(values[0]!=NULL)&&isvalidname(values[0])&&(strlen(values[0])<buflen)) + { + strcpy(buf,values[0]); + uid=buf; + } + /* clean up and return */ myldap_search_close(search); return uid; } @@ -216,31 +218,38 @@ char *dn2uid(MYLDAP_SESSION *session,const char *dn,char *buf,size_t buflen) } pthread_mutex_unlock(&dn2uid_cache_mutex); /* look up the uid using an LDAP query */ - uid=lookup_dn2uid(session,dn,NULL); + uid=lookup_dn2uid(session,dn,NULL,buf,buflen); /* store the result in the cache */ pthread_mutex_lock(&dn2uid_cache_mutex); + /* try to get the entry from the cache here again because it could have + changed in the meantime */ + cacheentry=dict_get(dn2uid_cache,dn); if (cacheentry==NULL) { /* allocate a new entry in the cache */ cacheentry=(struct dn2uid_cache_entry *)malloc(sizeof(struct dn2uid_cache_entry)); if (cacheentry!=NULL) + { + cacheentry->uid=NULL; dict_put(dn2uid_cache,dn,cacheentry); + } } - else if (cacheentry->uid!=NULL) - free(cacheentry->uid); /* update the cache entry */ if (cacheentry!=NULL) { cacheentry->timestamp=time(NULL); - cacheentry->uid=uid; + /* copy the uid if needed */ + if (cacheentry->uid==NULL) + cacheentry->uid=uid!=NULL?strdup(uid):NULL; + else if (strcmp(cacheentry->uid,uid)!=0) + { + free(cacheentry->uid); + cacheentry->uid=uid!=NULL?strdup(uid):NULL; + } } pthread_mutex_unlock(&dn2uid_cache_mutex); /* copy the result into the buffer */ - if ((uid!=NULL)&&(strlen(uid)<buflen)) - strcpy(buf,uid); - else - buf=NULL; - return buf; + return uid; } MYLDAP_ENTRY *uid2entry(MYLDAP_SESSION *session,const char *uid) |