aboutsummaryrefslogtreecommitdiffstats
path: root/modules/lookup_yp.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>1997-10-06 21:05:49 +0000
committerH. Peter Anvin <hpa@zytor.com>1997-10-06 21:05:49 +0000
commitbddd43e289c8b8b62d7cb3f1f7eb27ca67cae28e (patch)
treeaac5e4a4b924cb13a54cc0760e99f349ea36bd12 /modules/lookup_yp.c
downloadautofs3-bddd43e289c8b8b62d7cb3f1f7eb27ca67cae28e.tar.gz
autofs3-bddd43e289c8b8b62d7cb3f1f7eb27ca67cae28e.tar.xz
autofs3-bddd43e289c8b8b62d7cb3f1f7eb27ca67cae28e.zip
Initial revision
Diffstat (limited to 'modules/lookup_yp.c')
-rw-r--r--modules/lookup_yp.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/modules/lookup_yp.c b/modules/lookup_yp.c
new file mode 100644
index 0000000..93d7c1b
--- /dev/null
+++ b/modules/lookup_yp.c
@@ -0,0 +1,106 @@
+/*
+ * lookup_yp.c
+ *
+ * Module for Linux automountd to access a YP (NIS) automount map
+ */
+
+#include <stdio.h>
+#include <malloc.h>
+#include <errno.h>
+#include <unistd.h>
+#include <syslog.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <rpc/rpc.h>
+#include <rpc/xdr.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+
+#define MODULE_LOOKUP
+#include "automount.h"
+
+#define MAPFMT_DEFAULT "sun"
+
+#define MODPREFIX "lookup(yp): "
+
+struct lookup_context {
+ const char *domainname;
+ const char *mapname;
+ struct parse_mod *parse;
+};
+
+int lookup_version = AUTOFS_LOOKUP_VERSION; /* Required by protocol */
+
+int lookup_init(const char *mapfmt, int argc, const char * const *argv,
+ void **context)
+{
+ struct lookup_context *ctxt;
+ int err;
+
+ if ( !(*context = ctxt = malloc(sizeof(struct lookup_context))) ) {
+ syslog(LOG_CRIT, MODPREFIX "%m");
+ return 1;
+ }
+
+ if ( argc < 1 ) {
+ syslog(LOG_CRIT, MODPREFIX "No map name");
+ return 1;
+ }
+ ctxt->mapname = argv[0];
+
+ /* This should, but doesn't, take a const char ** */
+ err = yp_get_default_domain((char **) &ctxt->domainname);
+ if ( err ) {
+ syslog(LOG_CRIT, MODPREFIX "map %s: %s\n", ctxt->mapname, yperr_string(err));
+ return 1;
+ }
+
+ if ( !mapfmt )
+ mapfmt = MAPFMT_DEFAULT;
+
+ return !(ctxt->parse = open_parse(mapfmt,MODPREFIX,argc-1,argv+1));
+}
+
+int lookup_mount(const char *root, const char *name,
+ int name_len, void *context)
+{
+ struct lookup_context *ctxt = (struct lookup_context *) context;
+ char *mapent;
+ int mapent_len;
+ int err, rv;
+
+ syslog(LOG_DEBUG, MODPREFIX "looking up %s", name);
+
+ /* For reasons unknown, the standard YP definitions doesn't define input
+ strings as const char *. However, my understanding is that they will
+ not be modified by the library. */
+ err = yp_match((char *) ctxt->domainname, (char *) ctxt->mapname,
+ (char *) name, name_len, &mapent, &mapent_len);
+ if ( err == YPERR_KEY ) {
+ /* Try to get the "*" entry if there is one - note that we *don't*
+ modify "name" so & -> the name we used, not "*" */
+ err = yp_match((char *) ctxt->domainname, (char *) ctxt->mapname,
+ "*", 1, &mapent, &mapent_len);
+ }
+ if ( err ) {
+ syslog(LOG_NOTICE, MODPREFIX "lookup for %s failed: %s", name, yperr_string(err));
+ return 1;
+ }
+
+ mapent[mapent_len] = '\0';
+
+ syslog(LOG_DEBUG, MODPREFIX "%s -> %s", name, mapent);
+
+ rv = ctxt->parse->parse_mount(root,name,name_len,mapent,ctxt->parse->context);
+ free(mapent);
+ return rv;
+}
+
+int lookup_done(void *context)
+{
+ struct lookup_context *ctxt = (struct lookup_context *) context;
+ int rv = close_parse(ctxt->parse);
+ free(ctxt);
+ return rv;
+}