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