|
9 | 9 | /* */ |
10 | 10 | /***************************************************************************/ |
11 | 11 |
|
12 | | -#define _XOPEN_SOURCE |
13 | 12 | #include <stdio.h> |
14 | 13 | #include <stdlib.h> |
15 | 14 | #include <unistd.h> |
|
21 | 20 |
|
22 | 21 |
|
23 | 22 | int main (int argc, char** argv) { |
24 | | - // defining ip |
| 23 | + /* define ip */ |
25 | 24 | char *ip = "127.0.0.1"; |
26 | 25 |
|
27 | | - // checking argument list |
| 26 | + /* check argument list */ |
28 | 27 | if (3 > argc) { |
29 | 28 | printf("Error: bad args\n",argv[0]); |
30 | 29 | printf("Usage: %s user password [ip]\n",argv[0]); |
31 | 30 | exit(1); |
32 | 31 | }; |
33 | 32 |
|
34 | | - // checking ip |
| 33 | + /* check ip */ |
35 | 34 | if (4 <= argc) { |
36 | 35 | ip = (char*)malloc(strlen(argv[3])); |
37 | 36 | strcpy(ip, argv[3]); |
38 | 37 | } |
39 | 38 |
|
40 | | - // formating current time |
| 39 | + /* format current time */ |
41 | 40 | time_t lt = time(NULL); |
42 | 41 | struct tm* ptr = localtime(<); |
43 | 42 | char str[280]; |
44 | 43 | strftime(str, 100, "%Y-%m-%d %H:%M:%S ", ptr); |
45 | 44 |
|
46 | | - // openning log file |
| 45 | + /* open log file */ |
47 | 46 | FILE* pFile = fopen ("/usr/local/vesta/log/auth.log","a+"); |
48 | 47 | if (NULL == pFile) { |
49 | 48 | printf("Error: can not open file %s \n", argv[0]); |
50 | 49 | exit(12); |
51 | 50 | } |
52 | 51 |
|
53 | | - // parsing user argument |
| 52 | + /* parse user argument */ |
54 | 53 | struct passwd* userinfo = getpwnam(argv[1]); |
55 | 54 | if (NULL != userinfo) { |
56 | 55 | struct spwd* passw = getspnam(userinfo->pw_name); |
57 | 56 | if (NULL != passw) { |
58 | 57 | char* cryptedPasswrd = (char*)crypt(argv[2], passw->sp_pwdp); |
59 | 58 | if (strcmp(passw->sp_pwdp,crypt(argv[2],passw->sp_pwdp))==0) { |
60 | | - // concatinating time with user and ip |
| 59 | + /* concatinate time with user and ip */ |
61 | 60 | strcat(str, userinfo->pw_name); |
62 | 61 | strcat(str, " "); |
63 | 62 | strcat(str, ip); |
64 | 63 | strcat(str, " successfully logged in \n"); |
65 | | - fputs (str,pFile); // writing |
66 | | - fclose (pFile); // closing |
67 | | - exit(EXIT_SUCCESS); // exiting |
| 64 | + fputs (str,pFile); /* write */ |
| 65 | + fclose (pFile); /* close */ |
| 66 | + exit(EXIT_SUCCESS); /* exit */ |
68 | 67 | } else { |
69 | | - // concatinating time with user string |
| 68 | + /* concatinate time with user string */ |
70 | 69 | printf ("Error: password missmatch\n"); |
71 | 70 | strcat(str, userinfo->pw_name); |
72 | 71 | strcat(str, " "); |
73 | 72 | strcat(str, ip); |
74 | 73 | strcat(str, " failed to login \n"); |
75 | | - fputs (str,pFile); // writing |
76 | | - fclose (pFile); // closing |
77 | | - exit(9); // exiting |
| 74 | + fputs (str,pFile); /* write */ |
| 75 | + fclose (pFile); /* close */ |
| 76 | + exit(9); /* exit */ |
78 | 77 | }; |
79 | 78 | } |
80 | 79 | } else { |
|
0 commit comments