Use some symbolic constants where possible - take some of the magic out
of this. Make the --list-keys command work again.
This commit is contained in:
parent
f024404c50
commit
ff02cd3e84
@ -79,6 +79,11 @@ enum optdefs {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
USERID_RAW_LEN = OPS_KEY_ID_SIZE,
|
||||||
|
USERID_FORMATTED = USERID_RAW_LEN * 2
|
||||||
|
};
|
||||||
|
|
||||||
#define EXIT_ERROR 2
|
#define EXIT_ERROR 2
|
||||||
|
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
@ -108,7 +113,7 @@ static struct option long_options[] = {
|
|||||||
/* debug */
|
/* debug */
|
||||||
{"debug", required_argument, NULL, OPS_DEBUG},
|
{"debug", required_argument, NULL, OPS_DEBUG},
|
||||||
|
|
||||||
{0, 0, 0, 0},
|
{ NULL, 0, NULL, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
/* gather up program variables into one struct */
|
/* gather up program variables into one struct */
|
||||||
@ -127,7 +132,7 @@ typedef struct prog_t {
|
|||||||
int armour; /* ASCII armor */
|
int armour; /* ASCII armor */
|
||||||
int cmd; /* openpgp command */
|
int cmd; /* openpgp command */
|
||||||
int ex; /* exit code */
|
int ex; /* exit code */
|
||||||
} prog_t;
|
} prog_t;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -146,24 +151,24 @@ get_pass_phrase(char *phrase, size_t size)
|
|||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
if ((p = getpass("openpgp pass phrase: ")) == NULL) {
|
if ((p = getpass("openpgp passphrase: ")) == NULL) {
|
||||||
exit(EXIT_ERROR);
|
exit(EXIT_ERROR);
|
||||||
}
|
}
|
||||||
(void) snprintf(phrase, size, "%s", p);
|
(void) snprintf(phrase, size, "%s", p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* small function to pretty print an 8character raw userid */
|
/* small function to pretty print an 8-character raw userid */
|
||||||
static char *
|
static char *
|
||||||
userid_to_id(const unsigned char *userid, char *id)
|
userid_to_id(const unsigned char *userid, char *id)
|
||||||
{
|
{
|
||||||
static const char *hexes = "0123456789ABCDEF";
|
static const char *hexes = "0123456789ABCDEF";
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < USERID_RAW_LEN ; i++) {
|
||||||
id[i * 2] = hexes[(userid[i] & 0xf0) >> 4];
|
id[i * 2] = hexes[(userid[i] & 0xf0) >> 4];
|
||||||
id[(i * 2) + 1] = hexes[userid[i] & 0xf];
|
id[(i * 2) + 1] = hexes[userid[i] & 0xf];
|
||||||
}
|
}
|
||||||
id[16] = 0x0;
|
id[USERID_FORMATTED] = 0x0;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +177,7 @@ static void
|
|||||||
psuccess(char *f, ops_validate_result_t * results, ops_keyring_t *pubring)
|
psuccess(char *f, ops_validate_result_t * results, ops_keyring_t *pubring)
|
||||||
{
|
{
|
||||||
const ops_keydata_t *pubkey;
|
const ops_keydata_t *pubkey;
|
||||||
char id[17];
|
char id[USERID_FORMATTED + 1];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < results->valid_count; i++) {
|
for (i = 0; i < results->valid_count; i++) {
|
||||||
@ -412,6 +417,7 @@ main(int argc, char **argv)
|
|||||||
char homedir[MAXBUF + 1];
|
char homedir[MAXBUF + 1];
|
||||||
char default_homedir[MAXBUF + 1];
|
char default_homedir[MAXBUF + 1];
|
||||||
char *dir;
|
char *dir;
|
||||||
|
int zeroargs;
|
||||||
int optindex = 0;
|
int optindex = 0;
|
||||||
int ch = 0;
|
int ch = 0;
|
||||||
int i;
|
int i;
|
||||||
@ -419,6 +425,7 @@ main(int argc, char **argv)
|
|||||||
pname = argv[0];
|
pname = argv[0];
|
||||||
(void) memset(&p, 0x0, sizeof(p));
|
(void) memset(&p, 0x0, sizeof(p));
|
||||||
(void) memset(homedir, 0x0, sizeof(homedir));
|
(void) memset(homedir, 0x0, sizeof(homedir));
|
||||||
|
zeroargs = 0;
|
||||||
p.numbits = DEFAULT_NUMBITS;
|
p.numbits = DEFAULT_NUMBITS;
|
||||||
p.overwrite = ops_true;
|
p.overwrite = ops_true;
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
@ -434,6 +441,9 @@ main(int argc, char **argv)
|
|||||||
switch (long_options[optindex].val) {
|
switch (long_options[optindex].val) {
|
||||||
/* commands */
|
/* commands */
|
||||||
case LIST_KEYS:
|
case LIST_KEYS:
|
||||||
|
zeroargs = 1;
|
||||||
|
p.cmd = long_options[optindex].val;
|
||||||
|
break;
|
||||||
case FIND_KEY:
|
case FIND_KEY:
|
||||||
case EXPORT_KEY:
|
case EXPORT_KEY:
|
||||||
case IMPORT_KEY:
|
case IMPORT_KEY:
|
||||||
@ -516,9 +526,9 @@ main(int argc, char **argv)
|
|||||||
* We will then have variables pubring, secring and myring.
|
* We will then have variables pubring, secring and myring.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (homedir[0])
|
if (homedir[0]) {
|
||||||
dir = homedir;
|
dir = homedir;
|
||||||
else {
|
} else {
|
||||||
(void) snprintf(default_homedir, MAXBUF, "%s/.gnupg",
|
(void) snprintf(default_homedir, MAXBUF, "%s/.gnupg",
|
||||||
getenv("HOME"));
|
getenv("HOME"));
|
||||||
if (ops_get_debug_level(__FILE__)) {
|
if (ops_get_debug_level(__FILE__)) {
|
||||||
@ -547,12 +557,17 @@ main(int argc, char **argv)
|
|||||||
exit(EXIT_ERROR);
|
exit(EXIT_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* now do the required action for each of the files on the command
|
* now do the required action for each of the files on the command
|
||||||
* line
|
* line
|
||||||
*/
|
*/
|
||||||
for (p.ex = EXIT_SUCCESS, i = optind; i < argc; i++) {
|
if (zeroargs) {
|
||||||
openpgp(&p, argv[i]);
|
openpgp(&p, NULL);
|
||||||
|
} else {
|
||||||
|
for (p.ex = EXIT_SUCCESS, i = optind; i < argc; i++) {
|
||||||
|
openpgp(&p, argv[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.pubring) {
|
if (p.pubring) {
|
||||||
|
Loading…
Reference in New Issue
Block a user