From ryan@pcslink.com Fri Jul 10 16:18:25 1998 Date: Fri, 10 Jul 1998 13:14:18 -0700 (MST) From: Ryan Mooney To: chris@westnet.com Subject: Virtual Popper, the saga continues I found what appears to be a bug in some versions of the ndbm compatibility part of the gdbm. Basically I reduced the code down to a pretty simple open, insert, fetch. The fetch would consistently core dump. As such I've written an alternate version of the pop_virtualh.c file that uses the "NEWDB" (#include ) version of the dbm library. If anyone is having Sig 11 problems in the dbm_fetch routing, they should use this file instead. I've only verified that the problem exists on some FreeBSD releases, but I'd be suprised if no one else has a problem.... NOTE: This isn't the whole patch, apply the regular patch first, and THEN replace the pop_virtualh.c file with this file. ---------------------------------------------------------- /* ** Free Mod, Copyright Abandoned. ** Distribute Freely. ** Written by Ryan Mooney (ryan@pcslink.com) to add virtual Host ** Support to the Qualcomm Popper Daemon on Mon Feb 17 MST 1997 ** ** Use at your own risk, no warranty is implied or granted, this ** code has not been thoroughly tested and may have bugs, it may ** destroy your entire system, it may contain unsuspected worms and ** take over all the computers in your company and mail the little ** green men from outer space your password file. If you are uncomfortable ** with this write your own damn code, and don't blame me. ** ** Loosely based on code included in the other popper files: ** Copyright (c) 1990 Regents of the University of California. ** */ #include "config.h" #ifdef VIRTUAL_SERVER #define NEWDB #undef NDBM #ifndef lint static char copyright[] = "CopyRight Abandoned 1997"; static char SccsId[] = "DO YOUR SCCS THING HERE!!!!"; #endif /* not lint */ #include #include #include #if defined(SOLARIS2) || defined(SYSV) || defined(AIX) # include #else # include #endif #if defined(SOLARIS2) || defined(UNIXWARE) || defined(AIX) || defined(PTX) \ || defined(AUX) || defined(POPSCO) || defined(OSF1) || defined(ULTRIX) # include #else # include #endif #ifdef NDBM #include #else #ifdef NEWDB #include #endif #endif #include "popper.h" int pop_virtualh (p) POP * p; { #ifdef NDBM DBM *virt_db; datum key, value; #else #ifdef NEWDB DB * virt_db; DBT key, value; #endif #endif char real_user[MAXLINELEN]; char virtual_dir[BUFSIZ]; int err; /* Allow user@vhost.com to supersede DNS lookup */ if(strstr(p->user, "@")) { strcpy(real_user, p->user); } else { if ((strlen(p->server) + strlen(p->user)) > MAXLINELEN - 2) { pop_msg(p,POP_FAILURE, "Server (%s) + user (%s) bigger than MAX %d", p->user, p->server, MAXLINELEN - 1); return(-1); } sprintf(real_user, "%s@%s", p->user, p->server); } # ifdef DEBUG if (p->debug) pop_log(p, POP_DEBUG, "Attempting to Virtualize (%s)", real_user); # endif /* DEBUG */ #ifdef NDBM if ( (virt_db = dbm_open(VIRTUAL_SERVER, O_RDONLY, 0)) != NULL) { #else #ifdef NEWDB sprintf(virtual_dir, "%s.db", VIRTUAL_SERVER); if( (virt_db = dbopen(virtual_dir, O_RDONLY , 0644, DB_HASH, NULL)) != NULL) { #endif #endif // key.dsize = strlen (real_user) + 1; #ifdef NDBM key.dsize = strlen (real_user); key.dptr = real_user; #else #ifdef NEWDB key.size = strlen (real_user); key.data = real_user; #endif #endif #ifdef NDBM value = dbm_fetch (virt_db, key); dbm_close (virt_db); #else #ifdef NEWDB err = (virt_db->get)(virt_db, &key, &value, 0); /* Close the database */ (virt_db->close)(virt_db); if(err<0) pop_log(p, POP_PRIORITY, "Error accessing virtual DB %s", strerror(errno)); else if(err == 1) /* Double check, some don't seem to null nicely */ value.data = NULL; #endif #endif /* ** Got a live one, this is the users "real" name on our server ** Replace the "fake" name and carry on */ #ifdef NDBM if (value.dptr != NULL) { #else #ifdef NEWDB if (value.data != NULL) { #endif #endif # ifdef DEBUG if (p->debug) pop_log(p, POP_DEBUG, "User (%s) Virtualized", p->user); # endif #ifdef NDBM bcopy(value.dptr, p->user, value.dsize); p->user[value.dsize] = 0; #else #ifdef NEWDB bcopy(value.data, p->user, value.size); p->user[value.size] = 0; #endif #endif # ifdef DEBUG if (p->debug) pop_log(p, POP_DEBUG, "Virtualized User is (%s)", p->user); # endif } else { # ifdef DEBUG if (p->debug) pop_log(p, POP_DEBUG, "Virt DB Value returned NULL"); # endif } } else { pop_log(p, POP_PRIORITY, "Virtualization DB %s unopened (%s)", VIRTUAL_SERVER, strerror(errno)); } return(0); } #endif /* VIRTUAL_SERVER */ ---------------------------------------------------------- >-=-=-=-=-=-=-<>-=-=-=-=-=-<>-=-=-=-=-=-<>-=-=-=-=-=-<>-=-=-=-=-=-=-< Ryan Mooney Phone (602)265-9188 PCSLink ryan@pcslink.com Internet Services NT is an excellent choice for managers who need to show that they used up their fiscal year budget for hardware/software expenditures. <-=-=-=-=-=-=-><-=-=-=-=-=-><-=-=-=-=-=-><-=-=-=-=-=-><-=-=-=-=-=-=->