]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/cyrus.c
Added check for Cyrus SASL sasl_version()
[openldap] / libraries / libldap / cyrus.c
index 06d275eeb4865c783742c5d8e8f24dc003eca865..db6b80805b0049f583aa09e2ad6f1b2579da619d 100644 (file)
@@ -56,6 +56,28 @@ int ldap_int_sasl_init( void )
                { SASL_CB_LIST_END, NULL, NULL }
        };
 
+#ifdef HAVE_SASL_VERSION
+#define SASL_BUILD_VERSION ((SASL_VERSION_MAJOR << 24) |\
+       (SASL_VERSION_MINOR << 16) | SASL_VERSION_STEP)
+
+       { int rc;
+       sasl_version( NULL, &rc );
+       if ( ((rc >> 16) != ((SASL_VERSION_MAJOR << 8)|SASL_VERSION_MINOR)) ||
+               (rc & 0xffff) < SASL_VERSION_STEP) {
+
+#ifdef NEW_LOGGING
+               LDAP_LOG( TRANSPORT, INFO,
+               "ldap_int_sasl_init: SASL version mismatch, got %x, wanted %x.\n",
+                       rc, SASL_BUILD_VERSION, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+               "ldap_int_sasl_init: SASL version mismatch, got %x, wanted %x.\n",
+                       rc, SASL_BUILD_VERSION, 0 );
+#endif
+               return -1;
+       }
+       }
+#endif
        if ( sasl_initialized ) {
                return 0;
        }
@@ -161,12 +183,16 @@ sb_sasl_pkt_length( const unsigned char *buf, unsigned max, int debuglevel )
                | buf[2] << 8
                | buf[3];
    
-       if ( size > max ) {
+       if ( size > SASL_MAX_BUFF_SIZE ) {
                /* somebody is trying to mess me up. */
                ber_log_printf( LDAP_DEBUG_ANY, debuglevel,
                        "sb_sasl_pkt_length: received illegal packet length "
                        "of %lu bytes\n", (unsigned long)size );      
                size = 16; /* this should lead to an error. */
+       } else if ( size > max ) {
+               ber_log_printf( LDAP_DEBUG_ANY, debuglevel,
+                       "sb_sasl_pkt_length: received packet length "
+                       "of %lu exceeds negotiated max of %lu bytes\n", (unsigned long)size, (unsigned long)max );
        }
 
        return size + 4; /* include the size !!! */
@@ -357,7 +383,7 @@ Sockbuf_IO ldap_pvt_sockbuf_io_sasl = {
 int ldap_pvt_sasl_install( Sockbuf *sb, void *ctx_arg )
 {
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "cyrus", LDAP_LEVEL_ENTRY, "ldap_pvt_sasl_install\n" ));
+       LDAP_LOG ( TRANSPORT, ENTRY, "ldap_pvt_sasl_install\n", 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "ldap_pvt_sasl_install\n",
                0, 0, 0 );
@@ -453,8 +479,8 @@ ldap_int_sasl_open(
        }
 
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "cyrus", LDAP_LEVEL_DETAIL1
-               "ldap_int_sasl_open: host=%s\n", host ));
+       LDAP_LOG ( TRANSPORT, DETAIL1, "ldap_int_sasl_open: host=%s\n"
+               host, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "ldap_int_sasl_open: host=%s\n",
                host, 0, 0 );
@@ -475,8 +501,8 @@ ldap_int_sasl_open(
                        (void *) &extprops );
 #endif
 #ifdef NEW_LOGGING
-               LDAP_LOG (( "cyrus", LDAP_LEVEL_DETAIL1, 
-                       "ldap_int_sasl_open: ssf=%ld\n", (long) ssf ));
+               LDAP_LOG ( TRANSPORT, DETAIL1, 
+                       "ldap_int_sasl_open: ssf=%ld\n", (long) ssf, 0, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE, "ldap_int_sasl_open: ssf=%ld\n",
                        (long) ssf, 0, 0 );
@@ -521,8 +547,8 @@ ldap_int_sasl_bind(
        ber_socket_t            sd;
 
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "cyrus", LDAP_LEVEL_ARGS
-                       "ldap_int_sasl_bind: %s\n", mechs ? mechs : "<null>" ));
+       LDAP_LOG ( TRANSPORT, ARGS, "ldap_int_sasl_bind: %s\n"
+               mechs ? mechs : "<null>", 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "ldap_int_sasl_bind: %s\n",
                mechs ? mechs : "<null>", 0, 0 );
@@ -633,9 +659,9 @@ ldap_int_sasl_bind(
                        if( scred && scred->bv_len ) {
                                /* and server provided us with data? */
 #ifdef NEW_LOGGING
-                               LDAP_LOG (( "cyrus", LDAP_LEVEL_DETAIL1, 
+                               LDAP_LOG ( TRANSPORT, DETAIL1, 
                                        "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n", 
-                                       rc, saslrc, scred->bv_len ));
+                                       rc, saslrc, scred->bv_len );
 #else
                                Debug( LDAP_DEBUG_TRACE,
                                        "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n",
@@ -651,9 +677,9 @@ ldap_int_sasl_bind(
                        if( scred && scred->bv_len ) {
                                /* but server provided us with data! */
 #ifdef NEW_LOGGING
-                               LDAP_LOG (( "cyrus", LDAP_LEVEL_DETAIL1, 
+                               LDAP_LOG ( TRANSPORT, DETAIL1, 
                                        "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n", 
-                                       rc, saslrc, scred->bv_len ));
+                                       rc, saslrc, scred->bv_len );
 #else
                                Debug( LDAP_DEBUG_TRACE,
                                        "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n",
@@ -674,8 +700,8 @@ ldap_int_sasl_bind(
                                &credlen );
 
 #ifdef NEW_LOGGING
-                               LDAP_LOG (( "cyrus", LDAP_LEVEL_DETAIL1, 
-                                       "ldap_int_sasl_bind: sasl_client_step: %d\n", saslrc ));
+                               LDAP_LOG ( TRANSPORT, DETAIL1, 
+                                       "ldap_int_sasl_bind: sasl_client_step: %d\n", saslrc,0,0 );
 #else
                        Debug( LDAP_DEBUG_TRACE, "sasl_client_step: %d\n",
                                saslrc, 0, 0 );