From 3128e988fa37671c3ca8b81f235d3e4a505aa256 Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Fri, 15 Oct 2010 09:22:01 +0000 Subject: 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 --- nss/common.h | 49 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) (limited to 'nss/common.h') 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); \ -- cgit v1.2.3