From 2080828ee85d7f711661e67b75c0964d7b11dbf4 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Tue, 18 Nov 2008 19:02:16 -0500 Subject: [PATCH] Revert "Added OPTION KEYFILE. Setting to 0 will disable trying to read the key" This reverts commit 3d407127fc88960a82650d67caac765ac5589f3e. --- COMMANDS | 3 --- src/commands.c | 34 +++++++----------------- src/common.h | 3 +-- src/pwmd.c | 82 +++++++++++++++++++--------------------------------------- 4 files changed, 36 insertions(+), 86 deletions(-) diff --git a/COMMANDS b/COMMANDS index d560a3f4..ec1e4f4a 100644 --- a/COMMANDS +++ b/COMMANDS @@ -194,9 +194,6 @@ pinentry options: a file, this option is reset to the files setting after opening. The CONFIG status message is sent after receiving this command. - KEYFILE When set to 0, disable trying to read the specified - key_file in the pwmd configuration. The default is 1 - for new clients. When pinentry is used with the SAVE command the key will be asked for confirmation. If the confirmation fails, the process is started over again diff --git a/src/commands.c b/src/commands.c index a6d4c925..70037fe1 100644 --- a/src/commands.c +++ b/src/commands.c @@ -217,7 +217,6 @@ void cleanup_client(struct client_s *client) { assuan_context_t ctx = client->ctx; struct client_thread_s *thd = client->thd; - gboolean keyfile = client->keyfile; #ifdef WITH_PINENTRY struct pinentry_s *pin = client->pinentry; #endif @@ -239,7 +238,6 @@ void cleanup_client(struct client_s *client) client->ctx = ctx; client->thd = thd; client->freed = TRUE; - client->keyfile = keyfile; #ifdef WITH_PINENTRY client->pinentry = pin; #endif @@ -725,10 +723,9 @@ static int open_command(assuan_context_t ctx, char *line) #ifdef WITH_PINENTRY gboolean b = get_key_file_boolean(filename, "enable_pinentry"); #endif - - if (client->keyfile && g_key_file_has_key(keyfileh, - client->filename, "key_file", NULL) == TRUE) { - gchar *tmp = parse_keyfile(client->filename, FALSE, &rc); + if (g_key_file_has_key(keyfileh, client->filename, "key_file", + NULL) == TRUE) { + gchar *tmp = parse_keyfile(client->filename, FALSE); if (tmp) { gcry_md_hash_buffer(GCRY_MD_SHA256, shakey, tmp, @@ -737,9 +734,8 @@ static int open_command(assuan_context_t ctx, char *line) goto done; } - log_write("key_file: %s", pwmd_strerror(rc)); + unlock_pin_mutex(client->pinentry); cleanup_client(client); - g_strfreev(req); g_free(fh); return send_error(ctx, GPG_ERR_UNUSABLE_SECKEY); } @@ -1277,9 +1273,9 @@ static int save_command(assuan_context_t ctx, char *line) memcmp(shakey, tmp, sizeof(shakey)) == 0) { CACHE_UNLOCK; - if (client->keyfile && g_key_file_has_key(keyfileh, - client->filename, "key_file", NULL) == TRUE) { - gchar *tmp = parse_keyfile(client->filename, FALSE, &rc); + if (g_key_file_has_key(keyfileh, client->filename, "key_file", + NULL) == TRUE) { + gchar *tmp = parse_keyfile(client->filename, FALSE); if (tmp) { gcry_md_hash_buffer(GCRY_MD_SHA256, shakey, tmp, @@ -1289,7 +1285,7 @@ static int save_command(assuan_context_t ctx, char *line) goto done; } - log_write("key_file: %s", pwmd_strerror(rc)); + unlock_pin_mutex(client->pinentry); return send_error(ctx, GPG_ERR_UNUSABLE_SECKEY); } @@ -2368,7 +2364,7 @@ static int getconfig_command(assuan_context_t ctx, gchar *line) if (!paramp) return send_syserror(ctx, ENOMEM); - if (strcmp(paramp, "key") == 0) { + if (strcmp(paramp, "key") == 0 || strcmp(paramp, "key_file") == 0) { g_free(paramp); return send_error(ctx, GPG_ERR_NOT_IMPLEMENTED); } @@ -2709,18 +2705,6 @@ static int option_handler(assuan_context_t ctx, const gchar *name, g_key_file_set_integer(keyfileh, client->filename ? client->filename : "global", "iterations", (guint)n); send_status_all(STATUS_CONFIG); } - else if (g_strcasecmp(name, (gchar *)"keyfile") == 0) { - long n; - gchar *p = NULL; - - errno = 0; - n = strtol(value, &p, 10); - - if (errno || (p && *p) || n < 0 || n > 1) - return gpg_err_make(PWMD_ERR_SOURCE, GPG_ERR_INV_VALUE); - - client->keyfile = n; - } #ifdef WITH_PINENTRY else if (g_strcasecmp(name, (gchar *)"ttyname") == 0) { g_free(client->pinentry->ttyname); diff --git a/src/common.h b/src/common.h index 6ffa5364..72a43e51 100644 --- a/src/common.h +++ b/src/common.h @@ -161,7 +161,6 @@ struct client_s { gcry_cipher_hd_t gh; gchar *filename; guchar md5file[16]; - gboolean keyfile; gboolean new; gboolean freed; time_t mtime; @@ -189,6 +188,6 @@ gchar *get_key_file_string(const gchar *section, const gchar *what); gchar *expand_homedir(gchar *str); void free_client(struct client_s *client); gpg_error_t send_status(assuan_context_t ctx, status_msg_t which); -gchar *parse_keyfile(const gchar *filename, gboolean cmdline, gpg_error_t *); +gchar *parse_keyfile(const gchar *filename, gboolean cmdline); #endif diff --git a/src/pwmd.c b/src/pwmd.c index 415ff6ed..d3dfc275 100644 --- a/src/pwmd.c +++ b/src/pwmd.c @@ -569,8 +569,6 @@ static void *client_thread(void *data) goto fail; } - /* A default setting. */ - cl->keyfile = 1; thd->cl = cl; cl->thd = thd; pth_cleanup_push(cleanup_cb, thd); @@ -1089,7 +1087,7 @@ done: #endif } -static gboolean _getline(const gchar *file, gchar **result, gpg_error_t *rc) +static gboolean _getline(const gchar *file, gchar **result) { FILE *fp; gchar buf[LINE_MAX] = {0}, *p; @@ -1097,7 +1095,6 @@ static gboolean _getline(const gchar *file, gchar **result, gpg_error_t *rc) gint len; if ((fp = fopen(file, "r")) == NULL) { - *rc = gpg_error_from_errno(errno); warn("%s", file); return FALSE; } @@ -1110,13 +1107,6 @@ static gboolean _getline(const gchar *file, gchar **result, gpg_error_t *rc) buf[--len] = 0; str = gcry_malloc(len + 1); - - if (!str) { - memset(&buf, 0, sizeof(buf)); - *rc = gpg_error_from_errno(ENOMEM); - return FALSE; - } - memcpy(str, buf, len ? len : 1); str[len] = 0; memset(&buf, 0, sizeof(buf)); @@ -1124,66 +1114,45 @@ static gboolean _getline(const gchar *file, gchar **result, gpg_error_t *rc) return TRUE; } -gchar *parse_keyfile(const gchar *filename, gboolean cmdline, gpg_error_t *rc) +gchar *parse_keyfile(const gchar *filename, gboolean cmdline) { - GError *rv = NULL; + GError *rc = NULL; gchar *t, *file = NULL, *str; - *rc = 0; - if (cmdline == FALSE) { - if (g_key_file_has_key(keyfileh, filename, "key_file", &rv) == TRUE) { - file = g_key_file_get_string(keyfileh, filename, "key_file", &rv); + if (g_key_file_has_key(keyfileh, filename, "key_file", &rc) == TRUE) { + file = g_key_file_get_string(keyfileh, filename, "key_file", &rc); if (!file) { - if (rv) { - warnx("%s", rv->message); - g_clear_error(&rv); + if (rc) { + warnx("%s", rc->message); + g_clear_error(&rc); } - *rc = gpg_error_from_errno(ENOMEM); return NULL; } t = expand_homedir(file); g_free(file); - - if (!t) { - *rc = gpg_error_from_errno(ENOMEM); - g_free(file); - return NULL; - } - file = t; } } else { t = g_strdup(filename); - - if (!t) { - *rc = gpg_error_from_errno(ENOMEM); - return NULL; - } - file = expand_homedir(t); g_free(t); - - if (!file) { - *rc = gpg_error_from_errno(ENOMEM); - return NULL; - } } - if (rv) { - *rc = GPG_ERR_UNUSABLE_SECKEY; - g_clear_error(&rv); + if (rc) { + warnx("%s", rc->message); + g_clear_error(&rc); return NULL; } if (!file) return NULL; - if (_getline(file, &str, rc) == FALSE) { + if (_getline(file, &str) == FALSE) { g_free(file); return NULL; } @@ -1211,7 +1180,7 @@ static gboolean xml_import(const gchar *filename, const gchar *outfile, } if (iter && keyfile) { - gchar *tmp = parse_keyfile(keyfile, TRUE, &rc); + gchar *tmp = parse_keyfile(keyfile, TRUE); if (!tmp) return FALSE; @@ -1367,16 +1336,15 @@ static gboolean parse_keyfile_key() groups = g_key_file_get_groups(keyfileh, &n); for (p = groups; *p; p++) { - GError *rv = NULL; - gpg_error_t rc; + GError *rc = NULL; - if (g_key_file_has_key(keyfileh, *p, "key", &rv) == TRUE) { - str = g_key_file_get_string(keyfileh, *p, "key", &rv); + if (g_key_file_has_key(keyfileh, *p, "key", &rc) == TRUE) { + str = g_key_file_get_string(keyfileh, *p, "key", &rc); if (!str) { if (rc) { - warnx("%s", rv->message); - g_clear_error(&rv); + warnx("%s", rc->message); + g_clear_error(&rc); } continue; @@ -1387,13 +1355,13 @@ static gboolean parse_keyfile_key() continue; } - if (rv) { - warnx("%s", rv->message); - g_clear_error(&rv); + if (rc) { + warnx("%s", rc->message); + g_clear_error(&rc); continue; } - str = parse_keyfile(*p, FALSE, &rc); + str = parse_keyfile(*p, FALSE); if (!str) continue; @@ -1886,10 +1854,12 @@ static gpg_error_t convert_file(const gchar *filename, const gchar *keyfile, */ if (fh->fh1.iter >= 0) { if (keyfile) { - gchar *tmp = parse_keyfile(keyfile, TRUE, &rc); + gchar *tmp = parse_keyfile(keyfile, TRUE); - if (!tmp) + if (!tmp) { + rc = GPG_ERR_UNKNOWN_ERRNO; goto done; + } gcry_md_hash_buffer(GCRY_MD_SHA256, shakey, tmp, strlen(tmp) ? strlen(tmp) : 1); -- 2.11.4.GIT