- Timestamp:
- Jun 22, 2013, 9:49:49 PM (11 years ago)
- Parents:
- 96d80e9 (diff), 7f86e3d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
zcrypt.c
r7f86e3d r8f335a8 16 16 #include <sys/wait.h> 17 17 #include <ctype.h> 18 19 #include "config.h" 18 #include <limits.h> 19 #include <getopt.h> 20 21 #include <config.h> 20 22 21 23 #ifdef HAVE_KERBEROS_IV … … 26 28 27 29 #include "filterproc.h" 30 31 #ifndef OWL_VERSION_STRING 32 #ifdef GIT_VERSION 33 #define stringify(x) __stringify(x) 34 #define __stringify(x) #x 35 #define OWL_VERSION_STRING stringify(GIT_VERSION) 36 #else 37 #define OWL_VERSION_STRING PACKAGE_VERSION 38 #endif 39 #endif /* !OWL_VERSION_STRING */ 40 41 /* Annotate functions in which the caller owns the return value and is 42 * responsible for ensuring it is freed. */ 43 #define CALLER_OWN G_GNUC_WARN_UNUSED_RESULT 28 44 29 45 #define MAX_KEY 128 … … 53 69 } ZWRITEOPTIONS; 54 70 55 char *GetZephyrVarKeyFile(const char *whoami, const char *class, const char *instance);71 CALLER_OWN char *GetZephyrVarKeyFile(const char *whoami, const char *class, const char *instance); 56 72 int ParseCryptSpec(const char *spec, const char **keyfile); 57 char *BuildArgString(char **argv, int start, int end);58 char *read_keystring(const char *keyfile);73 CALLER_OWN char *BuildArgString(char **argv, int start, int end); 74 CALLER_OWN char *read_keystring(const char *keyfile); 59 75 60 76 int do_encrypt(int zephyr, const char *class, const char *instance, … … 100 116 des_string_to_key(keystring, key); 101 117 des_key_sched(key, *schedule); 118 } 119 120 void usage(FILE *file, const char *progname) 121 { 122 fprintf(file, "Usage: %s [-Z|-D|-E|-R|-S] [-F Keyfile] [-c class] [-i instance]\n", progname); 123 fprintf(file, " [-advqtluon] [-s signature] [-f arg] [-m message]\n"); 124 fprintf(file, " One or more of class, instance, and keyfile must be specified.\n"); 102 125 } 103 126 … … 112 135 int mode = M_NONE; 113 136 114 charc;137 int c; 115 138 116 139 int messageflag = FALSE; … … 118 141 zoptions.flags = 0; 119 142 120 while ((c = getopt(argc, argv, "ZDERSF:c:i:advqtluons:f:m")) != (char)EOF) 143 enum { 144 OPT_VERSION = CHAR_MAX + 1, 145 OPT_HELP, 146 }; 147 static const struct option options[] = { 148 {"version", no_argument, NULL, OPT_VERSION}, 149 {"help", no_argument, NULL, OPT_HELP}, 150 {NULL, 0, NULL, 0} 151 }; 152 153 while ((c = getopt_long(argc, argv, "ZDERSF:c:i:advqtluons:f:m", options, NULL)) != -1) 121 154 { 122 155 switch(c) 123 156 { 157 case OPT_VERSION: 158 /* Version */ 159 printf("This is zcrypt version %s\n", OWL_VERSION_STRING); 160 exit(0); 161 case OPT_HELP: 162 /* Help */ 163 usage(stdout, argv[0]); 164 exit(0); 124 165 case 'Z': 125 166 /* Zephyr encrypt */ … … 253 294 if (error || !cryptspec) 254 295 { 255 fprintf(stderr, "Usage: %s [-Z|-D|-E|-R|-S] [-F Keyfile] [-c class] [-i instance]\n", argv[0]); 256 fprintf(stderr, " [-advqtluon] [-s signature] [-f arg] [-m message]\n"); 257 fprintf(stderr, " One or more of class, instance, and keyfile must be specified.\n"); 296 usage(stderr, argv[0]); 258 297 exit(1); 259 298 } … … 364 403 /* Build a space-separated string from argv from elements between start * 365 404 * and end - 1. malloc()'s the returned string. */ 366 char *BuildArgString(char **argv, int start, int end)405 CALLER_OWN char *BuildArgString(char **argv, int start, int end) 367 406 { 368 407 int len = 1; … … 401 440 #define MAX_SEARCH 3 402 441 /* Find the class/instance in the .crypt-table */ 403 char *GetZephyrVarKeyFile(const char *whoami, const char *class, const char *instance)442 CALLER_OWN char *GetZephyrVarKeyFile(const char *whoami, const char *class, const char *instance) 404 443 { 405 444 char *keyfile = NULL; … … 407 446 int length[MAX_SEARCH], i; 408 447 char buffer[MAX_BUFF]; 448 const char *home; 409 449 char *filename; 410 450 char result[MAX_SEARCH][MAX_BUFF]; … … 429 469 430 470 /* Open~/.crypt-table */ 431 filename = g_strdup_printf("%s/.crypt-table", getenv("HOME")); 471 home = getenv("HOME"); 472 if (home == NULL) 473 home = g_get_home_dir(); 474 filename = g_build_filename(home, ".crypt-table", NULL); 432 475 fsearch = fopen(filename, "r"); 433 476 if (fsearch) … … 579 622 } 580 623 581 char *slurp_stdin(int ignoredot, int *length) {624 CALLER_OWN char *slurp_stdin(int ignoredot, int *length) { 582 625 char *buf; 583 626 char *inptr; … … 611 654 } 612 655 613 char *GetInputBuffer(ZWRITEOPTIONS *zoptions, int *length) {656 CALLER_OWN char *GetInputBuffer(ZWRITEOPTIONS *zoptions, int *length) { 614 657 char *buf; 615 658 … … 637 680 } 638 681 639 char *read_keystring(const char *keyfile) {682 CALLER_OWN char *read_keystring(const char *keyfile) { 640 683 char *keystring; 641 684 FILE *fkey = fopen(keyfile, "r"); … … 758 801 "gpg", 759 802 "--symmetric", 803 "--no-options", 804 "--no-default-keyring", 805 "--keyring", "/dev/null", 806 "--secret-keyring", "/dev/null", 760 807 "--batch", 761 808 "--quiet", … … 766 813 NULL 767 814 }; 768 err = call_filter( "gpg",argv, in, &out, &status);815 err = call_filter(argv, in, &out, &status); 769 816 if(err || status) { 770 817 g_free(out); … … 838 885 "gpg", 839 886 "--decrypt", 887 "--no-options", 888 "--no-default-keyring", 889 "--keyring", "/dev/null", 890 "--secret-keyring", "/dev/null", 840 891 "--batch", 841 892 "--no-use-agent", … … 849 900 if(!in) return FALSE; 850 901 851 err = call_filter("gpg", argv, in, &out, &status); 902 err = call_filter(argv, in, &out, &status); 903 free(in); 852 904 if(err || status) { 853 905 g_free(out);
Note: See TracChangeset
for help on using the changeset viewer.