diff options
Diffstat (limited to 'database/sqlite/administration.c')
| -rw-r--r-- | database/sqlite/administration.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/database/sqlite/administration.c b/database/sqlite/administration.c index ee4f132..3cdf76b 100644 --- a/database/sqlite/administration.c +++ b/database/sqlite/administration.c @@ -689,7 +689,8 @@ xmlDoc *eDBadminGetUserInfo(eurephiaCTX *ctx, int getInfo, xmlDoc *srch) { // This function will add a user to the openvpn_users table, based on the -// XML document given. +// XML document given. The function returns the UID of the new user. On +// failure, the function returns -1 // // XML format: // <eurephia format="1"> @@ -705,7 +706,7 @@ int eDBadminAddUser(eurephiaCTX *ctx, xmlDoc *usrinf) { dbresult *res = NULL; xmlNode *usrinf_n = NULL; eDBfieldMap *usrinf_map = NULL; - int rc = 0; + int uid = 0; assert( (ctx != NULL) && (usrinf != NULL) ); @@ -729,14 +730,14 @@ int eDBadminAddUser(eurephiaCTX *ctx, xmlDoc *usrinf) { res = sqlite_query_mapped(ctx, SQL_INSERT, "INSERT INTO openvpn_users", usrinf_map, NULL, NULL); if( res == NULL ) { eurephia_log(ctx, LOG_FATAL, 0, "Could not register the new user account"); - rc = 0; + uid = -1; } else { - rc = 1; + uid = res->last_insert_id; } sqlite_free_results(res); eDBfreeMapping(usrinf_map); - return rc; + return uid; } @@ -963,11 +964,13 @@ xmlDoc *eDBadminGetCertificateInfo(eurephiaCTX *ctx, xmlDoc *srchxml, const char // </register_certificate> // </eurephia> // +// The function returns certid of the newly registered certificate on success, +// and -1 on failure int eDBadminAddCertificate(eurephiaCTX *ctx, xmlDoc *certxml) { - int rc = 0; xmlNode *crtinf_n = NULL; eDBfieldMap *crtinf_map = NULL, *ptr = NULL; dbresult *res = NULL; + int certid = 0; assert( (ctx != NULL) && (certxml != NULL) ); @@ -998,14 +1001,14 @@ int eDBadminAddCertificate(eurephiaCTX *ctx, xmlDoc *certxml) { res = sqlite_query_mapped(ctx, SQL_INSERT, "INSERT INTO openvpn_certificates", crtinf_map, NULL, NULL); if( res == NULL ) { eurephia_log(ctx, LOG_FATAL, 0, "Could not register the certificate"); - rc = 0; + certid = -1; } else { - rc = 1; + certid = res->last_insert_id; } sqlite_free_results(res); eDBfreeMapping(crtinf_map); - return rc; + return certid; } |
