Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nss/aliases.c7
-rw-r--r--nss/automount.c44
-rw-r--r--nss/common.h72
-rw-r--r--nss/ethers.c7
-rw-r--r--nss/group.c9
-rw-r--r--nss/hosts.c19
-rw-r--r--nss/networks.c11
-rw-r--r--nss/passwd.c7
-rw-r--r--nss/protocols.c7
-rw-r--r--nss/rpc.c7
-rw-r--r--nss/services.c7
-rw-r--r--nss/shadow.c7
12 files changed, 124 insertions, 80 deletions
diff --git a/nss/aliases.c b/nss/aliases.c
index 70a619f..50a4fd9 100644
--- a/nss/aliases.c
+++ b/nss/aliases.c
@@ -59,19 +59,18 @@ enum nss_status _nss_ldap_getaliasbyname_r(
/* thread-local file pointer to an ongoing request */
static __thread FILE *aliasentfp;
-#define fp aliasentfp
enum nss_status _nss_ldap_setaliasent(void)
{
- NSS_SETENT(NSLCD_ACTION_ALIAS_ALL);
+ NSS_SETENT(aliasentfp,NSLCD_ACTION_ALIAS_ALL);
}
enum nss_status _nss_ldap_getaliasent_r(struct aliasent *result,char *buffer,size_t buflen,int *errnop)
{
- NSS_GETENT(read_aliasent);
+ NSS_GETENT(aliasentfp,read_aliasent);
}
enum nss_status _nss_ldap_endaliasent(void)
{
- NSS_ENDENT();
+ NSS_ENDENT(aliasentfp);
}
diff --git a/nss/automount.c b/nss/automount.c
index d160e11..1297330 100644
--- a/nss/automount.c
+++ b/nss/automount.c
@@ -45,6 +45,18 @@ struct automount_context
int32_t magic; /* for sanity checks */
};
+static enum nss_status read_automount(
+ FILE *fp,const char **canon_key,const char **value,
+ char *buffer,size_t buflen,int *errnop)
+{
+ int32_t tmpint32;
+ size_t bufptr=0;
+ /* auto-genereted read code */
+ LDF_AUTOMOUNT;
+ /* we're done */
+ return NSS_STATUS_SUCCESS;
+}
+
/* this function initiates a structure for doing queries
using getautomountbyname() and getautomountent() */
enum nss_status _nss_ldap_setautomntent(
@@ -78,8 +90,8 @@ enum nss_status _nss_ldap_getautomntbyname_r(
{
struct automount_context *context;
FILE *fp;
- size_t bufptr=0;
int32_t tmpint32;
+ enum nss_status retv;
/* check context */
context=(struct automount_context *)private;
if ((context==NULL)||(context->magic!=AUTOMOUNT_CONTEXT_MAGIC))
@@ -94,43 +106,47 @@ enum nss_status _nss_ldap_getautomntbyname_r(
READ_RESPONSEHEADER(fp,NSLCD_ACTION_AUTOMOUNT_BYNAME);
/* read response */
READ_RESPONSE_CODE(fp);
- LDF_AUTOMOUNT;
+ retv=read_automount(fp,canon_key,value,buffer,buflen,errnop);
+ if (retv!=NSS_STATUS_SUCCESS)
+ return retv;
/* close socket and we're done */
fclose(fp);
return NSS_STATUS_SUCCESS;
}
-#define fp (context->fp)
-
enum nss_status _nss_ldap_getautomntent_r(
void *private,const char **canon_key,const char **value,
char *buffer,size_t buflen,int *errnop)
{
struct automount_context *context;
int32_t tmpint32;
- size_t bufptr=0;
+ enum nss_status retv;
/* check context */
context=(struct automount_context *)private;
if ((context==NULL)||(context->magic!=AUTOMOUNT_CONTEXT_MAGIC))
return NSS_STATUS_UNAVAIL;
/* if we don't have a file descriptor, begin a request now */
- if (fp==NULL)
+ if (context->fp==NULL)
{
/* open a new stream and write the request */
- OPEN_SOCK(fp);
- WRITE_REQUEST(fp,NSLCD_ACTION_AUTOMOUNT_ALL);
- WRITE_FLUSH(fp);
+ OPEN_SOCK(context->fp);
+ WRITE_REQUEST(context->fp,NSLCD_ACTION_AUTOMOUNT_ALL);
+ WRITE_FLUSH(context->fp);
/* read response header */
- READ_RESPONSEHEADER(fp,NSLCD_ACTION_AUTOMOUNT_ALL);
+ READ_RESPONSEHEADER(context->fp,NSLCD_ACTION_AUTOMOUNT_ALL);
}
/* read a response */
- READ_RESPONSE_CODE(fp);
- LDF_AUTOMOUNT;
+ READ_RESPONSE_CODE(context->fp);
+ retv=read_automount(context->fp,canon_key,value,buffer,buflen,errnop);
+ if (retv!=NSS_STATUS_SUCCESS)
+ {
+ /* remove reference to fp from context */
+ context->fp=NULL;
+ return retv;
+ }
return NSS_STATUS_SUCCESS;
}
-#undef fp
-
enum nss_status _nss_ldap_endautomntent(void **private)
{
struct automount_context *context;
diff --git a/nss/common.h b/nss/common.h
index 8eb6ee9..f985aed 100644
--- a/nss/common.h
+++ b/nss/common.h
@@ -25,40 +25,64 @@
#include <nss.h>
-/* translates a nslcd return code (as defined in nslcd.h) to
- a nss code (as defined in nss.h) */
+/* This function maps an nslcd return code (as defined in nslcd.h)
+ to an nss code (as defined in nss.h). */
enum nss_status nslcd2nss(int code);
-/* macros for handling read and write problems, they are
- NSS specific due to the return codes */
+/* These are macros for handling read and write problems, they are
+ NSS specific due to the return code so are defined here. They
+ genrally close the open file, set an error code and return with
+ an error status. */
+/* Macro is called to handle errors in opening a client connection. */
#define ERROR_OUT_OPENERROR \
*errnop=ENOENT; \
- return NSS_STATUS_UNAVAIL;
+ return (errno==EAGAIN)?NSS_STATUS_TRYAGAIN:NSS_STATUS_UNAVAIL;
+/* Macro is called to handle errors on fread(). */
#define ERROR_OUT_READERROR(fp) \
fclose(fp); \
fp=NULL; \
*errnop=ENOENT; \
return NSS_STATUS_UNAVAIL;
+/* Macro is called to handle problems with too small a buffer.
+ Note that this currently requires the caller to do setent()
+ again before doing getent() because this closes the stream.
+ Something more inteligent (e.g. ungetting the read data from
+ the stream) should be implemented. */
#define ERROR_OUT_BUFERROR(fp) \
fclose(fp); \
fp=NULL; \
*errnop=ERANGE; \
return NSS_STATUS_TRYAGAIN;
+/* This macro is called if there was a problem with an fwrite()
+ operation. */
#define ERROR_OUT_WRITEERROR(fp) \
ERROR_OUT_READERROR(fp)
+/* This macro is called if the read status code is not
+ NSLCD_RESULT_SUCCESS. */
#define ERROR_OUT_NOSUCCESS(fp,retv) \
fclose(fp); \
fp=NULL; \
*errnop=ENOENT; \
return nslcd2nss(retv);
-/* helper macros available to easily generate {set,get,end}ent functions */
-
+/* The following macros to automatically generate get..byname(),
+ get..bynumber(), setent(), getent() and endent() function
+ bodies. These functions have very common code so this can
+ easily be reused. */
+
+/* This is a generic get..by..() generation macro. The action
+ parameter is the NSLCD_ACTION_.. action, the param is the
+ operation for writing the parameter and readfn is the function
+ name for reading a single result entry. The function is assumed
+ to have result, buffer, buflen and errnop parameters that define
+ the result structure, the user buffer with length and the
+ errno to return. This macro should be called with some of
+ the customized ones below. */
#define NSS_BYGEN(action,param,readfn) \
FILE *fp; \
int32_t tmpint32; \
@@ -74,23 +98,30 @@ enum nss_status nslcd2nss(int code);
READ_RESPONSE_CODE(fp); \
readfn(fp,result,buffer,buflen,errnop); \
retv=readfn(fp,result,buffer,buflen,errnop); \
- /* check read result */ \
- if (retv!=NSS_STATUS_SUCCESS) \
- return retv; \
/* close socket and we're done */ \
- fclose(fp); \
- return NSS_STATUS_SUCCESS;
+ if (retv==NSS_STATUS_SUCCESS) \
+ fclose(fp); \
+ return retv;
+/* This macro can be used to generate a get..byname() function
+ body. */
#define NSS_BYNAME(action,name,readfn) \
NSS_BYGEN(action,WRITE_STRING(fp,name),readfn)
+/* This macro can be used to generate a get..by..() function
+ body where the value that is the key has the specified type. */
#define NSS_BYTYPE(action,val,type,readfn) \
NSS_BYGEN(action,WRITE_TYPE(fp,val,type),readfn)
+/* This macro can be used to generate a get..by..() function
+ body where the value should be passed as an int32_t. */
#define NSS_BYINT32(action,val,readfn) \
NSS_BYGEN(action,WRITE_INT32(fp,val),readfn)
-#define NSS_SETENT(action) \
+/* This macro generates a simple setent() function body. A stream
+ is opened, a request is written and a check is done for
+ a response header. */
+#define NSS_SETENT(fp,action) \
int32_t tmpint32; \
int errnocp; \
int *errnop; \
@@ -106,7 +137,9 @@ enum nss_status nslcd2nss(int code);
READ_RESPONSEHEADER(fp,action); \
return NSS_STATUS_SUCCESS;
-#define NSS_GETENT(readfn) \
+/* This macro generates a getent() function body. A single entry
+ is read with the readfn() function. */
+#define NSS_GETENT(fp,readfn) \
int32_t tmpint32; \
enum nss_status retv; \
/* check that we have a valid file descriptor */ \
@@ -120,12 +153,17 @@ enum nss_status nslcd2nss(int code);
retv=readfn(fp,result,buffer,buflen,errnop); \
/* check read result */ \
if (retv!=NSS_STATUS_SUCCESS) \
- return retv; \
- return NSS_STATUS_SUCCESS;
+ fp=NULL; /* file should be closed by now */ \
+ return retv;
-#define NSS_ENDENT() \
+/* This macro generates a endent() function body. This just closes
+ the stream. */
+#define NSS_ENDENT(fp) \
if (fp!=NULL) \
+ { \
fclose(fp); \
+ fp=NULL; \
+ } \
return NSS_STATUS_SUCCESS;
#endif /* not _NSS_COMMON_H */
diff --git a/nss/ethers.c b/nss/ethers.c
index 13443f7..c9dd1bc 100644
--- a/nss/ethers.c
+++ b/nss/ethers.c
@@ -66,21 +66,20 @@ enum nss_status _nss_ldap_getntohost_r(
/* thread-local file pointer to an ongoing request */
static __thread FILE *etherentfp;
-#define fp etherentfp
enum nss_status _nss_ldap_setetherent(int stayopen)
{
- NSS_SETENT(NSLCD_ACTION_ETHER_ALL);
+ NSS_SETENT(etherentfp,NSLCD_ACTION_ETHER_ALL);
}
enum nss_status _nss_ldap_getetherent_r(
struct etherent *result,
char *buffer,size_t buflen,int *errnop)
{
- NSS_GETENT(read_etherent);
+ NSS_GETENT(etherentfp,read_etherent);
}
enum nss_status _nss_ldap_endetherent(void)
{
- NSS_ENDENT();
+ NSS_ENDENT(etherentfp);
}
diff --git a/nss/group.c b/nss/group.c
index cdac7d5..04c45a8 100644
--- a/nss/group.c
+++ b/nss/group.c
@@ -113,7 +113,7 @@ enum nss_status _nss_ldap_initgroups_dyn(
(*groupsp)[*start++]=gid;
num++;
/* read next response code */
- READ_TYPE(fp,cd,int32_t);
+ READ_TYPE(fp,cd,int32_t);
}
/* close socket and we're done */
fclose(fp);
@@ -122,19 +122,18 @@ enum nss_status _nss_ldap_initgroups_dyn(
/* thread-local file pointer to an ongoing request */
static __thread FILE *grentfp;
-#define fp grentfp
enum nss_status _nss_ldap_setgrent(int stayopen)
{
- NSS_SETENT(NSLCD_ACTION_GROUP_ALL);
+ NSS_SETENT(grentfp,NSLCD_ACTION_GROUP_ALL);
}
enum nss_status _nss_ldap_getgrent_r(struct group *result,char *buffer,size_t buflen,int *errnop)
{
- NSS_GETENT(read_group);
+ NSS_GETENT(grentfp,read_group);
}
enum nss_status _nss_ldap_endgrent(void)
{
- NSS_ENDENT();
+ NSS_ENDENT(grentfp);
}
diff --git a/nss/hosts.c b/nss/hosts.c
index 852b37d..5513838 100644
--- a/nss/hosts.c
+++ b/nss/hosts.c
@@ -49,7 +49,7 @@
return nslcd2nss(retv);
/* read a single host entry from the stream, filtering on the
- specified address family, result is stored in result
+ specified address family, result is stored in result
it will return NSS_STATUS_NOTFOUND if an empty entry was read
(no addresses in the address family) */
static enum nss_status read_hostent(
@@ -70,7 +70,7 @@ static enum nss_status read_hostent(
/* allocate memory for array */
/* Note: this may allocate too much memory (e.g. also for
address records of other address families) but
- this is an easy way to do it */
+ this is an easy way to do it */
BUF_CHECK(fp,(numaddr+1)*sizeof(char *));
result->h_addr_list=(char **)BUF_CUR;
/* go through the address list and filter on af */
@@ -104,8 +104,8 @@ static enum nss_status read_hostent(
/* this function looks up a single host entry and returns all the addresses
associated with the host in a single address familiy
- name - IN - hostname to lookup
- af - IN - address familty to present results for
+ name - IN - hostname to lookup
+ af - IN - address familty to present results for
result - OUT - entry found
buffer,buflen - OUT - buffer to store allocated stuff on
errnop,h_errnop - OUT - for reporting errors */
@@ -196,11 +196,10 @@ enum nss_status _nss_ldap_gethostbyaddr_r(
/* thread-local file pointer to an ongoing request */
static __thread FILE *hostentfp;
-#define fp hostentfp
enum nss_status _nss_ldap_sethostent(int stayopen)
{
- NSS_SETENT(NSLCD_ACTION_HOST_ALL);
+ NSS_SETENT(hostentfp,NSLCD_ACTION_HOST_ALL);
}
/* this function only returns addresses of the AF_INET address family */
@@ -211,7 +210,7 @@ enum nss_status _nss_ldap_gethostent_r(
int32_t tmpint32;
enum nss_status retv=NSS_STATUS_NOTFOUND;
/* check that we have a valid file descriptor */
- if (fp==NULL)
+ if (hostentfp==NULL)
{
*errnop=ENOENT;
return NSS_STATUS_UNAVAIL;
@@ -220,8 +219,8 @@ enum nss_status _nss_ldap_gethostent_r(
do
{
/* read a response */
- READ_RESPONSE_CODE(fp);
- retv=read_hostent(fp,AF_INET,result,buffer,buflen,errnop,h_errnop);
+ READ_RESPONSE_CODE(hostentfp);
+ retv=read_hostent(hostentfp,AF_INET,result,buffer,buflen,errnop,h_errnop);
/* do another loop run if we read an ok address or */
}
while ((retv==NSS_STATUS_SUCCESS)||(retv==NSS_STATUS_NOTFOUND));
@@ -230,5 +229,5 @@ enum nss_status _nss_ldap_gethostent_r(
enum nss_status _nss_ldap_endhostent(void)
{
- NSS_ENDENT();
+ NSS_ENDENT(hostentfp);
}
diff --git a/nss/networks.c b/nss/networks.c
index 8c5ddb5..a8c0d3a 100644
--- a/nss/networks.c
+++ b/nss/networks.c
@@ -153,11 +153,10 @@ enum nss_status _nss_ldap_getnetbyaddr_r(uint32_t addr,int af,struct netent *res
/* thread-local file pointer to an ongoing request */
static __thread FILE *netentfp;
-#define fp netentfp
enum nss_status _nss_ldap_setnetent(int stayopen)
{
- NSS_SETENT(NSLCD_ACTION_NETWORK_ALL);
+ NSS_SETENT(netentfp,NSLCD_ACTION_NETWORK_ALL);
}
enum nss_status _nss_ldap_getnetent_r(struct netent *result,char *buffer,size_t buflen,int *errnop,int *h_errnop)
@@ -165,7 +164,7 @@ enum nss_status _nss_ldap_getnetent_r(struct netent *result,char *buffer,size_t
int32_t tmpint32;
enum nss_status retv=NSS_STATUS_NOTFOUND;
/* check that we have a valid file descriptor */
- if (fp==NULL)
+ if (netentfp==NULL)
{
*errnop=ENOENT;
return NSS_STATUS_UNAVAIL;
@@ -174,8 +173,8 @@ enum nss_status _nss_ldap_getnetent_r(struct netent *result,char *buffer,size_t
do
{
/* read a response */
- READ_RESPONSE_CODE(fp);
- retv=read_netent(fp,result,buffer,buflen,errnop,h_errnop);
+ READ_RESPONSE_CODE(netentfp);
+ retv=read_netent(netentfp,result,buffer,buflen,errnop,h_errnop);
/* do another loop run if we read an empty address list */
}
while ((retv==NSS_STATUS_SUCCESS)||(retv==NSS_STATUS_NOTFOUND));
@@ -184,5 +183,5 @@ enum nss_status _nss_ldap_getnetent_r(struct netent *result,char *buffer,size_t
enum nss_status _nss_ldap_endnetent(void)
{
- NSS_ENDENT();
+ NSS_ENDENT(netentfp);
}
diff --git a/nss/passwd.c b/nss/passwd.c
index c544ec8..4ce8116 100644
--- a/nss/passwd.c
+++ b/nss/passwd.c
@@ -64,22 +64,21 @@ enum nss_status _nss_ldap_getpwuid_r(uid_t uid,struct passwd *result,char *buffe
/* thread-local file pointer to an ongoing request */
static __thread FILE *pwentfp;
-#define fp pwentfp
/* open a connection to the nslcd and write the request */
enum nss_status _nss_ldap_setpwent(int stayopen)
{
- NSS_SETENT(NSLCD_ACTION_PASSWD_ALL);
+ NSS_SETENT(pwentfp,NSLCD_ACTION_PASSWD_ALL);
}
/* read password data from an opened stream */
enum nss_status _nss_ldap_getpwent_r(struct passwd *result,char *buffer,size_t buflen,int *errnop)
{
- NSS_GETENT(read_passwd);
+ NSS_GETENT(pwentfp,read_passwd);
}
/* close the stream opened with setpwent() above */
enum nss_status _nss_ldap_endpwent(void)
{
- NSS_ENDENT();
+ NSS_ENDENT(pwentfp);
}
diff --git a/nss/protocols.c b/nss/protocols.c
index a9e4297..3e4584c 100644
--- a/nss/protocols.c
+++ b/nss/protocols.c
@@ -62,19 +62,18 @@ enum nss_status _nss_ldap_getprotobynumber_r(int number,struct protoent *result,
/* thread-local file pointer to an ongoing request */
static __thread FILE *protoentfp;
-#define fp protoentfp
enum nss_status _nss_ldap_setprotoent(int stayopen)
{
- NSS_SETENT(NSLCD_ACTION_PROTOCOL_ALL);
+ NSS_SETENT(protoentfp,NSLCD_ACTION_PROTOCOL_ALL);
}
enum nss_status _nss_ldap_getprotoent_r(struct protoent *result,char *buffer,size_t buflen,int *errnop)
{
- NSS_GETENT(read_protoent);
+ NSS_GETENT(protoentfp,read_protoent);
}
enum nss_status _nss_ldap_endprotoent(void)
{
- NSS_ENDENT();
+ NSS_ENDENT(protoentfp);
}
diff --git a/nss/rpc.c b/nss/rpc.c
index 968327b..e10fe58 100644
--- a/nss/rpc.c
+++ b/nss/rpc.c
@@ -62,19 +62,18 @@ enum nss_status _nss_ldap_getrpcbynumber_r(int number,struct rpcent *result,char
/* thread-local file pointer to an ongoing request */
static __thread FILE *protoentfp;
-#define fp protoentfp
enum nss_status _nss_ldap_setrpcent(int stayopen)
{
- NSS_SETENT(NSLCD_ACTION_RPC_ALL);
+ NSS_SETENT(protoentfp,NSLCD_ACTION_RPC_ALL);
}
enum nss_status _nss_ldap_getrpcent_r(struct rpcent *result,char *buffer,size_t buflen,int *errnop)
{
- NSS_GETENT(read_rpcent);
+ NSS_GETENT(protoentfp,read_rpcent);
}
enum nss_status _nss_ldap_endrpcent(void)
{
- NSS_ENDENT();
+ NSS_ENDENT(protoentfp);
}
diff --git a/nss/services.c b/nss/services.c
index a024f23..5da0f19 100644
--- a/nss/services.c
+++ b/nss/services.c
@@ -63,19 +63,18 @@ enum nss_status _nss_ldap_getservbyport_r(int port,const char *protocol,struct s
/* thread-local file pointer to an ongoing request */
static __thread FILE *protoentfp;
-#define fp protoentfp
enum nss_status _nss_ldap_setservent(int stayopen)
{
- NSS_SETENT(NSLCD_ACTION_SERVICE_ALL);
+ NSS_SETENT(protoentfp,NSLCD_ACTION_SERVICE_ALL);
}
enum nss_status _nss_ldap_getservent_r(struct servent *result,char *buffer,size_t buflen,int *errnop)
{
- NSS_GETENT(read_servent);
+ NSS_GETENT(protoentfp,read_servent);
}
enum nss_status _nss_ldap_endservent(void)
{
- NSS_ENDENT();
+ NSS_ENDENT(protoentfp);
}
diff --git a/nss/shadow.c b/nss/shadow.c
index 4b2c9e2..b9ebdcb 100644
--- a/nss/shadow.c
+++ b/nss/shadow.c
@@ -60,19 +60,18 @@ enum nss_status _nss_ldap_getspnam_r(const char *name,struct spwd *result,char *
/* thread-local file pointer to an ongoing request */
static __thread FILE *spentfp;
-#define fp spentfp
enum nss_status _nss_ldap_setspent(int stayopen)
{
- NSS_SETENT(NSLCD_ACTION_SHADOW_ALL);
+ NSS_SETENT(spentfp,NSLCD_ACTION_SHADOW_ALL);
}
enum nss_status _nss_ldap_getspent_r(struct spwd *result,char *buffer,size_t buflen,int *errnop)
{
- NSS_GETENT(read_spwd);
+ NSS_GETENT(spentfp,read_spwd);
}
enum nss_status _nss_ldap_endspent(void)
{
- NSS_ENDENT();
+ NSS_ENDENT(spentfp);
}