1999-01-04 04:56:48 +00:00
|
|
|
--- builddbm.c.orig Tue Jun 2 09:32:29 1998
|
|
|
|
+++ builddbm.c Thu Dec 3 13:18:30 1998
|
|
|
|
@@ -32,6 +32,10 @@
|
1996-09-24 15:12:01 +00:00
|
|
|
static char sccsid[] =
|
|
|
|
"@(#)builddbm.c 1.4 Copyright 1992 Livingston Enterprises Inc";
|
|
|
|
|
|
|
|
+#if defined(_HAVE_PARAM_H)
|
|
|
|
+#include <sys/param.h>
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
#if defined(SOLARIS)
|
|
|
|
# include <sys/uio.h>
|
|
|
|
# include <unistd.h>
|
1999-01-04 04:56:48 +00:00
|
|
|
@@ -39,7 +43,11 @@
|
1996-09-24 15:12:01 +00:00
|
|
|
# include <fcntl.h>
|
|
|
|
# include </usr/ucbinclude/dbm.h>
|
|
|
|
#else
|
|
|
|
+#if defined(USE_NDBM)
|
|
|
|
+# include <ndbm.h>
|
|
|
|
+#else
|
|
|
|
# include <dbm.h>
|
|
|
|
+#endif
|
|
|
|
#endif /* SOLARIS */
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
1999-01-04 04:56:48 +00:00
|
|
|
@@ -61,8 +69,13 @@
|
1996-09-24 15:12:01 +00:00
|
|
|
char *progname;
|
|
|
|
char *radius_dir;
|
|
|
|
char *radius_users;
|
|
|
|
+#if defined(USE_NDBM)
|
|
|
|
+char dbfile[256];
|
|
|
|
+DBM *dbp;
|
|
|
|
+#else
|
|
|
|
char pagfile[256];
|
|
|
|
char dirfile[256];
|
|
|
|
+#endif
|
|
|
|
char dbmname[256];
|
1999-01-04 04:56:48 +00:00
|
|
|
FILE *userfp;
|
1996-09-24 15:12:01 +00:00
|
|
|
FILE *errf;
|
1999-01-04 04:56:48 +00:00
|
|
|
@@ -126,6 +139,20 @@
|
1996-09-24 15:12:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+#if defined(USE_NDBM)
|
|
|
|
+ sprintf(dbfile, "%s/%s.db", radius_dir, radius_users);
|
|
|
|
+ if((fd = open(dbfile, O_WRONLY | O_CREAT | O_TRUNC, 0600)) < 0) {
|
|
|
|
+ fprintf(errf, "%s: Couldn't open %s for writing\n",
|
|
|
|
+ progname, dbfile);
|
|
|
|
+ exit(-1);
|
|
|
|
+ }
|
|
|
|
+ close(fd);
|
|
|
|
+ sprintf(dbmname, "%s/%s", radius_dir, radius_users);
|
|
|
|
+ if(!(dbp=dbm_open(dbmname, O_RDWR | O_CREAT | O_TRUNC, 0600))) {
|
|
|
|
+ fprintf(errf, "%s: Couldn't dbm_open(%s)\n",
|
|
|
|
+ progname, dbmname);
|
|
|
|
+ }
|
|
|
|
+#else
|
|
|
|
sprintf(pagfile, "%s/%s.pag", radius_dir, radius_users);
|
|
|
|
if((fd = open(pagfile, O_WRONLY | O_CREAT | O_TRUNC, 0600)) < 0) {
|
|
|
|
fprintf(errf, "%s: Couldn't open %s for writing\n",
|
1999-01-04 04:56:48 +00:00
|
|
|
@@ -145,7 +172,7 @@
|
1996-09-24 15:12:01 +00:00
|
|
|
fprintf(errf, "%s: Couldn't dbminit(%s)\n", progname, dbmname);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
-
|
|
|
|
+#endif
|
1999-01-04 04:56:48 +00:00
|
|
|
userfp = (FILE *)NULL;
|
1996-09-24 15:12:01 +00:00
|
|
|
curParseLine = 0;
|
1999-01-04 04:56:48 +00:00
|
|
|
while(user_read(&userfp, name, content) == 0) {
|
|
|
|
@@ -155,7 +182,11 @@
|
1996-09-24 15:12:01 +00:00
|
|
|
}
|
|
|
|
named.dptr = name;
|
|
|
|
named.dsize = strlen(name)+1;
|
|
|
|
+#if defined(USE_NDBM)
|
|
|
|
+ contentd = dbm_fetch(dbp,named);
|
|
|
|
+#else
|
|
|
|
contentd = fetch(named);
|
|
|
|
+#endif
|
|
|
|
if(contentd.dsize != 0) { /* name found */
|
|
|
|
warn("Skipping duplicate record\n\tfor user '%s'", name);
|
|
|
|
continue;
|
1999-01-04 04:56:48 +00:00
|
|
|
@@ -164,13 +195,21 @@
|
1996-09-24 15:12:01 +00:00
|
|
|
named.dsize = strlen(name)+1;
|
|
|
|
contentd.dptr = content;
|
|
|
|
contentd.dsize = strlen(content)+1;
|
|
|
|
+#if defined(USE_NDBM)
|
|
|
|
+ if(dbm_store(dbp, named, contentd, DBM_INSERT) < 0) {
|
|
|
|
+#else
|
|
|
|
if(store(named, contentd) != 0) {
|
|
|
|
+#endif
|
|
|
|
fprintf(errf, "%s: Couldn't store datum for %s\n",
|
|
|
|
progname, name);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+#if defined(USE_NDBM)
|
|
|
|
+ dbm_close(dbp);
|
|
|
|
+#else
|
|
|
|
dbmclose();
|
|
|
|
+#endif
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|