-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtete.c
103 lines (96 loc) · 1.91 KB
/
tete.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
char userID[10][32];
char pwdID[10][32];
int stop = 0;
int count = 0;
void parsing_text(int fd, char *location)
{
for (int i = 0;; i++)
{
if (read(fd, &location[i], 1) <= 0)
{
stop = 1;
break;
}
if (location[i] == ' ' || location[i] == '\n')
{
location[i] = '\0';
break;
}
}
}
void get_user_list()
{
int fd;
fd = open("list.txt", O_RDONLY);
if (fd < 0)
{
printf(1, "init already exec file\n");
exit();
}
for (int i = 0; i < 1; i++)
{
if (stop)
{
break;
}
count++;
parsing_text(fd, userID[i]);
parsing_text(fd, pwdID[i]);
}
}
int check_idpw()
{
char id[32] = {
0,
};
char pw[32] = {
0,
};
printf(1, "Username: ");
parsing_text(0, id);
printf(1, "Password: ");
parsing_text(0, pw);
for (int i = 0; i < count; i++)
{
if (!strcmp(id, userID[i]))
{
if (!strcmp(pw, pwdID[i]))
{
return 1;
}
return 0;
}
}
return 0;
}
int main(int argc, char *argv[])
{
int pid, wpid;
get_user_list();
while (1)
{
if (check_idpw())
for (;;)
{
printf(1, "init: starting login\n");
pid = fork();
if (pid < 0)
{
printf(1, "init: fork failed\n");
exit();
}
if (pid == 0)
{
exec("sh", argv);
printf(1, "init: exec sh failed\n");
exit();
}
while ((wpid = wait()) >= 0 && wpid != pid)
printf(1, "zombie!\n");
}
}
}