diff options
Diffstat (limited to 'nss/common.h')
-rw-r--r-- | nss/common.h | 182 |
1 files changed, 91 insertions, 91 deletions
diff --git a/nss/common.h b/nss/common.h index 6e65c9e..adce4cf 100644 --- a/nss/common.h +++ b/nss/common.h @@ -41,42 +41,42 @@ an error status. */ /* Macro is called to handle errors in opening a client connection. */ -#define ERROR_OUT_OPENERROR \ - *errnop=ENOENT; \ - return (errno==EAGAIN)?NSS_STATUS_TRYAGAIN:NSS_STATUS_UNAVAIL; +#define ERROR_OUT_OPENERROR \ + *errnop = ENOENT; \ + return (errno == EAGAIN) ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL; /* Macro is called to handle errors on read operations. */ -#define ERROR_OUT_READERROR(fp) \ - (void)tio_close(fp); \ - fp=NULL; \ - *errnop=ENOENT; \ +#define ERROR_OUT_READERROR(fp) \ + (void)tio_close(fp); \ + fp = NULL; \ + *errnop = ENOENT; \ return NSS_STATUS_UNAVAIL; /* Macro is called to handle problems with too small a buffer. This triggers the caller to call the function with a larger buffer (see NSS_GETENT below). */ -#define ERROR_OUT_BUFERROR(fp) \ - *errnop=ERANGE; \ +#define ERROR_OUT_BUFERROR(fp) \ + *errnop = ERANGE; \ return NSS_STATUS_TRYAGAIN; /* This macro is called if there was a problem with a write operation. */ -#define ERROR_OUT_WRITEERROR(fp) \ +#define ERROR_OUT_WRITEERROR(fp) \ ERROR_OUT_READERROR(fp) /* This macro is called if the read status code is not NSLCD_RESULT_BEGIN. */ -#define ERROR_OUT_NOSUCCESS(fp) \ - (void)tio_close(fp); \ - fp=NULL; \ +#define ERROR_OUT_NOSUCCESS(fp) \ + (void)tio_close(fp); \ + 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) \ +#define NSS_AVAILCHECK \ + if (!_nss_ldap_enablelookups) \ return NSS_STATUS_UNAVAIL; #ifdef NSS_FLAVOUR_GLIBC @@ -85,11 +85,11 @@ #define NSS_EXTRA_DEFS ; /* check validity of passed buffer (Glibc flavour) */ -#define NSS_BUFCHECK \ - if ((buffer==NULL)||(buflen==0)) \ - { \ - *errnop=EINVAL; \ - return NSS_STATUS_UNAVAIL; \ +#define NSS_BUFCHECK \ + if ((buffer == NULL) || (buflen == 0)) \ + { \ + *errnop = EINVAL; \ + return NSS_STATUS_UNAVAIL; \ } #endif /* NSS_FLAVOUR_GLIBC */ @@ -107,96 +107,96 @@ the result structure, the user buffer with length and the errno to return. This macro should be called through some of the customized ones below. */ -#define NSS_BYGEN(action,writefn,readfn) \ - TFILE *fp; \ - int32_t tmpint32; \ - nss_status_t retv; \ - NSS_EXTRA_DEFS; \ - NSS_AVAILCHECK; \ - NSS_BUFCHECK; \ - /* open socket and write request */ \ - NSLCD_REQUEST(fp,action,writefn); \ - /* read response */ \ - READ_RESPONSE_CODE(fp); \ - retv=readfn; \ - /* close socket and we're done */ \ - if ((retv==NSS_STATUS_SUCCESS)||(retv==NSS_STATUS_TRYAGAIN)) \ - { \ - (void)tio_skipall(fp); \ - (void)tio_close(fp); \ - } \ +#define NSS_BYGEN(action, writefn, readfn) \ + TFILE *fp; \ + int32_t tmpint32; \ + nss_status_t retv; \ + NSS_EXTRA_DEFS; \ + NSS_AVAILCHECK; \ + NSS_BUFCHECK; \ + /* open socket and write request */ \ + NSLCD_REQUEST(fp, action, writefn); \ + /* read response */ \ + READ_RESPONSE_CODE(fp); \ + retv = readfn; \ + /* close socket and we're done */ \ + if ((retv == NSS_STATUS_SUCCESS) || (retv == NSS_STATUS_TRYAGAIN)) \ + { \ + (void)tio_skipall(fp); \ + (void)tio_close(fp); \ + } \ return retv; /* This macro can be used to generate a get..byname() function body. */ -#define NSS_BYNAME(action,name,readfn) \ - NSS_BYGEN(action,WRITE_STRING(fp,name),readfn) +#define NSS_BYNAME(action, name, readfn) \ + NSS_BYGEN(action, WRITE_STRING(fp, name), readfn) /* This macro can be used to generate a get..by..() function body where the value should be passed as an int32_t. */ -#define NSS_BYINT32(action,val,readfn) \ - NSS_BYGEN(action,WRITE_INT32(fp,val),readfn) +#define NSS_BYINT32(action, val, readfn) \ + NSS_BYGEN(action, WRITE_INT32(fp, val), readfn) /* 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) \ - NSS_AVAILCHECK; \ - if (fp!=NULL) \ - { \ - (void)tio_close(fp); \ - fp=NULL; \ - } \ +#define NSS_SETENT(fp) \ + NSS_AVAILCHECK; \ + if (fp != NULL) \ + { \ + (void)tio_close(fp); \ + fp = NULL; \ + } \ return NSS_STATUS_SUCCESS; /* This macro generates a getent() function body. If the stream is not yet open, a new one is opened, a request is written and a check is done for a response header. A single entry is read with the readfn() function. */ -#define NSS_GETENT(fp,action,readfn) \ - int32_t tmpint32; \ - nss_status_t retv; \ - NSS_EXTRA_DEFS; \ - NSS_AVAILCHECK; \ - NSS_BUFCHECK; \ - /* check that we have a valid file descriptor */ \ - if (fp==NULL) \ - { \ - /* open a new stream and write the request */ \ - NSLCD_REQUEST(fp,action,/* no writefn */;); \ - } \ - /* prepare for buffer errors */ \ - tio_mark(fp); \ - /* read a response */ \ - READ_RESPONSE_CODE(fp); \ - retv=readfn; \ - /* check read result */ \ - if (retv==NSS_STATUS_TRYAGAIN) \ - { \ - /* if we have a full buffer try to reset the stream */ \ - if (tio_reset(fp)) \ - { \ - /* reset failed, we close and give up with a permanent error \ - because we cannot retry just the getent() call because it \ - may not be only the first entry that failed */ \ - tio_close(fp); \ - fp=NULL; \ - *errnop=EINVAL; \ - return NSS_STATUS_UNAVAIL; \ - } \ - } \ - else if (retv!=NSS_STATUS_SUCCESS) \ - fp=NULL; /* file should be closed by now */ \ +#define NSS_GETENT(fp, action, readfn) \ + int32_t tmpint32; \ + nss_status_t retv; \ + NSS_EXTRA_DEFS; \ + NSS_AVAILCHECK; \ + NSS_BUFCHECK; \ + /* check that we have a valid file descriptor */ \ + if (fp == NULL) \ + { \ + /* open a new stream and write the request */ \ + NSLCD_REQUEST(fp, action, /* no writefn */ ;); \ + } \ + /* prepare for buffer errors */ \ + tio_mark(fp); \ + /* read a response */ \ + READ_RESPONSE_CODE(fp); \ + retv = readfn; \ + /* check read result */ \ + if (retv == NSS_STATUS_TRYAGAIN) \ + { \ + /* if we have a full buffer try to reset the stream */ \ + if (tio_reset(fp)) \ + { \ + /* reset failed, we close and give up with a permanent error \ + because we cannot retry just the getent() call because it \ + may not be only the first entry that failed */ \ + tio_close(fp); \ + fp = NULL; \ + *errnop = EINVAL; \ + return NSS_STATUS_UNAVAIL; \ + } \ + } \ + else if (retv != NSS_STATUS_SUCCESS) \ + fp = NULL; /* file should be closed by now */ \ return retv; /* This macro generates an endent() function body. This just closes the stream. */ -#define NSS_ENDENT(fp) \ - NSS_AVAILCHECK; \ - if (fp!=NULL) \ - { \ - (void)tio_skipall(fp); \ - (void)tio_close(fp); \ - fp=NULL; \ - } \ +#define NSS_ENDENT(fp) \ + NSS_AVAILCHECK; \ + if (fp != NULL) \ + { \ + (void)tio_skipall(fp); \ + (void)tio_close(fp); \ + fp = NULL; \ + } \ return NSS_STATUS_SUCCESS; #endif /* not NSS__COMMON_H */ |