/*genpw.c - generate a list of passwords and print it on the default printer. Save the corresponding list of encrypted passwords in the specified file. Uses makepw.c. By Matthew Belmonte, October 1997. Copyright (c) 1197 by the Howard Hughes Medical Institute.*/ #include #include #include #include static char makepw_cmd[] = "makepw", lpr_cmd[] = "enscript -2"; void main(argc, argv) int argc; char **argv; { register int c, i; int wordcount; FILE *makepw, *lpr; struct timeval tv; char cmd[0x100]; if((argc != 3) || (argv[2][0] < '0') || (argv[2][0] > '9')) { fprintf(stderr, "usage: %s <# of passwords>\n", *argv); exit(1); } wordcount = atoi(argv[2]); sprintf(cmd, "%s %s >/dev/null", makepw_cmd, argv[1]); makepw = popen(cmd, "w"); if(makepw == NULL) { perror(makepw_cmd); exit(errno); } lpr = popen(lpr_cmd, "w"); if(lpr == NULL) { perror(lpr_cmd); pclose(makepw); exit(errno); } gettimeofday(&tv, (struct timezone *)0); srandom((int)(tv.tv_usec >> 4)); while(wordcount--) { for(i = 0; i != 8; i++) { c = '!' + (((int)(random()&255L))*('z'-'!')) / 255; putc(c, makepw); putc(c, lpr); } putc('\n', makepw); putc('\n', lpr); } pclose(lpr); putc('\n', makepw); pclose(makepw); exit(0); }