forked from sshipway/wanderer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
passwords.c
86 lines (81 loc) · 2.24 KB
/
passwords.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* passwords.c */
#include "wand_head.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define PASS "poppycrash"
/***************************************************
* scrn_passwd *
* reads password num into passwd *
****************************************************/
int scrn_passwd(int num, char *passwd)
{
long position;
FILE *fp;
position = PASSWD;
if (position < 0)
position = -position;
while (position > 200000)
position -= 200000;
if (position > 198500)
position -= 198500;
if ((fp = fopen(DICTIONARY, "r")) == NULL)
return 0;
fseek(fp, position, ftell(fp));
while (fgetc(fp) != '\n');
if (fscanf(fp, "%s\n", passwd) == EOF && errno != 0)
{
fprintf(stderr, "fscanf error\n");
exit(EXIT_FAILURE);
}
/* read a word into passwd */
fclose(fp);
return (1);
}
/************************************************
* main *
*************************************************/
int main(int argc, char **argv)
{
int scr, position, mpw = 0;
char pass[20];
char pw[100];
if (argc < 2)
{
printf("Usage: %s screen1 screen2 ...\n", argv[0]);
exit(-1);
}
position = 0;
while (++position < argc)
{
if (atoi(argv[position]) < 1)
{
printf("Option not known: %s.\n", argv[position]);
continue;
}
scr = atoi(argv[position]);
if ((scr < 100) && (mpw == 0))
{
printf("You need clearance to see passwords below 100.\n");
printf("Enter master password:");
if (scanf("%s", pw) == EOF && errno != 0)
{
fprintf(stderr, "scanf error\n");
exit(EXIT_FAILURE);
}
if (strncmp(pw, PASS, strlen(PASS)))
{
printf("Foo, charlatan!\n");
exit(-1);
}
mpw = 1;
}
if (!scrn_passwd((scr - 1), pass))
{
printf("%s: Cannot access %s.\n", argv[0], DICTIONARY);
exit(-1);
}
printf("Screen %d password is '%s'.\n", scr, pass);
}
}