2 * charybdis: an advanced Internet Relay Chat Daemon(ircd).
3 * m_scan.c: Provides information about various targets on various topics
5 * Copyright (c) 2006 William Pitcock <nenolod -at- nenolod.net>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * 1.Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * 2.Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3.The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
31 * $Id: m_scan.c 1853 2006-08-24 18:30:52Z jilles $
46 #include "s_newconf.h"
53 static int mo_scan(struct Client
*, struct Client
*, int, const char **);
54 static int scan_umodes(struct Client
*, struct Client
*, int, const char **);
55 /*static int scan_cmodes(struct Client *, struct Client *, int, const char **);*/
57 struct Message scan_msgtab
= {
58 "SCAN", 0, 0, 0, MFLG_SLOW
,
59 {mg_ignore
, mg_not_oper
, mg_ignore
, mg_ignore
, mg_ignore
, {mo_scan
, 2}}
62 mapi_clist_av1 scan_clist
[] = { &scan_msgtab
, NULL
};
63 DECLARE_MODULE_AV1(scan
, NULL
, NULL
, scan_clist
, NULL
, NULL
, "$Revision: 1853 $");
65 typedef int (*scan_handler
)(struct Client
*, struct Client
*, int,
73 {"UMODES", L_OPER
, scan_umodes
},
77 static const char *empty_sockhost
= "255.255.255.255";
78 static const char *spoofed_sockhost
= "0";
82 * parv[0] = sender prefix
83 * parv[1] = options [or target]
87 mo_scan(struct Client
*client_p
, struct Client
*source_p
, int parc
,
90 struct scan_cmd
*sptr
;
92 for (sptr
= scan_cmds
; sptr
->name
!= NULL
; sptr
++)
94 if (!irccmp(sptr
->name
, parv
[1]))
96 if (sptr
->operlevel
== L_ADMIN
&&
97 !IsOperAdmin(source_p
))
100 return sptr
->handler(client_p
, source_p
, parc
, parv
);
104 sendto_one_notice(source_p
, ":*** %s is not an implemented SCAN target",
111 scan_umodes(struct Client
*client_p
, struct Client
*source_p
, int parc
,
114 unsigned int allowed_umodes
= 0, disallowed_umodes
= 0;
117 int list_users
= YES
;
119 int list_count
= 0, count
= 0;
120 const char *mask
= NULL
;
122 struct Client
*target_p
;
123 rb_dlink_list
*target_list
= &lclient_list
; /* local clients only by default */
126 const char *sockhost
;
131 if (MyClient(source_p
))
132 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
),
133 me
.name
, source_p
->name
, "SCAN UMODES");
138 for (c
= parv
[2]; *c
; c
++)
149 if ((mode
= user_modes
[(unsigned char) *c
]) != 0)
151 if (what
== MODE_ADD
)
152 allowed_umodes
|= mode
;
154 disallowed_umodes
|= mode
;
159 for (i
= 3; i
< parc
; i
++)
161 if (!irccmp(parv
[i
], "no-list"))
163 else if (!irccmp(parv
[i
], "list"))
165 else if (!irccmp(parv
[i
], "global"))
166 target_list
= &global_client_list
;
167 else if (i
< (parc
- 1))
169 if (!irccmp(parv
[i
], "list-max"))
170 list_max
= atoi(parv
[++i
]);
171 else if (!irccmp(parv
[i
], "mask"))
175 if (target_list
== &global_client_list
&& (list_users
|| mask
))
177 if (IsOperSpy(source_p
))
179 if (!ConfigFileEntry
.operspy_dont_care_user_info
)
181 rb_strlcpy(buf
, "UMODES", sizeof buf
);
182 for (i
= 2; i
< parc
; i
++)
184 rb_strlcat(buf
, " ", sizeof buf
);
185 rb_strlcat(buf
, parv
[i
], sizeof buf
);
187 report_operspy(source_p
, "SCAN", buf
);
192 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
193 me
.name
, source_p
->name
, "oper_spy");
198 RB_DLINK_FOREACH(tn
, target_list
->head
)
200 unsigned int working_umodes
= 0;
201 char maskbuf
[BUFSIZE
];
205 if (!IsClient(target_p
))
208 if(EmptyString(target_p
->sockhost
))
209 sockhost
= empty_sockhost
;
210 else if(!show_ip(source_p
, target_p
))
211 sockhost
= spoofed_sockhost
;
213 sockhost
= target_p
->sockhost
;
215 working_umodes
= target_p
->umodes
;
217 /* require that we have the allowed umodes... */
218 if ((working_umodes
& allowed_umodes
) != allowed_umodes
)
221 /* require that we have NONE of the disallowed ones */
222 if ((working_umodes
& disallowed_umodes
) != 0)
227 rb_snprintf(maskbuf
, BUFSIZE
, "%s!%s@%s",
228 target_p
->name
, target_p
->username
, target_p
->host
);
230 if (!match(mask
, maskbuf
))
234 if (list_users
&& (!list_max
|| (list_count
< list_max
)))
236 char modebuf
[BUFSIZE
];
241 for (i
= 0; i
< 128; i
++)
243 if (target_p
->umodes
& user_modes
[i
])
251 sendto_one_numeric(source_p
, RPL_SCANUMODES
,
252 form_str(RPL_SCANUMODES
),
253 target_p
->name
, target_p
->username
,
254 target_p
->host
, sockhost
,
255 target_p
->servptr
->name
, modebuf
,
261 sendto_one_numeric(source_p
, RPL_SCANMATCHED
,
262 form_str(RPL_SCANMATCHED
), count
);