diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2006-10-31 12:17:39 +0000 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2006-10-31 12:17:39 +0000 |
commit | fe8fb00dd57714528535de7e3a8d42f64e7a79aa (patch) | |
tree | e8642fbc016b084f6db00950bfb4e6e0d8da784d /nss/common.h | |
parent | 93bda65a159e1f03b934fcb7050a5e1fba9bb2b7 (diff) |
clear up protocol macros while implementing getpwuid() and {set,get,end}pwent() functions (last not yet on NSS side)
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/libnss_ldapd@34 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'nss/common.h')
-rw-r--r-- | nss/common.h | 68 |
1 files changed, 24 insertions, 44 deletions
diff --git a/nss/common.h b/nss/common.h index 1b14f96..3129eee 100644 --- a/nss/common.h +++ b/nss/common.h @@ -5,47 +5,27 @@ a nss code (as defined in nss.h) */ enum nss_status nslcd2nss(int code); -/* Macros for reading and writing to sockets. */ - -/* open a client socket */ -#define OPEN_SOCK(fp) \ - if ((fp=nslcd_client_open())==NULL) \ - { \ - *errnop=errno; \ - return NSS_STATUS_UNAVAIL; \ - } - -/* bail out of the function with the nss status and errno set, - closing the socket */ -#define ERROR_OUT(fp,status,errnoval) \ - { \ - fclose(fp); \ - *errnop=errnoval; \ - return (status); \ - } - -/* read a buffer from the stream */ -#define READ(fp,ptr,size) \ - if (fread(ptr,size,1,fp)<1) \ - ERROR_OUT(fp,NSS_STATUS_UNAVAIL,ENOENT); - -/* read a string (lengt,buffer) from the stream, nul-terminating the string */ -#define LDF_STRING(field) \ - /* read the size of the string */ \ - READ(fp,&sz,sizeof(int32_t)); \ - /* FIXME: add error checking and sanity checking */ \ - /* check if read would fit */ \ - if ((bufptr+(size_t)sz+1)>buflen) \ - ERROR_OUT(fp,NSS_STATUS_TRYAGAIN,ERANGE); /* will not fit */ \ - /* read string from the stream */ \ - READ(fp,buffer+bufptr,(size_t)sz); \ - /* TODO: check that string does not contain \0 */ \ - /* null-terminate string in buffer */ \ - buffer[bufptr+sz]='\0'; \ - /* prepare result */ \ - (field)=buffer+bufptr; \ - bufptr+=sz+1; - -/* read a typed value from the stream */ -#define LDF_TYPE(field,type) \ - READ(fp,&(field),sizeof(type)) +/* macros for handling read and write problems, they are + NSS specific due to the return codes */ + +#define ERROR_OUT_OPENERROR \ + *errnop=errno; \ + return NSS_STATUS_UNAVAIL; + +#define ERROR_OUT_READERROR(fp) \ + fclose(fp); \ + *errnop=ENOENT; \ + return NSS_STATUS_UNAVAIL; \ + +#define ERROR_OUT_BUFERROR(fp) \ + fclose(fp); \ + *errnop=ERANGE; \ + return NSS_STATUS_TRYAGAIN; \ + +#define ERROR_OUT_WRITEERROR(fp) \ + ERROR_OUT_READERROR(fp) + +#define ERROR_OUT_NOSUCCESS(fp,retv) \ + fclose(fp); \ + *errnop=ENOENT; \ + return nslcd2nss(retv); |