X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2Fmod-hostserv.c;h=b865afc52d746851c6b375ed8d25a3c4f9827b44;hb=9df739a7f0fc2c99a680b2e63475d63128f2ea33;hp=152eed0fb7333f055eec973140bdf3be2e3b7537;hpb=e7ce029daa935d256520e1a193e4ea4f87d8cad1;p=srvx.git diff --git a/src/mod-hostserv.c b/src/mod-hostserv.c index 152eed0..b865afc 100644 --- a/src/mod-hostserv.c +++ b/src/mod-hostserv.c @@ -23,7 +23,10 @@ * "hostserv" { * "nick" "HostServ"; * "modes" "+iok"; - "toplevel_access" "600"; + * "toplevel_access" "600"; + * "fallback_other_assignment" "1"; //fall back to another assignment when active assignment gets removed + * "manager_can_del_toplevel" "0"; //managers of a toplevel group may delete the whole group + * "manager_can_del_secondlevel" "0"; //managers of a secondlevel group may delete the whole group * }; * }; * @@ -39,7 +42,6 @@ #include "modcmd.h" #include "saxdb.h" #include "timeq.h" -#include "gline.h" #define KEY_TOPLEVEL "TopLevel" #define KEY_SECONDLEVEL "SecondLevel" @@ -47,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:" }, @@ -82,6 +88,7 @@ static const struct message_entry msgtab[] = { { "HSMSG_MANAGER_NOT", "$b%s$b is not a manager of %s.%s" }, { "HSMSG_MANAGER_DELETED", "$b%s$b is no longer a manager of %s.%s" }, { "HSMSG_FAKEHOST_ASSIGN_SUCCESS", "Group $b%s.%s$b was assigned successfully." }, + { "HSMSG_FAKEHOST_ASSIGNED", "Group $b%s.%s$b is already assigned to the user." }, { "HSMSG_FAKEHOST_UNASSIGN_SUCCESS", "Group $b%s.%s$b was unassigned successfully." }, { NULL, NULL } @@ -165,7 +172,7 @@ static void hs_free_all() { } for(slfh = tlfh->secondlevel; slfh; slfh = next_slfh) { next_slfh = slfh->next; - for(manager = tlfh->managers; manager; manager = next_manager) { + for(manager = slfh->managers; manager; manager = next_manager) { next_manager = manager->next; free(manager); } @@ -339,7 +346,7 @@ static void hs_activate_assignment(struct hs_user *user, struct hs_assignment *a assert((!assignment || (assignment->user == user))); if(user->assignments) { - for(assgn = assignment->user->assignments; assgn; assgn = assgn->unext) + for(assgn = user->assignments; assgn; assgn = assgn->unext) assgn->active = 0; } @@ -356,15 +363,17 @@ static void hs_activate_assignment(struct hs_user *user, struct hs_assignment *a assignment->active = 1; } - apply_fakehost(assignment->user->hi, NULL); + 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; @@ -707,7 +716,7 @@ static MODCMD_FUNC(cmd_addhost) { if(!irccasecmp(slfh_name, "*")) { if(!check_management_access(hi, NULL, NULL)) { reply("HSMSG_ACCESS_DENIED"); - return NULL; + return 0; } for(tlfh = toplevels; tlfh; tlfh = tlfh->next) { if(!irccasecmp(tlfh->fakehost, tlfh_name)) break; @@ -951,7 +960,6 @@ static MODCMD_FUNC(cmd_set) { struct handle_info *hi; struct hs_user *hs_user; struct hs_assignment *assignment; - struct hs_assignment *assgn; struct hs_toplevel *tlfh; struct hs_secondlevel *slfh; char *fakehost; @@ -967,9 +975,6 @@ static MODCMD_FUNC(cmd_set) { hs_activate_assignment(hs_user, NULL); return 1; } else { - if(!strchr(argv[1], '.')) { - - } fakehost = argv[1]; char *slfh_name = fakehost; char *tlfh_name = strchr(fakehost, '.'); @@ -1035,7 +1040,11 @@ static MODCMD_FUNC(cmd_assign) { reply("HSMSG_ACCESS_DENIED"); return 0; } - hs_add_assignment(slfh, hs_user); + if(hs_get_assignment(slfh, hs_user)) { + reply("HSMSG_FAKEHOST_ASSIGNED", slfh_name, tlfh_name); + return 0; + } + hs_add_assignment(slfh, hs_user, HS_ASSIGNMENTSTATE_AUTO); reply("HSMSG_FAKEHOST_ASSIGN_SUCCESS", slfh_name, tlfh_name); return 1; } @@ -1206,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;