Blame SOURCES/certmonger-dogtag-approval-options.patch

ed3c5e
Backported from master.
ed3c5e
ed3c5e
From de03df73802956143fd1fa743706b803938a610f Mon Sep 17 00:00:00 2001
ed3c5e
From: Jan Cholasta <jcholast@redhat.com>
ed3c5e
Date: Tue, 18 Nov 2014 13:25:08 +0000
ed3c5e
Subject: [PATCH] Allow overriding parameter values in Dogtag request approval
ed3c5e
ed3c5e
---
ed3c5e
 src/certmonger-dogtag-ipa-renew-agent-submit.8.in |  8 +++
ed3c5e
 src/dogtag.c                                      | 61 ++++++++++++++++++++++-
ed3c5e
 2 files changed, 68 insertions(+), 1 deletion(-)
ed3c5e
ed3c5e
diff --git a/src/certmonger-dogtag-ipa-renew-agent-submit.8.in b/src/certmonger-dogtag-ipa-renew-agent-submit.8.in
ed3c5e
index 45129d4818aad0d91960a1bfe35a79e4e2406f02..d6d0c4c122014ac77e04ab8c3fc4a2742dfb8bdb 100644
ed3c5e
--- a/src/certmonger-dogtag-ipa-renew-agent-submit.8.in
ed3c5e
+++ b/src/certmonger-dogtag-ipa-renew-agent-submit.8.in
ed3c5e
@@ -17,6 +17,7 @@ dogtag-ipa-renew-agent-submit -E EE-URL -A AGENT-URL
ed3c5e
 [-D serial (decimal)]
ed3c5e
 [-S state]
ed3c5e
 [-T profile]
ed3c5e
+[-O param=value]
ed3c5e
 [-v]
ed3c5e
 [csrfile]
ed3c5e
 
ed3c5e
@@ -125,6 +126,13 @@ The name of the type of certificate which the client should request from the CA
ed3c5e
 if it is not renewing a certificate (per the \fB-s\fR option above).  The
ed3c5e
 default value is \fBcaServerCert\fP.
ed3c5e
 .TP
ed3c5e
+\fB-O\fR param=value
ed3c5e
+An additional parameter to pass to the server when approving the signing
ed3c5e
+request using the agent's credentials.  By default, any server-supplied default
ed3c5e
+settings are applied.  This option can be used either to override a
ed3c5e
+server-supplied default setting, or to supply one which would otherwise have
ed3c5e
+not been used.
ed3c5e
+.TP
ed3c5e
 \fB-v\fR
ed3c5e
 Increases the logging level.  Use twice for more logging.  This option is mainly
ed3c5e
 useful for troubleshooting.
ed3c5e
diff --git a/src/dogtag.c b/src/dogtag.c
ed3c5e
index 700fe7f516a54f0581d94068e9066de9e4621f5d..6bd284327ffc1ab29d32deb8529fc5ef69314295 100644
ed3c5e
--- a/src/dogtag.c
ed3c5e
+++ b/src/dogtag.c
ed3c5e
@@ -76,6 +76,7 @@ help(const char *cmd)
ed3c5e
 		"\t[-D serial (decimal)]\n"
ed3c5e
 		"\t[-S state]\n"
ed3c5e
 		"\t[-T profile]\n"
ed3c5e
+		"\t[-O param=value]\n"
ed3c5e
 		"\t[-v]\n"
ed3c5e
 		"\t[-N]\n"
ed3c5e
 		"\t[-V dogtag_version]\n"
ed3c5e
@@ -140,6 +141,11 @@ main(int argc, char **argv)
ed3c5e
 	const char *sslcert = NULL, *sslkey = NULL;
ed3c5e
 	const char *sslpin = NULL, *sslpinfile = NULL;
ed3c5e
 	const char *host = NULL, *csr = NULL, *serial = NULL, *template = NULL;
ed3c5e
+	struct {
ed3c5e
+		char *name;
ed3c5e
+		char *value;
ed3c5e
+	} *options = NULL;
ed3c5e
+	size_t num_options = 0, j;
ed3c5e
 	const char *dogtag_version = NULL;
ed3c5e
 	char *ipaconfig = NULL, *savedstate = NULL;
ed3c5e
 	char *p, *q, *params = NULL, *params2 = NULL;
ed3c5e
@@ -178,7 +184,7 @@ main(int argc, char **argv)
ed3c5e
 
ed3c5e
 	savedstate = getenv(CM_SUBMIT_COOKIE_ENV);
ed3c5e
 
ed3c5e
-	while ((c = getopt(argc, argv, "E:A:d:n:i:C:c:k:p:P:s:D:S:T:vV:NR")) != -1) {
ed3c5e
+	while ((c = getopt(argc, argv, "E:A:d:n:i:C:c:k:p:P:s:D:S:T:O:vV:NR")) != -1) {
ed3c5e
 		switch (c) {
ed3c5e
 		case 'E':
ed3c5e
 			eeurl = optarg;
ed3c5e
@@ -220,6 +226,26 @@ main(int argc, char **argv)
ed3c5e
 		case 'T':
ed3c5e
 			template = optarg;
ed3c5e
 			break;
ed3c5e
+		case 'O':
ed3c5e
+			if (strchr(optarg, '=') == NULL) {
ed3c5e
+				printf(_("Profile params (-O) must be in the form of param=value.\n"));
ed3c5e
+				help(argv[0]);
ed3c5e
+				return CM_SUBMIT_STATUS_UNCONFIGURED;
ed3c5e
+			}
ed3c5e
+			options = realloc(options,
ed3c5e
+					  ++num_options * sizeof(*options));
ed3c5e
+			if (options == NULL) {
ed3c5e
+				printf(_("Out of memory.\n"));
ed3c5e
+				return CM_SUBMIT_STATUS_UNCONFIGURED;
ed3c5e
+			}
ed3c5e
+			options[num_options - 1].name = strdup(optarg);
ed3c5e
+			if (options[num_options - 1].name == NULL) {
ed3c5e
+				printf(_("Out of memory.\n"));
ed3c5e
+				return CM_SUBMIT_STATUS_UNCONFIGURED;
ed3c5e
+			}
ed3c5e
+			*strchr(options[num_options - 1].name, '=') = '\0';
ed3c5e
+			options[num_options - 1].value = strchr(optarg, '=') + 1;
ed3c5e
+			break;
ed3c5e
 		case 'v':
ed3c5e
 			verbose++;
ed3c5e
 			break;
ed3c5e
@@ -374,6 +400,18 @@ main(int argc, char **argv)
ed3c5e
 		printf(_("No profile/template (-T) given, and no default known.\n"));
ed3c5e
 		missing_args = TRUE;
ed3c5e
 	}
ed3c5e
+	if (options != NULL) {
ed3c5e
+		if (agenturl == NULL) {
ed3c5e
+			printf(_("No agent URL (-A) given, and no default "
ed3c5e
+				 "known.\n"));
ed3c5e
+			missing_args = TRUE;
ed3c5e
+		}
ed3c5e
+		if (!can_agent) {
ed3c5e
+			printf(_("No agent credentials specified, and no "
ed3c5e
+				 "default known.\n"));
ed3c5e
+			missing_args = TRUE;
ed3c5e
+		}
ed3c5e
+	}
ed3c5e
 	if (missing_args) {
ed3c5e
 		help(argv[0]);
ed3c5e
 		return CM_SUBMIT_STATUS_UNCONFIGURED;
ed3c5e
@@ -544,12 +582,33 @@ main(int argc, char **argv)
ed3c5e
 			for (i = 0;
ed3c5e
 			     (defaults != NULL) && (defaults[i] != NULL);
ed3c5e
 			     i++) {
ed3c5e
+				/* Check if this default is one of the
ed3c5e
+				 * paramters we've been explicitly provided. */
ed3c5e
+				for (j = 0; j < num_options; j++) {
ed3c5e
+					if (strcmp(defaults[i]->name,
ed3c5e
+						   options[j].name) == 0) {
ed3c5e
+						break;
ed3c5e
+					}
ed3c5e
+				}
ed3c5e
+				/* If we have a non-default value for it, skip
ed3c5e
+				 * this default. */
ed3c5e
+				if (j < num_options) {
ed3c5e
+					continue;
ed3c5e
+				}
ed3c5e
 				p = cm_submit_u_url_encode(defaults[i]->name);
ed3c5e
 				q = cm_submit_u_url_encode(defaults[i]->value);
ed3c5e
 				params2 = talloc_asprintf(ctx,
ed3c5e
 							  "%s&%s=%s",
ed3c5e
 							  params2, p, q);
ed3c5e
 			};
ed3c5e
+			/* Add parameters specified on command line */
ed3c5e
+			for (j = 0; j < num_options; j++) {
ed3c5e
+				p = cm_submit_u_url_encode(options[j].name);
ed3c5e
+				q = cm_submit_u_url_encode(options[j].value);
ed3c5e
+				params2 = talloc_asprintf(ctx,
ed3c5e
+							  "%s&%s=%s",
ed3c5e
+							  params2, p, q);
ed3c5e
+			}
ed3c5e
 			break;
ed3c5e
 		case op_none:
ed3c5e
 		case op_submit:
ed3c5e
-- 
ed3c5e
2.1.0
ed3c5e