[BACK]Return to encrypt.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / encrypt

Diff for /src/usr.bin/encrypt/encrypt.c between version 1.8 and 1.9

version 1.8, 1999/05/19 03:17:15 version 1.9, 1999/05/20 00:05:39
Line 52 
Line 52 
   
 void usage()  void usage()
 {  {
     fprintf(stderr, "usage: %s [-k] [-b rounds] [-m] [-s salt] [string]\n",      fprintf(stderr, "usage: %s [-k] [-b rounds] [-m] [-s salt] [-p | string]\n",
         progname);          progname);
     exit(1);      exit(1);
 }  }
Line 127 
Line 127 
 {  {
     int opt;      int opt;
     int operation = -1;      int operation = -1;
       int prompt = 0;
     int rounds;      int rounds;
     void *extra;                       /* Store salt or number of rounds */      void *extra;                       /* Store salt or number of rounds */
   
Line 138 
Line 139 
     if (strcmp(progname, "makekey") == 0)      if (strcmp(progname, "makekey") == 0)
          operation = DO_MAKEKEY;           operation = DO_MAKEKEY;
   
     while ((opt = getopt(argc, argv, "kms:b:")) != -1) {      while ((opt = getopt(argc, argv, "kmps:b:")) != -1) {
         switch (opt) {          switch (opt) {
         case 'k':                       /* Stdin/Stdout Unix crypt */          case 'k':                       /* Stdin/Stdout Unix crypt */
             if (operation != -1)              if (operation != -1)
Line 146 
Line 147 
             operation = DO_MAKEKEY;              operation = DO_MAKEKEY;
             break;              break;
         case 'm':                       /* MD5 password hash */          case 'm':                       /* MD5 password hash */
             if (operation != -1)              if (operation != -1 || prompt)
                  usage();                   usage();
             operation = DO_MD5;              operation = DO_MD5;
             break;              break;
           case 'p':
               if (operation != -1)
                    usage();
               prompt = 1;
               break;
         case 's':                       /* Unix crypt (DES) */          case 's':                       /* Unix crypt (DES) */
             if (operation != -1)              if (operation != -1)
                  usage();                   usage();
Line 173 
Line 179 
     if (((argc - optind) < 1) || operation == DO_MAKEKEY) {      if (((argc - optind) < 1) || operation == DO_MAKEKEY) {
         char line[BUFSIZ], *string;          char line[BUFSIZ], *string;
   
         /* Encrypt stdin to stdout. */          if (prompt) {
         while (!feof(stdin) && (fgets(line, sizeof(line), stdin) != NULL)) {              string = getpass("Enter string: ");
             /* Kill the whitesapce. */  
             string = trim(line);  
             if (*string == '\0')  
                 continue;  
   
             print_passwd(string, operation, extra);              print_passwd(string, operation, extra);
               fputc('\n', stdout);
           } else {
               /* Encrypt stdin to stdout. */
               while (!feof(stdin) && (fgets(line, sizeof(line), stdin) != NULL)) {
                   /* Kill the whitesapce. */
                   string = trim(line);
                   if (*string == '\0')
                       continue;
   
                   print_passwd(string, operation, extra);
   
             if (operation == DO_MAKEKEY) {                  if (operation == DO_MAKEKEY) {
                 fflush(stdout);                      fflush(stdout);
                 break;                      break;
                   }
                   fputc('\n', stdout);
             }              }
             fputc('\n', stdout);  
         }          }
     } else {      } else {
         char *string;          char *string;
   
           /* can't combine -p with a supplied string */
           if (prompt)
               usage();
   
         /* Perhaps it isn't worth worrying about, but... */          /* Perhaps it isn't worth worrying about, but... */
         string = strdup(argv[optind]);          string = strdup(argv[optind]);

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9