1 /* $NetBSD: suffixmassage.c,v 1.3 2021/08/14 16:15:00 christos Exp $ */ 2 3 /* suffixmassage.c - massages ldap backend dns */ 4 /* $OpenLDAP$ */ 5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>. 6 * 7 * Copyright 2003-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 initially developed by the Howard Chu for inclusion 20 * in OpenLDAP Software and subsequently enhanced by Pierangelo 21 * Masarati. 22 */ 23 /* This is an altered version */ 24 25 /* 26 * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com> 27 * Copyright 2000, Pierangelo Masarati, All rights reserved. <ando@sys-net.it> 28 * 29 * Module back-ldap, originally developed by Howard Chu 30 * 31 * has been modified by Pierangelo Masarati. The original copyright 32 * notice has been maintained. 33 * 34 * Permission is granted to anyone to use this software for any purpose 35 * on any computer system, and to alter it and redistribute it, subject 36 * to the following restrictions: 37 * 38 * 1. The author is not responsible for the consequences of use of this 39 * software, no matter how awful, even if they arise from flaws in it. 40 * 41 * 2. The origin of this software must not be misrepresented, either by 42 * explicit claim or by omission. Since few users ever read sources, 43 * credits should appear in the documentation. 44 * 45 * 3. Altered versions must be plainly marked as such, and must not be 46 * misrepresented as being the original software. Since few users 47 * ever read sources, credits should appear in the documentation. 48 * 49 * 4. This notice may not be removed or altered. 50 */ 51 52 #include <sys/cdefs.h> 53 __RCSID("$NetBSD: suffixmassage.c,v 1.3 2021/08/14 16:15:00 christos Exp $"); 54 55 #include "portable.h" 56 57 #include <stdio.h> 58 59 #include <ac/string.h> 60 #include <ac/socket.h> 61 62 #include "slap.h" 63 #include "../back-ldap/back-ldap.h" 64 #include "back-meta.h" 65 66 int 67 ldap_back_dn_massage( 68 dncookie *dc, 69 struct berval *dn, 70 struct berval *res ) 71 { 72 int rc = 0; 73 static char *dmy = ""; 74 75 switch ( rewrite_session( dc->target->mt_rwmap.rwm_rw, dc->ctx, 76 ( dn->bv_val ? dn->bv_val : dmy ), 77 dc->conn, &res->bv_val ) ) 78 { 79 case REWRITE_REGEXEC_OK: 80 if ( res->bv_val != NULL ) { 81 res->bv_len = strlen( res->bv_val ); 82 } else { 83 *res = *dn; 84 } 85 Debug( LDAP_DEBUG_ARGS, 86 "[rw] %s: \"%s\" -> \"%s\"\n", 87 dc->ctx, 88 BER_BVISNULL( dn ) ? "" : dn->bv_val, 89 BER_BVISNULL( res ) ? "" : res->bv_val ); 90 rc = LDAP_SUCCESS; 91 break; 92 93 case REWRITE_REGEXEC_UNWILLING: 94 if ( dc->rs ) { 95 dc->rs->sr_err = LDAP_UNWILLING_TO_PERFORM; 96 dc->rs->sr_text = "Operation not allowed"; 97 } 98 rc = LDAP_UNWILLING_TO_PERFORM; 99 break; 100 101 case REWRITE_REGEXEC_ERR: 102 if ( dc->rs ) { 103 dc->rs->sr_err = LDAP_OTHER; 104 dc->rs->sr_text = "Rewrite error"; 105 } 106 rc = LDAP_OTHER; 107 break; 108 } 109 110 if ( res->bv_val == dmy ) { 111 BER_BVZERO( res ); 112 } 113 114 return rc; 115 } 116