fixed ssl.c bug when ssl backend returns IO_BLOCKED but IO engine doesn't get informe...
[ircu2.10.12-pk.git] / ircd / m_hidehost.c
1 /*
2  * IRC - Internet Relay Chat, ircd/m_hidehost.c
3  * Written by David Herrmann.
4  */
5
6 /*
7  * m_functions execute protocol messages on this server:
8  *
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...).
14  *
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.
18  *
19  *            (!IsServer(cptr)) => (cptr == sptr), because
20  *            prefixes are taken *only* from servers...
21  *
22  *            (IsServer(cptr))
23  *                    (sptr == cptr) => the message didn't
24  *                    have the prefix.
25  *
26  *                    (sptr != cptr && IsServer(sptr) means
27  *                    the prefix specified servername. (?)
28  *
29  *                    (sptr != cptr && !IsServer(sptr) means
30  *                    that message originated from a remote
31  *                    user (not local).
32  *
33  *            combining
34  *
35  *            (!IsServer(sptr)) means that, sptr can safely
36  *            taken as defining the target structure of the
37  *            message in this server.
38  *
39  *    *Always* true (if 'parse' and others are working correct):
40  *
41  *    1)      sptr->from == cptr  (note: cptr->from == cptr)
42  *
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 ]
47  *
48  *    parc    number of variable parameter strings (if zero,
49  *            parv is allowed to be NULL)
50  *
51  *    parv    a NULL terminated list of parameter pointers,
52  *
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*
58  *
59  *            note:   it is guaranteed that parv[0]..parv[parc-1] are all
60  *                    non-NULL pointers.
61  */
62 #include "config.h"
63
64 #include "client.h"
65 #include "handlers.h"
66 #include "hash.h"
67 #include "ircd.h"
68 #include "ircd_defs.h"
69 #include "ircd_features.h"
70 #include "ircd_log.h"
71 #include "ircd_reply.h"
72 #include "ircd_string.h"
73 #include "match.h"
74 #include "msg.h"
75 #include "numeric.h"
76 #include "numnicks.h"
77 #include "s_conf.h"
78 #include "s_misc.h"
79 #include "s_user.h"
80 #include "send.h"
81 #include "sys.h"
82
83 /* ms_hidehost
84  *  parv[0] = sender
85  *  parv[1] = target nick
86  */
87 /** Remote hidehost
88  * Allows ulined servers to force umode +x on remote users. Though, we should use numerics
89  * as target, the current services use nicknames. This may be changed in future.
90  *
91  * The HIDEHOST request can be generated by EVERY server. It is forwarded to the server
92  * of the user which then sets the umode +x and broadcasts the new umodes.
93  */
94 int ms_hidehost(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) {
95     signed int propagate;
96     struct Client *acptr;
97     struct Flags setflags;
98
99     if(parc < 2) {
100         return need_more_params(sptr, "HIDEHOST");
101     }
102
103     /* Check whether the user is already gone or already hidden. */
104     if(!(acptr = FindUser(parv[1])) || !IsUser(acptr) || IsHiddenHost(acptr)) {
105         return 0;
106     }
107
108     /* If the user is no local user, we forward the message to the user's server. */
109     if(!MyConnect(acptr)) {
110         sendcmdto_one(sptr, CMD_HIDEHOST, cli_user(acptr)->server, "%s", cli_name(acptr));
111         return 0;
112     }
113
114     /* Set +x and propagate the changed modes. */
115     propagate = !!HasPriv(acptr, PRIV_PROPAGATE);
116     setflags = cli_flags(acptr);
117     hide_hostmask(acptr, HIDE_HOSTMASK_FLAG_HIDDENHOST);
118     send_umode_out(acptr, acptr, &setflags, propagate);
119
120     return 0;
121 }
122