Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/nss
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2006-11-14 15:40:51 +0100
committerArthur de Jong <arthur@arthurdejong.org>2006-11-14 15:40:51 +0100
commit96967f6d0d79d20de09033c1e63c24c772a6c063 (patch)
treea08cc58073fd4f08f8dc36642c14f245eb8e9641 /nss
parentd1eedf789d383b1a654f9f13191f6bae015faf2b (diff)
implement automounter maps lookups
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/libnss_ldapd@88 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'nss')
-rw-r--r--nss/Makefile.am4
-rw-r--r--nss/automount.c154
-rw-r--r--nss/prototypes.h4
3 files changed, 158 insertions, 4 deletions
diff --git a/nss/Makefile.am b/nss/Makefile.am
index 6f671f9..41c596e 100644
--- a/nss/Makefile.am
+++ b/nss/Makefile.am
@@ -22,5 +22,5 @@ noinst_LIBRARIES = libnss.a
libnss_a_SOURCES = common.c common.h prototypes.h ../nslcd-client.h \
../nslcd.h ../nslcd-common.h \
- aliases.c ethers.c group.c hosts.c passwd.c \
- shadow.c
+ aliases.c automount.c ethers.c group.c hosts.c \
+ passwd.c shadow.c
diff --git a/nss/automount.c b/nss/automount.c
new file mode 100644
index 0000000..d160e11
--- /dev/null
+++ b/nss/automount.c
@@ -0,0 +1,154 @@
+/*
+ automount.c - NSS lookup functions for automounter maps
+
+ 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 "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <nss.h>
+#include <errno.h>
+
+#include "prototypes.h"
+#include "nslcd-client.h"
+#include "common.h"
+
+/* macros for expanding the LDF_AUTOMOUNT macro */
+#define LDF_STRING(field) READ_STRING_BUF(fp,field)
+#define AUTOMOUNT_KEY *canon_key
+#define AUTOMOUNT_INFO *value
+
+#define AUTOMOUNT_CONTEXT_MAGIC 0x83451830
+
+struct automount_context
+{
+ char *mapname;
+ FILE *fp; /* for getautomntent() call */
+ int32_t magic; /* for sanity checks */
+};
+
+/* this function initiates a structure for doing queries
+ using getautomountbyname() and getautomountent() */
+enum nss_status _nss_ldap_setautomntent(
+ const char *mapname,void **private)
+{
+ struct automount_context *context;
+ /* allocate memory */
+ context=malloc(sizeof(struct automount_context));
+ if (context==NULL)
+ return NSS_STATUS_UNAVAIL;
+ /* store mapname */
+ context->mapname=strdup(mapname);
+ if (context->mapname==NULL)
+ {
+ free(context);
+ return NSS_STATUS_UNAVAIL;
+ }
+ /* clear file handle and store magic */
+ context->fp=NULL;
+ context->magic=AUTOMOUNT_CONTEXT_MAGIC;
+ /* return context */
+ *private=context;
+ return NSS_STATUS_SUCCESS;
+}
+
+/* this searches for an automounter key within the automounter
+ map initialized by setautomountent() */
+enum nss_status _nss_ldap_getautomntbyname_r(
+ void *private,const char *key,const char **canon_key,
+ const char **value,char *buffer,size_t buflen,int *errnop)
+{
+ struct automount_context *context;
+ FILE *fp;
+ size_t bufptr=0;
+ int32_t tmpint32;
+ /* check context */
+ context=(struct automount_context *)private;
+ if ((context==NULL)||(context->magic!=AUTOMOUNT_CONTEXT_MAGIC))
+ return NSS_STATUS_UNAVAIL;
+ /* open socket and write request */
+ OPEN_SOCK(fp);
+ WRITE_REQUEST(fp,NSLCD_ACTION_AUTOMOUNT_BYNAME);
+ WRITE_STRING(fp,context->mapname);
+ WRITE_STRING(fp,key);
+ WRITE_FLUSH(fp);
+ /* read response header */
+ READ_RESPONSEHEADER(fp,NSLCD_ACTION_AUTOMOUNT_BYNAME);
+ /* read response */
+ READ_RESPONSE_CODE(fp);
+ LDF_AUTOMOUNT;
+ /* 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;
+ /* 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)
+ {
+ /* open a new stream and write the request */
+ OPEN_SOCK(fp);
+ WRITE_REQUEST(fp,NSLCD_ACTION_AUTOMOUNT_ALL);
+ WRITE_FLUSH(fp);
+ /* read response header */
+ READ_RESPONSEHEADER(fp,NSLCD_ACTION_AUTOMOUNT_ALL);
+ }
+ /* read a response */
+ READ_RESPONSE_CODE(fp);
+ LDF_AUTOMOUNT;
+ return NSS_STATUS_SUCCESS;
+}
+
+#undef fp
+
+enum nss_status _nss_ldap_endautomntent(void **private)
+{
+ struct automount_context *context;
+ /* check private */
+ if (private==NULL)
+ return NSS_STATUS_UNAVAIL;
+ /* check context */
+ context=(struct automount_context *)*private;
+ if ((context==NULL)||(context->magic!=AUTOMOUNT_CONTEXT_MAGIC))
+ return NSS_STATUS_UNAVAIL;
+ /* close any connections */
+ if (context->fp!=NULL)
+ fclose(context->fp);
+ /* free memory */
+ free(context->mapname);
+ free(context);
+ /* invalidate reference */
+ *private=NULL;
+ /* we're done */
+ return NSS_STATUS_SUCCESS;
+}
diff --git a/nss/prototypes.h b/nss/prototypes.h
index 4ac5eba..5cb5f22 100644
--- a/nss/prototypes.h
+++ b/nss/prototypes.h
@@ -57,9 +57,9 @@ enum nss_status _nss_ldap_getaliasent_r(struct aliasent *result,char *buffer,siz
enum nss_status _nss_ldap_endaliasent(void);
/* automount - automounter maps */
-enum nss_status _nss_ldap_getautomntbyname_r(void *private,const char *key,const char **canon_key,const char **value,char *buffer,size_t buflen,int *errnop);
enum nss_status _nss_ldap_setautomntent(const char *mapname,void **private);
-enum nss_status _nss_ldap_getautomntent_r(void *private,const char **key,const char **value,char *buffer,size_t buflen,int *errnop);
+enum nss_status _nss_ldap_getautomntbyname_r(void *private,const char *key,const char **canon_key,const char **value,char *buffer,size_t buflen,int *errnop);
+enum nss_status _nss_ldap_getautomntent_r(void *private,const char **canon_key,const char **value,char *buffer,size_t buflen,int *errnop);
enum nss_status _nss_ldap_endautomntent(void **private);
/* ethers - ethernet numbers */