From 9df739a7f0fc2c99a680b2e63475d63128f2ea33 Mon Sep 17 00:00:00 2001 From: pk910 Date: Mon, 7 Jan 2013 00:41:48 +0100 Subject: [PATCH] fixed #0000071 (first assignment always got active on reload) --- src/mod-hostserv.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/mod-hostserv.c b/src/mod-hostserv.c index 8e1ee36..b865afc 100644 --- a/src/mod-hostserv.c +++ b/src/mod-hostserv.c @@ -49,6 +49,10 @@ #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; -- 2.20.1