diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2006-11-01 12:13:34 +0000 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2006-11-01 12:13:34 +0000 |
commit | 629c39e774db8ba8ae01ba1591c7382e020378f3 (patch) | |
tree | ecb6b7d577fd5d74cb161a93bdcde1e985107501 | |
parent | 3964dee96be1b083da654d9b0d8435e8b6c314ff (diff) |
implement _nss_ldap_{set,get,end}pwent() functions with thread-local opened file
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/libnss_ldapd@44 ef36b2f9-881f-0410-afb5-c4e39611909c
-rw-r--r-- | nss/passwd.c | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/nss/passwd.c b/nss/passwd.c index d89fb9b..94e3a81 100644 --- a/nss/passwd.c +++ b/nss/passwd.c @@ -81,18 +81,49 @@ enum nss_status _nss_ldap_getpwuid_r(uid_t uid,struct passwd *result,char *buffe return NSS_STATUS_SUCCESS; } +/* thread-local file pointer to an ongoing request */ +static __thread FILE *pwentfp; +#define fp pwentfp + +/* open a connection to the nslcd and write the request */ enum nss_status _nss_ldap_setpwent(void) { - return NSS_STATUS_UNAVAIL; + int32_t tmpint32; + /* this is to satisfy our macros */ + int errnocp; + int *errnop; + errnop=&errnocp; + /* close the existing stream if it is still open */ + if (fp!=NULL) + _nss_ldap_endpwent(); + /* open a new stream and write the request */ + OPEN_SOCK(fp); + WRITE_REQUEST(fp,NSLCD_RT_GETPWALL); + WRITE_FLUSH(fp); + /* read response header */ + READ_RESPONSEHEADER(fp,NSLCD_RT_GETPWALL); + return NSS_STATUS_SUCCESS; } +/* read password data from an opened stream */ enum nss_status _nss_ldap_getpwent_r(struct passwd *result,char *buffer,size_t buflen,int *errnop) { - *errnop=ENOENT; - return NSS_STATUS_UNAVAIL; + int32_t tmpint32; + size_t bufptr=0; + /* check that we have a valid file descriptor */ + if (fp==NULL) + return NSS_STATUS_UNAVAIL; + /* read a response */ + READ_RESPONSE(fp); + LDF_PASSWD; + return NSS_STATUS_SUCCESS; } +/* close the stream opened with setpwent() above */ enum nss_status _nss_ldap_endpwent(void) { - return NSS_STATUS_UNAVAIL; + if (fp==NULL) + return NSS_STATUS_SUCCESS; + fclose(fp); + return NSS_STATUS_SUCCESS; } |