summaryrefslogtreecommitdiffstats
path: root/eurephiadm
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2009-03-31 00:30:45 +0200
committerDavid Sommerseth <dazo@users.sourceforge.net>2009-03-31 00:30:45 +0200
commit66741a5d99b49fd6a2d62a232a7d9b43074b55fa (patch)
tree6011bc06f4c3f4e219b60279732c61981e70492a /eurephiadm
parentda80d77425893015518eb2339f87b65d199c1eb8 (diff)
downloadeurephia-66741a5d99b49fd6a2d62a232a7d9b43074b55fa.tar.gz
eurephia-66741a5d99b49fd6a2d62a232a7d9b43074b55fa.tar.xz
eurephia-66741a5d99b49fd6a2d62a232a7d9b43074b55fa.zip
Rewrote places using xmlPrint_certs(...) to use the XSLT
Added XSLT template for displaying certificate info.
Diffstat (limited to 'eurephiadm')
-rw-r--r--eurephiadm/commands/certificates.c109
-rw-r--r--eurephiadm/commands/users.c4
2 files changed, 11 insertions, 102 deletions
diff --git a/eurephiadm/commands/certificates.c b/eurephiadm/commands/certificates.c
index ce1b710..57dd4fc 100644
--- a/eurephiadm/commands/certificates.c
+++ b/eurephiadm/commands/certificates.c
@@ -50,6 +50,8 @@
#include "../get_console_input.h"
#include "../field_print.h"
#include "../parse_certificate_files.h"
+#include "../xsltparser.h"
+
void display_certs_help(int page) {
switch( page ) {
@@ -122,88 +124,6 @@ int help_Certificates2(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *
}
-#define SHOWCERTS_FIREWALL 0x001
-#define SHOWCERTS_DIGEST 0x002
-
-void xmlPrint_certs(xmlXPathContext *certsXP, const char *xpath, int show_flags) {
- xmlXPathObject *certsObj = NULL;
- xmlNode *certnode = NULL;
- int i = 0;
-
- // Find the certificates in the given XPath query
- certsObj = xmlXPathEvalExpression((xmlChar *)xpath, certsXP);
- if( certsObj == NULL ) {
- fprintf(stderr,"Error: unable to evaluate xpath expression \"%s\"\n", xpath);
- return;
- }
-
- // If no certs were found, inform and exit
- if( certsObj->nodesetval->nodeNr == 0 ) {
- field_print_str("Associated certificates", "None");
- printf("\n");
- xmlXPathFreeObject(certsObj);
- return;
- }
-
- // Parse all certificates found
- printf("\n");
- printf(" %3s (D) %-35.35s %33.33s\n %-49.49s %19.19s\n",
- "ID", "Common name", "Organisation", "e-mail", "Registered");
- if( show_flags & SHOWCERTS_DIGEST ) {
- printf(" %-60.60s\n", "Certificate SHA1 digest");
- }
-#ifdef FIREWALL
- if( show_flags & SHOWCERTS_FIREWALL ) {
- printf(" %-44.44s %24.24s\n", "Firewall access profile", "FW Destination");
- }
-#endif
- printf(" --------------------------------------------------------------------"
- "----------\n");
-
- for( i = 0; i < certsObj->nodesetval->nodeNr; i++ ) {
- xmlNode *acpr = NULL;
-
- certnode = certsObj->nodesetval->nodeTab[i];
- if( certnode->type != XML_ELEMENT_NODE) {
- // Skip nodes which is not element nodes
- continue;
- }
- if( xmlStrcmp(certnode->name, (xmlChar *)"certificate") != 0 ) {
- // Skip nodes which is not a certificate "collection"
- continue;
- }
-
- acpr = xmlFindNode(certnode, "access_profile");
-
- printf(" %3s (%1s) %-35.35s %33.33s\n %-49.49s %19.19s\n",
- xmlGetAttrValue(certnode->properties, "certid"),
- xmlGetAttrValue(certnode->properties, "depth"),
- xmlGetNodeContent(certnode, "common_name"),
- xmlGetNodeContent(certnode, "organisation"),
- xmlGetNodeContent(certnode, "email"),
- xmlGetAttrValue(certnode->properties, "registered"));
-
- if( show_flags & SHOWCERTS_DIGEST ) {
- printf(" %-60.60s\n", xmlGetNodeContent(certnode, "digest"));
- }
-#ifdef FIREWALL
- if( (show_flags & SHOWCERTS_FIREWALL) && (acpr != NULL) ) {
- printf(" %-44.44s %24.24s\n",
- defaultValue(xmlExtractContent(acpr), "(not set)"),
- defaultValue(xmlGetAttrValue(acpr->properties, "fwdestination"), "-"));
- }
-#endif
- if( (i+1) < certsObj->nodesetval->nodeNr ) {
- printf("\n");
- }
- }
- printf(" --------------------------------------------------------------------"
- "----------\n");
-
- xmlXPathFreeObject(certsObj);
-}
-
-
int register_certificate(eurephiaCTX *ctx, int depth, const char *digest,
const char *cname, const char *org, const char *email)
{
@@ -393,8 +313,8 @@ int add_cert(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int a
int delete_cert(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) {
xmlDoc *cert_xml = NULL, *delete_xml = NULL, *certlist = NULL;
xmlNode *cert_n = NULL, *search_n = NULL, *delete_n = NULL;
- xmlXPathContext *cert_XP = NULL;
char *digest = NULL, *cname = NULL, *org = NULL, *email = NULL, *certid = NULL, confirm[5];
+ const char *xsltparams[] = {"view_digest", "'1'", "view_fw", "'0'", NULL};
int i, rc = 0, count = 0;
e_options addcertargs[] = {
{"--certid", "-i", 1},
@@ -473,19 +393,15 @@ int delete_cert(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, in
if( certlist == NULL ) {
return 0;
}
+
delete_n = eurephiaXML_getRoot(ctx, certlist, "certificates", 1);
if( atoi_nullsafe(xmlGetAttrValue(delete_n->properties, "certificates")) == 0 ) {
printf("%s: No certificates found\n", MODULE);
goto exit;
}
- cert_XP = xmlXPathNewContext(certlist);
- if( cert_XP == NULL ) {
- fprintf(stderr,"Error: unable to create new XPath context\n");
- return 1;
- }
- xmlPrint_certs(cert_XP, "/eurephia/certificates/certificate", SHOWCERTS_DIGEST);
- xmlXPathFreeContext(cert_XP);
+ // Show certificate(s)
+ xslt_print_xmldoc(stdout, cfg, certlist, "certificates.xsl", xsltparams);
// Get delete confirmation
memset(&confirm, 0, 5);
@@ -522,7 +438,7 @@ 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;
+ const char *xsltparams[] = {"view_digest", "'1'", "view_fw", "'0'", NULL};
int i, rc = 0;
char *sortkeys = NULL;
@@ -573,15 +489,8 @@ int list_certs(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int
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);
+ // Show certificate(s)
+ xslt_print_xmldoc(stdout, cfg, certlist, "certificates.xsl", xsltparams);
rc = 0;
exit:
xmlFreeDoc(certlist);
diff --git a/eurephiadm/commands/users.c b/eurephiadm/commands/users.c
index 581cf18..7b1dcd3 100644
--- a/eurephiadm/commands/users.c
+++ b/eurephiadm/commands/users.c
@@ -52,7 +52,6 @@
#define SHOWCERTS_FIREWALL 0x001
#define SHOWCERTS_DIGEST 0x002
-void xmlPrint_certs(xmlXPathContext *certsXP, const char *xpath, int show_flags);
int register_certificate(eurephiaCTX *ctx, int depth, const char *digest,
const char *cname, const char *org, const char *email);
@@ -374,7 +373,8 @@ int show_user(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int
// Show associated certificates if we was asked to show this info
if( show_info & USERINFO_certs ) {
- xmlPrint_certs(user_XP, "/eurephia/user/certificates/certificate", SHOWCERTS_FIREWALL);
+ const char *xsltparams[] = {"view_digest", "'0'", "view_fw", "'1'", NULL};
+ xslt_print_xmldoc(stdout, cfg, user_xml, "certificates.xsl", xsltparams);
}
if( show_info & USERINFO_lastlog ) {