-
Notifications
You must be signed in to change notification settings - Fork 7
/
misc.c
116 lines (111 loc) · 3.2 KB
/
misc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* Copyright (C) 2000,2001 Florian Sander
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* maskstricthost():
* basically the same as maskhost() from src/misc.c, but _never_ stripts
* "~+-^=" off the host
* maskhost() version: * $Id: misc.c,v 1.1 2005/04/14 10:55:00 Administrator Exp $
*/
static void maskstricthost(const char *s, char *nw)
{
register const char *p, *q, *e, *f;
int i;
*nw++ = '*';
*nw++ = '!';
p = (q = strchr(s, '!')) ? q + 1 : s;
/* Strip of any nick, if a username is found, use last 8 chars */
if ((q = strchr(p, '@'))) {
int fl = 0;
if ((q - p) > 9) {
nw[0] = '*';
p = q - 7;
i = 1;
} else
i = 0;
while (*p != '@') {
if (!fl && strchr("~+-^=", *p)) {
// if (strict_host)
nw[i] = '?';
// else
// i--;
} else
nw[i] = *p;
fl++;
p++;
i++;
}
nw[i++] = '@';
q++;
} else {
nw[0] = '*';
nw[1] = '@';
i = 2;
q = s;
}
nw += i;
e = NULL;
/* Now q points to the hostname, i point to where to put the mask */
if ((!(p = strchr(q, '.')) || !(e = strchr(p + 1, '.'))) && !strchr(q, ':'))
/* TLD or 2 part host */
strcpy(nw, q);
else {
if (e == NULL) { /* IPv6 address? */
const char *mask_str;
f = strrchr(q, ':');
if (strchr(f, '.')) { /* IPv4 wrapped in an IPv6? */
f = strrchr(f, '.');
mask_str = ".*";
} else /* ... no, true IPv6. */
mask_str = ":*";
strncpy(nw, q, f - q);
/* No need to nw[f-q] = 0 here, as the strcpy below will
* terminate the string for us.
*/
nw += (f - q);
strcpy(nw, mask_str);
} else {
for (f = e; *f; f++);
f--;
if (*f >= '0' && *f <= '9') { /* Numeric IP address */
while (*f != '.')
f--;
strncpy(nw, q, f - q);
/* No need to nw[f-q] = 0 here, as the strcpy below will
* terminate the string for us.
*/
nw += (f - q);
strcpy(nw, ".*");
} else { /* Normal host >= 3 parts */
/* a.b.c -> *.b.c
* a.b.c.d -> *.b.c.d if tld is a country (2 chars)
* OR *.c.d if tld is com/edu/etc (3 chars)
* a.b.c.d.e -> *.c.d.e etc
*/
const char *x = strchr(e + 1, '.');
if (!x)
x = p;
else if (strchr(x + 1, '.'))
x = e;
else if (strlen(x) == 3)
x = p;
else
x = e;
sprintf(nw, "*%s", x);
}
}
}
}