cs_register.c

Go to the documentation of this file.
00001 /* ChanServ core functions
00002  *
00003  * (C) 2003-2007 Anope Team
00004  * Contact us at info@anope.org
00005  *
00006  * Please read COPYING and README for further details.
00007  *
00008  * Based on the original code of Epona by Lara.
00009  * Based on the original code of Services by Andy Church. 
00010  * 
00011  * $Id: cs_register.c 1270 2007-08-27 03:23:06Z drstein $
00012  *
00013  */
00014 /*************************************************************************/
00015 
00016 #include "module.h"
00017 
00018 int do_register(User * u);
00019 void myChanServHelp(User * u);
00020 
00027 int AnopeInit(int argc, char **argv)
00028 {
00029     Command *c;
00030 
00031     moduleAddAuthor("Anope");
00032     moduleAddVersion("$Id: cs_register.c 1270 2007-08-27 03:23:06Z drstein $");
00033     moduleSetType(CORE);
00034 
00035     c = createCommand("REGISTER", do_register, NULL, CHAN_HELP_REGISTER,
00036                       -1, -1, -1, -1);
00037     c->help_param1 = s_NickServ;
00038     moduleAddCommand(CHANSERV, c, MOD_UNIQUE);
00039 
00040     moduleSetChanHelp(myChanServHelp);
00041 
00042     return MOD_CONT;
00043 }
00044 
00048 void AnopeFini(void)
00049 {
00050 
00051 }
00052 
00053 
00054 
00059 void myChanServHelp(User * u)
00060 {
00061     notice_lang(s_ChanServ, u, CHAN_HELP_CMD_REGISTER);
00062 }
00063 
00069 int do_register(User * u)
00070 {
00071     char *chan = strtok(NULL, " ");
00072     char *pass = strtok(NULL, " ");
00073     char *desc = strtok(NULL, "");
00074     NickCore *nc;
00075     Channel *c;
00076     ChannelInfo *ci;
00077     struct u_chaninfolist *uc;
00078     int is_servadmin = is_services_admin(u);
00079     char founderpass[PASSMAX + 1];
00080     char tmp_pass[PASSMAX];
00081 
00082     if (readonly) {
00083         notice_lang(s_ChanServ, u, CHAN_REGISTER_DISABLED);
00084         return MOD_CONT;
00085     }
00086 
00087     if (checkDefCon(DEFCON_NO_NEW_CHANNELS)) {
00088         notice_lang(s_ChanServ, u, OPER_DEFCON_DENIED);
00089         return MOD_CONT;
00090     }
00091 
00092     if (!desc) {
00093         syntax_error(s_ChanServ, u, "REGISTER", CHAN_REGISTER_SYNTAX);
00094     } else if (*chan == '&') {
00095         notice_lang(s_ChanServ, u, CHAN_REGISTER_NOT_LOCAL);
00096     } else if (*chan != '#') {
00097         notice_lang(s_ChanServ, u, CHAN_SYMBOL_REQUIRED);
00098     } else if (!anope_valid_chan(chan)) {
00099         notice_lang(s_ChanServ, u, CHAN_X_INVALID, chan);
00100     } else if (!u->na || !(nc = u->na->nc)) {
00101         notice_lang(s_ChanServ, u, CHAN_MUST_REGISTER_NICK, s_NickServ);
00102     } else if (!nick_recognized(u)) {
00103         notice_lang(s_ChanServ, u, CHAN_MUST_IDENTIFY_NICK, s_NickServ,
00104                     s_NickServ);
00105     } else if (!(c = findchan(chan))) {
00106         notice_lang(s_ChanServ, u, CHAN_REGISTER_NONE_CHANNEL, chan);
00107     } else if ((ci = cs_findchan(chan)) != NULL) {
00108         if (ci->flags & CI_VERBOTEN) {
00109             alog("%s: Attempt to register FORBIDden channel %s by %s!%s@%s", s_ChanServ, ci->name, u->nick, u->username, u->host);
00110             notice_lang(s_ChanServ, u, CHAN_MAY_NOT_BE_REGISTERED, chan);
00111         } else {
00112             notice_lang(s_ChanServ, u, CHAN_ALREADY_REGISTERED, chan);
00113         }
00114     } else if (!stricmp(chan, "#")) {
00115         notice_lang(s_ChanServ, u, CHAN_MAY_NOT_BE_REGISTERED, chan);
00116     } else if (!chan_has_user_status(c, u, CUS_OP)) {
00117         notice_lang(s_ChanServ, u, CHAN_MUST_BE_CHANOP);
00118 
00119     } else if (!is_servadmin && nc->channelmax > 0
00120                && nc->channelcount >= nc->channelmax) {
00121         notice_lang(s_ChanServ, u,
00122                     nc->channelcount >
00123                     nc->
00124                     channelmax ? CHAN_EXCEEDED_CHANNEL_LIMIT :
00125                     CHAN_REACHED_CHANNEL_LIMIT, nc->channelmax);
00126     } else if (stricmp(u->nick, pass) == 0
00127                || (StrictPasswords && strlen(pass) < 5)) {
00128         notice_lang(s_ChanServ, u, MORE_OBSCURE_PASSWORD);
00129     } else if (!(ci = makechan(chan))) {
00130         alog("%s: makechan() failed for REGISTER %s", s_ChanServ, chan);
00131         notice_lang(s_ChanServ, u, CHAN_REGISTRATION_FAILED);
00132 
00133     } else if (strscpy(founderpass, pass, PASSMAX + 1),
00134                enc_encrypt_in_place(founderpass, PASSMAX) < 0) {
00135         alog("%s: Couldn't encrypt password for %s (REGISTER)",
00136              s_ChanServ, chan);
00137         notice_lang(s_ChanServ, u, CHAN_REGISTRATION_FAILED);
00138         delchan(ci);
00139     } else {
00140         c->ci = ci;
00141         ci->c = c;
00142         ci->bantype = CSDefBantype;
00143         ci->flags = CSDefFlags;
00144         ci->mlock_on = ircd->defmlock;
00145         ci->memos.memomax = MSMaxMemos;
00146         ci->last_used = ci->time_registered;
00147         ci->founder = nc;
00148         if (strlen(pass) > PASSMAX)
00149             notice_lang(s_ChanServ, u, PASSWORD_TRUNCATED, PASSMAX);
00150         memset(pass, 0, strlen(pass));
00151         memcpy(ci->founderpass, founderpass, PASSMAX);
00152         ci->desc = sstrdup(desc);
00153         if (c->topic) {
00154             ci->last_topic = sstrdup(c->topic);
00155             strscpy(ci->last_topic_setter, c->topic_setter, NICKMAX);
00156             ci->last_topic_time = c->topic_time;
00157         } else {
00158             /* Set this to something, otherwise it will maliform the topic */
00159             strscpy(ci->last_topic_setter, s_ChanServ, NICKMAX);
00160         }
00161         ci->bi = NULL;
00162         ci->botflags = BSDefFlags;
00163         ci->founder->channelcount++;
00164         alog("%s: Channel '%s' registered by %s!%s@%s", s_ChanServ, chan,
00165              u->nick, u->username, u->host);
00166         notice_lang(s_ChanServ, u, CHAN_REGISTERED, chan, u->nick);
00167     
00168     if(enc_decrypt(ci->founderpass,tmp_pass,PASSMAX) == 1) {
00169             notice_lang(s_ChanServ, u, CHAN_PASSWORD_IS, ci->founderpass);
00170     }
00171 
00172         uc = scalloc(sizeof(*uc), 1);
00173         uc->next = u->founder_chans;
00174         uc->prev = NULL;
00175         if (u->founder_chans)
00176             u->founder_chans->prev = uc;
00177         u->founder_chans = uc;
00178         uc->chan = ci;
00179         /* Implement new mode lock */
00180         check_modes(c);
00181         /* On most ircds you do not receive the admin/owner mode till its registered */
00182         if (ircd->admin) {
00183             anope_cmd_mode(s_ChanServ, chan, "%s %s", ircd->adminset,
00184                            u->nick);
00185         }
00186         if (ircd->owner && ircd->ownerset) {
00187             anope_cmd_mode(s_ChanServ, chan, "%s %s", ircd->ownerset,
00188                            u->nick);
00189         }
00190         send_event(EVENT_CHAN_REGISTERED, 1, chan);
00191     }
00192     return MOD_CONT;
00193 }

Generated on Sun Dec 30 09:26:47 2007 for Anope by  doxygen 1.5.1-20070107