summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2006-11-27 09:59:19 +0000
committerArthur de Jong <arthur@arthurdejong.org>2006-11-27 09:59:19 +0000
commitd22651f5099312abb620bba25af9bc8bc3a520a1 (patch)
treee3167edd02b709dd2edf16012f906814d59c4744
parente23505ff456b72aa8c1fe3e7105f22c8f9331c91 (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
-rw-r--r--Makefile.am4
-rw-r--r--nslcd-client.c62
-rw-r--r--nslcd-client.h57
-rw-r--r--nss/Makefile.am2
-rw-r--r--nss/aliases.c1
-rw-r--r--nss/common.c37
-rw-r--r--nss/common.h39
-rw-r--r--nss/ethers.c1
-rw-r--r--nss/group.c1
-rw-r--r--nss/hosts.c1
-rw-r--r--nss/netgroup.c1
-rw-r--r--nss/networks.c1
-rw-r--r--nss/passwd.c1
-rw-r--r--nss/protocols.c1
-rw-r--r--nss/rpc.c1
-rw-r--r--nss/services.c1
-rw-r--r--nss/shadow.c1
17 files changed, 79 insertions, 133 deletions
diff --git a/Makefile.am b/Makefile.am
index c88b3d0..eb65e0f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -30,7 +30,7 @@ EXTRA_DIST = ChangeLog \
ldap.conf \
debian doc exports.linux nss_ldap.5 tests
-nss_ldap_so_SOURCES = nslcd-client.c nslcd-client.h nslcd.h
+nss_ldap_so_SOURCES = nslcd.h
nss_ldap_so_LDADD = nss/libnss.a
nss_ldap_so_LDFLAGS = @nss_ldap_so_LDFLAGS@
@@ -40,7 +40,7 @@ nslcd_SOURCES = nslcd.c nslcd.h \
xmalloc.c xmalloc.h
nslcd_LDADD = server/libserver.a
-testnss_SOURCES = testnss.c nslcd-client.c nslcd-client.h nslcd.h
+testnss_SOURCES = testnss.c nslcd.h
testnss_LDADD = nss/libnss.a
NSS_LDAP_PATH_CONF = @NSS_LDAP_PATH_CONF@
diff --git a/nslcd-client.c b/nslcd-client.c
deleted file mode 100644
index c5ac9f9..0000000
--- a/nslcd-client.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- nslcd-client.c - request/response functions for nslcd communication
-
- Copyright (C) 2006 West Consulting
- Copyright (C) 2006 Arthur de Jong
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with this library; if not, write to the Free
- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
- MA 02110-1301 USA
-*/
-
-#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 "nslcd-client.h"
-
-
-/* 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/nslcd-client.h b/nslcd-client.h
deleted file mode 100644
index f67ea41..0000000
--- a/nslcd-client.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- nslcd-client.c - request/response functions for nslcd communication
-
- Copyright (C) 2006 West Consulting
- Copyright (C) 2006 Arthur de Jong
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with this library; if not, write to the Free
- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
- MA 02110-1301 USA
-*/
-
-#ifndef _NSLCD_CLIENT_H
-#define _NSLCD_CLIENT_H 1
-
-#include <stdio.h>
-
-#include "nslcd.h"
-#include "nslcd-common.h"
-
-/* returns a socket to the server or NULL on error (see errno),
- socket should be closed with fclose() */
-FILE *nslcd_client_open(void);
-
-/* open a client socket */
-#define OPEN_SOCK(fp) \
- if ((fp=nslcd_client_open())==NULL) \
- { ERROR_OUT_OPENERROR }
-
-#define WRITE_REQUEST(fp,req) \
- WRITE_INT32(fp,NSLCD_VERSION) \
- WRITE_INT32(fp,req)
-
-#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) }
-
-#define READ_RESPONSE_CODE(fp) \
- READ_TYPE(fp,tmpint32,int32_t); \
- if (tmpint32!=NSLCD_RESULT_SUCCESS) \
- { ERROR_OUT_NOSUCCESS(fp,tmpint32) }
-
-#endif /* not _NSLCD_CLIENT_H */
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 */
diff --git a/nss/rpc.c b/nss/rpc.c
index e10fe58..86f74cb 100644
--- a/nss/rpc.c
+++ b/nss/rpc.c
@@ -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. */