diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2007-12-09 16:23:26 +0100 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2007-12-09 16:23:26 +0100 |
commit | 3e46366fd3b63b8551ae66187fa0d75c74fa29f8 (patch) | |
tree | 50d03076a62ebdcd5559ca476fc89b5360d14fee /nslcd | |
parent | 534c504364428682deaa2704c3f9ae4cf7f6ab39 (diff) |
get rid of some old code and rename ldap-nss to myldap since there is no more NSS-related code in there
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-ldapd@489 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'nslcd')
-rw-r--r-- | nslcd/Makefile.am | 3 | ||||
-rw-r--r-- | nslcd/alias.c | 2 | ||||
-rw-r--r-- | nslcd/attmap.h | 2 | ||||
-rw-r--r-- | nslcd/cfg.c | 7 | ||||
-rw-r--r-- | nslcd/common.h | 2 | ||||
-rw-r--r-- | nslcd/group.c | 2 | ||||
-rw-r--r-- | nslcd/ldap-nss.h | 93 | ||||
-rw-r--r-- | nslcd/myldap.c (renamed from nslcd/ldap-nss.c) | 269 | ||||
-rw-r--r-- | nslcd/myldap.h | 6 |
9 files changed, 24 insertions, 362 deletions
diff --git a/nslcd/Makefile.am b/nslcd/Makefile.am index 786ad31..c69c611 100644 --- a/nslcd/Makefile.am +++ b/nslcd/Makefile.am @@ -27,8 +27,7 @@ nslcd_SOURCES = nslcd.c ../nslcd.h ../nslcd-common.h \ ../compat/attrs.h ../compat/ldap.h \ log.c log.h \ common.c common.h \ - ldap-nss.c ldap-nss.h \ - myldap.h \ + myldap.c myldap.h \ pagectrl.c pagectrl.h \ cfg.c cfg.h \ attmap.c attmap.h \ diff --git a/nslcd/alias.c b/nslcd/alias.c index 9451af3..65c198b 100644 --- a/nslcd/alias.c +++ b/nslcd/alias.c @@ -119,7 +119,7 @@ static int write_alias(TFILE *fp,MYLDAP_ENTRY *entry,const char *reqalias) { WRITE_INT32(fp,NSLCD_RESULT_SUCCESS); WRITE_STRING(fp,names[i]); - WRITE_STRINGLIST_NULLTERM(fp,members); + WRITE_STRINGLIST(fp,members); } return 0; } diff --git a/nslcd/attmap.h b/nslcd/attmap.h index 2132cfb..906f285 100644 --- a/nslcd/attmap.h +++ b/nslcd/attmap.h @@ -23,7 +23,7 @@ #ifndef _ATTMAP_H #define _ATTMAP_H 1 -#include "ldap-nss.h" +#include "cfg.h" /* these are the attribute names per database */ extern const char *attmap_alias_cn; diff --git a/nslcd/cfg.c b/nslcd/cfg.c index 065b12a..29b9a0a 100644 --- a/nslcd/cfg.c +++ b/nslcd/cfg.c @@ -25,14 +25,16 @@ #include "config.h" -#include <string.h> #include <stdio.h> +#include <stdlib.h> +#include <string.h> #include <assert.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> -#include <stdlib.h> #include <errno.h> +#include <netdb.h> +#include <sys/socket.h> #ifdef HAVE_GSSAPI_H #include <gssapi.h> #endif /* HAVE_GSSAPI_H */ @@ -41,7 +43,6 @@ #include <gssapi/gssapi_krb5.h> #endif /* HAVE_GSSAPI_GSSAPI_KRB5_H */ -#include "ldap-nss.h" #include "common.h" #include "log.h" #include "cfg.h" diff --git a/nslcd/common.h b/nslcd/common.h index 9facf06..5d69581 100644 --- a/nslcd/common.h +++ b/nslcd/common.h @@ -28,7 +28,7 @@ #include "nslcd-common.h" #include "common/tio.h" #include "compat/attrs.h" -#include "ldap-nss.h" +#include "myldap.h" /* macros for basic read and write operations, the following ERROR_OUT* marcos define the action taken on errors diff --git a/nslcd/group.c b/nslcd/group.c index 32a0c60..4d28209 100644 --- a/nslcd/group.c +++ b/nslcd/group.c @@ -208,7 +208,7 @@ static int write_group(TFILE *fp,MYLDAP_ENTRY *entry,const char *reqname, WRITE_STRING(fp,passwd); WRITE_TYPE(fp,gids[j],gid_t); if (memberuidvalues!=NULL) - { WRITE_STRINGLIST_NULLTERM(fp,memberuidvalues); } + { WRITE_STRINGLIST(fp,memberuidvalues); } else { WRITE_INT32(fp,0); } } diff --git a/nslcd/ldap-nss.h b/nslcd/ldap-nss.h deleted file mode 100644 index b8cfdab..0000000 --- a/nslcd/ldap-nss.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - ldap-nss.c - main file for NSS interface - This file was part of the nss_ldap library which has been - forked into the nss-ldapd library. - - Copyright (C) 1997-2005 Luke Howard - Copyright (C) 2006, 2007 West Consulting - Copyright (C) 2006, 2007 Arthur de Jong - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#ifndef _LDAP_NSS_LDAP_LDAP_NSS_H -#define _LDAP_NSS_LDAP_LDAP_NSS_H - -#include <time.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> -#include <netinet/in.h> -#include <nss.h> -#include <ldap.h> - -#include "cfg.h" -#include "myldap.h" - -#ifdef __GNUC__ -#define alignof(ptr) __alignof__(ptr) -#elif defined(HAVE_ALIGNOF_H) -#include <alignof.h> -#else -#define alignof(ptr) (sizeof(char *)) -#endif /* __GNUC__ */ - -#define align(ptr, blen, TYPE)\ - { \ - char *qtr = ptr; \ - ptr += alignof(TYPE) - 1; \ - ptr -= ((ptr - (char *)NULL) % alignof(TYPE)); \ - blen -= (ptr - qtr); \ - } - -/* worst case */ -#define bytesleft(ptr, blen, TYPE) \ - ( (blen < alignof(TYPE)) ? 0 : (blen - alignof(TYPE) + 1)) - -/* parsing utility functions */ - -enum nss_status _nss_ldap_assign_attrvals ( - MYLDAP_ENTRY *entry, - const char *attr, /* IN */ - const char *omitvalue, /* IN */ - char ***valptr, /* OUT */ - char **pbuffer, /* IN/OUT */ - size_t * pbuflen, /* IN/OUT */ - size_t * pvalcount /* OUT */ ); - -enum nss_status _nss_ldap_assign_attrval( - MYLDAP_ENTRY *entry, - const char *attr, /* IN */ - char **valptr, /* OUT */ - char **buffer, /* IN/OUT */ - size_t * buflen /* IN/OUT */ ); - -enum nss_status _nss_ldap_assign_userpassword( - MYLDAP_ENTRY *entry, - const char *attr, /* IN */ - char **valptr, /* OUT */ - char **buffer, /* IN/OUT */ - size_t * buflen); /* IN/OUT */ - -/* - * get the RDN's value: eg. if the RDN was cn=lukeh, getrdnvalue(entry) - * would return lukeh. - */ -enum nss_status _nss_ldap_getrdnvalue( - MYLDAP_ENTRY *entry,const char *rdntype, - char **rval,char **buffer,size_t * buflen); - -#endif /* _LDAP_NSS_LDAP_LDAP_NSS_H */ diff --git a/nslcd/ldap-nss.c b/nslcd/myldap.c index b6232fc..879514e 100644 --- a/nslcd/ldap-nss.c +++ b/nslcd/myldap.c @@ -1,7 +1,8 @@ /* - ldap-nss.c - main file for NSS interface - This file was part of the nss_ldap library which has been - forked into the nss-ldapd library. + myldap.c - simple interface to do LDAP requests + + Parts of this file were part of the nss_ldap library (as ldap-nss.c) + which has been forked into the nss-ldapd library. Copyright (C) 1997-2006 Luke Howard Copyright (C) 2006, 2007 West Consulting @@ -59,7 +60,9 @@ #endif #include <ctype.h> -#include "ldap-nss.h" +/* FIXME: get rid of this */ +#include <nss.h> + #include "myldap.h" #include "pagectrl.h" #include "common.h" @@ -492,7 +495,6 @@ static int do_open(MYLDAP_SESSION *session) int rc; time_t current_time; int sd=-1; - log_log(LOG_DEBUG,"do_open()"); /* check if the idle time for the connection has expired */ if ((session->ls_conn!=NULL)&&nslcd_cfg->ldc_idle_timelimit) { @@ -507,7 +509,6 @@ static int do_open(MYLDAP_SESSION *session) called) then we can return the cached connection */ if (session->ls_conn!=NULL) { - log_log(LOG_DEBUG,"do_open(): using cached session"); return 0; } /* we should build a new session now */ @@ -595,7 +596,7 @@ static int do_open(MYLDAP_SESSION *session) * Wrapper around ldap_result() to skip over search references * and deal transparently with the last entry. */ -static enum nss_status do_result_async(MYLDAP_SEARCH *search) +static enum nss_status do_result(MYLDAP_SEARCH *search) { int rc=LDAP_UNAVAILABLE; enum nss_status stat=NSS_STATUS_TRYAGAIN; @@ -676,7 +677,7 @@ static enum nss_status do_result_async(MYLDAP_SEARCH *search) return stat; } -static int do_search_async(MYLDAP_SEARCH *search,int *msgidp) +static int do_search(MYLDAP_SEARCH *search,int *msgidp) { int rc; LDAPControl *serverCtrls[2]; @@ -710,7 +711,7 @@ static int do_search_async(MYLDAP_SEARCH *search,int *msgidp) } /* - * Function to call do_search_async() with reconnection logic (depending on + * Function to call do_search() with reconnection logic (depending on * wheter res or msgid is not NULL). */ static enum nss_status do_with_reconnect( @@ -740,7 +741,7 @@ static enum nss_status do_with_reconnect( start_uri=search->session->ls_current_uri; do { - stat=do_map_error(do_search_async(search,&msgid)); + stat=do_map_error(do_search(search,&msgid)); /* if we got any feedback from the server, don't try any other URIs */ if (stat!=NSS_STATUS_UNAVAIL) break; @@ -861,7 +862,7 @@ void myldap_search_close(MYLDAP_SEARCH *search) if ((search==NULL)||(search->session==NULL)) return; /* abandon the search if there were more results to fetch */ - if ((search->msgid>-1)&&(do_result_async(search)==NSS_STATUS_SUCCESS)) + if ((search->msgid>-1)&&(do_result(search)==NSS_STATUS_SUCCESS)) ldap_abandon(search->session->ls_conn,search->msgid); /* find the reference to this search in the session */ for (i=0;i<MAX_SEARCHES_IN_SESSION;i++) @@ -896,7 +897,7 @@ MYLDAP_ENTRY *myldap_get_entry(MYLDAP_SEARCH *search) { /* get an entry from the LDAP server, the result is stored in context->ec_res */ - stat=do_result_async(search); + stat=do_result(search); /* we we have an entry construct a search entry from it */ if (stat==NSS_STATUS_SUCCESS) { @@ -937,7 +938,7 @@ MYLDAP_ENTRY *myldap_get_entry(MYLDAP_SEARCH *search) } else { - log_log(LOG_DEBUG,"myldap_get_entry(): do_result_async() returned error code"); + log_log(LOG_DEBUG,"myldap_get_entry(): do_result() returned error code"); /* there was another problem, bail out */ return NULL; } @@ -1018,18 +1019,6 @@ const char **myldap_get_values(MYLDAP_ENTRY *entry,const char *attr) return (const char **)values; } -/* return the number of elements in the array returned by - by myldap_get_values() */ -int myldap_count_values(const char **vals) -{ - int i; - if (vals==NULL) - return 0; - for (i=0;vals[i]!=NULL;i++) - /* nothing here */; - return i; -} - /* Go over the entries in exploded_rdn and see if any start with the requested attribute. Return a reference to the value part of the DN (does not modify exploded_rdn). */ @@ -1132,236 +1121,6 @@ int myldap_has_objectclass(MYLDAP_ENTRY *entry,const char *objectclass) return 0; } -/* - * These functions are called from within the parser, where it is assumed - * to be safe to use the connection and the respective message. - */ - -/* - * Assign all values, bar omitvalue (if not NULL), to *valptr. - */ -enum nss_status _nss_ldap_assign_attrvals( - MYLDAP_ENTRY *entry, - const char *attr,const char *omitvalue, - char ***valptr,char **pbuffer,size_t *pbuflen,size_t *pvalcount) -{ - const char **vals; - const char **valiter; - size_t valcount; - char **p=NULL; - - size_t buflen=*pbuflen; - char *buffer=*pbuffer; - - if (pvalcount!=NULL) - *pvalcount=0; - - if (entry->search->session->ls_conn==NULL) - return NSS_STATUS_UNAVAIL; - - vals=myldap_get_values(entry,attr); - - valcount=myldap_count_values(vals); - if (bytesleft(buffer,buflen,char *)<(valcount+1)*sizeof(char *)) - { - return NSS_STATUS_TRYAGAIN; - } - - align(buffer,buflen,char *); - p=*valptr=(char **)buffer; - - buffer+=(valcount+1)*sizeof(char *); - buflen-=(valcount+1)*sizeof(char *); - - if (valcount==0) - { - *p = NULL; - *pbuffer=buffer; - *pbuflen=buflen; - return NSS_STATUS_SUCCESS; - } - - valiter=vals; - - while (*valiter!=NULL) - { - size_t vallen; - char *elt = NULL; - - if ((omitvalue!=NULL)&&(strcmp(*valiter,omitvalue)==0)) - valcount--; - else - { - vallen=strlen(*valiter); - if (buflen<(vallen+1)) - { - return NSS_STATUS_TRYAGAIN; - } - - /* copy this value into the next block of buffer space */ - elt=buffer; - buffer+=vallen+1; - buflen-=vallen+1; - - strncpy(elt,*valiter,vallen); - elt[vallen]='\0'; - *p=elt; - p++; - } - valiter++; - } - - *p=NULL; - *pbuffer=buffer; - *pbuflen=buflen; - - if (pvalcount!=NULL) - *pvalcount=valcount; - - return NSS_STATUS_SUCCESS; -} - -/* Assign a single value to *valptr. */ -enum nss_status _nss_ldap_assign_attrval( - MYLDAP_ENTRY *entry,const char *attr,char **valptr, - char **buffer,size_t *buflen) -{ - const char **vals; - int vallen; - if (entry->search->session->ls_conn==NULL) - return NSS_STATUS_UNAVAIL; - vals=myldap_get_values(entry,attr); - if ((vals==NULL)||(vals[0]==NULL)) - return NSS_STATUS_NOTFOUND; - vallen=strlen(vals[0]); - if (*buflen<(size_t)(vallen+1)) - { - return NSS_STATUS_TRYAGAIN; - } - *valptr=*buffer; - strncpy(*valptr,*vals,vallen); - (*valptr)[vallen]='\0'; - *buffer+=vallen + 1; - *buflen-=vallen + 1; - return NSS_STATUS_SUCCESS; -} - -static const char *_nss_ldap_locate_userpassword(const char **vals) -{ - const char *token=NULL; - size_t token_length=0; - const char **valiter; - const char *pwd=NULL; - - if (nslcd_cfg!=NULL) - { - switch (nslcd_cfg->ldc_password_type) - { - case LU_RFC2307_USERPASSWORD: - token = "{CRYPT}"; - token_length = sizeof("{CRYPT}") - 1; - break; - case LU_RFC3112_AUTHPASSWORD: - token = "CRYPT$"; - token_length = sizeof("CRYPT$") - 1; - break; - case LU_OTHER_PASSWORD: - default: - break; - } - } - - if (vals!=NULL) - { - for (valiter=vals;*valiter!=NULL;valiter++) - { - if (token_length==0 || - strncasecmp(*valiter,token,token_length)==0) - { - pwd=*valiter; - break; - } - } - } - - if (pwd==NULL) - pwd="*"; - else - pwd+=token_length; - - return pwd; -} - -/* - * Assign a single value to *valptr, after examining userPassword for - * a syntactically suitable value. - */ -enum nss_status _nss_ldap_assign_userpassword( - MYLDAP_ENTRY *entry, - const char *attr,char **valptr, - char **buffer,size_t *buflen) -{ - const char **vals; - const char *pwd; - int vallen; - log_log(LOG_DEBUG,"==> _nss_ldap_assign_userpassword"); - if (entry->search->session->ls_conn==NULL) - return NSS_STATUS_UNAVAIL; - vals=myldap_get_values(entry,attr); - pwd=_nss_ldap_locate_userpassword(vals); - vallen=strlen(pwd); - if (*buflen<(size_t)(vallen+1)) - { - log_log(LOG_DEBUG,"<== _nss_ldap_assign_userpassword"); - return NSS_STATUS_TRYAGAIN; - } - *valptr=*buffer; - strncpy(*valptr,pwd,vallen); - (*valptr)[vallen]='\0'; - *buffer+=vallen+1; - *buflen-=vallen+1; - log_log(LOG_DEBUG,"<== _nss_ldap_assign_userpassword"); - return NSS_STATUS_SUCCESS; -} - -enum nss_status _nss_ldap_getrdnvalue( - MYLDAP_ENTRY *entry,const char *rdntype, - char **rval,char **buffer,size_t *buflen) -{ - size_t rdnlen; - const char *rdnval; - const char **vals; - - rdnval=myldap_get_rdn_value(entry,rdntype); - if (rdnval==NULL) - { - /* - * If examining the DN failed, then pick the nominal first - * value of cn as the canonical name (recall that attributes - * are sets, not sequences) - */ - vals=myldap_get_values(entry,rdntype); - if ((vals==NULL)||(vals[0]==NULL)) - return NSS_STATUS_NOTFOUND; - rdnval=vals[0]; - } - - /* copy the value into the destination buffer */ - rdnlen = strlen(rdnval); - if (*buflen > rdnlen) - { - char *rdnvalue=*buffer; - strncpy(rdnvalue,rdnval,rdnlen); - rdnvalue[rdnlen] = '\0'; - *buffer += rdnlen + 1; - *buflen -= rdnlen + 1; - *rval = rdnvalue; - return NSS_STATUS_SUCCESS; - } - else - return NSS_STATUS_TRYAGAIN; -} - int myldap_escape(const char *src,char *buffer,size_t buflen) { size_t pos=0; diff --git a/nslcd/myldap.h b/nslcd/myldap.h index a85b37d..d5412ea 100644 --- a/nslcd/myldap.h +++ b/nslcd/myldap.h @@ -80,13 +80,9 @@ MUST_USE MYLDAP_ENTRY *myldap_get_entry(MYLDAP_SEARCH *search); MUST_USE const char *myldap_get_dn(MYLDAP_ENTRY *entry); /* Get the attribute values from a ceirtain entry as - a NULL terminated list. */ + a NULL terminated list. May return NULL or an empty array. */ MUST_USE const char **myldap_get_values(MYLDAP_ENTRY *entry,const char *attr); -/* Return the number of elements in the array returned by - by myldap_get_values(). */ -MUST_USE int myldap_count_values(const char **vals); - /* Checks to see if the entry has the specified object class. */ MUST_USE int myldap_has_objectclass(MYLDAP_ENTRY *entry,const char *objectclass); |