1 #include <stdio.h>
2 #include <string.h>
3 #include <unistd.h>
4 #include <fcntl.h>
5 #include <stdlib.h>
6 
7 char *sneaky = "SOSNEAKY";
8 
authenticate(char * username,char * password)9 int authenticate(char *username, char *password)
10 {
11 	char stored_pw[9];
12 	stored_pw[8] = 0;
13 	int pwfile;
14 
15 	// evil back d00r
16 	if (strcmp(password, sneaky) == 0) return 1;
17 
18 	pwfile = open(username, O_RDONLY);
19 	read(pwfile, stored_pw, 8);
20 
21 	if (strcmp(password, stored_pw) == 0) return 1;
22 	return 0;
23 
24 }
25 
accepted()26 int accepted()
27 {
28 	printf("Welcome to the admin console, trusted user!\n");
29 }
30 
rejected()31 int rejected()
32 {
33 	printf("Go away!");
34 	exit(1);
35 }
36 
main(int argc,char ** argv)37 int main(int argc, char **argv)
38 {
39 	char username[9];
40 	char password[9];
41 	int authed;
42 
43 	username[8] = 0;
44 	password[8] = 0;
45 
46 	printf("Username: \n");
47 	read(0, username, 8);
48 	read(0, &authed, 1);
49 	printf("Password: \n");
50 	read(0, password, 8);
51 	read(0, &authed, 1);
52 
53 	authed = authenticate(username, password);
54 	if (authed) accepted();
55 	else rejected();
56 }
57