summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2010-04-13 19:17:39 +0000
committerArthur de Jong <arthur@arthurdejong.org>2010-04-13 19:17:39 +0000
commitc2b19908cd670ee3b616db572996423b5d8651f4 (patch)
tree210de693fdf13626189c62068d6165deb75f61f1
parentf41023a2c8fc0cf2c54549020269ba6c79533b0f (diff)
also have myldap_search() return an LDAP status code
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd@1078 ef36b2f9-881f-0410-afb5-c4e39611909c
-rw-r--r--nslcd/cfg.c2
-rw-r--r--nslcd/common.h4
-rw-r--r--nslcd/myldap.c17
-rw-r--r--nslcd/myldap.h8
-rw-r--r--nslcd/passwd.c27
-rw-r--r--tests/test_myldap.c20
6 files changed, 43 insertions, 35 deletions
diff --git a/nslcd/cfg.c b/nslcd/cfg.c
index 4f7114d..a82fc6e 100644
--- a/nslcd/cfg.c
+++ b/nslcd/cfg.c
@@ -1104,7 +1104,7 @@ static MUST_USE char *get_base_from_rootdse(void)
session=myldap_create_session();
assert(session!=NULL);
/* perform search */
- search=myldap_search(session,"",LDAP_SCOPE_BASE,"(objectClass=*)",attrs);
+ search=myldap_search(session,"",LDAP_SCOPE_BASE,"(objectClass=*)",attrs,NULL);
if (search==NULL)
{
myldap_session_close(session);
diff --git a/nslcd/common.h b/nslcd/common.h
index a92a6b3..eaf3f53 100644
--- a/nslcd/common.h
+++ b/nslcd/common.h
@@ -3,7 +3,7 @@
This file is part of the nss-pam-ldapd library.
Copyright (C) 2006 West Consulting
- Copyright (C) 2006, 2007, 2008, 2009 Arthur de Jong
+ Copyright (C) 2006, 2007, 2008, 2009, 2010 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
@@ -178,7 +178,7 @@ int nslcd_pam_pwmod(TFILE *fp,MYLDAP_SESSION *session);
for (i=0; (base=db##_bases[i])!=NULL; i++) \
{ \
/* do the LDAP search */ \
- if ((search=myldap_search(session,base,db##_scope,filter,db##_attrs))==NULL) \
+ if ((search=myldap_search(session,base,db##_scope,filter,db##_attrs,NULL))==NULL) \
return -1; \
/* go over results */ \
while ((entry=myldap_get_entry(search,&rc))!=NULL) \
diff --git a/nslcd/myldap.c b/nslcd/myldap.c
index 5016759..2f7a2dc 100644
--- a/nslcd/myldap.c
+++ b/nslcd/myldap.c
@@ -871,15 +871,19 @@ static int do_retry_search(MYLDAP_SEARCH *search)
MYLDAP_SEARCH *myldap_search(
MYLDAP_SESSION *session,
- const char *base,int scope,const char *filter,const char **attrs)
+ const char *base,int scope,const char *filter,const char **attrs,
+ int *rcp)
{
MYLDAP_SEARCH *search;
int i;
+ int rc;
/* check parameters */
if (!is_valid_session(session)||(base==NULL)||(filter==NULL)||(attrs==NULL))
{
log_log(LOG_ERR,"myldap_search(): invalid parameter passed");
errno=EINVAL;
+ if (rcp!=NULL)
+ *rcp=LDAP_OPERATIONS_ERROR;
return NULL;
}
/* log the call */
@@ -895,16 +899,23 @@ MYLDAP_SEARCH *myldap_search(
log_log(LOG_ERR,"myldap_search(): too many searches registered with session (max %d)",
MAX_SEARCHES_IN_SESSION);
myldap_search_close(search);
+ if (rcp!=NULL)
+ *rcp=LDAP_OPERATIONS_ERROR;
return NULL;
}
/* regsiter search with the session so we can free it later on */
session->searches[i]=search;
/* do the search with retries to all configured servers */
- if (do_retry_search(search)!=LDAP_SUCCESS)
+ rc=do_retry_search(search);
+ if (rc!=LDAP_SUCCESS)
{
myldap_search_close(search);
+ if (rcp!=NULL)
+ *rcp=rc;
return NULL;
}
+ if (rcp!=NULL)
+ *rcp=LDAP_SUCCESS;
return search;
}
@@ -1282,7 +1293,7 @@ static SET *myldap_get_ranged_values(MYLDAP_ENTRY *entry,const char *attr)
if (search!=NULL)
myldap_search_close(search);
/* start the new search */
- search=myldap_search(session,dn,LDAP_SCOPE_BASE,"(objectClass=*)",attrs);
+ search=myldap_search(session,dn,LDAP_SCOPE_BASE,"(objectClass=*)",attrs,NULL);
if (search==NULL)
break;
entry=myldap_get_entry(search,NULL);
diff --git a/nslcd/myldap.h b/nslcd/myldap.h
index b9d1058..70fad1d 100644
--- a/nslcd/myldap.h
+++ b/nslcd/myldap.h
@@ -2,7 +2,7 @@
myldap.h - simple interface to do LDAP requests
This file is part of the nss-pam-ldapd library.
- Copyright (C) 2007, 2008, 2009 Arthur de Jong
+ Copyright (C) 2007, 2008, 2009, 2010 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
@@ -83,10 +83,12 @@ void myldap_session_close(MYLDAP_SESSION *session);
/* Do an LDAP search and return a reference to the results (returns NULL on
error). This function uses paging, and does reconnects to the configured
- URLs transparently. */
+ URLs transparently. The function returns an LDAP status code in the
+ location pointed to by rcp if it is non-NULL. */
MUST_USE MYLDAP_SEARCH *myldap_search(
MYLDAP_SESSION *session,
- const char *base,int scope,const char *filter,const char **attrs);
+ const char *base,int scope,const char *filter,const char **attrs,
+ int *rcp);
/* Close the specified search. This frees all the memory that was allocated
for the search and its results. */
diff --git a/nslcd/passwd.c b/nslcd/passwd.c
index a5149f5..f1b9031 100644
--- a/nslcd/passwd.c
+++ b/nslcd/passwd.c
@@ -5,7 +5,7 @@
Copyright (C) 1997-2005 Luke Howard
Copyright (C) 2006 West Consulting
- Copyright (C) 2006, 2007, 2008, 2009 Arthur de Jong
+ Copyright (C) 2006, 2007, 2008, 2009, 2010 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
@@ -145,29 +145,25 @@ char *lookup_dn2uid(MYLDAP_SESSION *session,const char *dn,int *rcp)
MYLDAP_SEARCH *search;
MYLDAP_ENTRY *entry;
static const char *attrs[2];
- int rc;
+ int rc=LDAP_SUCCESS;
const char **values;
char *uid;
- if (rcp!=NULL)
- *rcp=LDAP_SUCCESS;
+ if (rcp==NULL)
+ rcp=&rc;
/* we have to look up the entry */
attrs[0]=attmap_passwd_uid;
attrs[1]=NULL;
- search=myldap_search(session,dn,LDAP_SCOPE_BASE,passwd_filter,attrs);
+ search=myldap_search(session,dn,LDAP_SCOPE_BASE,passwd_filter,attrs,rcp);
if (search==NULL)
{
- log_log(LOG_WARNING,"lookup of user %s failed",dn);
+ log_log(LOG_WARNING,"lookup of user %s failed: %s",dn,ldap_err2string(*rcp));
return NULL;
}
- entry=myldap_get_entry(search,&rc);
+ entry=myldap_get_entry(search,rcp);
if (entry==NULL)
{
- if (rc!=LDAP_SUCCESS)
- {
- log_log(LOG_WARNING,"lookup of user %s failed: %s",dn,ldap_err2string(rc));
- if (rcp!=NULL)
- *rcp=rc;
- }
+ if (*rcp!=LDAP_SUCCESS)
+ log_log(LOG_WARNING,"lookup of user %s failed: %s",dn,ldap_err2string(*rcp));
return NULL;
}
/* get uid (just use first one) */
@@ -254,7 +250,6 @@ MYLDAP_ENTRY *uid2entry(MYLDAP_SESSION *session,const char *uid)
const char *base;
int i;
static const char *attrs[2];
- int rc;
char filter[1024];
/* if it isn't a valid username, just bail out now */
if (!isvalidname(uid))
@@ -266,10 +261,10 @@ MYLDAP_ENTRY *uid2entry(MYLDAP_SESSION *session,const char *uid)
mkfilter_passwd_byname(uid,filter,sizeof(filter));
for (i=0;(i<NSS_LDAP_CONFIG_MAX_BASES)&&((base=passwd_bases[i])!=NULL);i++)
{
- search=myldap_search(session,base,passwd_scope,filter,attrs);
+ search=myldap_search(session,base,passwd_scope,filter,attrs,NULL);
if (search==NULL)
return NULL;
- entry=myldap_get_entry(search,&rc);
+ entry=myldap_get_entry(search,NULL);
if (entry!=NULL)
return entry;
}
diff --git a/tests/test_myldap.c b/tests/test_myldap.c
index 44dfc34..ff2f27e 100644
--- a/tests/test_myldap.c
+++ b/tests/test_myldap.c
@@ -72,7 +72,7 @@ static void test_search(void)
search=myldap_search(session,nslcd_cfg->ldc_bases[0],
LDAP_SCOPE_SUBTREE,
"(objectclass=posixAccount)",
- attrs);
+ attrs,NULL);
assert(search!=NULL);
/* go over results */
printf("test_myldap: test_search(): get results...\n");
@@ -89,7 +89,7 @@ static void test_search(void)
search=myldap_search(session,nslcd_cfg->ldc_bases[0],
LDAP_SCOPE_SUBTREE,
"(objectclass=posixGroup)",
- attrs);
+ attrs,NULL);
assert(search!=NULL);
/* go over results */
printf("test_myldap: test_search(): get results...\n");
@@ -122,7 +122,7 @@ static void test_get(void)
search1=myldap_search(session,nslcd_cfg->ldc_bases[0],
LDAP_SCOPE_SUBTREE,
"(&(|(objectClass=posixGroup)(objectClass=groupOfUniqueNames))(cn=testgroup2))",
- attrs1);
+ attrs1,NULL);
assert(search1!=NULL);
/* get one entry */
entry=myldap_get_entry(search1,&rc);
@@ -138,7 +138,7 @@ static void test_get(void)
search2=myldap_search(session,"cn=Test User2,ou=people,dc=test,dc=tld",
LDAP_SCOPE_BASE,
"(objectclass=posixAccount)",
- attrs2);
+ attrs2,NULL);
assert(search2!=NULL);
/* get one entry */
entry=myldap_get_entry(search2,&rc);
@@ -169,7 +169,7 @@ static void test_get_values(void)
search=myldap_search(session,nslcd_cfg->ldc_bases[0],
LDAP_SCOPE_SUBTREE,
"(&(objectClass=posixAccount)(uid=*))",
- attrs);
+ attrs,NULL);
assert(search!=NULL);
/* go over results */
for (i=0;(entry=myldap_get_entry(search,NULL))!=NULL;i++)
@@ -224,7 +224,7 @@ static void test_get_rdnvalues(void)
search=myldap_search(session,"cn=Aka Ashbach+uid=aashbach,ou=lotsofpeople,dc=test,dc=tld",
LDAP_SCOPE_BASE,
"(objectClass=*)",
- attrs);
+ attrs,NULL);
assert(search!=NULL);
/* get one entry */
entry=myldap_get_entry(search,&rc);
@@ -259,7 +259,7 @@ static void test_two_searches(void)
search1=myldap_search(session,nslcd_cfg->ldc_bases[0],
LDAP_SCOPE_SUBTREE,
"(&(objectClass=posixAccount)(uid=*))",
- attrs);
+ attrs,NULL);
assert(search1!=NULL);
/* get a result from search1 */
entry=myldap_get_entry(search1,NULL);
@@ -272,7 +272,7 @@ static void test_two_searches(void)
search2=myldap_search(session,nslcd_cfg->ldc_bases[0],
LDAP_SCOPE_SUBTREE,
"(&(objectclass=posixGroup)(gidNumber=*))",
- attrs);
+ attrs,NULL);
assert(search2!=NULL);
/* get a result from search2 */
entry=myldap_get_entry(search2,NULL);
@@ -318,7 +318,7 @@ static void *worker(void *arg)
search=myldap_search(session,nslcd_cfg->ldc_bases[0],
LDAP_SCOPE_SUBTREE,
"(objectclass=posixAccount)",
- attrs);
+ attrs,NULL);
assert(search!=NULL);
/* go over results */
for (i=0;(entry=myldap_get_entry(search,&rc))!=NULL;i++)
@@ -385,7 +385,7 @@ static void test_connections(void)
search=myldap_search(session,nslcd_cfg->ldc_bases[0],
LDAP_SCOPE_SUBTREE,
"(objectclass=posixAccount)",
- attrs);
+ attrs,NULL);
assert(search==NULL);
/* clean up */
myldap_session_close(session);