ARPA2 Common Libraries  2.6.2
access.h
1 
31 /* SPDX-FileCopyrightText: Copyright 2020 Rick van Rein <rick@openfortress.nl>
32  * SPDX-License-Identifier: BSD-2-Clause
33  */
34 
35 
36 #ifndef ARPA2_ACCESS_H
37 #define ARPA2_ACCESS_H
38 
39 
40 #include <stdbool.h>
41 #include <stdint.h>
42 
43 #include "arpa2/identity.h"
44 #include "arpa2/rules.h"
45 
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 
89 
90 
124 
125 
152 
153 
163 
164 
173 #define ACCESS_RIGHT(c) ( 1 << (c - 'A') )
174 
175 
176 /* Rights to resources, from the highest grade to lower,
177  * though it is up to the resource settings to actually
178  * allow lower-grade rights along with higher-grade
179  * rights like set with the _DOWN definitions below -- or
180  * they may choose to withhold those implied privileges.
181  * Applications have the opposite option; they may reason
182  * that higher rights grant lower privileges, and use the
183  * _UP macros to derive the bit mask to work with. There
184  * is no harm in combining these approaches.
185  *
186  * ACCESS_ADMIN is the highest privilege, reserved for humans
187  * with overall access to everything.
188  *
189  * ACCESS_SERVICE is the highest automation privilege, reserved
190  * for bots and such performing administrative changes.
191  *
192  * ACCESS_CONFIGURE is the right to modify the configuration of
193  * a service.
194  *
195  * ACCESS_OPERATE is the right to start or stop a service, not
196  * knowing anything about its contents or resources.
197  *
198  * ACCESS_DELETE is the right to delete a resource. This is
199  * the highest resource right because it can undo all
200  * the other levels.
201  *
202  * ACCESS_CREATE is the right to create a resource. Other than
203  * perhaps defining a name or retrieving an identity is
204  * not permitted with this, and certainly no changes.
205  *
206  * ACCESS_EXECUTE is the right to run a service or make a
207  * resource do something, such as accepting connections.
208  *
209  * ACCESS_WRITE is the right to write to an existing resource.
210  *
211  * ACCESS_READ is the right to read from an existing resource.
212  *
213  * ACCESS_PROVE is the right to prove properties about the
214  * resource. An example could be a password check
215  * without actually seeing a key stored for that use.
216  *
217  * ACCESS_KNOW is the right to know about the existence of a
218  * resource. It is not the right to know anything about
219  * its contents, nor to create or delete resources.
220  *
221  * ACCESS_OWNER is the right to own a resource. This may sound
222  * like a lot, but it really does not allow to do anything
223  * with it. A directory or an account might have this
224  * right, for instance. It is mostly useful to pin the
225  * owner on the resource.
226  *
227  * ACCESS_VISITOR is the lowest of all rights. It allows no actual
228  * operations, not even to know whether a resource exists.
229  * It is the ultimate send-away ("kluitje in het riet") right.
230  *
231  * ACCESS_FORBIDDEN is not even a proper level. It simply has no
232  * flags at all, and is a downright negative, "damn all"
233  * response. Try to be careful about this one; normally
234  * you might be able to include a cautious ACCESS_VISITOR
235  * level.
236  */
237 #define ACCESS_ADMIN ACCESS_RIGHT('A')
238 #define ACCESS_SERVICE ACCESS_RIGHT('S')
239 #define ACCESS_CONFIG ACCESS_RIGHT('F')
240 #define ACCESS_OPERATE ACCESS_RIGHT('T')
241 #define ACCESS_DELETE ACCESS_RIGHT('D')
242 #define ACCESS_CREATE ACCESS_RIGHT('C')
243 #define ACCESS_EXECUTE ACCESS_RIGHT('X')
244 #define ACCESS_WRITE ACCESS_RIGHT('W')
245 #define ACCESS_READ ACCESS_RIGHT('R')
246 #define ACCESS_PROVE ACCESS_RIGHT('P')
247 #define ACCESS_KNOW ACCESS_RIGHT('K')
248 #define ACCESS_OWNER ACCESS_RIGHT('O')
249 #define ACCESS_VISITOR ACCESS_RIGHT('V')
250 //
251 #define ACCESS_FORBIDDEN 0
252 
253 
254 /* The ACL rights with their higher rights added, to allow for
255  * easier tests of inclusiveness.
256  */
257 #define ACCESS_ADMIN_UP ( ACCESS_ADMIN | 0 )
258 #define ACCESS_SERVICE_UP ( ACCESS_SERVICE | ACCESS_ADMIN_UP )
259 #define ACCESS_CONFIG_UP ( ACCESS_CONFIG | ACCESS_SERVICE_UP )
260 #define ACCESS_OPERATE_UP ( ACCESS_OPERATE | ACCESS_CONFIG_UP )
261 #define ACCESS_DELETE_UP ( ACCESS_DELETE | ACCESS_OPERATE_UP )
262 #define ACCESS_CREATE_UP ( ACCESS_CREATE | ACCESS_DELETE_UP )
263 #define ACCESS_EXECUTE_UP ( ACCESS_EXECUTE | ACCESS_CREATE_UP )
264 #define ACCESS_WRITE_UP ( ACCESS_WRITE | ACCESS_EXECUTE_UP )
265 #define ACCESS_READ_UP ( ACCESS_READ | ACCESS_WRITE_UP )
266 #define ACCESS_PROVE_UP ( ACCESS_PROVE | ACCESS_READ_UP )
267 #define ACCESS_KNOW_UP ( ACCESS_KNOW | ACCESS_PROVE_UP )
268 #define ACCESS_OWNER_UP ( ACCESS_OWNER | ACCESS_KNOW_UP )
269 #define ACCESS_VISITOR_UP ( ACCESS_VISITOR | ACCESS_OWNER_UP )
270 
271 
272 /* The ACL rights with their lower rights added, to allow for
273  * easier tests of inclusiveness.
274  */
275 #define ACCESS_ADMIN_DOWN ( ACCESS_ADMIN | ACCESS_SERVICE_DOWN )
276 #define ACCESS_SERVICE_DOWN ( ACCESS_SERVICE | ACCESS_CONFIG_DOWN )
277 #define ACCESS_CONFIG_DOWN ( ACCESS_CONFIG | ACCESS_OPERATE_DOWN )
278 #define ACCESS_OPERATE_DOWN ( ACCESS_OPERATE | ACCESS_DELETE_DOWN )
279 #define ACCESS_DELETE_DOWN ( ACCESS_DELETE | ACCESS_CREATE_DOWN )
280 #define ACCESS_CREATE_DOWN ( ACCESS_CREATE | ACCESS_EXECUTE_DOWN )
281 #define ACCESS_EXECUTE_DOWN ( ACCESS_EXECUTE | ACCESS_WRITE_DOWN )
282 #define ACCESS_WRITE_DOWN ( ACCESS_WRITE | ACCESS_READ_DOWN )
283 #define ACCESS_READ_DOWN ( ACCESS_READ | ACCESS_PROVE_DOWN )
284 #define ACCESS_PROVE_DOWN ( ACCESS_PROVE | ACCESS_KNOW_DOWN )
285 #define ACCESS_KNOW_DOWN ( ACCESS_KNOW | ACCESS_OWNER_DOWN )
286 #define ACCESS_OWNER_DOWN ( ACCESS_OWNER | ACCESS_VISITOR_DOWN )
287 #define ACCESS_VISITOR_DOWN ( ACCESS_VISITOR | 0 )
288 
289 
323 bool access_parse (char *userstr, access_rights *accumulator);
324 
325 
326 
351 void access_format (const char *opt_fmtstr, access_rights rights, char *outstr);
352 
353 
358 static inline void access_init (void) {
359  rules_init ();
360 }
361 
362 
367 static inline void access_fini (void) {
368  rules_fini ();
369 }
370 
371 
392 const char *access_host2domain (const char *fqdn_hostname);
393 
394 
397 #ifdef __cplusplus
398 }
399 #endif
400 
401 #endif /* ARPA2_ACCESS_H */
402 
void access_format(const char *opt_fmtstr, access_rights rights, char *outstr)
Format Access Rights flags to a string.
const char * access_host2domain(const char *fqdn_hostname)
Lookup the realm for a fully qualified host name.
static void access_init(void)
Initialise the ARPA2 Access system.
Definition: access.h:358
static void access_fini(void)
Finalise the ARPA2 Access system.
Definition: access.h:367
bool access_parse(char *userstr, access_rights *accumulator)
Parse a string of Access Rights flags.
rules_flags access_rights
Access Rights in a bit mask.
Definition: access.h:162
rules_name access_name
Access Names represent instances of an Access Type.
Definition: access.h:151
rules_type access_type
Access Types are 128-bit "well-known service identities".
Definition: access.h:123
rules_domain access_domain
Access Domains are UTF-8 representations of a Fully Qualified Domain Name.
Definition: access.h:88
void rules_init(void)
Initialise the ARPA2 Rules system.
void rules_fini(void)
Finalise the ARPA2 Rules system.
uint32_t rules_flags
Flags in a bit mask.
Definition: rules.h:214
char * rules_domain
Rules Domains are UTF-8 representations of a Fully Qualified Domain Name.
Definition: rules.h:99
uint8_t rules_type[16]
Rules Types are 128-bit "well-known service identities".
Definition: rules.h:134
char * rules_name
Rules Names represent instances of a Rules Type.
Definition: rules.h:167