/** * Save all our data to our db file * @return 0 for success **/ int mSaveData(int argc, char **argv) { NickCore *nc = NULL; int i = 0; int ret = 0; FILE *out; FILE *xmlout; char *data; if (argc >= 1) { if (!stricmp(argv[0], EVENT_START)) { /* Regular Database */ if ((out = fopen(qdbBanDBName, "w")) == NULL) { alog("ns_qdbban: ERROR: can not open the regular database file!"); anope_cmd_global(s_OperServ, "ns_qdbban: ERROR: can not open the regular database file!"); ret = 1; } else { /* XML Database */ if ((xmlout = fopen(qdbBanXMLDBName, "w")) == NULL) { alog("ns_qdbban: ERROR: can not open the XML database file!"); anope_cmd_global(s_OperServ, "ns_qdbban.c: ERROR: can not open the XML database file!"); ret = 1; } else { fprintf(xmlout, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"no\" ?>\n"); fprintf(xmlout, "<qdbbanlist>\n"); for (i = 0; i < 1024; i++) { for (nc = nclists[i]; nc; nc = nc->next) { /* If we have any info on this user */ if ((data = moduleGetData(&nc->moduleData, "qdbban"))) { fprintf(out, "%s\n", nc->display); fprintf(xmlout, "\t<qdbban>\n"); char *nickEnt = html_entities(nc->display); fprintf(xmlout, "\t\t<nick>%s</nick>\n", nickEnt); fprintf(xmlout, "\t</qdbban>\n"); free(nickEnt); free(data); } } } fprintf(xmlout, "</qdbbanlist>\n"); fclose(out); fclose(xmlout); } } } else { ret = 0; } } return ret; }
static int do_qakill_some_lameass(User * u) { char *to_be_akilled, *reason; char reasonx[512]; char mask[USERMAX + HOSTMAX + 2]; User *target; to_be_akilled = strtok(NULL, " "); reason = strtok(NULL, ""); if (!is_services_admin(u)) { notice(s_OperServ, u->nick, "Access Denied"); return MOD_STOP; } if (to_be_akilled) { if (!reason) { reason = "You have been AKILLED"; } if (AddAkiller) { snprintf(reasonx, sizeof(reasonx), "[%s] %s", u->nick, reason); } if ((target = finduser(to_be_akilled))) { sprintf(mask, "*@%s", target->host); #ifdef DISABLE_LOWER_QAKILL if ((is_services_admin(target)) && (!is_services_root(u))) { notice(s_OperServ, u->nick, "Permission Denied"); #ifndef ANOPE17x wallops(s_OperServ, "%s attempted to QAKILL %s (%s)", u->nick, target->nick, reasonx); #else anope_cmd_global(s_OperServ, "%s attempted to QAKILL %s (%s)", u->nick, target->nick, reasonx); #endif return MOD_STOP; } #endif add_akill(u, mask, u->nick, time(NULL)+AutokillExpiry, reason); if (WallOSAkill) { #ifndef ANOPE17x wallops(s_OperServ, "%s used QAKILL on %s (%s)", u->nick, target->nick, reasonx); #else anope_cmd_global(s_OperServ, "%s used QAKILL on %s (%s)", u->nick, target->nick, reasonx); #endif } if (!AkillOnAdd) { kill_user(s_OperServ, target->nick, reasonx); } } else { notice_lang(s_OperServ, u, NICK_X_NOT_IN_USE, to_be_akilled); } } else { notice(s_OperServ, u->nick, "See /msg OperServ HELP QAKILL for more info."); } return MOD_CONT; }
/** * Automaticaly re-set the DefCon level if the time limit has expired. **/ void resetDefCon(int level) { char strLevel[5]; snprintf(strLevel, 4, "%d", level); if (DefConLevel != level) { if ((DefContimer) && (time(NULL) - DefContimer >= dotime(DefConTimeOut))) { DefConLevel = level; send_event(EVENT_DEFCON_LEVEL, 1, strLevel); alog("Defcon level timeout, returning to lvl %d", level); anope_cmd_global(s_OperServ, getstring2(NULL, OPER_DEFCON_WALL), s_OperServ, level); if (GlobalOnDefcon) { if (DefConOffMessage) { oper_global(NULL, "%s", DefConOffMessage); } else { oper_global(NULL, getstring(NULL, DEFCON_GLOBAL), DefConLevel); } } if (GlobalOnDefconMore && !DefConOffMessage) { oper_global(NULL, "%s", DefconMessage); } runDefCon(); } } }
/** * The /os mode command. * @param u The user who issued the command * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. **/ static int do_os_mode(User * u) { int ac; char **av; char *chan = strtok(NULL, " "), *modes = strtok(NULL, ""); Channel *c; if (!chan || !modes) { syntax_error(s_OperServ, u, "MODE", OPER_MODE_SYNTAX); return MOD_CONT; } if (!(c = findchan(chan))) { notice_lang(s_OperServ, u, CHAN_X_NOT_IN_USE, chan); } else if (c->bouncy_modes) { notice_lang(s_OperServ, u, OPER_BOUNCY_MODES_U_LINE); return MOD_CONT; } else if ((ircd->adminmode) && (!is_services_admin(u)) && (c->mode & ircd->adminmode)) { notice_lang(s_OperServ, u, PERMISSION_DENIED); return MOD_CONT; } else { anope_cmd_mode(s_OperServ, chan, "%s", modes); ac = split_buf(modes, &av, 1); chan_set_modes(s_OperServ, c, ac, av, -1); free(av); if (WallOSMode) anope_cmd_global(s_OperServ, "%s used MODE %s on %s", u->nick, modes, chan); } return MOD_CONT; }
int add_session(char *nick, char *host, char *hostip) { Session *session, **list; Exception *exception; int sessionlimit = 0; session = findsession(host); if (session) { exception = find_hostip_exception(host, hostip); if (checkDefCon(DEFCON_REDUCE_SESSION)) { sessionlimit = exception ? exception->limit : DefConSessionLimit; } else { sessionlimit = exception ? exception->limit : DefSessionLimit; } if (sessionlimit != 0 && session->count >= sessionlimit) { if (SessionLimitExceeded) notice(s_OperServ, nick, SessionLimitExceeded, host); if (SessionLimitDetailsLoc) notice(s_OperServ, nick, "%s", SessionLimitDetailsLoc); /* We don't use kill_user() because a user stucture has not yet * been created. Simply kill the user. -TheShadow */ kill_user(s_OperServ, nick, "Session limit exceeded"); session->hits++; if (MaxSessionKill && session->hits >= MaxSessionKill) { char akillmask[BUFSIZE]; snprintf(akillmask, sizeof(akillmask), "*@%s", host); add_akill(NULL, akillmask, s_OperServ, time(NULL) + SessionAutoKillExpiry, "Session limit exceeded"); anope_cmd_global(s_OperServ, "Added a temporary AKILL for \2%s\2 due to excessive connections", akillmask); } return 0; } else { session->count++; return 1; } } nsessions++; session = scalloc(sizeof(Session), 1); session->host = sstrdup(host); list = &sessionlist[HASH(session->host)]; session->next = *list; if (*list) (*list)->prev = session; *list = session; session->count = 1; return 1; }
static int do_unsuspend(User * u) { ChannelInfo *ci; char *chan = strtok(NULL, " "); /* Assumes that permission checking has already been done. */ if (!chan) { syntax_error(s_ChanServ, u, "UNSUSPEND", CHAN_UNSUSPEND_SYNTAX); return MOD_CONT; } if (chan[0] != '#') { notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_ERROR); return MOD_CONT; } if (readonly) notice_lang(s_ChanServ, u, READ_ONLY_MODE); /* Only UNSUSPEND already suspended channels */ if ((ci = cs_findchan(chan)) == NULL) { notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan); return MOD_CONT; } if (!(ci->flags & CI_SUSPENDED)) { notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_FAILED, chan); return MOD_CONT; } if (ci) { ci->flags &= ~CI_SUSPENDED; if (ci->forbidreason) { free(ci->forbidreason); ci->forbidreason = NULL; } if (ci->forbidby) { free(ci->forbidby); ci->forbidby = NULL; } if (WallForbid) anope_cmd_global(s_ChanServ, "\2%s\2 used UNSUSPEND on channel \2%s\2", u->nick, ci->name); alog("%s: %s set UNSUSPEND for channel %s", s_ChanServ, u->nick, ci->name); notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_SUCCEEDED, chan); send_event(EVENT_CHAN_UNSUSPEND, 1, chan); } else { alog("%s: Valid UNSUSPEND for %s by %s failed", s_ChanServ, chan, u->nick); notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_FAILED, chan); } return MOD_CONT; }
void del_session(const char *host) { Session *session; if (!LimitSessions) { if (debug) { alog("debug: del_session called when LimitSessions is disabled"); } return; } if (!host || !*host) { if (debug) { alog("debug: del_session called with NULL values"); } return; } if (debug >= 2) alog("debug: del_session() called"); session = findsession(host); if (!session) { if (debug) { anope_cmd_global(s_OperServ, "WARNING: Tried to delete non-existant session: \2%s", host); alog("session: Tried to delete non-existant session: %s", host); } return; } if (session->count > 1) { session->count--; return; } if (session->prev) session->prev->next = session->next; else sessionlist[HASH(session->host)] = session->next; if (session->next) session->next->prev = session->prev; if (debug >= 2) alog("debug: del_session(): free session structure"); free(session->host); free(session); nsessions--; if (debug >= 2) alog("debug: del_session() done"); }
/** * The /os oline command. * @param u The user who issued the command * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. **/ int do_operoline(User * u) { char *nick = strtok(NULL, " "); char *flags = strtok(NULL, ""); User *u2 = NULL; /* Only allow this if SuperAdmin is enabled */ if (!u->isSuperAdmin) { notice_lang(s_OperServ, u, OPER_SUPER_ADMIN_ONLY); return MOD_CONT; } if (!nick || !flags) { syntax_error(s_OperServ, u, "OLINE", OPER_OLINE_SYNTAX); return MOD_CONT; } else { /* let's check whether the user is online */ if (!(u2 = finduser(nick))) { notice_lang(s_OperServ, u, NICK_X_NOT_IN_USE, nick); } else if (u2 && flags[0] == '+') { anope_cmd_svso(s_OperServ, nick, flags); anope_cmd_mode(s_OperServ, nick, "+o"); common_svsmode(u2, "+o", NULL); notice_lang(s_OperServ, u2, OPER_OLINE_IRCOP); notice_lang(s_OperServ, u, OPER_OLINE_SUCCESS, flags, nick); anope_cmd_global(s_OperServ, "\2%s\2 used OLINE for %s", u->nick, nick); } else if (u2 && flags[0] == '-') { anope_cmd_svso(s_OperServ, nick, flags); notice_lang(s_OperServ, u, OPER_OLINE_SUCCESS, flags, nick); anope_cmd_global(s_OperServ, "\2%s\2 used OLINE for %s", u->nick, nick); } else syntax_error(s_OperServ, u, "OLINE", OPER_OLINE_SYNTAX); } return MOD_CONT; }
void expire_akills(void) { int i; time_t now = time(NULL); Akill *ak; for (i = akills.count - 1; i >= 0; i--) { ak = akills.list[i]; if (!ak->expires || ak->expires > now) continue; if (WallAkillExpire) anope_cmd_global(s_OperServ, "AKILL on %s@%s has expired", ak->user, ak->host); slist_delete(&akills, i); } }
void expire_szlines(void) { int i; time_t now = time(NULL); SXLine *sx; for (i = szlines.count - 1; i >= 0; i--) { sx = szlines.list[i]; if (!sx->expires || sx->expires > now) continue; if (WallSZLineExpire) anope_cmd_global(s_OperServ, "SZLINE on \2%s\2 has expired", sx->mask); slist_delete(&szlines, i); } }
static int do_saset_password(User * u, NickCore * nc, char *param) { int len = strlen(param); char tmp_pass[PASSMAX]; if (NSSecureAdmins && u->na->nc != nc && nick_is_services_admin(nc) && !is_services_root(u)) { notice_lang(s_NickServ, u, PERMISSION_DENIED); return MOD_CONT; } else if (stricmp(nc->display, param) == 0 || (StrictPasswords && len < 5)) { notice_lang(s_NickServ, u, MORE_OBSCURE_PASSWORD); return MOD_CONT; } else if (enc_encrypt_check_len(len ,PASSMAX - 1)) { notice_lang(s_NickServ, u, PASSWORD_TOO_LONG); return MOD_CONT; } if (enc_encrypt(param, len, nc->pass, PASSMAX - 1) < 0) { memset(param, 0, len); alog("%s: Failed to encrypt password for %s (set)", s_NickServ, nc->display); notice_lang(s_NickServ, u, NICK_SASET_PASSWORD_FAILED, nc->display); return MOD_CONT; } memset(param, 0, len); if(enc_decrypt(nc->pass,tmp_pass,PASSMAX - 1)==1) { notice_lang(s_NickServ, u, NICK_SASET_PASSWORD_CHANGED_TO, nc->display, tmp_pass); } else { notice_lang(s_NickServ, u, NICK_SASET_PASSWORD_CHANGED, nc->display); } alog("%s: %s!%s@%s used SASET PASSWORD on %s (e-mail: %s)", s_NickServ, u->nick, u->username, u->host, nc->display, (nc->email ? nc->email : "none")); if (WallSetpass) anope_cmd_global(s_NickServ, "\2%s\2 used SASET PASSWORD on \2%s\2", u->nick, nc->display); return MOD_CONT; }
/** * The /os raw command. * @param u The user who issued the command * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. **/ int do_raw(User * u) { char *text = strtok(NULL, ""); if (!text) syntax_error(s_OperServ, u, "RAW", OPER_RAW_SYNTAX); else { send_cmd(NULL, "%s", text); if (WallOSRaw) { char *kw = strtok(text, " "); while (kw && *kw == ':') kw = strtok(NULL, " "); anope_cmd_global(s_OperServ, "\2%s\2 used RAW command for \2%s\2", u->nick, (kw ? kw : "\2non RFC compliant message\2")); } alog("%s used RAW command for %s", u->nick, text); } return MOD_CONT; }
void expire_exceptions(void) { int i; time_t now = time(NULL); for (i = 0; i < nexceptions; i++) { if (exceptions[i].expires == 0 || exceptions[i].expires > now) continue; if (WallExceptionExpire) anope_cmd_global(s_OperServ, "Session limit exception for %s has expired.", exceptions[i].mask); free(exceptions[i].mask); free(exceptions[i].reason); nexceptions--; memmove(exceptions + i, exceptions + i + 1, sizeof(Exception) * (nexceptions - i)); exceptions = srealloc(exceptions, sizeof(Exception) * nexceptions); i--; } }
static int do_akill(User * u) { char *cmd = strtok(NULL, " "); char breason[BUFSIZE]; if (!cmd) cmd = ""; if (!stricmp(cmd, "ADD")) { int deleted = 0; char *expiry, *mask, *reason; time_t expires, now = time(NULL); mask = strtok(NULL, " "); if (mask && *mask == '+') { expiry = mask; mask = strtok(NULL, " "); } else { expiry = NULL; } expires = expiry ? dotime(expiry) : AutokillExpiry; /* If the expiry given does not contain a final letter, it's in days, * said the doc. Ah well. */ if (expiry && isdigit(expiry[strlen(expiry) - 1])) expires *= 86400; /* Do not allow less than a minute expiry time */ if (expires != 0 && expires < 60) { notice_lang(s_OperServ, u, BAD_EXPIRY_TIME); return MOD_CONT; } else if (expires > 0) { expires += time(NULL); } if (mask && (reason = strtok(NULL, ""))) { /* We first do some sanity check on the proposed mask. */ if (strchr(mask, '!')) { notice_lang(s_OperServ, u, OPER_AKILL_NO_NICK); return MOD_CONT; } if (!strchr(mask, '@')) { notice_lang(s_OperServ, u, BAD_USERHOST_MASK); return MOD_CONT; } if (mask && strspn(mask, "~@.*?") == strlen(mask)) { notice_lang(s_OperServ, u, USERHOST_MASK_TOO_WIDE, mask); return MOD_CONT; } /** * Changed sprintf() to snprintf()and increased the size of * breason to match bufsize * -Rob **/ if (AddAkiller) { snprintf(breason, sizeof(breason), "[%s] %s", u->nick, reason); reason = sstrdup(breason); } deleted = add_akill(u, mask, u->nick, expires, reason); if (deleted < 0) { if (AddAkiller) { free(reason); } return MOD_CONT; } else if (deleted) { notice_lang(s_OperServ, u, OPER_AKILL_DELETED_SEVERAL, deleted); } notice_lang(s_OperServ, u, OPER_AKILL_ADDED, mask); if (WallOSAkill) { char buf[128]; if (!expires) { strcpy(buf, "does not expire"); } else { int wall_expiry = expires - now; char *s = NULL; if (wall_expiry >= 86400) { wall_expiry /= 86400; s = "day"; } else if (wall_expiry >= 3600) { wall_expiry /= 3600; s = "hour"; } else if (wall_expiry >= 60) { wall_expiry /= 60; s = "minute"; } snprintf(buf, sizeof(buf), "expires in %d %s%s", wall_expiry, s, (wall_expiry == 1) ? "" : "s"); } anope_cmd_global(s_OperServ, "%s added an AKILL for %s (%s) (%s)", u->nick, mask, reason, buf); } if (readonly) { notice_lang(s_OperServ, u, READ_ONLY_MODE); } if (AddAkiller) { free(reason); } } else { syntax_error(s_OperServ, u, "AKILL", OPER_AKILL_SYNTAX); } } else if (!stricmp(cmd, "DEL")) { char *mask; int res = 0; mask = strtok(NULL, " "); if (!mask) { syntax_error(s_OperServ, u, "AKILL", OPER_AKILL_SYNTAX); return MOD_CONT; } if (akills.count == 0) { notice_lang(s_OperServ, u, OPER_AKILL_LIST_EMPTY); return MOD_CONT; } if (isdigit(*mask) && strspn(mask, "1234567890,-") == strlen(mask)) { /* Deleting a range */ res = slist_delete_range(&akills, mask, NULL); if (res == 0) { notice_lang(s_OperServ, u, OPER_AKILL_NO_MATCH); return MOD_CONT; } else if (res == 1) { notice_lang(s_OperServ, u, OPER_AKILL_DELETED_ONE); } else { notice_lang(s_OperServ, u, OPER_AKILL_DELETED_SEVERAL, res); } } else { if ((res = slist_indexof(&akills, mask)) == -1) { notice_lang(s_OperServ, u, OPER_AKILL_NOT_FOUND, mask); return MOD_CONT; } slist_delete(&akills, res); notice_lang(s_OperServ, u, OPER_AKILL_DELETED, mask); } if (readonly) notice_lang(s_OperServ, u, READ_ONLY_MODE); } else if (!stricmp(cmd, "LIST")) { char *mask; int res, sent_header = 0; if (akills.count == 0) { notice_lang(s_OperServ, u, OPER_AKILL_LIST_EMPTY); return MOD_CONT; } mask = strtok(NULL, " "); if (!mask || (isdigit(*mask) && strspn(mask, "1234567890,-") == strlen(mask))) { res = slist_enum(&akills, mask, &akill_list_callback, u, &sent_header); if (res == 0) { notice_lang(s_OperServ, u, OPER_AKILL_NO_MATCH); return MOD_CONT; } else { notice_lang(s_OperServ, u, END_OF_ANY_LIST, "Akill"); } } else { int i; char amask[BUFSIZE]; for (i = 0; i < akills.count; i++) { snprintf(amask, sizeof(amask), "%s@%s", ((Akill *) akills.list[i])->user, ((Akill *) akills.list[i])->host); if (!stricmp(mask, amask) || match_wild_nocase(mask, amask)) akill_list(i + 1, akills.list[i], u, &sent_header); } if (!sent_header) notice_lang(s_OperServ, u, OPER_AKILL_NO_MATCH); else { notice_lang(s_OperServ, u, END_OF_ANY_LIST, "Akill"); } } } else if (!stricmp(cmd, "VIEW")) { char *mask; int res, sent_header = 0; if (akills.count == 0) { notice_lang(s_OperServ, u, OPER_AKILL_LIST_EMPTY); return MOD_CONT; } mask = strtok(NULL, " "); if (!mask || (isdigit(*mask) && strspn(mask, "1234567890,-") == strlen(mask))) { res = slist_enum(&akills, mask, &akill_view_callback, u, &sent_header); if (res == 0) { notice_lang(s_OperServ, u, OPER_AKILL_NO_MATCH); return MOD_CONT; } } else { int i; char amask[BUFSIZE]; for (i = 0; i < akills.count; i++) { snprintf(amask, sizeof(amask), "%s@%s", ((Akill *) akills.list[i])->user, ((Akill *) akills.list[i])->host); if (!stricmp(mask, amask) || match_wild_nocase(mask, amask)) akill_view(i + 1, akills.list[i], u, &sent_header); } if (!sent_header) notice_lang(s_OperServ, u, OPER_AKILL_NO_MATCH); } } else if (!stricmp(cmd, "CLEAR")) { slist_clear(&akills, 1); notice_lang(s_OperServ, u, OPER_AKILL_CLEAR); } else { syntax_error(s_OperServ, u, "AKILL", OPER_AKILL_SYNTAX); } return MOD_CONT; }
int do_root(User *u) { char *buf = moduleGetLastBuffer(); char *cmd = myStrGetToken(buf, ' ', 0); char *nick = myStrGetToken(buf, ' ', 1); if (!cmd) { do_syntax_err(u); } else { if (!stricmp(cmd, "LIST")) { notice_user(s_OperServ, u, "Current services roots:"); int i; for (i = 0; i < RootNumber; ++i) { notice_user(s_OperServ, u, "%d. %s", i + 1, ServicesRoots[i]); } notice_user(s_OperServ, u, "End of services root list."); } else if (!nick) do_syntax_err(u); else { NickAlias *na = findnick(nick); if (!na) notice_lang(s_OperServ, u, NICK_X_NOT_REGISTERED, nick); else if (!stricmp(cmd, "ADD")) { if (na->nc->flags & NI_SERVICES_ROOT) { notice_user(s_OperServ, u, "\2%s\2 is already a services root", na->nick); } else { ++RootNumber; ServicesRoots = srealloc(ServicesRoots, sizeof(char *) * RootNumber); ServicesRoots[RootNumber - 1] = sstrdup(na->nick); na->nc->flags |= NI_SERVICES_ROOT; anope_cmd_global(s_OperServ, "\2%s\2 made \2%s\2 (\2%s\2) a services root administrator", u->nick, na->nick, na->nc->display); alog("%s: %s!%s@%s made %s (%s) a services root administrator", s_OperServ, u->nick, u->username, u->host, na->nick, na->nc->display); notice_user(s_OperServ, u, "\2%s\2 added to the services root administrator list.", na->nick); } } else if (!stricmp(cmd, "DEL")) { if (!(na->nc->flags & NI_SERVICES_ROOT)) { notice_user(s_OperServ, u, "\2%s\2 isn't already a services root", na->nick); } else { na->nc->flags &= ~NI_SERVICES_ROOT; int i, j, removed = 0; NickAlias *na2; for (i = 0; i < RootNumber; ++i) { for (j = 0; j < na->nc->aliases.count; ++j) { na2 = na->nc->aliases.list[j]; if (ServicesRoots[i] && !stricmp(ServicesRoots[i], na2->nick)) { free(ServicesRoots[i]); ServicesRoots[i] = NULL; ++removed; break; } } } int RealRootNum = RootNumber - removed;; char **RealRoots = scalloc(RealRootNum, sizeof(char *)); j = 0; for (i = 0; i < RootNumber; ++i) { if (ServicesRoots[i]) { RealRoots[j] = sstrdup(ServicesRoots[i]); ++j; } } free(ServicesRoots); ServicesRoots = RealRoots; RootNumber = RealRootNum; anope_cmd_global(s_OperServ, "\2%s\2 removed \2%s\2 (\2%s\2) from being a services root administrator", u->nick, na->nick, na->nc->display); alog("%s: %s!%s@%s made %s (%s) a services root administrator", s_OperServ, u->nick, u->username, u->host, na->nick, na->nc->display); notice_user(s_OperServ, u, "\2%s\2 removed from the services root administrator list.", na->nick); } } else do_syntax_err(u); } } if (cmd) free(cmd); if (nick) free(nick); return MOD_CONT; }
/** * The /os set command. * @param u The user who issued the command * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. **/ static int do_set(User * u) { char *option = strtok(NULL, " "); char *setting = strtok(NULL, " "); int index; Channel *c; if (!option) { syntax_error(s_OperServ, u, "SET", OPER_SET_SYNTAX); } else if (stricmp(option, "LIST") == 0) { index = (allow_ignore ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF); notice_lang(s_OperServ, u, index, "IGNORE"); index = (readonly ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF); notice_lang(s_OperServ, u, index, "READONLY"); index = (logchan ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF); notice_lang(s_OperServ, u, index, "LOGCHAN"); index = (debug ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF); notice_lang(s_OperServ, u, index, "DEBUG"); index = (noexpire ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF); notice_lang(s_OperServ, u, index, "NOEXPIRE"); #ifdef USE_MYSQL index = (do_mysql ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF); notice_lang(s_OperServ, u, index, "SQL"); #endif } else if (!setting) { syntax_error(s_OperServ, u, "SET", OPER_SET_SYNTAX); } else if (stricmp(option, "IGNORE") == 0) { if (stricmp(setting, "on") == 0) { allow_ignore = 1; notice_lang(s_OperServ, u, OPER_SET_IGNORE_ON); } else if (stricmp(setting, "off") == 0) { allow_ignore = 0; notice_lang(s_OperServ, u, OPER_SET_IGNORE_OFF); } else { notice_lang(s_OperServ, u, OPER_SET_IGNORE_ERROR); } #ifdef USE_MYSQL } else if (stricmp(option, "SQL") == 0) { if (stricmp(setting, "on") == 0) { if (!MysqlHost) { notice_lang(s_OperServ, u, OPER_SET_SQL_ERROR_DISABLED); } else { if (rdb_init()) { notice_lang(s_OperServ, u, OPER_SET_SQL_ON); } else { notice_lang(s_OperServ, u, OPER_SET_SQL_ERROR_INIT); } } } else if (stricmp(setting, "off") == 0) { if (!MysqlHost) { notice_lang(s_OperServ, u, OPER_SET_SQL_ERROR_DISABLED); } else { /* could call rdb_close() but that does nothing - TSL */ do_mysql = 0; notice_lang(s_OperServ, u, OPER_SET_SQL_OFF); } } else { notice_lang(s_OperServ, u, OPER_SET_SQL_ERROR); } #endif } else if (stricmp(option, "READONLY") == 0) { if (stricmp(setting, "on") == 0) { readonly = 1; alog("Read-only mode activated"); close_log(); notice_lang(s_OperServ, u, OPER_SET_READONLY_ON); } else if (stricmp(setting, "off") == 0) { readonly = 0; open_log(); alog("Read-only mode deactivated"); notice_lang(s_OperServ, u, OPER_SET_READONLY_OFF); } else { notice_lang(s_OperServ, u, OPER_SET_READONLY_ERROR); } } else if (stricmp(option, "LOGCHAN") == 0) { /* Unlike the other SET commands where only stricmp is necessary, * we also have to ensure that LogChannel is defined or we can't * send to it. * * -jester */ if (LogChannel && (stricmp(setting, "on") == 0)) { if (ircd->join2msg) { c = findchan(LogChannel); anope_cmd_join(s_GlobalNoticer, LogChannel, c ? c->creation_time : time(NULL)); } logchan = 1; alog("Now sending log messages to %s", LogChannel); notice_lang(s_OperServ, u, OPER_SET_LOGCHAN_ON, LogChannel); } else if (LogChannel && (stricmp(setting, "off") == 0)) { alog("No longer sending log messages to a channel"); if (ircd->join2msg) { anope_cmd_part(s_GlobalNoticer, LogChannel, NULL); } logchan = 0; notice_lang(s_OperServ, u, OPER_SET_LOGCHAN_OFF); } else { notice_lang(s_OperServ, u, OPER_SET_LOGCHAN_ERROR); } /** * Allow the user to turn super admin on/off * * Rob **/ } else if (stricmp(option, "SUPERADMIN") == 0) { if (!SuperAdmin) { notice_lang(s_OperServ, u, OPER_SUPER_ADMIN_NOT_ENABLED); } else if (stricmp(setting, "on") == 0) { u->isSuperAdmin = 1; notice_lang(s_OperServ, u, OPER_SUPER_ADMIN_ON); alog("%s: %s is a SuperAdmin ", s_OperServ, u->nick); anope_cmd_global(s_OperServ, getstring2(NULL, OPER_SUPER_ADMIN_WALL_ON), u->nick); } else if (stricmp(setting, "off") == 0) { u->isSuperAdmin = 0; notice_lang(s_OperServ, u, OPER_SUPER_ADMIN_OFF); alog("%s: %s is no longer a SuperAdmin", s_OperServ, u->nick); anope_cmd_global(s_OperServ, getstring2(NULL, OPER_SUPER_ADMIN_WALL_OFF), u->nick); } else { notice_lang(s_OperServ, u, OPER_SUPER_ADMIN_SYNTAX); } } else if (stricmp(option, "DEBUG") == 0) { if (stricmp(setting, "on") == 0) { debug = 1; alog("Debug mode activated"); notice_lang(s_OperServ, u, OPER_SET_DEBUG_ON); } else if (stricmp(setting, "off") == 0 || (*setting == '0' && atoi(setting) == 0)) { alog("Debug mode deactivated"); debug = 0; notice_lang(s_OperServ, u, OPER_SET_DEBUG_OFF); } else if (isdigit(*setting) && atoi(setting) > 0) { debug = atoi(setting); alog("Debug mode activated (level %d)", debug); notice_lang(s_OperServ, u, OPER_SET_DEBUG_LEVEL, debug); } else { notice_lang(s_OperServ, u, OPER_SET_DEBUG_ERROR); } } else if (stricmp(option, "NOEXPIRE") == 0) { if (stricmp(setting, "ON") == 0) { noexpire = 1; alog("No expire mode activated"); notice_lang(s_OperServ, u, OPER_SET_NOEXPIRE_ON); } else if (stricmp(setting, "OFF") == 0) { noexpire = 0; alog("No expire mode deactivated"); notice_lang(s_OperServ, u, OPER_SET_NOEXPIRE_OFF); } else { notice_lang(s_OperServ, u, OPER_SET_NOEXPIRE_ERROR); } } else { notice_lang(s_OperServ, u, OPER_SET_UNKNOWN_OPTION, option); } return MOD_CONT; }
/** * The /cs (un)suspend command. * @param u The user who issued the command * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. **/ static int do_suspend(User * u) { ChannelInfo *ci; char *chan = strtok(NULL, " "); char *reason = strtok(NULL, ""); Channel *c; /* Assumes that permission checking has already been done. */ if (!chan || (ForceForbidReason && !reason)) { syntax_error(s_ChanServ, u, "SUSPEND", (ForceForbidReason ? CHAN_SUSPEND_SYNTAX_REASON : CHAN_SUSPEND_SYNTAX)); return MOD_CONT; } if (chan[0] != '#') { notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_ERROR); return MOD_CONT; } /* Only SUSPEND existing channels, otherwise use FORBID (bug #54) */ if ((ci = cs_findchan(chan)) == NULL) { notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan); return MOD_CONT; } /* You should not SUSPEND a FORBIDEN channel */ if (ci->flags & CI_VERBOTEN) { notice_lang(s_ChanServ, u, CHAN_MAY_NOT_BE_REGISTERED, chan); return MOD_CONT; } if (readonly) notice_lang(s_ChanServ, u, READ_ONLY_MODE); if (ci) { ci->flags |= CI_SUSPENDED; ci->forbidby = sstrdup(u->nick); if (reason) ci->forbidreason = sstrdup(reason); if ((c = findchan(ci->name))) { struct c_userlist *cu, *next; char *av[3]; for (cu = c->users; cu; cu = next) { next = cu->next; if (is_oper(cu->user)) continue; av[0] = c->name; av[1] = cu->user->nick; av[2] = reason ? reason : getstring(cu->user->na, CHAN_SUSPEND_REASON); anope_cmd_kick(s_ChanServ, av[0], av[1], av[2]); do_kick(s_ChanServ, 3, av); } } if (WallForbid) anope_cmd_global(s_ChanServ, "\2%s\2 used SUSPEND on channel \2%s\2", u->nick, ci->name); alog("%s: %s set SUSPEND for channel %s", s_ChanServ, u->nick, ci->name); notice_lang(s_ChanServ, u, CHAN_SUSPEND_SUCCEEDED, chan); send_event(EVENT_CHAN_SUSPENDED, 1, chan); } else { alog("%s: Valid SUSPEND for %s by %s failed", s_ChanServ, ci->name, u->nick); notice_lang(s_ChanServ, u, CHAN_SUSPEND_FAILED, chan); } return MOD_CONT; }
/** * The /cs forbid command. * @param u The user who issued the command * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. **/ static int do_forbid(User * u) { Channel *c; ChannelInfo *ci; char *chan = strtok(NULL, " "); char *reason = strtok(NULL, ""); Entry *cur, *enext; /* Assumes that permission checking has already been done. */ if (!chan || (ForceForbidReason && !reason)) { syntax_error(s_ChanServ, u, "FORBID", (ForceForbidReason ? CHAN_FORBID_SYNTAX_REASON : CHAN_FORBID_SYNTAX)); return MOD_CONT; } if (*chan != '#') { notice_lang(s_ChanServ, u, CHAN_SYMBOL_REQUIRED); return MOD_CONT; } else if (!anope_valid_chan(chan)) { notice_lang(s_ChanServ, u, CHAN_X_INVALID, chan); return MOD_CONT; } if (readonly) notice_lang(s_ChanServ, u, READ_ONLY_MODE); if ((ci = cs_findchan(chan)) != NULL) { delchan(ci); send_event(EVENT_CHAN_DROP, 1, chan); } ci = makechan(chan); if (ci) { ci->flags |= CI_VERBOTEN; ci->forbidby = sstrdup(u->nick); if (reason) ci->forbidreason = sstrdup(reason); if ((c = findchan(ci->name))) { struct c_userlist *cu, *next; char *av[3]; /* Before banning everyone, it might be prudent to clear +e and +I lists.. * to prevent ppl from rejoining.. ~ Viper */ if (ircd->except && c->excepts && c->excepts->count) { av[0] = sstrdup("-e"); for (cur = c->excepts->entries; cur; cur = enext) { enext = cur->next; av[1] = sstrdup(cur->mask); anope_cmd_mode(whosends(ci), chan, "-e %s", cur->mask); chan_set_modes(whosends(ci), c, 2, av, 0); free(av[1]); } free(av[0]); } if (ircd->invitemode && c->invites && c->invites->count) { av[0] = sstrdup("-I"); for (cur = c->invites->entries; cur; cur = enext) { enext = cur->next; av[1] = sstrdup(cur->mask); anope_cmd_mode(whosends(ci), chan, "-I %s", cur->mask); chan_set_modes(whosends(ci), c, 2, av, 0); free(av[1]); } free(av[0]); } for (cu = c->users; cu; cu = next) { next = cu->next; if (is_oper(cu->user)) continue; av[0] = c->name; av[1] = cu->user->nick; av[2] = reason ? reason : "CHAN_FORBID_REASON"; anope_cmd_kick(s_ChanServ, av[0], av[1], av[2]); do_kick(s_ChanServ, 3, av); } } if (WallForbid) anope_cmd_global(s_ChanServ, "\2%s\2 used FORBID on channel \2%s\2", u->nick, ci->name); if (ircd->chansqline) { anope_cmd_sqline(ci->name, ((reason) ? reason : "Forbidden")); } alog("%s: %s set FORBID for channel %s", s_ChanServ, u->nick, ci->name); notice_lang(s_ChanServ, u, CHAN_FORBID_SUCCEEDED, chan); send_event(EVENT_CHAN_FORBIDDEN, 1, chan); } else { alog("%s: Valid FORBID for %s by %s failed", s_ChanServ, ci->name, u->nick); notice_lang(s_ChanServ, u, CHAN_FORBID_FAILED, chan); } return MOD_CONT; }
void plexus_set_umode (User * user, int ac, char **av) { int add = 1; /* 1 if adding modes, 0 if deleting */ char *modes = av[0]; ac--; if (debug) alog ("debug: Changing mode for %s to %s", user->nick, modes); while (*modes) { /* This looks better, much better than "add ? (do_add) : (do_remove)". * At least this is readable without paying much attention :) -GD */ if (add) user->mode |= umodes[(int) *modes]; else user->mode &= ~umodes[(int) *modes]; switch (*modes++) { case '+': add = 1; break; case '-': add = 0; break; case 'd': if (ac == 0) { alog ("user: umode +d with no parameter (?) for user %s", user->nick); break; } ac--; av++; user->svid = strtoul (*av, NULL, 0); break; case 'x': update_host (user); break; case 'o': if (add) { opcnt++; if (WallOper) anope_cmd_global (s_OperServ, "\2%s\2 is now an IRC operator.", user->nick); display_news (user, NEWS_OPER); } else { opcnt--; } break; case 'r': if (add && !nick_identified (user)) { common_svsmode (user, "-r", NULL); user->mode &= ~UMODE_r; } break; } } }