Changeset 356465e


Ignore:
Timestamp:
Mar 17, 2010, 10:36:59 PM (10 years ago)
Author:
Nelson Elhage <nelhage@ksplice.com>
Branches:
master, 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)
Message:
zcrypt.c: Clean up warnings.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zcrypt.c

    r49bc81e r356465e  
    99#include <stdio.h>
    1010
    11 
    1211#include <unistd.h>
    1312#include <sys/types.h>
    1413#include <zephyr/zephyr.h>
    1514#include <glib.h>
     15#include <string.h>
     16#include <stdlib.h>
     17#include <sys/wait.h>
    1618
    1719#ifdef HAVE_KERBEROS_IV
     
    4951int do_encrypt(char *keystring, int zephyr, char *class, char *instance,
    5052          ZWRITEOPTIONS *zoptions, char* keyfile);
    51 int do_decrypt(char *keystring);
     53void do_decrypt(char *keystring);
    5254
    5355#define M_NONE            0
     
    5860#define M_SETKEY          5
    5961
    60 main(int argc, char *argv[])
     62static 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
     73int main(int argc, char *argv[])
    6174{
    6275  char *fname = NULL;
     
    229242        printf("Enter new key: ");
    230243        /* 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      }
    235249
    236250      fkey = fopen(fname, "w");
     
    260274      {
    261275        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        }
    263281        if (mode == M_ZEPHYR_ENCRYPT || mode == M_ENCRYPT)
    264282          do_encrypt(keystring, (mode == M_ZEPHYR_ENCRYPT), class, instance,
     
    274292  if (mode == M_DECRYPT)
    275293    printf("**END**\n");
     294  return 0;
    276295}
    277296
     
    304323        *ptr++ = ' ';
    305324      /* Copy argv[i], leaving ptr pointing to the '\0' copied from temp */
    306       while (*ptr = *temp++)
     325      while ((*ptr = *temp++))
    307326        ptr++;
    308327    }
     
    317336char *GetZephyrVarKeyFile(char *whoami, char *class, char *instance)
    318337{
    319   int retval;
    320   char *keyfile;
     338  char *keyfile = NULL;
    321339  char *varname[MAX_SEARCH];
    322340  int length[MAX_SEARCH], i;
     
    351369    while (!feof(fsearch))
    352370    {
    353       fgets(buffer, MAX_BUFF - 3, fsearch);
     371      if (!fgets(buffer, MAX_BUFF - 3, fsearch)) break;
    354372      for (i = 0; i < numsearch; i++)
    355373        if (strncasecmp(varname[i], buffer, length[i]) == 0)
     
    415433  pid_t pid;
    416434  FILE *result;
    417   char *argv[20], argc = 0;
     435  char *argv[20];
     436  int argc = 0;
    418437
    419438  if (pipe(fildes) < 0)
     
    481500
    482501/* Close the pipe to zwrite */
    483 CloseZephyrPipe(FILE *pipe)
     502void CloseZephyrPipe(FILE *pipe)
    484503{
    485504  fclose(pipe);
     
    494513#define OUTPUT_BLOCK_SIZE 16
    495514
    496 block_to_ascii(char *output, FILE *outfile)
     515void block_to_ascii(unsigned char *output, FILE *outfile)
    497516{
    498517  int i;
     
    511530          ZWRITEOPTIONS *zoptions, char* keyfile)
    512531{
    513   des_cblock key;
    514532  des_key_schedule schedule;
    515   char input[8], output[8];
     533  unsigned char input[8], output[8];
    516534  int size;
    517   int save_result = zephyr && isatty(0);
    518535  FILE *outfile = stdout;
    519536  int error = FALSE;
     
    521538  int freein = FALSE;
    522539  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);
    527543
    528544  if (zephyr)
     
    553569      while (inptr - inbuff < MAX_RESULT - MAX_LINE - 20)
    554570      {
    555         fgets(inptr, MAX_LINE, stdin);
     571        if (!fgets(inptr, MAX_LINE, stdin))
     572          return FALSE;
    556573        if (inptr[0])
    557574        {
     
    619636
    620637    /* Encrypt and output the block */
    621     des_ecb_encrypt(input, output, schedule, TRUE);
     638    des_ecb_encrypt(&input, &output, schedule, TRUE);
    622639    block_to_ascii(output, outfile);
    623640
     
    641658/* Read a half-byte from stdin, skipping invalid characters.  Returns -1
    642659   if at EOF or file error */
    643 int read_ascii_nybble()
     660int read_ascii_nybble(void)
    644661{
    645662  char c;
     
    656673/* Read both halves of the byte and return the single byte.  Returns -1
    657674   if at EOF or file error. */
    658 int read_ascii_byte()
     675int read_ascii_byte(void)
    659676{
    660677  int c1, c2;
     
    672689
    673690/* Read an 8-byte DES block from stdin */
    674 int read_ascii_block(char *input)
     691int read_ascii_block(unsigned char *input)
    675692{
    676693  int c;
     
    690707
    691708/* Decrypt stdin */
    692 int do_decrypt(char *keystring)
    693 {
    694   des_cblock key;
     709void do_decrypt(char *keystring)
     710{
    695711  des_key_schedule schedule;
    696   char input[8], output[9];
    697   int size;
     712  unsigned char input[8], output[8];
    698713
    699714  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);
    704717
    705718  while (read_ascii_block(input))
    706719  {
    707     des_ecb_encrypt(input, output, schedule, FALSE);
     720    des_ecb_encrypt(&input, &output, schedule, FALSE);
    708721    printf("%s", output);
    709722  }
    710723
    711   if (output[0])
    712   {
    713     if (output[strlen(output)-1] != '\n')
     724  if (!output[0] || output[strlen((const char*)output) - 1] != '\n')
    714725      printf("\n");
    715   }
    716   else
    717     printf("\n");
    718 }
     726}
Note: See TracChangeset for help on using the changeset viewer.