+static MODCMD_FUNC(cmd_delhost) {
+ struct handle_info *hi;
+ if (!(hi = user->handle_info)) {
+ reply("NSMSG_MUST_AUTH");
+ return 0;
+ }
+ struct hs_fakehost_info fhinfo = parse_fakehost_info(argv[1], 1);
+ if(fhinfo.parse_state == HS_FHPARSE_INVALID) {
+ reply("HSMSG_TOPLEVEL_INVALID", argv[1]);
+ return 0;
+ } else if(fhinfo.parse_state == HS_FHPARSE_UNKNOWN) {
+ reply("HSMSG_UNKNOWN_FAKEHOST", fhinfo.slfh_name, fhinfo.tlfh_name);
+ return 0;
+ }
+ if(!fhinfo.slfh) {
+ if(!check_management_access(hi, (hostserv_conf.manager_can_del_toplevel ? fhinfo.tlfh : NULL), NULL)) { /* manager access is enough to delete whole toplevel? */
+ reply("HSMSG_ACCESS_DENIED");
+ return 0;
+ }
+ hs_del_toplevel(fhinfo.tlfh);
+ reply("HSMSG_FAKEHOST_TOPLEVEL_DELETED", fhinfo.tlfh_name);
+ } else {
+ if(!check_management_access(hi, fhinfo.tlfh, (hostserv_conf.manager_can_del_secondlevel ? fhinfo.slfh : NULL))) {
+ reply("HSMSG_ACCESS_DENIED");
+ return 0;
+ }
+ hs_del_secondlevel(fhinfo.slfh, 1);
+ reply("HSMSG_FAKEHOST_SECONDLEVEL_DELETED", fhinfo.slfh_name, fhinfo.tlfh_name);
+ }
+ return 1;
+}
+
+static MODCMD_FUNC(cmd_renamehost) {
+ struct handle_info *hi;
+ if (!(hi = user->handle_info)) {
+ reply("NSMSG_MUST_AUTH");
+ return 0;
+ }
+ //old fakehost name
+ struct hs_fakehost_info fhinfo = parse_fakehost_info(argv[1], 1);
+ if(fhinfo.parse_state == HS_FHPARSE_INVALID) {
+ reply("HSMSG_TOPLEVEL_INVALID", argv[1]);
+ return 0;
+ } else if(fhinfo.parse_state == HS_FHPARSE_UNKNOWN) {
+ reply("HSMSG_UNKNOWN_FAKEHOST", fhinfo.slfh_name, fhinfo.tlfh_name);
+ return 0;
+ }
+ //new fakehost name
+ struct hs_fakehost_info new_fhinfo = parse_fakehost_info(argv[2], 0);
+ if(new_fhinfo.parse_state == HS_FHPARSE_INVALID) {
+ reply("HSMSG_TOPLEVEL_INVALID", argv[1]);
+ return 0;
+ } else if(new_fhinfo.parse_state != HS_FHPARSE_UNKNOWN && (irccasecmp(fhinfo.tlfh_name, new_fhinfo.tlfh_name) || (new_fhinfo.slfh && irccasecmp(fhinfo.slfh_name, new_fhinfo.slfh_name)))) {
+ reply("HSMSG_FAKEHOST_TOPLEVEL_ALREADY_EXISTS", new_fhinfo.slfh_name, new_fhinfo.tlfh_name);
+ return 0;
+ }
+
+ if(!fhinfo.slfh) {
+ if(!check_management_access(hi, (hostserv_conf.manager_can_rename_toplevel ? fhinfo.tlfh : NULL), NULL)) { /* manager access is enough to delete whole toplevel? */
+ reply("HSMSG_ACCESS_DENIED");
+ return 0;
+ }
+ if(fhinfo.have_secondlevel) {
+ //can't rename toplevel into secondlevel fakehost!
+ new_fhinfo.tlfh_name--;
+ new_fhinfo.tlfh_name[0] = '.';
+ reply("HSMSG_TOPLEVEL_INVALID", new_fhinfo.slfh_name);
+ return 0;
+ }
+ if(strcmp(new_fhinfo.tlfh_name, fhinfo.tlfh->fakehost))
+ hs_rename_toplevel(fhinfo.tlfh, new_fhinfo.tlfh_name);
+ reply("HSMSG_FAKEHOST_RENAMED", fhinfo.slfh_name, fhinfo.tlfh_name, new_fhinfo.slfh_name, new_fhinfo.tlfh_name);
+ } else {
+ if(!check_management_access(hi, fhinfo.tlfh, (hostserv_conf.manager_can_rename_secondlevel ? fhinfo.slfh : NULL))) {
+ reply("HSMSG_ACCESS_DENIED");
+ return 0;
+ }
+ if(irccasecmp(new_fhinfo.tlfh_name, fhinfo.tlfh_name)) {
+ //can't rename toplevel and secondlevel fakehost with one command!
+ new_fhinfo.tlfh_name--;
+ new_fhinfo.tlfh_name[0] = '.';
+ reply("HSMSG_TOPLEVEL_INVALID", new_fhinfo.slfh_name);
+ return 0;
+ }
+ if(strcmp(new_fhinfo.slfh_name, fhinfo.slfh->fakehost))
+ hs_rename_secondlevel(fhinfo.slfh, new_fhinfo.slfh_name);
+ reply("HSMSG_FAKEHOST_RENAMED", fhinfo.slfh_name, fhinfo.tlfh_name, new_fhinfo.slfh_name, new_fhinfo.tlfh_name);
+ }
+ return 1;
+}
+
+static MODCMD_FUNC(cmd_addmanager) {