From 4c7621a867ef5a1a554cac21fad00e79444997c4 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Thu, 26 Aug 2010 18:14:04 -0400 Subject: [PATCH] Removed client option LOCK_ON_OPEN and added option --lock to the OPEN command. --- doc/COMMANDS | 16 ++++++++-------- src/commands.c | 38 +++++++++++++++++++++----------------- src/common.h | 2 +- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/doc/COMMANDS b/doc/COMMANDS index a9bd6f0c..d530bad2 100644 --- a/doc/COMMANDS +++ b/doc/COMMANDS @@ -8,7 +8,7 @@ about the protocol. PROTOCOL COMMANDS ----------------- -OPEN [] +OPEN [--lock] [] Opens using . If the filename is not found on the file-system, then a new document will be created. If the file is found, it is looked for in the file cache for an existing key. When found and no key @@ -18,6 +18,9 @@ OPEN [] using an empty or NULL key and you want to avoid the pinentry dialog, set ENABLE_PINENTRY to 0 (see OPTIONS below). + When the --lock option is passed then the file mutex will be locked as if + the LOCK command had been sent after the file has been opened. + SAVE [] Writes the XML document to disk. The file written to is the file that was @@ -56,16 +59,16 @@ CACHETIMEOUT LIST [--norecurse] [--verbose] [[!]element[[!]element[...]]] If no element path is given then a newline separated list of root elements is returned with the data response. If given, then all reachable elements - for the specified element path is returned unless the "norecurse" option is - specified. If specified, only the root elements of the element path is + for the specified element path is returned unless the --norecurse option + is specified. If specified, only the root elements of the element path is returned. Each element in the path is prefixed with the literal '!' character when the element contains no "target" attribute (See THE TARGET ATTRIBUTE below). - When the "verbose" option is passed then each element path returned in the + When the --verbose option is passed then each element path returned in the list will have a single space character followed by either a 0 or 1 appended to it. When 0, the element path has no children, otherwise it - does have children. When used with the "norecurse" option this may be + does have children. When used with the --norecurse option this may be useful to limit the amount of data transferred to the client. @@ -268,9 +271,6 @@ options: with the specified textual representation. Useful for debugging log messages. CIPHER The cipher to use for the next SAVE. - LOCK_ON_OPEN 0|1 If enabled then the file mutex will be locked - after a successful OPEN as if the LOCK - command had been sent. RC_ON_LOCKED 0|1 If enabled then return an error code instead of a status message when the file mutex is locked. diff --git a/src/commands.c b/src/commands.c index 4e07ab3d..fd5cf79e 100644 --- a/src/commands.c +++ b/src/commands.c @@ -186,8 +186,8 @@ void cleanup_client(struct client_s *client) { assuan_context_t ctx = client->ctx; struct client_thread_s *thd = client->thd; - gboolean lock_on_open = client->lockonopen; gboolean rc_on_locked = client->rc_on_locked; + gboolean lock_on_open = client->lock_on_open; #ifdef WITH_PINENTRY struct pinentry_s *pin = client->pinentry; #endif @@ -214,7 +214,7 @@ void cleanup_client(struct client_s *client) client->pinentry = pin; #endif client->rc_on_locked = rc_on_locked; - client->lockonopen = lock_on_open; + client->lock_on_open = lock_on_open; } static void gz_cleanup(void *arg) @@ -488,7 +488,7 @@ done: cleanup_crypto(&client->crypto); - if (!rc && client->lockonopen) + if (!rc && client->lock_on_open) return do_lock_command(client); return send_error(ctx, rc); @@ -502,6 +502,14 @@ static void req_cleanup(void *arg) g_strfreev((gchar **)arg); } +static gpg_error_t parse_open_opt_lock(gpointer data, gpointer value) +{ + gboolean *b = (gboolean *)data; + + *b = TRUE; + return 0; +} + static gint open_command(assuan_context_t ctx, gchar *line) { gboolean cached = FALSE; @@ -510,6 +518,16 @@ static gint open_command(assuan_context_t ctx, gchar *line) gchar **req; gchar *filename = NULL; gsize hashlen = gcry_md_get_algo_dlen(GCRY_MD_SHA256); + struct argv_s *args[] = { + &(struct argv_s) { "lock", OPT_NOARG, parse_open_opt_lock }, + NULL + }; + + client->lock_on_open = FALSE; + rc = parse_options(&line, args, &client->lock_on_open); + + if (rc) + return send_error(ctx, rc); if ((req = split_input_line(line, " ", 2)) != NULL) filename = req[0]; @@ -3186,20 +3204,6 @@ static gint set_unset_common(assuan_context_t ctx, const gchar *name, client->rc_on_locked = l ? TRUE : FALSE; goto done; } - else if (g_ascii_strcasecmp(name, (gchar *)"lock_on_open") == 0) { - glong l = 0; - - if (value) { - l = strtol(value, NULL, 10); - - if (l < 0 || l > 1) - return gpg_err_make(PWMD_ERR_SOURCE, GPG_ERR_INV_VALUE); - } - - log_write1("lock_on_open=%li", l); - client->lockonopen = l ? TRUE : FALSE; - goto done; - } else if (g_ascii_strcasecmp(name, (gchar *)"cipher") == 0) { guint64 flags; const gchar *p = value; diff --git a/src/common.h b/src/common.h index 3335244b..94a36579 100644 --- a/src/common.h +++ b/src/common.h @@ -218,7 +218,7 @@ struct client_s { struct crypto_s *crypto; guchar opts; gpg_error_t last_rc; - gboolean lockonopen; + gboolean lock_on_open; gboolean rc_on_locked; }; -- 2.11.4.GIT