Changeset 356465e
- Timestamp:
- Mar 17, 2010, 10:36:59 PM (14 years ago)
- Branches:
- master, release-1.10, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- a08bfc3
- Parents:
- 49bc81e
- git-author:
- Anders Kaseorg <andersk@mit.edu> (09/14/09 23:52:36)
- git-committer:
- Nelson Elhage <nelhage@ksplice.com> (03/17/10 22:36:59)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
zcrypt.c
r49bc81e r356465e 9 9 #include <stdio.h> 10 10 11 12 11 #include <unistd.h> 13 12 #include <sys/types.h> 14 13 #include <zephyr/zephyr.h> 15 14 #include <glib.h> 15 #include <string.h> 16 #include <stdlib.h> 17 #include <sys/wait.h> 16 18 17 19 #ifdef HAVE_KERBEROS_IV … … 49 51 int do_encrypt(char *keystring, int zephyr, char *class, char *instance, 50 52 ZWRITEOPTIONS *zoptions, char* keyfile); 51 intdo_decrypt(char *keystring);53 void do_decrypt(char *keystring); 52 54 53 55 #define M_NONE 0 … … 58 60 #define M_SETKEY 5 59 61 60 main(int argc, char *argv[]) 62 static void owl_zcrypt_string_to_schedule(char *keystring, des_key_schedule schedule) { 63 #ifdef HAVE_KERBEROS_IV 64 des_cblock key; 65 #else 66 des_cblock _key, *key = &_key; 67 #endif 68 69 des_string_to_key(keystring, key); 70 des_key_sched(key, schedule); 71 } 72 73 int main(int argc, char *argv[]) 61 74 { 62 75 char *fname = NULL; … … 229 242 printf("Enter new key: "); 230 243 /* Really should read without echo!!! */ 231 fgets(newkey, MAX_KEY - 1, stdin); 232 } 233 else 234 fgets(newkey, MAX_KEY - 1, stdin); 244 } 245 if(!fgets(newkey, MAX_KEY - 1, stdin)) { 246 fprintf(stderr, "Error reading key.\n"); 247 return 1; 248 } 235 249 236 250 fkey = fopen(fname, "w"); … … 260 274 { 261 275 char keystring[MAX_KEY]; 262 fgets(keystring, MAX_KEY-1, fkey); 276 if(!fgets(keystring, MAX_KEY-1, fkey)) { 277 fclose(fkey); 278 fprintf(stderr, "Error reading key file.\n"); 279 return 1; 280 } 263 281 if (mode == M_ZEPHYR_ENCRYPT || mode == M_ENCRYPT) 264 282 do_encrypt(keystring, (mode == M_ZEPHYR_ENCRYPT), class, instance, … … 274 292 if (mode == M_DECRYPT) 275 293 printf("**END**\n"); 294 return 0; 276 295 } 277 296 … … 304 323 *ptr++ = ' '; 305 324 /* Copy argv[i], leaving ptr pointing to the '\0' copied from temp */ 306 while ( *ptr = *temp++)325 while ((*ptr = *temp++)) 307 326 ptr++; 308 327 } … … 317 336 char *GetZephyrVarKeyFile(char *whoami, char *class, char *instance) 318 337 { 319 int retval; 320 char *keyfile; 338 char *keyfile = NULL; 321 339 char *varname[MAX_SEARCH]; 322 340 int length[MAX_SEARCH], i; … … 351 369 while (!feof(fsearch)) 352 370 { 353 fgets(buffer, MAX_BUFF - 3, fsearch);371 if (!fgets(buffer, MAX_BUFF - 3, fsearch)) break; 354 372 for (i = 0; i < numsearch; i++) 355 373 if (strncasecmp(varname[i], buffer, length[i]) == 0) … … 415 433 pid_t pid; 416 434 FILE *result; 417 char *argv[20], argc = 0; 435 char *argv[20]; 436 int argc = 0; 418 437 419 438 if (pipe(fildes) < 0) … … 481 500 482 501 /* Close the pipe to zwrite */ 483 CloseZephyrPipe(FILE *pipe)502 void CloseZephyrPipe(FILE *pipe) 484 503 { 485 504 fclose(pipe); … … 494 513 #define OUTPUT_BLOCK_SIZE 16 495 514 496 block_to_ascii(char *output, FILE *outfile)515 void block_to_ascii(unsigned char *output, FILE *outfile) 497 516 { 498 517 int i; … … 511 530 ZWRITEOPTIONS *zoptions, char* keyfile) 512 531 { 513 des_cblock key;514 532 des_key_schedule schedule; 515 char input[8], output[8];533 unsigned char input[8], output[8]; 516 534 int size; 517 int save_result = zephyr && isatty(0);518 535 FILE *outfile = stdout; 519 536 int error = FALSE; … … 521 538 int freein = FALSE; 522 539 int use_buffer = FALSE; 523 int num_blocks, last_block_size; 524 525 des_string_to_key(keystring, key); 526 des_key_sched(key, schedule); 540 int num_blocks = 0, last_block_size = 0; 541 542 owl_zcrypt_string_to_schedule(keystring, schedule); 527 543 528 544 if (zephyr) … … 553 569 while (inptr - inbuff < MAX_RESULT - MAX_LINE - 20) 554 570 { 555 fgets(inptr, MAX_LINE, stdin); 571 if (!fgets(inptr, MAX_LINE, stdin)) 572 return FALSE; 556 573 if (inptr[0]) 557 574 { … … 619 636 620 637 /* Encrypt and output the block */ 621 des_ecb_encrypt( input,output, schedule, TRUE);638 des_ecb_encrypt(&input, &output, schedule, TRUE); 622 639 block_to_ascii(output, outfile); 623 640 … … 641 658 /* Read a half-byte from stdin, skipping invalid characters. Returns -1 642 659 if at EOF or file error */ 643 int read_ascii_nybble( )660 int read_ascii_nybble(void) 644 661 { 645 662 char c; … … 656 673 /* Read both halves of the byte and return the single byte. Returns -1 657 674 if at EOF or file error. */ 658 int read_ascii_byte( )675 int read_ascii_byte(void) 659 676 { 660 677 int c1, c2; … … 672 689 673 690 /* Read an 8-byte DES block from stdin */ 674 int read_ascii_block( char *input)691 int read_ascii_block(unsigned char *input) 675 692 { 676 693 int c; … … 690 707 691 708 /* Decrypt stdin */ 692 int do_decrypt(char *keystring) 693 { 694 des_cblock key; 709 void do_decrypt(char *keystring) 710 { 695 711 des_key_schedule schedule; 696 char input[8], output[9]; 697 int size; 712 unsigned char input[8], output[8]; 698 713 699 714 output[0] = '\0'; /* In case no message at all */ 700 output[8] = '\0'; /* NULL at end will limit string length to 8 */ 701 702 des_string_to_key(keystring, key); 703 des_key_sched(key, schedule); 715 716 owl_zcrypt_string_to_schedule(keystring, schedule); 704 717 705 718 while (read_ascii_block(input)) 706 719 { 707 des_ecb_encrypt( input,output, schedule, FALSE);720 des_ecb_encrypt(&input, &output, schedule, FALSE); 708 721 printf("%s", output); 709 722 } 710 723 711 if (output[0]) 712 { 713 if (output[strlen(output)-1] != '\n') 724 if (!output[0] || output[strlen((const char*)output) - 1] != '\n') 714 725 printf("\n"); 715 } 716 else 717 printf("\n"); 718 } 726 }
Note: See TracChangeset
for help on using the changeset viewer.