1 1.3 christos /* $NetBSD: overlay.c,v 1.4 2025/09/05 21:16:28 christos Exp $ */ 2 1.2 christos 3 1.1 lukem /* overlay.c - deals with overlay subsystem */ 4 1.1 lukem /* This work is part of OpenLDAP Software <http://www.openldap.org/>. 5 1.1 lukem * 6 1.4 christos * Copyright 2001-2024 The OpenLDAP Foundation. 7 1.1 lukem * Portions Copyright 2001-2003 Pierangelo Masarati. 8 1.1 lukem * All rights reserved. 9 1.1 lukem * 10 1.1 lukem * Redistribution and use in source and binary forms, with or without 11 1.1 lukem * modification, are permitted only as authorized by the OpenLDAP 12 1.1 lukem * Public License. 13 1.1 lukem * 14 1.1 lukem * A copy of this license is available in file LICENSE in the 15 1.1 lukem * top-level directory of the distribution or, alternatively, at 16 1.1 lukem * <http://www.OpenLDAP.org/license.html>. 17 1.1 lukem */ 18 1.1 lukem /* ACKNOWLEDGEMENTS: 19 1.1 lukem * This work was initially developed by Pierangelo Masarati for inclusion 20 1.1 lukem * in OpenLDAP Software. 21 1.1 lukem */ 22 1.1 lukem 23 1.1 lukem 24 1.2 christos #include <sys/cdefs.h> 25 1.3 christos __RCSID("$NetBSD: overlay.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 <stdio.h> 30 1.1 lukem #include <ac/string.h> 31 1.1 lukem 32 1.1 lukem #include "slap.h" 33 1.1 lukem #include "back-monitor.h" 34 1.1 lukem 35 1.1 lukem /* 36 1.1 lukem * initializes overlay subentries 37 1.1 lukem */ 38 1.1 lukem int 39 1.1 lukem monitor_subsys_overlay_init( 40 1.1 lukem BackendDB *be, 41 1.1 lukem monitor_subsys_t *ms 42 1.1 lukem ) 43 1.1 lukem { 44 1.1 lukem monitor_info_t *mi; 45 1.4 christos Entry *e_overlay; 46 1.1 lukem int i; 47 1.1 lukem monitor_entry_t *mp; 48 1.1 lukem slap_overinst *on; 49 1.1 lukem monitor_subsys_t *ms_database; 50 1.1 lukem 51 1.1 lukem mi = ( monitor_info_t * )be->be_private; 52 1.1 lukem 53 1.1 lukem ms_database = monitor_back_get_subsys( SLAPD_MONITOR_DATABASE_NAME ); 54 1.1 lukem if ( ms_database == NULL ) { 55 1.1 lukem Debug( LDAP_DEBUG_ANY, 56 1.1 lukem "monitor_subsys_backend_init: " 57 1.1 lukem "unable to get " 58 1.1 lukem "\"" SLAPD_MONITOR_DATABASE_NAME "\" " 59 1.3 christos "subsystem\n" ); 60 1.1 lukem return -1; 61 1.1 lukem } 62 1.1 lukem 63 1.1 lukem if ( monitor_cache_get( mi, &ms->mss_ndn, &e_overlay ) ) { 64 1.1 lukem Debug( LDAP_DEBUG_ANY, 65 1.1 lukem "monitor_subsys_overlay_init: " 66 1.1 lukem "unable to get entry \"%s\"\n", 67 1.3 christos ms->mss_ndn.bv_val ); 68 1.1 lukem return( -1 ); 69 1.1 lukem } 70 1.1 lukem 71 1.1 lukem for ( on = overlay_next( NULL ), i = 0; on; on = overlay_next( on ), i++ ) { 72 1.1 lukem char buf[ BACKMONITOR_BUFSIZE ]; 73 1.1 lukem struct berval bv; 74 1.1 lukem int j; 75 1.1 lukem Entry *e; 76 1.1 lukem BackendDB *be; 77 1.1 lukem 78 1.1 lukem bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Overlay %d", i ); 79 1.1 lukem bv.bv_val = buf; 80 1.1 lukem e = monitor_entry_stub( &ms->mss_dn, &ms->mss_ndn, &bv, 81 1.2 christos mi->mi_oc_monitoredObject, NULL, NULL ); 82 1.1 lukem if ( e == NULL ) { 83 1.1 lukem Debug( LDAP_DEBUG_ANY, 84 1.1 lukem "monitor_subsys_overlay_init: " 85 1.1 lukem "unable to create entry \"cn=Overlay %d,%s\"\n", 86 1.3 christos i, ms->mss_ndn.bv_val ); 87 1.1 lukem return( -1 ); 88 1.1 lukem } 89 1.1 lukem ber_str2bv( on->on_bi.bi_type, 0, 0, &bv ); 90 1.1 lukem attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo, &bv, NULL ); 91 1.1 lukem attr_merge_normalize_one( e, mi->mi_ad_monitorRuntimeConfig, 92 1.1 lukem on->on_bi.bi_cf_ocs ? (struct berval *)&slap_true_bv : 93 1.1 lukem (struct berval *)&slap_false_bv, NULL ); 94 1.1 lukem 95 1.1 lukem attr_merge_normalize_one( e_overlay, mi->mi_ad_monitoredInfo, 96 1.1 lukem &bv, NULL ); 97 1.1 lukem 98 1.1 lukem j = -1; 99 1.1 lukem LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) { 100 1.1 lukem char buf[ SLAP_LDAPDN_MAXLEN ]; 101 1.1 lukem struct berval dn; 102 1.1 lukem 103 1.1 lukem j++; 104 1.1 lukem if ( !overlay_is_inst( be, on->on_bi.bi_type ) ) { 105 1.1 lukem continue; 106 1.1 lukem } 107 1.1 lukem 108 1.1 lukem snprintf( buf, sizeof( buf ), "cn=Database %d,%s", 109 1.1 lukem j, ms_database->mss_dn.bv_val ); 110 1.1 lukem 111 1.1 lukem ber_str2bv( buf, 0, 0, &dn ); 112 1.1 lukem attr_merge_normalize_one( e, slap_schema.si_ad_seeAlso, 113 1.1 lukem &dn, NULL ); 114 1.1 lukem } 115 1.1 lukem 116 1.1 lukem mp = monitor_entrypriv_create(); 117 1.1 lukem if ( mp == NULL ) { 118 1.1 lukem return -1; 119 1.1 lukem } 120 1.1 lukem e->e_private = ( void * )mp; 121 1.1 lukem mp->mp_info = ms; 122 1.1 lukem mp->mp_flags = ms->mss_flags 123 1.1 lukem | MONITOR_F_SUB; 124 1.1 lukem 125 1.4 christos if ( monitor_cache_add( mi, e, e_overlay ) ) { 126 1.1 lukem Debug( LDAP_DEBUG_ANY, 127 1.1 lukem "monitor_subsys_overlay_init: " 128 1.1 lukem "unable to add entry \"cn=Overlay %d,%s\"\n", 129 1.3 christos i, ms->mss_ndn.bv_val ); 130 1.1 lukem return( -1 ); 131 1.1 lukem } 132 1.1 lukem } 133 1.1 lukem 134 1.1 lukem monitor_cache_release( mi, e_overlay ); 135 1.1 lukem 136 1.1 lukem return( 0 ); 137 1.1 lukem } 138 1.1 lukem 139