summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2009-09-27 16:07:43 +0200
committerDavid Sommerseth <dazo@users.sourceforge.net>2009-09-27 16:07:43 +0200
commit82c1708bd650602d892112c5846e685be94e8a46 (patch)
treecae2ce0eede3891bd4b4b7961ecb884131f39b11 /utils
parent9084528b2a0ca002fbd26663960e2a6006d40553 (diff)
downloadeurephia-82c1708bd650602d892112c5846e685be94e8a46.tar.gz
eurephia-82c1708bd650602d892112c5846e685be94e8a46.tar.xz
eurephia-82c1708bd650602d892112c5846e685be94e8a46.zip
Reworked eurephia_init to use the new eDBadminUserAccount() API
Diffstat (limited to 'utils')
-rw-r--r--utils/eurephia_init.c80
1 files changed, 66 insertions, 14 deletions
diff --git a/utils/eurephia_init.c b/utils/eurephia_init.c
index e0f998d..9eded5d 100644
--- a/utils/eurephia_init.c
+++ b/utils/eurephia_init.c
@@ -209,7 +209,7 @@ static int config_set(eurephiaCTX *ctx, const char *key, const char *val) {
* @return Returns 1 on success, otherwise 0.
*/
int setup_admin_account(eurephiaCTX *ctx) {
- xmlDoc *xmldoc = NULL;
+ xmlDoc *xmldoc = NULL, *resxml = NULL;
xmlNode *node = NULL, *node2 = NULL;
int uid = 0, i;
char uname[66], pwd1[66], pwd2[66];
@@ -219,15 +219,24 @@ int setup_admin_account(eurephiaCTX *ctx) {
printf("------------------------------------------------------------------------------\n\n");
printf("Checking database for user accounts ... ");
- xmldoc = eDBadminGetUserList(ctx, NULL);
- node = eurephiaXML_getRoot(ctx, xmldoc, "userlist", 1);
+ eurephiaXML_CreateDoc(ctx, 1, "UserAccount", &xmldoc, &node);
+ assert( (xmldoc != NULL) && (node != NULL) );
+ xmlNewProp(node, (xmlChar *) "mode", (xmlChar *) "view");
+
+ node = xmlNewChild(node, NULL, (xmlChar *) "fieldMapping", NULL);
+ assert( node != NULL );
+ xmlNewProp(node, (xmlChar *) "table", (xmlChar *) "users");
+
+ resxml = eDBadminUserAccount(ctx, xmldoc);
+ node = eurephiaXML_getRoot(ctx, resxml, "UserAccount", 1);
if( node == NULL ) {
fprintf(stderr, "Could not retrieve valid data\n");
xmlFreeDoc(xmldoc);
return 0;
}
- if( node->children != NULL ) {
+ node = xmlFindNode(node, "Account");
+ if( (node != NULL) ) {
printf("User accounts found, aborting. eurephia is already initialised\n");
xmlFreeDoc(xmldoc);
return 0;
@@ -252,7 +261,8 @@ int setup_admin_account(eurephiaCTX *ctx) {
}
memset(pwd2, 0, 66);
- eurephiaXML_CreateDoc(ctx, 1, "add_user", &xmldoc, &node);
+ eurephiaXML_CreateDoc(ctx, 1, "UserAccount", &xmldoc, &node);
+ xmlNewProp(node, (xmlChar *) "mode", (xmlChar *) "add");
node = xmlNewChild(node, NULL, (xmlChar *) "fieldMapping", NULL);
xmlNewProp(node, (xmlChar *) "table", (xmlChar *) "users");
@@ -261,18 +271,40 @@ int setup_admin_account(eurephiaCTX *ctx) {
xmlNewProp(node2, (xmlChar *) "pwhash", (xmlChar *) "none");
// Add the user
- uid = eDBadminAddUser(ctx, xmldoc);
+ resxml = eDBadminUserAccount(ctx, xmldoc);
memset(pwd1, 0, 66);
+ xmlFreeDoc(xmldoc);
- if( uid > 0 ) {
- fprintf(stdout, "Admin user account registered successfully (user id %i)\n", uid);
- } else {
+ if( !eurephiaXML_IsResultMsg(ctx, resxml) ) {
fprintf(stderr, "Failed to register user\n");
- xmlFreeDoc(xmldoc);
+ if( resxml ) {
+ xmlFreeDoc(resxml);
+ }
return 0;
- }
- xmlFreeDoc(xmldoc);
+ } else {
+ eurephiaRESULT *res = NULL;
+ res = eurephiaXML_ParseResultMsg(ctx, resxml);
+ switch( res->resultType ) {
+ case exmlERROR:
+ fprintf(stderr, "** ERROR ** %s\n", res->message);
+ uid = 0;
+ break;
+
+ case exmlRESULT:
+ fprintf(stdout, "%s\n", res->message);
+ node = xmlFindNode(res->details, "UserAccount");
+ uid = atoi_nullsafe(xmlGetAttrValue(node->properties, "uid"));
+ break;
+ }
+ xmlFreeDoc(resxml);
+ free_nullsafe(ctx, res);
+
+ if( uid < 1 ) {
+ fprintf(stderr, "Failed to register user\n");
+ return 0;
+ }
+ }
// Grant all available access levels to the admin account
static char *grants[] = { "config", "useradmin", "certadmin", "fwprofiles",
@@ -312,7 +344,8 @@ int setup_admin_account(eurephiaCTX *ctx) {
// Activate the user account
printf("Activating the user account ... ");
- eurephiaXML_CreateDoc(ctx, 1, "update_user", &xmldoc, &node);
+ eurephiaXML_CreateDoc(ctx, 1, "UserAccount", &xmldoc, &node);
+ xmlNewProp(node, (xmlChar *) "mode", (xmlChar *) "update");
xmlNewProp(node, (xmlChar *) "uid", (xmlChar *) uname); // uid should still be in uname as string
// Add fieldMapping - to correctly map eurephia fields into the database fields
@@ -320,11 +353,30 @@ int setup_admin_account(eurephiaCTX *ctx) {
xmlNewProp(node2, (xmlChar *) "table", (xmlChar *) "users");
xmlNewChild(node2, NULL, (xmlChar *) "activated", (xmlChar *) "CURRENT_TIMESTAMP");
- if( !eDBadminUpdateUser(ctx, uid, xmldoc) ) {
+ resxml = eDBadminUserAccount(ctx, xmldoc);
+ if( !eurephiaXML_IsResultMsg(ctx, resxml) ) {
printf("FAILED\n");
xmlFreeDoc(xmldoc);
+ xmlFreeDoc(resxml);
return 0;
+ } else {
+ eurephiaRESULT *res = NULL;
+
+ res = eurephiaXML_ParseResultMsg(ctx, resxml);
+ switch( res->resultType ) {
+ case exmlERROR:
+ fprintf(stderr, "** ERROR ** %s\n", res->message);
+ break;
+
+ case exmlRESULT:
+ break;
+ }
+ xmlFreeDoc(resxml);
+ free_nullsafe(ctx, res);
}
+
+
+
printf("Done");
xmlFreeDoc(xmldoc);