implement new -n option to check and print print configuration
diff --git usr.sbin/acme-client/acme-client.1 usr.sbin/acme-client/acme-client.1
index db17814..40086cc 100644
--- usr.sbin/acme-client/acme-client.1
+++ usr.sbin/acme-client/acme-client.1
@@ -22,7 +22,7 @@
.Nd ACME client
.Sh SYNOPSIS
.Nm acme-client
-.Op Fl bFNnrv
+.Op Fl bFADrvn
.Op Fl f Ar configfile
.Ar domain
.Sh DESCRIPTION
@@ -61,6 +61,8 @@ Revoke the X509 certificate found in the certificates.
.It Fl v
Verbose operation.
Specify twice to also trace communication and data transfers.
+.It Fl n
+No operation, check and print configuration.
.It Ar domain
The domain name.
.El
diff --git usr.sbin/acme-client/main.c usr.sbin/acme-client/main.c
index d129dee..471f33e 100644
--- usr.sbin/acme-client/main.c
+++ usr.sbin/acme-client/main.c
@@ -54,7 +54,7 @@ main(int argc, char *argv[])
struct domain_c *domain = NULL;
struct altname_c *ac;
- while (-1 != (c = getopt(argc, argv, "bFADrvf:")))
+ while (-1 != (c = getopt(argc, argv, "bFADrvnf:")))
switch (c) {
case 'b':
backup = 1;
@@ -79,6 +79,9 @@ main(int argc, char *argv[])
verbose = verbose ? 2 : 1;
popts |= ACME_OPT_VERBOSE;
break;
+ case 'n':
+ popts |= ACME_OPT_CHECK;
+ break;
default:
goto usage;
}
@@ -182,6 +185,9 @@ main(int argc, char *argv[])
if (ne > 0)
exit(EXIT_FAILURE);
+ if (popts & ACME_OPT_CHECK)
+ exit(EXIT_SUCCESS);
+
/* Set the zeroth altname as our domain. */
altsz = domain->altname_count + 1;
alts = calloc(altsz, sizeof(char *));
@@ -399,6 +405,6 @@ main(int argc, char *argv[])
(2 == c ? EXIT_SUCCESS : 2));
usage:
fprintf(stderr,
- "usage: acme-client [-bFADrv] [-f file] domain\n");
+ "usage: acme-client [-bFADrvn] [-f file] domain\n");
return (EXIT_FAILURE);
}
diff --git usr.sbin/acme-client/parse.h usr.sbin/acme-client/parse.h
index e4435b2..055a432 100644
--- usr.sbin/acme-client/parse.h
+++ usr.sbin/acme-client/parse.h
@@ -59,6 +59,7 @@ struct keyfile {
#define ACME_OPT_VERBOSE 0x00000001
#define ACME_OPT_NEWACCT 0x00000002
#define ACME_OPT_NEWDKEY 0x00000004
+#define ACME_OPT_CHECK 0x00000008
struct acme_conf {
int opts;
diff --git usr.sbin/acme-client/parse.y usr.sbin/acme-client/parse.y
index bdff45c..f242320 100644
--- usr.sbin/acme-client/parse.y
+++ usr.sbin/acme-client/parse.y
@@ -62,7 +62,8 @@ int findeol(void);
struct authority_c *conf_new_authority(struct acme_conf *, char *);
struct domain_c *conf_new_domain(struct acme_conf *, char *);
struct keyfile *conf_new_keyfile(struct acme_conf *, char *);
-void clear_config(struct acme_conf *xconf);
+void clear_config(struct acme_conf *);
+void print_config(struct acme_conf *);
int conf_check_file(char *, int);
TAILQ_HEAD(symhead, sym) symhead = TAILQ_HEAD_INITIALIZER(symhead);
@@ -717,6 +718,9 @@ parse_config(const char *filename, int opts)
}
}
+ if (opts & ACME_OPT_CHECK)
+ print_config(conf);
+
if (errors) {
clear_config(conf);
return (NULL);
@@ -912,6 +916,49 @@ clear_config(struct acme_conf *xconf)
free(xconf);
}
+void
+print_config(struct acme_conf *xconf)
+{
+ struct authority_c *a;
+ struct domain_c *d;
+ struct altname_c *ac;
+ int f;
+
+ LIST_FOREACH(a, &xconf->authority_list, entry) {
+ printf("authority %s {\n", a->name);
+ if (a->agreement != NULL)
+ printf("\tagreement url \"%s\"\n", a->agreement);
+ if (a->api != NULL)
+ printf("\tapi url \"%s\"\n", a->api);
+ if (a->account != NULL)
+ printf("\taccount key \"%s\"\n", a->account);
+ printf("}\n\n");
+ }
+ LIST_FOREACH(d, &xconf->domain_list, entry) {
+ f = 0;
+ printf("domain %s {\n", d->domain);
+ LIST_FOREACH(ac, &d->altname_list, entry) {
+ if (!f)
+ printf("\talternative names { ");
+ if (ac->domain != NULL) {
+ printf("%s%s", f ? ", " : " ", ac->domain);
+ f = 1;
+ }
+ }
+ if (f)
+ printf("}\n");
+ if (d->key != NULL)
+ printf("\tdomain key \"%s\"\n", d->key);
+ if (d->cert != NULL)
+ printf("\tdomain certificate \"%s\"\n", d->cert);
+ if (d->auth != NULL)
+ printf("\tsign with \"%s\"\n", d->auth);
+ if (d->challengedir != NULL)
+ printf("\tchallengedir \"%s\"\n", d->challengedir);
+ printf("}\n\n");
+ }
+}
+
/*
* This isn't RFC1035 compliant, but does the bare minimum in making
* sure that we don't get bogus domain names on the command line, which