diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2006-11-03 11:06:54 +0100 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2006-11-03 11:06:54 +0100 |
commit | 5779d9e2ce26a8a9419ebf4fcf02f3571af34332 (patch) | |
tree | c3faeacbfb389bdf198a79de1f2a2a4d6a55ade5 /nss | |
parent | 3a1886177509b8712e447dbfb65293841a832596 (diff) |
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
Diffstat (limited to 'nss')
-rw-r--r-- | nss/aliases.c | 29 | ||||
-rw-r--r-- | nss/common.h | 37 | ||||
-rw-r--r-- | nss/group.c | 62 | ||||
-rw-r--r-- | nss/passwd.c | 34 |
4 files changed, 61 insertions, 101 deletions
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<tmpint32;tmp2int32++) \ - { \ - opr \ - } - /* macros for expanding the LDF_GROUP macro */ #define LDF_STRING(field) READ_STRING_BUF(fp,field) #define LDF_TYPE(field,type) READ_TYPE(fp,field,type) @@ -95,8 +77,14 @@ enum nss_status _nss_ldap_getgrgid_r(gid_t gid,struct group *result,char *buffer return NSS_STATUS_SUCCESS; } -enum nss_status _nss_ldap_initgroups(const char *user,gid_t group,long int *start,long int *size,gid_t *groups,long int limit,int *errnop); -enum nss_status _nss_ldap_initgroups_dyn(const char *user,gid_t group,long int *start,long int *size,gid_t **groupsp,long int limit,int *errnop); +/* this function returns a list of groups */ +enum nss_status _nss_ldap_initgroups_dyn( + const char *user,gid_t group,long int *start, + long int *size,gid_t **groupsp,long int limit,int *errnop) +{ + return NSS_STATUS_UNAVAIL; + /* TODO: implement skipping of entries as we're only interested in gids */ +} /* thread-local file pointer to an ongoing request */ static __thread FILE *pwentfp; @@ -104,42 +92,16 @@ static __thread FILE *pwentfp; enum nss_status _nss_ldap_setgrent(void) { - 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_ACTION_GROUP_ALL); - WRITE_FLUSH(fp); - /* read response header */ - READ_RESPONSEHEADER(fp,NSLCD_ACTION_GROUP_ALL); - return NSS_STATUS_SUCCESS; + NSS_SETENT(NSLCD_ACTION_GROUP_ALL); } enum nss_status _nss_ldap_getgrent_r(struct group *result,char *buffer,size_t buflen,int *errnop) { - int32_t tmpint32,tmp2int32; - 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); - LDF_GROUP; - return NSS_STATUS_SUCCESS; + int32_t tmp2int32; + NSS_GETENT(LDF_GROUP); } enum nss_status _nss_ldap_endgrent(void) { - if (fp!=NULL) - fclose(fp); - return NSS_STATUS_SUCCESS; + NSS_ENDENT(); } diff --git a/nss/passwd.c b/nss/passwd.c index 0557bc6..2ed200f 100644 --- a/nss/passwd.c +++ b/nss/passwd.c @@ -88,45 +88,17 @@ static __thread FILE *pwentfp; /* open a connection to the nslcd and write the request */ enum nss_status _nss_ldap_setpwent(void) { - 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_ACTION_PASSWD_ALL); - WRITE_FLUSH(fp); - /* read response header */ - READ_RESPONSEHEADER(fp,NSLCD_ACTION_PASSWD_ALL); - return NSS_STATUS_SUCCESS; + NSS_SETENT(NSLCD_ACTION_PASSWD_ALL); } /* read password data from an opened stream */ enum nss_status _nss_ldap_getpwent_r(struct passwd *result,char *buffer,size_t buflen,int *errnop) { - 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); - LDF_PASSWD; - return NSS_STATUS_SUCCESS; + NSS_GETENT(LDF_PASSWD); } /* close the stream opened with setpwent() above */ enum nss_status _nss_ldap_endpwent(void) { - if (fp==NULL) - return NSS_STATUS_SUCCESS; - fclose(fp); - return NSS_STATUS_SUCCESS; + NSS_ENDENT(); } |