Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2007-10-28 11:57:37 +0100
committerArthur de Jong <arthur@arthurdejong.org>2007-10-28 11:57:37 +0100
commitd0bee6fe83adeeac591d2b8971d81b94963f2ded (patch)
tree3315dd27acf657885db5b287fd919549e795b4c9
parent1a60134c376f0023ab0a5283391e2c51e6031f7d (diff)
first step to use the new myldap interface
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-ldapd@468 ef36b2f9-881f-0410-afb5-c4e39611909c
-rw-r--r--nslcd/alias.c113
-rw-r--r--nslcd/common.h38
-rw-r--r--nslcd/ether.c151
-rw-r--r--nslcd/group.c189
-rw-r--r--nslcd/host.c202
-rw-r--r--nslcd/ldap-nss.c64
-rw-r--r--nslcd/ldap-nss.h17
-rw-r--r--nslcd/netgroup.c48
-rw-r--r--nslcd/network.c196
-rw-r--r--nslcd/passwd.c173
-rw-r--r--nslcd/protocol.c160
-rw-r--r--nslcd/rpc.c159
-rw-r--r--nslcd/service.c217
-rw-r--r--nslcd/shadow.c139
14 files changed, 662 insertions, 1204 deletions
diff --git a/nslcd/alias.c b/nslcd/alias.c
index 36c816d..ecc3e97 100644
--- a/nslcd/alias.c
+++ b/nslcd/alias.c
@@ -40,6 +40,7 @@
#include "ldap-nss.h"
#include "common.h"
#include "log.h"
+#include "myldap.h"
#include "attmap.h"
/* Vendor-specific attributes and object classes.
@@ -96,100 +97,62 @@ static void alias_init(void)
alias_attrs[2]=NULL;
}
-/* 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)
-#define ALIAS_NAME result->alias_name
-#define ALIAS_RCPTS result->alias_members
-
-static int write_aliasent(TFILE *fp,struct aliasent *result)
-{
- int32_t tmpint32,tmp2int32;
- NSLCD_ALIAS;
- return 0;
-}
-
static enum nss_status _nss_ldap_parse_alias(
- MYLDAP_SESSION *session,LDAPMessage *e,struct ldap_state UNUSED(*state),void *result,
+ MYLDAP_ENTRY *entry,struct aliasent *result,
char *buffer,size_t buflen)
{
/* FIXME: fix following problem:
if the entry has multiple cn fields we may end up
sending the wrong cn, we should return the requested
CN instead, otherwise write an entry for each cn */
- struct aliasent *alias=(struct aliasent *)result;
enum nss_status stat;
- stat=_nss_ldap_getrdnvalue(session,e,attmap_alias_cn,&alias->alias_name,&buffer,&buflen);
+ stat=_nss_ldap_getrdnvalue(entry,attmap_alias_cn,&result->alias_name,&buffer,&buflen);
if (stat != NSS_STATUS_SUCCESS)
return stat;
- stat=_nss_ldap_assign_attrvals(session,e,attmap_alias_rfc822MailMember,NULL,&alias->alias_members,&buffer,&buflen,&alias->alias_members_len);
+ stat=_nss_ldap_assign_attrvals(entry,attmap_alias_rfc822MailMember,NULL,&result->alias_members,&buffer,&buflen,&result->alias_members_len);
return stat;
}
-int nslcd_alias_byname(TFILE *fp,MYLDAP_SESSION *session)
-{
- int32_t tmpint32;
- char name[256];
- char filter[1024];
- /* these are here for now until we rewrite the LDAP code */
- struct aliasent result;
- char buffer[1024];
- int retv;
- /* read request parameters */
- READ_STRING_BUF2(fp,name,sizeof(name));
- /* log call */
- log_log(LOG_DEBUG,"nslcd_alias_byname(%s)",name);
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_ALIAS_BYNAME);
- /* do the LDAP request */
- mkfilter_alias_byname(name,filter,sizeof(filter));
- alias_init();
- retv=_nss_ldap_getbyname(session,&result,buffer,1024,
- alias_base,alias_scope,filter,alias_attrs,
- _nss_ldap_parse_alias);
- /* write the response */
- WRITE_INT32(fp,retv);
- if (retv==NSLCD_RESULT_SUCCESS)
- if (write_aliasent(fp,&result))
- return -1;
- /* we're done */
- return 0;
-}
+/* 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)
+#define ALIAS_NAME result.alias_name
+#define ALIAS_RCPTS result.alias_members
-int nslcd_alias_all(TFILE *fp,MYLDAP_SESSION *session)
+static int write_alias(TFILE *fp,MYLDAP_ENTRY *entry)
{
- int32_t tmpint32;
- struct ent_context context;
- /* these are here for now until we rewrite the LDAP code */
struct aliasent result;
char buffer[1024];
- int retv;
- /* log call */
- log_log(LOG_DEBUG,"nslcd_alias_all()");
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_ALIAS_ALL);
- /* initialize context */
- _nss_ldap_ent_context_init(&context,session);
- /* loop over all results */
- alias_init();
- while ((retv=_nss_ldap_getent(&context,&result,buffer,sizeof(buffer),
- alias_base,alias_scope,alias_filter,alias_attrs,
- _nss_ldap_parse_alias))==NSLCD_RESULT_SUCCESS)
- {
- /* write the result */
- WRITE_INT32(fp,retv);
- if (write_aliasent(fp,&result))
- return -1;
- }
- /* write the final result code */
- WRITE_INT32(fp,retv);
- /* FIXME: if a previous call returns what happens to the context? */
- _nss_ldap_ent_context_cleanup(&context);
- /* we're done */
+ int32_t tmpint32,tmp2int32;
+ if (_nss_ldap_parse_alias(entry,&result,buffer,sizeof(buffer))!=NSS_STATUS_SUCCESS)
+ return 0;
+ /* write the result code */
+ WRITE_INT32(fp,NSLCD_RESULT_SUCCESS);
+ /* write the entry */
+ NSLCD_ALIAS;
return 0;
}
+
+NSLCD_HANDLE(
+ alias,byname,
+ char name[256];
+ char filter[1024];
+ READ_STRING_BUF2(fp,name,sizeof(name));,
+ log_log(LOG_DEBUG,"nslcd_alias_byname(%s)",name);,
+ NSLCD_ACTION_ALIAS_BYNAME,
+ mkfilter_alias_byname(name,filter,sizeof(filter)),
+ write_alias(fp,entry)
+)
+
+NSLCD_HANDLE(
+ alias,all,
+ const char *filter;
+ /* no parameters to read */,
+ log_log(LOG_DEBUG,"nslcd_alias_all()");,
+ NSLCD_ACTION_ALIAS_ALL,
+ (filter=alias_filter,0),
+ write_alias(fp,entry)
+)
diff --git a/nslcd/common.h b/nslcd/common.h
index 280e292..3b83860 100644
--- a/nslcd/common.h
+++ b/nslcd/common.h
@@ -85,4 +85,42 @@ int nslcd_service_all(TFILE *fp,MYLDAP_SESSION *session);
int nslcd_shadow_byname(TFILE *fp,MYLDAP_SESSION *session);
int nslcd_shadow_all(TFILE *fp,MYLDAP_SESSION *session);
+/* macro for generating service handling code */
+#define NSLCD_HANDLE(db,fn,readfn,logcall,action,mkfilter,writefn) \
+ int nslcd_##db##_##fn(TFILE *fp,MYLDAP_SESSION *session) \
+ { \
+ /* define commong variables */ \
+ int32_t tmpint32; \
+ MYLDAP_SEARCH *search; \
+ MYLDAP_ENTRY *entry; \
+ /* read request parameters */ \
+ readfn; \
+ /* log call */ \
+ logcall; \
+ /* write the response header */ \
+ WRITE_INT32(fp,NSLCD_VERSION); \
+ WRITE_INT32(fp,action); \
+ /* prepare the search filter */ \
+ if (mkfilter) \
+ { \
+ log_log(LOG_WARNING,"nslcd_" __STRING(db) "_" __STRING(fn) "(): filter buffer too small"); \
+ return -1; \
+ } \
+ /* build the list of attributes */ \
+ db##_init(); \
+ /* do the LDAP search */ \
+ if ((search=myldap_search(session,db##_base,db##_scope,filter,db##_attrs))==NULL) \
+ return -1; \
+ /* go over results */ \
+ while ((entry=myldap_get_entry(search))!=NULL) \
+ { \
+ writefn; \
+ } \
+ /* write the final result code */ \
+ WRITE_INT32(fp,NSLCD_RESULT_NOTFOUND); \
+ /* we're done */ \
+ WRITE_FLUSH(fp); \
+ return 0; \
+ }
+
#endif /* not _SERVER_COMMON_H */
diff --git a/nslcd/ether.c b/nslcd/ether.c
index 01d19f4..648e851 100644
--- a/nslcd/ether.c
+++ b/nslcd/ether.c
@@ -57,6 +57,7 @@
#include "ldap-nss.h"
#include "common.h"
#include "log.h"
+#include "myldap.h"
#include "attmap.h"
#ifndef HAVE_STRUCT_ETHER_ADDR
@@ -140,130 +141,72 @@ static void ether_init(void)
ether_attrs[2]=NULL;
}
-/* macros for expanding the NSLCD_ETHER macro */
-#define NSLCD_STRING(field) WRITE_STRING(fp,field)
-#define NSLCD_TYPE(field,type) WRITE_TYPE(fp,field,type)
-#define ETHER_NAME result->e_name
-#define ETHER_ADDR result->e_addr
-
-static int write_ether(TFILE *fp,struct ether *result)
-{
- int32_t tmpint32;
- NSLCD_ETHER;
- return 0;
-}
-
static enum nss_status _nss_ldap_parse_ether(
- MYLDAP_SESSION *session,LDAPMessage *e,
- struct ldap_state UNUSED(*state),void *result,char *buffer,
+ MYLDAP_ENTRY *entry,
+ struct ether *ether,char *buffer,
size_t buflen)
{
- struct ether *ether=(struct ether *)result;
char *saddr;
enum nss_status stat;
struct ether_addr *addr;
- stat=_nss_ldap_assign_attrval(session,e,attmap_ether_cn,&ether->e_name,&buffer,&buflen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_ether_cn,&ether->e_name,&buffer,&buflen);
if (stat!=NSS_STATUS_SUCCESS)
return stat;
- stat=_nss_ldap_assign_attrval(session,e,attmap_ether_macAddress,&saddr,&buffer,&buflen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_ether_macAddress,&saddr,&buffer,&buflen);
if ((stat!=NSS_STATUS_SUCCESS)||((addr=ether_aton(saddr))==NULL))
return NSS_STATUS_NOTFOUND;
memcpy(&ether->e_addr,addr,sizeof(*addr));
return NSS_STATUS_SUCCESS;
}
-int nslcd_ether_byname(TFILE *fp,MYLDAP_SESSION *session)
+/* macros for expanding the NSLCD_ETHER macro */
+#define NSLCD_STRING(field) WRITE_STRING(fp,field)
+#define NSLCD_TYPE(field,type) WRITE_TYPE(fp,field,type)
+#define ETHER_NAME result.e_name
+#define ETHER_ADDR result.e_addr
+
+static int write_ether(TFILE *fp,MYLDAP_ENTRY *entry)
{
int32_t tmpint32;
- char name[256];
- char filter[1024];
- /* these are here for now until we rewrite the LDAP code */
struct ether result;
char buffer[1024];
- int retv;
- /* read request parameters */
- READ_STRING_BUF2(fp,name,sizeof(name));
- /* log call */
- log_log(LOG_DEBUG,"nslcd_ether_byname(%s)",name);
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_ETHER_BYNAME);
- /* do the LDAP request */
- mkfilter_ether_byname(name,filter,sizeof(filter));
- ether_init();
- retv=_nss_ldap_getbyname(session,&result,buffer,1024,
- ether_base,ether_scope,filter,ether_attrs,
- _nss_ldap_parse_ether);
- /* write the response */
- WRITE_INT32(fp,retv);
- if (retv==NSLCD_RESULT_SUCCESS)
- if (write_ether(fp,&result))
- return -1;
- /* we're done */
+ if (_nss_ldap_parse_ether(entry,&result,buffer,sizeof(buffer))!=NSS_STATUS_SUCCESS)
+ return 0;
+ /* write the result code */
+ WRITE_INT32(fp,NSLCD_RESULT_SUCCESS);
+ /* write the entry */
+ NSLCD_ETHER;
return 0;
}
-int nslcd_ether_byether(TFILE *fp,MYLDAP_SESSION *session)
-{
- int32_t tmpint32;
+NSLCD_HANDLE(
+ ether,byname,
+ char name[256];
+ char filter[1024];
+ READ_STRING_BUF2(fp,name,sizeof(name));,
+ log_log(LOG_DEBUG,"nslcd_ether_byname(%s)",name);,
+ NSLCD_ACTION_ETHER_BYNAME,
+ mkfilter_ether_byname(name,filter,sizeof(filter)),
+ write_ether(fp,entry)
+)
+
+NSLCD_HANDLE(
+ ether,byether,
struct ether_addr addr;
char filter[1024];
- /* these are here for now until we rewrite the LDAP code */
- struct ether result;
- char buffer[1024];
- int retv;
- /* read request parameters */
- READ_TYPE(fp,addr,u_int8_t[6]);
- /* log call */
- log_log(LOG_DEBUG,"nslcd_ether_byether(%s)",ether_ntoa(&addr));
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_ETHER_BYETHER);
- /* do the LDAP request */
- mkfilter_ether_byether(&addr,filter,sizeof(filter));
- ether_init();
- retv=_nss_ldap_getbyname(session,&result,buffer,1024,
- ether_base,ether_scope,filter,ether_attrs,
- _nss_ldap_parse_ether);
- /* write the response */
- WRITE_INT32(fp,retv);
- if (retv==NSLCD_RESULT_SUCCESS)
- if (write_ether(fp,&result))
- return -1;
- /* we're done */
- return 0;
-}
-
-int nslcd_ether_all(TFILE *fp,MYLDAP_SESSION *session)
-{
- int32_t tmpint32;
- struct ent_context context;
- /* these are here for now until we rewrite the LDAP code */
- struct ether result;
- char buffer[1024];
- int retv;
- /* log call */
- log_log(LOG_DEBUG,"nslcd_ether_all()");
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_ETHER_ALL);
- /* initialize context */
- _nss_ldap_ent_context_init(&context,session);
- /* loop over all results */
- ether_init();
- while ((retv=_nss_ldap_getent(&context,&result,buffer,sizeof(buffer),
- ether_base,ether_scope,ether_filter,ether_attrs,
- _nss_ldap_parse_ether))==NSLCD_RESULT_SUCCESS)
- {
- /* write the result */
- WRITE_INT32(fp,retv);
- if (write_ether(fp,&result))
- return -1;
- }
- /* write the final result code */
- WRITE_INT32(fp,retv);
- /* FIXME: if a previous call returns what happens to the context? */
- _nss_ldap_ent_context_cleanup(&context);
- /* we're done */
- return 0;
-}
+ READ_TYPE(fp,addr,u_int8_t[6]);,
+ log_log(LOG_DEBUG,"nslcd_ether_byether(%s)",ether_ntoa(&addr));,
+ NSLCD_ACTION_ETHER_BYETHER,
+ mkfilter_ether_byether(&addr,filter,sizeof(filter)),
+ write_ether(fp,entry)
+)
+
+NSLCD_HANDLE(
+ ether,all,
+ const char *filter;
+ /* no parameters to read */,
+ log_log(LOG_DEBUG,"nslcd_ether_all()");,
+ NSLCD_ACTION_ETHER_ALL,
+ (filter=ether_filter,0),
+ write_ether(fp,entry)
+)
diff --git a/nslcd/group.c b/nslcd/group.c
index fc4dc31..434c1c8 100644
--- a/nslcd/group.c
+++ b/nslcd/group.c
@@ -47,6 +47,7 @@
#include "ldap-nss.h"
#include "common.h"
#include "log.h"
+#include "myldap.h"
#include "cfg.h"
#include "attmap.h"
@@ -185,117 +186,51 @@ static void group_init(void)
/* group_attrs[4]=attmap_group_uniqueMember; */
}
-/* macros for expanding the NSLCD_GROUP macro */
-#define NSLCD_STRING(field) WRITE_STRING(fp,field)
-#define NSLCD_TYPE(field,type) WRITE_TYPE(fp,field,type)
-#define NSLCD_STRINGLIST(field) WRITE_STRINGLIST_NULLTERM(fp,field)
-#define GROUP_NAME result->gr_name
-#define GROUP_PASSWD result->gr_passwd
-#define GROUP_GID result->gr_gid
-#define GROUP_MEMBERS result->gr_mem
-
-static int write_group(TFILE *fp,struct group *result)
-{
- int32_t tmpint32,tmp2int32,tmp3int32;
- NSLCD_GROUP;
- return 0;
-}
-
static enum nss_status _nss_ldap_parse_gr(
- MYLDAP_SESSION *session,LDAPMessage *e,struct ldap_state UNUSED(*state),
- void *result,char *buffer,size_t buflen)
+ MYLDAP_ENTRY *entry,
+ struct group *gr,char *buffer,size_t buflen)
{
- struct group *gr=(struct group *)result;
char *gid;
enum nss_status stat;
/* get group gid (gidNumber) */
- stat=_nss_ldap_assign_attrval(session,e,attmap_group_gidNumber,&gid,&buffer,&buflen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_group_gidNumber,&gid,&buffer,&buflen);
if (stat != NSS_STATUS_SUCCESS)
return stat;
gr->gr_gid=(*gid=='\0')?(unsigned)GID_NOBODY:(gid_t)strtoul(gid,NULL,10);
/* get group name (cn) */
- stat=_nss_ldap_getrdnvalue(session,e,attmap_group_cn,&gr->gr_name,&buffer,&buflen);
+ stat=_nss_ldap_getrdnvalue(entry,attmap_group_cn,&gr->gr_name,&buffer,&buflen);
if (stat != NSS_STATUS_SUCCESS)
return stat;
/* get group passwd (userPassword) */
- stat=_nss_ldap_assign_userpassword(session,e,attmap_group_userPassword,&gr->gr_passwd,&buffer,&buflen);
+ stat=_nss_ldap_assign_userpassword(entry,attmap_group_userPassword,&gr->gr_passwd,&buffer,&buflen);
if (stat != NSS_STATUS_SUCCESS)
return stat;
/* get group memebers (memberUid) */
- stat=_nss_ldap_assign_attrvals(session,e,attmap_group_memberUid,NULL,
+ stat=_nss_ldap_assign_attrvals(entry,attmap_group_memberUid,NULL,
&gr->gr_mem,&buffer,&buflen,NULL);
return stat;
}
-int nslcd_group_byname(TFILE *fp,MYLDAP_SESSION *session)
-{
- int32_t tmpint32;
- char name[256];
- char filter[1024];
- /* these are here for now until we rewrite the LDAP code */
- struct group result;
- char buffer[1024];
- int retv;
- /* read request parameters */
- READ_STRING_BUF2(fp,name,sizeof(name));
- /* log call */
- log_log(LOG_DEBUG,"nslcd_group_byname(%s)",name);
- /* static buffer size check */
- if (1024<LDAP_NSS_BUFLEN_GROUP)
- {
- log_log(LOG_CRIT,"allocated buffer in nslcd_group_byname() too small");
- exit(EXIT_FAILURE);
- }
- /* do the LDAP request */
- mkfilter_group_byname(name,filter,sizeof(filter));
- group_init();
- retv=_nss_ldap_getbyname(session,&result,buffer,1024,
- group_base,group_scope,filter,group_attrs,
- _nss_ldap_parse_gr);
- /* write the response */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_GROUP_BYNAME);
- WRITE_INT32(fp,retv);
- if (retv==NSLCD_RESULT_SUCCESS)
- if (write_group(fp,&result))
- return -1;
- /* we're done */
- return 0;
-}
+/* macros for expanding the NSLCD_GROUP macro */
+#define NSLCD_STRING(field) WRITE_STRING(fp,field)
+#define NSLCD_TYPE(field,type) WRITE_TYPE(fp,field,type)
+#define NSLCD_STRINGLIST(field) WRITE_STRINGLIST_NULLTERM(fp,field)
+#define GROUP_NAME result.gr_name
+#define GROUP_PASSWD result.gr_passwd
+#define GROUP_GID result.gr_gid
+#define GROUP_MEMBERS result.gr_mem
-int nslcd_group_bygid(TFILE *fp,MYLDAP_SESSION *session)
+static int write_group(TFILE *fp,MYLDAP_ENTRY *entry)
{
- int32_t tmpint32;
- gid_t gid;
- char filter[1024];
- /* these are here for now until we rewrite the LDAP code */
+ int32_t tmpint32,tmp2int32,tmp3int32;
struct group result;
char buffer[1024];
- int retv;
- /* read request parameters */
- READ_TYPE(fp,gid,gid_t);
- /* log call */
- log_log(LOG_DEBUG,"nslcd_group_bygid(%d)",(int)gid);
- /* static buffer size check */
- if (1024<LDAP_NSS_BUFLEN_GROUP)
- {
- log_log(LOG_CRIT,"allocated buffer in nslcd_group_byname() too small");
- exit(EXIT_FAILURE);
- }
- /* do the LDAP request */
- mkfilter_group_bygid(gid,filter,sizeof(filter));
- group_init();
- retv=_nss_ldap_getbyname(session,&result,buffer,1024,
- group_base,group_scope,filter,
- group_attrs,_nss_ldap_parse_gr);
- /* write the response */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_GROUP_BYGID);
- WRITE_INT32(fp,retv);
- if (retv==NSLCD_RESULT_SUCCESS)
- if (write_group(fp,&result))
- return -1;
- /* we're done */
+ if (_nss_ldap_parse_gr(entry,&result,buffer,sizeof(buffer))!=NSS_STATUS_SUCCESS)
+ return 0;
+ /* write the result code */
+ WRITE_INT32(fp,NSLCD_RESULT_SUCCESS);
+ /* write the entry */
+ NSLCD_GROUP;
return 0;
}
@@ -353,36 +288,48 @@ int nslcd_group_bymember(TFILE *fp,MYLDAP_SESSION *session)
return 0;
}
-int nslcd_group_all(TFILE *fp,MYLDAP_SESSION *session)
-{
- int32_t tmpint32;
- struct ent_context context;
- /* these are here for now until we rewrite the LDAP code */
- struct group result;
- char buffer[1024];
- int retv;
- /* log call */
- log_log(LOG_DEBUG,"nslcd_group_all()");
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_GROUP_ALL);
- /* initialize context */
- _nss_ldap_ent_context_init(&context,session);
- /* loop over all results */
- group_init();
- while ((retv=_nss_ldap_getent(&context,&result,buffer,sizeof(buffer),
- group_base,group_scope,group_filter,group_attrs,
- _nss_ldap_parse_gr))==NSLCD_RESULT_SUCCESS)
- {
- /* write the result */
- WRITE_INT32(fp,retv);
- if (write_group(fp,&result))
- return -1;
- }
- /* write the final result code */
- WRITE_INT32(fp,retv);
- /* FIXME: if a previous call returns what happens to the context? */
- _nss_ldap_ent_context_cleanup(&context);
- /* we're done */
- return 0;
-}
+NSLCD_HANDLE(
+ group,byname,
+ char name[256];
+ char filter[1024];
+ READ_STRING_BUF2(fp,name,sizeof(name));,
+ log_log(LOG_DEBUG,"nslcd_group_byname(%s)",name);,
+ NSLCD_ACTION_GROUP_BYNAME,
+ mkfilter_group_byname(name,filter,sizeof(filter)),
+ write_group(fp,entry)
+)
+
+NSLCD_HANDLE(
+ group,bygid,
+ gid_t gid;
+ char filter[1024];
+ READ_TYPE(fp,gid,gid_t);,
+ log_log(LOG_DEBUG,"nslcd_group_bygid(%d)",(int)gid);,
+ NSLCD_ACTION_GROUP_BYGID,
+ mkfilter_group_bygid(gid,filter,sizeof(filter)),
+ write_group(fp,entry)
+)
+
+/*
+NSLCD_HANDLE(
+ group,bymember,
+ char name[256];
+ char filter[1024];
+ READ_STRING_BUF2(fp,name,sizeof(name)),
+ log_log(LOG_DEBUG,"nslcd_group_bymember(%s)",name);,
+ NSLCD_ACTION_GROUP_BYMEMBER,
+ mkfilter_group_bymember(name,filter,sizeof(filter)),
+ write_group(fp,entry)
+)
+*/
+
+NSLCD_HANDLE(
+ group,all,
+ const char *filter;
+ /* no parameters to read */,
+ log_log(LOG_DEBUG,"nslcd_group_all()");,
+ NSLCD_ACTION_GROUP_ALL,
+ (filter=group_filter,0),
+ write_group(fp,entry)
+)
+
diff --git a/nslcd/host.c b/nslcd/host.c
index a253608..cc119c1 100644
--- a/nslcd/host.c
+++ b/nslcd/host.c
@@ -126,35 +126,11 @@ static void host_init(void)
host_attrs[2]=NULL;
}
-/* write a single host entry to the stream */
-static int write_hostent(TFILE *fp,struct hostent *result)
-{
- int32_t tmpint32,tmp2int32,tmp3int32;
- int numaddr,i;
- /* write the host entry */
- WRITE_STRING(fp,result->h_name);
- /* write the alias list */
- WRITE_STRINGLIST_NULLTERM(fp,result->h_aliases);
- /* write the number of addresses */
- for (numaddr=0;result->h_addr_list[numaddr]!=NULL;numaddr++)
- /*noting*/ ;
- WRITE_INT32(fp,numaddr);
- /* write the addresses */
- for (i=0;i<numaddr;i++)
- {
- WRITE_INT32(fp,result->h_addrtype);
- WRITE_INT32(fp,result->h_length);
- WRITE(fp,result->h_addr_list[i],result->h_length);
- }
- return 0;
-}
-
static enum nss_status _nss_ldap_parse_host(
- MYLDAP_SESSION *session,LDAPMessage *e,struct ldap_state UNUSED(*state),
- void *result,char *buffer,size_t buflen)
+ MYLDAP_ENTRY *entry,
+ struct hostent *host,char *buffer,size_t buflen)
{
/* this code needs reviewing. XXX */
- struct hostent *host = (struct hostent *) result;
enum nss_status stat;
#ifdef INET6
char addressbuf[sizeof ("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255") *
@@ -171,20 +147,18 @@ static enum nss_status _nss_ldap_parse_host(
*addressbuf = *buffer = '\0';
- stat = _nss_ldap_assign_attrval (session,e, attmap_host_cn, &host->h_name,
- &buffer, &buflen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_host_cn,&host->h_name,
+ &buffer,&buflen);
if (stat != NSS_STATUS_SUCCESS)
return stat;
- stat =
- _nss_ldap_assign_attrvals (session,e, attmap_host_cn, host->h_name,
- &host->h_aliases, &buffer, &buflen, NULL);
+ stat=_nss_ldap_assign_attrvals(entry,attmap_host_cn,host->h_name,
+ &host->h_aliases,&buffer,&buflen,NULL);
if (stat != NSS_STATUS_SUCCESS)
return stat;
- stat =
- _nss_ldap_assign_attrvals (session,e, attmap_host_ipHostNumber, NULL, &addresses,
- &p_addressbuf, &addresslen, &addresscount);
+ stat=_nss_ldap_assign_attrvals(entry,attmap_host_ipHostNumber,NULL,&addresses,
+ &p_addressbuf,&addresslen,&addresscount);
if (stat != NSS_STATUS_SUCCESS)
return stat;
if (addresscount == 0)
@@ -290,116 +264,102 @@ static enum nss_status _nss_ldap_parse_host(
return NSS_STATUS_SUCCESS;
}
-int nslcd_host_byname(TFILE *fp,MYLDAP_SESSION *session)
+/* write a single host entry to the stream */
+static int write_host(TFILE *fp,MYLDAP_ENTRY *entry)
{
- int32_t tmpint32;
- char name[256];
- char filter[1024];
- int retv;
+ int32_t tmpint32,tmp2int32,tmp3int32;
+ int numaddr,i;
struct hostent result;
char buffer[1024];
- /* read request parameters */
- READ_STRING_BUF2(fp,name,sizeof(name));
- /* log call */
- log_log(LOG_DEBUG,"nslcd_host_byname(%s)",name);
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_HOST_BYNAME);
- /* do the LDAP request */
- mkfilter_host_byname(name,filter,sizeof(filter));
- host_init();
- retv=_nss_ldap_getbyname(session,&result,buffer,1024,
- host_base,host_scope,filter,host_attrs,
- _nss_ldap_parse_host);
- /* write the response */
- WRITE_INT32(fp,retv);
- if (retv==NSLCD_RESULT_SUCCESS)
- write_hostent(fp,&result);
- /* we're done */
+ if (_nss_ldap_parse_host(entry,&result,buffer,sizeof(buffer))!=NSS_STATUS_SUCCESS)
+ return 0;
+ /* write the result code */
+ WRITE_INT32(fp,NSLCD_RESULT_SUCCESS);
+ /* write the host entry */
+ WRITE_STRING(fp,result.h_name);
+ /* write the alias list */
+ WRITE_STRINGLIST_NULLTERM(fp,result.h_aliases);
+ /* write the number of addresses */
+ for (numaddr=0;result.h_addr_list[numaddr]!=NULL;numaddr++)
+ /*noting*/ ;
+ WRITE_INT32(fp,numaddr);
+ /* write the addresses */
+ for (i=0;i<numaddr;i++)
+ {
+ WRITE_INT32(fp,result.h_addrtype);
+ WRITE_INT32(fp,result.h_length);
+ WRITE(fp,result.h_addr_list[i],result.h_length);
+ }
return 0;
}
-int nslcd_host_byaddr(TFILE *fp,MYLDAP_SESSION *session)
+static int read_address(TFILE *fp,char *addr,int *addrlen,int *af)
{
int32_t tmpint32;
- int af;
int len;
- char addr[64],name[1024];
- char filter[1024];
- int retv;
- struct hostent result;
- char buffer[1024];
/* read address family */
- READ_INT32(fp,af);
- if ((af!=AF_INET)&&(af!=AF_INET6))
+ READ_INT32(fp,*af);
+ if ((*af!=AF_INET)&&(*af!=AF_INET6))
{
- log_log(LOG_WARNING,"incorrect address family specified: %d",af);
+ log_log(LOG_WARNING,"incorrect address family specified: %d",*af);
return -1;
}
/* read address length */
READ_INT32(fp,len);
- if ((len>64)||(len<=0))
+ if ((len>*addrlen)||(len<=0))
{
log_log(LOG_WARNING,"address length incorrect: %d",len);
return -1;
}
+ *addrlen=len;
/* read address */
READ(fp,addr,len);
- /* translate the address to a string */
- if (inet_ntop(af,addr,name,1024)==NULL)
- {
- log_log(LOG_WARNING,"unable to convert address to string");
- return -1;
- }
- /* log call */
- log_log(LOG_DEBUG,"nslcd_host_byaddr(%s)",name);
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_HOST_BYADDR);
- /* do the LDAP request */
- mkfilter_host_byaddr(name,filter,sizeof(filter));
- host_init();
- retv=_nss_ldap_getbyname(session,&result,buffer,1024,
- host_base,host_scope,filter,host_attrs,
- _nss_ldap_parse_host);
- /* write the response */
- WRITE_INT32(fp,retv);
- if (retv==NSLCD_RESULT_SUCCESS)
- write_hostent(fp,&result);
/* we're done */
return 0;
}
-int nslcd_host_all(TFILE *fp,MYLDAP_SESSION *session)
-{
- int32_t tmpint32;
- struct ent_context context;
- /* these are here for now until we rewrite the LDAP code */
- struct hostent result;
- char buffer[1024];
- int retv;
- /* log call */
- log_log(LOG_DEBUG,"nslcd_host_all()");
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_HOST_ALL);
- /* initialize context */
- _nss_ldap_ent_context_init(&context,session);
- /* loop over all results */
- host_init();
- while ((retv=_nss_ldap_getent(&context,&result,buffer,sizeof(buffer),
- host_base,host_scope,host_filter,host_attrs,
- _nss_ldap_parse_host))==NSLCD_RESULT_SUCCESS)
+#define READ_ADDRESS(fp,addr,len,af) \
+ len=(int)sizeof(addr); \
+ if (read_address(fp,addr,&(len),&(af))) \
+ return -1;
+
+NSLCD_HANDLE(
+ host,byname,
+ char name[256];
+ char filter[1024];
+ READ_STRING_BUF2(fp,name,sizeof(name));,
+ log_log(LOG_DEBUG,"nslcd_host_byname(%s)",name);,
+ NSLCD_ACTION_HOST_BYNAME,
+ mkfilter_host_byname(name,filter,sizeof(filter)),
+ write_host(fp,entry)
+)
+
+NSLCD_HANDLE(
+ host,byaddr,
+ int af;
+ char addr[64];
+ int len=sizeof(addr);
+ char name[1024];
+ char filter[1024];
+ READ_ADDRESS(fp,addr,len,af);
+ /* translate the address to a string */
+ if (inet_ntop(af,addr,name,sizeof(name))==NULL)
{
- /* write the result */
- WRITE_INT32(fp,retv);
- if (write_hostent(fp,&result))
- return -1;
- }
- /* write the final result code */
- WRITE_INT32(fp,retv);
- /* FIXME: if a previous call returns what happens to the context? */
- _nss_ldap_ent_context_cleanup(&context);
- /* we're done */
- return 0;
-}
+ log_log(LOG_WARNING,"unable to convert address to string");
+ return -1;
+ },
+ log_log(LOG_DEBUG,"nslcd_host_byaddr(%s)",name);,
+ NSLCD_ACTION_HOST_BYADDR,
+ mkfilter_host_byaddr(name,filter,sizeof(filter)),
+ write_host(fp,entry)
+)
+
+NSLCD_HANDLE(
+ host,all,
+ const char *filter;
+ /* no parameters to read */,
+ log_log(LOG_DEBUG,"nslcd_host_all()");,
+ NSLCD_ACTION_HOST_ALL,
+ (filter=host_filter,0),
+ write_host(fp,entry)
+)
diff --git a/nslcd/ldap-nss.c b/nslcd/ldap-nss.c
index 63c70b0..917fa21 100644
--- a/nslcd/ldap-nss.c
+++ b/nslcd/ldap-nss.c
@@ -894,13 +894,13 @@ static enum nss_status do_with_reconnect(
* Simple wrapper around ldap_get_values(). Requires that
* session is already established.
*/
-char **_nss_ldap_get_values(MYLDAP_SESSION *session,LDAPMessage *e,
+char **_nss_ldap_get_values(MYLDAP_ENTRY *entry,
const char *attr)
{
- if (!session->is_connected)
+ if (!entry->search->session->is_connected)
return NULL;
- assert(session->ls_conn!=NULL);
- return ldap_get_values(session->ls_conn,e,attr);
+ assert(entry->search->session->ls_conn!=NULL);
+ return ldap_get_values(entry->search->session->ls_conn,entry->msg,attr);
}
/* translates a nslcd return code (as defined in nslcd.h) to
@@ -1362,7 +1362,7 @@ int _nss_ldap_getbyname(MYLDAP_SESSION *session,void *result, char *buffer, size
{
MYLDAP_SEARCH *search;
MYLDAP_ENTRY *entry;
- enum nss_status stat = NSS_STATUS_NOTFOUND;
+ enum nss_status stat=NSS_STATUS_NOTFOUND;
/* do the search */
search=myldap_search(session,base,scope,filter,attrs);
if (search==NULL)
@@ -1400,8 +1400,8 @@ int _nss_ldap_getbyname(MYLDAP_SESSION *session,void *result, char *buffer, size
* Assign all values, bar omitvalue (if not NULL), to *valptr.
*/
enum nss_status _nss_ldap_assign_attrvals(
- MYLDAP_SESSION *session,
- LDAPMessage *e,const char *attr,const char *omitvalue,
+ MYLDAP_ENTRY *entry,
+ const char *attr,const char *omitvalue,
char ***valptr,char **pbuffer,size_t *pbuflen,size_t *pvalcount)
{
char **vals;
@@ -1415,10 +1415,10 @@ enum nss_status _nss_ldap_assign_attrvals(
if (pvalcount!=NULL)
*pvalcount=0;
- if (session->ls_conn==NULL)
+ if (entry->search->session->ls_conn==NULL)
return NSS_STATUS_UNAVAIL;
- vals=_nss_ldap_get_values(session,e,attr);
+ vals=_nss_ldap_get_values(entry,attr);
valcount=(vals==NULL)?0:ldap_count_values(vals);
if (bytesleft(buffer,buflen,char *)<(valcount+1)*sizeof(char *))
@@ -1485,14 +1485,14 @@ enum nss_status _nss_ldap_assign_attrvals(
/* Assign a single value to *valptr. */
enum nss_status _nss_ldap_assign_attrval(
- MYLDAP_SESSION *session,LDAPMessage *e,const char *attr,char **valptr,
+ MYLDAP_ENTRY *entry,const char *attr,char **valptr,
char **buffer,size_t *buflen)
{
char **vals;
int vallen;
- if (session->ls_conn==NULL)
+ if (entry->search->session->ls_conn==NULL)
return NSS_STATUS_UNAVAIL;
- vals=_nss_ldap_get_values(session,e,attr);
+ vals=_nss_ldap_get_values(entry,attr);
if (vals==NULL)
return NSS_STATUS_NOTFOUND;
vallen=strlen(*vals);
@@ -1561,17 +1561,17 @@ static const char *_nss_ldap_locate_userpassword(char **vals)
* a syntactically suitable value.
*/
enum nss_status _nss_ldap_assign_userpassword(
- MYLDAP_SESSION *session,
- LDAPMessage *e,const char *attr,char **valptr,
+ MYLDAP_ENTRY *entry,
+ const char *attr,char **valptr,
char **buffer,size_t *buflen)
{
char **vals;
const char *pwd;
int vallen;
log_log(LOG_DEBUG,"==> _nss_ldap_assign_userpassword");
- if (session->ls_conn==NULL)
+ if (entry->search->session->ls_conn==NULL)
return NSS_STATUS_UNAVAIL;
- vals=_nss_ldap_get_values(session,e,attr);
+ vals=_nss_ldap_get_values(entry,attr);
pwd=_nss_ldap_locate_userpassword(vals);
vallen=strlen(pwd);
if (*buflen<(size_t)(vallen+1))
@@ -1592,29 +1592,6 @@ enum nss_status _nss_ldap_assign_userpassword(
return NSS_STATUS_SUCCESS;
}
-int has_objectclass(MYLDAP_SESSION *session,LDAPMessage *entry,const char *objectclass)
-{
- char **vals;
- int i;
- LDAP *ld;
- ld=session->ls_conn;
- if (ld==NULL)
- return 0;
- vals=_nss_ldap_get_values(session,entry,"objectClass");
- if (vals==NULL)
- return 0;
- for (i=0;vals[i]!=NULL;i++)
- {
- if (strcasecmp(vals[i],objectclass)==0)
- {
- ldap_value_free(vals);
- return -1;
- }
- }
- ldap_value_free(vals);
- return 0;
-}
-
static enum nss_status do_getrdnvalue(
const char *dn,const char *rdntype,
char **rval,char **buffer,size_t *buflen)
@@ -1676,18 +1653,17 @@ static enum nss_status do_getrdnvalue(
}
enum nss_status _nss_ldap_getrdnvalue(
- MYLDAP_SESSION *session,LDAPMessage *entry,const char *rdntype,
+ MYLDAP_ENTRY *entry,const char *rdntype,
char **rval,char **buffer,size_t *buflen)
{
- char *dn;
+ const char *dn;
enum nss_status status;
size_t rdnlen;
- dn=ldap_get_dn(session->ls_conn,entry);
+ dn=myldap_get_dn(entry);
if (dn==NULL)
return NSS_STATUS_NOTFOUND;
status=do_getrdnvalue(dn,rdntype,rval,buffer,buflen);
- ldap_memfree(dn);
/*
* If examining the DN failed, then pick the nominal first
@@ -1697,7 +1673,7 @@ enum nss_status _nss_ldap_getrdnvalue(
if (status==NSS_STATUS_NOTFOUND)
{
char **vals;
- vals=_nss_ldap_get_values(session,entry,rdntype);
+ vals=_nss_ldap_get_values(entry,rdntype);
if (vals != NULL)
{
rdnlen = strlen (*vals);
diff --git a/nslcd/ldap-nss.h b/nslcd/ldap-nss.h
index 7039ba7..2c8a9db 100644
--- a/nslcd/ldap-nss.h
+++ b/nslcd/ldap-nss.h
@@ -136,11 +136,10 @@ int _nss_ldap_getbyname(
/* parsing utility functions */
-char **_nss_ldap_get_values(MYLDAP_SESSION *session,LDAPMessage *e,const char *attr);
+char **_nss_ldap_get_values(MYLDAP_ENTRY *entry,const char *attr);
enum nss_status _nss_ldap_assign_attrvals (
- MYLDAP_SESSION *session,
- LDAPMessage *e, /* IN */
+ MYLDAP_ENTRY *entry,
const char *attr, /* IN */
const char *omitvalue, /* IN */
char ***valptr, /* OUT */
@@ -149,31 +148,25 @@ enum nss_status _nss_ldap_assign_attrvals (
size_t * pvalcount /* OUT */ );
enum nss_status _nss_ldap_assign_attrval(
- MYLDAP_SESSION *session,
- LDAPMessage *e, /* IN */
+ 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_SESSION *session,
- LDAPMessage *e, /* IN */
+ MYLDAP_ENTRY *entry,
const char *attr, /* IN */
char **valptr, /* OUT */
char **buffer, /* IN/OUT */
size_t * buflen); /* IN/OUT */
-/* check that the entry has the specified objectclass
- return 0 for false, not-0 for true */
-int has_objectclass(MYLDAP_SESSION *session,LDAPMessage *entry,const char *objectclass);
-
/*
* get the RDN's value: eg. if the RDN was cn=lukeh, getrdnvalue(entry)
* would return lukeh.
*/
enum nss_status _nss_ldap_getrdnvalue(
- MYLDAP_SESSION *session,LDAPMessage *entry,const char *rdntype,
+ MYLDAP_ENTRY *entry,const char *rdntype,
char **rval,char **buffer,size_t * buflen);
#endif /* _LDAP_NSS_LDAP_LDAP_NSS_H */
diff --git a/nslcd/netgroup.c b/nslcd/netgroup.c
index d0bb331..5824c61 100644
--- a/nslcd/netgroup.c
+++ b/nslcd/netgroup.c
@@ -268,26 +268,25 @@ _nss_ldap_parse_netgr (void *vresultp, char *buffer, size_t buflen)
}
static enum nss_status _nss_ldap_load_netgr(
- MYLDAP_SESSION *session,LDAPMessage *e,struct ldap_state UNUSED(*state),
- void *vresultp,char UNUSED(*buffer),size_t UNUSED(buflen))
+ MYLDAP_ENTRY *entry,struct mynetgrent *result)
{
int attr;
int nvals;
int valcount = 0;
char **vals;
char **valiter;
- struct mynetgrent *result = vresultp;
enum nss_status stat = NSS_STATUS_SUCCESS;
+ /* FIXME: this function is wrong because it can segfault on some occasions */
for (attr = 0; attr < 2; attr++)
{
switch (attr)
{
case 1:
- vals=_nss_ldap_get_values(session,e,attmap_netgroup_nisNetgroupTriple);
+ vals=_nss_ldap_get_values(entry,attmap_netgroup_nisNetgroupTriple);
break;
default:
- vals=_nss_ldap_get_values(session,e,attmap_netgroup_memberNisNetgroup);
+ vals=_nss_ldap_get_values(entry,attmap_netgroup_memberNisNetgroup);
break;
}
@@ -334,31 +333,18 @@ out:
return stat;
}
-int nslcd_netgroup_byname(TFILE *fp,MYLDAP_SESSION *session)
+static int write_netgroup(TFILE *fp,MYLDAP_ENTRY *entry)
{
int32_t tmpint32;
- char name[256];
- char filter[1024];
- /* these are here for now until we rewrite the LDAP code */
struct mynetgrent result;
char buffer[1024];
enum nss_status stat=NSS_STATUS_SUCCESS;
- /* read request parameters */
- READ_STRING_BUF2(fp,name,sizeof(name));
- /* log call */
- log_log(LOG_DEBUG,"nslcd_netgroup_byname(%s)",name);
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_NETGROUP_BYNAME);
- /* initialize structure */
- result.data=result.cursor=NULL;
- result.data_size = 0;
- /* do initial ldap request */
- mkfilter_netgroup_byname(name,filter,sizeof(filter));
- netgroup_init();
- if (_nss_ldap_getbyname(session,&result,buffer,1024,
- netgroup_base,netgroup_scope,filter,netgroup_attrs,_nss_ldap_load_netgr))
- return -1;
+ result.data_size=0;
+ if (_nss_ldap_load_netgr(entry,&result)!=NSS_STATUS_SUCCESS)
+ return 0;
+ /* write the result code */
+ WRITE_INT32(fp,NSLCD_RESULT_SUCCESS);
+ /* write the entry */
/* loop over all results */
while ((stat=_nss_ldap_parse_netgr(&result,buffer,1024))==NSS_STATUS_SUCCESS)
{
@@ -389,8 +375,16 @@ int nslcd_netgroup_byname(TFILE *fp,MYLDAP_SESSION *session)
/* free data */
if (result.data!=NULL)
free(result.data);
- /* write the final result code */
- WRITE_INT32(fp,NSLCD_RESULT_NOTFOUND);
return 0;
}
+NSLCD_HANDLE(
+ netgroup,byname,
+ char name[256];
+ char filter[1024];
+ READ_STRING_BUF2(fp,name,sizeof(name));,
+ log_log(LOG_DEBUG,"nslcd_netgroup_byname(%s)",name);,
+ NSLCD_ACTION_NETGROUP_BYNAME,
+ mkfilter_netgroup_byname(name,filter,sizeof(filter)),
+ write_netgroup(fp,entry)
+)
diff --git a/nslcd/network.c b/nslcd/network.c
index e6d379f..7c44ea9 100644
--- a/nslcd/network.c
+++ b/nslcd/network.c
@@ -121,25 +121,8 @@ static void network_init(void)
network_attrs[2]=NULL;
}
-/* write a single network entry to the stream */
-static int write_netent(TFILE *fp,struct netent *result)
-{
- int32_t tmpint32,tmp2int32,tmp3int32;
- /* write the network name */
- WRITE_STRING(fp,result->n_name);
- /* write the alias list */
- WRITE_STRINGLIST_NULLTERM(fp,result->n_aliases);
- /* write the number of addresses */
- WRITE_INT32(fp,1);
- /* write the addresses in network byte order */
- WRITE_INT32(fp,result->n_addrtype);
- WRITE_INT32(fp,sizeof(unsigned long int));
- result->n_net=htonl(result->n_net);
- WRITE_INT32(fp,result->n_net);
- return 0;
-}
static enum nss_status _nss_ldap_parse_net(
- MYLDAP_SESSION *session,LDAPMessage *e,struct ldap_state UNUSED(*state),
+ MYLDAP_ENTRY *entry,
void *result,char *buffer,size_t buflen)
{
@@ -150,148 +133,115 @@ static enum nss_status _nss_ldap_parse_net(
/* IPv6 support ? XXX */
network->n_addrtype = AF_INET;
- stat=_nss_ldap_assign_attrval(session,e,attmap_network_cn,&network->n_name,&buffer,&buflen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_network_cn,&network->n_name,&buffer,&buflen);
if (stat!=NSS_STATUS_SUCCESS)
return stat;
- stat=_nss_ldap_assign_attrval(session,e,attmap_network_ipNetworkNumber,&tmp,&buffer,&buflen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_network_ipNetworkNumber,&tmp,&buffer,&buflen);
if (stat != NSS_STATUS_SUCCESS)
return stat;
network->n_net = inet_network (tmp);
- stat=_nss_ldap_assign_attrvals(session,e,attmap_network_cn,network->n_name,&network->n_aliases,&buffer,&buflen,NULL);
+ stat=_nss_ldap_assign_attrvals(entry,attmap_network_cn,network->n_name,&network->n_aliases,&buffer,&buflen,NULL);
if (stat != NSS_STATUS_SUCCESS)
return stat;
return NSS_STATUS_SUCCESS;
}
-int nslcd_network_byname(TFILE *fp,MYLDAP_SESSION *session)
+/* write a single network entry to the stream */
+static int write_network(TFILE *fp,MYLDAP_ENTRY *entry)
{
- int32_t tmpint32;
- char name[256];
- char filter[1024];
- int retv;
+ int32_t tmpint32,tmp2int32,tmp3int32;
struct netent result;
char buffer[1024];
- /* read request parameters */
- READ_STRING_BUF2(fp,name,sizeof(name));
- /* log call */
- log_log(LOG_DEBUG,"nslcd_network_byname(%s)",name);
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_NETWORK_BYNAME);
- /* do the LDAP request */
- mkfilter_network_byname(name,filter,sizeof(filter));
- network_init();
- retv=_nss_ldap_getbyname(session,&result,buffer,1024,
- network_base,network_scope,filter,network_attrs,
- _nss_ldap_parse_net);
- /* write the response */
- WRITE_INT32(fp,retv);
- if (retv==NSLCD_RESULT_SUCCESS)
- write_netent(fp,&result);
- /* we're done */
+ if (_nss_ldap_parse_net(entry,&result,buffer,sizeof(buffer))!=NSS_STATUS_SUCCESS)
+ return 0;
+ /* write the result code */
+ WRITE_INT32(fp,NSLCD_RESULT_SUCCESS);
+ /* write the entry */
+ /* write the network name */
+ WRITE_STRING(fp,result.n_name);
+ /* write the alias list */
+ WRITE_STRINGLIST_NULLTERM(fp,result.n_aliases);
+ /* write the number of addresses */
+ WRITE_INT32(fp,1);
+ /* write the addresses in network byte order */
+ WRITE_INT32(fp,result.n_addrtype);
+ WRITE_INT32(fp,sizeof(unsigned long int));
+ result.n_net=htonl(result.n_net);
+ WRITE_INT32(fp,result.n_net);
return 0;
}
-int nslcd_network_byaddr(TFILE *fp,MYLDAP_SESSION *session)
+static int read_address(TFILE *fp,char *addr,int *addrlen,int *af)
{
int32_t tmpint32;
- int af;
int len;
- char addr[64],name[1024];
- char filter[1024];
- int retv=456;
- struct netent result;
- char buffer[1024];
/* read address family */
- READ_INT32(fp,af);
- if (af!=AF_INET)
+ READ_INT32(fp,*af);
+ if (*af!=AF_INET)
{
- log_log(LOG_WARNING,"incorrect address family specified: %d",af);
+ log_log(LOG_WARNING,"incorrect address family specified: %d",*af);
return -1;
}
/* read address length */
READ_INT32(fp,len);
- if ((len>64)||(len<=0))
+ if ((len>*addrlen)||(len<=0))
{
log_log(LOG_WARNING,"address length incorrect: %d",len);
return -1;
}
+ *addrlen=len;
/* read address */
READ(fp,addr,len);
- /* translate the address to a string */
- if (inet_ntop(af,addr,name,1024)==NULL)
- {
- log_log(LOG_WARNING,"unable to convert address to string");
- return -1;
- }
- /* log call */
- log_log(LOG_DEBUG,"nslcd_network_byaddr(%s)",name);
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_NETWORK_BYADDR);
- /* do requests until we find a result */
- /* TODO: probably do more sofisticated queries */
- while (retv==456)
- {
- /* do the request */
- mkfilter_network_byaddr(name,filter,sizeof(filter));
- network_init();
- retv=_nss_ldap_getbyname(session,&result,buffer,1024,
- network_base,network_scope,filter,network_attrs,
- _nss_ldap_parse_net);
- /* if no entry was found, retry with .0 stripped from the end */
- if ((retv==NSLCD_RESULT_NOTFOUND) &&
- (strlen(name)>2) &&
- (strncmp(name+strlen(name)-2,".0",2)==0))
- {
- /* strip .0 and try again */
- name[strlen(name)-2]='\0';
- retv=456;
- }
- }
- /* write the response */
- WRITE_INT32(fp,retv);
- if (retv==NSLCD_RESULT_SUCCESS)
- if (write_netent(fp,&result))
- return -1;
/* we're done */
return 0;
}
-int nslcd_network_all(TFILE *fp,MYLDAP_SESSION *session)
-{
- int32_t tmpint32;
- struct ent_context context;
- /* these are here for now until we rewrite the LDAP code */
- struct netent result;
- char buffer[1024];
- int retv;
- /* log call */
- log_log(LOG_DEBUG,"nslcd_network_all()");
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_NETWORK_ALL);
- /* initialize context */
- _nss_ldap_ent_context_init(&context,session);
- /* loop over all results */
- network_init();
- while ((retv=_nss_ldap_getent(&context,&result,buffer,sizeof(buffer),
- network_base,network_scope,network_filter,network_attrs,
- _nss_ldap_parse_net))==NSLCD_RESULT_SUCCESS)
+#define READ_ADDRESS(fp,addr,len,af) \
+ len=(int)sizeof(addr); \
+ if (read_address(fp,addr,&(len),&(af))) \
+ return -1;
+
+NSLCD_HANDLE(
+ network,byname,
+ char name[256];
+ char filter[1024];
+ READ_STRING_BUF2(fp,name,sizeof(name));,
+ log_log(LOG_DEBUG,"nslcd_network_byname(%s)",name);,
+ NSLCD_ACTION_NETWORK_BYNAME,
+ mkfilter_network_byname(name,filter,sizeof(filter)),
+ write_network(fp,entry)
+)
+
+NSLCD_HANDLE(
+ network,byaddr,
+ int af;
+ char addr[64];
+ int len=sizeof(addr);
+ char name[1024];
+ char filter[1024];
+ READ_ADDRESS(fp,addr,len,af);
+ /* translate the address to a string */
+ if (inet_ntop(af,addr,name,sizeof(name))==NULL)
{
- /* write the result */
- WRITE_INT32(fp,retv);
- if (write_netent(fp,&result))
- return -1;
- }
- /* write the final result code */
- WRITE_INT32(fp,retv);
- /* FIXME: if a previous call returns what happens to the context? */
- _nss_ldap_ent_context_cleanup(&context);
- /* we're done */
- return 0;
-}
+ log_log(LOG_WARNING,"unable to convert address to string");
+ return -1;
+ },
+ log_log(LOG_DEBUG,"nslcd_network_byaddr(%s)",name);,
+ NSLCD_ACTION_NETWORK_BYADDR,
+ mkfilter_network_byaddr(name,filter,sizeof(filter)),
+ write_network(fp,entry)
+)
+
+NSLCD_HANDLE(
+ network,all,
+ const char *filter;
+ /* no parameters to read */,
+ log_log(LOG_DEBUG,"nslcd_network_all()");,
+ NSLCD_ACTION_NETWORK_ALL,
+ (filter=network_filter,0),
+ write_network(fp,entry)
+)
diff --git a/nslcd/passwd.c b/nslcd/passwd.c
index 9912022..f904e14 100644
--- a/nslcd/passwd.c
+++ b/nslcd/passwd.c
@@ -131,24 +131,6 @@ static void passwd_init(void)
passwd_attrs[9]=NULL;
}
-/* macros for expanding the NSLCD_PASSWD macro */
-#define NSLCD_STRING(field) WRITE_STRING(fp,field)
-#define NSLCD_TYPE(field,type) WRITE_TYPE(fp,field,type)
-#define PASSWD_NAME result->pw_name
-#define PASSWD_PASSWD result->pw_passwd
-#define PASSWD_UID result->pw_uid
-#define PASSWD_GID result->pw_gid
-#define PASSWD_GECOS result->pw_gecos
-#define PASSWD_DIR result->pw_dir
-#define PASSWD_SHELL result->pw_shell
-
-static int write_passwd(TFILE *fp,struct passwd *result)
-{
- int32_t tmpint32;
- NSLCD_PASSWD;
- return 0;
-}
-
static inline enum nss_status _nss_ldap_assign_emptystring(
char **valptr, char **buffer, size_t * buflen)
{
@@ -166,15 +148,14 @@ static inline enum nss_status _nss_ldap_assign_emptystring(
}
static enum nss_status _nss_ldap_parse_pw(
- MYLDAP_SESSION *session,LDAPMessage *e,struct ldap_state UNUSED(*state),
- void *result,char *buffer,size_t buflen)
+ MYLDAP_ENTRY *entry,
+ struct passwd *pw,char *buffer,size_t buflen)
{
/* FIXME: fix following problem:
if the entry has multiple uid fields we may end up
sending the wrong uid, we should return the requested
uid instead, otherwise write an entry for each uid
(maybe also for uidNumber) */
- struct passwd *pw=(struct passwd *)result;
char *uid, *gid;
enum nss_status stat;
char tmpbuf[ sizeof( uid_t ) * 8 / 3 + 2 ];
@@ -183,7 +164,7 @@ static enum nss_status _nss_ldap_parse_pw(
tmpbuf[ sizeof(tmpbuf) - 1 ] = '\0';
- if (has_objectclass(session,e,"shadowAccount"))
+ if (myldap_has_objectclass(entry,"shadowAccount"))
{
/* don't include password for shadowAccount */
if (buflen < 3)
@@ -196,140 +177,102 @@ static enum nss_status _nss_ldap_parse_pw(
}
else
{
- stat=_nss_ldap_assign_userpassword(session,e,attmap_passwd_userPassword,&pw->pw_passwd,&buffer,&buflen);
+ stat=_nss_ldap_assign_userpassword(entry,attmap_passwd_userPassword,&pw->pw_passwd,&buffer,&buflen);
if (stat != NSS_STATUS_SUCCESS)
return stat;
}
- stat=_nss_ldap_assign_attrval(session,e,attmap_passwd_uid,&pw->pw_name,&buffer,&buflen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_passwd_uid,&pw->pw_name,&buffer,&buflen);
if (stat != NSS_STATUS_SUCCESS)
return stat;
tmp = tmpbuf;
tmplen = sizeof (tmpbuf) - 1;
- stat=_nss_ldap_assign_attrval(session,e,attmap_passwd_uidNumber,&uid,&tmp,&tmplen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_passwd_uidNumber,&uid,&tmp,&tmplen);
if (stat != NSS_STATUS_SUCCESS)
return stat;
pw->pw_uid = (*uid == '\0') ? UID_NOBODY : (uid_t) atol (uid);
tmp = tmpbuf;
tmplen = sizeof (tmpbuf) - 1;
- stat=_nss_ldap_assign_attrval(session,e,attmap_passwd_gidNumber,&gid,&tmp,&tmplen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_passwd_gidNumber,&gid,&tmp,&tmplen);
if (stat != NSS_STATUS_SUCCESS)
return stat;
pw->pw_gid = (*gid == '\0') ? GID_NOBODY : (gid_t) atol (gid);
- stat=_nss_ldap_assign_attrval(session,e,attmap_passwd_gecos,&pw->pw_gecos,&buffer,&buflen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_passwd_gecos,&pw->pw_gecos,&buffer,&buflen);
if (stat != NSS_STATUS_SUCCESS)
{
pw->pw_gecos = NULL;
- stat=_nss_ldap_assign_attrval(session,e,attmap_passwd_cn,&pw->pw_gecos,&buffer,&buflen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_passwd_cn,&pw->pw_gecos,&buffer,&buflen);
if (stat != NSS_STATUS_SUCCESS)
return stat;
}
- stat=_nss_ldap_assign_attrval(session,e,attmap_passwd_homeDirectory,&pw->pw_dir,&buffer,&buflen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_passwd_homeDirectory,&pw->pw_dir,&buffer,&buflen);
if (stat != NSS_STATUS_SUCCESS)
(void) _nss_ldap_assign_emptystring (&pw->pw_dir, &buffer, &buflen);
- stat=_nss_ldap_assign_attrval(session,e,attmap_passwd_loginShell,&pw->pw_shell,&buffer,&buflen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_passwd_loginShell,&pw->pw_shell,&buffer,&buflen);
if (stat != NSS_STATUS_SUCCESS)
(void) _nss_ldap_assign_emptystring (&pw->pw_shell, &buffer, &buflen);
return NSS_STATUS_SUCCESS;
}
-/* the caller should take care of opening and closing the stream */
-int nslcd_passwd_byname(TFILE *fp,MYLDAP_SESSION *session)
+/* macros for expanding the NSLCD_PASSWD macro */
+#define NSLCD_STRING(field) WRITE_STRING(fp,field)
+#define NSLCD_TYPE(field,type) WRITE_TYPE(fp,field,type)
+#define PASSWD_NAME result.pw_name
+#define PASSWD_PASSWD result.pw_passwd
+#define PASSWD_UID result.pw_uid
+#define PASSWD_GID result.pw_gid
+#define PASSWD_GECOS result.pw_gecos
+#define PASSWD_DIR result.pw_dir
+#define PASSWD_SHELL result.pw_shell
+
+static int write_passwd(TFILE *fp,MYLDAP_ENTRY *entry)
{
int32_t tmpint32;
- char name[256];
- char filter[1024];
- /* these are here for now until we rewrite the LDAP code */
struct passwd result;
char buffer[1024];
- int retv;
- /* read request parameters */
- READ_STRING_BUF2(fp,name,sizeof(name));
- /* log call */
- log_log(LOG_DEBUG,"nslcd_passwd_byname(%s)",name);
- /* do the LDAP request */
- mkfilter_passwd_byname(name,filter,sizeof(filter));
- passwd_init();
- retv=_nss_ldap_getbyname(session,&result,buffer,1024,
- passwd_base,passwd_scope,filter,passwd_attrs,
- _nss_ldap_parse_pw);
- /* write the response */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_PASSWD_BYNAME);
- WRITE_INT32(fp,retv);
- if (retv==NSLCD_RESULT_SUCCESS)
- if (write_passwd(fp,&result))
- return -1;
- /* we're done */
+ if (_nss_ldap_parse_pw(entry,&result,buffer,sizeof(buffer))!=NSS_STATUS_SUCCESS)
+ return 0;
+ /* write the result code */
+ WRITE_INT32(fp,NSLCD_RESULT_SUCCESS);
+ /* write the entry */
+ NSLCD_PASSWD;
return 0;
}
-int nslcd_passwd_byuid(TFILE *fp,MYLDAP_SESSION *session)
-{
- int32_t tmpint32;
+NSLCD_HANDLE(
+ passwd,byname,
+ char name[256];
+ char filter[1024];
+ READ_STRING_BUF2(fp,name,sizeof(name));,
+ log_log(LOG_DEBUG,"nslcd_passwd_byname(%s)",name);,
+ NSLCD_ACTION_PASSWD_BYNAME,
+ mkfilter_passwd_byname(name,filter,sizeof(filter)),
+ write_passwd(fp,entry)
+)
+
+NSLCD_HANDLE(
+ passwd,byuid,
uid_t uid;
- /* these are here for now until we rewrite the LDAP code */
- struct passwd result;
- char buffer[1024];
char filter[1024];
- int retv;
- /* read request parameters */
- READ_TYPE(fp,uid,uid_t);
- /* log call */
- log_log(LOG_DEBUG,"nslcd_passwd_byuid(%d)",(int)uid);
- /* do the LDAP request */
- mkfilter_passwd_byuid(uid,filter,sizeof(filter));
- passwd_init();
- retv=_nss_ldap_getbyname(session,&result,buffer,1024,
- passwd_base,passwd_scope,filter,passwd_attrs,
- _nss_ldap_parse_pw);
- /* write the response */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_PASSWD_BYUID);
- WRITE_INT32(fp,retv);
- if (retv==NSLCD_RESULT_SUCCESS)
- if (write_passwd(fp,&result))
- return -1;
- /* we're done */
- return 0;
-}
-
-int nslcd_passwd_all(TFILE *fp,MYLDAP_SESSION *session)
-{
- int32_t tmpint32;
- struct ent_context context;
- /* these are here for now until we rewrite the LDAP code */
- struct passwd result;
- char buffer[1024];
- int retv;
- /* log call */
- log_log(LOG_DEBUG,"nslcd_passwd_all()");
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_PASSWD_ALL);
- /* initialize context */
- _nss_ldap_ent_context_init(&context,session);
- /* go over results */
- passwd_init();
- while ((retv=_nss_ldap_getent(&context,&result,buffer,sizeof(buffer),
- passwd_base,passwd_scope,passwd_filter,passwd_attrs,
- _nss_ldap_parse_pw))==NSLCD_RESULT_SUCCESS)
- {
- /* write the result */
- WRITE_INT32(fp,retv);
- if (write_passwd(fp,&result))
- return -1;
- }
- /* write the final result code */
- WRITE_INT32(fp,retv);
- /* FIXME: if some statement returns what happens to the context? */
- _nss_ldap_ent_context_cleanup(&context);
- /* we're done */
- return 0;
-}
+ READ_TYPE(fp,uid,uid_t);,
+ log_log(LOG_DEBUG,"nslcd_passwd_byuid(%d)",(int)uid);,
+ NSLCD_ACTION_PASSWD_BYUID,
+ mkfilter_passwd_byuid(uid,filter,sizeof(filter)),
+ write_passwd(fp,entry)
+)
+
+NSLCD_HANDLE(
+ passwd,all,
+ const char *filter;
+ /* no parameters to read */,
+ log_log(LOG_DEBUG,"nslcd_passwd_all()");,
+ NSLCD_ACTION_PASSWD_ALL,
+ (filter=passwd_filter,0),
+ write_passwd(fp,entry)
+)
diff --git a/nslcd/protocol.c b/nslcd/protocol.c
index fd67a0f..866284d 100644
--- a/nslcd/protocol.c
+++ b/nslcd/protocol.c
@@ -114,140 +114,80 @@ static void protocol_init(void)
protocol_attrs[2]=NULL;
}
-/* macros for expanding the NSLCD_PROTOCOL macro */
-#define NSLCD_STRING(field) WRITE_STRING(fp,field)
-#define NSLCD_STRINGLIST(field) WRITE_STRINGLIST_NULLTERM(fp,field)
-#define NSLCD_INT32(field) WRITE_INT32(fp,field)
-#define PROTOCOL_NAME result->p_name
-#define PROTOCOL_ALIASES result->p_aliases
-#define PROTOCOL_NUMBER result->p_proto
-
-static int write_protoent(TFILE *fp,struct protoent *result)
-{
- int32_t tmpint32,tmp2int32,tmp3int32;
- NSLCD_PROTOCOL;
- return 0;
-}
-
static enum nss_status _nss_ldap_parse_proto(
- MYLDAP_SESSION *session,LDAPMessage *e,struct ldap_state UNUSED(*state),
- void *result,char *buffer,size_t buflen)
+ MYLDAP_ENTRY *entry,
+ struct protoent *proto,char *buffer,size_t buflen)
{
-
- struct protoent *proto = (struct protoent *) result;
char *number;
enum nss_status stat;
- stat=_nss_ldap_getrdnvalue(session,e,attmap_protocol_cn,&proto->p_name,&buffer,&buflen);
+ stat=_nss_ldap_getrdnvalue(entry,attmap_protocol_cn,&proto->p_name,&buffer,&buflen);
if (stat != NSS_STATUS_SUCCESS)
return stat;
- stat=_nss_ldap_assign_attrval(session,e,attmap_protocol_ipProtocolNumber,&number,&buffer,&buflen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_protocol_ipProtocolNumber,&number,&buffer,&buflen);
if (stat != NSS_STATUS_SUCCESS)
return stat;
proto->p_proto = atoi (number);
- stat=_nss_ldap_assign_attrvals (session,e,attmap_protocol_cn,proto->p_name,&proto->p_aliases,&buffer,&buflen,NULL);
+ stat=_nss_ldap_assign_attrvals (entry,attmap_protocol_cn,proto->p_name,&proto->p_aliases,&buffer,&buflen,NULL);
if (stat != NSS_STATUS_SUCCESS)
return stat;
return NSS_STATUS_SUCCESS;
}
-int nslcd_protocol_byname(TFILE *fp,MYLDAP_SESSION *session)
+/* macros for expanding the NSLCD_PROTOCOL macro */
+#define NSLCD_STRING(field) WRITE_STRING(fp,field)
+#define NSLCD_STRINGLIST(field) WRITE_STRINGLIST_NULLTERM(fp,field)
+#define NSLCD_INT32(field) WRITE_INT32(fp,field)
+#define PROTOCOL_NAME result.p_name
+#define PROTOCOL_ALIASES result.p_aliases
+#define PROTOCOL_NUMBER result.p_proto
+
+static int write_protocol(TFILE *fp,MYLDAP_ENTRY *entry)
{
- int32_t tmpint32;
- char name[256];
- char filter[1024];
- /* these are here for now until we rewrite the LDAP code */
+ int32_t tmpint32,tmp2int32,tmp3int32;
struct protoent result;
char buffer[1024];
- int retv;
- /* read request parameters */
- READ_STRING_BUF2(fp,name,sizeof(name));
- /* log call */
- log_log(LOG_DEBUG,"nslcd_protocol_byname(%s)",name);
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_PROTOCOL_BYNAME);
- /* do the LDAP request */
- mkfilter_protocol_byname(name,filter,sizeof(filter));
- protocol_init();
- retv=_nss_ldap_getbyname(session,&result,buffer,1024,
- protocol_base,protocol_scope,filter,protocol_attrs,
- _nss_ldap_parse_proto);
- /* write the response */
- WRITE_INT32(fp,retv);
- if (retv==NSLCD_RESULT_SUCCESS)
- if (write_protoent(fp,&result))
- return -1;
- /* we're done */
+ if (_nss_ldap_parse_proto(entry,&result,buffer,sizeof(buffer))!=NSS_STATUS_SUCCESS)
+ return 0;
+ /* write the result code */
+ WRITE_INT32(fp,NSLCD_RESULT_SUCCESS);
+ /* write the entry */
+ NSLCD_PROTOCOL;
return 0;
}
-int nslcd_protocol_bynumber(TFILE *fp,MYLDAP_SESSION *session)
-{
- int32_t tmpint32;
+NSLCD_HANDLE(
+ protocol,byname,
+ char name[256];
+ char filter[1024];
+ READ_STRING_BUF2(fp,name,sizeof(name));,
+ log_log(LOG_DEBUG,"nslcd_protocol_byname(%s)",name);,
+ NSLCD_ACTION_PROTOCOL_BYNAME,
+ mkfilter_protocol_byname(name,filter,sizeof(filter)),
+ write_protocol(fp,entry)
+)
+
+NSLCD_HANDLE(
+ protocol,bynumber,
int protocol;
char filter[1024];
- /* these are here for now until we rewrite the LDAP code */
- struct protoent result;
- char buffer[1024];
- int retv;
- /* read request parameters */
- READ_INT32(fp,protocol);
- /* log call */
- log_log(LOG_DEBUG,"nslcd_protocol_bynumber(%d)",protocol);
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_PROTOCOL_BYNUMBER);
- /* do the LDAP request */
- mkfilter_protocol_bynumber(protocol,filter,sizeof(filter));
- protocol_init();
- retv=_nss_ldap_getbyname(session,&result,buffer,1024,
- protocol_base,protocol_scope,filter,protocol_attrs,
- _nss_ldap_parse_proto);
- /* write the response */
- WRITE_INT32(fp,retv);
- if (retv==NSLCD_RESULT_SUCCESS)
- if (write_protoent(fp,&result))
- return -1;
- /* we're done */
- return 0;
-}
-
-int nslcd_protocol_all(TFILE *fp,MYLDAP_SESSION *session)
-{
- int32_t tmpint32;
- struct ent_context context;
- /* these are here for now until we rewrite the LDAP code */
- struct protoent result;
- char buffer[1024];
- int retv;
- /* log call */
- log_log(LOG_DEBUG,"nslcd_protocol_all()");
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_PROTOCOL_ALL);
- /* initialize context */
- _nss_ldap_ent_context_init(&context,session);
- /* loop over all results */
- protocol_init();
- while ((retv=_nss_ldap_getent(&context,&result,buffer,sizeof(buffer),
- protocol_base,protocol_scope,protocol_filter,protocol_attrs,
- _nss_ldap_parse_proto))==NSLCD_RESULT_SUCCESS)
- {
- /* write the result code */
- WRITE_INT32(fp,retv);
- /* write the entry */
- if (write_protoent(fp,&result))
- return -1;
- }
- /* write the final result code */
- WRITE_INT32(fp,retv);
- /* FIXME: if a previous call returns what happens to the context? */
- _nss_ldap_ent_context_cleanup(&context);
- /* we're done */
- return 0;
-}
+ READ_INT32(fp,protocol);,
+ log_log(LOG_DEBUG,"nslcd_protocol_bynumber(%d)",protocol);,
+ NSLCD_ACTION_PROTOCOL_BYNUMBER,
+ mkfilter_protocol_bynumber(protocol,filter,sizeof(filter)),
+ write_protocol(fp,entry)
+)
+
+NSLCD_HANDLE(
+ protocol,all,
+ const char *filter;
+ /* no parameters to read */,
+ log_log(LOG_DEBUG,"nslcd_protocol_all()");,
+ NSLCD_ACTION_PROTOCOL_ALL,
+ (filter=protocol_filter,0),
+ write_protocol(fp,entry)
+)
diff --git a/nslcd/rpc.c b/nslcd/rpc.c
index 0fa4c8c..52b80c2 100644
--- a/nslcd/rpc.c
+++ b/nslcd/rpc.c
@@ -119,138 +119,81 @@ static void rpc_init(void)
rpc_attrs[2]=NULL;
}
-/* macros for expanding the NSLCD_RPC macro */
-#define NSLCD_STRING(field) WRITE_STRING(fp,field)
-#define NSLCD_STRINGLIST(field) WRITE_STRINGLIST_NULLTERM(fp,field)
-#define NSLCD_INT32(field) WRITE_INT32(fp,field)
-#define RPC_NAME result->r_name
-#define RPC_ALIASES result->r_aliases
-#define RPC_NUMBER result->r_number
-
-/* write a single rpc entry to the stream */
-static int write_rpcent(TFILE *fp,struct rpcent *result)
-{
- int32_t tmpint32,tmp2int32,tmp3int32;
- NSLCD_RPC;
- return 0;
-}
-
static enum nss_status _nss_ldap_parse_rpc(
- MYLDAP_SESSION *session,LDAPMessage *e,struct ldap_state UNUSED(*state),
- void *result,char *buffer,size_t buflen)
+ MYLDAP_ENTRY *entry,
+ struct rpcent *rpc,char *buffer,size_t buflen)
{
-
- struct rpcent *rpc = (struct rpcent *) result;
char *number;
enum nss_status stat;
- stat=_nss_ldap_getrdnvalue(session,e,attmap_rpc_cn,&rpc->r_name,&buffer,&buflen);
+ stat=_nss_ldap_getrdnvalue(entry,attmap_rpc_cn,&rpc->r_name,&buffer,&buflen);
if (stat != NSS_STATUS_SUCCESS)
return stat;
- stat=_nss_ldap_assign_attrval(session,e,attmap_rpc_oncRpcNumber,&number,&buffer,&buflen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_rpc_oncRpcNumber,&number,&buffer,&buflen);
if (stat != NSS_STATUS_SUCCESS)
return stat;
rpc->r_number = atol (number);
- stat=_nss_ldap_assign_attrvals(session,e,attmap_rpc_cn,rpc->r_name,&rpc->r_aliases,&buffer,&buflen,NULL);
+ stat=_nss_ldap_assign_attrvals(entry,attmap_rpc_cn,rpc->r_name,&rpc->r_aliases,&buffer,&buflen,NULL);
if (stat != NSS_STATUS_SUCCESS)
return stat;
return NSS_STATUS_SUCCESS;
}
-int nslcd_rpc_byname(TFILE *fp,MYLDAP_SESSION *session)
+/* macros for expanding the NSLCD_RPC macro */
+#define NSLCD_STRING(field) WRITE_STRING(fp,field)
+#define NSLCD_STRINGLIST(field) WRITE_STRINGLIST_NULLTERM(fp,field)
+#define NSLCD_INT32(field) WRITE_INT32(fp,field)
+#define RPC_NAME result.r_name
+#define RPC_ALIASES result.r_aliases
+#define RPC_NUMBER result.r_number
+
+/* write a single rpc entry to the stream */
+static int write_rpc(TFILE *fp,MYLDAP_ENTRY *entry)
{
- int32_t tmpint32;
- char name[256];
- char filter[1024];
- /* these are here for now until we rewrite the LDAP code */
+ int32_t tmpint32,tmp2int32,tmp3int32;
struct rpcent result;
char buffer[1024];
- int retv;
- /* read request parameters */
- READ_STRING_BUF2(fp,name,sizeof(name));
- /* log call */
- log_log(LOG_DEBUG,"nslcd_rpc_byname(%s)",name);
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_RPC_BYNAME);
- /* do the LDAP request */
- mkfilter_rpc_byname(name,filter,sizeof(filter));
- rpc_init();
- retv=_nss_ldap_getbyname(session,&result,buffer,1024,
- rpc_base,rpc_scope,filter,rpc_attrs,
- _nss_ldap_parse_rpc);
- /* write the response */
- WRITE_INT32(fp,retv);
- if (retv==NSLCD_RESULT_SUCCESS)
- write_rpcent(fp,&result);
- /* we're done */
+ if (_nss_ldap_parse_rpc(entry,&result,buffer,sizeof(buffer))!=NSS_STATUS_SUCCESS)
+ return 0;
+ /* write the result code */
+ WRITE_INT32(fp,NSLCD_RESULT_SUCCESS);
+ /* write the entry */
+ NSLCD_RPC;
return 0;
}
-int nslcd_rpc_bynumber(TFILE *fp,MYLDAP_SESSION *session)
-{
- int32_t tmpint32;
+NSLCD_HANDLE(
+ rpc,byname,
+ char name[256];
+ char filter[1024];
+ READ_STRING_BUF2(fp,name,sizeof(name));,
+ log_log(LOG_DEBUG,"nslcd_rpc_byname(%s)",name);,
+ NSLCD_ACTION_RPC_BYNAME,
+ mkfilter_rpc_byname(name,filter,sizeof(filter)),
+ write_rpc(fp,entry)
+)
+
+NSLCD_HANDLE(
+ rpc,bynumber,
int number;
char filter[1024];
- /* these are here for now until we rewrite the LDAP code */
- struct rpcent result;
- char buffer[1024];
- int retv;
- /* read request parameters */
- READ_INT32(fp,number);
- /* log call */
- log_log(LOG_DEBUG,"nslcd_rpc_bynumber(%d)",number);
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_RPC_BYNUMBER);
- /* do the LDAP request */
- mkfilter_rpc_bynumber(number,filter,sizeof(filter));
- rpc_init();
- retv=_nss_ldap_getbyname(session,&result,buffer,1024,
- rpc_base,rpc_scope,filter,rpc_attrs,
- _nss_ldap_parse_rpc);
- /* write the response */
- WRITE_INT32(fp,retv);
- if (retv==NSLCD_RESULT_SUCCESS)
- write_rpcent(fp,&result);
- /* we're done */
- return 0;
-}
-
-int nslcd_rpc_all(TFILE *fp,MYLDAP_SESSION *session)
-{
- int32_t tmpint32;
- struct ent_context context;
- /* these are here for now until we rewrite the LDAP code */
- struct rpcent result;
- char buffer[1024];
- int retv;
- /* log call */
- log_log(LOG_DEBUG,"nslcd_rpc_all()");
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_RPC_ALL);
- /* initialize context */
- _nss_ldap_ent_context_init(&context,session);
- /* loop over all results */
- rpc_init();
- while ((retv=_nss_ldap_getent(&context,&result,buffer,sizeof(buffer),
- rpc_base,rpc_scope,rpc_filter,rpc_attrs,
- _nss_ldap_parse_rpc))==NSLCD_RESULT_SUCCESS)
- {
- /* write the result code */
- WRITE_INT32(fp,retv);
- /* write the entry */
- write_rpcent(fp,&result);
- }
- /* write the final result code */
- WRITE_INT32(fp,retv);
- /* FIXME: if a previous call returns what happens to the context? */
- _nss_ldap_ent_context_cleanup(&context);
- /* we're done */
- return 0;
-}
+ READ_INT32(fp,number);,
+ log_log(LOG_DEBUG,"nslcd_rpc_bynumber(%d)",number);,
+ NSLCD_ACTION_RPC_BYNUMBER,
+ mkfilter_rpc_bynumber(number,filter,sizeof(filter)),
+ write_rpc(fp,entry)
+)
+
+NSLCD_HANDLE(
+ rpc,all,
+ const char *filter;
+ /* no parameters to read */,
+ log_log(LOG_DEBUG,"nslcd_rpc_all()");,
+ NSLCD_ACTION_RPC_ALL,
+ (filter=rpc_filter,0),
+ write_rpc(fp,entry)
+)
diff --git a/nslcd/service.c b/nslcd/service.c
index 71fc28d..b68c5f9 100644
--- a/nslcd/service.c
+++ b/nslcd/service.c
@@ -146,27 +146,10 @@ static void service_init(void)
service_attrs[3]=NULL;
}
-/* macros for expanding the NSLCD_SERVICE macro */
-#define NSLCD_STRING(field) WRITE_STRING(fp,field)
-#define NSLCD_STRINGLIST(field) WRITE_STRINGLIST_NULLTERM(fp,field)
-#define NSLCD_INT32(field) WRITE_INT32(fp,field)
-#define SERVICE_NAME result->s_name
-#define SERVICE_ALIASES result->s_aliases
-#define SERVICE_NUMBER htons(result->s_port)
-#define SERVICE_PROTOCOL result->s_proto
-
-static int write_servent(TFILE *fp,struct servent *result)
-{
- int32_t tmpint32,tmp2int32,tmp3int32;
- NSLCD_SERVICE;
- return 0;
-}
-
static enum nss_status _nss_ldap_parse_serv(
- MYLDAP_SESSION *session,LDAPMessage *e,struct ldap_state *state,
- void *result,char *buffer,size_t buflen)
+ MYLDAP_ENTRY *entry,const char *protocol,
+ struct servent *service,char *buffer,size_t buflen)
{
- struct servent *service = (struct servent *)result;
char *port;
enum nss_status stat = NSS_STATUS_SUCCESS;
@@ -175,196 +158,118 @@ static enum nss_status _nss_ldap_parse_serv(
* ipServiceProtocol fields.
*/
- if (state->ls_type==LS_TYPE_KEY)
+ if ((protocol!=NULL)&&(*protocol!='\0'))
{
- if (state->ls_info.ls_key == NULL)
- {
- /* non-deterministic behaviour is ok */
- stat=_nss_ldap_assign_attrval(session,e,attmap_service_ipServiceProtocol,&service->s_proto,&buffer,&buflen);
- if (stat != NSS_STATUS_SUCCESS)
- {
- return stat;
- }
- }
- else
- {
register int len;
- len = strlen (state->ls_info.ls_key);
+ len = strlen (protocol);
if (buflen < (size_t) (len + 1))
{
return NSS_STATUS_TRYAGAIN;
}
- strncpy (buffer, state->ls_info.ls_key, len);
+ strncpy (buffer, protocol, len);
buffer[len] = '\0';
service->s_proto = buffer;
buffer += len + 1;
buflen -= len + 1;
- }
}
else
{
- char **vals=_nss_ldap_get_values(session,e,attmap_service_ipServiceProtocol);
+ char **vals=_nss_ldap_get_values(entry,attmap_service_ipServiceProtocol);
int len;
if (vals == NULL)
{
- state->ls_info.ls_index = -1;
return NSS_STATUS_NOTFOUND;
}
+ /* FIXME: write an antry for each protocol */
- switch (state->ls_info.ls_index)
- {
- case 0:
- /* last time. decrementing ls_index to -1 AND returning !NSS_STATUS_SUCCESS
- will force this entry to be discarded.
- */
- stat = NSS_STATUS_NOTFOUND;
- break;
- case -1:
- /* first time */
- state->ls_info.ls_index = ldap_count_values (vals);
- /* fall off to default ... */
- default:
- len = strlen (vals[state->ls_info.ls_index - 1]);
- if (buflen < (size_t) (len + 1))
- {
- return NSS_STATUS_TRYAGAIN;
- }
- strncpy (buffer, vals[state->ls_info.ls_index - 1], len);
+ len = strlen (vals[0]);
+ strncpy (buffer, vals[0], len);
buffer[len] = '\0';
service->s_proto = buffer;
buffer += len + 1;
buflen -= len + 1;
- stat = NSS_STATUS_SUCCESS;
- }
ldap_value_free (vals);
- state->ls_info.ls_index--;
- }
-
- if (stat != NSS_STATUS_SUCCESS)
- {
- return stat;
}
- stat=_nss_ldap_getrdnvalue(session,e,attmap_service_cn,&service->s_name,&buffer,&buflen);
+ stat=_nss_ldap_getrdnvalue(entry,attmap_service_cn,&service->s_name,&buffer,&buflen);
if (stat != NSS_STATUS_SUCCESS)
{
return stat;
}
- stat=_nss_ldap_assign_attrvals(session,e,attmap_service_cn,service->s_name,&service->s_aliases,&buffer,&buflen,NULL);
+ stat=_nss_ldap_assign_attrvals(entry,attmap_service_cn,service->s_name,&service->s_aliases,&buffer,&buflen,NULL);
if (stat != NSS_STATUS_SUCCESS)
{
return stat;
}
- stat=_nss_ldap_assign_attrval(session,e,attmap_service_ipServicePort,&port,&buffer,&buflen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_service_ipServicePort,&port,&buffer,&buflen);
if (stat != NSS_STATUS_SUCCESS)
{
return stat;
}
- service->s_port = htons (atoi (port));
+ service->s_port = atoi(port);
return NSS_STATUS_SUCCESS;
}
-int nslcd_service_byname(TFILE *fp,MYLDAP_SESSION *session)
+/* macros for expanding the NSLCD_SERVICE macro */
+#define NSLCD_STRING(field) WRITE_STRING(fp,field)
+#define NSLCD_STRINGLIST(field) WRITE_STRINGLIST_NULLTERM(fp,field)
+#define NSLCD_INT32(field) WRITE_INT32(fp,field)
+#define SERVICE_NAME result.s_name
+#define SERVICE_ALIASES result.s_aliases
+#define SERVICE_NUMBER result.s_port
+#define SERVICE_PROTOCOL result.s_proto
+
+static int write_service(TFILE *fp,MYLDAP_ENTRY *entry,const char *protocol)
{
- int32_t tmpint32;
- char name[256],protocol[256];
- char filter[1024];
- /* these are here for now until we rewrite the LDAP code */
+ int32_t tmpint32,tmp2int32,tmp3int32;
struct servent result;
char buffer[1024];
- int retv;
- /* read request parameters */
- READ_STRING_BUF2(fp,name,sizeof(name));
- READ_STRING_BUF2(fp,protocol,sizeof(protocol));
- /* log call */
- log_log(LOG_DEBUG,"nslcd_service_byname(%s,%s)",name,protocol);
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_SERVICE_BYNAME);
- /* do the LDAP request */
- mkfilter_service_byname(name,protocol,filter,sizeof(filter));
- service_init();
- retv=_nss_ldap_getbyname(session,&result,buffer,1024,
- service_base,service_scope,filter,service_attrs,
- _nss_ldap_parse_serv);
- /* write the response */
- WRITE_INT32(fp,retv);
- if (retv==NSLCD_RESULT_SUCCESS)
- if (write_servent(fp,&result))
- return -1;
- /* we're done */
+ if (_nss_ldap_parse_serv(entry,protocol,&result,buffer,sizeof(buffer))!=NSS_STATUS_SUCCESS)
+ return 0;
+ /* write the result code */
+ WRITE_INT32(fp,NSLCD_RESULT_SUCCESS);
+ /* write the entry */
+ NSLCD_SERVICE;
return 0;
}
-int nslcd_service_bynumber(TFILE *fp,MYLDAP_SESSION *session)
-{
- int32_t tmpint32;
+NSLCD_HANDLE(
+ service,byname,
+ char name[256];
+ char protocol[256];
+ char filter[1024];
+ READ_STRING_BUF2(fp,name,sizeof(name));
+ READ_STRING_BUF2(fp,protocol,sizeof(protocol));,
+ log_log(LOG_DEBUG,"nslcd_service_byname(%s,%s)",name,protocol);,
+ NSLCD_ACTION_SERVICE_BYNAME,
+ mkfilter_service_byname(name,protocol,filter,sizeof(filter)),
+ write_service(fp,entry,protocol)
+)
+
+NSLCD_HANDLE(
+ service,bynumber,
int number;
char protocol[256];
char filter[1024];
- /* these are here for now until we rewrite the LDAP code */
- struct servent result;
- char buffer[1024];
- int retv;
- /* read request parameters */
READ_INT32(fp,number);
- READ_STRING_BUF2(fp,protocol,sizeof(protocol));
- /* log call */
- log_log(LOG_DEBUG,"nslcd_service_bynumber(%d,%s)",number,protocol);
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_SERVICE_BYNUMBER);
- /* do the LDAP request */
- mkfilter_service_bynumber(number,protocol,filter,sizeof(filter));
- service_init();
- retv=_nss_ldap_getbyname(session,&result,buffer,1024,
- service_base,service_scope,filter,service_attrs,
- _nss_ldap_parse_serv);
- /* write the response */
- WRITE_INT32(fp,retv);
- if (retv==NSLCD_RESULT_SUCCESS)
- if (write_servent(fp,&result))
- return -1;
- /* we're done */
- return 0;
-}
-
-int nslcd_service_all(TFILE *fp,MYLDAP_SESSION *session)
-{
- int32_t tmpint32;
- struct ent_context context;
- /* these are here for now until we rewrite the LDAP code */
- struct servent result;
- char buffer[1024];
- int retv;
- /* log call */
- log_log(LOG_DEBUG,"nslcd_service_all()");
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_SERVICE_ALL);
- /* initialize context */
- _nss_ldap_ent_context_init(&context,session);
- /* loop over all results */
- service_init();
- while ((retv=_nss_ldap_getent(&context,&result,buffer,sizeof(buffer),
- service_base,service_scope,service_filter,service_attrs,
- _nss_ldap_parse_serv))==NSLCD_RESULT_SUCCESS)
- {
- /* write the result code */
- WRITE_INT32(fp,retv);
- /* write the entry */
- if (write_servent(fp,&result))
- return -1;
- }
- /* write the final result code */
- WRITE_INT32(fp,retv);
- /* FIXME: if a previous call returns what happens to the context? */
- _nss_ldap_ent_context_cleanup(&context);
- /* we're done */
- return 0;
-}
+ READ_STRING_BUF2(fp,protocol,sizeof(protocol));,
+ log_log(LOG_DEBUG,"nslcd_service_bynumber(%d,%s)",number,protocol);,
+ NSLCD_ACTION_SERVICE_BYNUMBER,
+ mkfilter_service_bynumber(number,protocol,filter,sizeof(filter)),
+ write_service(fp,entry,protocol)
+)
+
+NSLCD_HANDLE(
+ service,all,
+ const char *filter;
+ /* no parameters to read */,
+ log_log(LOG_DEBUG,"nslcd_service_all()");,
+ NSLCD_ACTION_SERVICE_ALL,
+ (filter=service_filter,0),
+ write_service(fp,entry,NULL)
+)
diff --git a/nslcd/shadow.c b/nslcd/shadow.c
index 82335a9..0ea42b4 100644
--- a/nslcd/shadow.c
+++ b/nslcd/shadow.c
@@ -115,26 +115,6 @@ static void shadow_init(void)
shadow_attrs[9]=NULL;
}
-/* macros for expanding the NSLCD_SHADOW macro */
-#define NSLCD_STRING(field) WRITE_STRING(fp,field)
-#define NSLCD_INT32(field) WRITE_INT32(fp,field)
-#define SHADOW_NAME result->sp_namp
-#define SHADOW_PASSWD result->sp_pwdp
-#define SHADOW_LASTCHANGE result->sp_lstchg
-#define SHADOW_MINDAYS result->sp_min
-#define SHADOW_MAXDAYS result->sp_max
-#define SHADOW_WARN result->sp_warn
-#define SHADOW_INACT result->sp_inact
-#define SHADOW_EXPIRE result->sp_expire
-#define SHADOW_FLAG result->sp_flag
-
-static int write_spwd(TFILE *fp,struct spwd *result)
-{
- int32_t tmpint32;
- NSLCD_SHADOW;
- return 0;
-}
-
static int
_nss_ldap_shadow_date (const char *val)
{
@@ -169,40 +149,39 @@ _nss_ldap_shadow_handle_flag (struct spwd *sp)
}
static enum nss_status _nss_ldap_parse_sp(
- MYLDAP_SESSION *session,LDAPMessage *e,struct ldap_state UNUSED(*state),
- void *result,char *buffer,size_t buflen)
+ MYLDAP_ENTRY *entry,
+ struct spwd *sp,char *buffer,size_t buflen)
{
- struct spwd *sp = (struct spwd *) result;
enum nss_status stat;
char *tmp = NULL;
- stat=_nss_ldap_assign_userpassword(session,e,attmap_shadow_userPassword,&sp->sp_pwdp,&buffer,&buflen);
+ stat=_nss_ldap_assign_userpassword(entry,attmap_shadow_userPassword,&sp->sp_pwdp,&buffer,&buflen);
if (stat != NSS_STATUS_SUCCESS)
return stat;
- stat=_nss_ldap_assign_attrval(session,e,attmap_shadow_uid,&sp->sp_namp,&buffer,&buflen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_shadow_uid,&sp->sp_namp,&buffer,&buflen);
if (stat != NSS_STATUS_SUCCESS)
return stat;
- stat=_nss_ldap_assign_attrval(session,e,attmap_shadow_shadowLastChange,&tmp,&buffer,&buflen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_shadow_shadowLastChange,&tmp,&buffer,&buflen);
sp->sp_lstchg = (stat == NSS_STATUS_SUCCESS) ? _nss_ldap_shadow_date (tmp) : -1;
- stat=_nss_ldap_assign_attrval(session,e,attmap_shadow_shadowMax,&tmp,&buffer,&buflen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_shadow_shadowMax,&tmp,&buffer,&buflen);
sp->sp_max = (stat == NSS_STATUS_SUCCESS) ? atol (tmp) : -1;
- stat=_nss_ldap_assign_attrval(session,e,attmap_shadow_shadowMin,&tmp,&buffer,&buflen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_shadow_shadowMin,&tmp,&buffer,&buflen);
sp->sp_min = (stat == NSS_STATUS_SUCCESS) ? atol (tmp) : -1;
- stat=_nss_ldap_assign_attrval(session,e,attmap_shadow_shadowWarning,&tmp,&buffer,&buflen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_shadow_shadowWarning,&tmp,&buffer,&buflen);
sp->sp_warn = (stat == NSS_STATUS_SUCCESS) ? atol (tmp) : -1;
- stat=_nss_ldap_assign_attrval(session,e,attmap_shadow_shadowInactive,&tmp,&buffer,&buflen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_shadow_shadowInactive,&tmp,&buffer,&buflen);
sp->sp_inact = (stat == NSS_STATUS_SUCCESS) ? atol (tmp) : -1;
- stat=_nss_ldap_assign_attrval(session,e,attmap_shadow_shadowExpire,&tmp,&buffer,&buflen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_shadow_shadowExpire,&tmp,&buffer,&buflen);
sp->sp_expire = (stat == NSS_STATUS_SUCCESS) ? _nss_ldap_shadow_date (tmp) : -1;
- stat=_nss_ldap_assign_attrval(session,e,attmap_shadow_shadowFlag,&tmp,&buffer,&buflen);
+ stat=_nss_ldap_assign_attrval(entry,attmap_shadow_shadowFlag,&tmp,&buffer,&buflen);
sp->sp_flag = (stat == NSS_STATUS_SUCCESS) ? atol (tmp) : 0;
_nss_ldap_shadow_handle_flag(sp);
@@ -210,66 +189,50 @@ static enum nss_status _nss_ldap_parse_sp(
return NSS_STATUS_SUCCESS;
}
-int nslcd_shadow_byname(TFILE *fp,MYLDAP_SESSION *session)
+/* macros for expanding the NSLCD_SHADOW macro */
+#define NSLCD_STRING(field) WRITE_STRING(fp,field)
+#define NSLCD_INT32(field) WRITE_INT32(fp,field)
+#define SHADOW_NAME result.sp_namp
+#define SHADOW_PASSWD result.sp_pwdp
+#define SHADOW_LASTCHANGE result.sp_lstchg
+#define SHADOW_MINDAYS result.sp_min
+#define SHADOW_MAXDAYS result.sp_max
+#define SHADOW_WARN result.sp_warn
+#define SHADOW_INACT result.sp_inact
+#define SHADOW_EXPIRE result.sp_expire
+#define SHADOW_FLAG result.sp_flag
+
+static int write_shadow(TFILE *fp,MYLDAP_ENTRY *entry)
{
int32_t tmpint32;
- char name[256];
- char filter[1024];
- int retv;
struct spwd result;
char buffer[1024];
- /* read request parameters */
- READ_STRING_BUF2(fp,name,sizeof(name));
- /* log call */
- log_log(LOG_DEBUG,"nslcd_shadow_byname(%s)",name);
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_SHADOW_BYNAME);
- /* do the LDAP request */
- mkfilter_shadow_byname(name,filter,sizeof(filter));
- shadow_init();
- retv=_nss_ldap_getbyname(session,&result,buffer,1024,
- shadow_base,shadow_scope,filter,shadow_attrs,
- _nss_ldap_parse_sp);
- /* write the response */
- WRITE_INT32(fp,retv);
- if (retv==NSLCD_RESULT_SUCCESS)
- if (write_spwd(fp,&result))
- return -1;
- /* we're done */
+ if (_nss_ldap_parse_sp(entry,&result,buffer,sizeof(buffer))!=NSS_STATUS_SUCCESS)
+ return 0;
+ /* write the result code */
+ WRITE_INT32(fp,NSLCD_RESULT_SUCCESS);
+ /* write the entry */
+ NSLCD_SHADOW;
return 0;
}
-int nslcd_shadow_all(TFILE *fp,MYLDAP_SESSION *session)
-{
- int32_t tmpint32;
- struct ent_context context;
- /* these are here for now until we rewrite the LDAP code */
- struct spwd result;
- char buffer[1024];
- int retv;
- /* log call */
- log_log(LOG_DEBUG,"nslcd_shadow_all()");
- /* write the response header */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,NSLCD_ACTION_SHADOW_ALL);
- /* initialize context */
- _nss_ldap_ent_context_init(&context,session);
- /* loop over all results */
- shadow_init();
- while ((retv=_nss_ldap_getent(&context,&result,buffer,sizeof(buffer),
- shadow_base,shadow_scope,shadow_filter,shadow_attrs,
- _nss_ldap_parse_sp))==NSLCD_RESULT_SUCCESS)
- {
- /* write the result */
- WRITE_INT32(fp,retv);
- if (write_spwd(fp,&result))
- return -1;
- }
- /* write the final result code */
- WRITE_INT32(fp,retv);
- /* FIXME: if a previous call returns what happens to the context? */
- _nss_ldap_ent_context_cleanup(&context);
- /* we're done */
- return 0;
-}
+NSLCD_HANDLE(
+ shadow,byname,
+ char name[256];
+ char filter[1024];
+ READ_STRING_BUF2(fp,name,sizeof(name));,
+ log_log(LOG_DEBUG,"nslcd_shadow_byname(%s)",name);,
+ NSLCD_ACTION_SHADOW_BYNAME,
+ mkfilter_shadow_byname(name,filter,sizeof(filter)),
+ write_shadow(fp,entry)
+)
+
+NSLCD_HANDLE(
+ shadow,all,
+ const char *filter;
+ /* no parameters to read */,
+ log_log(LOG_DEBUG,"nslcd_shadow_all()");,
+ NSLCD_ACTION_SHADOW_ALL,
+ (filter=shadow_filter,0),
+ write_shadow(fp,entry)
+)