Anope IRC Services  Version 1.8
hs_set.c
Go to the documentation of this file.
1 /* HostServ 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 myDoSet(User * u);
18 static void myHostServHelp(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("SET", myDoSet, is_host_setter, HOST_HELP_SET, -1,
35  -1, -1, -1);
37 
39 
40  return MOD_CONT;
41 }
42 
46 void AnopeFini(void)
47 {
48 
49 }
50 
51 
52 
57 static void myHostServHelp(User * u)
58 {
59  if (is_host_setter(u)) {
60  notice_lang(s_HostServ, u, HOST_HELP_CMD_SET);
61  }
62 }
63 
69 static int myDoSet(User * u)
70 {
71  char *nick = strtok(NULL, " ");
72  char *rawhostmask = strtok(NULL, " ");
73  char *hostmask = smalloc(HOSTMAX);
74 
75  NickAlias *na;
76  int32 tmp_time;
77  char *s;
78 
79  char *vIdent = NULL;
80 
81  if (!nick || !rawhostmask) {
82  syntax_error(s_HostServ, u, "SET", HOST_SET_SYNTAX);
83  free(hostmask);
84  return MOD_CONT;
85  }
86 
87  vIdent = myStrGetOnlyToken(rawhostmask, '@', 0); /* Get the first substring, @ as delimiter */
88  if (vIdent) {
89  rawhostmask = myStrGetTokenRemainder(rawhostmask, '@', 1); /* get the remaining string */
90  if (!rawhostmask) {
91  syntax_error(s_HostServ, u, "SET", HOST_SET_SYNTAX);
92  free(vIdent);
93  free(hostmask);
94  return MOD_CONT;
95  }
96  if (strlen(vIdent) > USERMAX - 1) {
97  notice_lang(s_HostServ, u, HOST_SET_IDENTTOOLONG, USERMAX);
98  free(vIdent);
99  free(rawhostmask);
100  free(hostmask);
101  return MOD_CONT;
102  } else {
103  for (s = vIdent; *s; s++) {
104  if (!isvalidchar(*s)) {
105  notice_lang(s_HostServ, u, HOST_SET_IDENT_ERROR);
106  free(vIdent);
107  free(rawhostmask);
108  free(hostmask);
109  return MOD_CONT;
110  }
111  }
112  }
113  if (!ircd->vident) {
114  notice_lang(s_HostServ, u, HOST_NO_VIDENT);
115  free(vIdent);
116  free(rawhostmask);
117  free(hostmask);
118  return MOD_CONT;
119  }
120  }
121  if (strlen(rawhostmask) < HOSTMAX)
122  snprintf(hostmask, HOSTMAX, "%s", rawhostmask);
123  else {
124  notice_lang(s_HostServ, u, HOST_SET_TOOLONG, HOSTMAX);
125  if (vIdent) {
126  free(vIdent);
127  free(rawhostmask);
128  }
129  free(hostmask);
130  return MOD_CONT;
131  }
132 
133  if (!isValidHost(hostmask, 3)) {
134  notice_lang(s_HostServ, u, HOST_SET_ERROR);
135  if (vIdent) {
136  free(vIdent);
137  free(rawhostmask);
138  }
139  free(hostmask);
140  return MOD_CONT;
141  }
142 
143 
144  tmp_time = time(NULL);
145 
146  if ((na = findnick(nick))) {
147  if (na->status & NS_VERBOTEN) {
148  notice_lang(s_HostServ, u, NICK_X_FORBIDDEN, nick);
149  if (vIdent) {
150  free(vIdent);
151  free(rawhostmask);
152  }
153  free(hostmask);
154  return MOD_CONT;
155  }
156  if (vIdent && ircd->vident) {
157  alog("vHost for user \002%s\002 set to \002%s@%s\002 by oper \002%s\002", nick, vIdent, hostmask, u->nick);
158  } else {
159  alog("vHost for user \002%s\002 set to \002%s\002 by oper \002%s\002", nick, hostmask, u->nick);
160  }
161  addHostCore(nick, vIdent, hostmask, u->nick, tmp_time);
162  if (vIdent) {
163  notice_lang(s_HostServ, u, HOST_IDENT_SET, nick, vIdent,
164  hostmask);
165  } else {
166  notice_lang(s_HostServ, u, HOST_SET, nick, hostmask);
167  }
168  } else {
169  notice_lang(s_HostServ, u, HOST_NOREG, nick);
170  }
171  free(hostmask);
172  if (vIdent) {
173  free(vIdent);
174  free(rawhostmask);
175  }
176  return MOD_CONT;
177 }
E int isValidHost(const char *host, int type)
Definition: misc.c:614
E void addHostCore(char *nick, char *vIdent, char *vhost, char *creator, int32 tmp_time)
Definition: hostserv.c:291
char nick[NICKMAX]
Definition: services.h:875
E int snprintf(char *buf, size_t size, const char *fmt,...)
Definition: compat.c:37
E NickAlias * findnick(const char *nick)
Definition: db-merger.c:1857
E IRCDVar * ircd
Definition: extern.h:39
static int myDoSet(User *u)
Definition: hs_set.c:69
void AnopeFini(void)
Definition: hs_set.c:46
E char * myStrGetTokenRemainder(const char *str, const char dilim, int token_number)
Definition: misc.c:720
#define NS_VERBOTEN
Definition: services.h:1273
int vident
Definition: services.h:337
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
E void syntax_error(char *service, User *u, const char *command, int msgnum)
Definition: language.c:295
#define HOSTSERV
Definition: modules.h:56
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
int32_t int32
Definition: db-merger.c:122
uint16 status
Definition: services.h:532
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
E int isvalidchar(const char c)
Definition: misc.c:634
Command * c
Definition: ns_recover.c:17
E void alog(const char *fmt,...) FORMAT(printf
E char * myStrGetOnlyToken(const char *str, const char dilim, int token_number)
Definition: misc.c:685
#define MOD_CONT
Definition: modules.h:54
E char * s_HostServ
Definition: extern.h:303
static void myHostServHelp(User *u)
Definition: hs_set.c:57
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 USERMAX
Definition: config.h:68
E void * smalloc(long size)
Definition: memory.c:30
E int is_host_setter(User *u)
Definition: hostserv.c:614
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
MDE void moduleSetHostHelp(void(*func)(User *u))
Definition: modules.c:2138
int AnopeInit(int argc, char **argv)
Definition: hs_set.c:26
#define HOSTMAX
Definition: config.h:71
#define MOD_UNIQUE
Definition: module.h:11