1 /* passwords.c */
2 /***************************************************************************
3 *  Copyright 2003 -   Steven Shipway <steve@cheshire.demon.co.uk>          *
4 *                     Put "nospam" in subject to avoid spam filter         *
5 *                                                                          *
6 *  This program is free software; you can redistribute it and/or modify    *
7 *  it under the terms of the GNU General Public License as published by    *
8 *  the Free Software Foundation; either version 2 of the License, or       *
9 *  (at your option) any later version.                                     *
10 *                                                                          *
11 *  This program is distributed in the hope that it will be useful,         *
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
14 *  GNU General Public License for more details.                            *
15 *                                                                          *
16 *  You should have received a copy of the GNU General Public License       *
17 *  along with this program; if not, write to the Free Software             *
18 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA               *
19 *  02111-1307, USA.                                                        *
20 ***************************************************************************/
21 
22 
23 #include "wand_head.h"
24 
25 #define PASS "poppycrash"
26 
27 /***************************************************
28 *                      scrn_passwd                 *
29 *            reads password num into passwd        *
30 ****************************************************/
scrn_passwd(num,passwd)31 int scrn_passwd(num, passwd)
32     int num;
33     char *passwd;
34 {
35         long position;
36         FILE *fp;
37 
38         position = PASSWD;
39         if(position < 0)
40                 position = -position;
41         while(position > 200000)
42                 position -= 200000;
43         if(position > 198500)
44                 position -=198500;
45         if((fp = fopen(DICTIONARY,"r")) == NULL)
46                 return 0;
47         fseek(fp,position,ftell(fp));
48         while(fgetc(fp) != '\n');
49         fscanf(fp,"%s\n",passwd);
50         /* read a word into passwd */
51         fclose(fp);
52         return (1);
53 }
54 
55 /************************************************
56 *                    main                       *
57 *************************************************/
main(argc,argv)58 main(argc,argv)
59 int argc;
60 char *argv[];
61 {
62         int scr,position,mpw = 0;
63         char pass[20];
64         char pw[100];
65         if(argc < 2) {
66                 printf("Usage: %s screen1 screen2 ...\n",argv[0]);
67                 exit(-1);
68         }
69         position = 0;
70         while(++position < argc) {
71                 if(atoi(argv[position])<1) {
72                         printf("Option not known: %s.\n",argv[position]);
73                         continue;
74                 }
75                 scr = atoi(argv[position]);
76                 if((scr < 100) && (mpw == 0)) {
77                         printf("You need clearance to see passwords below 100.\n");
78                         printf("Enter master password:");
79                         scanf("%s",pw);
80                         if(strncmp(pw,PASS,strlen(PASS))) {
81                                 printf("Foo, charlatan!\n");
82                                 exit(-1);
83                         }
84                         mpw = 1;
85                 }
86                 if( ! scrn_passwd((scr-1),pass)) {
87                         printf("%s: Cannot access %s.\n",argv[0],DICTIONARY);
88                         exit(-1);
89                 }
90                 printf("Screen %d password is '%s'.\n",scr,pass);
91         }
92 }
93