int do_getpass(User * u) { char *chan = strtok(NULL, " "); char tmp_pass[PASSMAX]; ChannelInfo *ci; if (!chan) { syntax_error(s_ChanServ, u, "GETPASS", CHAN_GETPASS_SYNTAX); } else if (!(ci = cs_findchan(chan))) { notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan); } else if (ci->flags & CI_VERBOTEN) { notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, chan); } else if (CSRestrictGetPass && !is_services_root(u)) { notice_lang(s_ChanServ, u, PERMISSION_DENIED); } else { if(enc_decrypt(ci->founderpass,tmp_pass,PASSMAX)==1) { alog("%s: %s!%s@%s used GETPASS on %s", s_ChanServ, u->nick, u->username, u->host, ci->name); if (WallGetpass) { xanadu_cmd_global(s_ChanServ, "\2%s\2 used GETPASS on channel \2%s\2", u->nick, chan); } notice_lang(s_ChanServ, u, CHAN_GETPASS_PASSWORD_IS, chan, ci->founderpass); } else { notice_lang(s_ChanServ, u, CHAN_GETPASS_UNAVAILABLE); } } return MOD_CONT; }
static int do_saset_email(User * u, NickCore * nc, char *param) { if (!param && NSForceEmail) { notice_lang(s_NickServ, u, NICK_SASET_EMAIL_UNSET_IMPOSSIBLE); return MOD_CONT; } else 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 (param && !MailValidate(param)) { notice_lang(s_NickServ, u, MAIL_X_INVALID, param); return MOD_CONT; } alog("%s: %s!%s@%s used SASET EMAIL on %s (e-mail: %s)", s_NickServ, u->nick, u->username, u->host, nc->display, (nc->email ? nc->email : "none")); if (nc->email) free(nc->email); if (param) { nc->email = sstrdup(param); notice_lang(s_NickServ, u, NICK_SASET_EMAIL_CHANGED, nc->display, param); } else { nc->email = NULL; notice_lang(s_NickServ, u, NICK_SASET_EMAIL_UNSET, nc->display); } return MOD_CONT; }
/** * The /ns getpass command. * @param u The user who issued the command * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. **/ int do_getpass(User * u) { char *nick = strtok(NULL, " "); char tmp_pass[PASSMAX]; NickAlias *na; NickRequest *nr = NULL; if (!nick) { syntax_error(s_NickServ, u, "GETPASS", NICK_GETPASS_SYNTAX); } else if (!(na = findnick(nick))) { if ((nr = findrequestnick(nick))) { alog("%s: %s!%s@%s used GETPASS on %s", s_NickServ, u->nick, u->username, u->host, nick); if (WallGetpass) xanadu_cmd_global(s_NickServ, "\2%s\2 used GETPASS on \2%s\2", u->nick, nick); notice_lang(s_NickServ, u, NICK_GETPASS_PASSCODE_IS, nick, nr->passcode); } else { notice_lang(s_NickServ, u, NICK_X_NOT_REGISTERED, nick); } } else if (na->status & NS_VERBOTEN) { notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, na->nick); } else if (NSSecureAdmins && nick_is_services_admin(na->nc) && !is_services_root(u)) { notice_lang(s_NickServ, u, PERMISSION_DENIED); } else if (NSRestrictGetPass && !is_services_root(u)) { notice_lang(s_NickServ, u, PERMISSION_DENIED); } else { if(enc_decrypt(na->nc->pass,tmp_pass,PASSMAX)==1) { alog("%s: %s!%s@%s used GETPASS on %s", s_NickServ, u->nick, u->username, u->host, nick); if (WallGetpass) xanadu_cmd_global(s_NickServ, "\2%s\2 used GETPASS on \2%s\2", u->nick, nick); notice_lang(s_NickServ, u, NICK_GETPASS_PASSWORD_IS, nick, na->nc->pass); } else { notice_lang(s_NickServ, u, NICK_GETPASS_UNAVAILABLE); } } return MOD_CONT; }
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; }
int list_global_opers(Channel *c, User *u) { int j, i , carryon, count = 0; User *u2; char *access; noticeLang(c->ci->bi->nick, u, LANG_GOLIST_HEADER); for (j = 0; j < 1024; j++) { for (u2 = userlist[j]; u2; u2 = u2->next) { carryon = 0; /* Prevent listing of users with +H */ if (finduser((u2->nick)) && !has_umode_H(u2) && !has_umode_B(u2) && !is_ulined(u2->server->name)) { i = 0; while (i < excempt_nr) { if (!ListExempts[i] || !u2->nick) break; if (my_match_wild_nocase(ListExempts[i], u2->nick)) { carryon = 1; break; } i++; } if (carryon) continue; if (is_oper(u2)) { count++; access = getLangString(u->na, LANG_GOLIST_OPER_ONLY); if (is_services_oper(u2)) access = getLangString(u->na, LANG_GOLIST_OPER_AND_SO); if (is_services_admin(u2)) access = getLangString(u->na, LANG_GOLIST_OPER_AND_SA); if (is_services_root(u2)) access = getLangString(u->na, LANG_GOLIST_OPER_AND_SRA); notice(c->ci->bi->nick, u->nick, "%-15s - %s", u2->nick, access); } } } } if (count == 0) noticeLang(c->ci->bi->nick, u, LANG_GOLIST_NONE); noticeLang(c->ci->bi->nick, u, LANG_GOLIST_FOOTER, count); return MOD_CONT; }
int list_admins(Channel *c, User *u) { int j, i , carryon, count = 0; User *u2; noticeLang(c->ci->bi->nick, u, LANG_ADLIST_HEADER); for (j = 0; j < 1024; j++) { for (u2 = userlist[j]; u2; u2 = u2->next) { carryon = 0; /* Prevent listing of users with +H */ if (finduser((u2->nick)) && !has_umode_H(u2) && !has_umode_B(u2) && !is_ulined(u2->server->name)) { i = 0; while (i < excempt_nr) { if (!ListExempts[i] || !u2->nick) break; if (!stricmp(u2->nick, ListExempts[i])) carryon = 1; i++; } if (carryon) continue; if (is_oper(u2)) { if (is_services_root(u2)) { count++; notice(c->ci->bi->nick, u->nick, "%-15s - %s", u2->nick, getLangString(u->na, LANG_ADLIST_SRA)); continue; } if (is_services_admin(u2)) { count++; notice(c->ci->bi->nick, u->nick, "%-15s - %s", u2->nick, getLangString(u->na, LANG_ADLIST_SA)); } } } } } if (count == 0) noticeLang(c->ci->bi->nick, u, LANG_ADLIST_NONE); noticeLang(c->ci->bi->nick, u, LANG_ADLIST_FOOTER, count); return MOD_CONT; }
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; }
void help_cmd(const char *service, User *u, Command *list, const char *cmd) { Command *c = lookup_cmd(list, cmd); if (c) { const char *p1 = c->help_param1, *p2 = c->help_param2, *p3 = c->help_param3, *p4 = c->help_param4; if (c->helpmsg_all >= 0) { notice_help(service, u, c->helpmsg_all, p1, p2, p3, p4); } if (is_services_root(u)) { if (c->helpmsg_root >= 0) notice_help(service, u, c->helpmsg_root, p1, p2, p3, p4); else if (c->helpmsg_all < 0) notice_lang(service, u, NO_HELP_AVAILABLE, cmd); } else if (is_services_admin(u)) { if (c->helpmsg_admin >= 0) notice_help(service, u, c->helpmsg_admin, p1, p2, p3, p4); else if (c->helpmsg_all < 0) notice_lang(service, u, NO_HELP_AVAILABLE, cmd); } else if (is_services_oper(u)) { if (c->helpmsg_oper >= 0) notice_help(service, u, c->helpmsg_oper, p1, p2, p3, p4); else if (c->helpmsg_all < 0) notice_lang(service, u, NO_HELP_AVAILABLE, cmd); } else { if (c->helpmsg_reg >= 0) notice_help(service, u, c->helpmsg_reg, p1, p2, p3, p4); else if (c->helpmsg_all < 0) notice_lang(service, u, NO_HELP_AVAILABLE, cmd); } } else { notice_lang(service, u, NO_HELP_AVAILABLE, cmd); } }
int is_services_admin(User * u) { unsigned int fields, rows; MYSQL_RES *result; if (!(u->mode & UMODE_o)) return(0); if (!nick_identified(u)) return(0); if (is_services_root(u)) return(1); result = smysql_bulk_query(mysqlconn, &fields, &rows, "SELECT 1 FROM admin WHERE nick_id=%u || nick_id=%u", u->nick_id, u->real_id); mysql_free_result(result); return(rows? 1 : 0); }
void plexus_cmd_svid_umode3 (User * u, char *ts) { char modes[512]; strlcpy(modes, "+r", sizeof(modes)); if(ircd->rootmodeonid && is_services_root(u)) { strlcat(modes, ircd->rootmodeonid, sizeof(modes)); } else if(ircd->adminmodeonid && is_services_admin(u)) { strlcat(modes, ircd->adminmodeonid, sizeof(modes)); } else if(ircd->opermodeonid && is_services_oper(u)) { strlcat(modes, ircd->opermodeonid, sizeof(modes)); } if (u->svid != u->timestamp) { strlcat(modes, "d", sizeof(modes)); common_svsmode (u, modes, ts); } else { common_svsmode (u, modes, NULL); } }
/** * The /ns identify command. * @param u The user who issued the command * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. **/ int do_identify(User * u) { char *pass = strtok(NULL, " "); NickAlias *na; NickRequest *nr; int res; char tsbuf[16]; char modes[512]; int len; if (!pass) { syntax_error(s_NickServ, u, "IDENTIFY", NICK_IDENTIFY_SYNTAX); } else if (!(na = u->na)) { if ((nr = findrequestnick(u->nick))) { notice_lang(s_NickServ, u, NICK_IS_PREREG); } else { notice_lang(s_NickServ, u, NICK_NOT_REGISTERED); } } else if (na->status & NS_VERBOTEN) { notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, na->nick); } else if (na->nc->flags & NI_SUSPENDED) { notice_lang(s_NickServ, u, NICK_X_SUSPENDED, na->nick); } else if (nick_identified(u)) { notice_lang(s_NickServ, u, NICK_ALREADY_IDENTIFIED); } else if (!(res = enc_check_password(pass, na->nc->pass))) { alog("%s: Failed IDENTIFY for %s!%s@%s", s_NickServ, u->nick, u->username, u->host); notice_lang(s_NickServ, u, PASSWORD_INCORRECT); bad_password(u); } else if (res == -1) { notice_lang(s_NickServ, u, NICK_IDENTIFY_FAILED); } else { if (!(na->status & NS_IDENTIFIED) && !(na->status & NS_RECOGNIZED)) { if (na->last_usermask) free(na->last_usermask); na->last_usermask = scalloc(strlen(common_get_vident(u)) + strlen(common_get_vhost(u)) + 2, 1); sprintf(na->last_usermask, "%s@%s", common_get_vident(u), common_get_vhost(u)); if (na->last_realname) free(na->last_realname); na->last_realname = sstrdup(u->realname); } na->status |= NS_IDENTIFIED; na->last_seen = time(NULL); snprintf(tsbuf, sizeof(tsbuf), "%lu", (unsigned long int) u->timestamp); if (ircd->modeonreg) { len = strlen(ircd->modeonreg); strncpy(modes,ircd->modeonreg,512); if(ircd->rootmodeonid && is_services_root(u)) { strncat(modes,ircd->rootmodeonid,512-len); } else if(ircd->adminmodeonid && is_services_admin(u)) { strncat(modes,ircd->adminmodeonid,512-len); } else if(ircd->opermodeonid && is_services_oper(u)) { strncat(modes,ircd->opermodeonid,512-len); } if (ircd->tsonmode) { common_svsmode(u, modes, tsbuf); } else { common_svsmode(u, modes, ""); } } send_event(EVENT_NICK_IDENTIFY, 1, u->nick); alog("%s: %s!%s@%s identified for nick %s", s_NickServ, u->nick, u->username, u->host, u->nick); notice_lang(s_NickServ, u, NICK_IDENTIFY_SUCCEEDED); if (ircd->vhost) { do_on_id(u); } if (NSModeOnID) { do_setmodes(u); } if (NSForceEmail && u->na && !u->na->nc->email) { notice_lang(s_NickServ, u, NICK_IDENTIFY_EMAIL_REQUIRED); notice_help(s_NickServ, u, NICK_IDENTIFY_EMAIL_HOWTO); } if (!(na->status & NS_RECOGNIZED)) check_memos(u); /* Enable nick tracking if enabled */ if (NSNickTracking) nsStartNickTracking(u); /* Clear any timers */ if (na->nc->flags & NI_KILLPROTECT) { del_ns_timeout(na, TO_COLLIDE); } } return MOD_CONT; }
int do_addnick(User * u) { NickAlias *na, *target; NickCore *nc; char *nick = strtok(NULL, " "); char *pass = strtok(NULL, " "); int i; char tsbuf[16]; char modes[512]; int len; if (NSEmailReg && (findrequestnick(u->nick))) { notice_lang(s_NickServ, u, NS_REQUESTED); return MOD_CONT; } if (readonly) { notice_lang(s_NickServ, u, NS_ADDNICK_DISABLED); return MOD_CONT; } if (checkDefCon(DEFCON_NO_NEW_NICKS)) { notice_lang(s_NickServ, u, OPER_DEFCON_DENIED); return MOD_CONT; } if (RestrictOperNicks) { for (i = 0; i < RootNumber; i++) { if (stristr(u->nick, ServicesRoots[i]) && !is_oper(u)) { notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED, u->nick); return MOD_CONT; } } for (i = 0; i < servadmins.count && (nc = servadmins.list[i]); i++) { if (stristr(u->nick, nc->display) && !is_oper(u)) { notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED, u->nick); return MOD_CONT; } } for (i = 0; i < servopers.count && (nc = servopers.list[i]); i++) { if (stristr(u->nick, nc->display) && !is_oper(u)) { notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED, u->nick); return MOD_CONT; } } } if (!nick || !pass) { syntax_error(s_NickServ, u, "ADDNICK", NS_ADDNICK_SYNTAX); } else if (!(target = findnick(nick))) { notice_lang(s_NickServ, u, NICK_X_NOT_REGISTERED, nick); } else if (time(NULL) < u->lastnickreg + NSRegDelay) { notice_lang(s_NickServ, u, NS_ADDNICK_PLEASE_WAIT, NSRegDelay); } else if (u->na && (u->na->status & NS_VERBOTEN)) { alog("%s: %s@%s tried to use ADDNICK from forbidden nick %s.", s_NickServ, u->username, u->host, u->nick); notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, u->nick); } else if (u->na && (u->na->nc->flags & NI_SUSPENDED)) { alog("%s: %s!%s@%s tried to use ADDNICK from suspended nick %s.", s_NickServ, u->nick, u->username, u->host, target->nick); notice_lang(s_NickServ, u, NICK_X_SUSPENDED, u->nick); } else if (u->na && NSNoGroupChange) { notice_lang(s_NickServ, u, NS_ADDNICK_CHANGE_DISABLED, s_NickServ); } else if (u->na && !nick_identified(u)) { notice_lang(s_NickServ, u, NICK_IDENTIFY_REQUIRED, s_NickServ); } else if (target && (target->nc->flags & NI_SUSPENDED)) { alog("%s: %s!%s@%s tried to use GROUP from SUSPENDED nick %s", s_NickServ, u->nick, u->username, u->host, target->nick); notice_lang(s_NickServ, u, NICK_X_SUSPENDED, target->nick); } else if (target->status & NS_VERBOTEN) { notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, nick); } else if (u->na && target->nc == u->na->nc) { notice_lang(s_NickServ, u, NS_ADDNICK_SAME, target->nick); } else if (NSMaxAliases && (target->nc->aliases.count >= NSMaxAliases) && !nick_is_services_admin(target->nc)) { notice_lang(s_NickServ, u, NS_ADDNICK_TOO_MANY, target->nick, s_NickServ, s_NickServ); } else if (enc_check_password(pass, target->nc->pass) != 1) { alog("%s: Failed ADDNICK for %s!%s@%s (invalid password).", s_NickServ, u->nick, u->username, u->host); notice_lang(s_NickServ, u, PASSWORD_INCORRECT); bad_password(u); } else { /* If the nick is already registered, drop it. * If not, check that it is valid. */ if (u->na) { delnick(u->na); } else { int prefixlen = strlen(NSGuestNickPrefix); int nicklen = strlen(u->nick); if (nicklen <= prefixlen + 7 && nicklen >= prefixlen + 1 && stristr(u->nick, NSGuestNickPrefix) == u->nick && strspn(u->nick + prefixlen, "1234567890") == nicklen - prefixlen) { notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED, u->nick); return MOD_CONT; } } na = makealias(u->nick, target->nc); if (na) { na->last_usermask = scalloc(strlen(common_get_vident(u)) + strlen(common_get_vhost(u)) + 2, 1); sprintf(na->last_usermask, "%s@%s", common_get_vident(u), common_get_vhost(u)); na->last_realname = sstrdup(u->realname); na->time_registered = na->last_seen = time(NULL); na->status = (int16) (NS_IDENTIFIED | NS_RECOGNIZED); if (!(na->nc->flags & NI_SERVICES_ROOT)) { for (i = 0; i < RootNumber; i++) { if (!stricmp(ServicesRoots[i], u->nick)) { na->nc->flags |= NI_SERVICES_ROOT; break; } } } u->na = na; na->u = u; #ifdef USE_RDB /* Is this really needed? Since this is a new alias it will get * its unique id on the next update, since it was previously * deleted by delnick. Must observe... */ if (rdb_open()) { rdb_save_ns_alias(na); rdb_close(); } #endif send_event(EVENT_GROUP, 1, u->nick); alog("%s: %s!%s@%s makes %s join group of %s (%s) (e-mail: %s)", s_NickServ, u->nick, u->username, u->host, u->nick, target->nick, target->nc->display, (target->nc->email ? target->nc->email : "none")); notice_lang(s_NickServ, u, NS_ADDNICK_SUCCESS, target->nick); u->lastnickreg = time(NULL); snprintf(tsbuf, sizeof(tsbuf), "%lu", (unsigned long int) u->timestamp); if (ircd->modeonreg) { len = strlen(ircd->modeonreg); strncpy(modes,ircd->modeonreg,512); if(ircd->rootmodeonid && is_services_root(u)) { strncat(modes,ircd->rootmodeonid,512-len); } else if(ircd->adminmodeonid && is_services_admin(u)) { strncat(modes,ircd->adminmodeonid,512-len); } else if(ircd->opermodeonid && is_services_oper(u)) { strncat(modes,ircd->opermodeonid,512-len); } if (ircd->tsonmode) { common_svsmode(u, modes, tsbuf); } else { common_svsmode(u, modes, NULL); } } check_memos(u); } else { alog("%s: makealias(%s) failed", s_NickServ, u->nick); notice_lang(s_NickServ, u, NS_ADDNICK_FAILED); } } return MOD_CONT; }
/** * Add the help response to anopes /os help output. * @param u The user who is requesting help **/ void myOperServHelp(User * u) { if (is_services_root(u)) { notice_lang(s_OperServ, u, OPER_HELP_CMD_MODLOAD); } }
static void do_admin(User * u) { MYSQL_ROW row; unsigned int nick_id, fields, rows, err; char *cmd, *nick; MYSQL_RES *result; cmd = strtok(NULL, " "); if (!cmd) cmd = ""; if (stricmp(cmd, "ADD") == 0) { if (!is_services_root(u)) { notice_lang(s_OperServ, u, PERMISSION_DENIED); return; } nick = strtok(NULL, " "); if (nick) { if (!(nick_id = mysql_findnick(nick))) { notice_lang(s_OperServ, u, NICK_X_NOT_REGISTERED, nick); return; } else if (num_serv_admins() >= MAX_SERVADMINS) { notice_lang(s_OperServ, u, OPER_ADMIN_TOO_MANY, MAX_SERVADMINS); return; } nick_id = mysql_getlink(nick_id); result = mysql_simple_query(mysqlconn, &err, "INSERT INTO admin (nick_id) VALUES (%u)", nick_id); switch (err) { case 0: mysql_free_result(result); notice_lang(s_OperServ, u, OPER_ADMIN_ADDED, nick); break; case ER_DUP_ENTRY: notice_lang(s_OperServ, u, OPER_ADMIN_EXISTS, nick); break; default: handle_mysql_error(mysqlconn, "insert_admin"); break; /* never reached */ } } else { syntax_error(s_OperServ, u, "ADMIN", OPER_ADMIN_ADD_SYNTAX); } } else if (stricmp(cmd, "DEL") == 0) { if (!is_services_root(u)) { notice_lang(s_OperServ, u, PERMISSION_DENIED); return; } nick = strtok(NULL, " "); if (nick) { if (!(nick_id = mysql_findnick(nick))) { notice_lang(s_OperServ, u, NICK_X_NOT_REGISTERED, nick); return; } nick_id = mysql_getlink(nick_id); result = smysql_bulk_query(mysqlconn, &fields, &rows, "DELETE FROM admin WHERE nick_id=%u", nick_id); if (rows) { notice_lang(s_OperServ, u, OPER_ADMIN_REMOVED, nick); } else { notice_lang(s_OperServ, u, OPER_ADMIN_NOT_FOUND, nick); } mysql_free_result(result); } else { syntax_error(s_OperServ, u, "ADMIN", OPER_ADMIN_DEL_SYNTAX); } } else if (stricmp(cmd, "LIST") == 0) { notice_lang(s_OperServ, u, OPER_ADMIN_LIST_HEADER); result = smysql_bulk_query(mysqlconn, &fields, &rows, "SELECT nick.nick FROM admin, nick " "WHERE nick.nick_id=admin.nick_id ORDER BY nick.nick"); while ((row = smysql_fetch_row(mysqlconn, result))) notice(s_OperServ, u->nick, "%s", row[0]); mysql_free_result(result); } else { syntax_error(s_OperServ, u, "ADMIN", OPER_ADMIN_SYNTAX); } }
/** * The /os admin command. * @param u The user who issued the command * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. **/ int do_admin(User * u) { char *cmd = strtok(NULL, " "); char *nick = strtok(NULL, " "); NickAlias *na; int res = 0; if (skeleton) { notice_lang(s_OperServ, u, OPER_ADMIN_SKELETON); return MOD_CONT; } if (!cmd || (!nick && stricmp(cmd, "LIST") && stricmp(cmd, "CLEAR"))) { syntax_error(s_OperServ, u, "ADMIN", OPER_ADMIN_SYNTAX); } else if (!stricmp(cmd, "ADD")) { if (!is_services_root(u)) { notice_lang(s_OperServ, u, PERMISSION_DENIED); return MOD_CONT; } if (!(na = findnick(nick))) { notice_lang(s_OperServ, u, NICK_X_NOT_REGISTERED, nick); return MOD_CONT; } if (na->status & NS_VERBOTEN) { notice_lang(s_OperServ, u, NICK_X_FORBIDDEN, nick); return MOD_CONT; } if (na->nc->flags & NI_SERVICES_ADMIN || slist_indexof(&servadmins, na->nc) != -1) { notice_lang(s_OperServ, u, OPER_ADMIN_EXISTS, nick); return MOD_CONT; } res = slist_add(&servadmins, na->nc); if (res == -2) { notice_lang(s_OperServ, u, OPER_ADMIN_REACHED_LIMIT, nick); return MOD_CONT; } else { if (na->nc->flags & NI_SERVICES_OPER && (res = slist_indexof(&servopers, na->nc)) != -1) { slist_delete(&servopers, res); na->nc->flags |= NI_SERVICES_ADMIN; notice_lang(s_OperServ, u, OPER_ADMIN_MOVED, nick); } else if (na->nc->flags & NI_SERVICES_HELPOP && (res = slist_indexof(&servhelpops, na->nc)) != -1) { slist_delete(&servhelpops, res); na->nc->flags |= NI_SERVICES_ADMIN; notice_lang(s_OperServ, u, OPER_ADMIN_MOVED, nick); } else { na->nc->flags |= NI_SERVICES_ADMIN; notice_lang(s_OperServ, u, OPER_ADMIN_ADDED, nick); } LogStaffAction(STAFFLOG_CHANNEL | STAFFLOG_OPERGLOBAL, "OperServ", "%s!%s@%s added %s to the services admin list", u->nick, u->username, u->host, nick); } if (readonly) notice_lang(s_OperServ, u, READ_ONLY_MODE); } else if (!stricmp(cmd, "DEL")) { if (!is_services_root(u)) { notice_lang(s_OperServ, u, PERMISSION_DENIED); return MOD_CONT; } if (servadmins.count == 0) { notice_lang(s_OperServ, u, OPER_ADMIN_LIST_EMPTY); return MOD_CONT; } if (isdigit(*nick) && strspn(nick, "1234567890,-") == strlen(nick)) { /* Deleting a range */ res = slist_delete_range(&servadmins, nick, NULL); if (res == 0) { notice_lang(s_OperServ, u, OPER_ADMIN_NO_MATCH); return MOD_CONT; } else if (res == 1) { notice_lang(s_OperServ, u, OPER_ADMIN_DELETED_ONE); } else { notice_lang(s_OperServ, u, OPER_ADMIN_DELETED_SEVERAL, res); } } else { if (!(na = findnick(nick))) { notice_lang(s_OperServ, u, NICK_X_NOT_REGISTERED, nick); return MOD_CONT; } if (na->status & NS_VERBOTEN) { notice_lang(s_OperServ, u, NICK_X_FORBIDDEN, nick); return MOD_CONT; } if (!(na->nc->flags & NI_SERVICES_ADMIN) || (res = slist_indexof(&servadmins, na->nc)) == -1) { notice_lang(s_OperServ, u, OPER_ADMIN_NOT_FOUND, nick); return MOD_CONT; } slist_delete(&servadmins, res); notice_lang(s_OperServ, u, OPER_ADMIN_DELETED, nick); } if (readonly) notice_lang(s_OperServ, u, READ_ONLY_MODE); } else if (!stricmp(cmd, "LIST")) { int sent_header = 0; if (servadmins.count == 0) { notice_lang(s_OperServ, u, OPER_ADMIN_LIST_EMPTY); return MOD_CONT; } if (!nick || (isdigit(*nick) && strspn(nick, "1234567890,-") == strlen(nick))) { res = slist_enum(&servadmins, nick, &admin_list_callback, u, &sent_header); if (res == 0) { notice_lang(s_OperServ, u, OPER_ADMIN_NO_MATCH); return MOD_CONT; } else { notice_lang(s_OperServ, u, END_OF_ANY_LIST, "Admin"); } } else { int i; for (i = 0; i < servadmins.count; i++) if (!stricmp (nick, ((NickCore *) servadmins.list[i])->display) || match_wild_nocase(nick, ((NickCore *) servadmins. list[i])->display)) admin_list(i + 1, servadmins.list[i], u, &sent_header); if (!sent_header) notice_lang(s_OperServ, u, OPER_ADMIN_NO_MATCH); else { notice_lang(s_OperServ, u, END_OF_ANY_LIST, "Admin"); } } } else if (!stricmp(cmd, "CLEAR")) { if (!is_services_root(u)) { notice_lang(s_OperServ, u, PERMISSION_DENIED); return MOD_CONT; } if (servadmins.count == 0) { notice_lang(s_OperServ, u, OPER_ADMIN_LIST_EMPTY); return MOD_CONT; } slist_clear(&servadmins, 1); notice_lang(s_OperServ, u, OPER_ADMIN_CLEAR); } else { syntax_error(s_OperServ, u, "ADMIN", OPER_ADMIN_SYNTAX); } return MOD_CONT; }