00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00032 #include <stdio.h>
00033 #include <string.h>
00034 #include <assert.h>
00035
00036 #ifdef HAVE_LIBXML2
00037 #include <libxml/tree.h>
00038 #include <libxml/xpath.h>
00039 #endif
00040
00041 #define MODULE "eurephia::LastLog"
00042 #include <eurephia_nullsafe.h>
00043 #include <eurephia_context.h>
00044 #include <eurephia_log.h>
00045 #include <eurephia_xml.h>
00046 #include <eurephia_values_struct.h>
00047 #include <eurephiadb_session_struct.h>
00048 #include <eurephiadb_mapping.h>
00049 #include <eurephiadb_driver.h>
00050 #include <certinfo.h>
00051
00052 #include "../argparser.h"
00053 #include "../xsltparser.h"
00054
00055
00059 void help_Lastlog()
00060 {
00061 printf("eurephiadm::Lastlog\n\n"
00062 "This command will query the lastlog entries, which contains information\n"
00063 "about all logins done with the eurephia-auth plug-in.\n\n"
00064 "Valid arguments:\n"
00065 " * Filters:\n"
00066 " -c | --certid Certificate ID\n"
00067 " -i | --uid User ID\n"
00068 " -u | --username User name\n"
00069 " -I | --ip-addr IP address of remote host\n"
00070 " -s | --login Login time\n"
00071 " -e | --logout Logout time\n"
00072 " -m | --mac-addr MAC address of remote VPN interface\n"
00073 " -a | --uicid Access profile ID\n"
00074 "\n"
00075 " * Other arguments:\n"
00076 " -S | --sortkeys List sorting fields\n"
00077 " -v | --verbose View detailed lastlog\n"
00078 "\n"
00079 " Valid sort keys are: uid, certid, ip, vpnip, status, login, logout,\n"
00080 " username, macaddr, uicid\n"
00081 "\n"
00082 );
00083 }
00084
00085
00097 int cmd_Lastlog(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv)
00098 {
00099 xmlDoc *lastlog_xml = NULL, *srch_xml = NULL;
00100 xmlNode *fmap_n = NULL, *srch_n = NULL, *flt_n = NULL;
00101 int i = 0;
00102 char *sortkeys = NULL;
00103 #ifdef FIREWALL
00104 char *xsltparams[] = {"view", "'list'", "firewall", "'1'", NULL};
00105 #else
00106 char *xsltparams[] = {"view", "'list'", "firewall", "'0'", NULL};
00107 #endif
00108
00109 e_options listargs[] = {
00110 {"--certid", "-c", 1},
00111 {"--uid", "-i", 1},
00112 {"--username", "-u", 1},
00113 {"--ip-addr", "-I", 1},
00114 {"--vpn-ip-addr","-V", 1},
00115 {"--login", "-s", 1},
00116 {"--logout", "-e", 1},
00117 {"--mac-addr", "-m", 1},
00118 {"--uicid", "-a", 1},
00119 {"--sort", "-S", 1},
00120 {"--help", "-h", 0},
00121 {"--verbose", "-v", 0},
00122 {NULL, NULL, 0}
00123 };
00124 assert( (ctx != NULL) && (ctx->dbc != NULL) && (ctx->dbc->config != NULL));
00125
00126 eurephiaXML_CreateDoc(ctx, 1, "lastlog_query", &srch_xml, &srch_n);
00127 fmap_n = xmlNewChild(srch_n, NULL, (xmlChar *) "fieldMapping", NULL);
00128 xmlNewProp(fmap_n, (xmlChar *) "table", (xmlChar *) "lastlog");
00129
00130
00131 for( i = 1; i < argc; i++ ) {
00132 switch( eurephia_getopt(&i, argc, argv, listargs) ) {
00133 case 'S':
00134 sortkeys = optargs[0];
00135 break;
00136
00137 case 'h':
00138 help_Lastlog();
00139 return 0;
00140
00141 case 'c':
00142 xmlNewChild(fmap_n, NULL, (xmlChar *) "certid", (xmlChar *) optargs[0]);
00143 break;
00144
00145 case 'i':
00146 xmlNewChild(fmap_n, NULL, (xmlChar *) "uid", (xmlChar *) optargs[0]);
00147 break;
00148
00149 case 'u':
00150 xmlNewChild(fmap_n, NULL, (xmlChar *) "username", (xmlChar *) optargs[0]);
00151 break;
00152
00153 case 'I':
00154 xmlNewChild(fmap_n, NULL, (xmlChar *) "ip", (xmlChar *) optargs[0]);
00155 break;
00156
00157 case 'V':
00158 xmlNewChild(fmap_n, NULL, (xmlChar *) "vpnip", (xmlChar *) optargs[0]);
00159 break;
00160
00161 case 's':
00162 flt_n = xmlNewChild(fmap_n, NULL, (xmlChar *) "login", (xmlChar *) optargs[0]);
00163 xmlNewProp(flt_n, (xmlChar *) "filter", (xmlChar *) "greater-than-equals");
00164 break;
00165
00166 case 'e':
00167 flt_n = xmlNewChild(fmap_n, NULL, (xmlChar *) "logout", (xmlChar *) optargs[0]);
00168 xmlNewProp(flt_n, (xmlChar *) "filter", (xmlChar *) "less-than-equals");
00169 break;
00170
00171 case 'm':
00172 xmlNewChild(fmap_n, NULL, (xmlChar *) "macaddr", (xmlChar *) optargs[0]);
00173 break;
00174
00175 case 'a':
00176 xmlNewChild(fmap_n, NULL, (xmlChar *) "uicid", (xmlChar *) optargs[0]);
00177 break;
00178
00179 case 'v':
00180 xsltparams[1] = "'details2'";
00181 break;
00182
00183 default:
00184 fprintf(stderr, "%s: Invalid argument: %s\n", MODULE, argv[i-1]);
00185 return 1;
00186 }
00187 }
00188
00189 lastlog_xml = eDBadminGetLastlog(ctx, srch_xml, sortkeys);
00190 xmlFreeDoc(srch_xml);
00191 if( lastlog_xml == NULL ) {
00192 fprintf(stderr, "%s: Error retrieving lastlog entries\n", MODULE);
00193 return 1;
00194 }
00195
00196 xslt_print_xmldoc(stdout, cfg, lastlog_xml, "lastlog.xsl", (const char **) xsltparams);
00197
00198 xmlFreeDoc(lastlog_xml);
00199 return 0;
00200 }