diff options
author | Harald Welte (local) <laflocal@hanuman.gnumonks.org> | 2009-08-13 13:26:11 +0200 |
---|---|---|
committer | Harald Welte (local) <laflocal@hanuman.gnumonks.org> | 2009-08-13 13:26:11 +0200 |
commit | 3feef255d256f689fa9227ca12f0be0b17cabe89 (patch) | |
tree | db55386cc74ff77cdd01baf65d957b0750be8172 | |
parent | 571602f43cf59d9d46d9643319aafbf074731e64 (diff) |
fix token allocation sql strings
-rw-r--r-- | openbsc/src/db.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/openbsc/src/db.c b/openbsc/src/db.c index 938c5c440..0704bca2b 100644 --- a/openbsc/src/db.c +++ b/openbsc/src/db.c @@ -468,23 +468,24 @@ int db_subscriber_alloc_exten(struct gsm_subscriber* subscriber) { * an error. */ -int db_subscriber_alloc_token(struct gsm_subscriber* subscriber, u_int32_t* token) { - dbi_result result=NULL; +int db_subscriber_alloc_token(struct gsm_subscriber* subscriber, u_int32_t* token) +{ + dbi_result result; u_int32_t try; + for (;;) { try = rand(); if (!try) /* 0 is an invalid token */ continue; result = dbi_conn_queryf(conn, "SELECT * FROM AuthToken " - "WHERE subscriber_id = %llu OR token = %08x ", - subscriber->id, try - ); - if (result==NULL) { + "WHERE subscriber_id = %llu OR token = \"%08X\" ", + subscriber->id, try); + if (!result) { printf("DB: Failed to query AuthToken while allocating new token.\n"); return 1; } - if (dbi_result_get_numrows(result)){ + if (dbi_result_get_numrows(result)) { dbi_result_free(result); continue; } @@ -498,15 +499,16 @@ int db_subscriber_alloc_token(struct gsm_subscriber* subscriber, u_int32_t* toke "INSERT INTO AuthToken " "(subscriber_id, created, token) " "VALUES " - "(%llu, datetime('now'), %08x)) ", - subscriber->id, try - ); - if (result==NULL) { - printf("DB: Failed to create token %08x for IMSI %s.\n", try, subscriber->imsi); + "(%llu, datetime('now'), \"%08X\") ", + subscriber->id, try); + if (!result) { + printf("DB: Failed to create token %08X for IMSI %s.\n", try, subscriber->imsi); return 1; } + dbi_result_free(result); *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; } |