Back to index

openldap  2.4.31
Functions
suffixmassage.c File Reference
#include "portable.h"
#include <stdio.h>
#include <ac/string.h>
#include <ac/socket.h>
#include "slap.h"
#include "../back-ldap/back-ldap.h"
#include "back-meta.h"

Go to the source code of this file.

Functions

int ldap_back_dn_massage (dncookie *dc, struct berval *odn, struct berval *res)

Function Documentation

int ldap_back_dn_massage ( dncookie dc,
struct berval odn,
struct berval res 
)

Definition at line 120 of file suffixmassage.c.

{
       int     i, src, dst;
       struct berval pretty = {0,NULL}, *dn = odn;

       assert( res != NULL );

       if ( dn == NULL ) {
              res->bv_val = NULL;
              res->bv_len = 0;
              return 0;
       }
       if ( dc->target->mt_rwmap.rwm_suffix_massage == NULL ) {
              *res = *dn;
              return 0;
       }

       if ( dc->tofrom ) {
              src = 0 + dc->normalized;
              dst = 2 + dc->normalized;
       } else {
              src = 2 + dc->normalized;
              dst = 0 + dc->normalized;
              /* DN from remote server may be in arbitrary form.
               * Pretty it so we can parse reliably.
               */
              dnPretty( NULL, dn, &pretty, NULL );
              if (pretty.bv_val) dn = &pretty;
       }

       for ( i = 0;
              dc->target->mt_rwmap.rwm_suffix_massage[i].bv_val != NULL;
              i += 4 ) {
              int aliasLength = dc->target->mt_rwmap.rwm_suffix_massage[i+src].bv_len;
              int diff = dn->bv_len - aliasLength;

              if ( diff < 0 ) {
                     /* alias is longer than dn */
                     continue;
              } else if ( diff > 0 && ( !DN_SEPARATOR(dn->bv_val[diff-1]))) {
                     /* boundary is not at a DN separator */
                     continue;
                     /* At a DN Separator */
              }

              if ( !strcmp( dc->target->mt_rwmap.rwm_suffix_massage[i+src].bv_val, &dn->bv_val[diff] ) ) {
                     res->bv_len = diff + dc->target->mt_rwmap.rwm_suffix_massage[i+dst].bv_len;
                     res->bv_val = ch_malloc( res->bv_len + 1 );
                     strncpy( res->bv_val, dn->bv_val, diff );
                     strcpy( &res->bv_val[diff], dc->target->mt_rwmap.rwm_suffix_massage[i+dst].bv_val );
                     Debug( LDAP_DEBUG_ARGS,
                            "ldap_back_dn_massage:"
                            " converted \"%s\" to \"%s\"\n",
                            BER_BVISNULL( dn ) ? "" : dn->bv_val,
                            BER_BVISNULL( res ) ? "" : res->bv_val, 0 );
                     break;
              }
       }
       if (pretty.bv_val) {
              ch_free(pretty.bv_val);
              dn = odn;
       }
       /* Nothing matched, just return the original DN */
       if (res->bv_val == NULL) {
              *res = *dn;
       }

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function: