static int do_saset_display(User * u, NickCore * nc, char *param) { int i; NickAlias *na; /* First check whether param is a valid nick of the group */ for (i = 0; i < nc->aliases.count; i++) { na = nc->aliases.list[i]; if (stricmp(na->nick, param) == 0) { param = na->nick; /* Because case may differ */ break; } } if (i == nc->aliases.count) { notice_lang(s_NickServ, u, NICK_SASET_DISPLAY_INVALID, nc->display); return MOD_CONT; } alog("%s: %s!%s@%s set the display of %s to: %s", s_NickServ, u->nick, u->username, u->host, nc->display, param); change_core_display(nc, param); notice_lang(s_NickServ, u, NICK_SASET_DISPLAY_CHANGED, nc->display); if (NSNickTracking) { for (i = 0; i < nc->aliases.count; ++i) { na = nc->aliases.list[i]; if (na->u && nick_identified(na->u)) nsStartNickTracking(na->u); } } 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; }
int DenoraInit(int argc, char **argv) { if (denora->protocoldebug) { protocol_debug(NULL, argc, argv); } /* Only 1 protocol module may be loaded */ if (protocolModuleLoaded()) { alog(LOG_NORMAL, langstr(ALOG_MOD_BE_ONLY_ONE)); return MOD_STOP; } moduleAddAuthor("Denora"); moduleAddVersion ("$Id$"); moduleSetType(PROTOCOL); pmodule_ircd_version("InspIRCd 1.1.x"); pmodule_ircd_cap(myIrcdcap); pmodule_ircd_var(myIrcd); pmodule_ircd_useTSMode(0); pmodule_irc_var(IRC_INSPIRCD11); IRCDModeInit(); pmodule_oper_umode(UMODE_o); moduleAddIRCDCmds(); moduleAddIRCDMsgs(); return MOD_CONT; }
void send_event(const char *name, int argc, ...) { va_list va; char *a; int idx = 0; char **argv; argv = (char **) malloc(sizeof(char *) * argc); va_start(va, argc); for (idx = 0; idx < argc; idx++) { a = va_arg(va, char *); argv[idx] = sstrdup(a); } va_end(va); if (debug) alog("debug: Emitting event \"%s\" (%d args)", name, argc); event_process_hook(name, argc, argv); /** * Now that the events have seen the message, free it up **/ for (idx = 0; idx < argc; idx++) { free(argv[idx]); } free(argv); }
int db_getservfromnick(char *nick) { int res = 0; #ifdef USE_MYSQL MYSQL_RES *mysql_res; #endif if (!denora->do_sql) { return -1; } SET_SEGV_LOCATION(); rdb_query(QUERY_HIGH, "SELECT servid FROM %s WHERE nick=\'%s\'", UserTable, nick); #ifdef USE_MYSQL mysql_res = mysql_store_result(mysql); if (mysql_res) { if (mysql_num_rows(mysql_res)) { mysql_row = mysql_fetch_row(mysql_res); res = strtol(mysql_row[0], NULL, 10); } else { alog(LOG_NONEXISTANT, "nickname not found ! %s", nick); } SET_SEGV_LOCATION(); mysql_free_result(mysql_res); } #endif return res; }
/** * Load data from the db file, and populate our ChanBanInfo lines * @return 0 for success **/ int mLoadData(void) { FILE *in; char *nick = NULL; int len = 0; NickCore *nc = NULL; /* will _never_ be this big thanks to the 512 limit of a message */ char buffer[2000]; if ((in = fopen(qdbBanDBName, "r")) == NULL) { alog("ns_qdbban: WARNING: can not open the %s database file! (it might not exist, this is not fatal)", qdbBanDBName); return 1; } else { while (fgets(buffer, 1500, in)) { nick = myStrGetToken(buffer, ' ', 0); if (nick) { len = strlen(nick); /* Take the \n from the end of the nick */ nick[len - 1] = '\0'; if ((nc = findcore(nick))) { moduleAddData(&nc->moduleData, "qdbban", "on"); } free(nick); } } return 0; } return 0; }
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; }
char *db_getchannel_byid(int chanid) { char *res = NULL; #ifdef USE_MYSQL MYSQL_RES *mysql_res; MYSQL_ROW row; #endif if (!denora->do_sql) { return NULL; } SET_SEGV_LOCATION(); rdb_query(QUERY_HIGH, "SELECT channel FROM %s WHERE chanid=%d", ChanTable, chanid); #ifdef USE_MYSQL mysql_res = mysql_store_result(mysql); if (mysql_res) { if (!mysql_num_rows(mysql_res)) { alog(LOG_NONEXISTANT, "channel not found ! %d", chanid); } else { row = mysql_fetch_row(mysql_res); res = rdb_escape(row[0]); } SET_SEGV_LOCATION(); mysql_free_result(mysql_res); } #endif return res; }
/** * 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(); } } }
/** * Create the command, and tell anope about it. * @param argc Argument count * @param argv Argument list * @return MOD_CONT to allow the module, MOD_STOP to stop it **/ int AnopeInit(int argc, char **argv) { Command *c; EvtHook *hook; moduleAddAuthor("Anope"); moduleAddVersion(VERSION_STRING); moduleSetType(CORE); /** * For some unknown reason, do_logonnews is actaully defined in news.c * we can look at moving it here later **/ c = createCommand("LOGONNEWS", do_logonnews, is_services_admin, NEWS_HELP_LOGON, -1, -1, -1, -1); c->help_param1 = (char *) (long) NewsCount; moduleAddCommand(OPERSERV, c, MOD_UNIQUE); moduleSetOperHelp(myOperServHelp); hook = createEventHook(EVENT_RELOAD, reload_config); if (moduleAddEventHook(hook) != MOD_ERR_OK) { alog("[\002os_logonnews\002] Can't hook to EVENT_RELOAD event"); return MOD_STOP; } return MOD_CONT; }
int DenoraInit(int argc, char **argv) { if (denora->protocoldebug) { protocol_debug(NULL, argc, argv); } /* Only 1 protocol module may be loaded */ if (protocolModuleLoaded()) { alog(LOG_NORMAL, langstr(ALOG_MOD_BE_ONLY_ONE)); return MOD_STOP; } moduleAddAuthor("Denora"); moduleAddVersion("$Id: bahamut.c 388 2011-01-04 21:12:18Z hal9000 $"); moduleSetType(PROTOCOL); pmodule_ircd_version("BahamutIRCd 1.4.*/1.8.*"); pmodule_ircd_cap(myIrcdcap); pmodule_ircd_var(myIrcd); pmodule_ircd_useTSMode(0); IRCDModeInit(); pmodule_oper_umode(UMODE_o); pmodule_irc_var(IRC_BAHAMUT); moduleAddIRCDCmds(); moduleAddIRCDMsgs(); return MOD_CONT; }
int set_topic(User * u, Channel *c, char *topic) { ChannelInfo *ci = c->ci; if (!my_check_access(u, ci, CA_TOPIC) && ((ci->flags & CI_TOPICLOCK) || !my_check_access(u, ci, CA_OPDEOPME))) notice_lang(ci->bi->nick, u, PERMISSION_DENIED); else { if (ci->last_topic) free(ci->last_topic); ci->last_topic = topic ? sstrdup(topic) : NULL; strscpy(ci->last_topic_setter, u->nick, NICKMAX); ci->last_topic_time = time(NULL); if (c->topic) free(c->topic); c->topic = topic ? sstrdup(topic) : NULL; strscpy(c->topic_setter, u->nick, NICKMAX); if (ircd->topictsbackward) { c->topic_time = c->topic_time - 1; } else { c->topic_time = ci->last_topic_time; } if (is_services_admin(u) && !check_access(u, ci, CA_TOPIC) && ((ci->flags & CI_TOPICLOCK) || !check_access(u, ci, CA_OPDEOPME))) alog("%s: %s!%s@%s changed topic of %s as services admin.", ci->bi->nick, u->nick, u->username, u->host, c->name); anope_cmd_topic(ci->bi->nick, c->name, u->nick, topic ? topic : "", c->topic_time); } return MOD_CONT; }
/* PONG */ void nefarious_cmd_pong(char *servname, char *who) { char *t, *s; uint32 ts, tsnow, value; t = myStrGetToken(who, '!', 1); s = myStrGetToken(t, '.', 0); if (!s) { ts = 0; } else { ts = strtol(s, NULL, 10); } tsnow = time(NULL); value = tsnow - ts; if (denora->protocoldebug) { alog(LOG_PROTOCOL, "PONG: Server Name %s : Who %s", servname, who); } send_cmd(p10id, "Z %s %ld %ld %ld %s", p10id, (long int) ts, (long int) tsnow, (long int) value, militime_float(NULL)); if (s) { free(s); } if (t) { free(t); } }
/** * Helper routine to try and write up to one chunk of data from the buffer * to the socket. Return how much was written. * @param wait Wait * @return int */ static int flush_write_buffer(int wait) { fd_set fds; struct timeval tv = { 0, 0 }; int errno_save = ano_sockgeterr(); if (write_bufend == write_curpos || write_fd == -1) return 0; FD_ZERO(&fds); FD_SET(write_fd, &fds); if (select(write_fd + 1, 0, &fds, 0, wait ? NULL : &tv) == 1) { int maxwrite, nwritten; if (write_curpos > write_bufend) /* wrapped around? */ maxwrite = write_buftop - write_curpos; else if (write_bufend == write_netbuf) maxwrite = write_buftop - write_curpos - 1; else maxwrite = write_bufend - write_curpos; nwritten = ano_sockwrite(write_fd, write_curpos, maxwrite); errno_save = ano_sockgeterr(); if (debug >= 3) alog("debug: flush_write_buffer wanted %d, got %d", maxwrite, nwritten); if (nwritten > 0) { write_curpos += nwritten; if (write_curpos == write_buftop) write_curpos = write_netbuf; total_written += nwritten; return nwritten; } } ano_sockseterr(errno_save); return 0; }
/* * ENCAP handler * av[0] = servermask (not used) * av[1] = command * av[2] and beyond are dynamic. */ int anope_event_encap (char *source, int ac, char **av) { if (ac < 2) return MOD_CONT; if (!stricmp (av[1], "CHGHOST")) { User *u; if (ac != 4) return MOD_CONT; u = finduser (av[2]); if (!u) { if (debug) { alog ("debug: CHGHOST for nonexistent user %s", av[2]); } return MOD_CONT; } change_user_host (u, av[3]); return MOD_CONT; } return MOD_CONT; }
static void my_load_config(void) { int i; char *tmp = NULL; Directive confvalues[][1] = { {{"HSRequestMemoUser", {{PARAM_SET, PARAM_RELOAD, &HSRequestMemoUser}}}}, {{"HSRequestMemoOper", {{PARAM_SET, PARAM_RELOAD, &HSRequestMemoOper}}}}, {{"HSRequestMemoSetters", {{PARAM_SET, PARAM_RELOAD, &HSRequestMemoSetters}}}}, {{"HSRequestDBName", {{PARAM_STRING, PARAM_RELOAD, &tmp}}}} }; for (i = 0; i < 4; i++) moduleGetConfigDirective(confvalues[i]); if (tmp) { if (HSRequestDBName) free(HSRequestDBName); HSRequestDBName = sstrdup(tmp); } else { HSRequestDBName = sstrdup(HSREQ_DEFAULT_DBNAME); } if (debug) alog("debug: [hs_request] Set config vars: MemoUser=%d MemoOper=%d MemoSetters=%d DBName='%s'", HSRequestMemoUser, HSRequestMemoOper, HSRequestMemoSetters, HSRequestDBName); }
/* Enforcing functions */ static void do_enforce_secureops(Channel * c) { struct c_userlist *user; struct c_userlist *next; ChannelInfo *ci; uint32 flags; if (!(ci = c->ci)) return; if (debug) alog("debug: cs_enforce: Enforcing SECUREOPS on %s", c->name); /* Dirty hack to allow chan_set_correct_modes to work ok. * We pretend like SECUREOPS is on so it doesn't ignore that * part of the code. This way we can enforce SECUREOPS even * if it's off. */ flags = ci->flags; ci->flags |= CI_SECUREOPS; for (user = c->users; user; user = next) { next = user->next; chan_set_correct_modes(user->user, c, 0); } ci->flags = flags; }
/* chan should be db_escape'd before call */ int db_getchannel_users(char *chan) { int res = 0; #ifdef USE_MYSQL MYSQL_RES *mysql_res; #endif SET_SEGV_LOCATION(); strtolwr(chan); if (!denora->do_sql) { return -1; } SET_SEGV_LOCATION(); rdb_query(QUERY_HIGH, "SELECT currentusers FROM %s WHERE channel=\'%s\'", ChanTable, chan); #ifdef USE_MYSQL mysql_res = mysql_store_result(mysql); SET_SEGV_LOCATION(); if (mysql_res) { if (mysql_num_rows(mysql_res)) { res = strtol(*mysql_fetch_row(mysql_res), NULL, 10); } else { alog(LOG_DEBUG, "debug: unable to find the requested channel %s", chan); } SET_SEGV_LOCATION(); mysql_free_result(mysql_res); } #endif return res; }
VOIDSIG signal_rehash(int signum) { #ifdef POSIX_SIGNALS struct sigaction act; #endif #ifdef SIGHUP if (signum == SIGHUP) { #endif Dadmin *a; int i; alog(LOG_NORMAL, "Received SIGHUP: Saving Databases & Rehash Configuration"); if (initconf(denora->config, 1, mainconf) == -1) { denora->qmsg = calloc(50, 1); if (!denora->qmsg) { denora->qmsg = sstrdup(langstr(ALOG_ERR_REHASH_NO_MEM)); } else { ircsnprintf(denora->qmsg, sizeof(denora->qmsg), "%s", langstr(ALOG_ERR_REHASH)); } denora->quitting = 1; send_event(EVENT_SIGNAL, 2, "SIGHUP", denora->qmsg); } else { /* Remove all config file admins from admin struct before re-reading config file */ for (i = 0; i < 1024; i++) { for (a = adminlists[i]; a; a = a->next) { if (a->configfile) { free_admin(a); } break; } } merge_confs(); } /* Reload GeoIP db files */ if (gi) { GeoIP_delete(gi); } if (gi_v6) { GeoIP_delete(gi_v6); } gi = GeoIP_new(GEOIP_STANDARD); gi_v6 = GeoIP_open_type(GEOIP_COUNTRY_EDITION_V6, GEOIP_STANDARD); #ifdef POSIX_SIGNALS act.sa_handler = signal_rehash; act.sa_flags = 0; (void) sigemptyset(&act.sa_mask); (void) sigaddset(&act.sa_mask, SIGHUP); (void) sigaction(SIGHUP, &act, NULL); #else # ifndef _WIN32 (void) signal(SIGHUP, signal_rehash); /* sysV -argv */ # endif #endif #ifdef SIGHUP } #endif }
void db_removenick(char *nick, char *reason) { char *sqlreason; int nickid = db_getnick(nick); SET_SEGV_LOCATION(); if (!denora->do_sql) { return; } if (nickid == 0) { alog(LOG_DEBUG, "nickid 0"); return; } SET_SEGV_LOCATION(); db_removefromchans(nickid); if (UserCacheTime) { sqlreason = rdb_escape(reason); rdb_query(QUERY_LOW, "UPDATE %s SET online=\'N\', lastquit=NOW(), lastquitmsg=\'%s\', servid=0 WHERE nickid=%d", UserTable, sqlreason, nickid); if (sqlreason) { free(sqlreason); } } else { rdb_query(QUERY_LOW, "DELETE FROM %s WHERE nickid=%d", UserTable, nickid); } SET_SEGV_LOCATION(); }
static void ATHEME_CONVERT_write_akills(void) { int i; if (!f) return; if (!akills.count) return; alog("[convert to atheme] converting akills..."); for (i = 0; i < akills.count; i++) { Akill *ak = akills.list[i]; const char *username = ak->user; const char *hostname = ak->host; if (!username || !*username) username = "******"; if (!hostname || !*hostname) continue; fprintf(f, "KL %s %s %lu %lu %s %s\n", username, hostname, (unsigned long)(ak->expires == 0 ? 0 : ak->expires - ak->seton), (unsigned long)ak->seton, ak->by, ak->reason); klnout++; } }
void AnopeFini(void) { csav_save_db(); if (CSAVoiceDBName) free(CSAVoiceDBName); alog("cs_autovoice: Module unloaded."); }
int DenoraInit(int argc, char **argv) { if (denora->protocoldebug) { protocol_debug(NULL, argc, argv); } /* Only 1 protocol module may be loaded */ if (protocolModuleLoaded()) { alog(LOG_NORMAL, langstr(ALOG_MOD_BE_ONLY_ONE)); return MOD_STOP; } /* Actual module code stuff */ moduleAddAuthor("Denora"); moduleAddVersion("$Id: asuka.c 388 2011-01-04 21:12:18Z hal9000 $"); moduleSetType(PROTOCOL); /* protocol version and name that we support */ pmodule_ircd_version("Asuka 1.2.1"); /* set the flag of what ircd */ pmodule_irc_var(IRC_ASUKA); pmodule_ircd_cap(myIrcdcap); pmodule_ircd_var(myIrcd); pmodule_ircd_useTSMode(0); IRCDModeInit(); pmodule_oper_umode(UMODE_o); moduleAddIRCDCmds(); moduleAddIRCDMsgs(); return MOD_CONT; }
void alog_open(char *fname, int use_localtm, int use_markers) { FILE *f; use_localtime = use_localtm; markers = use_markers; if (file != NULL) { warning(0, "Opening an already opened access log"); alog_close(); } if (strlen(fname) > FILENAME_MAX) { error(0, "Access Log filename too long: `%s', cannot open.", fname); return; } if (writers == NULL) writers = gwlist_create(); f = fopen(fname, "a"); if (f == NULL) { error(errno, "Couldn't open logfile `%s'.", fname); return; } file = f; strcpy(filename, fname); info(0, "Started access logfile `%s'.", filename); if (markers) alog("Log begins"); }
/** * strdup, replacement so we can trap for "out of memory" * @param oldptr Old Pointer * @param newsize Size of new pointer * @return void */ char *sstrdup(const char *src) { char *ret = NULL; if (src) { #ifdef __STRICT_ANSI__ if ((ret = (char *) malloc(strlen(src) + 1))) {; strlcpy(ret, src, sizeof(ret)); } #else ret = strdup(src); #endif if (!ret) #ifndef _WIN32 raise(SIGUSR1); #else abort(); #endif } else { alog("sstrdup() called with NULL-arg"); if (debug) do_backtrace(0); } return ret; }
int DenoraInit(int argc, char **argv) { if (denora->protocoldebug) { protocol_debug(NULL, argc, argv); } /* Only 1 protocol module may be loaded */ if (protocolModuleLoaded()) { alog(LOG_NORMAL, langstr(ALOG_MOD_BE_ONLY_ONE)); return MOD_STOP; } moduleAddAuthor("Denora"); moduleAddVersion("$Id: scarynet.c 64 2007-05-08 16:48:13Z outsider $"); moduleSetType(PROTOCOL); pmodule_ircd_version("ScaryNet IRCu 2.10.11"); pmodule_ircd_cap(myIrcdcap); pmodule_ircd_var(myIrcd); pmodule_ircd_useTSMode(0); pmodule_irc_var(IRC_SCARYNET); IRCDModeInit(); pmodule_oper_umode(UMODE_o); moduleAddIRCDCmds(); moduleAddIRCDMsgs(); return MOD_CONT; }
void queue_signal(void) { #ifdef USE_THREADS alog(LOG_DEBUG, "debug: Thread %ld: Signaling proxy queue condition", (long int) deno_thread_self()); deno_cond_signal(queuecond); #endif }
void queue_lock(void) { #ifdef USE_THREADS alog(LOG_DEBUG, "debug: Thread %ld: Locking proxy queue mutex", (long int) deno_thread_self()); deno_mutex_lock(queuemut); #endif }
void queue_wait(void) { #ifdef USE_THREADS alog(LOG_DEBUG, "debug: Thread %ld: waiting proxy queue condition", (long int) deno_thread_self()); deno_cond_wait(queuecond, queuemut); #endif }
void queue_unlock(void *arg) { #ifdef USE_THREADS alog(LOG_DEBUG, "debug: Thread %ld: Unlocking queue mutex", (long int) deno_thread_self()); deno_mutex_unlock(queuemut); #endif }