first version of cac.c - crypt and compare
[my-code/get-passwd.git] / cac.c
1 /* cac.c - crypt and compare 
2  *
3  * author: hackbard
4  *
5  */
6
7 #include <stdio.h>
8 #include <crypt.h>
9 #include <string.h>
10
11 int main(int argc, char *argv[]) {
12         
13         FILE *file_h;
14         char temp[256];
15
16         if(argc!=3) {
17                 printf("usage: %s <shadow-file> <password>\n",argv[0]);
18                 return 0;
19         }
20
21         file_h=fopen(argv[1],"r");
22         if(file_h==NULL) {
23                 printf("error: cant open %s for reading\n",argv[1]);
24                 return 0;
25         } else {
26                 printf("reading %s\n",argv[1]);
27         }
28         
29         while(fgets(temp,256,file_h)) {
30                 if(strstr(temp,"root")) {
31                         /* none md5 way ... */
32                         if(temp[4]==':') {
33                         if(strncmp(crypt(argv[2],(temp+5)),(temp+5),13)==0)
34                                 printf("succes: %s\n",argv[2]);
35                         else printf("wrong\n");
36                         }
37                 }
38         }
39         return 0;
40 }