Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/nss/common.h
blob: d54cf6e368421e8d9366b72ee4580744b9335a73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

#include <nss.h>

/* translates a nsklcd 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 \
  if ((fp=nslcd_client_open())==NULL) \
  { \
    *errnop=errno; \
    return NSS_STATUS_UNAVAIL; \
  }

#define ERROR_OUT(status,errnoval) \
  { \
    fclose(fp); \
    *errnop=errnoval; \
    return (status); \
  }

#define READ(fp,ptr,size) \
  if (fread(ptr,size,1,fp)<1) \
    ERROR_OUT(NSS_STATUS_UNAVAIL,ENOENT);

#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 */ \
  /* 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;

#define LDF_TYPE(field,type) \
  READ(fp,&(field),sizeof(type))