X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Fget-passwd.git;a=blobdiff_plain;f=cac.c;h=e488344b56f34b9c67c943e4d01c23ca2bda948b;hp=88628bc64872b95166de3eb87831b8695bc30639;hb=HEAD;hpb=399075456ccaa76629d7148e439b43ebb7d2406d diff --git a/cac.c b/cac.c index 88628bc..e488344 100644 --- a/cac.c +++ b/cac.c @@ -10,29 +10,52 @@ 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 \n",argv[0]); + printf("usage: %s \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) - printf("succes: %s\n",argv[2]); - else printf("wrong\n"); + 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",temp2); + return 0; + } + } + } } } }