summaryrefslogtreecommitdiffstats
path: root/database
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2008-08-17 20:55:07 +0200
committerDavid Sommerseth <dazo@users.sourceforge.net>2008-08-17 20:55:07 +0200
commitd21a340a5594f0ebe31d4ae2345444312b8a1ca0 (patch)
treec759e11c117ab23bd40ff65c0788d05608374d71 /database
parenta6d801819cacd7f776b678b0041714fe1bd9346a (diff)
downloadeurephia-d21a340a5594f0ebe31d4ae2345444312b8a1ca0.tar.gz
eurephia-d21a340a5594f0ebe31d4ae2345444312b8a1ca0.tar.xz
eurephia-d21a340a5594f0ebe31d4ae2345444312b8a1ca0.zip
Only updating opevpn_attempts on ATTEMPT_RESET when attempt count > 0
Diffstat (limited to 'database')
-rw-r--r--database/sqlite/eurephiadb-sqlite.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/database/sqlite/eurephiadb-sqlite.c b/database/sqlite/eurephiadb-sqlite.c
index 5594c14..b1294ed 100644
--- a/database/sqlite/eurephiadb-sqlite.c
+++ b/database/sqlite/eurephiadb-sqlite.c
@@ -420,6 +420,7 @@ int eDBblacklist_check(eurephiaCTX *ctx, const int type, const char *val)
void eDBregister_attempt(eurephiaCTX *ctx, int type, int mode, const char *value) {
dbresult *res;
char *id = NULL, *atmpt_block = NULL, *blid = NULL;
+ int attempts = 0;
eurephia_log(ctx, LOG_DEBUG, 10, "Function call: eDBregister_attempt(ctx, %s, %s, '%s')",
eDBattempt_types[type].colname,
@@ -430,7 +431,7 @@ void eDBregister_attempt(eurephiaCTX *ctx, int type, int mode, const char *value
// openvpn_attempts
//
res = sqlite_query(ctx,
- "SELECT atpid, attempts > %s, blid "
+ "SELECT atpid, attempts > %s, blid, attempts "
" FROM openvpn_attempts "
" LEFT JOIN openvpn_blacklist USING(%s)"
" WHERE %s = '%s'",
@@ -442,15 +443,16 @@ void eDBregister_attempt(eurephiaCTX *ctx, int type, int mode, const char *value
return;
}
- if( (mode == ATTEMPT_RESET) && (sqlite_get_numtuples(res) == 0) ) {
- // If we are asked to reset the attempt counter and we do not find any attempts, exit here
+ attempts = atoi_nullsafe(sqlite_get_value(res, 0, 3));
+ // If we are asked to reset the attempt counter and we do not find any attempts, exit here
+ if( (mode == ATTEMPT_RESET) && ((sqlite_get_numtuples(res) == 0) || (attempts == 0))) {
sqlite_free_results(res);
return;
}
id = strdup_nullsafe(sqlite_get_value(res, 0, 0));
atmpt_block = strdup_nullsafe(sqlite_get_value(res, 0, 1));
- blid = strdup_nullsafe(sqlite_get_value(res, 0, 1));
+ blid = strdup_nullsafe(sqlite_get_value(res, 0, 2));
sqlite_free_results(res);
@@ -460,12 +462,20 @@ void eDBregister_attempt(eurephiaCTX *ctx, int type, int mode, const char *value
eDBattempt_types[type].colname, value);
} else if( id != NULL ){
// if a attempt record exists, update it according to mode
- res = sqlite_query(ctx,
- "UPDATE openvpn_attempts "
- " SET last_attempt = CURRENT_TIMESTAMP, attempts = %s"
- " WHERE atpid = %s",
- (mode == ATTEMPT_RESET ? "0" : "attempts + 1"),
- id);
+ switch( mode ) {
+ case ATTEMPT_RESET:
+ res = sqlite_query(ctx,
+ "UPDATE openvpn_attempts "
+ " SET attempts = 0 "
+ " WHERE atpid = %s", id);
+ break;
+ default:
+ res = sqlite_query(ctx,
+ "UPDATE openvpn_attempts "
+ " SET last_attempt = CURRENT_TIMESTAMP, attempts = attempts + 1"
+ " WHERE atpid = %s", id);
+ break;
+ }
}
if( res == NULL ) {
eurephia_log(ctx, LOG_CRITICAL, 0,