1 /* $NetBSD: operational.c,v 1.3 2021/08/14 16:14:58 christos Exp $ */
2
3 /* operational.c - routines to deal with on-the-fly operational attrs */
4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 *
6 * Copyright 2001-2021 The OpenLDAP Foundation.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
11 * Public License.
12 *
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
16 */
17
18 #include <sys/cdefs.h>
19 __RCSID("$NetBSD: operational.c,v 1.3 2021/08/14 16:14:58 christos Exp $");
20
21 #include "portable.h"
22
23 #include "slap.h"
24
25 /*
26 * helpers for on-the-fly operational attribute generation
27 */
28
29 Attribute *
slap_operational_subschemaSubentry(Backend * be)30 slap_operational_subschemaSubentry( Backend *be )
31 {
32 Attribute *a;
33
34 /* The backend wants to take care of it */
35 if ( be && !SLAP_FRONTEND(be) && be->be_schemadn.bv_val ) return NULL;
36
37 a = attr_alloc( slap_schema.si_ad_subschemaSubentry );
38
39 a->a_numvals = 1;
40 a->a_vals = ch_malloc( 2 * sizeof( struct berval ) );
41 ber_dupbv( a->a_vals, &frontendDB->be_schemadn );
42 a->a_vals[1].bv_len = 0;
43 a->a_vals[1].bv_val = NULL;
44
45 a->a_nvals = ch_malloc( 2 * sizeof( struct berval ) );
46 ber_dupbv( a->a_nvals, &frontendDB->be_schemandn );
47 a->a_nvals[1].bv_len = 0;
48 a->a_nvals[1].bv_val = NULL;
49
50 return a;
51 }
52
53 Attribute *
slap_operational_entryDN(Entry * e)54 slap_operational_entryDN( Entry *e )
55 {
56 Attribute *a;
57
58 assert( e != NULL );
59 assert( !BER_BVISNULL( &e->e_name ) );
60 assert( !BER_BVISNULL( &e->e_nname ) );
61
62 a = attr_alloc( slap_schema.si_ad_entryDN );
63
64 a->a_numvals = 1;
65 a->a_vals = ch_malloc( 2 * sizeof( struct berval ) );
66 ber_dupbv( &a->a_vals[ 0 ], &e->e_name );
67 BER_BVZERO( &a->a_vals[ 1 ] );
68
69 a->a_nvals = ch_malloc( 2 * sizeof( struct berval ) );
70 ber_dupbv( &a->a_nvals[ 0 ], &e->e_nname );
71 BER_BVZERO( &a->a_nvals[ 1 ] );
72
73 return a;
74 }
75
76 Attribute *
slap_operational_hasSubordinate(int hs)77 slap_operational_hasSubordinate( int hs )
78 {
79 Attribute *a;
80 struct berval val;
81
82 val = hs ? slap_true_bv : slap_false_bv;
83
84 a = attr_alloc( slap_schema.si_ad_hasSubordinates );
85 a->a_numvals = 1;
86 a->a_vals = ch_malloc( 2 * sizeof( struct berval ) );
87
88 ber_dupbv( &a->a_vals[0], &val );
89 a->a_vals[1].bv_val = NULL;
90
91 a->a_nvals = a->a_vals;
92
93 return a;
94 }
95
96