diff options
| author | David Sommerseth <davids@redhat.com> | 2009-05-07 15:10:00 +0200 |
|---|---|---|
| committer | David Sommerseth <davids@redhat.com> | 2009-05-07 15:10:00 +0200 |
| commit | bbfeb72250428609c464a9abbb1c1a95ca83f882 (patch) | |
| tree | 7f80a6fc7722cf64b8f303cdf15925f5171bafc2 /database | |
| parent | e81e2357a03c26903a48c664b6b5d5be62e16f23 (diff) | |
| download | eurephia-bbfeb72250428609c464a9abbb1c1a95ca83f882.tar.gz eurephia-bbfeb72250428609c464a9abbb1c1a95ca83f882.tar.xz eurephia-bbfeb72250428609c464a9abbb1c1a95ca83f882.zip | |
Completed the attempts command in eurephiadm
Added functionality for resetting and deleting attempt records
Diffstat (limited to 'database')
| -rw-r--r-- | database/sqlite/administration.c | 8 | ||||
| -rw-r--r-- | database/sqlite/attempts.c | 48 |
2 files changed, 48 insertions, 8 deletions
diff --git a/database/sqlite/administration.c b/database/sqlite/administration.c index e75dccd..f831c69 100644 --- a/database/sqlite/administration.c +++ b/database/sqlite/administration.c @@ -1565,7 +1565,7 @@ xmlDoc *eDBadminGetLastlog(eurephiaCTX *ctx, xmlDoc *srch, const char *sortkeys) // The search XML document format is: // <eurephia format="1"> -// <attemptslog mode="{search|add|delete}"> +// <attemptslog mode="{search|reset|delete}"> // <fieldMapping table="attempts"> // <{field name}>{field value}</{field field}> // </fieldMapping> @@ -1575,7 +1575,7 @@ xmlDoc *eDBadminGetLastlog(eurephiaCTX *ctx, xmlDoc *srch, const char *sortkeys) // It can be several search field tags to limit the search even more. // xmlDoc *attempts_list(eurephiaCTX *ctx, eDBfieldMap *fmap); -xmlDoc *attempts_add(eurephiaCTX *ctx, eDBfieldMap *fmap); +xmlDoc *attempts_reset(eurephiaCTX *ctx, eDBfieldMap *fmap); xmlDoc *attempts_delete(eurephiaCTX *ctx, eDBfieldMap *fmap); xmlDoc *eDBadminAttemptsLog(eurephiaCTX *ctx, xmlDoc *qryxml) { @@ -1612,8 +1612,8 @@ xmlDoc *eDBadminAttemptsLog(eurephiaCTX *ctx, xmlDoc *qryxml) { if( strcmp(mode, "list") == 0 ) { resxml = attempts_list(ctx, fmap); - } else if( strcmp(mode, "add") == 0 ) { - resxml = attempts_add(ctx, fmap); + } else if( strcmp(mode, "reset") == 0 ) { + resxml = attempts_reset(ctx, fmap); } else if( strcmp(mode, "delete") == 0 ) { resxml = attempts_delete(ctx, fmap); } else { diff --git a/database/sqlite/attempts.c b/database/sqlite/attempts.c index 4afd981..a524175 100644 --- a/database/sqlite/attempts.c +++ b/database/sqlite/attempts.c @@ -62,7 +62,7 @@ xmlDoc *attempts_list(eurephiaCTX *ctx, eDBfieldMap *fmap) { NULL, fmap, "atpid"); if( res == NULL ) { eurephia_log(ctx, LOG_ERROR, 0, "Error querying the attempts log"); - return 0; + return NULL; } eurephiaXML_CreateDoc(ctx, 1, "attemptslog", &doc, &root_n); @@ -106,12 +106,52 @@ xmlDoc *attempts_list(eurephiaCTX *ctx, eDBfieldMap *fmap) { } -xmlDoc *attempts_add(eurephiaCTX *ctx, eDBfieldMap *fmap) { - return NULL; +xmlDoc *attempts_reset(eurephiaCTX *ctx, eDBfieldMap *fmap) { + dbresult *res = NULL; + xmlDoc *ret = NULL; + int fields = 0; + eDBfieldMap update_vals[] = { + {TABLE_ATTEMPTS, NULL, FIELD_ATTEMPTS, ft_INT, flt_NOTSET, "attempts", "0", NULL}, + {0, NULL, 0, ft_UNDEF, flt_NOTSET, NULL, NULL, NULL} + }; + + fields = eDBmappingFieldsPresent(fmap); + if( (fields & (FIELD_UNAME | FIELD_CERTDIGEST | FIELD_REMOTEIP | FIELD_RECID)) == 0 ) { + return eurephiaXML_ResultMsg(ctx, exmlERROR, + "Missing username, IP address, certificate digest or atpid"); + } + + res = sqlite_query_mapped(ctx, SQL_UPDATE, "UPDATE openvpn_attempts", update_vals, fmap, NULL); + if( res == NULL ) { + eurephia_log(ctx, LOG_FATAL, 0, "Could not reset the attempts count"); + ret = eurephiaXML_ResultMsg(ctx, exmlERROR, "Could not reset the attempts count"); + } else { + ret = eurephiaXML_ResultMsg(ctx, exmlRESULT, "Attempts count reset"); + sqlite_free_results(res); + } + return ret; } xmlDoc *attempts_delete(eurephiaCTX *ctx, eDBfieldMap *fmap) { - return NULL; + dbresult *res = NULL; + xmlDoc *ret = NULL; + int fields; + + fields = eDBmappingFieldsPresent(fmap); + if( (fields & (FIELD_UNAME | FIELD_CERTDIGEST | FIELD_REMOTEIP | FIELD_RECID)) == 0 ) { + return eurephiaXML_ResultMsg(ctx, exmlERROR, + "Missing username, IP address, certificate digest or atpid"); + } + + res = sqlite_query_mapped(ctx, SQL_DELETE, "DELETE FROM openvpn_attempts", NULL, fmap, NULL); + if( res == NULL ) { + eurephia_log(ctx, LOG_FATAL, 0, "Could not remove attempts record"); + ret = eurephiaXML_ResultMsg(ctx, exmlERROR, "Could not delete the attempts record"); + } else { + ret = eurephiaXML_ResultMsg(ctx, exmlRESULT, "Attempts record removed"); + sqlite_free_results(res); + } + return ret; } |
