2
2
common.h - common functions for NSS lookups
4
4
Copyright (C) 2006 West Consulting
5
Copyright (C) 2006, 2007, 2008, 2009, 2010 Arthur de Jong
5
Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Arthur de Jong
7
7
This library is free software; you can redistribute it and/or
8
8
modify it under the terms of the GNU Lesser General Public
67
68
return NSS_STATUS_NOTFOUND;
70
/* These are some general macros that are used to build parts of the
71
genral macros below. */
73
/* check to see if we should answer NSS requests */
74
#define NSS_AVAILCHECK \
75
if (!_nss_ldap_enablelookups) \
76
return NSS_STATUS_UNAVAIL;
78
#ifdef NSS_FLAVOUR_GLIBC
80
/* extra definitions we need (nothing for Glibc) */
81
#define NSS_EXTRA_DEFS ;
83
/* check validity of passed buffer (Glibc flavour) */
84
#define NSS_BUFCHECK \
85
if ((buffer==NULL)||(buflen==0)) \
88
return NSS_STATUS_UNAVAIL; \
91
#endif /* NSS_FLAVOUR_GLIBC */
93
#ifdef NSS_FLAVOUR_SOLARIS
95
/* extra definitions we need (Solaris NSS functions don't pass errno) */
96
#define NSS_EXTRA_DEFS \
99
/* check validity of passed buffer (Solaris flavour) */
100
#define NSS_BUFCHECK \
101
if ((NSS_ARGS(args)->buf.buffer==NULL)||(NSS_ARGS(args)->buf.buflen<=0)) \
103
NSS_ARGS(args)->erange=1; \
104
return NSS_STATUS_TRYAGAIN; \
107
/* this is the backend structure for Solaris */
108
struct nss_ldap_backend
110
nss_backend_op_t *ops; /* function-pointer table */
111
int n_ops; /* number of function pointers */
112
TFILE *fp; /* the file pointer for {set,get,end}ent() functions */
115
/* constructor for LDAP backends */
116
nss_backend_t *nss_ldap_constructor(nss_backend_op_t *ops,size_t sizeofops);
118
/* destructor for LDAP backends */
119
nss_status_t nss_ldap_destructor(nss_backend_t *be,void UNUSED(*args));
121
#endif /* NSS_FLAVOUR_SOLARIS */
69
123
/* The following macros to automatically generate get..byname(),
70
124
get..bynumber(), setent(), getent() and endent() function
71
125
bodies. These functions have very common code so this can
82
136
#define NSS_BYGEN(action,writefn,readfn) \
84
138
int32_t tmpint32; \
85
enum nss_status retv; \
86
if (!_nss_ldap_enablelookups) \
87
return NSS_STATUS_UNAVAIL; \
88
/* check that we have a valid buffer */ \
89
if ((buffer==NULL)||(buflen<=0)) \
92
return NSS_STATUS_UNAVAIL; \
94
143
/* open socket and write request */ \
95
144
NSLCD_REQUEST(fp,action,writefn); \
96
145
/* read response */ \
133
181
a response header. A single entry is read with the readfn() function. */
134
182
#define NSS_GETENT(fp,action,readfn) \
135
183
int32_t tmpint32; \
136
enum nss_status retv; \
137
if (!_nss_ldap_enablelookups) \
138
return NSS_STATUS_UNAVAIL; \
139
/* check that we have a valid buffer */ \
140
if ((buffer==NULL)||(buflen<=0)) \
145
(void)tio_close(fp); \
148
/* indicate error */ \
150
return NSS_STATUS_UNAVAIL; \
152
188
/* check that we have a valid file descriptor */ \