summaryrefslogtreecommitdiffstats
path: root/database/sqlite/eurephiadb-sqlite.c
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 21:06:14 +0200
commit94c76823e975279e4477891f0516681296590fbd (patch)
tree44a1a4c56f9075a142783922e44c4f44b972b863 /database/sqlite/eurephiadb-sqlite.c
parent6cdb4cef3fc8ad268e63081ce817605cc7a38549 (diff)
downloadeurephia-94c76823e975279e4477891f0516681296590fbd.tar.gz
eurephia-94c76823e975279e4477891f0516681296590fbd.tar.xz
eurephia-94c76823e975279e4477891f0516681296590fbd.zip
Only updating opevpn_attempts on ATTEMPT_RESET when attempt count > 0alpha_0.2
Diffstat (limited to 'database/sqlite/eurephiadb-sqlite.c')
-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,