+static MODCMD_FUNC(cmd_oset) {
+ struct handle_info *hi;
+ char *fakehost;
+ struct hs_assignment *assignment;
+ if(!strchr(argv[1], '.') && strcmp(argv[1], "*")) {
+ if (!(hi = modcmd_get_handle_info(user, argv[1])))
+ return 0;
+ fakehost = argv[2];
+ } else {
+ if (!(hi = modcmd_get_handle_info(user, argv[2])))
+ return 0;
+ fakehost = argv[1];
+ }
+ if (!user->handle_info) {
+ reply("NSMSG_MUST_AUTH");
+ return 0;
+ }
+ struct hs_user *hs_user = hs_get_user(hi, 1);
+ for(assignment = hs_user->assignments; assignment; assignment = assignment->unext) {
+ if(assignment->active)
+ break;
+ }
+ if(assignment && !check_management_access(user->handle_info, (hostserv_conf.manager_toplevel_can_oset ? assignment->secondlevel->toplevel : NULL), (hostserv_conf.manager_secondlevel_can_oset ? assignment->secondlevel : NULL))) {
+ reply("HSMSG_ACCESS_DENIED");
+ return 0;
+ }
+ if(!strcmp(fakehost, "*")) {
+ if(!assignment)
+ return 0; //simply ignore (there is no assignment in use)
+ hs_activate_assignment(hs_user, NULL);
+ return 1;
+ } else {
+ struct hs_fakehost_info fhinfo = parse_fakehost_info(fakehost, 1);
+ if(fhinfo.parse_state == HS_FHPARSE_INVALID) {
+ reply("HSMSG_TOPLEVEL_INVALID", fakehost);
+ return 0;
+ } else if(fhinfo.parse_state == HS_FHPARSE_UNKNOWN || !fhinfo.slfh) {
+ reply("HSMSG_UNKNOWN_FAKEHOST", fhinfo.slfh_name, fhinfo.tlfh_name);
+ return 0;
+ }
+ if(!check_management_access(user->handle_info, (hostserv_conf.manager_toplevel_can_oset ? fhinfo.tlfh : NULL), (hostserv_conf.manager_secondlevel_can_oset ? fhinfo.slfh : NULL))) {
+ reply("HSMSG_ACCESS_DENIED");
+ return 0;
+ }
+ struct hs_toplevel *tlfh;
+ struct hs_secondlevel *slfh;
+ for(assignment = hs_user->assignments; assignment; assignment = assignment->unext) {
+ slfh = assignment->secondlevel;
+ tlfh = slfh->toplevel;
+ if(tlfh == fhinfo.tlfh && slfh == fhinfo.slfh) {
+ hs_activate_assignment(hs_user, assignment);
+ reply("HSMSG_FAKEHOST_SET_SUCCESS", slfh->fakehost, tlfh->fakehost);
+ return 1;
+ }
+ }
+ reply("HSMSG_UNKNOWN_FAKEHOST", fhinfo.slfh_name, fhinfo.tlfh_name);
+ return 0;
+ }
+}
+
+static MODCMD_FUNC(cmd_setdevnull) {
+ 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;
+ }
+ if(!fhinfo.have_secondlevel) {
+ reply("HSMSG_FAKEHOST_TLDEVNULL");
+ return 0;
+ } else {
+ if(!fhinfo.tlfh) {
+ reply("HSMSG_UNKNOWN_FAKEHOST", fhinfo.slfh_name, fhinfo.tlfh_name);
+ return 0;
+ }
+ if(!check_management_access(hi, NULL, NULL)) {
+ reply("HSMSG_ACCESS_DENIED");
+ return 0;
+ }
+ char *fakehost_name;
+ if(!strcmp(argv[2], "*")) {
+ fhinfo.slfh->devnull_id = 0;
+ fakehost_name = "-";
+ } else {
+ struct devnull_class *th = devnull_find_name(argv[2]);
+ if(!th) {
+ reply("OSMSG_DEVNULL_NOTFOUND", argv[2]);
+ return 0;
+ }
+ fhinfo.slfh->devnull_id = th->id;
+ fakehost_name = th->name;
+ }
+ reply("HSMSG_DEVNULL_CLASS", fhinfo.slfh_name, fhinfo.tlfh_name, fakehost_name);
+ }
+ return 1;
+}
+
+
+struct devnull_class hostserv_get_user_priv(struct handle_info *hi) {
+ struct devnull_class th;
+ memset(&th, 0, sizeof(th));
+
+ struct hs_user *huser = hs_get_user(hi, 0);
+ if(huser) {
+ struct devnull_class *devc;
+ if(hi->devnull_id != 0) {
+ devc = devnull_find_id(huser->hi->devnull_id);
+ if(devc) {
+ if(DEVNULL_HAS_PRIV(devc, CHANLIMIT) && (!DEVNULL_HAS_PRIV(&th, CHANLIMIT) || th.maxchan < devc->maxchan))
+ th.maxchan = devc->maxchan;
+ if(DEVNULL_HAS_PRIV(devc, MAXSENDQ) && (!DEVNULL_HAS_PRIV(&th, MAXSENDQ) || th.maxsendq < devc->maxsendq))
+ th.maxsendq = devc->maxsendq;
+ th.modes |= devc->modes;
+ if(!th.name)
+ th.name = devc->name;
+ }
+ } else {
+ struct hs_assignment *assignment;
+ struct hs_secondlevel *slfh;
+ for(assignment = huser->assignments; assignment; assignment = assignment->unext) {
+ slfh = assignment->secondlevel;
+ if(slfh->devnull_id) {
+ devc = devnull_find_id(slfh->devnull_id);
+ if(!devc) {
+ slfh->devnull_id = 0;
+ continue;
+ }
+ if(DEVNULL_HAS_PRIV(devc, CHANLIMIT) && (!DEVNULL_HAS_PRIV(&th, CHANLIMIT) || th.maxchan < devc->maxchan))
+ th.maxchan = devc->maxchan;
+ if(DEVNULL_HAS_PRIV(devc, MAXSENDQ) && (!DEVNULL_HAS_PRIV(&th, MAXSENDQ) || th.maxsendq < devc->maxsendq))
+ th.maxsendq = devc->maxsendq;
+ th.modes |= devc->modes;
+ if(!th.name)
+ th.name = devc->name;
+ }
+ }
+ }
+ }
+ return th;
+}
+