* "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
* };
* };
*
#include "modcmd.h"
#include "saxdb.h"
#include "timeq.h"
-#include "gline.h"
#define KEY_TOPLEVEL "TopLevel"
#define KEY_SECONDLEVEL "SecondLevel"
#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:" },
{ "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 }
}
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);
}
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;
}
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;
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;
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;
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, '.');
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;
}
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;