Anope IRC Services  Version 1.8
hs_setall.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 do_setall(User * u);
18 static void myHostServHelp(User * u);
19 extern int do_hs_sync(NickCore * nc, char *vIdent, char *hostmask,
20  char *creator, time_t time);
21 
28 int AnopeInit(int argc, char **argv)
29 {
30  Command *c;
31 
32  moduleAddAuthor("Anope");
33  moduleAddVersion(VERSION_STRING);
35 
36  c = createCommand("SETALL", do_setall, is_host_setter,
37  HOST_HELP_SETALL, -1, -1, -1, -1);
40 
41  return MOD_CONT;
42 }
43 
47 void AnopeFini(void)
48 {
49 
50 }
51 
52 
53 
58 static void myHostServHelp(User * u)
59 {
60  if (is_host_setter(u)) {
61  notice_lang(s_HostServ, u, HOST_HELP_CMD_SETALL);
62  }
63 }
64 
70 static int do_setall(User * u)
71 {
72 
73  char *nick = strtok(NULL, " ");
74  char *rawhostmask = strtok(NULL, " ");
75  char *hostmask = smalloc(HOSTMAX);
76 
77  NickAlias *na;
78  int32 tmp_time;
79  char *s;
80 
81  char *vIdent = NULL;
82 
83  if (!nick || !rawhostmask) {
84  syntax_error(s_HostServ, u, "SETALL", HOST_SETALL_SYNTAX);
85  free(hostmask);
86  return MOD_CONT;
87  }
88 
89  vIdent = myStrGetOnlyToken(rawhostmask, '@', 0); /* Get the first substring, @ as delimiter */
90  if (vIdent) {
91  rawhostmask = myStrGetTokenRemainder(rawhostmask, '@', 1); /* get the remaining string */
92  if (!rawhostmask) {
93  syntax_error(s_HostServ, u, "SETALL", HOST_SETALL_SYNTAX);
94  free(vIdent);
95  free(hostmask);
96  return MOD_CONT;
97  }
98  if (strlen(vIdent) > USERMAX - 1) {
99  notice_lang(s_HostServ, u, HOST_SET_IDENTTOOLONG, USERMAX);
100  free(vIdent);
101  free(rawhostmask);
102  free(hostmask);
103  return MOD_CONT;
104  } else {
105  for (s = vIdent; *s; s++) {
106  if (!isvalidchar(*s)) {
107  notice_lang(s_HostServ, u, HOST_SET_IDENT_ERROR);
108  free(vIdent);
109  free(rawhostmask);
110  free(hostmask);
111  return MOD_CONT;
112  }
113  }
114  }
115  if (!ircd->vident) {
116  notice_lang(s_HostServ, u, HOST_NO_VIDENT);
117  free(vIdent);
118  free(rawhostmask);
119  free(hostmask);
120  return MOD_CONT;
121  }
122  }
123 
124  if (strlen(rawhostmask) < HOSTMAX)
125  snprintf(hostmask, HOSTMAX, "%s", rawhostmask);
126  else {
127  notice_lang(s_HostServ, u, HOST_SET_TOOLONG, HOSTMAX);
128  if (vIdent) {
129  free(vIdent);
130  free(rawhostmask);
131  }
132  free(hostmask);
133  return MOD_CONT;
134  }
135 
136  if (!isValidHost(hostmask, 3)) {
137  notice_lang(s_HostServ, u, HOST_SET_ERROR);
138  if (vIdent) {
139  free(vIdent);
140  free(rawhostmask);
141  }
142  free(hostmask);
143  return MOD_CONT;
144  }
145 
146  tmp_time = time(NULL);
147 
148  if ((na = findnick(nick))) {
149  if (na->status & NS_VERBOTEN) {
150  notice_lang(s_HostServ, u, NICK_X_FORBIDDEN, nick);
151  if (vIdent) {
152  free(vIdent);
153  free(rawhostmask);
154  }
155  free(hostmask);
156  return MOD_CONT;
157  }
158  if (vIdent && ircd->vident) {
159  alog("vHost for all nicks in group \002%s\002 set to \002%s@%s\002 by oper \002%s\002", nick, vIdent, hostmask, u->nick);
160  } else {
161  alog("vHost for all nicks in group \002%s\002 set to \002%s\002 by oper \002%s\002", nick, hostmask, u->nick);
162  }
163  do_hs_sync(na->nc, vIdent, hostmask, u->nick, tmp_time);
164  if (vIdent) {
165  notice_lang(s_HostServ, u, HOST_IDENT_SETALL, nick, vIdent,
166  hostmask);
167  } else {
168  notice_lang(s_HostServ, u, HOST_SETALL, nick, hostmask);
169  }
170  } else {
171  notice_lang(s_HostServ, u, HOST_NOREG, nick);
172  }
173  if (vIdent) {
174  free(vIdent);
175  free(rawhostmask);
176  }
177  free(hostmask);
178  return MOD_CONT;
179 }
static void myHostServHelp(User *u)
Definition: hs_setall.c:58
E int isValidHost(const char *host, int type)
Definition: misc.c:614
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
E char * myStrGetTokenRemainder(const char *str, const char dilim, int token_number)
Definition: misc.c:720
void AnopeFini(void)
Definition: hs_setall.c:47
#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
NickCore * nc
Definition: services.h:533
int AnopeInit(int argc, char **argv)
Definition: hs_setall.c:28
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
int do_hs_sync(NickCore *nc, char *vIdent, char *hostmask, char *creator, time_t time)
Definition: hostserv.c:568
E char * s_HostServ
Definition: extern.h:303
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
#define HOSTMAX
Definition: config.h:71
static int do_setall(User *u)
Definition: hs_setall.c:70
#define MOD_UNIQUE
Definition: module.h:11