1 1.3 christos /* $NetBSD: entry.c,v 1.4 2025/09/05 21:16:28 christos Exp $ */ 2 1.2 christos 3 1.1 lukem /* entry.c - monitor backend entry handling routines */ 4 1.2 christos /* $OpenLDAP$ */ 5 1.1 lukem /* This work is part of OpenLDAP Software <http://www.openldap.org/>. 6 1.1 lukem * 7 1.4 christos * Copyright 2001-2024 The OpenLDAP Foundation. 8 1.1 lukem * Portions Copyright 2001-2003 Pierangelo Masarati. 9 1.1 lukem * All rights reserved. 10 1.1 lukem * 11 1.1 lukem * Redistribution and use in source and binary forms, with or without 12 1.1 lukem * modification, are permitted only as authorized by the OpenLDAP 13 1.1 lukem * Public License. 14 1.1 lukem * 15 1.1 lukem * A copy of this license is available in file LICENSE in the 16 1.1 lukem * top-level directory of the distribution or, alternatively, at 17 1.1 lukem * <http://www.OpenLDAP.org/license.html>. 18 1.1 lukem */ 19 1.1 lukem /* ACKNOWLEDGEMENTS: 20 1.1 lukem * This work was initially developed by Pierangelo Masarati for inclusion 21 1.1 lukem * in OpenLDAP Software. 22 1.1 lukem */ 23 1.1 lukem 24 1.2 christos #include <sys/cdefs.h> 25 1.3 christos __RCSID("$NetBSD: entry.c,v 1.4 2025/09/05 21:16:28 christos Exp $"); 26 1.2 christos 27 1.1 lukem #include "portable.h" 28 1.1 lukem 29 1.1 lukem #include <slap.h> 30 1.1 lukem #include "back-monitor.h" 31 1.1 lukem 32 1.1 lukem int 33 1.1 lukem monitor_entry_update( 34 1.1 lukem Operation *op, 35 1.1 lukem SlapReply *rs, 36 1.1 lukem Entry *e 37 1.1 lukem ) 38 1.1 lukem { 39 1.1 lukem monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private; 40 1.1 lukem monitor_entry_t *mp; 41 1.1 lukem 42 1.1 lukem int rc = SLAP_CB_CONTINUE; 43 1.1 lukem 44 1.1 lukem assert( mi != NULL ); 45 1.1 lukem assert( e != NULL ); 46 1.1 lukem assert( e->e_private != NULL ); 47 1.1 lukem 48 1.1 lukem mp = ( monitor_entry_t * )e->e_private; 49 1.1 lukem 50 1.1 lukem if ( mp->mp_cb ) { 51 1.1 lukem struct monitor_callback_t *mc; 52 1.1 lukem 53 1.1 lukem for ( mc = mp->mp_cb; mc; mc = mc->mc_next ) { 54 1.1 lukem if ( mc->mc_update ) { 55 1.1 lukem rc = mc->mc_update( op, rs, e, mc->mc_private ); 56 1.1 lukem if ( rc != SLAP_CB_CONTINUE ) { 57 1.1 lukem break; 58 1.1 lukem } 59 1.1 lukem } 60 1.1 lukem } 61 1.1 lukem } 62 1.1 lukem 63 1.1 lukem if ( rc == SLAP_CB_CONTINUE && mp->mp_info && mp->mp_info->mss_update ) { 64 1.1 lukem rc = mp->mp_info->mss_update( op, rs, e ); 65 1.1 lukem } 66 1.1 lukem 67 1.1 lukem if ( rc == SLAP_CB_CONTINUE ) { 68 1.1 lukem rc = LDAP_SUCCESS; 69 1.1 lukem } 70 1.1 lukem 71 1.1 lukem return rc; 72 1.1 lukem } 73 1.1 lukem 74 1.1 lukem int 75 1.1 lukem monitor_entry_create( 76 1.1 lukem Operation *op, 77 1.1 lukem SlapReply *rs, 78 1.1 lukem struct berval *ndn, 79 1.1 lukem Entry *e_parent, 80 1.1 lukem Entry **ep ) 81 1.1 lukem { 82 1.1 lukem monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private; 83 1.1 lukem monitor_entry_t *mp; 84 1.1 lukem 85 1.1 lukem int rc = SLAP_CB_CONTINUE; 86 1.1 lukem 87 1.1 lukem assert( mi != NULL ); 88 1.1 lukem assert( e_parent != NULL ); 89 1.1 lukem assert( e_parent->e_private != NULL ); 90 1.1 lukem assert( ep != NULL ); 91 1.1 lukem 92 1.1 lukem mp = ( monitor_entry_t * )e_parent->e_private; 93 1.1 lukem 94 1.1 lukem if ( mp->mp_info && mp->mp_info->mss_create ) { 95 1.1 lukem rc = mp->mp_info->mss_create( op, rs, ndn, e_parent, ep ); 96 1.1 lukem } 97 1.1 lukem 98 1.1 lukem if ( rc == SLAP_CB_CONTINUE ) { 99 1.1 lukem rc = LDAP_SUCCESS; 100 1.1 lukem } 101 1.1 lukem 102 1.1 lukem return rc; 103 1.1 lukem } 104 1.1 lukem 105 1.1 lukem int 106 1.1 lukem monitor_entry_modify( 107 1.1 lukem Operation *op, 108 1.1 lukem SlapReply *rs, 109 1.1 lukem Entry *e 110 1.1 lukem ) 111 1.1 lukem { 112 1.1 lukem monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private; 113 1.1 lukem monitor_entry_t *mp; 114 1.1 lukem 115 1.1 lukem int rc = SLAP_CB_CONTINUE; 116 1.1 lukem 117 1.1 lukem assert( mi != NULL ); 118 1.1 lukem assert( e != NULL ); 119 1.1 lukem assert( e->e_private != NULL ); 120 1.1 lukem 121 1.1 lukem mp = ( monitor_entry_t * )e->e_private; 122 1.1 lukem 123 1.1 lukem if ( mp->mp_cb ) { 124 1.1 lukem struct monitor_callback_t *mc; 125 1.1 lukem 126 1.1 lukem for ( mc = mp->mp_cb; mc; mc = mc->mc_next ) { 127 1.1 lukem if ( mc->mc_modify ) { 128 1.1 lukem rc = mc->mc_modify( op, rs, e, mc->mc_private ); 129 1.1 lukem if ( rc != SLAP_CB_CONTINUE ) { 130 1.1 lukem break; 131 1.1 lukem } 132 1.1 lukem } 133 1.1 lukem } 134 1.1 lukem } 135 1.1 lukem 136 1.1 lukem if ( rc == SLAP_CB_CONTINUE && mp->mp_info && mp->mp_info->mss_modify ) { 137 1.1 lukem rc = mp->mp_info->mss_modify( op, rs, e ); 138 1.1 lukem } 139 1.1 lukem 140 1.1 lukem if ( rc == SLAP_CB_CONTINUE ) { 141 1.1 lukem rc = LDAP_SUCCESS; 142 1.1 lukem } 143 1.1 lukem 144 1.1 lukem return rc; 145 1.1 lukem } 146 1.1 lukem 147 1.1 lukem int 148 1.1 lukem monitor_entry_test_flags( 149 1.1 lukem monitor_entry_t *mp, 150 1.1 lukem int cond 151 1.1 lukem ) 152 1.1 lukem { 153 1.1 lukem assert( mp != NULL ); 154 1.1 lukem 155 1.1 lukem return( ( mp->mp_flags & cond ) || ( mp->mp_info->mss_flags & cond ) ); 156 1.1 lukem } 157 1.1 lukem 158 1.1 lukem monitor_entry_t * 159 1.2 christos monitor_back_entrypriv_create( void ) 160 1.1 lukem { 161 1.1 lukem monitor_entry_t *mp; 162 1.1 lukem 163 1.1 lukem mp = ( monitor_entry_t * )ch_calloc( sizeof( monitor_entry_t ), 1 ); 164 1.1 lukem 165 1.1 lukem mp->mp_next = NULL; 166 1.1 lukem mp->mp_children = NULL; 167 1.1 lukem mp->mp_info = NULL; 168 1.1 lukem mp->mp_flags = MONITOR_F_NONE; 169 1.1 lukem mp->mp_cb = NULL; 170 1.1 lukem 171 1.1 lukem ldap_pvt_thread_mutex_init( &mp->mp_mutex ); 172 1.1 lukem 173 1.1 lukem return mp; 174 1.1 lukem } 175 1.1 lukem 176 1.1 lukem Entry * 177 1.1 lukem monitor_entry_stub( 178 1.1 lukem struct berval *pdn, 179 1.1 lukem struct berval *pndn, 180 1.1 lukem struct berval *rdn, 181 1.1 lukem ObjectClass *oc, 182 1.1 lukem struct berval *create, 183 1.1 lukem struct berval *modify 184 1.1 lukem ) 185 1.1 lukem { 186 1.2 christos monitor_info_t *mi; 187 1.1 lukem AttributeDescription *nad = NULL; 188 1.1 lukem Entry *e; 189 1.1 lukem struct berval nat; 190 1.1 lukem char *ptr; 191 1.1 lukem const char *text; 192 1.1 lukem int rc; 193 1.1 lukem 194 1.2 christos mi = ( monitor_info_t * )be_monitor->be_private; 195 1.2 christos 196 1.1 lukem nat = *rdn; 197 1.1 lukem ptr = strchr( nat.bv_val, '=' ); 198 1.1 lukem nat.bv_len = ptr - nat.bv_val; 199 1.1 lukem rc = slap_bv2ad( &nat, &nad, &text ); 200 1.1 lukem if ( rc ) 201 1.1 lukem return NULL; 202 1.1 lukem 203 1.1 lukem e = entry_alloc(); 204 1.1 lukem if ( e ) { 205 1.1 lukem struct berval nrdn; 206 1.1 lukem 207 1.1 lukem rdnNormalize( 0, NULL, NULL, rdn, &nrdn, NULL ); 208 1.1 lukem build_new_dn( &e->e_name, pdn, rdn, NULL ); 209 1.1 lukem build_new_dn( &e->e_nname, pndn, &nrdn, NULL ); 210 1.1 lukem ber_memfree( nrdn.bv_val ); 211 1.1 lukem nat.bv_val = ptr + 1; 212 1.1 lukem nat.bv_len = rdn->bv_len - ( nat.bv_val - rdn->bv_val ); 213 1.1 lukem attr_merge_normalize_one( e, slap_schema.si_ad_objectClass, 214 1.1 lukem &oc->soc_cname, NULL ); 215 1.1 lukem attr_merge_normalize_one( e, slap_schema.si_ad_structuralObjectClass, 216 1.1 lukem &oc->soc_cname, NULL ); 217 1.1 lukem attr_merge_normalize_one( e, nad, &nat, NULL ); 218 1.1 lukem attr_merge_one( e, slap_schema.si_ad_creatorsName, &mi->mi_creatorsName, 219 1.1 lukem &mi->mi_ncreatorsName ); 220 1.1 lukem attr_merge_one( e, slap_schema.si_ad_modifiersName, &mi->mi_creatorsName, 221 1.1 lukem &mi->mi_ncreatorsName ); 222 1.1 lukem attr_merge_normalize_one( e, slap_schema.si_ad_createTimestamp, 223 1.1 lukem create ? create : &mi->mi_startTime, NULL ); 224 1.1 lukem attr_merge_normalize_one( e, slap_schema.si_ad_modifyTimestamp, 225 1.1 lukem modify ? modify : &mi->mi_startTime, NULL ); 226 1.1 lukem } 227 1.1 lukem return e; 228 1.1 lukem } 229 1.3 christos 230 1.3 christos Entry * 231 1.3 christos monitor_entry_get_unlocked( 232 1.3 christos struct berval *ndn 233 1.3 christos ) 234 1.3 christos { 235 1.3 christos monitor_info_t *mi = ( monitor_info_t * )be_monitor->be_private; 236 1.3 christos Entry *ret = NULL; 237 1.3 christos 238 1.3 christos if ( !monitor_cache_get( mi, ndn, &ret )) 239 1.3 christos monitor_cache_release( mi, ret ); 240 1.3 christos return ret; 241 1.3 christos } 242