fixed #0000071 (first assignment always got active on reload)
authorpk910 <philipp@zoelle1.de>
Sun, 6 Jan 2013 23:41:48 +0000 (00:41 +0100)
committerpk910 <philipp@zoelle1.de>
Sun, 6 Jan 2013 23:41:48 +0000 (00:41 +0100)
src/mod-hostserv.c

index 8e1ee36e3b08cc4c122078d7e541a85721aca1cd..b865afc52d746851c6b375ed8d25a3c4f9827b44 100644 (file)
 #define KEY_ASSIGNMENTS "Assignments"
 #define KEY_ACTIVE "active"
 
+#define HS_ASSIGNMENTSTATE_AUTO -1
+#define HS_ASSIGNMENTSTATE_OFF  0
+#define HS_ASSIGNMENTSTATE_ON   1
+
 static const struct message_entry msgtab[] = {
     { "HSMSG_ACCESS_DENIED", "Access denied." },
     { "HSMSG_ASSIGNED_FAKEHOSTS", "Assigned Fakehosts for User $b%s$b:" },
@@ -362,12 +366,14 @@ static void hs_activate_assignment(struct hs_user *user, struct hs_assignment *a
     apply_fakehost(user->hi, NULL);
 }
 
-static struct hs_assignment *hs_add_assignment(struct hs_secondlevel *slfh, struct hs_user *user) {
+static struct hs_assignment *hs_add_assignment(struct hs_secondlevel *slfh, struct hs_user *user, int active) {
     struct hs_assignment *assignment = calloc(1, sizeof(*assignment));
     assignment->secondlevel = slfh;
     assignment->user = user;
-    if(user->assignments == NULL)
-        assignment->active = 1;
+    if(active == HS_ASSIGNMENTSTATE_AUTO)
+        assignment->active = (user->assignments == NULL ? 1 : 0);
+    else
+        assignment->active = (active == HS_ASSIGNMENTSTATE_ON ? 1 : 0);
     assignment->next = slfh->assignments;
     slfh->assignments = assignment;
     assignment->unext = user->assignments;
@@ -1038,7 +1044,7 @@ static MODCMD_FUNC(cmd_assign) {
                         reply("HSMSG_FAKEHOST_ASSIGNED", slfh_name, tlfh_name);
                         return 0;
                     }
-                    hs_add_assignment(slfh, hs_user);
+                    hs_add_assignment(slfh, hs_user, HS_ASSIGNMENTSTATE_AUTO);
                     reply("HSMSG_FAKEHOST_ASSIGN_SUCCESS", slfh_name, tlfh_name);
                     return 1;
                 }
@@ -1209,18 +1215,15 @@ static int hostserv_saxdb_read_assignments(const char *name, void *data, UNUSED_
     struct record_data *rd = data;
     struct hs_secondlevel *slfh = extra;
     struct hs_user *user;
-    struct hs_assignment *assng;
+    int active;
     
     if (rd->type == RECDB_OBJECT) {
         dict_t db = GET_RECORD_OBJECT(rd);
         
         user = hs_get_user(get_handle_info(name), 1);
-        assng = hs_add_assignment(slfh, user);
+        active = (database_get_data(db, KEY_ACTIVE, RECDB_QSTRING) ? HS_ASSIGNMENTSTATE_ON : HS_ASSIGNMENTSTATE_OFF);
         
-        if (database_get_data(db, KEY_ACTIVE, RECDB_QSTRING))
-            assng->active = 1;
-        else
-            assng->active = 0;
+        hs_add_assignment(slfh, user, active);
     }
     
     return 0;