summaryrefslogtreecommitdiffstats
path: root/eurephiadm
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2009-03-31 23:00:34 +0200
committerDavid Sommerseth <dazo@users.sourceforge.net>2009-03-31 23:00:34 +0200
commite729a4b80c79a80b9acfd58c0f45707572eb1861 (patch)
tree7b3c993e348b50266d40353d2bb79df365f5d7c2 /eurephiadm
parent6607ee29039fbe651fc32e381c0d73bed079ee56 (diff)
downloadeurephia-e729a4b80c79a80b9acfd58c0f45707572eb1861.tar.gz
eurephia-e729a4b80c79a80b9acfd58c0f45707572eb1861.tar.xz
eurephia-e729a4b80c79a80b9acfd58c0f45707572eb1861.zip
Rewrote eurephiadm/users command to user XSLT wherever possible
Diffstat (limited to 'eurephiadm')
-rw-r--r--eurephiadm/commands/users.c117
1 files changed, 28 insertions, 89 deletions
diff --git a/eurephiadm/commands/users.c b/eurephiadm/commands/users.c
index 7b1dcd3..a25ced8 100644
--- a/eurephiadm/commands/users.c
+++ b/eurephiadm/commands/users.c
@@ -161,9 +161,9 @@ void help_Users() {
int list_users(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) {
xmlDoc *userlist = NULL;
- xmlNode *users_n = NULL;
int i = 0;
char *sortkeys = NULL;
+ const char *xsltparams[] = {"view", "'userlist'", NULL};
e_options listargs[] = {
{"--sort", "-S", 1},
@@ -190,37 +190,11 @@ int list_users(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int
}
}
- // Retrieve the user list - as an XML document
+ // Retrieve the user list - and display it
userlist = eDBadminGetUserList(ctx, sortkeys);
- if( userlist == NULL ) {
- fprintf(stderr, "Error retrieving user list\n");
- return 1;
- }
-
- fprintf(stdout, " %3s %-20.32s %-16.16s %-16.16s %-16.16s\n",
- "ID", "Username", "Activated","Deactivated","Last access");
- fprintf(stdout, " ----------------------------------------------------------------------------\n");
-
- // Find the user list node in the XML doc
- users_n = eurephiaXML_getRoot(ctx, userlist, "userlist", 1);
- if( users_n == NULL ) {
- fprintf(stderr, "Could not retrieve valid data\n");
- xmlFreeDoc(userlist);
- return 1;
- }
- users_n = users_n->children;
-
- // Loop through the user list
- for( ; users_n != NULL; users_n = users_n->next ) {
- fprintf(stdout, " %3.3s %-20.32s %-16.16s %-16.16s %-16.16s\n",
- xmlGetAttrValue(users_n->properties, "uid"),
- xmlGetNodeContent(users_n, "username"),
- defaultValue(xmlGetNodeContent(users_n, "activated"), "(Not activated)"),
- defaultValue(xmlGetNodeContent(users_n, "deactivated"), "-"),
- defaultValue(xmlGetNodeContent(users_n, "last_accessed"), "-"));
- }
- fprintf(stdout, " ----------------------------------------------------------------------------\n");
+ xslt_print_xmldoc(stdout, cfg, userlist, "users.xsl", xsltparams);
xmlFreeDoc(userlist);
+
return 0;
}
@@ -253,11 +227,15 @@ char *xmlFlags2str(xmlXPathContext *xpathCTX, const char *xpath) {
// Show account information for a particular user
int show_user(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) {
- xmlXPathContext *user_XP = NULL;
int i, crit_set = 0, lastlog_verb = 0;
long int show_info = USERINFO_user | USERINFO_certs;
xmlDoc *user_xml = NULL, *srch_xml = NULL;
- xmlNode *srch_root = NULL, *user_n = NULL;
+ xmlNode *srch_root = NULL;
+#ifdef FIREWALL
+ const char *xsltparams[] = {"view", NULL, "firewall", "'1'", "view_digest", "'0'", NULL};
+#else
+ const char *xsltparams[] = {"view", NULL, "firewall", "'0'", "view_digest", "'0'", NULL};
+#endif
e_options activargs[] = {
{"--uid", "-i", 1},
@@ -342,83 +320,44 @@ int show_user(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int
}
xmlFreeDoc(srch_xml);
- user_n = eurephiaXML_getRoot(ctx, user_xml, "user", 1);
- if( user_n == NULL ) {
- fprintf(stderr, "Could not retrieve valid data\n");
- xmlFreeDoc(user_xml);
- return 1;
- }
-
- // Create a XPath context for functions which users XPath to locate info
- user_XP = xmlXPathNewContext(user_xml);
- if( user_XP == NULL ) {
- fprintf(stderr,"Error: unable to create new XPath context\n");
- return 1;
- }
-
if( show_info & USERINFO_user ) {
- xmlNode *lastacc = NULL;
-
- lastacc = xmlFindNode(user_n, "last_accessed");
-
- field_print_str("User id", xmlGetAttrValue(user_n->properties, "uid"));
- field_print_str("User name", xmlGetNodeContent(user_n, "username"));
- field_print_str("Login count", xmlGetAttrValue(lastacc->properties, "logincount"));
- field_print_str("Last accessed", xmlExtractContent(lastacc));
- field_print_str("Activated", xmlGetNodeContent(user_n, "activated"));
- field_print_str("Dectivated", xmlGetNodeContent(user_n, "deactivated"));
- field_print_str("Flags", xmlFlags2str(user_XP, "/eurephia/user/flags/flag"));
- printf("\n");
+ xsltparams[1] = "'userinfo'";
+ xslt_print_xmldoc(stdout, cfg, user_xml, "users.xsl", xsltparams);
}
// Show associated certificates if we was asked to show this info
if( show_info & USERINFO_certs ) {
- const char *xsltparams[] = {"view_digest", "'0'", "view_fw", "'1'", NULL};
+ xsltparams[1] = "''";
xslt_print_xmldoc(stdout, cfg, user_xml, "certificates.xsl", xsltparams);
}
+ // Show lastlog for the user, if requested
if( show_info & USERINFO_lastlog ) {
-#ifdef FIREWALL
- char *xsltparams[] = {"view", "'list'", "firewall", "'1'", NULL};
-#else
- char *xsltparams[] = {"view", "'list'", "firewall", "'0'", NULL};
-#endif
+ xmlNode *user_n = NULL;
+
+ xsltparams[1] = "'list'";
if( lastlog_verb ) {
xsltparams[1] = "'details'";
}
+ user_n = eurephiaXML_getRoot(ctx, user_xml, "user", 1);
+ if( user_n == NULL ) {
+ fprintf(stderr, "Could not retrieve valid data\n");
+ xmlFreeDoc(user_xml);
+ return 1;
+ }
printf("** Lastlog entries for %s\n\n", xmlGetNodeContent(user_n, "username"));
- xslt_print_xmldoc(stdout, cfg, user_xml, "lastlog.xsl", (const char **)xsltparams);
+
+ xslt_print_xmldoc(stdout, cfg, user_xml, "lastlog.xsl", xsltparams);
}
+ // Show login attempt info and/or blacklist info
if( (show_info & USERINFO_attempts) || (show_info & USERINFO_blacklist) ) {
- xmlNode *atmpt = NULL, *blackl = NULL;
-
- atmpt = xmlFindNode(user_n, "attempts");
- blackl = xmlFindNode(user_n, "blacklist");
-
- if( atmpt->children != NULL ) {
- field_print_str("Login attempt information","");
- field_print_str("Failed attempts", xmlGetAttrValue(atmpt->properties, "attempts"));
- field_print_str("First attempt", xmlGetNodeContent(atmpt, "first_attempt"));
- field_print_str("Last attempt", xmlGetNodeContent(atmpt, "last_attempt"));
- } else {
- field_print_str("Login attempt information","Nothing registered");
- }
- printf("\n");
-
- if( blackl->children != NULL) {
- field_print_str("Blacklist information","");
- field_print_str("Blacklisted", xmlGetNodeContent(blackl, "blacklisted"));
- field_print_str("Last attempt", xmlGetNodeContent(blackl, "last_accessed"));
- } else {
- field_print_str("Blacklist information","Nothing registered");
- }
- printf("\n");
+ xsltparams[1] = "'attemptblacklist'";
+ xslt_print_xmldoc(stdout, cfg, user_xml, "users.xsl", xsltparams);
}
// Clean up
- xmlXPathFreeContext(user_XP);
xmlFreeDoc(user_xml);
return 0;