--- org/zipcloak.c Sat Jun 30 12:30:04 2001 +++ diff/zipcloak.c Sun Jul 15 17:08:49 2001 @@ -130,6 +130,8 @@ #else " -b use \"path\" for the temporary zip file", #endif +" -3 feed password in through FD 3", +" -t test if the archive is already encrypted", " -h show this help -v show version info -L show software license" }; @@ -203,6 +205,7 @@ int attr; /* attributes of zip file */ ulg start_offset; /* start of central directory */ int decrypt; /* decryption flag */ + int checkifencrypted; /* check if encrypted flag */ int temp_path; /* 1 if next argument is path for temp files */ char passwd[IZ_PWLEN+1]; /* password for encryption or decryption */ char verify[IZ_PWLEN+1]; /* password for encryption or decryption */ @@ -230,6 +233,7 @@ /* Go through args */ zipfile = tempzip = NULL; + *passwd = (char)0; tempzf = NULL; #ifdef SIGINT signal(SIGINT, handler); @@ -237,7 +241,7 @@ #ifdef SIGTERM /* Some don't have SIGTERM */ signal(SIGTERM, handler); #endif - temp_path = decrypt = 0; + temp_path = decrypt = 0; checkifencrypted = 0; for (r = 1; r < argc; r++) { if (*argv[r] == '-') { if (!argv[r][1]) ziperr(ZE_PARMS, "zip file cannot be stdin"); @@ -251,6 +255,8 @@ break; case 'd': decrypt = 1; break; + case 't': + checkifencrypted = 1; break; case 'h': /* Show help */ help(); EXIT(0); @@ -260,6 +266,18 @@ case 'v': /* Show version info */ version_info(); EXIT(0); + case '3': /* get passwd from fd 3 */ + passwd[read(3, passwd, PWLEN)]=(char)0; + if(*passwd) { + char *s; + if( (s=strchr(passwd, '\n')) || + (s=strchr(passwd, '\r')) ) + *s=(char)0; + } else { + ziperr(ZE_PARMS, "-3 requires input in fd 3"); + EXIT(1); + } + break; default: ziperr(ZE_PARMS, "unknown option"); } /* switch */ @@ -286,7 +304,17 @@ /* Check for something to do */ for (z = zfiles; z != NULL; z = z->nxt) { - if (decrypt ? z->flg & 1 : !(z->flg & 1)) break; + if ((decrypt | checkifencrypted) ? z->flg & 1 : !(z->flg & 1)) break; + } + if (checkifencrypted) { + if (z == NULL) { + printf ("The specified file is NOT encrypted.\n"); + EXIT(1); + } else + { + printf ("The specified file is encrypted.\n"); + EXIT(0); + } } if (z == NULL) { ziperr(ZE_NONE, decrypt ? "no encrypted files" @@ -304,6 +332,8 @@ } /* Get password */ + if (*passwd) /* got it with -3 */ + goto GOT_PASSWD; if (getp("Enter password: ", passwd, IZ_PWLEN+1) == NULL) ziperr(ZE_PARMS, "stderr is not a tty (you may never see this message!)"); @@ -320,6 +350,7 @@ ziperr(ZE_PARMS, "zero length password not allowed"); } + GOT_PASSWD: /* Open input zip file again, copy preamble if any */ if ((inzip = fopen(zipfile, FOPR)) == NULL) ziperr(ZE_NAME, zipfile);