summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2018-03-23 08:14:58 +0100
committerWerner Koch <wk@gnupg.org>2018-03-23 08:37:14 +0100
commit05c55ee260edc07cd19da56dfd00347bfe3f529c (patch)
tree058fda975959ac7bd01f1707d0be6c0ce1af6af0 /common
parentbuild: Fix the manual source field. (diff)
downloadgnupg2-05c55ee260edc07cd19da56dfd00347bfe3f529c.tar.xz
gnupg2-05c55ee260edc07cd19da56dfd00347bfe3f529c.zip
agent: New OPTION pretend-request-origin
* common/shareddefs.h (request_origin_t): New. * common/agent-opt.c (parse_request_origin): New. (str_request_origin): New. * agent/command.c (option_handler): Implement new option. -- This allows to pretend that a request originated from the extra or browser socket. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'common')
-rw-r--r--common/agent-opt.c35
-rw-r--r--common/shareddefs.h13
2 files changed, 48 insertions, 0 deletions
diff --git a/common/agent-opt.c b/common/agent-opt.c
index b32448242..6d9f9e77e 100644
--- a/common/agent-opt.c
+++ b/common/agent-opt.c
@@ -69,3 +69,38 @@ str_pinentry_mode (pinentry_mode_t mode)
}
return "?";
}
+
+
+/* Parse VALUE and return an integer representing a request_origin_t.
+ * (-1) is returned for an invalid VALUE. */
+int
+parse_request_origin (const char *value)
+{
+ int result;
+
+ if (!strcmp (value, "none") || !strcmp (value, "local"))
+ result = REQUEST_ORIGIN_LOCAL;
+ else if (!strcmp (value, "remote"))
+ result = REQUEST_ORIGIN_REMOTE;
+ else if (!strcmp (value, "browser"))
+ result = REQUEST_ORIGIN_BROWSER;
+ else
+ result = -1;
+
+ return result;
+}
+
+
+/* Return the string representation for the request origin. Returns
+ * "?" for an invalid mode. */
+const char *
+str_request_origin (request_origin_t mode)
+{
+ switch (mode)
+ {
+ case REQUEST_ORIGIN_LOCAL: return "local";
+ case REQUEST_ORIGIN_REMOTE: return "remote";
+ case REQUEST_ORIGIN_BROWSER: return "browser";
+ }
+ return "?";
+}
diff --git a/common/shareddefs.h b/common/shareddefs.h
index 1594f6650..4b1442133 100644
--- a/common/shareddefs.h
+++ b/common/shareddefs.h
@@ -39,10 +39,23 @@ typedef enum
pinentry_mode_t;
+/* Values for the request origin. */
+typedef enum
+ {
+ REQUEST_ORIGIN_LOCAL = 0,
+ REQUEST_ORIGIN_REMOTE,
+ REQUEST_ORIGIN_BROWSER
+ }
+request_origin_t;
+
+
/*-- agent-opt.c --*/
int parse_pinentry_mode (const char *value);
const char *str_pinentry_mode (pinentry_mode_t mode);
+int parse_request_origin (const char *value);
+const char *str_request_origin (request_origin_t mode);
+
#endif /*GNUPG_COMMON_SHAREDDEFS_H*/