2 * IRC - Internet Relay Chat, ircd/m_svsmode.c
3 * Written by David Herrmann.
7 * m_functions execute protocol messages on this server:
9 * cptr is always NON-NULL, pointing to a *LOCAL* client
10 * structure (with an open socket connected!). This
11 * identifies the physical socket where the message
12 * originated (or which caused the m_function to be
13 * executed--some m_functions may call others...).
15 * sptr is the source of the message, defined by the
16 * prefix part of the message if present. If not
17 * or prefix not found, then sptr==cptr.
19 * (!IsServer(cptr)) => (cptr == sptr), because
20 * prefixes are taken *only* from servers...
23 * (sptr == cptr) => the message didn't
26 * (sptr != cptr && IsServer(sptr) means
27 * the prefix specified servername. (?)
29 * (sptr != cptr && !IsServer(sptr) means
30 * that message originated from a remote
35 * (!IsServer(sptr)) means that, sptr can safely
36 * taken as defining the target structure of the
37 * message in this server.
39 * *Always* true (if 'parse' and others are working correct):
41 * 1) sptr->from == cptr (note: cptr->from == cptr)
43 * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
44 * *cannot* be a local connection, unless it's
45 * actually cptr!). [MyConnect(x) should probably
46 * be defined as (x == x->from) --msa ]
48 * parc number of variable parameter strings (if zero,
49 * parv is allowed to be NULL)
51 * parv a NULL terminated list of parameter pointers,
53 * parv[0], sender (prefix string), if not present
54 * this points to an empty string.
55 * parv[1]...parv[parc-1]
56 * pointers to additional parameters
57 * parv[parc] == NULL, *always*
59 * note: it is guaranteed that parv[0]..parv[parc-1] are all
67 #include "ircd_features.h"
69 #include "ircd_reply.h"
70 #include "ircd_string.h"
84 * SVSMODE is forwarded to the users server, hence, it can be called
87 int m_svsmode(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
93 struct Flags setflags;
95 if (!IsNetServ(sptr) || !HasFlag(sptr, FLAG_SECURITY_SERV))
96 return send_reply(sptr, ERR_NOPRIVILEGES);
99 return protocol_violation(cptr, "Too few arguments for SVSMODE");
102 if(!(acptr = FindUser(parv[1]))) {
103 return 0; /* Ignore SVSMODE for a user that has quit */
106 /* Forward the message to the server where the user is connected to. */
107 if(!MyConnect(acptr)) {
109 for(i = 2; i < (parc - 1); ++i) {
111 while((*act++ = *m++)) /* empty loop */ ;
116 while((*act++ = *m++)) /* empty loop */ ;
117 const struct User* user = cli_user(acptr);
118 struct Client *server = user->server;
119 sendcmdto_one(sptr, CMD_SVSMODE, acptr, "%s%s %s", cli_yxx(server), cli_yxx(acptr), buffer);
123 /* Set mode change. */
124 setflags = cli_flags(acptr);
125 /* This is a very important security check!
126 or shall we allow normal opers to set mode +D?
129 if(IsSecurityServ(sptr) && IsNetServ(sptr))
130 allow=ALLOWMODES_WITHSECSERV;
132 allow=ALLOWMODES_ANY;
133 set_user_mode(&me, acptr, parc, parv, allow);
134 send_umode(acptr, acptr, &setflags, ALL_UMODES, 0);
138 /* ms_svsmode - server message handler
139 * parv[0] = sender prefix
140 * parv[1] = target numeric
141 * parv[2-X] = mode string
143 signed int ms_svsmode(struct Client* cptr, struct Client* sptr, signed int parc, char* parv[]) {
144 struct Client *acptr;
145 unsigned int i,allow;
148 struct Flags setflags;
151 return protocol_violation(cptr, "Too few arguments for SVSMODE");
154 if(!(acptr = findNUser(parv[1]))) {
155 return 0; /* Ignore SVSMODE for a user that has quit */
158 /* Forward the message to the server where the user is connected to. */
159 if(!MyConnect(acptr)) {
161 for(i = 2; i < (parc - 1); ++i) {
163 while((*act++ = *m++)) /* empty loop */ ;
168 while((*act++ = *m++)) /* empty loop */ ;
169 sendcmdto_one(sptr, CMD_SVSMODE, acptr, "%s %s", parv[1], buffer);
173 #ifndef UNRESTRICTED_SERV
175 /* Set mode change. */
176 setflags = cli_flags(acptr);
177 /* This is a very important security check!
178 or shall we allow normal opers to set mode +D?
180 if(IsSecurityServ(sptr) && IsNetServ(sptr)) {
181 allow=ALLOWMODES_WITHSECSERV;
183 allow=ALLOWMODES_ANY;
185 set_user_mode(&me, acptr, parc, parv, allow);
186 send_umode(acptr, acptr, &setflags, ALL_UMODES, 0);