Skip to content

Commit 7bcc447

Browse files
committed
added c style convention and reformated coments
1 parent e9f9106 commit 7bcc447

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/c_coding_style.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
BASH CODING STYLE
2+
3+
Please see GNU Coding Standards
4+
********************
5+
http://www.gnu.org/prep/standards/standards.txt

src/v_check_user_password.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
/* */
1010
/***************************************************************************/
1111

12-
#define _XOPEN_SOURCE
1312
#include <stdio.h>
1413
#include <stdlib.h>
1514
#include <unistd.h>
@@ -21,60 +20,60 @@
2120

2221

2322
int main (int argc, char** argv) {
24-
// defining ip
23+
/* define ip */
2524
char *ip = "127.0.0.1";
2625

27-
// checking argument list
26+
/* check argument list */
2827
if (3 > argc) {
2928
printf("Error: bad args\n",argv[0]);
3029
printf("Usage: %s user password [ip]\n",argv[0]);
3130
exit(1);
3231
};
3332

34-
// checking ip
33+
/* check ip */
3534
if (4 <= argc) {
3635
ip = (char*)malloc(strlen(argv[3]));
3736
strcpy(ip, argv[3]);
3837
}
3938

40-
// formating current time
39+
/* format current time */
4140
time_t lt = time(NULL);
4241
struct tm* ptr = localtime(&lt);
4342
char str[280];
4443
strftime(str, 100, "%Y-%m-%d %H:%M:%S ", ptr);
4544

46-
// openning log file
45+
/* open log file */
4746
FILE* pFile = fopen ("/usr/local/vesta/log/auth.log","a+");
4847
if (NULL == pFile) {
4948
printf("Error: can not open file %s \n", argv[0]);
5049
exit(12);
5150
}
5251

53-
// parsing user argument
52+
/* parse user argument */
5453
struct passwd* userinfo = getpwnam(argv[1]);
5554
if (NULL != userinfo) {
5655
struct spwd* passw = getspnam(userinfo->pw_name);
5756
if (NULL != passw) {
5857
char* cryptedPasswrd = (char*)crypt(argv[2], passw->sp_pwdp);
5958
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 */
6160
strcat(str, userinfo->pw_name);
6261
strcat(str, " ");
6362
strcat(str, ip);
6463
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 */
6867
} else {
69-
// concatinating time with user string
68+
/* concatinate time with user string */
7069
printf ("Error: password missmatch\n");
7170
strcat(str, userinfo->pw_name);
7271
strcat(str, " ");
7372
strcat(str, ip);
7473
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 */
7877
};
7978
}
8079
} else {

0 commit comments

Comments
 (0)