Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/nss/common.h
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2006-10-30 14:44:40 +0100
committerArthur de Jong <arthur@arthurdejong.org>2006-10-30 14:44:40 +0100
commit81018fb9efe3b9a55fdaa628270e0963ae276748 (patch)
tree446e29d4bb882c3e14374489338443e254023e12 /nss/common.h
parent3f11f0a009ae5c48376f6c98dfa3876e0309cb3d (diff)
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
Diffstat (limited to 'nss/common.h')
-rw-r--r--nss/common.h17
1 files changed, 12 insertions, 5 deletions
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 <nss.h>
-/* 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))