summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2006-10-31 12:17:39 +0000
committerArthur de Jong <arthur@arthurdejong.org>2006-10-31 12:17:39 +0000
commitfe8fb00dd57714528535de7e3a8d42f64e7a79aa (patch)
treee8642fbc016b084f6db00950bfb4e6e0d8da784d
parent93bda65a159e1f03b934fcb7050a5e1fba9bb2b7 (diff)
clear up protocol macros while implementing getpwuid() and {set,get,end}pwent() functions (last not yet on NSS side)
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/libnss_ldapd@34 ef36b2f9-881f-0410-afb5-c4e39611909c
-rw-r--r--nslcd-client.c51
-rw-r--r--nslcd-client.h30
-rw-r--r--nslcd-server.c53
-rw-r--r--nslcd-server.h46
-rw-r--r--nslcd.h2
-rw-r--r--nss/Makefile.am1
-rw-r--r--nss/common.c1
-rw-r--r--nss/common.h68
-rw-r--r--nss/passwd.c36
-rw-r--r--server/common.h16
-rw-r--r--server/passwd.c124
-rw-r--r--testnss.c33
12 files changed, 244 insertions, 217 deletions
diff --git a/nslcd-client.c b/nslcd-client.c
index fd4cdb1..c5ac9f9 100644
--- a/nslcd-client.c
+++ b/nslcd-client.c
@@ -60,54 +60,3 @@ FILE *nslcd_client_open()
/* return the stream */
return fp;
}
-
-
-/* helper marco for writes, bails out on any write problems */
-#define WRITE(fp,buf,count) \
- if (fwrite(buf,1,count,fp)<1) \
- { return -1; }
-
-
-/* helper macro for writing 32-bit integer values, uses tmpint32 as
- temporary value (should be defined by caller) */
-#define WRITE_INT32(fp,i) \
- tmpint32=(int32_t)(i); \
- WRITE(fp,&tmpint32,sizeof(int32_t))
-
-
-/* write a request message, returns <0 in case of errors */
-int nslcd_client_writerequest(FILE *fp,int type,const char *name,size_t count)
-{
- int32_t tmpint32;
- /* see nslcd.h for protocol definition */
- WRITE_INT32(fp,NSLCD_VERSION);
- WRITE_INT32(fp,type);
- WRITE_INT32(fp,count);
- WRITE(fp,name,count);
- if (fflush(fp)<0)
- return -1;
- return 0; /* success */
-}
-
-/* read a response message, return a NSLCD_RS_* status,
- this function does not close stream on error,
- stream status is undetermined */
-int nslcd_client_readresponse(FILE *fp,int type)
-{
- int32_t tmp;
- /* read the protocol version */
- if (fread(&tmp,sizeof(int32_t),1,fp)<1)
- return -1;
- if (tmp != NSLCD_VERSION)
- return -1;
- /* read the original request type */
- if (fread(&tmp,sizeof(int32_t),1,fp)<1)
- return -1;
- if (tmp != type)
- return -1;
- /* read the response code */
- if (fread(&tmp,sizeof(int32_t),1,fp)<1)
- return -1;
- /* TODO: check that we have a valid code */
- return tmp;
-}
diff --git a/nslcd-client.h b/nslcd-client.h
index 1e5d46d..ca9273b 100644
--- a/nslcd-client.h
+++ b/nslcd-client.h
@@ -26,18 +26,32 @@
#include <stdio.h>
#include "nslcd.h"
-
-/* Extra request results. */
-#define NSLCD_RS_SMALLBUF 100 /* buffer too small */
+#include "nslcd-common.h"
/* returns a socket to the server or NULL on error (see errno),
socket should be closed with fclose() */
FILE *nslcd_client_open(void);
-/* write a request message, returns <0 in case of errors */
-int nslcd_client_writerequest(FILE *fp,int type,const char *name,size_t count);
-
-/* read a response message, return a NSLCD_RS_* status */
-int nslcd_client_readresponse(FILE *fp,int type);
+/* open a client socket */
+#define OPEN_SOCK(fp) \
+ if ((fp=nslcd_client_open())==NULL) \
+ { ERROR_OUT_OPENERROR }
+
+#define WRITE_REQUEST(fp,req) \
+ WRITE_INT32(fp,NSLCD_VERSION) \
+ WRITE_INT32(fp,req)
+
+#define READ_RESPONSEHEADER(fp,req) \
+ READ_TYPE(fp,tmpint32,int32_t); \
+ if (tmpint32!=NSLCD_VERSION) \
+ { ERROR_OUT_READERROR(fp) } \
+ READ_TYPE(fp,tmpint32,int32_t); \
+ if (tmpint32!=(req)) \
+ { ERROR_OUT_READERROR(fp) }
+
+#define READ_RESPONSE(fp) \
+ READ_TYPE(fp,tmpint32,int32_t); \
+ if (tmpint32!=NSLCD_RS_SUCCESS) \
+ { ERROR_OUT_NOSUCCESS(fp,tmpint32) }
#endif /* not _NSLCD_CLIENT_H */
diff --git a/nslcd-server.c b/nslcd-server.c
index b78db33..ff3f7b9 100644
--- a/nslcd-server.c
+++ b/nslcd-server.c
@@ -116,53 +116,46 @@ int nslcd_server_open(void)
return sock;
}
+/* redifine the ERROR_OUT mechanism */
+#undef ERROR_OUT_READERROR
+#define ERROR_OUT_READERROR(fp) \
+ fclose(fp); \
+ log_log(LOG_DEBUG,"error reading from stream: %s",strerror(errno)); \
+ return;
+
/* read a request message, returns <0 in case of errors,
this function closes the socket */
-int nslcd_server_handlerequest(int sock)
+void nslcd_server_handlerequest(int sock)
{
- int32_t tmpint32, tmp2, type;
- size_t sz;
- char *key;
+ int32_t tmpint32;
FILE *fp;
/* create a stream object */
if ((fp=fdopen(sock,"w+"))==NULL)
{
close(sock);
- return -1;
+ return;
}
/* read the protocol version */
- READ_INT32(fp,tmp2);
- if (tmp2 != NSLCD_VERSION)
+ READ_TYPE(fp,tmpint32,int32_t);
+ if (tmpint32 != NSLCD_VERSION)
{
fclose(fp);
- log_log(LOG_DEBUG,"wrong nslcd version id (%d)", tmp2);
- return -1;
+ log_log(LOG_DEBUG,"wrong nslcd version id (%d)",(int)tmpint32);
+ return;
}
/* read the request type */
- READ_INT32(fp,type);
- /* read the request key */
- /* TODO: probably move this to the request specific function */
- READ_INT32(fp,sz);
- key=(char *)malloc(sz+1);
- if (key==NULL)
- return -1; /* FIXME: report memory allocation errors */
- READ(fp,key,sz);
- key[sz]=0;
- /* log request */
- log_log(LOG_DEBUG,"request id=%d key=%s",(int)type,key);
+ READ_TYPE(fp,tmpint32,int32_t);
/* handle request */
- switch (type)
+ switch (tmpint32)
{
- case NSLCD_RT_GETPWBYNAME:
- log_log(LOG_DEBUG,"GETPWBYNAME(%s)",key);
- nslcd_getpwnam(fp,key);
- break;
+ case NSLCD_RT_GETPWBYNAME: nslcd_getpwnam(fp); break;
+ case NSLCD_RT_GETPWBYUID: nslcd_getpwuid(fp); break;
+ case NSLCD_RT_GETPWALL: nslcd_getpwall(fp); break;
default:
- return -1;
+ log_log(LOG_DEBUG,"invalid request id (%d)",(int)tmpint32);
+ break;
}
-
+ /* we're done with the request */
fclose(fp);
-
- return 0; /* success */
-
+ return;
}
diff --git a/nslcd-server.h b/nslcd-server.h
index f872d4f..5a1ca6f 100644
--- a/nslcd-server.h
+++ b/nslcd-server.h
@@ -24,6 +24,7 @@
#define _NSLCD_SERVER_H 1
#include "nslcd.h"
+#include "nslcd-common.h"
/* returns a socket ready to answer requests from the client,
return <0 on error */
@@ -31,49 +32,18 @@ int nslcd_server_open(void);
/* read a request message, returns <0 in case of errors,
this function closes the socket */
-int nslcd_server_handlerequest(int sock);
+void nslcd_server_handlerequest(int sock);
/* LDAP methods */
+/* TODO: these definitions should probably be moved */
/* the caller should take care of opening and closing the stream */
-int nslcd_getpwnam(FILE *fp,const char *name);
+int nslcd_getpwnam(FILE *fp);
-#define WRITE(fp,ptr,size) \
- if (fwrite(ptr,size,1,fp)<1) \
- { fclose(fp); return -1; }
-
-#define WRITE_INT32(fp,i) \
- tmpint32=(int32_t)(i); \
- WRITE(fp,&tmpint32,sizeof(int32_t))
-
-#define WRITE_STRING(fp,str) \
- /* write the size of the string */ \
- WRITE_INT32(fp,strlen(str)); \
- /* write the string itself */ \
- WRITE(fp,str,strlen(str));
-
-#define READ(fp,ptr,size) \
- if (fread(ptr,size,1,fp)<1) \
- { fclose(fp); return -1; }
+/* the caller should take care of opening and closing the stream */
+int nslcd_getpwuid(FILE *fp);
-#define READ_INT32(fp,i) \
- READ(fp,&tmpint32,sizeof(int32_t)); \
- i=tmpint32;
-
-#define READ_STRING(fp,field,buffer) \
- /* read the size of the string */ \
- READ(fp,&sz,sizeof(int32_t)); \
- /* FIXME: add error checking and sanity checking */ \
- /* check if read would fit */ \
- if ((bufptr+(size_t)sz+1)>buflen) \
- { fclose(fp); return -1; } /* will not fit */ \
- /* read string from the stream */ \
- READ(fp,buffer+bufptr,(size_t)sz); \
- /* TODO: check that string does not contain \0 */ \
- /* null-terminate string in buffer */ \
- buffer[bufptr+sz]='\0'; \
- /* prepare result */ \
- (field)=buffer+bufptr; \
- bufptr+=sz+1;
+/* the caller should take care of opening and closing the stream */
+int nslcd_getpwall(FILE *fp);
#endif /* not _NSLCD_SERVER_H */
diff --git a/nslcd.h b/nslcd.h
index c2d4b05..36ab2ae 100644
--- a/nslcd.h
+++ b/nslcd.h
@@ -125,7 +125,7 @@
/* Request types. */
#define NSLCD_RT_GETPWBYNAME 1001
#define NSLCD_RT_GETPWBYUID 1002
-#define NSLCD_RT_GETPWDALL 1004
+#define NSLCD_RT_GETPWALL 1004
#define NSLCD_RT_GETGRBYNAME 2003
#define NSLCD_RT_GETGRBYGID 2004
#define NSLCD_RT_GETHOSTBYNAME 3005
diff --git a/nss/Makefile.am b/nss/Makefile.am
index 56cc77c..0b63c31 100644
--- a/nss/Makefile.am
+++ b/nss/Makefile.am
@@ -21,4 +21,5 @@
noinst_LIBRARIES = libnss.a
libnss_a_SOURCES = common.c common.h exports.h ../nslcd-client.h \
+ ../nslcd.h ../nslcd-common.h \
passwd.c aliases.c
diff --git a/nss/common.c b/nss/common.c
index 4aa1878..9bf1eb6 100644
--- a/nss/common.c
+++ b/nss/common.c
@@ -13,7 +13,6 @@ enum nss_status nslcd2nss(int code)
case NSLCD_RS_UNAVAIL: return NSS_STATUS_UNAVAIL;
case NSLCD_RS_NOTFOUND: return NSS_STATUS_NOTFOUND;
case NSLCD_RS_SUCCESS: return NSS_STATUS_SUCCESS;
- case NSLCD_RS_SMALLBUF: return NSS_STATUS_TRYAGAIN;
default: return NSS_STATUS_UNAVAIL;
}
}
diff --git a/nss/common.h b/nss/common.h
index 1b14f96..3129eee 100644
--- a/nss/common.h
+++ b/nss/common.h
@@ -5,47 +5,27 @@
a nss code (as defined in nss.h) */
enum nss_status nslcd2nss(int code);
-/* Macros for reading and writing to sockets. */
-
-/* open a client socket */
-#define OPEN_SOCK(fp) \
- if ((fp=nslcd_client_open())==NULL) \
- { \
- *errnop=errno; \
- return NSS_STATUS_UNAVAIL; \
- }
-
-/* bail out of the function with the nss status and errno set,
- closing the socket */
-#define ERROR_OUT(fp,status,errnoval) \
- { \
- fclose(fp); \
- *errnop=errnoval; \
- return (status); \
- }
-
-/* read a buffer from the stream */
-#define READ(fp,ptr,size) \
- if (fread(ptr,size,1,fp)<1) \
- ERROR_OUT(fp,NSS_STATUS_UNAVAIL,ENOENT);
-
-/* read a string (lengt,buffer) from the stream, nul-terminating the string */
-#define LDF_STRING(field) \
- /* read the size of the string */ \
- READ(fp,&sz,sizeof(int32_t)); \
- /* FIXME: add error checking and sanity checking */ \
- /* check if read would fit */ \
- if ((bufptr+(size_t)sz+1)>buflen) \
- ERROR_OUT(fp,NSS_STATUS_TRYAGAIN,ERANGE); /* will not fit */ \
- /* read string from the stream */ \
- READ(fp,buffer+bufptr,(size_t)sz); \
- /* TODO: check that string does not contain \0 */ \
- /* null-terminate string in buffer */ \
- buffer[bufptr+sz]='\0'; \
- /* prepare result */ \
- (field)=buffer+bufptr; \
- bufptr+=sz+1;
-
-/* read a typed value from the stream */
-#define LDF_TYPE(field,type) \
- READ(fp,&(field),sizeof(type))
+/* macros for handling read and write problems, they are
+ NSS specific due to the return codes */
+
+#define ERROR_OUT_OPENERROR \
+ *errnop=errno; \
+ return NSS_STATUS_UNAVAIL;
+
+#define ERROR_OUT_READERROR(fp) \
+ fclose(fp); \
+ *errnop=ENOENT; \
+ return NSS_STATUS_UNAVAIL; \
+
+#define ERROR_OUT_BUFERROR(fp) \
+ fclose(fp); \
+ *errnop=ERANGE; \
+ return NSS_STATUS_TRYAGAIN; \
+
+#define ERROR_OUT_WRITEERROR(fp) \
+ ERROR_OUT_READERROR(fp)
+
+#define ERROR_OUT_NOSUCCESS(fp,retv) \
+ fclose(fp); \
+ *errnop=ENOENT; \
+ return nslcd2nss(retv);
diff --git a/nss/passwd.c b/nss/passwd.c
index 763dc6f..cf118bd 100644
--- a/nss/passwd.c
+++ b/nss/passwd.c
@@ -29,6 +29,8 @@
#include "common.h"
/* Macros for expanding the LDF_PASSWD macro. */
+#define LDF_STRING(field) READ_STRING_BUF(fp,field)
+#define LDF_TYPE(field,type) READ_TYPE(fp,field,type)
#define PASSWD_NAME result->pw_name
#define PASSWD_PASSWD result->pw_passwd
#define PASSWD_UID result->pw_uid
@@ -41,16 +43,16 @@ enum nss_status _nss_ldap_getpwnam_r(const char *name,struct passwd *result,char
{
FILE *fp;
size_t bufptr=0;
- int32_t sz;
- /* open socket */
+ int32_t tmpint32;
+ /* open socket and write request */
OPEN_SOCK(fp);
- /* write request to nslcd */
- if (nslcd_client_writerequest(fp,NSLCD_RT_GETPWBYNAME,name,strlen(name)))
- ERROR_OUT(fp,NSS_STATUS_UNAVAIL,ENOENT);
+ WRITE_REQUEST(fp,NSLCD_RT_GETPWBYNAME);
+ WRITE_STRING(fp,name);
+ WRITE_FLUSH(fp);
/* read response header */
- if ((sz=nslcd_client_readresponse(fp,NSLCD_RT_GETPWBYNAME))!=NSLCD_RS_SUCCESS)
- ERROR_OUT(fp,nslcd2nss(sz),ENOENT);
- /* read struct passwd */
+ READ_RESPONSEHEADER(fp,NSLCD_RT_GETPWBYNAME);
+ /* read response */
+ READ_RESPONSE(fp);
LDF_PASSWD;
/* close socket and we're done */
fclose(fp);
@@ -59,8 +61,22 @@ enum nss_status _nss_ldap_getpwnam_r(const char *name,struct passwd *result,char
enum nss_status _nss_ldap_getpwuid_r(uid_t uid,struct passwd *result,char *buffer,size_t buflen,int *errnop)
{
- *errnop=ENOENT;
- return NSS_STATUS_UNAVAIL;
+ FILE *fp;
+ size_t bufptr=0;
+ int32_t tmpint32;
+ /* open socket and write request */
+ OPEN_SOCK(fp);
+ WRITE_REQUEST(fp,NSLCD_RT_GETPWBYUID);
+ WRITE_TYPE(fp,uid,uid_t);
+ WRITE_FLUSH(fp);
+ /* read response header */
+ READ_RESPONSEHEADER(fp,NSLCD_RT_GETPWBYUID);
+ /* read response */
+ READ_RESPONSE(fp);
+ LDF_PASSWD;
+ /* close socket and we're done */
+ fclose(fp);
+ return NSS_STATUS_SUCCESS;
}
enum nss_status _nss_ldap_setpwent(void)
diff --git a/server/common.h b/server/common.h
index 9d21b11..d0218f9 100644
--- a/server/common.h
+++ b/server/common.h
@@ -24,10 +24,26 @@
#define _SERVER_COMMON_H 1
#include <nss.h>
+#include "nslcd-common.h"
/* translates a nss code (as defined in nss.h) to a
nslcd return code (as defined in nslcd.h) */
/* FIXME: this is a temporary hack, get rid of it */
int nss2nslcd(enum nss_status code);
+
+/* macros for basic read and write operations, the following
+ ERROR_OUT* marcos define the action taken on errors */
+
+#define ERROR_OUT_WRITEERROR(fp) \
+ fclose(fp); \
+ return -1;
+
+#define ERROR_OUT_READERROR(fp) \
+ fclose(fp); \
+ return -1;
+
+#define ERROR_OUT_ALLOCERROR(fp) \
+ ERROR_OUT_READERROR(fp)
+
#endif /* not _SERVER_COMMON_H */
diff --git a/server/passwd.c b/server/passwd.c
index 48a83cc..c34f717 100644
--- a/server/passwd.c
+++ b/server/passwd.c
@@ -45,6 +45,7 @@
#include "util.h"
#include "nslcd-server.h"
#include "common.h"
+#include "log.h"
static struct ent_context *pw_context = NULL;
@@ -188,7 +189,7 @@ static enum nss_status _nss_ldap_parse_pw (LDAPMessage * e,
#define LDF_TYPE(field,type) \
WRITE(fp,&(field),sizeof(type))
-enum nss_status _nss_ldap_getpwnam_r(const char *name,
+static enum nss_status _nss_ldap_getpwnam_r(const char *name,
struct passwd *result,
char *buffer,size_t buflen,int *errnop)
{
@@ -196,50 +197,121 @@ enum nss_status _nss_ldap_getpwnam_r(const char *name,
LM_PASSWD, _nss_ldap_parse_pw, LDAP_NSS_BUFLEN_DEFAULT);
}
+static enum nss_status _nss_ldap_getpwuid_r(uid_t uid,
+ struct passwd *result,
+ char *buffer,size_t buflen,int *errnop)
+{
+ LOOKUP_NUMBER (uid, result, buffer, buflen, errnop, _nss_ldap_filt_getpwuid,
+ LM_PASSWD, _nss_ldap_parse_pw, LDAP_NSS_BUFLEN_DEFAULT);
+}
+
+static enum nss_status _nss_ldap_setpwent(void)
+{
+ LOOKUP_SETENT (pw_context);
+}
+
+static enum nss_status _nss_ldap_getpwent_r(struct passwd *result,
+ char *buffer,size_t buflen,int *errnop)
+{
+ LOOKUP_GETENT (pw_context, result, buffer, buflen, errnop,
+ _nss_ldap_filt_getpwent, LM_PASSWD, _nss_ldap_parse_pw,
+ LDAP_NSS_BUFLEN_DEFAULT);
+}
+
+static enum nss_status _nss_ldap_endpwent(void)
+{
+ LOOKUP_ENDENT (pw_context);
+}
+
/* the caller should take care of opening and closing the stream */
-int nslcd_getpwnam(FILE *fp,const char *name)
+int nslcd_getpwnam(FILE *fp)
{
int32_t tmpint32;
+ char *name;
/* these are here for now until we rewrite the LDAP code */
struct passwd result;
char buffer[1024];
int errnop;
int retv;
+ /* read request parameters */
+ READ_STRING_ALLOC(fp,name);
+ /* FIXME: free() this buffer somewhere */
+ /* log call */
+ log_log(LOG_DEBUG,"nslcd_getpwnam(%s)",name);
/* do the LDAP request */
retv=nss2nslcd(_nss_ldap_getpwnam_r(name,&result,buffer,1024,&errnop));
- /* write the response header */
+ /* write the response */
WRITE_INT32(fp,NSLCD_VERSION);
WRITE_INT32(fp,NSLCD_RT_GETPWBYNAME);
WRITE_INT32(fp,retv);
- /* write the record */
- LDF_PASSWD;
- fflush(fp);
+ if (retv==NSLCD_RS_SUCCESS)
+ {
+ LDF_PASSWD;
+ }
+ WRITE_FLUSH(fp);
+ log_log(LOG_DEBUG,"nslcd_getpwnam DONE");
/* we're done */
return 0;
}
-enum nss_status _nss_ldap_getpwuid_r(uid_t uid,
- struct passwd *result,
- char *buffer,size_t buflen,int *errnop)
+int nslcd_getpwuid(FILE *fp)
{
- LOOKUP_NUMBER (uid, result, buffer, buflen, errnop, _nss_ldap_filt_getpwuid,
- LM_PASSWD, _nss_ldap_parse_pw, LDAP_NSS_BUFLEN_DEFAULT);
-}
-
-enum nss_status _nss_ldap_setpwent(void)
-{
- LOOKUP_SETENT (pw_context);
-}
-
-enum nss_status _nss_ldap_getpwent_r(struct passwd *result,
- char *buffer,size_t buflen,int *errnop)
-{
- LOOKUP_GETENT (pw_context, result, buffer, buflen, errnop,
- _nss_ldap_filt_getpwent, LM_PASSWD, _nss_ldap_parse_pw,
- LDAP_NSS_BUFLEN_DEFAULT);
+ int32_t tmpint32;
+ uid_t uid;
+ /* these are here for now until we rewrite the LDAP code */
+ struct passwd result;
+ char buffer[1024];
+ int errnop;
+ int retv;
+ /* read request parameters */
+ READ_TYPE(fp,uid,uid_t);
+ /* log call */
+ log_log(LOG_DEBUG,"nslcd_getpwuid(%d)",(int)uid);
+ /* do the LDAP request */
+ retv=nss2nslcd(_nss_ldap_getpwuid_r(uid,&result,buffer,1024,&errnop));
+ /* write the response */
+ WRITE_INT32(fp,NSLCD_VERSION);
+ WRITE_INT32(fp,NSLCD_RT_GETPWBYUID);
+ WRITE_INT32(fp,retv);
+ if (retv==NSLCD_RS_SUCCESS)
+ {
+ LDF_PASSWD;
+ }
+ WRITE_FLUSH(fp);
+ log_log(LOG_DEBUG,"nslcd_getpwuid DONE");
+ /* we're done */
+ return 0;
}
-enum nss_status _nss_ldap_endpwent(void)
+int nslcd_getpwall(FILE *fp)
{
- LOOKUP_ENDENT (pw_context);
+ int32_t tmpint32;
+ /* these are here for now until we rewrite the LDAP code */
+ struct passwd result;
+ char buffer[1024];
+ int errnop;
+ int retv;
+ /* log call */
+ log_log(LOG_DEBUG,"nslcd_getpwall");
+ /* write the response header */
+ WRITE_INT32(fp,NSLCD_VERSION);
+ WRITE_INT32(fp,NSLCD_RT_GETPWALL);
+ /* loop over all results */
+ _nss_ldap_setpwent();
+ while ((retv=nss2nslcd(_nss_ldap_getpwent_r(&result,buffer,1024,&errnop)))==NSLCD_RS_SUCCESS)
+ {
+ /* write the result code */
+ WRITE_INT32(fp,retv);
+ /* write the password entry */
+ LDF_PASSWD;
+ fflush(fp);
+ /* STRUCT PASSWD */
+ }
+ /* write the result code */
+ WRITE_INT32(fp,retv);
+ /* FIXME: if a previous call returns what happens to the context? */
+ _nss_ldap_endpwent();
+ log_log(LOG_DEBUG,"nslcd_getpwall DONE");
+ /* we're done */
+ return 0;
}
diff --git a/testnss.c b/testnss.c
index 5a53f88..5f774cb 100644
--- a/testnss.c
+++ b/testnss.c
@@ -18,7 +18,7 @@ static char *nssstatus(enum nss_status retv)
}
}
-void printpasswd(struct passwd *pw)
+static void printpasswd(struct passwd *pw)
{
printf("struct passwd {\n"
" pw_name=\"%s\",\n"
@@ -41,19 +41,36 @@ int main(int argc,char *argv[])
enum nss_status res;
int errnocp;
-
-
-
-
- res=_nss_ldap_getpwnam_r("aart",&result,buffer,1024,&errnocp);
+ /* test getpwnam() */
+ printf("TEST getpwnam()\n");
+ res=_nss_ldap_getpwnam_r("arthur",&result,buffer,1024,&errnocp);
+ printf("errno=%d:%s\n",(int)errno,strerror(errno));
+ printf("errnocp=%d:%s\n",(int)errnocp,strerror(errnocp));
+ printf("status=%s\n",nssstatus(res));
+ printpasswd(&result);
+ /* test getpwuid() */
+ printf("TEST getpwuid()\n");
+ res=_nss_ldap_getpwuid_r(180,&result,buffer,1024,&errnocp);
printf("errno=%d:%s\n",(int)errno,strerror(errno));
printf("errnocp=%d:%s\n",(int)errnocp,strerror(errnocp));
printf("status=%s\n",nssstatus(res));
printpasswd(&result);
-
- /* TODO: check response */
+ /* test {set,get,end}pwent() */
+ printf("TEST {set,get,end}pwent()\n");
+ _nss_ldap_setpwent();
+ while ((res=_nss_ldap_getpwent_r(&result,buffer,1024,&errnocp))==NSS_STATUS_SUCCESS)
+ {
+ printf("errno=%d:%s\n",(int)errno,strerror(errno));
+ printf("errnocp=%d:%s\n",(int)errnocp,strerror(errnocp));
+ printf("status=%s\n",nssstatus(res));
+ printpasswd(&result);
+ }
+ printf("errno=%d:%s\n",(int)errno,strerror(errno));
+ printf("errnocp=%d:%s\n",(int)errnocp,strerror(errnocp));
+ printf("status=%s\n",nssstatus(res));
+ _nss_ldap_endpwent();
return 0;
}