]> jfr.im git - solanum.git/blame - ircd/snomask.c
ircd/authproc.c: avoid crash on lack of any configured DNSBLs
[solanum.git] / ircd / snomask.c
CommitLineData
212380e3 1/*
a6f63a82 2 * Solanum: a slightly advanced ircd
212380e3
AC
3 * snomask.c: Management for user server-notice masks.
4 *
3fc0499e 5 * Copyright (c) 2006 Ariadne Conill <ariadne@dereferenced.org>
212380e3
AC
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * 1. Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
212380e3
AC
32 */
33
34#include "stdinc.h"
35#include "client.h"
36#include "snomask.h"
37
38/* *INDENT-OFF* */
39int snomask_modes[256] = {
40 /* 0x00 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x0F */
41 /* 0x10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x1F */
42 /* 0x20 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x2F */
43 /* 0x30 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x3F */
44 0, /* @ */
45 0, /* A */
be52c4c0 46 SNO_BANNED, /* B */
212380e3
AC
47 SNO_CCONNEXT, /* C */
48 0, /* D */
49 0, /* E */
50 0, /* F */
51 0, /* G */
52 0, /* H */
53 0, /* I */
54 0, /* J */
55 0, /* K */
56 0, /* L */
57 0, /* M */
58 0, /* N */
59 0, /* O */
60 0, /* P */
61 0, /* Q */
62 0, /* R */
63 0, /* S */
64 0, /* T */
65 0, /* U */
66 0, /* V */
67 0, /* W */
68 0, /* X */
69 0, /* Y */
70 SNO_OPERSPY, /* Z */
71 /* 0x5B */ 0, 0, 0, 0, 0, 0, /* 0x60 */
72 0, /* a */
73 SNO_BOTS, /* b */
74 SNO_CCONN, /* c */
75 SNO_DEBUG, /* d */
76 0, /* e */
77 SNO_FULL, /* f */
78 0, /* g */
79 0, /* h */
80 0, /* i */
81 0, /* j */
82 SNO_SKILL, /* k */
83 0, /* l */
84 0, /* m */
85 SNO_NCHANGE, /* n */
86 0, /* o */
87 0, /* p */
88 0, /* q */
89 SNO_REJ, /* r */
90 SNO_GENERAL, /* s */
91 0, /* t */
92 SNO_UNAUTH, /* u */
93 0, /* v */
94 0, /* w */
95 SNO_EXTERNAL, /* x */
96 SNO_SPY, /* y */
97 0, /* z */
98 /* 0x7B */ 0, 0, 0, 0, 0, /* 0x7F */
99 /* 0x80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
100 /* 0x90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
101 /* 0xA0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xAF */
102 /* 0xB0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xBF */
103 /* 0xC0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xCF */
104 /* 0xD0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xDF */
105 /* 0xE0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xEF */
106 /* 0xF0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xFF */
107};
108/* *INDENT-ON* */
109
110static char snobuf[BUFSIZE];
111
112/*
113 * construct_snobuf
114 *
115 * inputs - client to generate snomask string for
116 * outputs - snomask string of client
117 * side effects - NONE
118 */
119char *
120construct_snobuf(unsigned int val)
121{
122 int i;
123 char *ptr = snobuf;
124
125 *ptr = '\0';
126 *ptr++ = '+';
127
128 for (i = 0; i < 128; i++)
129 if (snomask_modes[i] && (val & snomask_modes[i]))
130 *ptr++ = (char) i;
131
132 *ptr++ = '\0';
133
134 return snobuf;
135}
136
137/*
138 * parse_snobuf_to_mask
139 *
140 * inputs - value to alter bitmask for, snomask itself
141 * outputs - replacement bitmask to set
142 * side effects - NONE
143 */
144unsigned int
145parse_snobuf_to_mask(unsigned int val, const char *sno)
146{
147 const char *p;
148 int what = SNO_ADD;
149
150 if (sno == NULL)
151 return val;
152
153 for (p = sno; *p != '\0'; p++)
154 {
155 switch(*p)
156 {
157 case '+':
158 what = SNO_ADD;
159 break;
160 case '-':
161 what = SNO_DEL;
162 break;
163 default:
164 if (what == SNO_ADD)
165 val |= snomask_modes[(unsigned char) *p];
166 else if (what == SNO_DEL)
167 val &= ~snomask_modes[(unsigned char) *p];
168
169 break;
170 }
171 }
172
173 return val;
174}
175
176/*
177 * find_snomask_slot
178 *
179 * inputs - NONE
180 * outputs - an available umode bitmask or
181 * 0 if no umodes are available
182 * side effects - NONE
183 */
184unsigned int
185find_snomask_slot(void)
186{
187 unsigned int all_umodes = 0, my_umode = 0, i;
188
189 for (i = 0; i < 128; i++)
190 all_umodes |= snomask_modes[i];
191
192 for (my_umode = 1; my_umode && (all_umodes & my_umode);
193 my_umode <<= 1);
194
195 return my_umode;
196}
197