diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2007-09-14 19:44:09 +0000 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2007-09-14 19:44:09 +0000 |
commit | f645df69737893f7846e70f27d0b9ab41165078e (patch) | |
tree | 97bf6e13e657b075e0385fc72ce78c2a2afef268 | |
parent | bc0bac94bbefd984a83d6d62fed132337719e014 (diff) |
revert special casing for alias_byname() to other functions and some logging strings simplifications
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-ldapd@394 ef36b2f9-881f-0410-afb5-c4e39611909c
-rw-r--r-- | nslcd/alias.c | 29 | ||||
-rw-r--r-- | nslcd/ldap-nss.c | 114 | ||||
-rw-r--r-- | nslcd/ldap-nss.h | 40 | ||||
-rw-r--r-- | nslcd/util.c | 69 | ||||
-rw-r--r-- | nslcd/util.h | 4 |
5 files changed, 28 insertions, 228 deletions
diff --git a/nslcd/alias.c b/nslcd/alias.c index 0593c6d..49b0fd3 100644 --- a/nslcd/alias.c +++ b/nslcd/alias.c @@ -118,17 +118,6 @@ static enum nss_status _nss_ldap_parse_alias( return stat; } -static int write_alias(MYLDAP_SESSION *session,LDAPMessage *e,struct ldap_state UNUSED(*state),TFILE *fp) -{ - int stat; - if ((stat=_nss_ldap_write_rndvalue(fp,session,e,attmap_alias_cn))!=NSLCD_RESULT_SUCCESS) - return stat; - if ((stat=_nss_ldap_write_attrvals(fp,session,e,attmap_alias_rfc822MailMember))!=NSLCD_RESULT_SUCCESS) - return stat; - return NSLCD_RESULT_SUCCESS; -} - - /* macros for expanding the NSLCD_ALIAS macro */ #define NSLCD_STRING(field) WRITE_STRING(fp,field) #define NSLCD_STRINGLIST(field) WRITE_STRINGLIST_NUM(fp,field,result.alias_members_len) @@ -137,9 +126,14 @@ static int write_alias(MYLDAP_SESSION *session,LDAPMessage *e,struct ldap_state int nslcd_alias_byname(TFILE *fp,MYLDAP_SESSION *session) { - int32_t tmpint32; + int32_t tmpint32,tmp2int32; char name[256]; char filter[1024]; + /* these are here for now until we rewrite the LDAP code */ + struct aliasent result; + char buffer[1024]; + int errnop; + int retv; /* read request parameters */ READ_STRING_BUF2(fp,name,sizeof(name)); /* log call */ @@ -150,8 +144,15 @@ int nslcd_alias_byname(TFILE *fp,MYLDAP_SESSION *session) /* do the LDAP request */ mkfilter_alias_byname(name,filter,sizeof(filter)); alias_init(); - _nss_ldap_searchbyname(session,alias_base,alias_scope,filter,alias_attrs, - fp,write_alias); + retv=_nss_ldap_getbyname(session,&result,buffer,1024,&errnop, + alias_base,alias_scope,filter,alias_attrs, + _nss_ldap_parse_alias); + /* write the response */ + WRITE_INT32(fp,retv); + if (retv==NSLCD_RESULT_SUCCESS) + { + NSLCD_ALIAS; + } WRITE_FLUSH(fp); /* we're done */ return 0; diff --git a/nslcd/ldap-nss.c b/nslcd/ldap-nss.c index 86dbe1c..f5829f0 100644 --- a/nslcd/ldap-nss.c +++ b/nslcd/ldap-nss.c @@ -702,11 +702,7 @@ static int do_search_sync( { int rc; struct timeval tv, *tvp; - - log_log(LOG_DEBUG,"==> do_search_sync"); - ldap_set_option(session->ls_conn,LDAP_OPT_SIZELIMIT,(void *)&sizelimit); - if (nslcd_cfg->ldc_timelimit==LDAP_NO_LIMIT) tvp=NULL; else @@ -715,11 +711,7 @@ static int do_search_sync( tv.tv_usec=0; tvp=&tv; } - rc=ldap_search_st(session->ls_conn,base,scope,filter,(char **)attrs,0,tvp,res); - - log_log(LOG_DEBUG,"<== do_search_sync"); - return rc; } @@ -735,9 +727,6 @@ static int do_search_async( int rc; LDAPControl *serverCtrls[2]; LDAPControl **pServerCtrls; - - log_log(LOG_DEBUG,"==> do_search_async"); - if (nslcd_cfg->ldc_pagesize>0) { rc=ldap_create_page_control(session->ls_conn,nslcd_cfg->ldc_pagesize, @@ -749,18 +738,13 @@ static int do_search_async( } else pServerCtrls=NULL; - rc=ldap_search_ext(session->ls_conn,base,scope,filter,(char **) attrs, 0,pServerCtrls,NULL,LDAP_NO_LIMIT,sizelimit,msgid); - if (pServerCtrls!=NULL) { ldap_control_free(serverCtrls[0]); serverCtrls[0]=NULL; } - - log_log(LOG_DEBUG,"<== do_search_async"); - return rc; } @@ -777,7 +761,7 @@ static enum nss_status do_with_reconnect( int hard=1, start_uri=0, log=0; enum nss_status stat=NSS_STATUS_UNAVAIL; int maxtries; - log_log(LOG_DEBUG,"==> do_with_reconnect (base=\"%s\", scope=%d, filter=\"%s\")",base,scope,filter); + log_log(LOG_DEBUG,"do_with_reconnect(base=\"%s\", scope=%d, filter=\"%s\")",base,scope,filter); /* get the maximum number of tries */ maxtries=nslcd_cfg->ldc_reconnect_tries; /* keep trying until we have success or a hard failure */ @@ -861,7 +845,6 @@ static enum nss_status do_with_reconnect( default: break; } - log_log(LOG_DEBUG,"<== do_with_reconnect"); return stat; } @@ -1235,75 +1218,6 @@ int _nss_ldap_getbyname(MYLDAP_SESSION *session,void *result, char *buffer, size return nss2nslcd(stat); } -static int NEW_do_parse_sync(struct ent_context *context,TFILE *fp,NEWparser_t parser) -{ - int parseStat=NSLCD_RESULT_NOTFOUND; - LDAPMessage *e=NULL; - /* - * if ec_state.ls_info.ls_index is non-zero, then we don't collect another - * entry off the LDAP chain, and instead refeed the existing result to - * the parser. Once the parser has finished with it, it will return - * NSS_STATUS_NOTFOUND and reset the index to -1, at which point we'll retrieve - * another entry. - */ - do - { - if ((context->ec_state.ls_retry==0) && - ( (context->ec_state.ls_type==LS_TYPE_KEY) || - (context->ec_state.ls_info.ls_index==-1) )) - { - if (e==NULL) - e=ldap_first_entry(context->session->ls_conn,context->ec_res); - else - e=ldap_next_entry(context->session->ls_conn,e); - } - if (e==NULL) - { - /* Could not get a result; bail */ - parseStat=NSLCD_RESULT_NOTFOUND; - break; - } - /* - * We have an entry; now, try to parse it. - * - * If we do not parse the entry because of a schema - * violation, the parser should return NSS_STATUS_NOTFOUND. - * We'll keep on trying subsequent entries until we - * find one which is parseable, or exhaust avialable - * entries, whichever is first. - */ - parseStat=parser(context->session,e,&context->ec_state,fp); - /* hold onto the state if we're out of memory XXX */ - context->ec_state.ls_retry=0; - } - while (parseStat==NSLCD_RESULT_NOTFOUND); - return parseStat; -} - -int _nss_ldap_searchbyname( - MYLDAP_SESSION *session,const char *base,int scope, - const char *filter,const char **attrs,TFILE *fp,NEWparser_t parser) -{ - int stat; - struct ent_context context; - int32_t tmpint32; - - _nss_ldap_ent_context_init(&context,session); - - stat=nss2nslcd(_nss_ldap_search_sync(session,base,scope,filter,attrs,1,&context.ec_res)); - /* write the result code */ - WRITE_INT32(fp,stat); - /* bail on nothing found */ - if (stat!=NSLCD_RESULT_SUCCESS) - return 1; - /* call the parser for the result */ - stat=NEW_do_parse_sync(&context,fp,parser); - - _nss_ldap_ent_context_cleanup(&context); - - return stat; -} - /* * These functions are called from within the parser, where it is assumed * to be safe to use the connection and the respective message. @@ -1396,32 +1310,6 @@ enum nss_status _nss_ldap_assign_attrvals( return NSS_STATUS_SUCCESS; } -int _nss_ldap_write_attrvals(TFILE *fp,MYLDAP_SESSION *session,LDAPMessage *e,const char *attr) -{ - char **vals; - int valcount; - int i; - int32_t tmpint32; - /* log */ - log_log(LOG_DEBUG,"_nss_ldap_write_attrvals(%s)",attr); - /* check if we have a connection */ - if (session->ls_conn==NULL) - return NSLCD_RESULT_UNAVAIL; - /* get the values and the number of values */ - vals=ldap_get_values(session->ls_conn,e,attr); - valcount=(vals==NULL)?0:ldap_count_values(vals); - /* write number of entries */ - WRITE_INT32(fp,valcount); - /* write the entries themselves */ - for (i=0;i<valcount;i++) - { - WRITE_STRING(fp,vals[i]); - } - if (vals!=NULL) - ldap_value_free(vals); - return NSLCD_RESULT_SUCCESS; -} - /* Assign a single value to *valptr. */ enum nss_status _nss_ldap_assign_attrval( MYLDAP_SESSION *session,LDAPMessage *e,const char *attr,char **valptr, diff --git a/nslcd/ldap-nss.h b/nslcd/ldap-nss.h index b0188bf..344020f 100644 --- a/nslcd/ldap-nss.h +++ b/nslcd/ldap-nss.h @@ -34,13 +34,8 @@ #include <nss.h> #include <ldap.h> -#include "common/tio.h" #include "cfg.h" -#ifndef LDAP_FILT_MAXSIZ -#define LDAP_FILT_MAXSIZ 1024 -#endif /* not LDAP_FILT_MAXSIZ */ - #ifdef __GNUC__ #define alignof(ptr) __alignof__(ptr) #elif defined(HAVE_ALIGNOF_H) @@ -107,10 +102,10 @@ struct ent_context /* create a new session, this does not yet connect to the LDAP server */ MUST_USE MYLDAP_SESSION *myldap_create_session(void); +/* this a a parser function for LDAP results */ typedef enum nss_status (*parser_t)(MYLDAP_SESSION *session,LDAPMessage *e, - struct ldap_state *, void *,char *, size_t); - -typedef int (*NEWparser_t)(MYLDAP_SESSION *session,LDAPMessage *e,struct ldap_state *pvt,TFILE *fp); + struct ldap_state *state,void *result, + char *buffer,size_t buflen); /* * _nss_ldap_ent_context_init() is called for each getXXent() call @@ -120,35 +115,17 @@ void _nss_ldap_ent_context_init(struct ent_context *context,MYLDAP_SESSION *sess /* * _nss_ldap_ent_context_cleanup() is used to manually free a context */ -void _nss_ldap_ent_context_cleanup (struct ent_context *); - -/* - * these are helper functions for ldap-grp.c only on Solaris - */ -char **_nss_ldap_get_values(MYLDAP_SESSION *session,LDAPMessage *e,const char *attr); -char *_nss_ldap_get_dn (MYLDAP_SESSION *session,LDAPMessage *e); -LDAPMessage *_nss_ldap_first_entry(MYLDAP_SESSION *session,LDAPMessage *res); -char *_nss_ldap_first_attribute(MYLDAP_SESSION *session,LDAPMessage *entry,BerElement **berptr); -char *_nss_ldap_next_attribute(MYLDAP_SESSION *session,LDAPMessage *entry,BerElement *ber); +void _nss_ldap_ent_context_cleanup(struct ent_context *context); -/* - * Synchronous search cover. - */ enum nss_status _nss_ldap_search_sync( MYLDAP_SESSION *session,const char *base,int scope, const char *filter,const char **attrs,int sizelimit, LDAPMessage **res); -int _nss_ldap_searchbyname( - MYLDAP_SESSION *session,const char *base,int scope, - const char *filter,const char **attrs,TFILE *fp,NEWparser_t parser); - -int _nss_ldap_write_attrvals(TFILE *fp,MYLDAP_SESSION *session,LDAPMessage *e,const char *attr); - /* * Emulate X.500 read operation. */ -enum nss_status _nss_ldap_read_sync ( +enum nss_status _nss_ldap_read_sync( MYLDAP_SESSION *session, const char *dn, /* IN */ const char **attributes, /* IN */ @@ -178,6 +155,13 @@ int _nss_ldap_getbyname( parser_t parser); /* parsing utility functions */ + +char **_nss_ldap_get_values(MYLDAP_SESSION *session,LDAPMessage *e,const char *attr); +char *_nss_ldap_get_dn(MYLDAP_SESSION *session,LDAPMessage *e); +LDAPMessage *_nss_ldap_first_entry(MYLDAP_SESSION *session,LDAPMessage *res); +char *_nss_ldap_first_attribute(MYLDAP_SESSION *session,LDAPMessage *entry,BerElement **berptr); +char *_nss_ldap_next_attribute(MYLDAP_SESSION *session,LDAPMessage *entry,BerElement *ber); + enum nss_status _nss_ldap_assign_attrvals ( MYLDAP_SESSION *session, LDAPMessage *e, /* IN */ diff --git a/nslcd/util.c b/nslcd/util.c index 73be117..0dad86c 100644 --- a/nslcd/util.c +++ b/nslcd/util.c @@ -525,75 +525,6 @@ enum nss_status _nss_ldap_getrdnvalue( return status; } -int _nss_ldap_write_rndvalue(TFILE *fp,MYLDAP_SESSION *session,LDAPMessage *entry,const char *rdntype) -{ - char *dn; - int status=456; - char **vals; - int32_t tmpint32; - char **exploded_dn; - char **exploded_rdn; - char rdnava[64]; - int rdnavalen; - int i; - /* log call */ - log_log(LOG_DEBUG,"_nss_ldap_write_rndvalue(%s)",rdntype); - /* get the dn from the entry */ - dn=_nss_ldap_get_dn(session,entry); - if (dn==NULL) - return NSLCD_RESULT_NOTFOUND; - /* append a `=' to the rdntype */ - snprintf(rdnava,sizeof(rdnava),"%s=",rdntype); - rdnavalen=strlen(rdnava); - /* explode dn */ - exploded_dn=ldap_explode_dn(dn,0); - if (exploded_dn!=NULL) - { - /* - * attempt to get the naming attribute's principal - * value by parsing the RDN. We need to support - * multivalued RDNs (as they're essentially mandated - * for services) - */ - exploded_rdn=ldap_explode_rdn(exploded_dn[0],0); - if (exploded_rdn!=NULL) - { - for (i=0;exploded_rdn[i]!=NULL;i++) - { - /* if the values begins with rndava */ - if (strncasecmp(exploded_rdn[i],rdnava,rdnavalen)==0) - { - /* FIXME: handle case where WRITE fails */ - WRITE_STRING(fp,exploded_rdn[i]+rdnavalen); - status=0; - break; - } - } - ldap_value_free(exploded_rdn); - } - ldap_value_free(exploded_dn); - } - ldap_memfree(dn); - /* - * If examining the DN failed, then pick the nominal first - * value of cn as the canonical name (recall that attributes - * are sets, not sequences) - */ - if (status==456) - { - vals=_nss_ldap_get_values(session,entry,rdntype); - if (vals!=NULL) - { - /* write the first entry */ - WRITE_STRING(fp,vals[0]); - status=NSS_STATUS_SUCCESS; - ldap_value_free(vals); - status=0; - } - } - return status; -} - int _nss_ldap_escape_string(const char *src,char *buffer,size_t buflen) { int pos=0; diff --git a/nslcd/util.h b/nslcd/util.h index 84f3e71..63ecfff 100644 --- a/nslcd/util.h +++ b/nslcd/util.h @@ -26,8 +26,6 @@ #ifndef _LDAP_NSS_LDAP_UTIL_H #define _LDAP_NSS_LDAP_UTIL_H -#include "common/tio.h" - /* * get the RDN's value: eg. if the RDN was cn=lukeh, getrdnvalue(entry) * would return lukeh. @@ -36,8 +34,6 @@ enum nss_status _nss_ldap_getrdnvalue( MYLDAP_SESSION *session,LDAPMessage *entry,const char *rdntype, char **rval,char **buffer,size_t * buflen); -int _nss_ldap_write_rndvalue(TFILE *fp,MYLDAP_SESSION *session,LDAPMessage *entry,const char *rdntype); - /* * map a distinguished name to a login name, or group entry */ |