nss-pam-ldapd commit: r1078 - in nss-pam-ldapd: nslcd tests
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
nss-pam-ldapd commit: r1078 - in nss-pam-ldapd: nslcd tests
- From: "Commits of the nss-pam-ldapd project." <nss-pam-ldapd-commits [at] lists.arthurdejong.org>
- To: nss-pam-ldapd-commits [at] lists.arthurdejong.org
- Reply-to: nss-pam-ldapd-users [at] lists.arthurdejong.org
- Subject: nss-pam-ldapd commit: r1078 - in nss-pam-ldapd: nslcd tests
- Date: Tue, 13 Apr 2010 21:17:40 +0200 (CEST)
Author: arthur
Date: Tue Apr 13 21:17:39 2010
New Revision: 1078
URL: http://arthurdejong.org/viewvc/nss-pam-ldapd?view=rev&revision=1078
Log:
also have myldap_search return an LDAP status code
Modified:
nss-pam-ldapd/nslcd/cfg.c
nss-pam-ldapd/nslcd/common.h
nss-pam-ldapd/nslcd/myldap.c
nss-pam-ldapd/nslcd/myldap.h
nss-pam-ldapd/nslcd/passwd.c
nss-pam-ldapd/tests/test_myldap.c
Modified: nss-pam-ldapd/nslcd/cfg.c
==============================================================================
--- nss-pam-ldapd/nslcd/cfg.c Thu Apr 1 21:49:43 2010 (r1077)
+++ nss-pam-ldapd/nslcd/cfg.c Tue Apr 13 21:17:39 2010 (r1078)
@@ -1104,7 +1104,7 @@
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);
Modified: nss-pam-ldapd/nslcd/common.h
==============================================================================
--- nss-pam-ldapd/nslcd/common.h Thu Apr 1 21:49:43 2010 (r1077)
+++ nss-pam-ldapd/nslcd/common.h Tue Apr 13 21:17:39 2010 (r1078)
@@ -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 @@
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) \
Modified: nss-pam-ldapd/nslcd/myldap.c
==============================================================================
--- nss-pam-ldapd/nslcd/myldap.c Thu Apr 1 21:49:43 2010 (r1077)
+++ nss-pam-ldapd/nslcd/myldap.c Tue Apr 13 21:17:39 2010 (r1078)
@@ -871,15 +871,19 @@
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 @@
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 @@
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);
Modified: nss-pam-ldapd/nslcd/myldap.h
==============================================================================
--- nss-pam-ldapd/nslcd/myldap.h Thu Apr 1 21:49:43 2010 (r1077)
+++ nss-pam-ldapd/nslcd/myldap.h Tue Apr 13 21:17:39 2010 (r1078)
@@ -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 @@
/* 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. */
Modified: nss-pam-ldapd/nslcd/passwd.c
==============================================================================
--- nss-pam-ldapd/nslcd/passwd.c Thu Apr 1 21:49:43 2010 (r1077)
+++ nss-pam-ldapd/nslcd/passwd.c Tue Apr 13 21:17:39 2010 (r1078)
@@ -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 @@
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 @@
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 @@
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;
}
Modified: nss-pam-ldapd/tests/test_myldap.c
==============================================================================
--- nss-pam-ldapd/tests/test_myldap.c Thu Apr 1 21:49:43 2010 (r1077)
+++ nss-pam-ldapd/tests/test_myldap.c Tue Apr 13 21:17:39 2010 (r1078)
@@ -72,7 +72,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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);
--
To unsubscribe send an email to
nss-pam-ldapd-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/nss-pam-ldapd-commits
- nss-pam-ldapd commit: r1078 - in nss-pam-ldapd: nslcd tests,
Commits of the nss-pam-ldapd project.