ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/src/conf/operator.c
Revision: 475
Committed: Sat Feb 18 02:34:20 2006 UTC (20 years, 5 months ago) by adx
Content type: text/x-csrc
File size: 6990 byte(s)
Log Message:
+ make it compile, and maybe even run...

File Contents

# User Rev Content
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 adx 475 #include "stdinc.h"
26     #include "client.h"
27 michael 417
28     static dlink_node *hreset = NULL;
29     static struct AccessItem tmpoper;
30    
31     static const struct FlagMapping {
32     const char *name;
33     unsigned int flags;
34     } flag_mappings[] = {
35     {"global_kill", OPER_FLAG_GLOBAL_KILL},
36     {"remote", OPER_FLAG_REMOTE},
37     {"remoteban", OPER_FLAG_REMOTEBAN},
38     {"kline", OPER_FLAG_K},
39     {"unkline", OPER_FLAG_UNKLINE},
40     {"gline", OPER_FLAG_GLINE},
41     {"xline", OPER_FLAG_X},
42     {"operwall", OPER_FLAG_OPERWALL},
43     {"nick_changes", OPER_FLAG_N},
44     {"rehash", OPER_FLAG_REHASH},
45     {"die", OPER_FLAG_DIE},
46     {"admin", OPER_FLAG_ADMIN},
47     {"hidden_admin", OPER_FLAG_HIDDEN_ADMIN},
48     {"hidden_oper", OPER_FLAG_HIDDEN_OPER},
49     { NULL, 0 }
50     };
51    
52 michael 422 void
53     conf_operator_report(struct Client *source_p)
54     {
55     dlink_node *ptr = NULL;
56    
57     DLINK_FOREACH(ptr, oconf_items.head)
58     {
59     dlink_node *ptr_mask = NULL;
60     struct ConfItem *conf = ptr->data;
61     struct AccessItem *aconf = &conf->conf.AccessItem;
62     assert(aconf->class_ptr);
63    
64     DLINK_FOREACH(ptr_mask, conf->mask_list.head)
65     {
66     const struct split_nuh_item *nuh = ptr_mask->data;
67    
68     /* Don't allow non opers to see oper privs */
69     if (IsOper(source_p))
70     sendto_one(source_p, form_str(RPL_STATSOLINE), me.name,
71     source_p->name, 'O', nuh->userptr, nuh->hostptr,
72     conf->name, oper_privs_as_string(aconf->port),
73     aconf->class_ptr->name);
74     else
75     sendto_one(source_p, form_str(RPL_STATSOLINE),
76     me.name, source_p->name, 'O', nuh->userptr, nuh->hostptr,
77     conf->name, "0",
78     aconf->class_ptr->name);
79     }
80     }
81     }
82     }
83    
84 michael 417 static void
85 michael 418 reset_operator(void)
86     {
87     dlink_node *ptr = NULL, *ptr_next = NULL;
88    
89     DLINK_FOREACH_SAFE(ptr, ptr_next, oconf_items.head)
90     delete_conf_item(ptr->data);
91     }
92    
93     static void
94 michael 417 before_operator(void)
95     {
96     memset(&tmpoper, 0, sizeof(tmpoper));
97    
98     SetConfEncrypted(&tmpoper.conf->AccessItem);
99     }
100    
101     static void
102     after_operator(void)
103     {
104     struct ConfItem *oper = NULL;
105     struct AccessItem *yy_tmp = &tmpoper.conf->AccessItem;
106    
107     if (tmpoper.name == NULL ||
108     yy_tmp->host == NULL ||
109     yy_tmp->user == NULL)
110     return;
111    
112     if (&tmpoper.conf->AccessItem->class_ptr == NULL)
113 michael 418 {
114     parse_error("Invalid or non-existant class in operator{}");
115 michael 417 return;
116 michael 418 }
117 michael 417
118     if (!yy_tmp->passwd && !yy_aconf->rsa_public_key)
119 michael 418 return;
120 michael 417
121     oper = make_conf_item(OPER_TYPE);
122    
123     /* XXX Temporary hack until we changed make_conf_item() so it doesn't add
124     * newly created items onto doubly linked lists immediately after creation */
125     &tmpoper.node->head = oper->node.head;
126     &tmpoper.node->tail = oper->node.tail;
127     &tmpoper.node->data = oper->node.data;
128    
129     memcpy(oper, &tmpoper, sizeof(*oper));
130     }
131    
132     static void
133     oper_encrypted(void *value, void *where)
134     {
135    
136     if (*(int *)value)
137     SetConfEncrypted(&tmpoper.conf->AccessItem);
138     else
139     ClearConfEncrypted(&tmpoper.conf->AccessItem);
140     }
141    
142     static void
143     oper_user(void *value, *void where)
144     {
145     char *str = value;
146     char userbuf[USERLEN + 1];
147     char hostbuf[HOSTLEN + 1];
148     struct split_nuh_item nuh, *cuh;
149    
150     nuh.nuhmask = str;
151     nuh.nickptr = NULL;
152     nuh.userptr = userbuf;
153     nuh.hostptr = hostbuf;
154    
155     nuh.nicksize = 0;
156     nuh.usersize = sizeof(userbuf);
157     nuh.hostsize = sizeof(hostbuf);
158    
159     split_nuh(&nuh);
160    
161     cuh = MyMalloc(sizeof(*cuh));
162     DupString(cuh->userptr, nuh.userptr);
163     DupString(cuh->hostptr, nuh.hostptr);
164    
165     dlinkAdd(cuh, &cuh->node, &tmpoper.conf->AccessItem->mask_list);
166     }
167    
168     static void
169     operator_class(void *value, void *where)
170     {
171 michael 418 tmpoper.conf->AccessItem->class_ptr = find_class(value);
172 michael 417 }
173    
174     static void
175     oper_rsa_public_key_file(void *value, void *where)
176     {
177     const char *str = value;
178     struct AccessItem *yy_tmp = &tmpoper.conf->AccessItem;
179     BIO *file = NULL;
180    
181     if (yy_aconf->rsa_public_key != NULL)
182     {
183     RSA_free(yy_aconf->rsa_public_key);
184     yy_aconf->rsa_public_key = NULL;
185     }
186    
187     if (yy_aconf->rsa_public_key_file != NULL)
188     {
189     MyFree(yy_aconf->rsa_public_key_file);
190     yy_aconf->rsa_public_key_file = NULL;
191     }
192    
193     DupString(yy_aconf->rsa_public_key_file, str);
194     file = BIO_new_file(str, "r");
195    
196     if (file == NULL)
197     {
198 michael 418 parse_error("Ignoring rsa_public_key_file -- file doesn't exist");
199 michael 417 return;
200     }
201    
202     yy_aconf->rsa_public_key = (RSA *)PEM_read_bio_RSA_PUBKEY(file, NULL, 0, NULL);
203    
204     if (yy_aconf->rsa_public_key == NULL)
205     {
206 michael 418 parse_error("Ignoring rsa_public_key_file -- Key invalid; check key syntax.");
207 michael 417 return;
208     }
209    
210     BIO_set_close(file, BIO_CLOSE);
211     BIO_free(file);
212     }
213    
214     /*
215     * parse_flag_list()
216     *
217     * Parses a list of oper flags
218     *
219     * inputs:
220     * list - points to a dlink_list of strings to parse
221     * var - where to save the result as unsigned int
222     * output: none
223     */
224     static void
225     parse_flag_list(void *list, void *where)
226     {
227     dlink_node *ptr;
228     unsigned int flags = 0;
229     int found;
230     struct FlagMapping *p;
231    
232     DLINK_FOREACH(ptr, ((dlink_list *)list)->head)
233     {
234     const char *str = ptr->data;
235    
236     found = 0;
237     for (p = flags_mappings; p->name; ++p)
238     {
239     if (!irccmp(str, p->name))
240     {
241     flags |= p->flag;
242     found = YES;
243     break;
244     }
245     }
246    
247     if (!found)
248     parse_error("Unknown flag [%s]", str);
249     }
250    
251     &tmpoper.conf->AccessItem->port = flags;
252     }
253    
254     void
255     init_operator(void)
256     {
257 michael 419 const char *alias[] = { "oper", "operator", NULL };
258     const char *p = alias;
259 michael 417
260 michael 418 hreset = install_hook(reset_conf, reset_operator);
261 michael 417
262 michael 419 for (; p != NULL; ++p)
263     {
264     struct ConfSection *s = add_conf_section(p, 2);
265 michael 417
266 michael 419 s->before = before_operator;
267 michael 417
268 adx 423 s->def_field = add_conf_field(s, "name", CT_STRING, NULL, &tmpoper.name);
269 michael 419 add_conf_field(s, "user", CT_STRING, oper_user, NULL);
270     add_conf_field(s, "class", CT_STRING, oper_class, NULL);
271     add_conf_field(s, "password", CT_STRING, NULL, &tmpoper.conf->AccessItem->password);
272     add_conf_field(s, "encrypted", CT_BOOL, oper_encrypted, NULL);
273     add_conf_field(s, "rsa_public_keyfile", CT_STRING, oper_rsa_public_key_file, NULL);
274     add_conf_field(s, "flags", CT_LIST, parse_flag_list, NULL);
275 michael 417
276 michael 419 s->after = after_operator;
277     }
278 michael 417 }

Properties

Name Value
svn:eol-style native
svn:keywords "Id Revision"