added support for dos files
[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 *shadow_h, *passwd_h;
14         char temp[256];
15         char temp2[30];
16
17         if(argc!=3) {
18                 printf("usage: %s <shadow-file> <password-file>\n",argv[0]);
19                 return 0;
20         }
21
22         shadow_h=fopen(argv[1],"r");
23         if(shadow_h==NULL) {
24                 printf("error: cant open %s for reading\n",argv[1]);
25                 return 0;
26         } else {
27                 printf("reading %s\n",argv[1]);
28         }
29         passwd_h=fopen(argv[2],"r");
30         if(passwd_h==NULL) {
31                 printf("error: cant open %s for reading\n",argv[2]);
32                 return 0;
33         } else {
34                 printf("using %s as passwd library\n",argv[2]);
35         }
36         
37         while(fgets(temp,256,shadow_h)) {
38                 if(strstr(temp,"root")) {
39                         /* none md5 way ... */
40                         if(temp[4]==':') {
41                         while(fgets(temp2,30,passwd_h)) {
42                         int mylen=strlen(temp2);
43                         if((mylen>=1) && (temp2[mylen-1]=='\n')) {
44                                 if((mylen>=2) && (temp2[mylen-2]==0x0d)) {
45                                         mylen-=2;
46                                         temp2[mylen]=0;
47                                         printf("dosfile!\n");
48                                 }
49                                 else
50                                         temp2[--mylen]=0;
51                         }
52                         if(mylen>=1) {
53                         if(strncmp(crypt(temp2,(temp+5)),(temp+5),13)==0) {
54                                 printf("succes: %s\n",argv[2]);
55                                 return 0;
56                         }
57                         }
58                         }
59                         }
60                 }
61         }
62         return 0;
63 }