1/* $NetBSD: operational.c,v 1.2 2021/08/14 16:15:02 christos Exp $ */ 2 3/* OpenLDAP WiredTiger backend */ 4/* $OpenLDAP$ */ 5/* This work is part of OpenLDAP Software <http://www.openldap.org/>. 6 * 7 * Copyright 2002-2021 The OpenLDAP Foundation. 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 * This work was developed by HAMANO Tsukasa <hamano@osstech.co.jp> 20 * based on back-bdb for inclusion in OpenLDAP Software. 21 * WiredTiger is a product of MongoDB Inc. 22 */ 23 24#include <sys/cdefs.h> 25__RCSID("$NetBSD: operational.c,v 1.2 2021/08/14 16:15:02 christos Exp $"); 26 27#include "portable.h" 28 29#include <stdio.h> 30#include <ac/string.h> 31 32#include "back-wt.h" 33#include "slap-config.h" 34 35int 36wt_hasSubordinates( 37 Operation *op, 38 Entry *e, 39 int *hasSubordinates ) 40{ 41 struct wt_info *wi = (struct wt_info *) op->o_bd->be_private; 42 wt_ctx *wc = NULL; 43 int rc; 44 45 assert( e != NULL ); 46 47 wc = wt_ctx_get(op, wi); 48 if( !wc ){ 49 Debug( LDAP_DEBUG_ANY, 50 LDAP_XSTRING(wt_compare) 51 ": wt_ctx_get failed\n" ); 52 return LDAP_OTHER; 53 } 54 55 rc = wt_dn2id_has_children(op, wc->session, e->e_id); 56 switch(rc){ 57 case 0: 58 *hasSubordinates = LDAP_COMPARE_TRUE; 59 break; 60 case WT_NOTFOUND: 61 *hasSubordinates = LDAP_COMPARE_FALSE; 62 rc = LDAP_SUCCESS; 63 break; 64 default: 65 Debug(LDAP_DEBUG_ANY, 66 "<=- " LDAP_XSTRING(wt_hasSubordinates) 67 ": has_children failed: %s (%d)\n", 68 wiredtiger_strerror(rc), rc ); 69 rc = LDAP_OTHER; 70 } 71 return rc; 72} 73 74/* 75 * sets the supported operational attributes (if required) 76 */ 77int 78wt_operational( 79 Operation *op, 80 SlapReply *rs ) 81{ 82 Attribute **ap; 83 84 assert( rs->sr_entry != NULL ); 85 86 for ( ap = &rs->sr_operational_attrs; *ap; ap = &(*ap)->a_next ) { 87 if ( (*ap)->a_desc == slap_schema.si_ad_hasSubordinates ) { 88 break; 89 } 90 } 91 92 if ( *ap == NULL && 93 attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_hasSubordinates ) == NULL && 94 ( SLAP_OPATTRS( rs->sr_attr_flags ) || 95 ad_inlist( slap_schema.si_ad_hasSubordinates, rs->sr_attrs ) ) ) 96 { 97 int hasSubordinates, rc; 98 99 rc = wt_hasSubordinates( op, rs->sr_entry, &hasSubordinates ); 100 if ( rc == LDAP_SUCCESS ) { 101 *ap = slap_operational_hasSubordinate( hasSubordinates == LDAP_COMPARE_TRUE ); 102 assert( *ap != NULL ); 103 104 ap = &(*ap)->a_next; 105 } 106 } 107 108 return LDAP_SUCCESS; 109} 110 111/* 112 * Local variables: 113 * indent-tabs-mode: t 114 * tab-width: 4 115 * c-basic-offset: 4 116 * End: 117 */ 118