From 81018fb9efe3b9a55fdaa628270e0963ae276748 Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Mon, 30 Oct 2006 13:44:40 +0000 Subject: return read data in struct and fix some marcos git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/libnss_ldapd@28 ef36b2f9-881f-0410-afb5-c4e39611909c --- nss/common.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'nss/common.h') diff --git a/nss/common.h b/nss/common.h index d54cf6e..1b14f96 100644 --- a/nss/common.h +++ b/nss/common.h @@ -1,36 +1,42 @@ #include -/* translates a nsklcd return code (as defined in nslcd.h) to +/* translates a nslcd return code (as defined in nslcd.h) to a nss code (as defined in nss.h) */ enum nss_status nslcd2nss(int code); /* Macros for reading and writing to sockets. */ -#define OPEN_SOCK \ + +/* open a client socket */ +#define OPEN_SOCK(fp) \ if ((fp=nslcd_client_open())==NULL) \ { \ *errnop=errno; \ return NSS_STATUS_UNAVAIL; \ } -#define ERROR_OUT(status,errnoval) \ +/* 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(NSS_STATUS_UNAVAIL,ENOENT); + 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(NSS_STATUS_TRYAGAIN,ERANGE); /* will not fit */ \ + 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 */ \ @@ -40,5 +46,6 @@ enum nss_status nslcd2nss(int code); (field)=buffer+bufptr; \ bufptr+=sz+1; +/* read a typed value from the stream */ #define LDF_TYPE(field,type) \ READ(fp,&(field),sizeof(type)) -- cgit v1.2.3