Sophie

Sophie

distrib > Mandriva > 2009.0 > x86_64 > by-pkgid > 862d316ef1e03f6edd0e1bcc1a3588a6 > files > 1

zip-3.0-1mdv2009.0.src.rpm

--- zipcloak.c	2008-05-08 04:17:00.000000000 +0200
+++ zipcloak.c.oden	2008-08-18 12:22:07.000000000 +0200
@@ -220,6 +220,8 @@ static ZCONST char *help_info[] = {
 "  -b  --temp-path    use \"path\" for the temporary zip file",
 #endif
 "  -O  --output-file  write output to new zip file",
+"  -3   feed password in through FD 3",
+"  -t   test if the archive is already encrypted",
 "  -q  --quiet        quiet operation, suppress some informational messages",
 "  -h  --help         show this help",
 "  -v  --version      show version info",
@@ -312,6 +314,7 @@ int main(argc, argv)
     int attr;                   /* attributes of zip file */
     zoff_t 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 */
@@ -390,6 +393,7 @@ int main(argc, argv)
 
     /* Go through args */
     zipfile = tempzip = NULL;
+    *passwd = (char)0;
     tempzf = NULL;
 #ifdef SIGINT
     signal(SIGINT, handler);
@@ -412,7 +416,7 @@ int main(argc, argv)
 #ifdef SIGSEGV
     signal(SIGSEGV, handler);
 #endif
-    temp_path = decrypt = 0;
+    temp_path = decrypt = 0; checkifencrypted = 0;
 #if 0
     /* old command line */
     for (r = 1; r < argc; r++) {
@@ -428,6 +432,8 @@ int main(argc, argv)
                     break;
                 case 'd':
                     decrypt = 1;  break;
+                case 't':
+                    checkifencrypted = 1;  break;                    
                 case 'h':   /* Show help */
                     help();
                     EXIT(ZE_OK);
@@ -439,6 +445,18 @@ int main(argc, argv)
                 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 */
@@ -569,7 +587,17 @@ int main(argc, argv)
 
     /* 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"
@@ -628,6 +656,8 @@ int main(argc, argv)
 #endif
 
     /* 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!)");
@@ -644,6 +674,7 @@ int main(argc, argv)
                ziperr(ZE_PARMS, "zero length password not allowed");
     }
 
+  GOT_PASSWD:
     /* Open input zip file again, copy preamble if any */
     if ((in_file = fopen(zipfile, FOPR)) == NULL) ziperr(ZE_NAME, zipfile);