Article View: news.software.nntp
Article #46047Re: Diablo 2.0 Server questions.
From: Thomas Neumann
Date: Wed, 26 Apr 2000 00:00
Date: Wed, 26 Apr 2000 00:00
236 lines
8422 bytes
8422 bytes
jgreco@ns.sol.net (Joe Greco) writes:
> [...] If you are going to do
> authentication, you can do RADIUS, or flat-file. If you have a lot of
> users, I'd suggest that you commission someone to write up something
> like a Berkeley DB interface. I might be interested in doing that, and
> I'd probably do it fairly cheap if you were willing to donate it back to
> the Diablo source tree.
I've already hacked up auth against a CDB database (see
<URL:http://cr.yp.to/cdb.html> for more info on CDB) which I prefer
because it's very lightweight and allows atomic updates of the
database without having to worry about locking in the diablo
code.
The patch below is against 2.0-BETA3, you need to
download <URL:ftp://cr.yp.to/cdb/cdb-0.55.tar.gz>,
extract it inside the diablo source tree and rename
the "cdb-0.55" dir to just "cdb". The patch is also available
at <URL:http://home.tmr-online.de/tn/diablo-cdb.patch> in
case it somehow gets messed up below ...
diff -r -u3 /tmp/diablo-2.0-BETA03/XMakefile diablo-2.0-BETA03/XMakefile
--- /tmp/diablo-2.0-BETA03/XMakefile Wed Apr 12 00:29:33 2000
+++ diablo-2.0-BETA03/XMakefile Wed Apr 26 17:48:40 2000
@@ -3,6 +3,7 @@
#include "XMakefile.inc"
all:
+ -(cd cdb && make)
(cd lib; xmake all)
(cd filter; xmake all)
(cd dreaderd; xmake all)
@@ -11,6 +12,7 @@
/* (cd contrib; xmake all) */
clean:
+ -(cd cdb && rm -f *.[0oa])
(cd lib; xmake clean)
(cd filter; xmake clean)
(cd dreaderd; xmake clean)
diff -r -u3 /tmp/diablo-2.0-BETA03/XMakefile.inc diablo-2.0-BETA03/XMakefile.inc
--- /tmp/diablo-2.0-BETA03/XMakefile.inc Tue Apr 18 17:28:56 2000
+++ diablo-2.0-BETA03/XMakefile.inc Wed Apr 26 17:49:25 2000
@@ -19,24 +19,24 @@
.set CC cc
#endif
-.set LFLAGS -L$(BD)obj -lfilter -ldiablo -lutil -lm
+.set LFLAGS -L$(BD)obj -L$(BD)cdb -lfilter -ldiablo -lcdb -lutil -lm
.set IDIR /news
.set MDIR /news/man
.set INSTALL install
#ifdef __FreeBSD__
-.set LFLAGS -L$(BD)obj -lfilter -ldiablo -lutil -lm -ldes -lmd -lradius
+.set LFLAGS -L$(BD)obj -L$(BD)cdb -lfilter -ldiablo -lcdb -lutil -lm -ldes -lmd -lradius
#endif
#ifdef __hpux
-.set LFLAGS "-L$(BD)obj" -lfilter -ldiablo -lm
+.set LFLAGS "-L$(BD)obj" "-L$(BD)cdb" -lfilter -ldiablo -lcdb -lm
#endif
#ifdef sun
/*
* some sun systems use -lsocket, some don't. complain to sun
*/
-.set LFLAGS "-L$(BD)obj" -lfilter -ldiablo -lm -lnsl -lsocket -lposix4
+.set LFLAGS "-L$(BD)obj" "-L$(BD)cdb" -lfilter -ldiablo -lcdb -lm -lnsl -lsocket -lposix4
.set LSTATIC
.set INSTALL /usr/ucb/install
#endif
diff -r -u3 /tmp/diablo-2.0-BETA03/dreaderd/defs.h diablo-2.0-BETA03/dreaderd/defs.h
--- /tmp/diablo-2.0-BETA03/dreaderd/defs.h Tue Apr 18 05:08:11 2000
+++ diablo-2.0-BETA03/dreaderd/defs.h Tue Apr 25 09:31:06 2000
@@ -110,8 +110,13 @@
typedef struct AuthDef { /* Define an authentication type */
char au_Name[DEFNAMELEN];
char au_File[255];
+#ifdef CDB_ENABLED
+ char au_Cdb[255];
+#endif
char au_External[255];
+#ifdef RADIUS_ENABLED
char au_Radius[255];
+#endif
char au_User[255];
char au_Pass[255];
char au_Realm[255];
diff -r -u3 /tmp/diablo-2.0-BETA03/dreaderd/dns.c diablo-2.0-BETA03/dreaderd/dns.c
--- /tmp/diablo-2.0-BETA03/dreaderd/dns.c Tue Apr 18 05:08:11 2000
+++ diablo-2.0-BETA03/dreaderd/dns.c Wed Apr 26 17:51:18 2000
@@ -23,13 +23,19 @@
void DnsTest(DnsReq *dreq, DnsRes *dres, char *fqdn, char **ary, const char *ipname);
int fileAuthenticate(char *user, char *pass, char *conf);
+#ifdef RADIUS_ENABLED
int radiusAuthenticate(char *user, char *pass, char *conf);
+#endif
int testForwardLookup(const char *hostName, const struct sockaddr_in *rsin);
void getAuthUser(const struct sockaddr_in *lsin, const struct sockaddr_in *rsin, char *ubuf, int ulen);
int readExactly(int fd, void *buf, int bytes);
void sigSegVDNS(int sigNo);
int readtoeof(int fd, void *buf, int bytes, int secs);
int readAccessLine(FILE *af, char *fname, AccessDef *adef);
+#ifdef CDB_ENABLED
+extern int cdb_seek(int, char*, unsigned int, unsigned int*);
+int cdbAuthenticate(char *user, char *pass, char *conf);
+#endif
int DFd = -1;
MemPool *DnsMemPool;
@@ -155,6 +161,38 @@
logit(LOG_NOTICE, "DNS process exiting n=%d/%d", n, sizeof(dreq));
}
+#ifdef CDB_ENABLED
+/*
+ * Search a CDB database for a matching username/passord
+ *
+ * Returns: -1 failure
+ * 0 success
+ *
+ */
+int cdbAuthenticate(char *user, char *pass, char *conf)
+{
+ unsigned int pwlen = 0;
+ int r = -1, fd = open(conf, O_RDONLY);
+ if (fd < 0) {
+ logit(LOG_ERR, "unable to open auth cdb %s", conf);
+ return(-1);
+ }
+ if (cdb_seek(fd, user, strlen(user), &pwlen) > 0) {
+ if (pwlen > 0) {
+ char pw[64+1];
+ if (pwlen > sizeof(pw)-1) pwlen = sizeof(pw)-1;
+ if (read(fd, pw, pwlen) == pwlen) {
+ pw[pwlen] = 0;
+ if (!strcmp(pw, pass)) r = 0;
+ }
+ }
+ }
+ close(fd);
+ return r;
+}
+#endif /* CDB_ENABLED */
+
+
/*
* Search a file of username:password pairs for a matching username/passord
*
@@ -444,6 +482,9 @@
if (*dres->dr_AuthDef->au_Radius ||
*dres->dr_AuthDef->au_File ||
+#ifdef CDB_ENABLED
+ *dres->dr_AuthDef->au_Cdb ||
+#endif
*dres->dr_AuthDef->au_External ||
*dres->dr_AuthDef->au_User)
AuthNeeded = 1;
@@ -561,6 +602,27 @@
printf("Authentication via file FAILED\n");
}
}
+
+#ifdef CDB_ENABLED
+ /*
+ * Check for the user+pass in a CDB
+ */
+
+ if (authok && *dres->dr_AuthDef->au_Cdb && *user &&
+ *dreq->dr_AuthPass) {
+ if (cdbAuthenticate(user, dreq->dr_AuthPass,
+ dres->dr_AuthDef->au_Cdb) == 0) {
+ Authenticated = 1;
+ if (DebugOpt)
+ printf("Authenticated via cdb\n");
+ } else {
+ Authenticated = -1;
+ if (DebugOpt)
+ printf("Authentication via cdb FAILED\n");
+ }
+ }
+#endif /* CDB_ENABLED */
+
}
if (!AuthNeeded ||
/* AUTHINFO and matched */
@@ -1205,6 +1267,12 @@
strncpy(authdef.au_File, val, sizeof(authdef.au_File) - 1);
continue;
}
+#ifdef CDB_ENABLED
+ if (*val && strcmp(opt, "cdb") == 0) {
+ strncpy(authdef.au_Cdb, val, sizeof(authdef.au_Cdb) - 1);
+ continue;
+ }
+#endif
if (*val && strcmp(opt, "external") == 0) {
strncpy(authdef.au_External, val, sizeof(authdef.au_External) - 1);
continue;
@@ -1786,8 +1854,13 @@
printf(" vs_Interface: %ld\n", dres->dr_VServerDef->vs_Interface);
printf("au_Name: %s\n", dres->dr_AuthDef->au_Name);
printf(" au_File: %s\n", dres->dr_AuthDef->au_File);
+#ifdef CDB_ENABLED
+ printf(" au_Cdb: %s\n", dres->dr_AuthDef->au_Cdb);
+#endif
printf(" au_External: %s\n", dres->dr_AuthDef->au_External);
+#ifdef RADIUS_ENABLED
printf(" au_Radius: %s\n", dres->dr_AuthDef->au_Radius);
+#endif
printf(" au_User: %s\n", dres->dr_AuthDef->au_User);
printf(" au_Pass: %s\n", dres->dr_AuthDef->au_Pass);
printf(" au_Realm: %s\n", dres->dr_AuthDef->au_Realm);
Only in diablo-2.0-BETA03/dreaderd: dns.c~
diff -r -u3 /tmp/diablo-2.0-BETA03/lib/vendor.h diablo-2.0-BETA03/lib/vendor.h
--- /tmp/diablo-2.0-BETA03/lib/vendor.h Mon Apr 10 18:45:18 2000
+++ diablo-2.0-BETA03/lib/vendor.h Wed Apr 26 17:49:54 2000
@@ -109,3 +109,10 @@
*/
#undef RADIUS_ENABLED
+
+/*
+ * Enable CDB authentication.
+ */
+
+#undef CDB_ENABLED
+
Technical Details
Message-ID:
<86em7sdf9g.fsf@smart.ruhr.de>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mailReferences:
<8F2172A5Fringdahlusenetnserve@209.247.210.100> <3905d1ac$0$63041@news.execpc.com>Show Full Headers
Complete Article Headers
Message-ID: <86em7sdf9g.fsf@smart.ruhr.de> Subject: Re: Diablo 2.0 Server questions. Date: Wed, 26 Apr 2000 00:00:00 +0000 From: Thomas Neumann <tom@smart.ruhr.de> References: <8F2172A5Fringdahlusenetnserve@209.247.210.100> <3905d1ac$0$63041@news.execpc.com> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail X-Deja-AN: 615951408 Sender: tn@smart.ruhr.de X-Sender: 320056444537-0001@t-dialin.net Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@t-online.de X-Trace: news02.btx.dtag.de 956764832 24387 320056444537-0001 000426 16:00:32 Organization: T-Online Mime-Version: 1.0 User-Agent: Gnus/5.070099 (Pterodactyl Gnus v0.99) Emacs/20.5 Newsgroups: news.software.nntp