Anope IRC Services  Version 1.8
cs_register.c
Go to the documentation of this file.
1 /* ChanServ core functions
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  * Based on the original code of Epona by Lara.
9  * Based on the original code of Services by Andy Church.
10  *
11  *
12  */
13 /*************************************************************************/
14 
15 #include "module.h"
16 
17 static int do_register(User * u);
18 static void myChanServHelp(User * u);
19 
26 int AnopeInit(int argc, char **argv)
27 {
28  Command *c;
29 
30  moduleAddAuthor("Anope");
31  moduleAddVersion(VERSION_STRING);
33 
34  c = createCommand("REGISTER", do_register, NULL, CHAN_HELP_REGISTER,
35  -1, -1, -1, -1);
38 
40 
41  return MOD_CONT;
42 }
43 
47 void AnopeFini(void)
48 {
49 
50 }
51 
52 
53 
58 static void myChanServHelp(User * u)
59 {
60  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_REGISTER);
61 }
62 
68 static int do_register(User * u)
69 {
70  char *chan = strtok(NULL, " ");
71  char *pass = strtok(NULL, " ");
72  char *desc = strtok(NULL, "");
73  NickCore *nc;
74  Channel *c;
75  ChannelInfo *ci;
76  struct u_chaninfolist *uc;
77  int is_servadmin = is_services_admin(u);
78  char tmp_pass[PASSMAX];
79 
80  if (readonly) {
81  notice_lang(s_ChanServ, u, CHAN_REGISTER_DISABLED);
82  return MOD_CONT;
83  }
84 
86  notice_lang(s_ChanServ, u, OPER_DEFCON_DENIED);
87  return MOD_CONT;
88  }
89 
90  if (!desc) {
91  syntax_error(s_ChanServ, u, "REGISTER", CHAN_REGISTER_SYNTAX);
92  } else if (*chan == '&') {
93  notice_lang(s_ChanServ, u, CHAN_REGISTER_NOT_LOCAL);
94  } else if (*chan != '#') {
95  notice_lang(s_ChanServ, u, CHAN_SYMBOL_REQUIRED);
96  } else if (!anope_valid_chan(chan)) {
97  notice_lang(s_ChanServ, u, CHAN_X_INVALID, chan);
98  } else if (!u->na || !(nc = u->na->nc)) {
99  notice_lang(s_ChanServ, u, CHAN_MUST_REGISTER_NICK, s_NickServ);
100  } else if (!nick_recognized(u)) {
101  notice_lang(s_ChanServ, u, CHAN_MUST_IDENTIFY_NICK, s_NickServ,
102  s_NickServ);
103  } else if (!(c = findchan(chan))) {
104  notice_lang(s_ChanServ, u, CHAN_REGISTER_NONE_CHANNEL, chan);
105  } else if ((ci = cs_findchan(chan)) != NULL) {
106  if (ci->flags & CI_VERBOTEN) {
107  alog("%s: Attempt to register FORBIDden channel %s by %s!%s@%s", s_ChanServ, ci->name, u->nick, u->username, u->host);
108  notice_lang(s_ChanServ, u, CHAN_MAY_NOT_BE_REGISTERED, chan);
109  } else {
110  notice_lang(s_ChanServ, u, CHAN_ALREADY_REGISTERED, chan);
111  }
112  } else if (!stricmp(chan, "#")) {
113  notice_lang(s_ChanServ, u, CHAN_MAY_NOT_BE_REGISTERED, chan);
114  } else if (!chan_has_user_status(c, u, CUS_OP)) {
115  notice_lang(s_ChanServ, u, CHAN_MUST_BE_CHANOP);
116 
117  } else if (!is_servadmin && nc->channelmax > 0
118  && nc->channelcount >= nc->channelmax) {
120  nc->channelmax ? CHAN_EXCEEDED_CHANNEL_LIMIT :
121  CHAN_REACHED_CHANNEL_LIMIT, nc->channelmax);
122  } else if (stricmp(u->nick, pass) == 0
123  || (StrictPasswords && strlen(pass) < 5)) {
124  notice_lang(s_ChanServ, u, MORE_OBSCURE_PASSWORD);
125  } else if(enc_encrypt_check_len(strlen(pass), PASSMAX - 1)) {
126  notice_lang(s_ChanServ, u, PASSWORD_TOO_LONG);
127  } else if (!(ci = makechan(chan))) {
128  alog("%s: makechan() failed for REGISTER %s", s_ChanServ, chan);
129  notice_lang(s_ChanServ, u, CHAN_REGISTRATION_FAILED);
130 
131  } else if (enc_encrypt(pass, strlen(pass), ci->founderpass, PASSMAX - 1) < 0) {
132  alog("%s: Couldn't encrypt password for %s (REGISTER)",
133  s_ChanServ, chan);
134  notice_lang(s_ChanServ, u, CHAN_REGISTRATION_FAILED);
135  delchan(ci);
136  } else {
137  c->ci = ci;
138  ci->c = c;
139  ci->bantype = CSDefBantype;
140  ci->flags = CSDefFlags;
141  ci->mlock_on = ircd->defmlock;
142  ci->memos.memomax = MSMaxMemos;
143  ci->last_used = ci->time_registered;
144  ci->founder = nc;
145 
146  ci->desc = sstrdup(desc);
147  if (c->topic) {
148  ci->last_topic = sstrdup(c->topic);
150  ci->last_topic_time = c->topic_time;
151  } else {
152  /* Set this to something, otherwise it will maliform the topic */
154  }
155  ci->bi = NULL;
156  ci->botflags = BSDefFlags;
157  ci->founder->channelcount++;
158  alog("%s: Channel '%s' registered by %s!%s@%s", s_ChanServ, chan,
159  u->nick, u->username, u->host);
160  notice_lang(s_ChanServ, u, CHAN_REGISTERED, chan, u->nick);
161 
162  if(enc_decrypt(ci->founderpass,tmp_pass,PASSMAX - 1) == 1) {
163  notice_lang(s_ChanServ, u, CHAN_PASSWORD_IS, tmp_pass);
164  }
165 
166  uc = scalloc(sizeof(*uc), 1);
167  uc->next = u->founder_chans;
168  uc->prev = NULL;
169  if (u->founder_chans)
170  u->founder_chans->prev = uc;
171  u->founder_chans = uc;
172  uc->chan = ci;
173  /* Implement new mode lock */
174  check_modes(c);
175  /* On most ircds you do not receive the admin/owner mode till its registered */
176  if (ircd->admin) {
177  anope_cmd_mode(s_ChanServ, chan, "%s %s", ircd->adminset,
178  GET_USER(u));
179  }
180  if (ircd->owner && ircd->ownerset) {
181  anope_cmd_mode(s_ChanServ, chan, "%s %s", ircd->ownerset,
182  GET_USER(u));
183  }
185  }
186  return MOD_CONT;
187 }
E int CSDefBantype
Definition: extern.h:405
E int readonly
Definition: extern.h:776
char nick[NICKMAX]
Definition: services.h:875
E int chan_has_user_status(Channel *chan, User *user, int16 status)
Definition: channels.c:124
uint32 botflags
Definition: services.h:700
char * ownerset
Definition: services.h:303
E int checkDefCon(int level)
Definition: operserv.c:1608
struct user_::u_chaninfolist * founder_chans
E IRCDVar * ircd
Definition: extern.h:39
static int do_register(User *u)
Definition: cs_register.c:68
E int anope_valid_chan(char *chan)
Definition: ircd.c:666
time_t last_used
Definition: services.h:664
void AnopeFini(void)
Definition: cs_register.c:47
E void send_event(const char *name, int argc,...)
Definition: events.c:37
char founderpass[PASSMAX]
Definition: services.h:658
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
#define CI_VERBOTEN
Definition: services.h:725
char topic_setter[NICKMAX]
Definition: services.h:1004
char * host
Definition: services.h:878
E int BSDefFlags
Definition: extern.h:420
E char * strscpy(char *d, const char *s, size_t len)
Definition: db-merger.c:1886
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
ChannelInfo * ci
Definition: services.h:1001
E void syntax_error(char *service, User *u, const char *command, int msgnum)
Definition: language.c:295
char name[CHANMAX]
Definition: services.h:654
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
time_t last_topic_time
Definition: services.h:667
E int nick_recognized(User *u)
Definition: nickserv.c:1131
char last_topic_setter[NICKMAX]
Definition: services.h:666
char * last_topic
Definition: services.h:665
E Channel * findchan(const char *chan)
Definition: channels.c:394
E char * sstrdup(const char *s)
Definition: memory.c:105
char * help_param1
Definition: modules.h:187
NickCore * nc
Definition: services.h:533
E void * scalloc(long elsize, long els)
Definition: memory.c:55
int16 bantype
Definition: services.h:673
E int enc_encrypt(const char *src, int len, char *dest, int size)
Definition: encrypt.c:50
uint32 defmlock
Definition: services.h:347
uint32 flags
Definition: services.h:669
int16 memomax
Definition: services.h:505
#define PASSMAX
Definition: config.h:65
uint16 channelcount
Definition: services.h:553
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
ChannelInfo * chan
Definition: services.h:906
struct channel_ * c
Definition: services.h:692
MDE void moduleSetChanHelp(void(*func)(User *u))
Definition: modules.c:2090
static void myChanServHelp(User *u)
Definition: cs_register.c:58
Command * c
Definition: ns_recover.c:17
#define CHANSERV
Definition: modules.h:60
E void alog(const char *fmt,...) FORMAT(printf
#define MOD_CONT
Definition: modules.h:54
#define DEFCON_NO_NEW_CHANNELS
Definition: services.h:1254
char * adminset
Definition: services.h:305
E void check_modes(Channel *c)
Definition: chanserv.c:1081
E int delchan(ChannelInfo *ci)
Definition: chanserv.c:2063
E int is_services_admin(User *u)
Definition: operserv.c:591
int AnopeInit(int argc, char **argv)
Definition: cs_register.c:26
E int enc_encrypt_check_len(int passlen, int bufsize)
Definition: encrypt.c:66
char * username
Definition: services.h:877
char * topic
Definition: services.h:1003
uint16 channelmax
Definition: services.h:554
E int CSDefFlags
Definition: extern.h:402
E void anope_cmd_mode(char *source, char *dest, const char *fmt,...)
Definition: ircd.c:211
Definition: modules.h:99
MDE Command * createCommand(const char *name, int(*func)(User *u), int(*has_priv)(User *u), int help_all, int help_reg, int help_oper, int help_admin, int help_root)
Definition: modules.c:987
#define EVENT_CHAN_REGISTERED
Definition: events.h:32
#define NICKMAX
Definition: config.h:62
time_t topic_time
Definition: services.h:1005
MemoInfo memos
Definition: services.h:690
E int StrictPasswords
Definition: extern.h:341
int admin
Definition: services.h:324
time_t time_registered
Definition: services.h:663
#define GET_USER(u)
Definition: services.h:270
E ChannelInfo * cs_findchan(const char *chan)
Definition: db-merger.c:2000
int owner
Definition: services.h:302
E int enc_decrypt(const char *src, char *dest, int size)
Definition: encrypt.c:80
E char * s_ChanServ
Definition: extern.h:285
char * desc
Definition: services.h:659
struct u_chaninfolist * prev
Definition: services.h:905
E char * s_NickServ
Definition: extern.h:284
E int MSMaxMemos
Definition: extern.h:415
BotInfo * bi
Definition: services.h:699
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
NickCore * founder
Definition: services.h:655
E ChannelInfo * makechan(const char *chan)
Definition: chanserv.c:2042
#define CUS_OP
Definition: services.h:1341
uint32 mlock_on
Definition: services.h:681
NickAlias * na
Definition: services.h:892
#define MOD_UNIQUE
Definition: module.h:11