#include "portable.h"
-#include <ac/stdlib.h>
#include <stdio.h>
+#include <ac/stdlib.h>
+#include <ac/string.h>
#include <lber.h>
#include <ldap_log.h>
/* Blatantly anonymous ID */
- len = sizeof( "anonymous" ) - 1;
- if( id && ( id[len] == '\0' || id[len] == '@' ) &&
- !strncasecmp( id, "anonymous", len) ) {
+ if( id &&
+ ( id[sizeof( "anonymous" )-1] == '\0'
+ || id[sizeof( "anonymous" )-1] == '@' ) &&
+ !strncasecmp( id, "anonymous", sizeof( "anonymous" )-1) ) {
*dnptr = NULL;
return( LDAP_SUCCESS );
}
dn[0] = 'd';
dn[1] = 'n';
dn[2] = ':';
- memmove( &dn[3], tmpdn, len+1 );
+ AC_MEMCPY( &dn[3], tmpdn, len+1 );
len += 3;
} else {
dn = ch_malloc( len+3 );
dn[0] = 'u';
dn[1] = ':';
- memmove( &dn[2], id, len+1 );
+ AC_MEMCPY( &dn[2], id, len+1 );
len += 2;
}
} else {
/* An authzID must be properly prefixed */
if( flags & FLAG_GETDN_AUTHZID
- && strncasecmp( dn, "u:", 2 )
- && strncasecmp( dn, "dn:", 3 ) )
+ && strncasecmp( dn, "u:", sizeof("u:")-1 )
+ && strncasecmp( dn, "dn:", sizeof("dn:")-1 ) )
{
ch_free( dn );
*dnptr = NULL;
}
/* Username strings */
- if( !strncasecmp( dn, "u:", 2 ) ) {
- int len1 = strlen( ",cn=auth" );
- len += strlen( "dn:uid=" ) + len1;
+ if( !strncasecmp( dn, "u:", sizeof("u:")-1 ) ) {
+ len += (sizeof("dn:uid=")-1) + (sizeof(",cn=auth")-1);
/* Figure out how much data we have for the dn */
rc = sasl_getprop( ctx, SASL_REALM, (void **)&c );
}
if( c && *c ) {
- len += strlen( c ) + strlen(",cn=" );
+ len += strlen( c ) + (sizeof(",cn=")-1);
}
if( conn->c_sasl_bind_mech ) {
- len += strlen( conn->c_sasl_bind_mech ) + strlen( ",cn=" );
+ len += strlen( conn->c_sasl_bind_mech ) + (sizeof(",cn=")-1);
}
/* Build the new dn */
len += sprintf( dn+len, ",cn=%s", conn->c_sasl_bind_mech );
}
strcpy( dn+len, ",cn=auth" );
- len += len1;
+ len += (sizeof(",cn=auth")-1);
#ifdef NEW_LOGGING
LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
}
/* DN strings that are a cn=auth identity to run through regexp */
- if( !strncasecmp( dn, "dn:", 3) &&
+ if( !strncasecmp( dn, "dn:", sizeof("dn:")-1) &&
( ( flags & FLAG_GETDN_FINAL ) == 0 ) )
{
- c1 = slap_sasl2dn( dn + 3 );
+ c1 = slap_sasl2dn( dn + (sizeof("dn:")-1) );
if( c1 ) {
ch_free( dn );
dn = c1;
/* Reaffix the dn: prefix if it was removed */
- if( strncasecmp( dn, "dn:", 3) ) {
+ if( strncasecmp( dn, "dn:", sizeof("dn:")-1) ) {
c1 = dn;
- dn = ch_malloc( strlen( c1 ) + 4 );
+ dn = ch_malloc( strlen( c1 ) + sizeof("dn:") );
sprintf( dn, "dn:%s", c1 );
ch_free( c1 );
}
}
if( ( flags & FLAG_GETDN_FINAL ) == 0 ) {
- dn_normalize( dn+3 );
+ dn_normalize( dn+(sizeof("dn:")-1) );
}
*dnptr = dn;
if( sc != SASL_OK ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "sasl", LDAP_LEVEL_ERR,
- "slap_sasl_mechs: sasl_listmech failed: %d\n", sc ));
+ "slap_sasl_mechs: sasl_listmech failed: %d\n", sc ));
#else
Debug( LDAP_DEBUG_ANY, "slap_sasl_listmech failed: %d\n",
sc, 0, 0 );
#include "portable.h"
-#include <ac/stdlib.h>
#include <stdio.h>
+#include <ac/stdlib.h>
#include <ac/string.h>
#include "slap.h"
#include <ldap_pvt.h>
#endif
-/* URI format: ldap://<host>/<base>[?[<attrs>][?[<scope>][?[<filter>]]]] */
+/* URI format: ldap://<host>/<base>[?[<attrs>][?[<scope>][?[<filter>]]]] */
-int slap_parseURI( char *uri, struct berval *searchbase, int *scope, Filter **filter )
+static int slap_parseURI( char *uri,
+ struct berval *searchbase, int *scope, Filter **filter )
{
char *start, *end;
struct berval bv;
#ifdef NEW_LOGGING
LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
- "slap_parseURI: parsing %s\n", uri ));
+ "slap_parseURI: parsing %s\n", uri ));
#else
Debug( LDAP_DEBUG_TRACE, "slap_parseURI: parsing %s\n", uri, 0, 0 );
#endif
-
/* If it does not look like a URI, assume it is a DN */
- if( !strncasecmp( uri, "dn:", 3 ) ) {
- uri += 3;
+ if( !strncasecmp( uri, "dn:", sizeof("dn:")-1 ) ) {
+ uri += sizeof("dn:")-1;
uri += strspn( uri, " " );
bv.bv_val = uri;
/* FIXME: if dnNormalize actually uses input bv_len we
}
return( rc );
}
- if( strncasecmp( uri, "ldap://", 7 ) ) {
+
+ /* FIXME: should use ldap_url_parse() */
+ if( strncasecmp( uri, "ldap://", sizeof("ldap://")-1 ) ) {
bv.bv_val = uri;
goto is_dn;
}
- end = strchr( uri + 7, '/' );
+ end = strchr( uri + (sizeof("ldap://")-1), '/' );
if ( end == NULL )
return( LDAP_PROTOCOL_ERROR );
/* Grab the scope */
start = end+1;
- if( !strncasecmp( start, "base?", 5 )) {
+ if( !strncasecmp( start, "base?", sizeof("base?")-1 )) {
*scope = LDAP_SCOPE_BASE;
- start += 5;
+ start += sizeof("base?")-1;
}
- else if( !strncasecmp( start, "one?", 4 )) {
+ else if( !strncasecmp( start, "one?", sizeof("one?")-1 )) {
*scope = LDAP_SCOPE_ONELEVEL;
- start += 4;
+ start += sizeof("one?")-1;
}
- else if( !strncasecmp( start, "sub?", 3 )) {
+ else if( !strncasecmp( start, "sub?", sizeof("sub?")-1 )) {
*scope = LDAP_SCOPE_SUBTREE;
- start += 4;
+ start += sizeof("sub?")-1;
}
else {
free( searchbase->bv_val );
}
-
-
-
int slap_sasl_regexp_config( const char *match, const char *replace )
{
#ifdef HAVE_CYRUS_SASL
}
-
-
-
#ifdef HAVE_CYRUS_SASL
-
-
/* Take the passed in SASL name and attempt to convert it into an
LDAP URI to find the matching LDAP entry, using the pattern matching
strings given in the saslregexp config file directive(s) */
int i, n, len, insert;
SaslRegexp_t *reg;
-
#ifdef NEW_LOGGING
LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
- "slap_sasl_regexp: converting SASL name %s\n", saslname ));
+ "slap_sasl_regexp: converting SASL name %s\n", saslname ));
#else
Debug( LDAP_DEBUG_TRACE, "slap_sasl_regexp: converting SASL name %s\n",
saslname, 0, 0 );
uri[insert] = '\0';
#ifdef NEW_LOGGING
LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
- "slap_sasl_regexp: converted SASL name to %s\n", uri ));
+ "slap_sasl_regexp: converted SASL name to %s\n", uri ));
#else
Debug( LDAP_DEBUG_TRACE,
"slap_sasl_regexp: converted SASL name to %s\n", uri, 0, 0 );
}
-
-
-
/*
* This function answers the question, "Can this ID authorize to that ID?",
* based on authorization rules. The rules are stored in the *searchDN, in the
*
* DN's passed in should have a dn: prefix
*/
-
static int
slap_sasl_check_authz(char *searchDN, char *assertDN, char *attr, char *authc)
{
AttributeDescription *ad=NULL;
struct berval bv;
-
#ifdef NEW_LOGGING
LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
"slap_sasl_check_authz: does %s match %s rule in %s?\n",
return( rc );
}
-
-
-
#endif /* HAVE_CYRUS_SASL */
-
-
-
/* Check if a bind can SASL authorize to another identity.
Accepts authorization DN's with "dn:" prefix */
#ifdef NEW_LOGGING
LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
- "slap_sasl_authorized: can %s become %s?\n", authcDN, authzDN ));
+ "slap_sasl_authorized: can %s become %s?\n", authcDN, authzDN ));
#else
Debug( LDAP_DEBUG_TRACE,
"==>slap_sasl_authorized: can %s become %s?\n", authcDN, authzDN, 0 );
#endif
-
/* If person is authorizing to self, succeed */
if ( !strcmp( authcDN, authzDN ) ) {
rc = LDAP_SUCCESS;
#ifdef NEW_LOGGING
LDAP_LOG(( "sasl", LDAP_LEVEL_ENTRY,
- "slap_sasl_authorized: return %d\n", rc ));
+ "slap_sasl_authorized: return %d\n", rc ));
#else
- Debug( LDAP_DEBUG_TRACE, "<== slap_sasl_authorized: return %d\n",rc,0,0 );
+ Debug( LDAP_DEBUG_TRACE,
+ "<== slap_sasl_authorized: return %d\n", rc, 0, 0 );
#endif
return( rc );