diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2006-11-27 10:59:19 +0100 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2006-11-27 10:59:19 +0100 |
commit | d22651f5099312abb620bba25af9bc8bc3a520a1 (patch) | |
tree | e3167edd02b709dd2edf16012f906814d59c4744 /nss | |
parent | e23505ff456b72aa8c1fe3e7105f22c8f9331c91 (diff) |
get rid of nslcd-client.{c,h} and move it to nss/common.{c,h}, this ensures that all code that is needed for the nss part is in the nss directory
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/libnss_ldapd@127 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'nss')
-rw-r--r-- | nss/Makefile.am | 2 | ||||
-rw-r--r-- | nss/aliases.c | 1 | ||||
-rw-r--r-- | nss/common.c | 37 | ||||
-rw-r--r-- | nss/common.h | 39 | ||||
-rw-r--r-- | nss/ethers.c | 1 | ||||
-rw-r--r-- | nss/group.c | 1 | ||||
-rw-r--r-- | nss/hosts.c | 1 | ||||
-rw-r--r-- | nss/netgroup.c | 1 | ||||
-rw-r--r-- | nss/networks.c | 1 | ||||
-rw-r--r-- | nss/passwd.c | 1 | ||||
-rw-r--r-- | nss/protocols.c | 1 | ||||
-rw-r--r-- | nss/rpc.c | 1 | ||||
-rw-r--r-- | nss/services.c | 1 | ||||
-rw-r--r-- | nss/shadow.c | 1 |
14 files changed, 77 insertions, 12 deletions
diff --git a/nss/Makefile.am b/nss/Makefile.am index f128466..655e94d 100644 --- a/nss/Makefile.am +++ b/nss/Makefile.am @@ -20,7 +20,7 @@ noinst_LIBRARIES = libnss.a -libnss_a_SOURCES = common.c common.h prototypes.h ../nslcd-client.h \ +libnss_a_SOURCES = common.c common.h prototypes.h \ ../nslcd.h ../nslcd-common.h \ aliases.c ethers.c group.c hosts.c netgroup.c \ networks.c passwd.c protocols.c rpc.c services.c \ diff --git a/nss/aliases.c b/nss/aliases.c index 50a4fd9..5bc0a9e 100644 --- a/nss/aliases.c +++ b/nss/aliases.c @@ -27,7 +27,6 @@ #include <errno.h> #include "prototypes.h" -#include "nslcd-client.h" #include "common.h" /* macros for expanding the LDF_ALIAS macro */ diff --git a/nss/common.c b/nss/common.c index a1fc34f..ab8fb40 100644 --- a/nss/common.c +++ b/nss/common.c @@ -22,6 +22,14 @@ #include "config.h" +#include <stdint.h> +#include <unistd.h> +#include <stdio.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <errno.h> #include <nss.h> #include "nslcd.h" @@ -39,3 +47,32 @@ enum nss_status nslcd2nss(int code) default: return NSS_STATUS_UNAVAIL; } } + +/* returns a socket to the server or NULL on error (see errno), + socket should be closed with fclose() */ +FILE *nslcd_client_open() +{ + int sock; + struct sockaddr_un addr; + FILE *fp; + /* create a socket */ + if ( (sock=socket(PF_UNIX,SOCK_STREAM,0))<0 ) + return NULL; + /* create socket address structure */ + addr.sun_family=AF_UNIX; + strcpy(addr.sun_path,NSLCD_SOCKET); + /* connect to the socket */ + if (connect(sock,(struct sockaddr *)&addr,sizeof(struct sockaddr_un))<0) + { + close(sock); + return NULL; + } + /* create a stream object */ + if ((fp=fdopen(sock,"w+"))==NULL) + { + close(sock); + return NULL; + } + /* return the stream */ + return fp; +} diff --git a/nss/common.h b/nss/common.h index 8255035..cf0c7e1 100644 --- a/nss/common.h +++ b/nss/common.h @@ -23,12 +23,51 @@ #ifndef _NSS_COMMON_H #define _NSS_COMMON_H 1 +#include <stdio.h> #include <nss.h> +#include "nslcd.h" +#include "nslcd-common.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); +/* returns a socket to the server or NULL on error (see errno), + socket should be closed with fclose() */ +FILE *nslcd_client_open(void); + +/* These are macors for performing common operations in the nslcd + request/response protocol, they are an extension for client + applications to the macros defined in nslcd-common.h. */ + +/* Open a client socket. */ +#define OPEN_SOCK(fp) \ + if ((fp=nslcd_client_open())==NULL) \ + { ERROR_OUT_OPENERROR } + +/* Write a request header with a request code. */ +#define WRITE_REQUEST(fp,req) \ + WRITE_INT32(fp,NSLCD_VERSION) \ + WRITE_INT32(fp,req) + +/* Read a response header and check that the returned request + code equals the expected code. */ +#define READ_RESPONSEHEADER(fp,req) \ + READ_TYPE(fp,tmpint32,int32_t); \ + if (tmpint32!=NSLCD_VERSION) \ + { ERROR_OUT_READERROR(fp) } \ + READ_TYPE(fp,tmpint32,int32_t); \ + if (tmpint32!=(req)) \ + { ERROR_OUT_READERROR(fp) } + +/* Read the response code (the result code of the query) from + the stream. */ +#define READ_RESPONSE_CODE(fp) \ + READ_TYPE(fp,tmpint32,int32_t); \ + if (tmpint32!=NSLCD_RESULT_SUCCESS) \ + { ERROR_OUT_NOSUCCESS(fp,tmpint32) } + /* 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 diff --git a/nss/ethers.c b/nss/ethers.c index 6174794..de3f050 100644 --- a/nss/ethers.c +++ b/nss/ethers.c @@ -27,7 +27,6 @@ #include <errno.h> #include "prototypes.h" -#include "nslcd-client.h" #include "common.h" /* macros for expanding the LDF_ETHER macro */ diff --git a/nss/group.c b/nss/group.c index 04c45a8..31141cb 100644 --- a/nss/group.c +++ b/nss/group.c @@ -27,7 +27,6 @@ #include <errno.h> #include "prototypes.h" -#include "nslcd-client.h" #include "common.h" /* macros for expanding the LDF_GROUP macro */ diff --git a/nss/hosts.c b/nss/hosts.c index 2015488..9f641cc 100644 --- a/nss/hosts.c +++ b/nss/hosts.c @@ -27,7 +27,6 @@ #include <errno.h> #include "prototypes.h" -#include "nslcd-client.h" #include "common.h" /* Redifine some ERROR_OUT macros as we also want to set h_errnop. */ diff --git a/nss/netgroup.c b/nss/netgroup.c index 51b7f80..1ea602e 100644 --- a/nss/netgroup.c +++ b/nss/netgroup.c @@ -28,7 +28,6 @@ #include <errno.h> #include "prototypes.h" -#include "nslcd-client.h" #include "common.h" static enum nss_status read_netgrent( diff --git a/nss/networks.c b/nss/networks.c index a8c0d3a..4290c3e 100644 --- a/nss/networks.c +++ b/nss/networks.c @@ -27,7 +27,6 @@ #include <errno.h> #include "prototypes.h" -#include "nslcd-client.h" #include "common.h" /* Redifine some ERROR_OUT macros as we also want to set h_errnop. */ diff --git a/nss/passwd.c b/nss/passwd.c index 4ce8116..ee5e75a 100644 --- a/nss/passwd.c +++ b/nss/passwd.c @@ -27,7 +27,6 @@ #include <errno.h> #include "prototypes.h" -#include "nslcd-client.h" #include "common.h" /* Macros for expanding the LDF_PASSWD macro. */ diff --git a/nss/protocols.c b/nss/protocols.c index 3e4584c..d186a05 100644 --- a/nss/protocols.c +++ b/nss/protocols.c @@ -27,7 +27,6 @@ #include <errno.h> #include "prototypes.h" -#include "nslcd-client.h" #include "common.h" /* macros for expanding the LDF_PROTOCOL macro */ @@ -27,7 +27,6 @@ #include <errno.h> #include "prototypes.h" -#include "nslcd-client.h" #include "common.h" /* macros for expanding the LDF_RPC macro */ diff --git a/nss/services.c b/nss/services.c index 9f6047a..75b807e 100644 --- a/nss/services.c +++ b/nss/services.c @@ -27,7 +27,6 @@ #include <errno.h> #include "prototypes.h" -#include "nslcd-client.h" #include "common.h" /* macros for expanding the LDF_SERVICE macro */ diff --git a/nss/shadow.c b/nss/shadow.c index b9ebdcb..440e97b 100644 --- a/nss/shadow.c +++ b/nss/shadow.c @@ -27,7 +27,6 @@ #include <errno.h> #include "prototypes.h" -#include "nslcd-client.h" #include "common.h" /* Macros for expanding the LDF_SHADOW macro. */ |