Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zcrypt.c

    r36486be ra6ac9fe  
    2323#include <unistd.h>
    2424#include <sys/types.h>
    25 #include <des.h>
     25
     26#ifdef HAVE_KERBEROS_IV
     27#include <kerberosIV/des.h>
     28#else
     29#include <openssl/des.h>
     30#endif
    2631
    2732#define MAX_KEY 128
     
    5156char *GetZephyrVarKeyFile(const char *whoami, const char *class, const char *instance);
    5257
    53 #ifndef HAVE_DES_ECB_ENCRYPT_PROTO
    54 int des_ecb_encrypt(char [], char [], des_key_schedule, int);
    55 #endif
    56 
    5758#define M_NONE            0
    5859#define M_ZEPHYR_ENCRYPT  1
     
    6162#define M_RANDOMIZE       4
    6263#define M_SETKEY          5
     64
     65static void owl_zcrypt_string_to_schedule(char *keystring, des_key_schedule schedule) {
     66#ifdef HAVE_KERBEROS_IV
     67  des_cblock key;
     68#else
     69  des_cblock _key, *key = &_key;
     70#endif
     71
     72  des_string_to_key(keystring, key);
     73  des_key_sched(key, schedule);
     74}
    6375
    6476/* The 'owl_zcrypt_decrypt' function was written by kretch for Owl.
     
    7385  char *fname, keystring[MAX_KEY];
    7486  FILE *fkey;
    75   des_cblock key;
    7687  des_key_schedule schedule;
    77   char input[8], output[9];
     88  unsigned char input[8], output[8];
    7889  int i, c1, c2;
    7990 
     
    8293  fkey=fopen(fname, "r");
    8394  if (!fkey) return(-1);
    84   fgets(keystring, MAX_KEY-1, fkey);
     95  if (!fgets(keystring, MAX_KEY-1, fkey)) {
     96    fclose(fkey);
     97    return -1;
     98  }
    8599  fclose(fkey);
    86100
     
    88102
    89103  output[0] = '\0';    /* In case no message at all                 */
    90   output[8] = '\0';    /* NULL at end will limit string length to 8 */
    91 
    92   des_string_to_key(keystring, key);
    93   des_key_sched(key, schedule);
     104
     105  owl_zcrypt_string_to_schedule(keystring, schedule);
    94106
    95107  inptr=in;
     
    102114      inptr+=2;
    103115    }
    104     des_ecb_encrypt(input, output, schedule, FALSE);
    105     strcat(out, output);
    106   }
    107 
    108   if (output[0]) {
    109     if (output[strlen(output)-1] != '\n') {
    110       strcat(out, "\n");
    111     }
    112   } else {
     116    des_ecb_encrypt(&input, &output, schedule, FALSE);
     117    strncat(out, (const char *)output, 8);
     118  }
     119
     120  if (out[0] && out[strlen(out) - 1] != '\n')
    113121    strcat(out, "\n");
    114   }
    115122  return(0);
    116123}
     
    119126  char *fname, keystring[MAX_KEY];
    120127  FILE *fkey;
    121   des_cblock key;
    122128  des_key_schedule schedule;
    123   char input[8], output[8];
     129  unsigned char input[8], output[8];
    124130  int size, length, i;
    125131  const char *inbuff = NULL, *inptr;
    126   int use_buffer = FALSE;
    127132  int num_blocks=0, last_block_size=0;
    128133
     
    131136  fkey=fopen(fname, "r");
    132137  if (!fkey) return(-1);
    133   fgets(keystring, MAX_KEY-1, fkey);
     138  if (!fgets(keystring, MAX_KEY-1, fkey)) {
     139    fclose(fkey);
     140    return -1;
     141  }
    134142  fclose(fkey);
    135143
    136   des_string_to_key(keystring, key);
    137   des_key_sched(key, schedule);
     144  owl_zcrypt_string_to_schedule(keystring, schedule);
    138145
    139146  inbuff=in;
     
    141148  num_blocks=(length+7)/8;
    142149  last_block_size=((length+7)%8)+1;
    143   use_buffer=TRUE;
    144150
    145151  strcpy(out, "");
     
    167173
    168174    /* Encrypt and output the block */
    169     des_ecb_encrypt(input, output, schedule, TRUE);
     175    des_ecb_encrypt(&input, &output, schedule, TRUE);
    170176
    171177    for (i = 0; i < 8; i++) {
     
    216222    /* Scan file for a match */
    217223    while (!feof(fsearch)) {
    218       fgets(buffer, MAX_BUFF - 3, fsearch);
     224      if (!fgets(buffer, MAX_BUFF - 3, fsearch)) break;
    219225      for (i = 0; i < numsearch; i++) {
    220226        if (strncasecmp(varname[i], buffer, length[i]) == 0) {
     
    262268}
    263269
    264 static pid_t zephyrpipe_pid = 0;
    265 
    266 #endif
     270#endif
Note: See TracChangeset for help on using the changeset viewer.