summaryrefslogtreecommitdiffstats
path: root/userdb/userdb2.c
diff options
context:
space:
mode:
Diffstat (limited to 'userdb/userdb2.c')
-rw-r--r--userdb/userdb2.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/userdb/userdb2.c b/userdb/userdb2.c
new file mode 100644
index 0000000..fd904c1
--- /dev/null
+++ b/userdb/userdb2.c
@@ -0,0 +1,57 @@
+/*
+** Copyright 1998 - 2007 Double Precision, Inc.
+** See COPYING for distribution information.
+*/
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include "dbobj.h"
+#include "userdb.h"
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+
+
+extern int userdb_debug_level;
+
+char *userdbshadow(const char *sh, const char *u)
+{
+struct dbobj d;
+char *p,*q;
+size_t l;
+
+ dbobj_init(&d);
+
+ if (dbobj_open(&d, sh, "R"))
+ {
+ if (userdb_debug_level)
+ fprintf(stderr,
+ "DEBUG: userdbshadow: unable to open %s\n", sh);
+ return (0);
+ }
+
+ q=dbobj_fetch(&d, u, strlen(u), &l, "");
+ dbobj_close(&d);
+ if (!q)
+ {
+ if (userdb_debug_level)
+ fprintf(stderr,
+ "DEBUG: userdbshadow: entry not found\n");
+ errno=ENOENT;
+ return(0);
+ }
+
+ p=malloc(l+1);
+ if (!p)
+ {
+ free(q);
+ return (0);
+ }
+
+ if (l) memcpy(p, q, l);
+ free(q);
+ p[l]=0;
+ return (p);
+}