xref: /netbsd-src/external/bsd/openldap/dist/contrib/slapd-modules/rbac/rbacreq.c (revision 549b59ed3ccf0d36d3097190a0db27b770f3a839)
1 /*	$NetBSD: rbacreq.c,v 1.2 2021/08/14 16:14:53 christos Exp $	*/
2 
3 /* rbacreq.c - RBAC requests */
4 /* $OpenLDAP$ */
5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6  *
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted only as authorized by the OpenLDAP
12  * Public License.
13  *
14  * A copy of this license is available in the file LICENSE in the
15  * top-level directory of the distribution or, alternatively, at
16  * <http://www.OpenLDAP.org/license.html>.
17  */
18 /* ACKNOWLEDGEMENTS:
19  */
20 
21 #include <sys/cdefs.h>
22 __RCSID("$NetBSD: rbacreq.c,v 1.2 2021/08/14 16:14:53 christos Exp $");
23 
24 #include "portable.h"
25 
26 #include <stdio.h>
27 
28 #include <ac/string.h>
29 
30 #include "slap.h"
31 #include "slap-config.h"
32 #include "lutil.h"
33 
34 #include "rbac.h"
35 
36 rbac_req_t *
rbac_alloc_req(int type)37 rbac_alloc_req( int type )
38 {
39 	rbac_req_t *reqp = NULL;
40 
41 	reqp = ch_calloc( 1, sizeof(rbac_req_t) );
42 
43 	reqp->req_type = type;
44 	BER_BVZERO( &reqp->sessid );
45 	BER_BVZERO( &reqp->tenantid );
46 	/* session creation */
47 	BER_BVZERO( &reqp->uid );
48 	BER_BVZERO( &reqp->authtok );
49 	reqp->roles = NULL;
50 	/* check access  */
51 	BER_BVZERO( &reqp->opname );
52 	BER_BVZERO( &reqp->objname );
53 	BER_BVZERO( &reqp->objid );
54 	/* add/drop role */
55 	BER_BVZERO( &reqp->role );
56 
57 	return reqp;
58 }
59 
60 void
rbac_free_req(rbac_req_t * reqp)61 rbac_free_req( rbac_req_t *reqp )
62 {
63 	if ( !reqp ) return;
64 
65 	if ( !BER_BVISNULL( &reqp->sessid ) )
66 		ber_memfree( reqp->sessid.bv_val );
67 
68 	if ( !BER_BVISNULL( &reqp->tenantid ) )
69 		ber_memfree( reqp->tenantid.bv_val );
70 
71 	/* session creation */
72 	if ( !BER_BVISNULL( &reqp->uid ) )
73 		ber_memfree( reqp->uid.bv_val );
74 
75 	if ( !BER_BVISNULL( &reqp->authtok ) )
76 		ber_memfree( reqp->authtok.bv_val );
77 
78 	if ( reqp->roles )
79 		ber_bvarray_free( reqp->roles );
80 
81 	/* check access  */
82 	if ( !BER_BVISNULL( &reqp->opname ) )
83 		ber_memfree( reqp->opname.bv_val );
84 
85 	if ( !BER_BVISNULL( &reqp->objname ) )
86 		ber_memfree( reqp->objname.bv_val );
87 
88 	if ( !BER_BVISNULL( &reqp->objid ) )
89 		ber_memfree( reqp->objid.bv_val );
90 
91 	ch_free( reqp );
92 
93 	return;
94 }
95