fi
+echo "$as_me:$LINENO: checking for memrchr" >&5
+echo $ECHO_N "checking for memrchr... $ECHO_C" >&6
+if test "${ac_cv_func_memrchr+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+/* Define memrchr to an innocuous variant, in case <limits.h> declares memrchr.
+ For example, HP-UX 11i <limits.h> declares gettimeofday. */
+#define memrchr innocuous_memrchr
+
+/* System header to define __stub macros and hopefully few prototypes,
+ which can conflict with char memrchr (); below.
+ Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+ <limits.h> exists even on freestanding compilers. */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef memrchr
+
+/* Override any gcc2 internal prototype to avoid an error. */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char memrchr ();
+/* The GNU C library defines this for functions which it implements
+ to always fail with ENOSYS. Some functions are actually named
+ something starting with __ and the normal name is an alias. */
+#if defined (__stub_memrchr) || defined (__stub___memrchr)
+choke me
+#else
+char (*f) () = memrchr;
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+int
+main ()
+{
+return f != memrchr;
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_func_memrchr=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_func_memrchr=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_func_memrchr" >&5
+echo "${ECHO_T}$ac_cv_func_memrchr" >&6
+if test $ac_cv_func_memrchr = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_MEMRCHR 1
+_ACEOF
+
+fi
+
+
for ac_func in strftime
do
[define if memcmp is not 8-bit clean or is otherwise broken])
fi
+AC_CHECK_FUNC(memrchr, AC_DEFINE(HAVE_MEMRCHR,1,[if you have memrchr()]))
+
AC_FUNC_STRFTIME
OL_FUNC_INET_ATON
#define memcmp lutil_memcmp
#endif
+#ifndef HAVE_MEMRCHR
+ /* Actually, I think this is a GNU extension only */
+ void * lutil_memrchr(const void *b, int c, size_t len);
+#undef memrchr
+#define memrchr lutil_memrchr
+#endif /* ! HAVE_MEMRCHR */
+
#define STRLENOF(s) (sizeof(s)-1)
#if defined( HAVE_NONPOSIX_STRERROR_R )
#define ber_bvchr(bv,c) \
memchr( (bv)->bv_val, (c), (bv)->bv_len )
+#define ber_bvrchr(bv,c) \
+ memrchr( (bv)->bv_val, (c), (bv)->bv_len )
+
+#define ber_bvchr_right(dst,bv,c) \
+ do { \
+ (dst)->bv_val = memchr( (bv)->bv_val, (c), (bv)->bv_len ); \
+ (dst)->bv_len = (dst)->bv_val ? (bv)->bv_len - ((dst)->bv_val - (bv)->bv_val) : 0; \
+ } while (0)
+
+#define ber_bvchr_left(dst,bv,c) \
+ do { \
+ (dst)->bv_val = memchr( (bv)->bv_val, (c), (bv)->bv_len ); \
+ (dst)->bv_len = (dst)->bv_val ? ((dst)->bv_val - (bv)->bv_val) : (bv)->bv_len; \
+ (dst)->bv_val = (bv)->bv_val; \
+ } while (0)
+
+#define ber_bvrchr_right(dst,bv,c) \
+ do { \
+ (dst)->bv_val = memrchr( (bv)->bv_val, (c), (bv)->bv_len ); \
+ (dst)->bv_len = (dst)->bv_val ? (bv)->bv_len - ((dst)->bv_val - (bv)->bv_val) : 0; \
+ } while (0)
+
+#define ber_bvrchr_left(dst,bv,c) \
+ do { \
+ (dst)->bv_val = memrchr( (bv)->bv_val, (c), (bv)->bv_len ); \
+ (dst)->bv_len = (dst)->bv_val ? ((dst)->bv_val - (bv)->bv_val) : (bv)->bv_len; \
+ (dst)->bv_val = (bv)->bv_val; \
+ } while (0)
+
#define BER_BVC(s) { STRLENOF(s), (s) }
#define BER_BVNULL { 0L, NULL }
#define BER_BVZERO(bv) \
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
+/* if you have memrchr() */
+#undef HAVE_MEMRCHR
+
/* Define to 1 if you have the `mkstemp' function. */
#undef HAVE_MKSTEMP
#endif
}
#endif
+
+/*
+ * Memory Reverse Search
+ */
+void *
+lutil_memrchr(const void *b, int c, size_t n)
+{
+ if (n != 0) {
+ const unsigned char *s;
+
+ for ( s = b + n; s-- > b; ) {
+ if ( *s == c ) {
+ return s;
+ }
+ }
+ }
+
+ return NULL;
+}
+
struct berval ocbv = BER_BVNULL,
atbv = BER_BVNULL;
- ocbv.bv_val = strchr( type.bv_val, '/' );
- if ( ocbv.bv_val != NULL
- && ( ocbv.bv_val - type.bv_val ) < type.bv_len )
- {
+ ocbv.bv_val = ber_bvchr( &type, '/' );
+ if ( ocbv.bv_val != NULL ) {
ocbv.bv_val++;
+ ocbv.bv_len = type.bv_len
+ - ( ocbv.bv_val - type.bv_val );
- atbv.bv_val = strchr( ocbv.bv_val, '/' );
- if ( atbv.bv_val != NULL
- && ( atbv.bv_val - ocbv.bv_val ) < ocbv.bv_len )
- {
+ atbv.bv_val = ber_bvchr( &ocbv, '/' );
+ if ( atbv.bv_val != NULL ) {
AttributeDescription *ad = NULL;
const char *text = NULL;
int rc;
if ( rc != LDAP_SUCCESS ) {
return LDAP_INVALID_SYNTAX;
}
-
- } else {
- ocbv.bv_len = type.bv_len
- - ( ocbv.bv_val - type.bv_val );
}
if ( oc_bvfind( &ocbv ) == NULL ) {
struct berval ocbv = BER_BVNULL,
atbv = BER_BVNULL;
- ocbv.bv_val = strchr( type.bv_val, '/' );
- if ( ocbv.bv_val != NULL
- && ( ocbv.bv_val - type.bv_val ) < type.bv_len )
- {
+ ocbv.bv_val = ber_bvchr( &type, '/' );
+ if ( ocbv.bv_val != NULL ) {
ObjectClass *oc = NULL;
AttributeDescription *ad = NULL;
const char *text = NULL;
ocbv.bv_val++;
ocbv.bv_len = type.bv_len - ( ocbv.bv_val - type.bv_val );
- atbv.bv_val = strchr( ocbv.bv_val, '/' );
- if ( atbv.bv_val != NULL
- && ( atbv.bv_val - ocbv.bv_val ) < ocbv.bv_len )
- {
+ atbv.bv_val = ber_bvchr( &ocbv, '/' );
+ if ( atbv.bv_val != NULL ) {
atbv.bv_val++;
atbv.bv_len = type.bv_len
- ( atbv.bv_val - type.bv_val );
}
bv.bv_len += STRLENOF( "/" ) + ad->ad_cname.bv_len;
-
- } else {
- ocbv.bv_len = type.bv_len
- - ( ocbv.bv_val - type.bv_val );
}
oc = oc_bvfind( &ocbv );
memset( &desc, 0, sizeof( desc ) );
desc.ad_cname = *bv;
name = bv->bv_val;
- options = strchr( name, ';' );
+ options = ber_bvchr( bv, ';' );
if ( options != NULL && (unsigned) ( options - name ) < bv->bv_len ) {
/* don't go past the end of the berval! */
desc.ad_cname.bv_len = options - name;
} else {
csn = op->o_csn;
}
- ptr = strchr( csn.bv_val, '#' );
+ ptr = ber_bvchr( &csn, '#' );
if ( ptr ) {
timestamp.bv_len = ptr - csn.bv_val;
if ( timestamp.bv_len >= sizeof(timebuf) )
#ifdef BDB_HIER
if ( nrdn->bv_len != e->e_nname.bv_len ) {
- char *ptr = strchr( rdn.bv_val, ',' );
+ char *ptr = ber_bvchr( &rdn, ',' );
+ assert( ptr != NULL );
rdn.bv_len = ptr - rdn.bv_val;
}
ber_dupbv( &ei.bei_rdn, &rdn );
rdn = e->e_name;
if ( nrdn->bv_len != e->e_nname.bv_len ) {
- char *ptr = strchr(rdn.bv_val, ',');
+ char *ptr = ber_bvchr(&rdn, ',');
+ assert( ptr != NULL );
rdn.bv_len = ptr - rdn.bv_val;
}
ber_dupbv( &ei->bei_rdn, &rdn );
ber_str2bv( pw->pw_gecos, 0, 0, &val );
attr_merge_normalize_one( e, ad_desc, &val, NULL );
- s = strchr( val.bv_val, ',' );
+ s = ber_bvchr( &val, ',' );
if ( s ) *s = '\0';
- s = strchr( val.bv_val, '&' );
+ s = ber_bvchr( &val, '&' );
if ( s ) {
char buf[1024];
/* quote all args but the first */
line = ldap_charray2str( c->argv, "\" \"" );
ber_str2bv( line, 0, 0, &bv );
- s = strchr( bv.bv_val, '"' );
+ s = ber_bvchr( &bv, '"' );
assert( s != NULL );
/* move the trailing quote of argv[0] to the end */
AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
/* See if the rdn has an index already */
dnRdn( &e->e_name, &rdn );
- ptr1 = strchr( e->e_name.bv_val, '{' );
+ ptr1 = ber_bvchr( &e->e_name, '{' );
if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
ptr2 = strchr( ptr1, '}' );
if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
{
char *p;
- p = strchr( dn->bv_val, ',' );
+ p = ber_bvchr( dn, ',' );
/* one-level dn */
if ( p == NULL ) {
char *p;
*rdn = *dn;
- p = strchr( dn->bv_val, ',' );
+ p = ber_bvchr( dn, ',' );
/* one-level dn */
if ( p == NULL ) {
return 0;
}
- p = strchr( dn_in->bv_val, ',' );
+ p = ber_bvchr( dn_in, ',' );
return p ? p - dn_in->bv_val : dn_in->bv_len;
}
{
return LDAP_INVALID_SYNTAX;
}
- return strchr( rdn->bv_val, ',' ) == NULL
+ return ber_bvchr( rdn, ',' ) == NULL
? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
#else
int valid = 0;
char *rid_ptr;
char *cval;
+ char *next;
if ( cookie == NULL )
return -1;
+ if ( cookie->octet_str.bv_len <= STRLENOF( "rid=" ) )
+ return -1;
+
cookie->rid = -1;
- if (( rid_ptr = strstr( cookie->octet_str.bv_val, "rid=" )) != NULL ) {
- if ( (cval = strchr( rid_ptr, ',' )) != NULL ) {
- *cval = '\0';
- }
- cookie->rid = atoi( rid_ptr + sizeof("rid=") - 1 );
- if ( cval != NULL ) {
- *cval = ',';
- }
- } else {
+ /* FIXME: may read past end of cookie->octet_str.bv_val */
+ rid_ptr = strstr( cookie->octet_str.bv_val, "rid=" );
+ if ( rid_ptr == NULL
+ || rid_ptr > &cookie->octet_str.bv_val[ cookie->octet_str.bv_len - STRLENOF( "rid=" ) ] )
+ {
+ return -1;
+
+ }
+
+ cookie->rid = strtoul( &rid_ptr[ STRLENOF( "rid=" ) ], &next, 10 );
+ if ( next == &rid_ptr[ STRLENOF( "rid=" ) ] || ( next[ 0 ] != ',' && next[ 0 ] != '\0' ) ) {
return -1;
}
if ( ad == NULL )
break;
+ if ( csn_ptr >= &cookie->octet_str.bv_val[ cookie->octet_str.bv_len - STRLENOF( "csn=" ) ] ) {
+ return -1;
+ }
+
csn_str = csn_ptr + STRLENOF("csn=");
cval = strchr( csn_str, ',' );
- if ( cval )
+ if ( cval && cval < &cookie->octet_str.bv_val[ cookie->octet_str.bv_len ] )
csn_str_len = cval - csn_str;
else
csn_str_len = 0;
/* FIXME use csnValidate when it gets implemented */
csn_ptr = strchr( csn_str, '#' );
- if ( !csn_ptr ) break;
+ if ( !csn_ptr || csn_str >= &cookie->octet_str.bv_val[ cookie->octet_str.bv_len ] ) break;
stamp.bv_val = csn_str;
stamp.bv_len = csn_ptr - csn_str;
} else {
csn = op->o_csn;
}
- ptr = strchr( csn.bv_val, '#' );
+ ptr = ber_bvchr( &csn, '#' );
if ( ptr && ptr < &csn.bv_val[csn.bv_len] ) {
timestamp.bv_len = ptr - csn.bv_val;
if ( timestamp.bv_len >= sizeof( timebuf ))
Operation nop = *op;
slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
struct berval dn = { 0, NULL };
- char *odn = op->o_req_ndn.bv_val;
Attribute *a;
Entry *e;
- int idn, ldn;
-
- /* tis more work to use strchr() for a berval... */
- for(idn = 0; odn[idn] && odn[idn] != ','; idn++);
- if(!idn || !odn[idn]) return; /* because you never know */
- idn++;
- ldn = dn.bv_len = op->o_req_ndn.bv_len - idn;
- dn.bv_val = ch_malloc(ldn + 1);
- strcpy(dn.bv_val, odn + idn);
+ struct berval pdn;
+
+ dnParent( &op->o_req_ndn, &pdn );
+ ber_dupbv( &dn, &pdn );
Debug(LDAP_DEBUG_TRACE, "=> glue_parent: fabricating glue for <%s>\n", dn.bv_val, 0, 0);
gotnvals = (a->a_vals != a->a_nvals );
for (i=0; i<n; i++) {
- char *ptr = strchr( a->a_nvals[i].bv_val, '{' );
+ char *ptr = ber_bvchr( &a->a_nvals[i], '{' );
char *end = NULL;
if ( !ptr ) {
Debug(LDAP_DEBUG_TRACE, "weights missing from attr %s "
if ( a->a_vals != a->a_nvals ) {
ptr = a->a_vals[i].bv_val;
- end = strchr( ptr, '}' ) + 1;
+ end = ber_bvchr( &a->a_vals[i], '}' ) + 1;
+ assert( end != NULL );
for (;*end;)
*ptr++ = *end++;
*ptr = '\0';
if ( !a )
continue;
for (i=0; !BER_BVISNULL( &a->a_vals[i] ); i++) {
- ptr = strchr(a->a_vals[i].bv_val, '{' );
+ ptr = ber_bvchr(&a->a_vals[i], '{' );
if ( !ptr ) {
Debug(LDAP_DEBUG_TRACE, "weight missing from attribute %s\n",
vi->vi_ad->ad_cname.bv_val, 0, 0);
if ( !ml )
continue;
for (i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++) {
- ptr = strchr(ml->sml_values[i].bv_val, '{' );
+ ptr = ber_bvchr(&ml->sml_values[i], '{' );
if ( !ptr ) {
Debug(LDAP_DEBUG_TRACE, "weight missing from attribute %s\n",
vi->vi_ad->ad_cname.bv_val, 0, 0);
* u[.mech[/realm]]:user
*/
- user->bv_val = strchr( id->bv_val, ':' );
+ user->bv_val = ber_bvchr( id, ':' );
if ( BER_BVISNULL( user ) ) {
return LDAP_PROTOCOL_ERROR;
}
user->bv_val++;
user->bv_len = id->bv_len - ( user->bv_val - id->bv_val );
- mech->bv_val = strchr( id->bv_val, '.' );
+ mech->bv_val = ber_bvchr( id, '.' );
if ( !BER_BVISNULL( mech ) ) {
mech->bv_val[ 0 ] = '\0';
mech->bv_val++;
+ mech->bv_len = user->bv_val - mech->bv_val - 1;
- realm->bv_val = strchr( mech->bv_val, '/' );
+ realm->bv_val = ber_bvchr( mech, '/' );
if ( !BER_BVISNULL( realm ) ) {
realm->bv_val[ 0 ] = '\0';
realm->bv_val++;
mech->bv_len = realm->bv_val - mech->bv_val - 1;
realm->bv_len = user->bv_val - realm->bv_val - 1;
- } else {
- mech->bv_len = user->bv_val - mech->bv_val - 1;
}
} else {
member_at = BER_BVNULL;
bv.bv_val = in->bv_val + STRLENOF( "group" );
- group_dn.bv_val = strchr( bv.bv_val, ':' );
+ bv.bv_len = in->bv_len - STRLENOF( "group" );
+ group_dn.bv_val = ber_bvchr( &bv, ':' );
if ( group_dn.bv_val == NULL ) {
/* last chance: assume it's a(n exact) DN ... */
bv.bv_val = in->bv_val;
*/
if ( bv.bv_val[ 0 ] == '/' ) {
group_oc.bv_val = &bv.bv_val[ 1 ];
+ group_oc.bv_len = group_dn.bv_val - group_oc.bv_val;
- member_at.bv_val = strchr( group_oc.bv_val, '/' );
+ member_at.bv_val = ber_bvchr( &group_oc, '/' );
if ( member_at.bv_val ) {
AttributeDescription *ad = NULL;
const char *text = NULL;
if ( rc != LDAP_SUCCESS ) {
return rc;
}
+ }
- } else {
- group_oc.bv_len = group_dn.bv_val - group_oc.bv_val;
-
- if ( oc_bvfind( &group_oc ) == NULL ) {
- return LDAP_INVALID_SYNTAX;
- }
+ if ( oc_bvfind( &group_oc ) == NULL ) {
+ return LDAP_INVALID_SYNTAX;
}
}
char *ptr;
bv.bv_val = val->bv_val + STRLENOF( "group" );
- group_dn.bv_val = strchr( bv.bv_val, ':' );
+ bv.bv_len = val->bv_len - STRLENOF( "group" );
+ group_dn.bv_val = ber_bvchr( &bv, ':' );
if ( group_dn.bv_val == NULL ) {
/* last chance: assume it's a(n exact) DN ... */
bv.bv_val = val->bv_val;
* are present in schema...
*/
if ( bv.bv_val[ 0 ] == '/' ) {
+ ObjectClass *oc = NULL;
+
group_oc.bv_val = &bv.bv_val[ 1 ];
+ group_oc.bv_len = group_dn.bv_val - group_oc.bv_val;
- member_at.bv_val = strchr( group_oc.bv_val, '/' );
+ member_at.bv_val = ber_bvchr( &group_oc, '/' );
if ( member_at.bv_val ) {
AttributeDescription *ad = NULL;
const char *text = NULL;
member_at = ad->ad_cname;
- } else {
- ObjectClass *oc = NULL;
-
- group_oc.bv_len = group_dn.bv_val - group_oc.bv_val;
-
- oc = oc_bvfind( &group_oc );
- if ( oc == NULL ) {
- return LDAP_INVALID_SYNTAX;
- }
+ }
- group_oc = oc->soc_cname;
+ oc = oc_bvfind( &group_oc );
+ if ( oc == NULL ) {
+ return LDAP_INVALID_SYNTAX;
}
+
+ group_oc = oc->soc_cname;
}
group_dn.bv_val++;
if ( idx.bv_val[ 0 ] == '{' ) {
char *ptr;
- ptr = strchr( idx.bv_val, '}' ) + 1;
+ ptr = ber_bvchr( &idx, '}' ) + 1;
assert( ptr != (void *)1 );
char *tmp;
bv.bv_val = uri->bv_val + STRLENOF( "group" );
- group_dn.bv_val = strchr( bv.bv_val, ':' );
+ bv.bv_len = uri->bv_len - STRLENOF( "group" );
+ group_dn.bv_val = ber_bvchr( &bv, ':' );
if ( group_dn.bv_val == NULL ) {
/* last chance: assume it's a(n exact) DN ... */
bv.bv_val = uri->bv_val;
if ( bv.bv_val[ 0 ] == '/' ) {
group_oc.bv_val = &bv.bv_val[ 1 ];
+ group_oc.bv_len = group_dn.bv_val - group_oc.bv_val;
- member_at.bv_val = strchr( group_oc.bv_val, '/' );
+ member_at.bv_val = ber_bvchr( &group_oc, '/' );
if ( member_at.bv_val ) {
group_oc.bv_len = member_at.bv_val - group_oc.bv_val;
member_at.bv_val++;
member_at.bv_len = group_dn.bv_val - member_at.bv_val;
} else {
- group_oc.bv_len = group_dn.bv_val - group_oc.bv_val;
BER_BVSTR( &member_at, SLAPD_GROUP_ATTR );
}
int rc;
AttributeDescription *desc = NULL;
struct berval rdn = frontendDB->be_schemadn;
- vals[0].bv_val = strchr( rdn.bv_val, '=' );
+ vals[0].bv_val = ber_bvchr( &rdn, '=' );
if( vals[0].bv_val == NULL ) {
*text = "improperly configured subschema subentry";
return LDAP_OTHER;
}
- nvals[0].bv_val = strchr( frontendDB->be_schemandn.bv_val, '=' );
+ nvals[0].bv_val = ber_bvchr( &frontendDB->be_schemandn, '=' );
assert( nvals[0].bv_val != NULL );
nvals[0].bv_val++;
nvals[0].bv_len = frontendDB->be_schemandn.bv_len -
struct berval sn, i;
if( in->bv_len < 3 ) return LDAP_INVALID_SYNTAX;
- i.bv_val = strchr( in->bv_val, '$' );
+ i.bv_val = ber_bvchr( in, '$' );
if( BER_BVISNULL( &i ) ) return LDAP_INVALID_SYNTAX;
sn.bv_val = in->bv_val;
if( val->bv_len < 3 ) return LDAP_INVALID_SYNTAX;
- i.bv_val = strchr( val->bv_val, '$' );
+ i.bv_val = ber_bvchr( val, '$' );
if( BER_BVISNULL( &i ) ) return LDAP_INVALID_SYNTAX;
sn.bv_val = val->bv_val;
if( val->bv_len < 3 ) return LDAP_INVALID_SYNTAX;
- i.bv_val = strchr( val->bv_val, '$' );
+ i.bv_val = ber_bvchr( val, '$' );
if( BER_BVISNULL( &i ) ) return LDAP_INVALID_SYNTAX;
sn.bv_val = val->bv_val;
ad = NULL;
bv = vals[i];
- colon = strchr( bv.bv_val, ':' );
+ colon = ber_bvchr( &bv, ':' );
if ( !colon )
continue; /* invalid */
bv.bv_len = colon - bv.bv_val;
int rc;
int suffrdns;
int i;
- struct berval dn = {0, NULL};
- struct berval ndn = {0, NULL};
+ struct berval dn = BER_BVNULL;
+ struct berval ndn = BER_BVNULL;
Entry *glue;
SlapReply rs_add = {REP_RESULT};
- char *ptr, *comma;
+ struct berval ptr, nptr;
+ char *comma;
op->o_tag = LDAP_REQ_ADD;
op->o_callback = &cb;
/* count RDNs in suffix */
if ( !BER_BVISEMPTY( &be->be_nsuffix[0] ) ) {
- for ( i = 0, ptr = be->be_nsuffix[0].bv_val; ptr; ptr = strchr( ptr, ',' ) ) {
- ptr++;
+ for ( i = 0, ptr = be->be_nsuffix[0], comma = ptr.bv_val; comma != NULL; comma = ber_bvchr( &ptr, ',' ) ) {
+ comma++;
+ ptr.bv_len -= comma - ptr.bv_val;
+ ptr.bv_val = comma;
i++;
}
suffrdns = i;
}
/* Start with BE suffix */
- for ( i = 0, ptr = NULL; i < suffrdns; i++ ) {
- comma = strrchr( dn.bv_val, ',' );
- if ( ptr ) *ptr = ',';
- if ( comma ) *comma = '\0';
- ptr = comma;
+ ptr = dn;
+ for ( i = 0; i < suffrdns; i++ ) {
+ comma = ber_bvrchr( &ptr, ',' );
+ if ( comma != NULL ) {
+ ptr.bv_len = comma - ptr.bv_val;
+ } else {
+ ptr.bv_len = 0;
+ break;
+ }
}
- if ( ptr ) {
- *ptr++ = ',';
- dn.bv_len -= ptr - dn.bv_val;
- dn.bv_val = ptr;
+
+ if ( !BER_BVISEMPTY( &ptr ) ) {
+ dn.bv_len -= ptr.bv_len + 1;
+ dn.bv_val += ptr.bv_len + 1;
}
+
/* the normalizedDNs are always the same length, no counting
* required.
*/
+ nptr = ndn;
if ( ndn.bv_len > be->be_nsuffix[0].bv_len ) {
ndn.bv_val += ndn.bv_len - be->be_nsuffix[0].bv_len;
ndn.bv_len = be->be_nsuffix[0].bv_len;
+
+ nptr.bv_len = ndn.bv_val - nptr.bv_val - 1;
+
+ } else {
+ nptr.bv_len = 0;
}
while ( ndn.bv_val > e->e_nname.bv_val ) {
}
/* Move to next child */
- for (ptr = dn.bv_val-2; ptr > e->e_name.bv_val && *ptr != ','; ptr--) {
- /* empty */
- }
- if ( ptr == e->e_name.bv_val ) break;
- dn.bv_val = ++ptr;
- dn.bv_len = e->e_name.bv_len - (ptr-e->e_name.bv_val);
- for( ptr = ndn.bv_val-2;
- ptr > e->e_nname.bv_val && *ptr != ',';
- ptr--)
- {
- /* empty */
+ comma = ber_bvrchr( &ptr, ',' );
+ if ( comma == NULL ) {
+ break;
}
- ndn.bv_val = ++ptr;
- ndn.bv_len = e->e_nname.bv_len - (ptr-e->e_nname.bv_val);
+ ptr.bv_len = comma - ptr.bv_val;
+
+ dn.bv_val = ++comma;
+ dn.bv_len = e->e_name.bv_len - (dn.bv_val - e->e_name.bv_val);
+
+ comma = ber_bvrchr( &nptr, ',' );
+ assert( comma != NULL );
+ nptr.bv_len = comma - nptr.bv_val;
+
+ ndn.bv_val = ++comma;
+ ndn.bv_len = e->e_nname.bv_len - (ndn.bv_val - e->e_nname.bv_val);
}
op->o_req_dn = e->e_name;
ibv.bv_len = sprintf(ibv.bv_val, "{%d}", i);
vtmp = a->a_vals[i];
if ( vtmp.bv_val[0] == '{' ) {
- ptr = strchr(vtmp.bv_val, '}') + 1;
+ ptr = ber_bvchr(&vtmp, '}') + 1;
+ assert( ptr != NULL );
vtmp.bv_len -= ptr - vtmp.bv_val;
vtmp.bv_val = ptr;
}
if ( a->a_nvals && a->a_nvals != a->a_vals ) {
vtmp = a->a_nvals[i];
if ( vtmp.bv_val[0] == '{' ) {
- ptr = strchr(vtmp.bv_val, '}') + 1;
+ ptr = ber_bvchr(&vtmp, '}') + 1;
+ assert( ptr != NULL );
vtmp.bv_len -= ptr - vtmp.bv_val;
vtmp.bv_val = ptr;
}
if ( a->a_vals[i].bv_val[0] == '{' ) {
char *ptr;
index = 1;
- ptr = strchr( a->a_vals[i].bv_val, '}' );
+ ptr = ber_bvchr( &a->a_vals[i], '}' );
if ( !ptr )
return LDAP_INVALID_SYNTAX;
if ( noindex )
a->a_nvals = ch_malloc( (vals+1)*sizeof(struct berval));
BER_BVZERO(a->a_nvals+vals);
for ( i=0; i<vals; i++ ) {
- ptr = strchr(a->a_vals[i].bv_val, '}') + 1;
+ ptr = ber_bvchr(&a->a_vals[i], '}') + 1;
a->a_nvals[i].bv_len = a->a_vals[i].bv_len -
(ptr - a->a_vals[i].bv_val);
a->a_nvals[i].bv_val = ch_malloc( a->a_nvals[i].bv_len + 1);
}
} else {
for ( i=0; i<vals; i++ ) {
- ptr = strchr(a->a_nvals[i].bv_val, '}') + 1;
+ ptr = ber_bvchr(&a->a_nvals[i], '}') + 1;
a->a_nvals[i].bv_len -= ptr - a->a_nvals[i].bv_val;
strcpy(a->a_nvals[i].bv_val, ptr);
}
if ( bv.bv_val[0] == '{' ) {
char *ptr;
- ptr = strchr( bv.bv_val, '}' );
- if ( ptr == NULL || ptr > &bv.bv_val[ bv.bv_len ] ) {
+ ptr = ber_bvchr( &bv, '}' );
+ if ( ptr == NULL ) {
return LDAP_INVALID_SYNTAX;
}
ptr++;
if ( bv.bv_val[0] == '{' ) {
char *ptr;
- ptr = strchr( bv.bv_val, '}' );
- if ( ptr == NULL || ptr > &bv.bv_val[ bv.bv_len ] ) {
+ ptr = ber_bvchr( &bv, '}' );
+ if ( ptr == NULL ) {
return LDAP_INVALID_SYNTAX;
}
ptr++;
if ( bv.bv_val[ 0 ] == '{' ) {
char *ptr;
- ptr = strchr( bv.bv_val, '}' );
- if ( ptr == NULL || ptr > &bv.bv_val[ bv.bv_len ] ) {
+ ptr = ber_bvchr( &bv, '}' );
+ if ( ptr == NULL ) {
return LDAP_INVALID_SYNTAX;
}
ptr++;
/* Skip past the assertion index */
if ( bv2.bv_val[0] == '{' ) {
- ptr = strchr( bv2.bv_val, '}' );
- if ( ptr == NULL || ptr > &bv2.bv_val[ bv2.bv_len ] ) {
+ ptr = ber_bvchr( &bv2, '}' );
+ if ( ptr == NULL ) {
return LDAP_INVALID_SYNTAX;
}
ptr++;
}
/* Skip past the attribute index */
if ( bv1.bv_val[0] == '{' ) {
- ptr = strchr( bv1.bv_val, '}' );
- if ( ptr == NULL || ptr > &bv1.bv_val[ bv1.bv_len ] ) {
+ ptr = ber_bvchr( &bv1, '}' );
+ if ( ptr == NULL ) {
return LDAP_INVALID_SYNTAX;
}
ptr++;