fix token allocation sql strings

This commit is contained in:
Harald Welte (local) 2009-08-13 13:26:11 +02:00
parent 571602f43c
commit 3feef255d2
1 changed files with 15 additions and 13 deletions

View File

@ -468,23 +468,24 @@ int db_subscriber_alloc_exten(struct gsm_subscriber* subscriber) {
* an error. * an error.
*/ */
int db_subscriber_alloc_token(struct gsm_subscriber* subscriber, u_int32_t* token) { int db_subscriber_alloc_token(struct gsm_subscriber* subscriber, u_int32_t* token)
dbi_result result=NULL; {
dbi_result result;
u_int32_t try; u_int32_t try;
for (;;) { for (;;) {
try = rand(); try = rand();
if (!try) /* 0 is an invalid token */ if (!try) /* 0 is an invalid token */
continue; continue;
result = dbi_conn_queryf(conn, result = dbi_conn_queryf(conn,
"SELECT * FROM AuthToken " "SELECT * FROM AuthToken "
"WHERE subscriber_id = %llu OR token = %08x ", "WHERE subscriber_id = %llu OR token = \"%08X\" ",
subscriber->id, try subscriber->id, try);
); if (!result) {
if (result==NULL) {
printf("DB: Failed to query AuthToken while allocating new token.\n"); printf("DB: Failed to query AuthToken while allocating new token.\n");
return 1; return 1;
} }
if (dbi_result_get_numrows(result)){ if (dbi_result_get_numrows(result)) {
dbi_result_free(result); dbi_result_free(result);
continue; continue;
} }
@ -498,15 +499,16 @@ int db_subscriber_alloc_token(struct gsm_subscriber* subscriber, u_int32_t* toke
"INSERT INTO AuthToken " "INSERT INTO AuthToken "
"(subscriber_id, created, token) " "(subscriber_id, created, token) "
"VALUES " "VALUES "
"(%llu, datetime('now'), %08x)) ", "(%llu, datetime('now'), \"%08X\") ",
subscriber->id, try subscriber->id, try);
); if (!result) {
if (result==NULL) { printf("DB: Failed to create token %08X for IMSI %s.\n", try, subscriber->imsi);
printf("DB: Failed to create token %08x for IMSI %s.\n", try, subscriber->imsi);
return 1; return 1;
} }
dbi_result_free(result);
*token = try; *token = try;
printf("DB: Allocated token %08x for IMSI %s.\n", try, subscriber->imsi); printf("DB: Allocated token %08X for IMSI %s.\n", try, subscriber->imsi);
return 0; return 0;
} }