Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/nslcd
diff options
context:
space:
mode:
Diffstat (limited to 'nslcd')
-rw-r--r--nslcd/alias.c9
-rw-r--r--nslcd/ether.c9
-rw-r--r--nslcd/group.c53
-rw-r--r--nslcd/host.c9
-rw-r--r--nslcd/ldap-nss.c326
-rw-r--r--nslcd/ldap-nss.h23
-rw-r--r--nslcd/netgroup.c7
-rw-r--r--nslcd/network.c9
-rw-r--r--nslcd/passwd.c9
-rw-r--r--nslcd/protocol.c9
-rw-r--r--nslcd/rpc.c9
-rw-r--r--nslcd/service.c9
-rw-r--r--nslcd/shadow.c9
13 files changed, 184 insertions, 306 deletions
diff --git a/nslcd/alias.c b/nslcd/alias.c
index a1bb482..28c5f03 100644
--- a/nslcd/alias.c
+++ b/nslcd/alias.c
@@ -141,7 +141,7 @@ int nslcd_alias_byname(TFILE *fp)
int nslcd_alias_all(TFILE *fp)
{
int32_t tmpint32,tmp2int32;
- struct ent_context *alias_context=NULL;
+ struct ent_context context;
char filter[1024];
/* these are here for now until we rewrite the LDAP code */
struct aliasent result;
@@ -154,12 +154,11 @@ int nslcd_alias_all(TFILE *fp)
WRITE_INT32(fp,NSLCD_VERSION);
WRITE_INT32(fp,NSLCD_ACTION_ALIAS_ALL);
/* initialize context */
- if (_nss_ldap_ent_context_init(&alias_context)==NULL)
- return -1;
+ _nss_ldap_ent_context_init(&context);
/* loop over all results */
mkfilter_alias_all(filter,sizeof(filter));
alias_attrs_init();
- while ((retv=_nss_ldap_getent(&alias_context,&result,buffer,sizeof(buffer),&errnop,
+ while ((retv=_nss_ldap_getent(&context,&result,buffer,sizeof(buffer),&errnop,
NULL,filter,alias_attrs,LM_ALIASES,_nss_ldap_parse_alias))==NSLCD_RESULT_SUCCESS)
{
/* write the result */
@@ -171,7 +170,7 @@ int nslcd_alias_all(TFILE *fp)
WRITE_FLUSH(fp);
/* FIXME: if a previous call returns what happens to the context? */
_nss_ldap_enter();
- _nss_ldap_ent_context_release(alias_context);
+ _nss_ldap_ent_context_cleanup(&context);
_nss_ldap_leave();
/* we're done */
return 0;
diff --git a/nslcd/ether.c b/nslcd/ether.c
index ac66519..39c7b9f 100644
--- a/nslcd/ether.c
+++ b/nslcd/ether.c
@@ -225,7 +225,7 @@ int nslcd_ether_all(TFILE *fp)
{
int32_t tmpint32;
char filter[1024];
- struct ent_context *ether_context=NULL;
+ struct ent_context context;
/* these are here for now until we rewrite the LDAP code */
struct ether result;
char buffer[1024];
@@ -237,12 +237,11 @@ int nslcd_ether_all(TFILE *fp)
WRITE_INT32(fp,NSLCD_VERSION);
WRITE_INT32(fp,NSLCD_ACTION_ETHER_ALL);
/* initialize context */
- if (_nss_ldap_ent_context_init(&ether_context)==NULL)
- return -1;
+ _nss_ldap_ent_context_init(&context);
/* loop over all results */
mkfilter_ether_all(filter,sizeof(filter));
ether_attrs_init();
- while ((retv=_nss_ldap_getent(&ether_context,&result,buffer,sizeof(buffer),&errnop,
+ while ((retv=_nss_ldap_getent(&context,&result,buffer,sizeof(buffer),&errnop,
NULL,filter,ether_attrs,LM_ETHERS,_nss_ldap_parse_ether))==NSLCD_RESULT_SUCCESS)
{
/* write the result */
@@ -254,7 +253,7 @@ int nslcd_ether_all(TFILE *fp)
WRITE_FLUSH(fp);
/* FIXME: if a previous call returns what happens to the context? */
_nss_ldap_enter();
- _nss_ldap_ent_context_release(ether_context);
+ _nss_ldap_ent_context_cleanup(&context);
_nss_ldap_leave();
/* we're done */
return 0;
diff --git a/nslcd/group.c b/nslcd/group.c
index 1856fa6..2cb55c0 100644
--- a/nslcd/group.c
+++ b/nslcd/group.c
@@ -174,7 +174,7 @@ static int mkfilter_group_bymember(const char *user,
char *buffer,size_t buflen)
{
char buf2[1024];
- const char *userdn;
+ char *userdn;
char buf3[1024];
/* escape attribute */
if(myldap_escape(user,buf2,sizeof(buf2)))
@@ -982,7 +982,7 @@ static enum nss_status ng_chase(const char *dn, ldap_initgroups_args_t * lia)
{
char filter[1024];
enum nss_status stat;
- struct ent_context *ctx=NULL;
+ struct ent_context context;
const char *gidnumber_attrs[2];
int erange;
@@ -995,22 +995,16 @@ static enum nss_status ng_chase(const char *dn, ldap_initgroups_args_t * lia)
gidnumber_attrs[0]=attmap_group_gidNumber;
gidnumber_attrs[1]=NULL;
- if (_nss_ldap_ent_context_init_locked(&ctx)==NULL)
- {
- return NSS_STATUS_UNAVAIL;
- }
+ _nss_ldap_ent_context_init_locked(&context);
mkfilter_getgroupsbydn(dn,filter,sizeof(filter));
- stat=_nss_ldap_getent_ex(&ctx,lia,NULL,0,&erange,
+ stat=_nss_ldap_getent_locked(&context,lia,NULL,0,&erange,
NULL,filter,gidnumber_attrs,
LM_GROUP,do_parse_initgroups_nested);
if (stat==NSS_STATUS_SUCCESS)
- {
stat=_nss_ldap_namelist_push(&lia->known_groups,dn);
- }
- _nss_ldap_ent_context_release(ctx);
- free(ctx);
+ _nss_ldap_ent_context_cleanup(&context);
return stat;
}
@@ -1018,7 +1012,7 @@ static enum nss_status ng_chase(const char *dn, ldap_initgroups_args_t * lia)
static enum nss_status ng_chase_backlink(const char ** membersOf, ldap_initgroups_args_t * lia)
{
enum nss_status stat;
- struct ent_context *ctx=NULL;
+ struct ent_context context;
const char *gidnumber_attrs[3];
const char **memberP;
const char **filteredMembersOf; /* remove already traversed groups */
@@ -1061,15 +1055,10 @@ static enum nss_status ng_chase_backlink(const char ** membersOf, ldap_initgroup
gidnumber_attrs[1] = attmap_group_memberOf;
gidnumber_attrs[2] = NULL;
- if (_nss_ldap_ent_context_init_locked (&ctx) == NULL)
- {
- free (filteredMembersOf);
- return NSS_STATUS_UNAVAIL;
- }
-
+ _nss_ldap_ent_context_init_locked(&context);
/* FIXME: the search filter is wrong here, we should figure out what it's
supposed to be */
- stat=_nss_ldap_getent_ex(&ctx,lia,NULL,0,&erange,
+ stat=_nss_ldap_getent_locked(&context,lia,NULL,0,&erange,
NULL,"(distinguishedName=%s)",gidnumber_attrs,
LM_GROUP,do_parse_initgroups_nested);
@@ -1090,8 +1079,7 @@ static enum nss_status ng_chase_backlink(const char ** membersOf, ldap_initgroup
free (filteredMembersOf);
- _nss_ldap_ent_context_release (ctx);
- free (ctx);
+ _nss_ldap_ent_context_cleanup(&context);
return stat;
}
@@ -1103,7 +1091,7 @@ static int group_bymember(const char *user, long int *start,
ldap_initgroups_args_t lia;
char filter[1024];
enum nss_status stat;
- struct ent_context *ctx=NULL;
+ struct ent_context context;
const char *gidnumber_attrs[3];
log_log(LOG_DEBUG,"==> group_bymember (user=%s)",user);
lia.depth = 0;
@@ -1120,18 +1108,12 @@ static int group_bymember(const char *user, long int *start,
mkfilter_group_bymember(user,filter,sizeof(filter));
gidnumber_attrs[0] = attmap_group_gidNumber;
gidnumber_attrs[1] = NULL;
- if (_nss_ldap_ent_context_init_locked(&ctx)==NULL)
- {
- log_log(LOG_DEBUG,"<== group_bymember (ent_context_init failed)");
- _nss_ldap_leave ();
- return -1;
- }
- stat=_nss_ldap_getent_ex(&ctx,(void *)&lia,NULL,0,errnop,
+ _nss_ldap_ent_context_init_locked(&context);
+ stat=_nss_ldap_getent_locked(&context,(void *)&lia,NULL,0,errnop,
NULL,filter,gidnumber_attrs,
LM_GROUP,do_parse_initgroups_nested);
_nss_ldap_namelist_destroy(&lia.known_groups);
- _nss_ldap_ent_context_release(ctx);
- free(ctx);
+ _nss_ldap_ent_context_cleanup(&context);
_nss_ldap_leave();
if ((stat!=NSS_STATUS_SUCCESS)&&(stat!=NSS_STATUS_NOTFOUND))
{
@@ -1286,7 +1268,7 @@ int nslcd_group_bymember(TFILE *fp)
int nslcd_group_all(TFILE *fp)
{
int32_t tmpint32,tmp2int32,tmp3int32;
- struct ent_context *gr_context=NULL;
+ struct ent_context context;
char filter[1024];
/* these are here for now until we rewrite the LDAP code */
struct group result;
@@ -1299,12 +1281,11 @@ int nslcd_group_all(TFILE *fp)
WRITE_INT32(fp,NSLCD_VERSION);
WRITE_INT32(fp,NSLCD_ACTION_GROUP_ALL);
/* initialize context */
- if (_nss_ldap_ent_context_init(&gr_context)==NULL)
- return -1;
+ _nss_ldap_ent_context_init(&context);
/* loop over all results */
mkfilter_group_all(filter,sizeof(filter));
group_attrs_init();
- while ((retv=_nss_ldap_getent(&gr_context,&result,buffer,sizeof(buffer),&errnop,
+ while ((retv=_nss_ldap_getent(&context,&result,buffer,sizeof(buffer),&errnop,
NULL,filter,group_attrs,LM_GROUP,_nss_ldap_parse_gr))==NSLCD_RESULT_SUCCESS)
{
/* write the result */
@@ -1316,7 +1297,7 @@ int nslcd_group_all(TFILE *fp)
WRITE_FLUSH(fp);
/* FIXME: if a previous call returns what happens to the context? */
_nss_ldap_enter();
- _nss_ldap_ent_context_release(gr_context);
+ _nss_ldap_ent_context_cleanup(&context);
_nss_ldap_leave();
/* we're done */
return 0;
diff --git a/nslcd/host.c b/nslcd/host.c
index 6e6dda0..c006577 100644
--- a/nslcd/host.c
+++ b/nslcd/host.c
@@ -387,7 +387,7 @@ int nslcd_host_byaddr(TFILE *fp)
int nslcd_host_all(TFILE *fp)
{
int32_t tmpint32;
- struct ent_context *host_context=NULL;
+ struct ent_context context;
char filter[1024];
/* these are here for now until we rewrite the LDAP code */
struct hostent result;
@@ -400,12 +400,11 @@ int nslcd_host_all(TFILE *fp)
WRITE_INT32(fp,NSLCD_VERSION);
WRITE_INT32(fp,NSLCD_ACTION_HOST_ALL);
/* initialize context */
- if (_nss_ldap_ent_context_init(&host_context)==NULL)
- return -1;
+ _nss_ldap_ent_context_init(&context);
/* loop over all results */
mkfilter_host_all(filter,sizeof(filter));
host_attrs_init();
- while ((retv=_nss_ldap_getent(&host_context,&result,buffer,sizeof(buffer),&errnop,
+ while ((retv=_nss_ldap_getent(&context,&result,buffer,sizeof(buffer),&errnop,
NULL,filter,host_attrs,LM_HOSTS,
#ifdef INET6
(_res.options&RES_USE_INET6)?_nss_ldap_parse_hostv6:_nss_ldap_parse_hostv4
@@ -424,7 +423,7 @@ int nslcd_host_all(TFILE *fp)
WRITE_FLUSH(fp);
/* FIXME: if a previous call returns what happens to the context? */
_nss_ldap_enter();
- _nss_ldap_ent_context_release(host_context);
+ _nss_ldap_ent_context_cleanup(&context);
_nss_ldap_leave();
/* we're done */
return 0;
diff --git a/nslcd/ldap-nss.c b/nslcd/ldap-nss.c
index 3a36010..b9b05ec 100644
--- a/nslcd/ldap-nss.c
+++ b/nslcd/ldap-nss.c
@@ -666,7 +666,6 @@ do_init_session (LDAP ** ld, const char *uri)
{
int rc;
int ldaps;
- char uribuf[1024];
char *p;
enum nss_status stat;
@@ -1137,32 +1136,11 @@ do_open (void)
}
/*
- * This function initializes an enumeration context, acquiring
- * the global mutex.
- *
- * It could be done from the default constructor, under Solaris, but we
- * delay it until the setXXent() function is called.
- */
-struct ent_context *
-_nss_ldap_ent_context_init (struct ent_context ** pctx)
-{
- struct ent_context *ctx;
-
- _nss_ldap_enter ();
-
- ctx = _nss_ldap_ent_context_init_locked (pctx);
-
- _nss_ldap_leave ();
-
- return ctx;
-}
-
-/*
* Wrapper around ldap_result() to skip over search references
* and deal transparently with the last entry.
*/
static enum nss_status
-do_result (struct ent_context * ctx, int all)
+do_result (struct ent_context *context, int all)
{
int rc = LDAP_UNAVAILABLE;
enum nss_status stat = NSS_STATUS_TRYAGAIN;
@@ -1183,15 +1161,15 @@ do_result (struct ent_context * ctx, int all)
do
{
- if (ctx->ec_res != NULL)
- {
- ldap_msgfree (ctx->ec_res);
- ctx->ec_res = NULL;
- }
+ if (context->ec_res!=NULL)
+ {
+ ldap_msgfree(context->ec_res);
+ context->ec_res=NULL;
+ }
rc =
- ldap_result (__session.ls_conn, ctx->ec_msgid, all, tvp,
- &ctx->ec_res);
+ ldap_result (__session.ls_conn, context->ec_msgid, all, tvp,
+ &(context->ec_res));
switch (rc)
{
case -1:
@@ -1218,19 +1196,19 @@ do_result (struct ent_context * ctx, int all)
{
#ifdef LDAP_MORE_RESULTS_TO_RETURN
int parserc;
- /* NB: this frees ctx->ec_res */
+ /* NB: this frees context->ec_res */
LDAPControl **resultControls = NULL;
- ctx->ec_cookie = NULL;
+ context->ec_cookie = NULL;
parserc =
- ldap_parse_result (__session.ls_conn, ctx->ec_res, &rc, NULL,
+ ldap_parse_result (__session.ls_conn, context->ec_res, &rc, NULL,
NULL, NULL, &resultControls, 1);
if (parserc != LDAP_SUCCESS
&& parserc != LDAP_MORE_RESULTS_TO_RETURN)
{
stat = NSS_STATUS_UNAVAIL;
- ldap_abandon (__session.ls_conn, ctx->ec_msgid);
+ ldap_abandon (__session.ls_conn, context->ec_msgid);
log_log(LOG_ERR,"could not get LDAP result - %s",
ldap_err2string (rc));
}
@@ -1239,7 +1217,7 @@ do_result (struct ent_context * ctx, int all)
/* See if there are any more pages to come */
parserc = ldap_parse_page_control (__session.ls_conn,
resultControls, NULL,
- &(ctx->ec_cookie));
+ &(context->ec_cookie));
ldap_controls_free (resultControls);
stat = NSS_STATUS_NOTFOUND;
}
@@ -1250,8 +1228,8 @@ do_result (struct ent_context * ctx, int all)
#else
stat = NSS_STATUS_NOTFOUND;
#endif /* LDAP_MORE_RESULTS_TO_RETURN */
- ctx->ec_res = NULL;
- ctx->ec_msgid = -1;
+ context->ec_res = NULL;
+ context->ec_msgid = -1;
}
break;
default:
@@ -1274,106 +1252,65 @@ do_result (struct ent_context * ctx, int all)
}
/*
- * This function initializes an enumeration context.
+ * This function initializes an enumeration context, acquiring
+ * the global mutex.
*
* It could be done from the default constructor, under Solaris, but we
* delay it until the setXXent() function is called.
*/
-struct ent_context *
-_nss_ldap_ent_context_init_locked(struct ent_context **pctx)
+void _nss_ldap_ent_context_init(struct ent_context *context)
{
- struct ent_context *ctx;
-
- log_log(LOG_DEBUG,"==> _nss_ldap_ent_context_init_locked");
-
- ctx = *pctx;
-
- if (ctx == NULL)
- {
- ctx=(struct ent_context *)malloc(sizeof(struct ent_context));
- if (ctx == NULL)
- {
- log_log(LOG_DEBUG,"<== _nss_ldap_ent_context_init_locked");
- return NULL;
- }
- *pctx = ctx;
- }
- else
- {
- if (ctx->ec_res != NULL)
- {
- ldap_msgfree (ctx->ec_res);
- }
- if (ctx->ec_cookie != NULL)
- {
- ber_bvfree (ctx->ec_cookie);
- }
- if (ctx->ec_msgid > -1 && do_result (ctx, LDAP_MSG_ONE) == NSS_STATUS_SUCCESS)
- {
- ldap_abandon (__session.ls_conn, ctx->ec_msgid);
- }
- }
-
- ctx->ec_cookie = NULL;
- ctx->ec_res = NULL;
- ctx->ec_msgid = -1;
- ctx->ec_sd = NULL;
-
- LS_INIT (ctx->ec_state);
-
- log_log(LOG_DEBUG,"<== _nss_ldap_ent_context_init_locked");
+ _nss_ldap_enter();
+ _nss_ldap_ent_context_init_locked(context);
+ _nss_ldap_leave();
+}
- return ctx;
+/*
+ * This function initializes an enumeration context.
+ *
+ * It could be done from the default constructor, under Solaris, but we
+ * delay it until the setXXent() function is called.
+ */
+void _nss_ldap_ent_context_init_locked(struct ent_context *context)
+{
+ /* TODO: find out why we need to have aquired a lock for this */
+ context->ec_cookie=NULL;
+ context->ec_res=NULL;
+ context->ec_msgid=-1;
+ context->ec_sd=NULL;
+ LS_INIT(context->ec_state);
}
/*
* Clears a given context; we require the caller
* to acquire the lock.
*/
-void
-_nss_ldap_ent_context_release (struct ent_context * ctx)
+void _nss_ldap_ent_context_cleanup(struct ent_context *context)
{
- log_log(LOG_DEBUG,"==> _nss_ldap_ent_context_release");
-
- if (ctx == NULL)
- {
- log_log(LOG_DEBUG,"<== _nss_ldap_ent_context_release");
- return;
- }
-
- if (ctx->ec_res != NULL)
- {
- ldap_msgfree (ctx->ec_res);
- ctx->ec_res = NULL;
- }
-
- /*
- * Abandon the search if there were more results to fetch.
- */
- if (ctx->ec_msgid > -1 && do_result (ctx, LDAP_MSG_ONE) == NSS_STATUS_SUCCESS)
- {
- ldap_abandon (__session.ls_conn, ctx->ec_msgid);
- ctx->ec_msgid = -1;
- }
-
- if (ctx->ec_cookie != NULL)
- {
- ber_bvfree (ctx->ec_cookie);
- ctx->ec_cookie = NULL;
- }
-
- ctx->ec_sd = NULL;
-
- LS_INIT (ctx->ec_state);
-
- if (_nss_ldap_test_config_flag (NSS_LDAP_FLAGS_CONNECT_POLICY_ONESHOT))
- {
- do_close ();
- }
-
- log_log(LOG_DEBUG,"<== _nss_ldap_ent_context_release");
-
- return;
+ if (context==NULL)
+ return;
+ /* free read messages */
+ if (context->ec_res!=NULL)
+ {
+ ldap_msgfree(context->ec_res);
+ context->ec_res=NULL;
+ }
+ /* abandon the search if there were more results to fetch */
+ if ((context->ec_msgid>-1)&&(do_result(context,LDAP_MSG_ONE)==NSS_STATUS_SUCCESS))
+ {
+ ldap_abandon(__session.ls_conn,context->ec_msgid);
+ context->ec_msgid=-1;
+ }
+ /* clean up cookie */
+ if (context->ec_cookie!=NULL)
+ {
+ ber_bvfree(context->ec_cookie);
+ context->ec_cookie=NULL;
+ }
+ context->ec_sd=NULL;
+ LS_INIT(context->ec_state);
+ if (_nss_ldap_test_config_flag(NSS_LDAP_FLAGS_CONNECT_POLICY_ONESHOT))
+ do_close ();
}
/*
@@ -1624,7 +1561,7 @@ do_map_errno (enum nss_status status, int *errnop)
* correctly or there is an exceptional condition.
*/
static enum nss_status
-do_parse (struct ent_context * ctx, void *result, char
+do_parse (struct ent_context *context, void *result, char
*buffer, size_t buflen, int *errnop, parser_t parser)
{
enum nss_status parseStat = NSS_STATUS_NOTFOUND;
@@ -1642,11 +1579,11 @@ do_parse (struct ent_context * ctx, void *result, char
{
enum nss_status resultStat = NSS_STATUS_SUCCESS;
- if (ctx->ec_state.ls_retry == 0 &&
- (ctx->ec_state.ls_type == LS_TYPE_KEY
- || ctx->ec_state.ls_info.ls_index == -1))
+ if ((context->ec_state.ls_retry==0) &&
+ ( (context->ec_state.ls_type==LS_TYPE_KEY) ||
+ (context->ec_state.ls_info.ls_index==-1) ))
{
- resultStat = do_result (ctx, LDAP_MSG_ONE);
+ resultStat=do_result(context,LDAP_MSG_ONE);
}
if (resultStat != NSS_STATUS_SUCCESS)
@@ -1665,20 +1602,19 @@ do_parse (struct ent_context * ctx, void *result, char
* find one which is parseable, or exhaust avialable
* entries, whichever is first.
*/
- parseStat = parser (ctx->ec_res, &ctx->ec_state, result,
- buffer, buflen);
+ parseStat=parser(context->ec_res,&(context->ec_state),result,buffer,buflen);
/* hold onto the state if we're out of memory XXX */
- ctx->ec_state.ls_retry = (parseStat == NSS_STATUS_TRYAGAIN && buffer != NULL ? 1 : 0);
+ context->ec_state.ls_retry = (parseStat == NSS_STATUS_TRYAGAIN && buffer != NULL ? 1 : 0);
/* free entry is we're moving on */
- if (ctx->ec_state.ls_retry == 0 &&
- (ctx->ec_state.ls_type == LS_TYPE_KEY
- || ctx->ec_state.ls_info.ls_index == -1))
+ if ((context->ec_state.ls_retry==0) &&
+ ( (context->ec_state.ls_type==LS_TYPE_KEY) ||
+ (context->ec_state.ls_info.ls_index==-1) ))
{
/* we don't need the result anymore, ditch it. */
- ldap_msgfree (ctx->ec_res);
- ctx->ec_res = NULL;
+ ldap_msgfree(context->ec_res);
+ context->ec_res=NULL;
}
}
while (parseStat == NSS_STATUS_NOTFOUND);
@@ -1694,7 +1630,7 @@ do_parse (struct ent_context * ctx, void *result, char
* Parse, fetching reuslts from chain instead of server.
*/
static enum nss_status
-do_parse_s (struct ent_context * ctx, void *result, char
+do_parse_s (struct ent_context *context, void *result, char
*buffer, size_t buflen, int *errnop, parser_t parser)
{
enum nss_status parseStat = NSS_STATUS_NOTFOUND;
@@ -1711,12 +1647,12 @@ do_parse_s (struct ent_context * ctx, void *result, char
*/
do
{
- if (ctx->ec_state.ls_retry == 0 &&
- (ctx->ec_state.ls_type == LS_TYPE_KEY
- || ctx->ec_state.ls_info.ls_index == -1))
+ 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 (__session.ls_conn, ctx->ec_res);
+ e = ldap_first_entry (__session.ls_conn, context->ec_res);
else
e = ldap_next_entry (__session.ls_conn, e);
}
@@ -1737,10 +1673,10 @@ do_parse_s (struct ent_context * ctx, void *result, char
* find one which is parseable, or exhaust avialable
* entries, whichever is first.
*/
- parseStat = parser (e, &ctx->ec_state, result, buffer, buflen);
+ parseStat=parser(e,&(context->ec_state),result,buffer,buflen);
/* hold onto the state if we're out of memory XXX */
- ctx->ec_state.ls_retry = (parseStat == NSS_STATUS_TRYAGAIN && buffer != NULL ? 1 : 0);
+ context->ec_state.ls_retry=(parseStat==NSS_STATUS_TRYAGAIN)&&(buffer!=NULL);
}
while (parseStat == NSS_STATUS_NOTFOUND);
@@ -2015,7 +1951,7 @@ do_next_page (const char *base,const char *filter,const char **attrs,
* Locks mutex.
*/
int
-_nss_ldap_getent(struct ent_context **ctx,
+_nss_ldap_getent(struct ent_context *context,
void *result,char *buffer,size_t buflen,int *errnop,
const char *base,const char *filter,
const char **attrs, enum ldap_map_selector sel, parser_t parser)
@@ -2027,7 +1963,7 @@ _nss_ldap_getent(struct ent_context **ctx,
* of the context.
*/
_nss_ldap_enter();
- status=nss2nslcd(_nss_ldap_getent_ex(ctx,result,
+ status=nss2nslcd(_nss_ldap_getent_locked(context,result,
buffer,buflen,
errnop,base,filter,attrs,sel,parser));
_nss_ldap_leave();
@@ -2039,73 +1975,53 @@ _nss_ldap_getent(struct ent_context **ctx,
* Caller holds global mutex
*/
enum nss_status
-_nss_ldap_getent_ex(struct ent_context **ctx,
+_nss_ldap_getent_locked(struct ent_context *context,
void *result,char *buffer,size_t buflen,int *errnop,
const char *base,const char *filter,
const char **attrs,
enum ldap_map_selector sel,parser_t parser)
{
enum nss_status stat = NSS_STATUS_SUCCESS;
-
- log_log(LOG_DEBUG,"==> _nss_ldap_getent_ex (base=\"%s\", filter=\"%s\")",base,filter);
-
- if (*ctx == NULL || (*ctx)->ec_msgid < 0)
- {
- /*
- * implicitly call setent() if this is the first time
- * or there is no active search
- */
- if (_nss_ldap_ent_context_init_locked (ctx) == NULL)
- {
- log_log(LOG_DEBUG,"<== _nss_ldap_getent_ex");
- return NSS_STATUS_UNAVAIL;
- }
- }
-
+ int msgid;
+ log_log(LOG_DEBUG,"==> _nss_ldap_getent_locked (base=\"%s\", filter=\"%s\")",base,filter);
next:
- /*
- * If ctx->ec_msgid < 0, then we haven't searched yet. Let's do it!
- */
- if ((*ctx)->ec_msgid < 0)
+ /* if context->ec_msgid < 0, then we haven't searched yet */
+ if (context->ec_msgid<0)
{
- int msgid;
-
stat=_nss_ldap_search(base,filter,attrs,sel,
- LDAP_NO_LIMIT,&msgid,&(*ctx)->ec_sd);
+ LDAP_NO_LIMIT,&msgid,&(context->ec_sd));
if (stat != NSS_STATUS_SUCCESS)
{
- log_log(LOG_DEBUG,"<== _nss_ldap_getent_ex");
+ log_log(LOG_DEBUG,"<== _nss_ldap_getent_locked");
return stat;
}
-
- (*ctx)->ec_msgid = msgid;
+ context->ec_msgid=msgid;
}
- stat = do_parse(*ctx, result, buffer, buflen, errnop, parser);
+ stat=do_parse(context,result,buffer,buflen,errnop,parser);
- if (stat == NSS_STATUS_NOTFOUND)
+ if (stat==NSS_STATUS_NOTFOUND)
{
/* Is there another page of results? */
- if ((*ctx)->ec_cookie != NULL && (*ctx)->ec_cookie->bv_len != 0)
+ if ((context->ec_cookie!=NULL)&&(context->ec_cookie->bv_len!=0))
{
- int msgid;
stat=do_next_page(base,filter,attrs,sel,LDAP_NO_LIMIT,&msgid,
- (*ctx)->ec_cookie);
+ context->ec_cookie);
if (stat!=NSS_STATUS_SUCCESS)
{
- log_log(LOG_DEBUG,"<== _nss_ldap_getent_ex");
+ log_log(LOG_DEBUG,"<== _nss_ldap_getent_locked");
return stat;
}
- (*ctx)->ec_msgid=msgid;
- stat=do_parse(*ctx,result,buffer,buflen,errnop,parser);
+ context->ec_msgid=msgid;
+ stat=do_parse(context,result,buffer,buflen,errnop,parser);
}
}
- if (stat == NSS_STATUS_NOTFOUND && (*ctx)->ec_sd != NULL)
+ if ((stat==NSS_STATUS_NOTFOUND)&&(context->ec_sd!=NULL))
{
- (*ctx)->ec_msgid = -1;
+ context->ec_msgid = -1;
goto next;
}
- log_log(LOG_DEBUG,"<== _nss_ldap_getent_ex");
+ log_log(LOG_DEBUG,"<== _nss_ldap_getent_locked");
return stat;
}
@@ -2121,16 +2037,15 @@ int _nss_ldap_getbyname(void *result, char *buffer, size_t buflen,
{
enum nss_status stat = NSS_STATUS_NOTFOUND;
- struct ent_context ctx;
+ struct ent_context context;
_nss_ldap_enter();
log_log(LOG_DEBUG,"==> _nss_ldap_getbyname (base=\"%s\", filter=\"%s\"",base,filter);
- ctx.ec_msgid=-1;
- ctx.ec_cookie=NULL;
+ _nss_ldap_ent_context_init_locked(&context);
- stat=_nss_ldap_search_s(base,filter,sel,attrs,1,&ctx.ec_res);
+ stat=_nss_ldap_search_s(base,filter,sel,attrs,1,&context.ec_res);
if (stat!=NSS_STATUS_SUCCESS)
{
_nss_ldap_leave ();
@@ -2144,13 +2059,13 @@ int _nss_ldap_getbyname(void *result, char *buffer, size_t buflen,
* we only pass the second argument along, as that's what we need
* in services.
*/
- LS_INIT(ctx.ec_state);
- ctx.ec_state.ls_type=LS_TYPE_KEY;
- ctx.ec_state.ls_info.ls_key=NULL /*was: args->la_arg2.la_string*/;
+ LS_INIT(context.ec_state);
+ context.ec_state.ls_type=LS_TYPE_KEY;
+ context.ec_state.ls_info.ls_key=NULL /*was: args->la_arg2.la_string*/;
- stat=do_parse_s(&ctx,result,buffer,buflen,errnop,parser);
+ stat=do_parse_s(&context,result,buffer,buflen,errnop,parser);
- _nss_ldap_ent_context_release(&ctx);
+ _nss_ldap_ent_context_cleanup(&context);
log_log(LOG_DEBUG,"<== _nss_ldap_getbyname");
@@ -2160,7 +2075,7 @@ int _nss_ldap_getbyname(void *result, char *buffer, size_t buflen,
return nss2nslcd(stat);
}
-static int NEW_do_parse_s(struct ent_context *ctx,TFILE *fp,NEWparser_t parser)
+static int NEW_do_parse_s(struct ent_context *context,TFILE *fp,NEWparser_t parser)
{
int parseStat=NSLCD_RESULT_NOTFOUND;
LDAPMessage *e=NULL;
@@ -2173,12 +2088,12 @@ static int NEW_do_parse_s(struct ent_context *ctx,TFILE *fp,NEWparser_t parser)
*/
do
{
- if (ctx->ec_state.ls_retry == 0 &&
- (ctx->ec_state.ls_type == LS_TYPE_KEY
- || ctx->ec_state.ls_info.ls_index == -1))
+ 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 (__session.ls_conn, ctx->ec_res);
+ e = ldap_first_entry (__session.ls_conn,context->ec_res);
else
e = ldap_next_entry (__session.ls_conn, e);
}
@@ -2197,9 +2112,9 @@ static int NEW_do_parse_s(struct ent_context *ctx,TFILE *fp,NEWparser_t parser)
* find one which is parseable, or exhaust avialable
* entries, whichever is first.
*/
- parseStat=parser(e,&ctx->ec_state,fp);
+ parseStat=parser(e,&context->ec_state,fp);
/* hold onto the state if we're out of memory XXX */
- ctx->ec_state.ls_retry=0;
+ context->ec_state.ls_retry=0;
}
while (parseStat==NSLCD_RESULT_NOTFOUND);
return parseStat;
@@ -2211,15 +2126,14 @@ int _nss_ldap_searchbyname(
enum ldap_map_selector sel,const char **attrs,TFILE *fp,NEWparser_t parser)
{
int stat;
- struct ent_context ctx;
+ struct ent_context context;
int32_t tmpint32;
_nss_ldap_enter();
- ctx.ec_msgid=-1;
- ctx.ec_cookie=NULL;
+ _nss_ldap_ent_context_init_locked(&context);
- stat=nss2nslcd(_nss_ldap_search_s(base,filter,sel,attrs,1,&ctx.ec_res));
+ stat=nss2nslcd(_nss_ldap_search_s(base,filter,sel,attrs,1,&context.ec_res));
/* write the result code */
WRITE_INT32(fp,stat);
/* bail on nothing found */
@@ -2229,9 +2143,9 @@ int _nss_ldap_searchbyname(
return 1;
}
/* call the parser for the result */
- stat=NEW_do_parse_s(&ctx,fp,parser);
+ stat=NEW_do_parse_s(&context,fp,parser);
- _nss_ldap_ent_context_release(&ctx);
+ _nss_ldap_ent_context_cleanup(&context);
/* moved unlock here to avoid race condition bug #49 */
_nss_ldap_leave();
diff --git a/nslcd/ldap-nss.h b/nslcd/ldap-nss.h
index 7f89305..1b0e529 100644
--- a/nslcd/ldap-nss.h
+++ b/nslcd/ldap-nss.h
@@ -147,23 +147,22 @@ void _nss_ldap_enter (void);
void _nss_ldap_leave (void);
/*
- * _nss_ldap_ent_context_init() is called for each getXXent() call
- * This will acquire the global mutex.
- */
-struct ent_context *_nss_ldap_ent_context_init (struct ent_context **);
-
-/*
* _nss_ldap_ent_context_init_locked() has the same behaviour
* as above, except it assumes that the caller has acquired
* the lock
*/
+void _nss_ldap_ent_context_init_locked(struct ent_context *context);
-struct ent_context *_nss_ldap_ent_context_init_locked (struct ent_context **);
+/*
+ * _nss_ldap_ent_context_init() is called for each getXXent() call
+ * This will acquire the global mutex.
+ */
+void _nss_ldap_ent_context_init(struct ent_context *context);
/*
- * _nss_ldap_ent_context_release() is used to manually free a context
+ * _nss_ldap_ent_context_cleanup() is used to manually free a context
*/
-void _nss_ldap_ent_context_release (struct ent_context *);
+void _nss_ldap_ent_context_cleanup (struct ent_context *);
/*
* these are helper functions for ldap-grp.c only on Solaris
@@ -198,8 +197,8 @@ enum nss_status _nss_ldap_read (const char *dn, /* IN */
* extended enumeration routine; uses asynchronous API.
* Caller must have acquired the global mutex
*/
-enum nss_status _nss_ldap_getent_ex (
- struct ent_context ** ctx, /* IN/OUT */
+enum nss_status _nss_ldap_getent_locked (
+ struct ent_context *context, /* IN/OUT */
void *result, /* IN/OUT */
char *buffer, /* IN */
size_t buflen, /* IN */
@@ -214,7 +213,7 @@ enum nss_status _nss_ldap_getent_ex (
* common enumeration routine; uses asynchronous API.
* Acquires the global mutex
*/
-int _nss_ldap_getent(struct ent_context ** ctx, /* IN/OUT */
+int _nss_ldap_getent(struct ent_context *context, /* IN/OUT */
void *result, /* IN/OUT */
char *buffer, /* IN */
size_t buflen, /* IN */
diff --git a/nslcd/netgroup.c b/nslcd/netgroup.c
index a426551..b7a3d36 100644
--- a/nslcd/netgroup.c
+++ b/nslcd/netgroup.c
@@ -312,7 +312,6 @@ out:
int nslcd_netgroup_byname(TFILE *fp)
{
int32_t tmpint32;
- struct ent_context *netgroup_context=NULL;
char name[256];
char filter[1024];
/* these are here for now until we rewrite the LDAP code */
@@ -336,8 +335,6 @@ int nslcd_netgroup_byname(TFILE *fp)
if (_nss_ldap_getbyname(&result,buffer,1024,&errnop,LM_NETGROUP,
NULL,filter,netgroup_attrs,_nss_ldap_load_netgr))
return -1;
- if (_nss_ldap_ent_context_init(&netgroup_context)==NULL)
- return -1;
/* loop over all results */
while ((stat=_nss_ldap_parse_netgr(&result,buffer,1024))==NSS_STATUS_SUCCESS)
{
@@ -370,10 +367,6 @@ int nslcd_netgroup_byname(TFILE *fp)
free(result.data);
/* write the final result code */
WRITE_INT32(fp,NSLCD_RESULT_NOTFOUND);
- /* we're done */
- _nss_ldap_enter();
- _nss_ldap_ent_context_release(netgroup_context);
- _nss_ldap_leave();
return 0;
}
diff --git a/nslcd/network.c b/nslcd/network.c
index 48f16dd..69049f5 100644
--- a/nslcd/network.c
+++ b/nslcd/network.c
@@ -255,7 +255,7 @@ int nslcd_network_byaddr(TFILE *fp)
int nslcd_network_all(TFILE *fp)
{
int32_t tmpint32;
- struct ent_context *net_context=NULL;
+ struct ent_context context;
char filter[1024];
/* these are here for now until we rewrite the LDAP code */
struct netent result;
@@ -268,12 +268,11 @@ int nslcd_network_all(TFILE *fp)
WRITE_INT32(fp,NSLCD_VERSION);
WRITE_INT32(fp,NSLCD_ACTION_NETWORK_ALL);
/* initialize context */
- if (_nss_ldap_ent_context_init(&net_context)==NULL)
- return -1;
+ _nss_ldap_ent_context_init(&context);
/* loop over all results */
mkfilter_network_all(filter,sizeof(filter));
network_attrs_init();
- while ((retv=_nss_ldap_getent(&net_context,&result,buffer,sizeof(buffer),&errnop,
+ while ((retv=_nss_ldap_getent(&context,&result,buffer,sizeof(buffer),&errnop,
NULL,filter,network_attrs,LM_NETWORKS,_nss_ldap_parse_net))==NSLCD_RESULT_SUCCESS)
{
/* write the result */
@@ -286,7 +285,7 @@ int nslcd_network_all(TFILE *fp)
WRITE_FLUSH(fp);
/* FIXME: if a previous call returns what happens to the context? */
_nss_ldap_enter();
- _nss_ldap_ent_context_release(net_context);
+ _nss_ldap_ent_context_cleanup(&context);
_nss_ldap_leave();
/* we're done */
return 0;
diff --git a/nslcd/passwd.c b/nslcd/passwd.c
index 22d4ff6..90f001f 100644
--- a/nslcd/passwd.c
+++ b/nslcd/passwd.c
@@ -295,7 +295,7 @@ int nslcd_passwd_byuid(TFILE *fp)
int nslcd_passwd_all(TFILE *fp)
{
int32_t tmpint32;
- struct ent_context *passwd_context=NULL;
+ struct ent_context context;
char filter[1024];
/* these are here for now until we rewrite the LDAP code */
struct passwd result;
@@ -308,12 +308,11 @@ int nslcd_passwd_all(TFILE *fp)
WRITE_INT32(fp,NSLCD_VERSION);
WRITE_INT32(fp,NSLCD_ACTION_PASSWD_ALL);
/* initialize context */
- if (_nss_ldap_ent_context_init(&passwd_context)==NULL)
- return -1;
+ _nss_ldap_ent_context_init(&context);
/* go over results */
mkfilter_passwd_all(filter,sizeof(filter));
passwd_attrs_init();
- while ((retv=_nss_ldap_getent(&passwd_context,&result,buffer,sizeof(buffer),&errnop,
+ while ((retv=_nss_ldap_getent(&context,&result,buffer,sizeof(buffer),&errnop,
NULL,filter,passwd_attrs,LM_PASSWD,_nss_ldap_parse_pw))==NSLCD_RESULT_SUCCESS)
{
/* write the result */
@@ -325,7 +324,7 @@ int nslcd_passwd_all(TFILE *fp)
WRITE_FLUSH(fp);
/* FIXME: if some statement returns what happens to the context? */
_nss_ldap_enter();
- _nss_ldap_ent_context_release(passwd_context);
+ _nss_ldap_ent_context_cleanup(&context);
_nss_ldap_leave();
/* we're done */
return 0;
diff --git a/nslcd/protocol.c b/nslcd/protocol.c
index 4300dd3..fe9cc81 100644
--- a/nslcd/protocol.c
+++ b/nslcd/protocol.c
@@ -207,7 +207,7 @@ int nslcd_protocol_bynumber(TFILE *fp)
int nslcd_protocol_all(TFILE *fp)
{
int32_t tmpint32,tmp2int32,tmp3int32;
- struct ent_context *protocol_context=NULL;
+ struct ent_context context;
char filter[1024];
/* these are here for now until we rewrite the LDAP code */
struct protoent result;
@@ -220,12 +220,11 @@ int nslcd_protocol_all(TFILE *fp)
WRITE_INT32(fp,NSLCD_VERSION);
WRITE_INT32(fp,NSLCD_ACTION_PROTOCOL_ALL);
/* initialize context */
- if (_nss_ldap_ent_context_init(&protocol_context)==NULL)
- return -1;
+ _nss_ldap_ent_context_init(&context);
/* loop over all results */
mkfilter_protocol_all(filter,sizeof(filter));
protocol_attrs_init();
- while ((retv=_nss_ldap_getent(&protocol_context,&result,buffer,sizeof(buffer),&errnop,
+ while ((retv=_nss_ldap_getent(&context,&result,buffer,sizeof(buffer),&errnop,
NULL,filter,protocol_attrs,LM_PROTOCOLS,_nss_ldap_parse_proto))==NSLCD_RESULT_SUCCESS)
{
/* write the result code */
@@ -238,7 +237,7 @@ int nslcd_protocol_all(TFILE *fp)
WRITE_FLUSH(fp);
/* FIXME: if a previous call returns what happens to the context? */
_nss_ldap_enter();
- _nss_ldap_ent_context_release(protocol_context);
+ _nss_ldap_ent_context_cleanup(&context);
_nss_ldap_leave();
/* we're done */
return 0;
diff --git a/nslcd/rpc.c b/nslcd/rpc.c
index 9cc5609..5393a93 100644
--- a/nslcd/rpc.c
+++ b/nslcd/rpc.c
@@ -212,7 +212,7 @@ int nslcd_rpc_bynumber(TFILE *fp)
int nslcd_rpc_all(TFILE *fp)
{
int32_t tmpint32;
- struct ent_context *rpc_context=NULL;
+ struct ent_context context;
char filter[1024];
/* these are here for now until we rewrite the LDAP code */
struct rpcent result;
@@ -225,12 +225,11 @@ int nslcd_rpc_all(TFILE *fp)
WRITE_INT32(fp,NSLCD_VERSION);
WRITE_INT32(fp,NSLCD_ACTION_RPC_ALL);
/* initialize context */
- if (_nss_ldap_ent_context_init(&rpc_context)==NULL)
- return -1;
+ _nss_ldap_ent_context_init(&context);
/* loop over all results */
mkfilter_rpc_all(filter,sizeof(filter));
rpc_attrs_init();
- while ((retv=_nss_ldap_getent(&rpc_context,&result,buffer,sizeof(buffer),&errnop,
+ while ((retv=_nss_ldap_getent(&context,&result,buffer,sizeof(buffer),&errnop,
NULL,filter,rpc_attrs,LM_RPC,_nss_ldap_parse_rpc))==NSLCD_RESULT_SUCCESS)
{
/* write the result code */
@@ -243,7 +242,7 @@ int nslcd_rpc_all(TFILE *fp)
WRITE_FLUSH(fp);
/* FIXME: if a previous call returns what happens to the context? */
_nss_ldap_enter();
- _nss_ldap_ent_context_release(rpc_context);
+ _nss_ldap_ent_context_cleanup(&context);
_nss_ldap_leave();
/* we're done */
return 0;
diff --git a/nslcd/service.c b/nslcd/service.c
index 897d3cc..35799cc 100644
--- a/nslcd/service.c
+++ b/nslcd/service.c
@@ -324,7 +324,7 @@ int nslcd_service_bynumber(TFILE *fp)
int nslcd_service_all(TFILE *fp)
{
int32_t tmpint32;
- struct ent_context *serv_context=NULL;
+ struct ent_context context;
char filter[1024];
/* these are here for now until we rewrite the LDAP code */
struct servent result;
@@ -337,12 +337,11 @@ int nslcd_service_all(TFILE *fp)
WRITE_INT32(fp,NSLCD_VERSION);
WRITE_INT32(fp,NSLCD_ACTION_SERVICE_ALL);
/* initialize context */
- if (_nss_ldap_ent_context_init(&serv_context)==NULL)
- return -1;
+ _nss_ldap_ent_context_init(&context);
/* loop over all results */
mkfilter_service_all(filter,sizeof(filter));
service_attrs_init();
- while ((retv=_nss_ldap_getent(&serv_context,&result,buffer,sizeof(buffer),&errnop,
+ while ((retv=_nss_ldap_getent(&context,&result,buffer,sizeof(buffer),&errnop,
NULL,filter,service_attrs,LM_SERVICES,_nss_ldap_parse_serv))==NSLCD_RESULT_SUCCESS)
{
/* write the result code */
@@ -355,7 +354,7 @@ int nslcd_service_all(TFILE *fp)
WRITE_FLUSH(fp);
/* FIXME: if a previous call returns what happens to the context? */
_nss_ldap_enter();
- _nss_ldap_ent_context_release(serv_context);
+ _nss_ldap_ent_context_cleanup(&context);
_nss_ldap_leave();
/* we're done */
return 0;
diff --git a/nslcd/shadow.c b/nslcd/shadow.c
index 6e4d88a..c8493af 100644
--- a/nslcd/shadow.c
+++ b/nslcd/shadow.c
@@ -227,7 +227,7 @@ int nslcd_shadow_byname(TFILE *fp)
int nslcd_shadow_all(TFILE *fp)
{
int32_t tmpint32;
- struct ent_context *shadow_context=NULL;
+ struct ent_context context;
char filter[1024];
/* these are here for now until we rewrite the LDAP code */
struct spwd result;
@@ -240,12 +240,11 @@ int nslcd_shadow_all(TFILE *fp)
WRITE_INT32(fp,NSLCD_VERSION);
WRITE_INT32(fp,NSLCD_ACTION_SHADOW_ALL);
/* initialize context */
- if (_nss_ldap_ent_context_init(&shadow_context)==NULL)
- return -1;
+ _nss_ldap_ent_context_init(&context);
/* loop over all results */
mkfilter_shadow_all(filter,sizeof(filter));
shadow_attrs_init();
- while ((retv=_nss_ldap_getent(&shadow_context,&result,buffer,sizeof(buffer),&errnop,
+ while ((retv=_nss_ldap_getent(&context,&result,buffer,sizeof(buffer),&errnop,
NULL,filter,shadow_attrs,LM_SHADOW,_nss_ldap_parse_sp))==NSLCD_RESULT_SUCCESS)
{
/* write the result */
@@ -257,7 +256,7 @@ int nslcd_shadow_all(TFILE *fp)
WRITE_FLUSH(fp);
/* FIXME: if a previous call returns what happens to the context? */
_nss_ldap_enter();
- _nss_ldap_ent_context_release(shadow_context);
+ _nss_ldap_ent_context_cleanup(&context);
_nss_ldap_leave();
/* we're done */
return 0;