1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 1997-2018 ircd-hybrid development team |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
* USA |
20 |
*/ |
21 |
|
22 |
/*! \file m_userhost.c |
23 |
* \brief Includes required functions for processing the USERHOST command. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "client.h" |
29 |
#include "ircd.h" |
30 |
#include "numeric.h" |
31 |
#include "send.h" |
32 |
#include "irc_string.h" |
33 |
#include "parse.h" |
34 |
#include "modules.h" |
35 |
|
36 |
|
37 |
/*! \brief USERHOST command handler |
38 |
* |
39 |
* \param source_p Pointer to allocated Client struct from which the message |
40 |
* originally comes from. This can be a local or remote client. |
41 |
* \param parc Integer holding the number of supplied arguments. |
42 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
43 |
* pointers. |
44 |
* \note Valid arguments for this command are: |
45 |
* - parv[0] = command |
46 |
* - parv[1] = space-separated list of up to 5 nicknames |
47 |
*/ |
48 |
static int |
49 |
m_userhost(struct Client *source_p, int parc, char *parv[]) |
50 |
{ |
51 |
char buf[IRCD_BUFSIZE]; |
52 |
char response[NICKLEN + USERLEN + HOSTLEN + 6]; /* +6 for "*=+@ \0" */ |
53 |
char *t = NULL, *p = NULL; |
54 |
int i = 0; |
55 |
int cur_len; |
56 |
int rl; |
57 |
|
58 |
cur_len = snprintf(buf, sizeof(buf), numeric_form(RPL_USERHOST), me.name, source_p->name, ""); |
59 |
t = buf + cur_len; |
60 |
|
61 |
for (const char *name = strtok_r(parv[1], " ", &p); name && i++ < 5; |
62 |
name = strtok_r(NULL, " ", &p)) |
63 |
{ |
64 |
const struct Client *target_p; |
65 |
if ((target_p = find_person(source_p, name))) |
66 |
{ |
67 |
/* |
68 |
* Show real IP address for USERHOST on yourself. |
69 |
* This is needed for things like mIRC, which do a server-based |
70 |
* lookup (USERHOST) to figure out what the clients' local IP |
71 |
* is. Useful for things like NAT, and dynamic dial-up users. |
72 |
*/ |
73 |
if (target_p == source_p) |
74 |
{ |
75 |
rl = snprintf(response, sizeof(response), "%s%s=%c%s@%s ", |
76 |
target_p->name, |
77 |
HasUMode(target_p, UMODE_OPER) ? "*" : "", |
78 |
(target_p->away[0]) ? '-' : '+', |
79 |
target_p->username, |
80 |
target_p->sockhost); |
81 |
} |
82 |
else |
83 |
{ |
84 |
rl = snprintf(response, sizeof(response), "%s%s=%c%s@%s ", |
85 |
target_p->name, (HasUMode(target_p, UMODE_OPER) && |
86 |
(!HasUMode(target_p, UMODE_HIDDEN) || |
87 |
HasUMode(source_p, UMODE_OPER))) ? "*" : "", |
88 |
(target_p->away[0]) ? '-' : '+', |
89 |
target_p->username, |
90 |
target_p->host); |
91 |
} |
92 |
|
93 |
if ((rl + cur_len) < (IRCD_BUFSIZE - 10)) |
94 |
{ |
95 |
sprintf(t, "%s", response); |
96 |
t += rl; |
97 |
cur_len += rl; |
98 |
} |
99 |
else |
100 |
break; |
101 |
} |
102 |
} |
103 |
|
104 |
sendto_one(source_p, "%s", buf); |
105 |
return 0; |
106 |
} |
107 |
|
108 |
static struct Message userhost_msgtab = |
109 |
{ |
110 |
.cmd = "USERHOST", |
111 |
.args_min = 2, |
112 |
.args_max = 1, |
113 |
.handlers[UNREGISTERED_HANDLER] = m_unregistered, |
114 |
.handlers[CLIENT_HANDLER] = m_userhost, |
115 |
.handlers[SERVER_HANDLER] = m_ignore, |
116 |
.handlers[ENCAP_HANDLER] = m_ignore, |
117 |
.handlers[OPER_HANDLER] = m_userhost |
118 |
}; |
119 |
|
120 |
static void |
121 |
module_init(void) |
122 |
{ |
123 |
mod_add_cmd(&userhost_msgtab); |
124 |
} |
125 |
|
126 |
static void |
127 |
module_exit(void) |
128 |
{ |
129 |
mod_del_cmd(&userhost_msgtab); |
130 |
} |
131 |
|
132 |
struct module module_entry = |
133 |
{ |
134 |
.version = "$Revision$", |
135 |
.modinit = module_init, |
136 |
.modexit = module_exit, |
137 |
}; |