Changeset f7f35c0


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

Legend:

Unmodified
Added
Removed
  • zcrypt.c

    r4133e34 rf7f35c0  
    5050char *BuildArgString(char **argv, int start, int end);
    5151int do_encrypt(char *keystring, int zephyr, char *class, char *instance,
    52           ZWRITEOPTIONS *zoptions, char* keyfile);
    53 void do_decrypt(char *keystring);
     52          ZWRITEOPTIONS *zoptions, char* keyfile);
     53int do_decrypt(char *keystring);
    5454
    5555#define M_NONE            0
     
    9494        /* Zephyr encrypt */
    9595        mode = M_ZEPHYR_ENCRYPT;
    96         break;
     96        break;
    9797      case 'D':
    9898        /* Decrypt */
    99         mode = M_DECRYPT;
    100         break;
     99        mode = M_DECRYPT;
     100        break;
    101101      case 'E':
    102         /* Encrypt */
    103         mode = M_ENCRYPT;
    104         break;
     102        /* Encrypt */
     103        mode = M_ENCRYPT;
     104        break;
    105105      case 'R':
    106         /* Randomize the keyfile */
    107         mode = M_RANDOMIZE;
    108         break;
     106        /* Randomize the keyfile */
     107        mode = M_RANDOMIZE;
     108        break;
    109109      case 'S':
    110         /* Set a new key value from stdin */
    111         mode = M_SETKEY;
    112         break;
     110        /* Set a new key value from stdin */
     111        mode = M_SETKEY;
     112        break;
    113113      case 'F':
    114         /* Specify the keyfile explicitly */
    115         if (fname != NULL) error = TRUE;
    116         fname = optarg;
    117         break;
     114        /* Specify the keyfile explicitly */
     115        if (fname != NULL) error = TRUE;
     116        fname = optarg;
     117        break;
    118118      case 'c':
    119         /* Zwrite/zcrypt: class name */
    120         if (class != NULL) error = TRUE;
    121         class = optarg;
    122         break;
     119        /* Zwrite/zcrypt: class name */
     120        if (class != NULL) error = TRUE;
     121        class = optarg;
     122        break;
    123123      case 'i':
    124         /* Zwrite/zcrypt: instance name */
    125         if (instance != NULL) error = TRUE;
    126         instance = optarg;
    127         break;
     124        /* Zwrite/zcrypt: instance name */
     125        if (instance != NULL) error = TRUE;
     126        instance = optarg;
     127        break;
    128128      case 'a':
    129         /* Zwrite: authenticate (default) */
    130         zoptions.flags &= ~ZWRITE_OPT_NOAUTH;
    131         break;
     129        /* Zwrite: authenticate (default) */
     130        zoptions.flags &= ~ZWRITE_OPT_NOAUTH;
     131        break;
    132132      case 'd':
    133         /* Zwrite: do not authenticate */
    134         zoptions.flags |= ZWRITE_OPT_NOAUTH;
    135         break;
     133        /* Zwrite: do not authenticate */
     134        zoptions.flags |= ZWRITE_OPT_NOAUTH;
     135        break;
    136136      case 'v':
    137         /* Zwrite: verbose */
    138         zoptions.flags |= ZWRITE_OPT_VERBOSE;
    139         break;
     137        /* Zwrite: verbose */
     138        zoptions.flags |= ZWRITE_OPT_VERBOSE;
     139        break;
    140140      case 'q':
    141         /* Zwrite: quiet */
    142         zoptions.flags |= ZWRITE_OPT_QUIET;
    143         break;
     141        /* Zwrite: quiet */
     142        zoptions.flags |= ZWRITE_OPT_QUIET;
     143        break;
    144144      case 't':
    145         /* Zwrite: no expand tabs (ignored) */
    146         break;
     145        /* Zwrite: no expand tabs (ignored) */
     146        break;
    147147      case 'l':
    148         /* Zwrite: ignore '.' on a line by itself (ignored) */
    149         zoptions.flags |= ZCRYPT_OPT_IGNOREDOT;
    150         break;
     148        /* Zwrite: ignore '.' on a line by itself (ignored) */
     149        zoptions.flags |= ZCRYPT_OPT_IGNOREDOT;
     150        break;
    151151      case 'u':
    152         /* Zwrite: urgent message */
    153         instance = "URGENT";
    154         break;
     152        /* Zwrite: urgent message */
     153        instance = "URGENT";
     154        break;
    155155      case 'o':
    156         /* Zwrite: ignore zephyr variables zwrite-class, zwrite-inst, */
    157         /*         zwrite-opcode */
    158         zoptions.flags |= ZWRITE_OPT_IGNOREVARS;
    159         break;
     156        /* Zwrite: ignore zephyr variables zwrite-class, zwrite-inst, */
     157        /*         zwrite-opcode */
     158        zoptions.flags |= ZWRITE_OPT_IGNOREVARS;
     159        break;
    160160      case 'n':
    161         /* Zwrite: prevent PING message (always used) */
    162         break;
     161        /* Zwrite: prevent PING message (always used) */
     162        break;
    163163      case 's':
    164         /* Zwrite: signature */
    165         zoptions.flags |= ZWRITE_OPT_SIGNATURE;
    166         zoptions.signature = optarg;
    167         break;
     164        /* Zwrite: signature */
     165        zoptions.flags |= ZWRITE_OPT_SIGNATURE;
     166        zoptions.signature = optarg;
     167        break;
    168168      case 'f':
    169         /* Zwrite: file system specification (ignored) */
    170         break;
     169        /* Zwrite: file system specification (ignored) */
     170        break;
    171171      case 'm':
    172         /* Message on rest of line*/
    173         messageflag = TRUE;
    174         break;
     172        /* Message on rest of line*/
     173        messageflag = TRUE;
     174        break;
    175175      case '?':
    176         error = TRUE;
    177         break;
     176        error = TRUE;
     177        break;
    178178    }
    179179    if (error || messageflag)
     
    227227      FILE *fkey = fopen(fname, "w");
    228228      if (!fkey)
    229         printf("Could not open key file for writing: %s\n", fname);
     229        printf("Could not open key file for writing: %s\n", fname);
    230230      else
    231231      {
    232         char string[100];
    233         fputs(fkey, string);
    234         fclose(fkey);
    235         }
     232        char string[100];
     233        fputs(fkey, string);
     234        fclose(fkey);
     235        }
    236236 */
    237237      fprintf(stderr, "Feature not yet implemented.\n");
     
    245245      if (isatty(0))
    246246      {
    247         printf("Enter new key: ");
    248         /* Really should read without echo!!! */
     247        printf("Enter new key: ");
     248        /* Really should read without echo!!! */
    249249      }
    250250      if(!fgets(newkey, MAX_KEY - 1, stdin)) {
     
    255255      fkey = fopen(fname, "w");
    256256      if (!fkey)
    257         fprintf(stderr, "Could not open key file for writing: %s\n", fname);
     257        fprintf(stderr, "Could not open key file for writing: %s\n", fname);
    258258      else
    259259      {
    260         if (fputs(newkey, fkey) != strlen(newkey) || putc('\n', fkey) != '\n')
    261         {
    262           fprintf(stderr, "Error writing to key file.\n");
    263           fclose(fkey);
     260        if (fputs(newkey, fkey) != strlen(newkey) || putc('\n', fkey) != '\n')
     261        {
     262          fprintf(stderr, "Error writing to key file.\n");
     263          fclose(fkey);
    264264          exit(1);
    265         }
    266         else
    267         {
    268           fclose(fkey);
    269           fprintf(stderr, "Key update complete.\n");
    270         }
     265        }
     266        else
     267        {
     268          fclose(fkey);
     269          fprintf(stderr, "Key update complete.\n");
     270        }
    271271      }
    272272    }
     
    276276      FILE *fkey = fopen(fname, "r");
    277277      if (!fkey) {
    278         fprintf(stderr, "Could not open key file: %s\n", fname);
     278        fprintf(stderr, "Could not open key file: %s\n", fname);
    279279        exit(1);
    280280      }
    281281      else
    282282      {
    283         char keystring[MAX_KEY];
    284         if(!fgets(keystring, MAX_KEY-1, fkey)) {
     283        char keystring[MAX_KEY];
     284        if(!fgets(keystring, MAX_KEY-1, fkey)) {
    285285          fclose(fkey);
    286286          fprintf(stderr, "Error reading key file.\n");
    287287          return 1;
    288288        }
    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);
     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);
    295295      }
    296296    }
     
    329329      /* Add a space, if not the first argument */
    330330      if (i != start)
    331         *ptr++ = ' ';
     331        *ptr++ = ' ';
    332332      /* Copy argv[i], leaving ptr pointing to the '\0' copied from temp */
    333333      while ((*ptr = *temp++))
    334         ptr++;
     334        ptr++;
    335335    }
    336336  }
     
    379379      if (!fgets(buffer, MAX_BUFF - 3, fsearch)) break;
    380380      for (i = 0; i < numsearch; i++)
    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         }
     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        }
    391391    }
    392392
     
    396396      if (*result[i])
    397397      {
    398         keyfile = result[i];
    399         break;
     398        keyfile = result[i];
     399        break;
    400400      }
    401401
     
    410410      keyfile = (char *)malloc(strlen(temp) + 1);
    411411      if (keyfile)
    412         strcpy(keyfile, temp);
     412        strcpy(keyfile, temp);
    413413      else
    414         fprintf(stderr, "Memory allocation error.\n");
     414        fprintf(stderr, "Memory allocation error.\n");
    415415    }
    416416   
     
    488488    {
    489489      if (dup2(fildes[0], STDIN_FILENO) != STDIN_FILENO)
    490         exit(0);
     490        exit(0);
    491491      close(fildes[0]);
    492492    }
     
    536536   if zephyr is set. */
    537537int do_encrypt(char *keystring, int zephyr, char *class, char *instance,
    538           ZWRITEOPTIONS *zoptions, char* keyfile)
     538          ZWRITEOPTIONS *zoptions, char* keyfile)
    539539{
    540540  des_key_schedule schedule;
     
    566566      /* tty input, so show the "Type your message now..." message */
    567567      if (zoptions->flags & ZCRYPT_OPT_IGNOREDOT)
    568         printf("Type your message now.  End with the end-of-file character.\n");
     568        printf("Type your message now.  End with the end-of-file character.\n");
    569569      else
    570         printf("Type your message now.  End with control-D or a dot on a line by itself.\n");
     570        printf("Type your message now.  End with control-D or a dot on a line by itself.\n");
    571571      use_buffer = TRUE;
    572572      if ((inptr = inbuff = (char *)malloc(MAX_RESULT)) == NULL)
    573573      {
    574         fprintf(stderr, "Memory allocation error\n");
    575         return FALSE;
     574        fprintf(stderr, "Memory allocation error\n");
     575        return FALSE;
    576576      }
    577577      while (inptr - inbuff < MAX_RESULT - MAX_LINE - 20)
    578578      {
    579         if (!fgets(inptr, MAX_LINE, stdin))
     579        if (!fgets(inptr, MAX_LINE, stdin))
    580580          return FALSE;
    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;
     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;
    594594      }
    595595      num_blocks = (inptr - inbuff + 7) / 8;
     
    604604      fprintf(stderr, "Could not run zwrite\n");
    605605      if (freein && inbuff)
    606         free(inbuff);
     606        free(inbuff);
    607607      return FALSE;
    608608    }
     
    619619      if (num_blocks > 1)
    620620      {
    621         size = 8;
    622         memcpy(input, inptr, size);
    623         inptr += 8;
    624         num_blocks--;
     621        size = 8;
     622        memcpy(input, inptr, size);
     623        inptr += 8;
     624        num_blocks--;
    625625      }
    626626      else if (num_blocks == 1)
    627627      {
    628         size = last_block_size;
    629         memcpy(input, inptr, size);
    630         num_blocks--;
     628        size = last_block_size;
     629        memcpy(input, inptr, size);
     630        num_blocks--;
    631631      }
    632632      else
    633         size = 0;
     633        size = 0;
    634634    }
    635635    else
Note: See TracChangeset for help on using the changeset viewer.