diff options
author | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-26 19:57:57 +0100 |
---|---|---|
committer | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-26 19:57:57 +0100 |
commit | 3973f81cb3a57c72263f26bbdb0a5957479211ae (patch) | |
tree | d5efa5cdf0d86a2cd548ef4e693afe8d76b8717f | |
parent | 3c35318429e33c98c2d7fac8943dfc6ff40359c7 (diff) | |
download | eurephia-3973f81cb3a57c72263f26bbdb0a5957479211ae.tar.gz eurephia-3973f81cb3a57c72263f26bbdb0a5957479211ae.tar.xz eurephia-3973f81cb3a57c72263f26bbdb0a5957479211ae.zip |
certs command: Added list certificates
-rw-r--r-- | eurephiadm/commands/certificates.c | 79 |
1 files changed, 78 insertions, 1 deletions
diff --git a/eurephiadm/commands/certificates.c b/eurephiadm/commands/certificates.c index 7656f45..dec9a65 100644 --- a/eurephiadm/commands/certificates.c +++ b/eurephiadm/commands/certificates.c @@ -88,6 +88,13 @@ void display_certs_help(int page) { "a list over certificates which matches your search criteria and you will need\n" "to approve the deletion of the matching certificate(s).\n\n"); break; + + case 'l': + printf("The list mode will list all registered certificates. It accepts one parameter:\n\n" + " -S | --sort <sort key> Decide the sort order of the certificate list\n" + "\n" + "Available sort keys are: certid, depth, digest, cname, org, email and registered.\n\n"); + break; default: printf("Available modes for the certficate command are:\n\n" " -A | --add Register a new certificate\n" @@ -518,6 +525,76 @@ int delete_cert(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, in } +int list_certs(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) { + xmlDoc *srch_xml = NULL, *certlist = NULL; + xmlNode *cert_n = NULL, *srch_n = NULL; + xmlXPathContext *cert_XP = NULL; + int i, rc = 0; + char *sortkeys = NULL; + + e_options listargs[] = { + {"--sort", "-S", 1}, + {"--help", "-h", 0}, + {NULL, NULL, 0} + }; + + // Parse arguments + for( i = 1; i < argc; i++ ) { + switch( eurephia_getopt(&i, argc, argv, listargs) ) { + case 'S': + sortkeys = optargs[0]; + i++; + break; + + case 'h': + display_certs_help('l'); + return 0; + + default: + return 1; + } + } + + if( sortkeys == NULL ) { + sortkeys = "certid"; + } + + // Create an empty field mapping to get all certificates + eurephiaXML_CreateDoc(ctx, 1, "certificate_info", &srch_xml, &srch_n); + srch_n = xmlNewChild(srch_n, NULL, (xmlChar *) "fieldMapping", NULL); + xmlNewProp(srch_n, (xmlChar *) "table", (xmlChar *) "certificates"); + + // Look up the certificate info and display it + certlist = eDBadminGetCertificateInfo(ctx, srch_xml, sortkeys); + if( certlist == NULL ) { + xmlFreeDoc(srch_xml); + fprintf(stderr, "%s: Failed to query for certificates\n", MODULE); + return 1; + } + + cert_n = eurephiaXML_getRoot(ctx, certlist, "certificates", 1); + if( atoi_nullsafe(xmlGetAttrValue(cert_n->properties, "certificates")) == 0 ) { + printf("%s: No certificates found\n", MODULE); + rc = 0; + goto exit; + } + + cert_XP = xmlXPathNewContext(certlist); + if( cert_XP == NULL ) { + fprintf(stderr,"Error: unable to create new XPath context\n"); + rc = 1; + goto exit; + } + + xmlPrint_certs(cert_XP, "/eurephia/certificates/certificate", SHOWCERTS_DIGEST); + xmlXPathFreeContext(cert_XP); + rc = 0; + exit: + xmlFreeDoc(certlist); + xmlFreeDoc(srch_xml); + return rc; +} + int cmd_Certificates(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) { char **mode_argv; int i, mode_argc = 0, rc = 0; @@ -537,7 +614,7 @@ int cmd_Certificates(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cf for( i = 1; i < argc; i++ ) { switch( eurephia_getopt(&i, argc, argv, modeargs) ) { case 'l': - // mode_fnc = list_certs; + mode_fnc = list_certs; break; case 's': |