summaryrefslogtreecommitdiffstats
path: root/eurephiadm
diff options
context:
space:
mode:
Diffstat (limited to 'eurephiadm')
-rw-r--r--eurephiadm/commands/attempts.c104
1 files changed, 94 insertions, 10 deletions
diff --git a/eurephiadm/commands/attempts.c b/eurephiadm/commands/attempts.c
index f20b9b4..05b08ee 100644
--- a/eurephiadm/commands/attempts.c
+++ b/eurephiadm/commands/attempts.c
@@ -53,14 +53,19 @@ void display_attempts_help(int page)
" -v | --verbose Show more details\n"
"\n"
"Filters:\n"
- " -n | --username <username> User name\n"
- " -d | --digest <SHA1 digest> Certificate SHA1 digest\n\n"
- " -i | --ipaddr <ip address> IP address\n");
+ " -u | --username <username> User name\n"
+ " -d | --digest <SHA1 digest> Certificate SHA1 digest\n"
+ " -i | --ipaddr <ip address> IP address\n\n");
break;
case 'D':
printf("The attempts delete mode will remove a record from the attempts log.\n"
"\n"
+ "One of the following parameters must be given (only one):\n"
+ " -u | --username <username> User name\n"
+ " -d | --digest <SHA1 digest> Certificate SHA1 digest\n"
+ " -i | --ipaddr <ip address> IP address\n"
+ " -a | --attemptid <ID> Attempts record ID\n"
"\n"
);
break;
@@ -68,10 +73,11 @@ void display_attempts_help(int page)
case 'R':
printf("The attempts reset mode will reset the attempt registration.\n"
"\n"
- "One of the following parameters must be given (only one):"
- " -u | --username <username> User name\n"
- " -d | --digest <SHA1 digest> Certificate SHA1 digest\n\n"
+ "One of the following parameters must be given (only one):\n"
+ " -n | --username <username> User name\n"
+ " -d | --digest <SHA1 digest> Certificate SHA1 digest\n"
" -i | --ipaddr <ip address> IP address\n"
+ " -a | --attemptid <ID> Attempts record ID\n"
"\n"
);
break;
@@ -79,7 +85,7 @@ void display_attempts_help(int page)
default:
printf("Available modes for the attempts command are:\n\n"
" -D | --delete Delete a registered login attempt\n"
- " -R | --add Reset a registered login attempt\n"
+ " -R | --reset Reset a registered login attempt\n"
" -l | --list List all registered login attempts\n"
" -h | --help <mode> Show help\n\n");
break;
@@ -170,6 +176,86 @@ int list_attempts(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg,
int modify_attempts(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv)
{
+ xmlDoc *result_xml = NULL, *upd_xml = NULL;
+ xmlNode *fmap_n = NULL, *res_n = NULL, *upd_n = NULL;
+ int i = 0, rc = 1, mode = 0;
+
+ e_options modeargs[] = {
+ {"--help", "-h", 0},
+ {"--username", "-u", 1},
+ {"--digest", "-d", 1},
+ {"--ipaddr", "-i", 1},
+ {"--attemptid", "-a", 1},
+ {NULL, NULL, 0}
+ };
+
+ eurephiaXML_CreateDoc(ctx, 1, "attemptslog", &upd_xml, &upd_n);
+ if( (strcmp(argv[0], "--reset") == 0) || (strcmp(argv[0], "-R") == 0) ) {
+ xmlNewProp(upd_n, (xmlChar *) "mode", (xmlChar *) "reset");
+ mode = 'R';
+ } else if( (strcmp(argv[0], "--delete") == 0) || (strcmp(argv[0], "-D") == 0) ) {
+ xmlNewProp(upd_n, (xmlChar *) "mode", (xmlChar *) "delete");
+ mode = 'D';
+ } else {
+ fprintf(stderr, "%s: Invalid mode\n", MODULE);
+ xmlFreeDoc(upd_xml);
+ return 1;
+ }
+
+ fmap_n = xmlNewChild(upd_n, NULL, (xmlChar *) "fieldMapping", NULL);
+ xmlNewProp(fmap_n, (xmlChar *) "table", (xmlChar *) "attemptslog");
+
+ for( i = 1; i < argc; i++ ) {
+ switch( eurephia_getopt(&i, argc, argv, modeargs) ) {
+ case 'u':
+ xmlNewChild(fmap_n, NULL, (xmlChar *) "username", (xmlChar *) optargs[0]);
+ break;
+
+ case 'd':
+ xmlNewChild(fmap_n, NULL, (xmlChar *) "digest", (xmlChar *) optargs[0]);
+ break;
+
+ case 'i':
+ xmlNewChild(fmap_n, NULL, (xmlChar *) "ip", (xmlChar *) optargs[0]);
+ break;
+
+ case 'a':
+ xmlNewChild(fmap_n, NULL, (xmlChar *) "id", (xmlChar *) optargs[0]);
+ break;
+
+ case 'h':
+ display_attempts_help(mode);
+ return 0;
+
+ default:
+ return 1;
+ }
+ }
+
+ result_xml = eDBadminAttemptsLog(ctx, upd_xml);
+ xmlFreeDoc(upd_xml);
+ if( result_xml == NULL ) {
+ fprintf(stderr, "%s: Error during modifying attempts register\n", MODULE);
+ return 1;
+ }
+
+ res_n = eurephiaXML_getRoot(ctx, result_xml, NULL, 1);
+ if( res_n == NULL ) {
+ fprintf(stderr, "%s: Error during modifying attempts register. No results returned.\n", MODULE);
+ return 1;
+
+ }
+
+ if( xmlStrcmp(res_n->name, (xmlChar *) "Error") == 0 ) {
+ fprintf(stderr, "%s: %s\n", MODULE, xmlExtractContent(res_n));
+ rc = 1;
+ } else {
+ fprintf(stdout, "%s: %s\n", MODULE, xmlExtractContent(res_n));
+ rc = 0;
+ }
+ xmlFreeDoc(result_xml);
+
+ return rc;
}
@@ -195,12 +281,10 @@ int cmd_Attempts(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, i
mode_fnc = list_attempts;
break;
- /*
- case 'A':
+ case 'R':
case 'D':
mode_fnc = modify_attempts;
break;
- */
case 'h':
mode_fnc = help_Attempts2;