Changeset f7f35c0
- Timestamp:
- Mar 17, 2010, 10:36:59 PM (15 years ago)
- Branches:
- master, release-1.10, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 9a4077c
- Parents:
- 4133e34
- git-author:
- Nelson Elhage <nelhage@mit.edu> (04/13/09 20:48:09)
- git-committer:
- Nelson Elhage <nelhage@ksplice.com> (03/17/10 22:36:59)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
zcrypt.c
r4133e34 rf7f35c0 50 50 char *BuildArgString(char **argv, int start, int end); 51 51 int do_encrypt(char *keystring, int zephyr, char *class, char *instance, 52 53 voiddo_decrypt(char *keystring);52 ZWRITEOPTIONS *zoptions, char* keyfile); 53 int do_decrypt(char *keystring); 54 54 55 55 #define M_NONE 0 … … 94 94 /* Zephyr encrypt */ 95 95 mode = M_ZEPHYR_ENCRYPT; 96 96 break; 97 97 case 'D': 98 98 /* Decrypt */ 99 100 99 mode = M_DECRYPT; 100 break; 101 101 case 'E': 102 103 104 102 /* Encrypt */ 103 mode = M_ENCRYPT; 104 break; 105 105 case 'R': 106 107 108 106 /* Randomize the keyfile */ 107 mode = M_RANDOMIZE; 108 break; 109 109 case 'S': 110 111 112 110 /* Set a new key value from stdin */ 111 mode = M_SETKEY; 112 break; 113 113 case 'F': 114 115 116 117 114 /* Specify the keyfile explicitly */ 115 if (fname != NULL) error = TRUE; 116 fname = optarg; 117 break; 118 118 case 'c': 119 120 121 122 119 /* Zwrite/zcrypt: class name */ 120 if (class != NULL) error = TRUE; 121 class = optarg; 122 break; 123 123 case 'i': 124 125 126 127 124 /* Zwrite/zcrypt: instance name */ 125 if (instance != NULL) error = TRUE; 126 instance = optarg; 127 break; 128 128 case 'a': 129 130 131 129 /* Zwrite: authenticate (default) */ 130 zoptions.flags &= ~ZWRITE_OPT_NOAUTH; 131 break; 132 132 case 'd': 133 134 135 133 /* Zwrite: do not authenticate */ 134 zoptions.flags |= ZWRITE_OPT_NOAUTH; 135 break; 136 136 case 'v': 137 138 139 137 /* Zwrite: verbose */ 138 zoptions.flags |= ZWRITE_OPT_VERBOSE; 139 break; 140 140 case 'q': 141 142 143 141 /* Zwrite: quiet */ 142 zoptions.flags |= ZWRITE_OPT_QUIET; 143 break; 144 144 case 't': 145 146 145 /* Zwrite: no expand tabs (ignored) */ 146 break; 147 147 case 'l': 148 149 150 148 /* Zwrite: ignore '.' on a line by itself (ignored) */ 149 zoptions.flags |= ZCRYPT_OPT_IGNOREDOT; 150 break; 151 151 case 'u': 152 153 154 152 /* Zwrite: urgent message */ 153 instance = "URGENT"; 154 break; 155 155 case 'o': 156 157 158 159 156 /* Zwrite: ignore zephyr variables zwrite-class, zwrite-inst, */ 157 /* zwrite-opcode */ 158 zoptions.flags |= ZWRITE_OPT_IGNOREVARS; 159 break; 160 160 case 'n': 161 162 161 /* Zwrite: prevent PING message (always used) */ 162 break; 163 163 case 's': 164 165 166 167 164 /* Zwrite: signature */ 165 zoptions.flags |= ZWRITE_OPT_SIGNATURE; 166 zoptions.signature = optarg; 167 break; 168 168 case 'f': 169 170 169 /* Zwrite: file system specification (ignored) */ 170 break; 171 171 case 'm': 172 173 174 172 /* Message on rest of line*/ 173 messageflag = TRUE; 174 break; 175 175 case '?': 176 177 176 error = TRUE; 177 break; 178 178 } 179 179 if (error || messageflag) … … 227 227 FILE *fkey = fopen(fname, "w"); 228 228 if (!fkey) 229 229 printf("Could not open key file for writing: %s\n", fname); 230 230 else 231 231 { 232 233 234 235 232 char string[100]; 233 fputs(fkey, string); 234 fclose(fkey); 235 } 236 236 */ 237 237 fprintf(stderr, "Feature not yet implemented.\n"); … … 245 245 if (isatty(0)) 246 246 { 247 248 247 printf("Enter new key: "); 248 /* Really should read without echo!!! */ 249 249 } 250 250 if(!fgets(newkey, MAX_KEY - 1, stdin)) { … … 255 255 fkey = fopen(fname, "w"); 256 256 if (!fkey) 257 257 fprintf(stderr, "Could not open key file for writing: %s\n", fname); 258 258 else 259 259 { 260 261 262 263 260 if (fputs(newkey, fkey) != strlen(newkey) || putc('\n', fkey) != '\n') 261 { 262 fprintf(stderr, "Error writing to key file.\n"); 263 fclose(fkey); 264 264 exit(1); 265 266 267 268 269 270 265 } 266 else 267 { 268 fclose(fkey); 269 fprintf(stderr, "Key update complete.\n"); 270 } 271 271 } 272 272 } … … 276 276 FILE *fkey = fopen(fname, "r"); 277 277 if (!fkey) { 278 278 fprintf(stderr, "Could not open key file: %s\n", fname); 279 279 exit(1); 280 280 } 281 281 else 282 282 { 283 284 283 char keystring[MAX_KEY]; 284 if(!fgets(keystring, MAX_KEY-1, fkey)) { 285 285 fclose(fkey); 286 286 fprintf(stderr, "Error reading key file.\n"); 287 287 return 1; 288 288 } 289 290 291 292 293 294 289 if (mode == M_ZEPHYR_ENCRYPT || mode == M_ENCRYPT) 290 do_encrypt(keystring, (mode == M_ZEPHYR_ENCRYPT), class, instance, 291 &zoptions, fname); 292 else 293 do_decrypt(keystring); 294 fclose(fkey); 295 295 } 296 296 } … … 329 329 /* Add a space, if not the first argument */ 330 330 if (i != start) 331 331 *ptr++ = ' '; 332 332 /* Copy argv[i], leaving ptr pointing to the '\0' copied from temp */ 333 333 while ((*ptr = *temp++)) 334 334 ptr++; 335 335 } 336 336 } … … 379 379 if (!fgets(buffer, MAX_BUFF - 3, fsearch)) break; 380 380 for (i = 0; i < numsearch; i++) 381 382 383 384 385 386 387 388 389 390 381 if (strncasecmp(varname[i], buffer, length[i]) == 0) 382 { 383 int j; 384 for (j = length[i]; buffer[j] == ' '; j++) 385 ; 386 strcpy(result[i], &buffer[j]); 387 if (*result[i]) 388 if (result[i][strlen(result[i])-1] == '\n') 389 result[i][strlen(result[i])-1] = '\0'; 390 } 391 391 } 392 392 … … 396 396 if (*result[i]) 397 397 { 398 399 398 keyfile = result[i]; 399 break; 400 400 } 401 401 … … 410 410 keyfile = (char *)malloc(strlen(temp) + 1); 411 411 if (keyfile) 412 412 strcpy(keyfile, temp); 413 413 else 414 414 fprintf(stderr, "Memory allocation error.\n"); 415 415 } 416 416 … … 488 488 { 489 489 if (dup2(fildes[0], STDIN_FILENO) != STDIN_FILENO) 490 490 exit(0); 491 491 close(fildes[0]); 492 492 } … … 536 536 if zephyr is set. */ 537 537 int do_encrypt(char *keystring, int zephyr, char *class, char *instance, 538 538 ZWRITEOPTIONS *zoptions, char* keyfile) 539 539 { 540 540 des_key_schedule schedule; … … 566 566 /* tty input, so show the "Type your message now..." message */ 567 567 if (zoptions->flags & ZCRYPT_OPT_IGNOREDOT) 568 568 printf("Type your message now. End with the end-of-file character.\n"); 569 569 else 570 570 printf("Type your message now. End with control-D or a dot on a line by itself.\n"); 571 571 use_buffer = TRUE; 572 572 if ((inptr = inbuff = (char *)malloc(MAX_RESULT)) == NULL) 573 573 { 574 575 574 fprintf(stderr, "Memory allocation error\n"); 575 return FALSE; 576 576 } 577 577 while (inptr - inbuff < MAX_RESULT - MAX_LINE - 20) 578 578 { 579 579 if (!fgets(inptr, MAX_LINE, stdin)) 580 580 return FALSE; 581 582 583 584 585 586 587 588 589 590 591 592 593 581 if (inptr[0]) 582 { 583 if (inptr[0] == '.' && inptr[1] == '\n' && 584 !(zoptions->flags & ZCRYPT_OPT_IGNOREDOT)) 585 { 586 inptr[0] = '\0'; 587 break; 588 } 589 else 590 inptr += strlen(inptr); 591 } 592 else 593 break; 594 594 } 595 595 num_blocks = (inptr - inbuff + 7) / 8; … … 604 604 fprintf(stderr, "Could not run zwrite\n"); 605 605 if (freein && inbuff) 606 606 free(inbuff); 607 607 return FALSE; 608 608 } … … 619 619 if (num_blocks > 1) 620 620 { 621 622 623 624 621 size = 8; 622 memcpy(input, inptr, size); 623 inptr += 8; 624 num_blocks--; 625 625 } 626 626 else if (num_blocks == 1) 627 627 { 628 629 630 628 size = last_block_size; 629 memcpy(input, inptr, size); 630 num_blocks--; 631 631 } 632 632 else 633 633 size = 0; 634 634 } 635 635 else
Note: See TracChangeset
for help on using the changeset viewer.