--- zip-2.32/zipcloak.c.orig 2005-06-16 00:15:00.000000000 -0400 +++ zip-2.32/zipcloak.c 2006-11-16 12:26:24.000000000 -0500 @@ -113,6 +113,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", " -q quieter operation, suppress some informational messages", " -h show this help -v show version info -L show software license" }; @@ -187,6 +189,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 */ @@ -217,6 +220,7 @@ /* Go through args */ zipfile = tempzip = NULL; + *passwd = (char)0; tempzf = NULL; #ifdef SIGINT signal(SIGINT, handler); @@ -239,7 +243,7 @@ #ifdef SIGSEGV signal(SIGSEGV, 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"); @@ -253,6 +257,8 @@ break; case 'd': decrypt = 1; break; + case 't': + checkifencrypted = 1; break; case 'h': /* Show help */ help(); EXIT(ZE_OK); @@ -264,6 +270,18 @@ case 'v': /* Show version info */ version_info(); EXIT(ZE_OK); + 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 */ @@ -290,7 +308,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" @@ -308,6 +336,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!)"); @@ -324,6 +354,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);