| 1 |
michael |
417 |
/* |
| 2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
|
|
* operator.c: Defines the operator{} block of ircd.conf. |
| 4 |
|
|
* |
| 5 |
|
|
* Copyright (C) 2006 by the Hybrid Development Team. |
| 6 |
|
|
* |
| 7 |
|
|
* This program is free software; you can redistribute it and/or modify |
| 8 |
|
|
* it under the terms of the GNU General Public License as published by |
| 9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
|
|
* (at your option) any later version. |
| 11 |
|
|
* |
| 12 |
|
|
* This program is distributed in the hope that it will be useful, |
| 13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
|
|
* GNU General Public License for more details. |
| 16 |
|
|
* |
| 17 |
|
|
* You should have received a copy of the GNU General Public License |
| 18 |
|
|
* along with this program; if not, write to the Free Software |
| 19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 20 |
|
|
* USA |
| 21 |
|
|
* |
| 22 |
|
|
* $Id$ |
| 23 |
|
|
*/ |
| 24 |
|
|
|
| 25 |
|
|
|
| 26 |
|
|
static dlink_node *hreset = NULL; |
| 27 |
|
|
static struct AccessItem tmpoper; |
| 28 |
|
|
|
| 29 |
|
|
static const struct FlagMapping { |
| 30 |
|
|
const char *name; |
| 31 |
|
|
unsigned int flags; |
| 32 |
|
|
} flag_mappings[] = { |
| 33 |
|
|
{"global_kill", OPER_FLAG_GLOBAL_KILL}, |
| 34 |
|
|
{"remote", OPER_FLAG_REMOTE}, |
| 35 |
|
|
{"remoteban", OPER_FLAG_REMOTEBAN}, |
| 36 |
|
|
{"kline", OPER_FLAG_K}, |
| 37 |
|
|
{"unkline", OPER_FLAG_UNKLINE}, |
| 38 |
|
|
{"gline", OPER_FLAG_GLINE}, |
| 39 |
|
|
{"xline", OPER_FLAG_X}, |
| 40 |
|
|
{"operwall", OPER_FLAG_OPERWALL}, |
| 41 |
|
|
{"nick_changes", OPER_FLAG_N}, |
| 42 |
|
|
{"rehash", OPER_FLAG_REHASH}, |
| 43 |
|
|
{"die", OPER_FLAG_DIE}, |
| 44 |
|
|
{"admin", OPER_FLAG_ADMIN}, |
| 45 |
|
|
{"hidden_admin", OPER_FLAG_HIDDEN_ADMIN}, |
| 46 |
|
|
{"hidden_oper", OPER_FLAG_HIDDEN_OPER}, |
| 47 |
|
|
{ NULL, 0 } |
| 48 |
|
|
}; |
| 49 |
|
|
|
| 50 |
michael |
422 |
void |
| 51 |
|
|
conf_operator_report(struct Client *source_p) |
| 52 |
|
|
{ |
| 53 |
|
|
dlink_node *ptr = NULL; |
| 54 |
|
|
|
| 55 |
|
|
DLINK_FOREACH(ptr, oconf_items.head) |
| 56 |
|
|
{ |
| 57 |
|
|
dlink_node *ptr_mask = NULL; |
| 58 |
|
|
struct ConfItem *conf = ptr->data; |
| 59 |
|
|
struct AccessItem *aconf = &conf->conf.AccessItem; |
| 60 |
|
|
assert(aconf->class_ptr); |
| 61 |
|
|
|
| 62 |
|
|
DLINK_FOREACH(ptr_mask, conf->mask_list.head) |
| 63 |
|
|
{ |
| 64 |
|
|
const struct split_nuh_item *nuh = ptr_mask->data; |
| 65 |
|
|
|
| 66 |
|
|
/* Don't allow non opers to see oper privs */ |
| 67 |
|
|
if (IsOper(source_p)) |
| 68 |
|
|
sendto_one(source_p, form_str(RPL_STATSOLINE), me.name, |
| 69 |
|
|
source_p->name, 'O', nuh->userptr, nuh->hostptr, |
| 70 |
|
|
conf->name, oper_privs_as_string(aconf->port), |
| 71 |
|
|
aconf->class_ptr->name); |
| 72 |
|
|
else |
| 73 |
|
|
sendto_one(source_p, form_str(RPL_STATSOLINE), |
| 74 |
|
|
me.name, source_p->name, 'O', nuh->userptr, nuh->hostptr, |
| 75 |
|
|
conf->name, "0", |
| 76 |
|
|
aconf->class_ptr->name); |
| 77 |
|
|
} |
| 78 |
|
|
} |
| 79 |
|
|
} |
| 80 |
|
|
} |
| 81 |
|
|
|
| 82 |
michael |
417 |
static void |
| 83 |
michael |
418 |
reset_operator(void) |
| 84 |
|
|
{ |
| 85 |
|
|
dlink_node *ptr = NULL, *ptr_next = NULL; |
| 86 |
|
|
|
| 87 |
|
|
DLINK_FOREACH_SAFE(ptr, ptr_next, oconf_items.head) |
| 88 |
|
|
delete_conf_item(ptr->data); |
| 89 |
|
|
} |
| 90 |
|
|
|
| 91 |
|
|
static void |
| 92 |
michael |
417 |
before_operator(void) |
| 93 |
|
|
{ |
| 94 |
|
|
memset(&tmpoper, 0, sizeof(tmpoper)); |
| 95 |
|
|
|
| 96 |
|
|
SetConfEncrypted(&tmpoper.conf->AccessItem); |
| 97 |
|
|
} |
| 98 |
|
|
|
| 99 |
|
|
static void |
| 100 |
|
|
after_operator(void) |
| 101 |
|
|
{ |
| 102 |
|
|
struct ConfItem *oper = NULL; |
| 103 |
|
|
struct AccessItem *yy_tmp = &tmpoper.conf->AccessItem; |
| 104 |
|
|
|
| 105 |
|
|
if (tmpoper.name == NULL || |
| 106 |
|
|
yy_tmp->host == NULL || |
| 107 |
|
|
yy_tmp->user == NULL) |
| 108 |
|
|
return; |
| 109 |
|
|
|
| 110 |
|
|
if (&tmpoper.conf->AccessItem->class_ptr == NULL) |
| 111 |
michael |
418 |
{ |
| 112 |
|
|
parse_error("Invalid or non-existant class in operator{}"); |
| 113 |
michael |
417 |
return; |
| 114 |
michael |
418 |
} |
| 115 |
michael |
417 |
|
| 116 |
|
|
if (!yy_tmp->passwd && !yy_aconf->rsa_public_key) |
| 117 |
michael |
418 |
return; |
| 118 |
michael |
417 |
|
| 119 |
|
|
oper = make_conf_item(OPER_TYPE); |
| 120 |
|
|
|
| 121 |
|
|
/* XXX Temporary hack until we changed make_conf_item() so it doesn't add |
| 122 |
|
|
* newly created items onto doubly linked lists immediately after creation */ |
| 123 |
|
|
&tmpoper.node->head = oper->node.head; |
| 124 |
|
|
&tmpoper.node->tail = oper->node.tail; |
| 125 |
|
|
&tmpoper.node->data = oper->node.data; |
| 126 |
|
|
|
| 127 |
|
|
memcpy(oper, &tmpoper, sizeof(*oper)); |
| 128 |
|
|
} |
| 129 |
|
|
|
| 130 |
|
|
static void |
| 131 |
|
|
oper_encrypted(void *value, void *where) |
| 132 |
|
|
{ |
| 133 |
|
|
|
| 134 |
|
|
if (*(int *)value) |
| 135 |
|
|
SetConfEncrypted(&tmpoper.conf->AccessItem); |
| 136 |
|
|
else |
| 137 |
|
|
ClearConfEncrypted(&tmpoper.conf->AccessItem); |
| 138 |
|
|
} |
| 139 |
|
|
|
| 140 |
|
|
static void |
| 141 |
|
|
oper_user(void *value, *void where) |
| 142 |
|
|
{ |
| 143 |
|
|
char *str = value; |
| 144 |
|
|
char userbuf[USERLEN + 1]; |
| 145 |
|
|
char hostbuf[HOSTLEN + 1]; |
| 146 |
|
|
struct split_nuh_item nuh, *cuh; |
| 147 |
|
|
|
| 148 |
|
|
nuh.nuhmask = str; |
| 149 |
|
|
nuh.nickptr = NULL; |
| 150 |
|
|
nuh.userptr = userbuf; |
| 151 |
|
|
nuh.hostptr = hostbuf; |
| 152 |
|
|
|
| 153 |
|
|
nuh.nicksize = 0; |
| 154 |
|
|
nuh.usersize = sizeof(userbuf); |
| 155 |
|
|
nuh.hostsize = sizeof(hostbuf); |
| 156 |
|
|
|
| 157 |
|
|
split_nuh(&nuh); |
| 158 |
|
|
|
| 159 |
|
|
cuh = MyMalloc(sizeof(*cuh)); |
| 160 |
|
|
DupString(cuh->userptr, nuh.userptr); |
| 161 |
|
|
DupString(cuh->hostptr, nuh.hostptr); |
| 162 |
|
|
|
| 163 |
|
|
dlinkAdd(cuh, &cuh->node, &tmpoper.conf->AccessItem->mask_list); |
| 164 |
|
|
} |
| 165 |
|
|
|
| 166 |
|
|
static void |
| 167 |
|
|
operator_class(void *value, void *where) |
| 168 |
|
|
{ |
| 169 |
michael |
418 |
tmpoper.conf->AccessItem->class_ptr = find_class(value); |
| 170 |
michael |
417 |
} |
| 171 |
|
|
|
| 172 |
|
|
static void |
| 173 |
|
|
oper_rsa_public_key_file(void *value, void *where) |
| 174 |
|
|
{ |
| 175 |
|
|
const char *str = value; |
| 176 |
|
|
struct AccessItem *yy_tmp = &tmpoper.conf->AccessItem; |
| 177 |
|
|
BIO *file = NULL; |
| 178 |
|
|
|
| 179 |
|
|
if (yy_aconf->rsa_public_key != NULL) |
| 180 |
|
|
{ |
| 181 |
|
|
RSA_free(yy_aconf->rsa_public_key); |
| 182 |
|
|
yy_aconf->rsa_public_key = NULL; |
| 183 |
|
|
} |
| 184 |
|
|
|
| 185 |
|
|
if (yy_aconf->rsa_public_key_file != NULL) |
| 186 |
|
|
{ |
| 187 |
|
|
MyFree(yy_aconf->rsa_public_key_file); |
| 188 |
|
|
yy_aconf->rsa_public_key_file = NULL; |
| 189 |
|
|
} |
| 190 |
|
|
|
| 191 |
|
|
DupString(yy_aconf->rsa_public_key_file, str); |
| 192 |
|
|
file = BIO_new_file(str, "r"); |
| 193 |
|
|
|
| 194 |
|
|
if (file == NULL) |
| 195 |
|
|
{ |
| 196 |
michael |
418 |
parse_error("Ignoring rsa_public_key_file -- file doesn't exist"); |
| 197 |
michael |
417 |
return; |
| 198 |
|
|
} |
| 199 |
|
|
|
| 200 |
|
|
yy_aconf->rsa_public_key = (RSA *)PEM_read_bio_RSA_PUBKEY(file, NULL, 0, NULL); |
| 201 |
|
|
|
| 202 |
|
|
if (yy_aconf->rsa_public_key == NULL) |
| 203 |
|
|
{ |
| 204 |
michael |
418 |
parse_error("Ignoring rsa_public_key_file -- Key invalid; check key syntax."); |
| 205 |
michael |
417 |
return; |
| 206 |
|
|
} |
| 207 |
|
|
|
| 208 |
|
|
BIO_set_close(file, BIO_CLOSE); |
| 209 |
|
|
BIO_free(file); |
| 210 |
|
|
} |
| 211 |
|
|
|
| 212 |
|
|
/* |
| 213 |
|
|
* parse_flag_list() |
| 214 |
|
|
* |
| 215 |
|
|
* Parses a list of oper flags |
| 216 |
|
|
* |
| 217 |
|
|
* inputs: |
| 218 |
|
|
* list - points to a dlink_list of strings to parse |
| 219 |
|
|
* var - where to save the result as unsigned int |
| 220 |
|
|
* output: none |
| 221 |
|
|
*/ |
| 222 |
|
|
static void |
| 223 |
|
|
parse_flag_list(void *list, void *where) |
| 224 |
|
|
{ |
| 225 |
|
|
dlink_node *ptr; |
| 226 |
|
|
unsigned int flags = 0; |
| 227 |
|
|
int found; |
| 228 |
|
|
struct FlagMapping *p; |
| 229 |
|
|
|
| 230 |
|
|
DLINK_FOREACH(ptr, ((dlink_list *)list)->head) |
| 231 |
|
|
{ |
| 232 |
|
|
const char *str = ptr->data; |
| 233 |
|
|
|
| 234 |
|
|
found = 0; |
| 235 |
|
|
for (p = flags_mappings; p->name; ++p) |
| 236 |
|
|
{ |
| 237 |
|
|
if (!irccmp(str, p->name)) |
| 238 |
|
|
{ |
| 239 |
|
|
flags |= p->flag; |
| 240 |
|
|
found = YES; |
| 241 |
|
|
break; |
| 242 |
|
|
} |
| 243 |
|
|
} |
| 244 |
|
|
|
| 245 |
|
|
if (!found) |
| 246 |
|
|
parse_error("Unknown flag [%s]", str); |
| 247 |
|
|
} |
| 248 |
|
|
|
| 249 |
|
|
&tmpoper.conf->AccessItem->port = flags; |
| 250 |
|
|
} |
| 251 |
|
|
|
| 252 |
|
|
void |
| 253 |
|
|
init_operator(void) |
| 254 |
|
|
{ |
| 255 |
michael |
419 |
const char *alias[] = { "oper", "operator", NULL }; |
| 256 |
|
|
const char *p = alias; |
| 257 |
michael |
417 |
|
| 258 |
michael |
418 |
hreset = install_hook(reset_conf, reset_operator); |
| 259 |
michael |
417 |
|
| 260 |
michael |
419 |
for (; p != NULL; ++p) |
| 261 |
|
|
{ |
| 262 |
|
|
struct ConfSection *s = add_conf_section(p, 2); |
| 263 |
michael |
417 |
|
| 264 |
michael |
419 |
s->before = before_operator; |
| 265 |
michael |
417 |
|
| 266 |
adx |
423 |
s->def_field = add_conf_field(s, "name", CT_STRING, NULL, &tmpoper.name); |
| 267 |
michael |
419 |
add_conf_field(s, "user", CT_STRING, oper_user, NULL); |
| 268 |
|
|
add_conf_field(s, "class", CT_STRING, oper_class, NULL); |
| 269 |
|
|
add_conf_field(s, "password", CT_STRING, NULL, &tmpoper.conf->AccessItem->password); |
| 270 |
|
|
add_conf_field(s, "encrypted", CT_BOOL, oper_encrypted, NULL); |
| 271 |
|
|
add_conf_field(s, "rsa_public_keyfile", CT_STRING, oper_rsa_public_key_file, NULL); |
| 272 |
|
|
add_conf_field(s, "flags", CT_LIST, parse_flag_list, NULL); |
| 273 |
michael |
417 |
|
| 274 |
michael |
419 |
s->after = after_operator; |
| 275 |
|
|
} |
| 276 |
michael |
417 |
} |