db operations fixed

This commit is contained in:
mom040267 2014-09-01 18:51:37 +00:00
parent 4f94e42494
commit 31089e909c
5 changed files with 73 additions and 60 deletions

View File

@ -1,5 +1,7 @@
08/22/2014 Oleg Moskalenko <mom040267@gmail.com>
Version 4.1.2.2 'Vitari':
- redis user key operation fixed.
- redis, mysql and psql db operations fixed.
- SHA-256 memory leak fixed.
- Mobility ticket retransmission fixed.

View File

@ -335,7 +335,9 @@ static int mysql_get_user_key(u08bits *usname, u08bits *realm, hmackey_t key) {
}
static int mysql_get_user_pwd(u08bits *usname, st_password_t pwd) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
snprintf(statement,sizeof(statement),"select password from turnusers_st where name='%s'",usname);
@ -375,7 +377,7 @@ static int mysql_get_user_pwd(u08bits *usname, st_password_t pwd) {
static int mysql_get_oauth_key(const u08bits *kid, oauth_key_data_raw *key) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
snprintf(statement,sizeof(statement),"select ikm_key,timestamp,lifetime,hkdf_hash_func,as_rs_alg,as_rs_key,auth_alg,auth_key from oauth_key where kid='%s'",(const char*)kid);
@ -440,7 +442,7 @@ static int mysql_list_oauth_keys(void) {
oauth_key_data_raw key_;
oauth_key_data_raw *key=&key_;
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
snprintf(statement,sizeof(statement),"select ikm_key,timestamp,lifetime,hkdf_hash_func,as_rs_alg,as_rs_key,auth_alg,auth_key,kid from oauth_key order by kid");
@ -508,7 +510,7 @@ static int mysql_list_oauth_keys(void) {
}
static int mysql_set_user_key(u08bits *usname, u08bits *realm, const char *key) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
MYSQL * myc = get_mydb_connection();
if(myc) {
@ -526,7 +528,7 @@ static int mysql_set_user_key(u08bits *usname, u08bits *realm, const char *key)
}
static int mysql_set_oauth_key(oauth_key_data_raw *key) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
MYSQL * myc = get_mydb_connection();
if(myc) {
@ -547,7 +549,7 @@ static int mysql_set_oauth_key(oauth_key_data_raw *key) {
}
static int mysql_set_user_pwd(u08bits *usname, st_password_t pwd) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
MYSQL * myc = get_mydb_connection();
if(myc) {
@ -567,7 +569,7 @@ static int mysql_set_user_pwd(u08bits *usname, st_password_t pwd) {
}
static int mysql_del_user(u08bits *usname, int is_st, u08bits *realm) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
MYSQL * myc = get_mydb_connection();
if(myc) {
@ -587,7 +589,7 @@ static int mysql_del_user(u08bits *usname, int is_st, u08bits *realm) {
}
static int mysql_del_oauth_key(const u08bits *kid) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
MYSQL * myc = get_mydb_connection();
if(myc) {
@ -603,7 +605,7 @@ static int mysql_del_oauth_key(const u08bits *kid) {
}
static int mysql_list_users(int is_st, u08bits *realm) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
MYSQL * myc = get_mydb_connection();
if(myc) {
@ -649,7 +651,7 @@ static int mysql_list_users(int is_st, u08bits *realm) {
}
static int mysql_show_secret(u08bits *realm) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
snprintf(statement,sizeof(statement)-1,"select value from turn_secret where realm='%s'",realm);
@ -688,7 +690,7 @@ static int mysql_show_secret(u08bits *realm) {
}
static int mysql_del_secret(u08bits *secret, u08bits *realm) {
int ret = 1;
int ret = -1;
donot_print_connection_success=1;
char statement[TURN_LONG_STRING_SIZE];
MYSQL * myc = get_mydb_connection();
@ -704,7 +706,7 @@ static int mysql_del_secret(u08bits *secret, u08bits *realm) {
}
static int mysql_set_secret(u08bits *secret, u08bits *realm) {
int ret = 1;
int ret = -1;
donot_print_connection_success = 1;
char statement[TURN_LONG_STRING_SIZE];
MYSQL * myc = get_mydb_connection();
@ -724,7 +726,7 @@ static int mysql_set_secret(u08bits *secret, u08bits *realm) {
}
static int mysql_add_origin(u08bits *origin, u08bits *realm) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
MYSQL * myc = get_mydb_connection();
if (myc) {
@ -743,7 +745,7 @@ static int mysql_add_origin(u08bits *origin, u08bits *realm) {
}
static int mysql_del_origin(u08bits *origin) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
MYSQL * myc = get_mydb_connection();
if (myc) {
@ -762,7 +764,7 @@ static int mysql_del_origin(u08bits *origin) {
}
static int mysql_list_origins(u08bits *realm) {
int ret = 1;
int ret = -1;
donot_print_connection_success = 1;
char statement[TURN_LONG_STRING_SIZE];
MYSQL * myc = get_mydb_connection();
@ -803,7 +805,7 @@ static int mysql_list_origins(u08bits *realm) {
}
static int mysql_set_realm_option_one(u08bits *realm, unsigned long value, const char* opt) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
MYSQL * myc = get_mydb_connection();
if (myc) {
@ -828,7 +830,7 @@ static int mysql_set_realm_option_one(u08bits *realm, unsigned long value, const
}
static int mysql_list_realm_options(u08bits *realm) {
int ret = 1;
int ret = -1;
donot_print_connection_success = 1;
char statement[TURN_LONG_STRING_SIZE];
MYSQL * myc = get_mydb_connection();
@ -890,7 +892,7 @@ static void mysql_auth_ping(void * rch) {
}
static int mysql_get_ip_list(const char *kind, ip_range_list_t * list) {
int ret = 1;
int ret = -1;
MYSQL * myc = get_mydb_connection();
if(myc) {
char statement[TURN_LONG_STRING_SIZE];
@ -916,7 +918,7 @@ static int mysql_get_ip_list(const char *kind, ip_range_list_t * list) {
}
}
}
ret = 0;
ret = 0;
}
if(mres)

View File

@ -86,7 +86,7 @@ static PGconn *get_pqdb_connection(void) {
///////////////////////////////////////////////////////////////////////////////////////////////////////////
static int pgsql_get_auth_secrets(secrets_list_t *sl, u08bits *realm) {
int ret = 1;
int ret = -1;
PGconn * pqc = get_pqdb_connection();
if(pqc) {
char statement[TURN_LONG_STRING_SIZE];
@ -114,7 +114,7 @@ static int pgsql_get_auth_secrets(secrets_list_t *sl, u08bits *realm) {
}
static int pgsql_get_user_key(u08bits *usname, u08bits *realm, hmackey_t key) {
int ret = 1;
int ret = -1;
PGconn * pqc = get_pqdb_connection();
if(pqc) {
char statement[TURN_LONG_STRING_SIZE];
@ -148,7 +148,7 @@ static int pgsql_get_user_key(u08bits *usname, u08bits *realm, hmackey_t key) {
}
static int pgsql_get_user_pwd(u08bits *usname, st_password_t pwd) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
snprintf(statement,sizeof(statement),"select password from turnusers_st where name='%s'",usname);
@ -177,7 +177,7 @@ static int pgsql_get_user_pwd(u08bits *usname, st_password_t pwd) {
static int pgsql_get_oauth_key(const u08bits *kid, oauth_key_data_raw *key) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
snprintf(statement,sizeof(statement),"select ikm_key,timestamp,lifetime,hkdf_hash_func,as_rs_alg,as_rs_key,auth_alg,auth_key from oauth_key where kid='%s'",(const char*)kid);
@ -214,7 +214,7 @@ static int pgsql_list_oauth_keys(void) {
oauth_key_data_raw key_;
oauth_key_data_raw *key=&key_;
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
snprintf(statement,sizeof(statement),"select ikm_key,timestamp,lifetime,hkdf_hash_func,as_rs_alg,as_rs_key,auth_alg,auth_key,kid from oauth_key order by kid");
@ -256,7 +256,7 @@ static int pgsql_list_oauth_keys(void) {
}
static int pgsql_set_user_key(u08bits *usname, u08bits *realm, const char *key) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
PGconn *pqc = get_pqdb_connection();
if(pqc) {
@ -284,7 +284,7 @@ static int pgsql_set_user_key(u08bits *usname, u08bits *realm, const char *key)
static int pgsql_set_oauth_key(oauth_key_data_raw *key) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
PGconn *pqc = get_pqdb_connection();
if(pqc) {
@ -314,7 +314,7 @@ static int pgsql_set_oauth_key(oauth_key_data_raw *key) {
}
static int pgsql_set_user_pwd(u08bits *usname, st_password_t pwd) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
PGconn *pqc = get_pqdb_connection();
if(pqc) {
@ -340,7 +340,7 @@ static int pgsql_set_user_pwd(u08bits *usname, st_password_t pwd) {
}
static int pgsql_del_user(u08bits *usname, int is_st, u08bits *realm) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
PGconn *pqc = get_pqdb_connection();
if(pqc) {
@ -360,7 +360,7 @@ static int pgsql_del_user(u08bits *usname, int is_st, u08bits *realm) {
static int pgsql_del_oauth_key(const u08bits *kid) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
PGconn *pqc = get_pqdb_connection();
if(pqc) {
@ -380,7 +380,7 @@ static int pgsql_del_oauth_key(const u08bits *kid) {
}
static int pgsql_list_users(int is_st, u08bits *realm) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
PGconn *pqc = get_pqdb_connection();
if(pqc) {
@ -417,7 +417,7 @@ static int pgsql_list_users(int is_st, u08bits *realm) {
}
static int pgsql_show_secret(u08bits *realm) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
snprintf(statement,sizeof(statement)-1,"select value from turn_secret where realm='%s'",realm);
@ -446,7 +446,7 @@ static int pgsql_show_secret(u08bits *realm) {
}
static int pgsql_del_secret(u08bits *secret, u08bits *realm) {
int ret = 1;
int ret = -1;
donot_print_connection_success=1;
char statement[TURN_LONG_STRING_SIZE];
PGconn *pqc = get_pqdb_connection();
@ -466,7 +466,7 @@ static int pgsql_del_secret(u08bits *secret, u08bits *realm) {
}
static int pgsql_set_secret(u08bits *secret, u08bits *realm) {
int ret = 1;
int ret = -1;
donot_print_connection_success = 1;
char statement[TURN_LONG_STRING_SIZE];
PGconn *pqc = get_pqdb_connection();
@ -490,7 +490,7 @@ static int pgsql_set_secret(u08bits *secret, u08bits *realm) {
}
static int pgsql_add_origin(u08bits *origin, u08bits *realm) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
PGconn *pqc = get_pqdb_connection();
if(pqc) {
@ -509,7 +509,7 @@ static int pgsql_add_origin(u08bits *origin, u08bits *realm) {
}
static int pgsql_del_origin(u08bits *origin) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
PGconn *pqc = get_pqdb_connection();
if(pqc) {
@ -528,7 +528,7 @@ static int pgsql_del_origin(u08bits *origin) {
}
static int pgsql_list_origins(u08bits *realm) {
int ret = 1;
int ret = -1;
donot_print_connection_success = 1;
char statement[TURN_LONG_STRING_SIZE];
PGconn *pqc = get_pqdb_connection();
@ -562,7 +562,7 @@ static int pgsql_list_origins(u08bits *realm) {
}
static int pgsql_set_realm_option_one(u08bits *realm, unsigned long value, const char* opt) {
int ret = 1;
int ret = -1;
char statement[TURN_LONG_STRING_SIZE];
PGconn *pqc = get_pqdb_connection();
if(pqc) {
@ -590,7 +590,7 @@ static int pgsql_set_realm_option_one(u08bits *realm, unsigned long value, const
}
static int pgsql_list_realm_options(u08bits *realm) {
int ret = 1;
int ret = -1;
donot_print_connection_success = 1;
char statement[TURN_LONG_STRING_SIZE];
PGconn *pqc = get_pqdb_connection();
@ -646,7 +646,7 @@ static void pgsql_auth_ping(void * rch) {
}
static int pgsql_get_ip_list(const char *kind, ip_range_list_t * list) {
int ret = 1;
int ret = -1;
PGconn * pqc = get_pqdb_connection();
if(pqc) {
char statement[TURN_LONG_STRING_SIZE];

View File

@ -397,7 +397,7 @@ static int set_redis_realm_opt(char *realm, const char* key, unsigned long *valu
///////////////////////////////////////////////////////////////////////////////////////////////////////////
static int redis_get_auth_secrets(secrets_list_t *sl, u08bits *realm) {
int ret = 1;
int ret = -1;
redisContext *rc = get_redis_connection();
if(rc) {
redisReply *reply = (redisReply*)redisCommand(rc, "keys turn/realm/%s/secret/*", (char*)realm);
@ -448,7 +448,7 @@ static int redis_get_auth_secrets(secrets_list_t *sl, u08bits *realm) {
}
static int redis_get_user_key(u08bits *usname, u08bits *realm, hmackey_t key) {
int ret = 1;
int ret = -1;
redisContext * rc = get_redis_connection();
if(rc) {
char s[TURN_LONG_STRING_SIZE];
@ -472,7 +472,7 @@ static int redis_get_user_key(u08bits *usname, u08bits *realm, hmackey_t key) {
}
turnFreeRedisReply(rget);
}
if(ret != 0) {
if(ret == 0) {
snprintf(s,sizeof(s),"get turn/realm/%s/user/%s/password", (char*)realm, usname);
rget = (redisReply *)redisCommand(rc, s);
if(rget) {
@ -494,7 +494,7 @@ static int redis_get_user_key(u08bits *usname, u08bits *realm, hmackey_t key) {
}
static int redis_get_oauth_key(const u08bits *kid, oauth_key_data_raw *key) {
int ret = 1;
int ret = -1;
redisContext * rc = get_redis_connection();
if(rc) {
char s[TURN_LONG_STRING_SIZE];
@ -542,7 +542,7 @@ static int redis_get_oauth_key(const u08bits *kid, oauth_key_data_raw *key) {
}
static int redis_get_user_pwd(u08bits *usname, st_password_t pwd) {
int ret = 1;
int ret = -1;
redisContext * rc = get_redis_connection();
if(rc) {
char s[TURN_LONG_STRING_SIZE];
@ -566,7 +566,7 @@ static int redis_get_user_pwd(u08bits *usname, st_password_t pwd) {
}
static int redis_set_user_key(u08bits *usname, u08bits *realm, const char *key) {
int ret = 1;
int ret = -1;
redisContext *rc = get_redis_connection();
if(rc) {
char statement[TURN_LONG_STRING_SIZE];
@ -581,7 +581,7 @@ static int redis_set_user_key(u08bits *usname, u08bits *realm, const char *key)
}
static int redis_set_oauth_key(oauth_key_data_raw *key) {
int ret = 1;
int ret = -1;
redisContext *rc = get_redis_connection();
if(rc) {
char statement[TURN_LONG_STRING_SIZE];
@ -595,7 +595,7 @@ static int redis_set_oauth_key(oauth_key_data_raw *key) {
}
static int redis_set_user_pwd(u08bits *usname, st_password_t pwd) {
int ret = 1;
int ret = -1;
redisContext *rc = get_redis_connection();
if(rc) {
char statement[TURN_LONG_STRING_SIZE];
@ -608,7 +608,7 @@ static int redis_set_user_pwd(u08bits *usname, st_password_t pwd) {
}
static int redis_del_user(u08bits *usname, int is_st, u08bits *realm) {
int ret = 1;
int ret = -1;
redisContext *rc = get_redis_connection();
if(rc) {
char statement[TURN_LONG_STRING_SIZE];
@ -629,7 +629,7 @@ static int redis_del_user(u08bits *usname, int is_st, u08bits *realm) {
}
static int redis_del_oauth_key(const u08bits *kid) {
int ret = 1;
int ret = -1;
redisContext *rc = get_redis_connection();
if(rc) {
char statement[TURN_LONG_STRING_SIZE];
@ -642,7 +642,7 @@ static int redis_del_oauth_key(const u08bits *kid) {
}
static int redis_list_users(int is_st, u08bits *realm) {
int ret = 1;
int ret = -1;
redisContext *rc = get_redis_connection();
if(rc) {
secrets_list_t keys;
@ -733,7 +733,7 @@ static int redis_list_users(int is_st, u08bits *realm) {
}
static int redis_list_oauth_keys(void) {
int ret = 1;
int ret = -1;
redisContext *rc = get_redis_connection();
secrets_list_t keys;
size_t isz = 0;
@ -781,7 +781,7 @@ static int redis_list_oauth_keys(void) {
}
static int redis_show_secret(u08bits *realm) {
int ret = 1;
int ret = -1;
donot_print_connection_success = 1;
redisContext *rc = get_redis_connection();
if(rc) {
@ -836,7 +836,7 @@ static int redis_show_secret(u08bits *realm) {
}
static int redis_del_secret(u08bits *secret, u08bits *realm) {
int ret = 1;
int ret = -1;
donot_print_connection_success = 1;
redisContext *rc = get_redis_connection();
if(rc) {
@ -896,7 +896,7 @@ static int redis_del_secret(u08bits *secret, u08bits *realm) {
}
static int redis_set_secret(u08bits *secret, u08bits *realm) {
int ret = 1;
int ret = -1;
donot_print_connection_success = 1;
redisContext *rc = get_redis_connection();
if(rc) {
@ -914,7 +914,7 @@ static int redis_set_secret(u08bits *secret, u08bits *realm) {
}
static int redis_add_origin(u08bits *origin, u08bits *realm) {
int ret = 1;
int ret = -1;
redisContext *rc = get_redis_connection();
if(rc) {
char s[TURN_LONG_STRING_SIZE];
@ -929,7 +929,7 @@ static int redis_add_origin(u08bits *origin, u08bits *realm) {
}
static int redis_del_origin(u08bits *origin) {
int ret = 1;
int ret = -1;
redisContext *rc = get_redis_connection();
if(rc) {
char s[TURN_LONG_STRING_SIZE];
@ -944,7 +944,7 @@ static int redis_del_origin(u08bits *origin) {
}
static int redis_list_origins(u08bits *realm) {
int ret = 1;
int ret = -1;
donot_print_connection_success = 1;
redisContext *rc = get_redis_connection();
if(rc) {
@ -1002,7 +1002,7 @@ static int redis_list_origins(u08bits *realm) {
}
static int redis_set_realm_option_one(u08bits *realm, unsigned long value, const char* opt) {
int ret = 1;
int ret = -1;
redisContext *rc = get_redis_connection();
if(rc) {
char s[TURN_LONG_STRING_SIZE];
@ -1020,7 +1020,7 @@ static int redis_set_realm_option_one(u08bits *realm, unsigned long value, const
}
static int redis_list_realm_options(u08bits *realm) {
int ret = 1;
int ret = -1;
donot_print_connection_success = 1;
redisContext *rc = get_redis_connection();
if(rc) {
@ -1095,7 +1095,7 @@ static void redis_auth_ping(void * rch) {
}
static int redis_get_ip_list(const char *kind, ip_range_list_t * list) {
int ret = 1;
int ret = -1;
redisContext *rc = get_redis_connection();
if(rc) {
char statement[TURN_LONG_STRING_SIZE];

View File

@ -7,11 +7,17 @@ AUTH turn
set turn/realm/north.gov/user/ninefingers/key "bc807ee29df3c9ffa736523fb2c4e8ee"
set turn/realm/north.gov/user/gorst/key "7da2270ccfa49786e0115366d3a3d14d"
set turn/realm/north.gov/user/bethod/key "3b4125e139811b8577a214c24273fee27b15ff397631c7775b980785a229e6bd"
set turn/realm/crinna.org/user/whirrun/key "6972e85e51f36e53b0b61759c5a5219a"
set turn/realm/crinna.org/user/stranger-come-knocking/key "d43cb678560259a1839bff61c19de15e"
set turn/realm/north.gov/user/ninefingers/password "youhavetoberealistic"
set turn/realm/north.gov/user/gorst/password "hero"
set turn/realm/north.gov/user/bethod/password "king-of-north"
set turn/realm/crinna.org/user/whirrun/password "sword"
set turn/realm/crinna.org/user/stranger-come-knocking/password "civilization"
@ -20,6 +26,9 @@ set turn/realm/crinna.org/secret/777888999 "north"
set turn/user/ninefingers/password "youhavetoberealistic"
set turn/user/gorst/password "hero"
set turn/user/bethod/password "king-of-north"
set turn/user/whirrun/password "sword"
set turn/user/stranger-come-knocking/password "civilization"