diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2010-10-15 11:22:01 +0200 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2010-10-15 11:22:01 +0200 |
commit | 3128e988fa37671c3ca8b81f235d3e4a505aa256 (patch) | |
tree | 934b1cefd0628d813fa5f1432126b52505f9a1cf /nss/common.h | |
parent | 9f9decee2a7a4e014ea5cfe880b53348d04f730e (diff) |
split out checking of NSS module availability and buffer correctness to separate macros (taken from the -solaris branch)
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd@1277 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'nss/common.h')
-rw-r--r-- | nss/common.h | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/nss/common.h b/nss/common.h index f9f5fbe..d8eaad8 100644 --- a/nss/common.h +++ b/nss/common.h @@ -67,6 +67,22 @@ fp=NULL; \ return NSS_STATUS_NOTFOUND; +/* These are some general macros that are used to build parts of the + genral macros below. */ + +/* check to see if we should answer NSS requests */ +#define NSS_AVAILCHECK \ + if (!_nss_ldap_enablelookups) \ + return NSS_STATUS_UNAVAIL; + +/* check validity of passed buffer */ +#define NSS_BUFCHECK \ + if ((buffer==NULL)||(buflen<=0)) \ + { \ + *errnop=EINVAL; \ + return NSS_STATUS_UNAVAIL; \ + } + /* The following macros to automatically generate get..byname(), get..bynumber(), setent(), getent() and endent() function bodies. These functions have very common code so this can @@ -84,14 +100,8 @@ TFILE *fp; \ int32_t tmpint32; \ nss_status_t retv; \ - if (!_nss_ldap_enablelookups) \ - return NSS_STATUS_UNAVAIL; \ - /* check that we have a valid buffer */ \ - if ((buffer==NULL)||(buflen<=0)) \ - { \ - *errnop=EINVAL; \ - return NSS_STATUS_UNAVAIL; \ - } \ + NSS_AVAILCHECK; \ + NSS_BUFCHECK; \ /* open socket and write request */ \ NSLCD_REQUEST(fp,action,writefn); \ /* read response */ \ @@ -120,8 +130,7 @@ /* This macro generates a simple setent() function body. This closes any open streams so that NSS_GETENT() can open a new file. */ #define NSS_SETENT(fp) \ - if (!_nss_ldap_enablelookups) \ - return NSS_STATUS_UNAVAIL; \ + NSS_AVAILCHECK; \ if (fp!=NULL) \ { \ (void)tio_close(fp); \ @@ -135,21 +144,8 @@ #define NSS_GETENT(fp,action,readfn) \ int32_t tmpint32; \ nss_status_t retv; \ - if (!_nss_ldap_enablelookups) \ - return NSS_STATUS_UNAVAIL; \ - /* check that we have a valid buffer */ \ - if ((buffer==NULL)||(buflen<=0)) \ - { \ - /* close stream */ \ - if (fp!=NULL) \ - { \ - (void)tio_close(fp); \ - fp=NULL; \ - } \ - /* indicate error */ \ - *errnop=EINVAL; \ - return NSS_STATUS_UNAVAIL; \ - } \ + NSS_AVAILCHECK; \ + NSS_BUFCHECK; \ /* check that we have a valid file descriptor */ \ if (fp==NULL) \ { \ @@ -181,8 +177,7 @@ /* This macro generates a endent() function body. This just closes the stream. */ #define NSS_ENDENT(fp) \ - if (!_nss_ldap_enablelookups) \ - return NSS_STATUS_UNAVAIL; \ + NSS_AVAILCHECK; \ if (fp!=NULL) \ { \ (void)tio_close(fp); \ |