From 5779d9e2ce26a8a9419ebf4fcf02f3571af34332 Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Fri, 3 Nov 2006 10:06:54 +0000 Subject: make loop macros common, create macros for expanding {set,get,end}ent() functions and implement {set,get,end}aliasent git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/libnss_ldapd@62 ef36b2f9-881f-0410-afb5-c4e39611909c --- nss/aliases.c | 29 +++++++++------------------- nss/common.h | 37 +++++++++++++++++++++++++++++++++++ nss/group.c | 62 ++++++++++++----------------------------------------------- nss/passwd.c | 34 +++----------------------------- 4 files changed, 61 insertions(+), 101 deletions(-) (limited to 'nss') diff --git a/nss/aliases.c b/nss/aliases.c index add8f15..52297e9 100644 --- a/nss/aliases.c +++ b/nss/aliases.c @@ -30,24 +30,9 @@ #include "nslcd-client.h" #include "common.h" -/* generic macros in development here */ -#define READ_LOOP(fp,num,arr,opr) \ - READ_TYPE(fp,tmpint32,int32_t); \ - (num)=tmpint32; \ - /* allocate room for *char[num] */ \ - tmpint32*=sizeof(char *); \ - if ((bufptr+(size_t)tmpint32)>buflen) \ - { ERROR_OUT_BUFERROR(fp) } /* will not fit */ \ - (arr)=(char **)(buffer+bufptr); \ - bufptr+=(size_t)tmpint32; \ - for (tmp2int32=0;tmp2int32<(num);tmp2int32++) \ - { \ - opr \ - } - /* macros for expanding the LDF_ALIAS macro */ #define LDF_STRING(field) READ_STRING_BUF(fp,field) -#define LDF_LOOP(field) READ_LOOP(fp,result->alias_members_len,result->alias_members,field) +#define LDF_LOOP(field) READ_LOOP_NUM(fp,result->alias_members_len,result->alias_members,field) #define ALIAS_NAME result->alias_name #define ALIAS_RCPT result->alias_members[tmp2int32] @@ -75,18 +60,22 @@ enum nss_status _nss_ldap_getaliasbyname_r( return NSS_STATUS_SUCCESS; } +/* thread-local file pointer to an ongoing request */ +static __thread FILE *pwentfp; +#define fp pwentfp + enum nss_status _nss_ldap_setaliasent(void) { - return NSS_STATUS_UNAVAIL; + NSS_SETENT(NSLCD_ACTION_ALIAS_ALL); } enum nss_status _nss_ldap_getaliasent_r(struct aliasent *result,char *buffer,size_t buflen,int *errnop) { - *errnop=ENOENT; - return NSS_STATUS_UNAVAIL; + int32_t tmp2int32; + NSS_GETENT(LDF_ALIAS); } enum nss_status _nss_ldap_endaliasent(void) { - return NSS_STATUS_UNAVAIL; + NSS_ENDENT(); } diff --git a/nss/common.h b/nss/common.h index f3465dd..21771e4 100644 --- a/nss/common.h +++ b/nss/common.h @@ -57,4 +57,41 @@ enum nss_status nslcd2nss(int code); *errnop=ENOENT; \ return nslcd2nss(retv); +/* helper macros available to easily generate {set,get,end}ent functions */ + +#define NSS_SETENT(action) \ + int32_t tmpint32; \ + 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,action); \ + WRITE_FLUSH(fp); \ + /* read response header */ \ + READ_RESPONSEHEADER(fp,action); \ + return NSS_STATUS_SUCCESS; + +#define NSS_GETENT(type) \ + int32_t tmpint32; \ + size_t bufptr=0; \ + /* check that we have a valid file descriptor */ \ + if (fp==NULL) \ + { \ + *errnop=ENOENT; \ + return NSS_STATUS_UNAVAIL; \ + } \ + /* read a response */ \ + READ_RESPONSE_CODE(fp); \ + type; \ + return NSS_STATUS_SUCCESS; + +#define NSS_ENDENT() \ + if (fp!=NULL) \ + fclose(fp); \ + return NSS_STATUS_SUCCESS; + #endif /* not _NSS_COMMON_H */ diff --git a/nss/group.c b/nss/group.c index 1013a6b..4c98f6b 100644 --- a/nss/group.c +++ b/nss/group.c @@ -30,24 +30,6 @@ #include "nslcd-client.h" #include "common.h" - -/* generic macros in development here */ -#define READ_LOOP_NULLTERM(fp,arr,opr) \ - READ_TYPE(fp,tmpint32,int32_t); \ - /* allocate room for *char[num+1] */ \ - tmp2int32=(tmpint32+1)*sizeof(char *); \ - if ((bufptr+(size_t)tmp2int32)>buflen) \ - { ERROR_OUT_BUFERROR(fp) } /* will not fit */ \ - (arr)=(char **)(buffer+bufptr); \ - /* set last entry to NULL */ \ - (arr)[tmpint32]=NULL; \ - /* read all entries */ \ - bufptr+=(size_t)tmpint32; \ - for (tmp2int32=0;tmp2int32