]> jfr.im git - irc/freenode/solanum.git/blob - include/privilege.h
Make privilegeset_privs more const
[irc/freenode/solanum.git] / include / privilege.h
1 /*
2 * Solanum: a slightly advanced ircd
3 * privilege.h: Dynamic privileges API.
4 *
5 * Copyright (c) 2021 Ed Kellett <e@kellett.im>
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 * Copyright (c) 2008 William Pitcock <nenolod@dereferenced.org>
23 *
24 * Permission to use, copy, modify, and/or distribute this software for any
25 * purpose with or without fee is hereby granted, provided that the above
26 * copyright notice and this permission notice is present in all copies.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
32 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
37 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
39 */
40
41 #ifndef __SOLANUM_PRIVILEGE_H
42 #define __SOLANUM_PRIVILEGE_H
43
44 #include "stdinc.h"
45
46 enum {
47 PRIV_NEEDOPER = 1
48 };
49 typedef unsigned int PrivilegeFlags;
50
51 struct PrivilegeSet {
52 rb_dlink_node node;
53 size_t size;
54 const char **privs;
55 size_t stored_size, allocated_size;
56 char *priv_storage;
57 char *name;
58 struct PrivilegeSet *shadow;
59 PrivilegeFlags flags;
60 unsigned int status; /* If CONF_ILLEGAL, delete when no refs */
61 int refs;
62 };
63
64 struct privset_diff {
65 const struct PrivilegeSet *unchanged;
66 const struct PrivilegeSet *added;
67 const struct PrivilegeSet *removed;
68 };
69
70 bool privilegeset_in_set(const struct PrivilegeSet *set, const char *priv);
71 const char *const *privilegeset_privs(const struct PrivilegeSet *set);
72 struct PrivilegeSet *privilegeset_set_new(const char *name, const char *privs, PrivilegeFlags flags);
73 struct PrivilegeSet *privilegeset_extend(const struct PrivilegeSet *parent, const char *name, const char *privs, PrivilegeFlags flags);
74 struct PrivilegeSet *privilegeset_get(const char *name);
75 struct PrivilegeSet *privilegeset_ref(struct PrivilegeSet *set);
76 void privilegeset_unref(struct PrivilegeSet *set);
77 void privilegeset_prepare_rehash(void);
78 void privilegeset_cleanup_rehash(void);
79 void privilegeset_report(struct Client *source_p);
80
81 struct privset_diff privilegeset_diff(const struct PrivilegeSet *, const struct PrivilegeSet *);
82
83 #endif