]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/getdn.c
Sync with HEAD
[openldap] / libraries / libldap / getdn.c
index 6b90e7999341b9f085573c528e1f47802e159047..e66f6175be5689413aea883efc141c6afe1d83ff 100644 (file)
@@ -1,13 +1,19 @@
 /* $OpenLDAP$ */
-/*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
- */
-/*  Portions
- *  Copyright (c) 1994 Regents of the University of Michigan.
- *  All rights reserved.
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2003 The OpenLDAP Foundation.
+ * All rights reserved.
  *
- *  getdn.c
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* Portions Copyright (c) 1994 Regents of the University of Michigan.
+ * All rights reserved.
  */
 
 #include "portable.h"
@@ -29,7 +35,7 @@
 
 /* parsing/printing routines */
 static int str2strval( const char *str, ber_len_t stoplen, struct berval *val, 
-               const char **next, unsigned flags, unsigned *retFlags, void *ctx );
+               const char **next, unsigned flags, int *retFlags, void *ctx );
 static int DCE2strval( const char *str, struct berval *val, 
                const char **next, unsigned flags, void *ctx );
 static int IA52strval( const char *str, struct berval *val, 
@@ -257,7 +263,7 @@ ldap_explode_rdn( LDAP_CONST char *rdn, int notypes )
                char            *str;
                LDAPAVA         *ava = tmpRDN[ iAVA ];
                
-               if ( ava->la_flags == LDAP_AVA_BINARY ) {
+               if ( ava->la_flags & LDAP_AVA_BINARY ) {
                        vl = 1 + 2 * ava->la_value.bv_len;
 
                } else {
@@ -281,7 +287,7 @@ ldap_explode_rdn( LDAP_CONST char *rdn, int notypes )
                        str = LDAP_MALLOC( l + 1 );
                }
                
-               if ( ava->la_flags == LDAP_AVA_BINARY ) {
+               if ( ava->la_flags & LDAP_AVA_BINARY ) {
                        str[ al++ ] = '#';
                        if ( binval2hexstr( &ava->la_value, &str[ al ] ) ) {
                                goto error_return;
@@ -543,7 +549,7 @@ ldap_dn_normalize( LDAP_CONST char *dnin,
 #define        LDAP_DC_ATTRU   "DC"
 #define LDAP_DN_IS_RDN_DC( r ) \
        ( (r) && (r)[0] && !(r)[1] \
-         && ((r)[0]->la_flags == LDAP_AVA_STRING) \
+         && ((r)[0]->la_flags & LDAP_AVA_STRING) \
          && ((r)[0]->la_attr.bv_len == 2) \
          && (((r)[0]->la_attr.bv_val[0] == LDAP_DC_ATTR[0]) \
                || ((r)[0]->la_attr.bv_val[0] == LDAP_DC_ATTRU[0])) \
@@ -1439,7 +1445,7 @@ return_result:;
  * '\' + HEXPAIR(p) -> unhex(p)
  */
 static int
-str2strval( const char *str, ber_len_t stoplen, struct berval *val, const char **next, unsigned flags, unsigned *retFlags, void *ctx )
+str2strval( const char *str, ber_len_t stoplen, struct berval *val, const char **next, unsigned flags, int *retFlags, void *ctx )
 {
        const char      *p, *end, *startPos, *endPos = NULL;
        ber_len_t       len, escapes;
@@ -1541,7 +1547,7 @@ str2strval( const char *str, ber_len_t stoplen, struct berval *val, const char *
        val->bv_len = len;
 
        if ( escapes == 0 ) {
-               if ( *retFlags == LDAP_AVA_NONPRINTABLE ) {
+               if ( *retFlags & LDAP_AVA_NONPRINTABLE ) {
                        val->bv_val = LDAP_MALLOCX( len + 1, ctx );
                        AC_MEMCPY( val->bv_val, startPos, len );
                        val->bv_val[ len ] = '\0';
@@ -2614,13 +2620,10 @@ rdn2DCEstrlen( LDAPRDN rdn, unsigned flags, ber_len_t *len )
                /* len(type) + '=' + ',' | '/' */
                l += ava->la_attr.bv_len + 2;
 
-               switch ( ava->la_flags ) {
-               case LDAP_AVA_BINARY:
+               if ( ava->la_flags & LDAP_AVA_BINARY ) {
                        /* octothorpe + twice the length */
                        l += 1 + 2 * ava->la_value.bv_len;
-                       break;
-
-               case LDAP_AVA_STRING: {
+               } else {
                        ber_len_t       vl;
                        unsigned        f = flags | ava->la_flags;
                        
@@ -2628,11 +2631,6 @@ rdn2DCEstrlen( LDAPRDN rdn, unsigned flags, ber_len_t *len )
                                return( -1 );
                        }
                        l += vl;
-                       break;
-               }
-
-               default:
-                       return( -1 );
                }
        }
        
@@ -2662,16 +2660,13 @@ rdn2DCEstr( LDAPRDN rdn, char *str, unsigned flags, ber_len_t *len, int first )
 
                str[ l++ ] = '=';
 
-               switch ( ava->la_flags ) {
-                       case LDAP_AVA_BINARY:
+               if ( ava->la_flags & LDAP_AVA_BINARY ) {
                        str[ l++ ] = '#';
                        if ( binval2hexstr( &ava->la_value, &str[ l ] ) ) {
                                return( -1 );
                        }
                        l += 2 * ava->la_value.bv_len;
-                       break;
-
-               case LDAP_AVA_STRING: {
+               } else {
                        ber_len_t       vl;
                        unsigned        f = flags | ava->la_flags;
 
@@ -2679,11 +2674,6 @@ rdn2DCEstr( LDAPRDN rdn, char *str, unsigned flags, ber_len_t *len, int first )
                                return( -1 );
                        }
                        l += vl;
-                       break;
-               }
-                                     
-               default:
-                       return( -1 );
                }
        }
 
@@ -2789,13 +2779,10 @@ rdn2ADstrlen( LDAPRDN rdn, unsigned flags, ber_len_t *len )
                l++;
 
                /* FIXME: are binary values allowed in UFN? */
-               switch ( ava->la_flags ) {
-               case LDAP_AVA_BINARY:
+               if ( ava->la_flags & LDAP_AVA_BINARY ) {
                        /* octothorpe + twice the value */
                        l += 1 + 2 * ava->la_value.bv_len;
-                       break;
-
-               case LDAP_AVA_STRING: {
+               } else {
                        ber_len_t       vl;
                        unsigned        f = flags | ava->la_flags;
 
@@ -2803,11 +2790,6 @@ rdn2ADstrlen( LDAPRDN rdn, unsigned flags, ber_len_t *len )
                                return( -1 );
                        }
                        l += vl;
-                       break;
-               }
-
-               default:
-                       return( -1 );
                }
        }
        
@@ -2831,16 +2813,13 @@ rdn2ADstr( LDAPRDN rdn, char *str, unsigned flags, ber_len_t *len, int first )
                        str[ l++ ] = ( iAVA ? ',' : '/' );
                }
 
-               switch ( ava->la_flags ) {
-               case LDAP_AVA_BINARY:
+               if ( ava->la_flags & LDAP_AVA_BINARY ) {
                        str[ l++ ] = '#';
                        if ( binval2hexstr( &ava->la_value, &str[ l ] ) ) {
                                return( -1 );
                        }
                        l += 2 * ava->la_value.bv_len;
-                       break;
-                       
-               case LDAP_AVA_STRING: {
+               } else {
                        ber_len_t       vl;
                        unsigned        f = flags | ava->la_flags;
                        
@@ -2848,11 +2827,6 @@ rdn2ADstr( LDAPRDN rdn, char *str, unsigned flags, ber_len_t *len, int first )
                                return( -1 );
                        }
                        l += vl;
-                       break;
-               }
-
-               default:
-                       return( -1 );
                }
        }
 
@@ -3283,7 +3257,7 @@ int ldap_dn2bv_x( LDAPDN dn, struct berval *bv, unsigned flags, void *ctx )
                }
 
                iRDN--;
-               if ( iRDN && dn2domain( dn, bv, 0, &iRDN ) ) {
+               if ( iRDN && dn2domain( dn, bv, 0, &iRDN ) != 0 ) {
                        for ( l = bv->bv_len; iRDN >= 0 ; iRDN-- ) {
                                ber_len_t       rdnl;
                        
@@ -3491,7 +3465,7 @@ get_oid:          newAVA->la_attr.bv_val = oidptr;
                                }
                        }
                }
-               Val.bv_val = str->data;
+               Val.bv_val = (char *) str->data;
                Val.bv_len = str->length;
                switch( str->type ) {
                case V_ASN1_UNIVERSALSTRING: