From owner-freebsd-questions Sat Jan 11 17:36:40 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.4/8.8.4) id RAA23067 for questions-outgoing; Sat, 11 Jan 1997 17:36:40 -0800 (PST) Received: from labs.usn.blaze.net.au (labs.usn.blaze.net.au [203.17.53.30]) by freefall.freebsd.org (8.8.4/8.8.4) with ESMTP id RAA23059 for ; Sat, 11 Jan 1997 17:36:36 -0800 (PST) Received: (from davidn@localhost) by labs.usn.blaze.net.au (8.8.4/8.8.4) id XAA00859; Sat, 11 Jan 1997 23:36:39 +1100 (EST) Message-ID: Date: Sat, 11 Jan 1997 12:36:39 +0000 From: davidn@unique.usn.blaze.net.au (David Nugent) To: robert@nanguo.chalmers.com.au (Robert Chalmers) Cc: freebsd-questions@freebsd.org (bsd) Subject: Re: is there a crypt tool? References: <199701112327.JAA22330@nanguo.chalmers.com.au> X-Mailer: Mutt 0.56 Mime-Version: 1.0 In-Reply-To: <199701112327.JAA22330@nanguo.chalmers.com.au>; from Robert Chalmers on Jan 12, 1997 09:27:29 +1000 Sender: owner-questions@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Robert Chalmers writes: > More to the point, is there a crypt too anywhere. I can't find > anything on the CD. I know its in the libraries etc, but I need a program, > seen on Coherent believe it or not, called 'crypt'. Great for creating > passworded access on the fly. This is NOT the same thing, but I wrote it for the same purpose. Create a file containing user:password in plain text format. e.g. yourname:yourpassword anothername:anotherpassword Run "crypt filename >passwd_file", replacing filename with the name of the file that contains this data, and passwd_file with the name of the user/password file (typically .htaccess). #include #include #include #include const char ll[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz."; char * salt(void) { static char buf[32]; int i; for (i=0; i < 8; i++) buf[i] = ll[rand() % sizeof(ll)]; buf[i] = '\0'; return buf; } int main(int argc, char * argv[]) { int carg = 0; srand((unsigned)time(NULL) ^ getpid()); while (++carg < argc) { char * argp = argv[carg]; FILE * fp = fopen(argp, "r"); if (fp == NULL) perror(argp); else { char tmp[256]; while (fgets(tmp, sizeof tmp, fp) != NULL) { char * p = strchr(tmp, '\n'); if (p != NULL) *p = '\0'; p = strchr(tmp, '\r'); if (p != NULL) *p = '\0'; p = strchr(tmp, ':'); if (p == NULL) p = tmp; else ++p; strcpy(p, crypt(p, salt())); printf("%s\n", tmp); } fclose(fp); } } return 0; } Regards, David Nugent - Unique Computing Pty Ltd - Melbourne, Australia Voice +61-3-9791-9547 Data/BBS +61-3-9792-3507 3:632/348@fidonet davidn@freebsd.org davidn@blaze.net.au http://www.blaze.net.au/~davidn/