diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2006-10-31 12:17:39 +0000 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2006-10-31 12:17:39 +0000 |
commit | fe8fb00dd57714528535de7e3a8d42f64e7a79aa (patch) | |
tree | e8642fbc016b084f6db00950bfb4e6e0d8da784d /server | |
parent | 93bda65a159e1f03b934fcb7050a5e1fba9bb2b7 (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
Diffstat (limited to 'server')
-rw-r--r-- | server/common.h | 16 | ||||
-rw-r--r-- | server/passwd.c | 124 |
2 files changed, 114 insertions, 26 deletions
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; } |