]> hackdaworld.org Git - my-code/get-passwd.git/commitdiff
added support for dos files
authorhackbard <hackbard>
Sat, 26 Oct 2002 13:13:09 +0000 (13:13 +0000)
committerhackbard <hackbard>
Sat, 26 Oct 2002 13:13:09 +0000 (13:13 +0000)
cac.c

diff --git a/cac.c b/cac.c
index 88628bc64872b95166de3eb87831b8695bc30639..80ee0e479befb4c70767103b1a94d8ff428e6bf0 100644 (file)
--- a/cac.c
+++ b/cac.c
 
 int main(int argc, char *argv[]) {
        
-       FILE *file_h;
+       FILE *shadow_h, *passwd_h;
        char temp[256];
+       char temp2[30];
 
        if(argc!=3) {
-               printf("usage: %s <shadow-file> <password>\n",argv[0]);
+               printf("usage: %s <shadow-file> <password-file>\n",argv[0]);
                return 0;
        }
 
-       file_h=fopen(argv[1],"r");
-       if(file_h==NULL) {
+       shadow_h=fopen(argv[1],"r");
+       if(shadow_h==NULL) {
                printf("error: cant open %s for reading\n",argv[1]);
                return 0;
        } else {
                printf("reading %s\n",argv[1]);
        }
+       passwd_h=fopen(argv[2],"r");
+       if(passwd_h==NULL) {
+               printf("error: cant open %s for reading\n",argv[2]);
+               return 0;
+       } else {
+               printf("using %s as passwd library\n",argv[2]);
+       }
        
-       while(fgets(temp,256,file_h)) {
+       while(fgets(temp,256,shadow_h)) {
                if(strstr(temp,"root")) {
                        /* none md5 way ... */
                        if(temp[4]==':') {
-                       if(strncmp(crypt(argv[2],(temp+5)),(temp+5),13)==0)
+                       while(fgets(temp2,30,passwd_h)) {
+                       int mylen=strlen(temp2);
+                       if((mylen>=1) && (temp2[mylen-1]=='\n')) {
+                               if((mylen>=2) && (temp2[mylen-2]==0x0d)) {
+                                       mylen-=2;
+                                       temp2[mylen]=0;
+                                       printf("dosfile!\n");
+                               }
+                               else
+                                       temp2[--mylen]=0;
+                       }
+                       if(mylen>=1) {
+                       if(strncmp(crypt(temp2,(temp+5)),(temp+5),13)==0) {
                                printf("succes: %s\n",argv[2]);
-                       else printf("wrong\n");
+                               return 0;
+                       }
+                       }
+                       }
                        }
                }
        }