]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/cyrus.c
ITS#6684
[openldap] / libraries / libldap / cyrus.c
index aad8f8ed8843a34ff4e9cadbdc7430c0d8f660d9..9bd5938dc400d23c4fc716dbb44eeda648b40bcf 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2008 The OpenLDAP Foundation.
+ * Copyright 1998-2010 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -410,9 +410,7 @@ ldap_int_sasl_bind(
        }
 
        rc = 0;
-#ifdef LDAP_R_COMPILE
-       ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
-#endif
+       LDAP_MUTEX_LOCK( &ld->ld_req_mutex );
        ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, &sd );
 
        if ( sd == AC_SOCKET_INVALID ) {
@@ -430,9 +428,7 @@ ldap_int_sasl_bind(
                        }
                }
        }   
-#ifdef LDAP_R_COMPILE
-       ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
-#endif
+       LDAP_MUTEX_UNLOCK( &ld->ld_req_mutex );
        if( rc != 0 ) return ld->ld_errno;
 
        oldctx = ld->ld_defconn->lconn_sasl_authctx;
@@ -446,16 +442,28 @@ ldap_int_sasl_bind(
        }
 
        {
-               char *saslhost = ldap_host_connected_to( ld->ld_defconn->lconn_sb,
+               char *saslhost;
+               int nocanon = (int)LDAP_BOOL_GET( &ld->ld_options,
+                       LDAP_BOOL_SASL_NOCANON );
+
+               /* If we don't need to canonicalize just use the host
+                * from the LDAP URI.
+                */
+               if ( nocanon )
+                       saslhost = ld->ld_defconn->lconn_server->lud_host;
+               else 
+                       saslhost = ldap_host_connected_to( ld->ld_defconn->lconn_sb,
                        "localhost" );
                rc = ldap_int_sasl_open( ld, ld->ld_defconn, saslhost );
-               LDAP_FREE( saslhost );
+               if ( !nocanon )
+                       LDAP_FREE( saslhost );
        }
 
        if ( rc != LDAP_SUCCESS ) return rc;
 
        ctx = ld->ld_defconn->lconn_sasl_authctx;
 
+#ifdef HAVE_TLS
        /* Check for TLS */
        ssl = ldap_pvt_tls_sb_ctx( ld->ld_defconn->lconn_sb );
        if ( ssl ) {
@@ -469,6 +477,7 @@ ldap_int_sasl_bind(
                (void) ldap_int_sasl_external( ld, ld->ld_defconn, authid.bv_val, fac );
                LDAP_FREE( authid.bv_val );
        }
+#endif
 
 #if !defined(_WIN32)
        /* Check for local */
@@ -996,11 +1005,58 @@ ldap_int_sasl_get_option( LDAP *ld, int option, void *arg )
                case LDAP_OPT_X_SASL_MAXBUFSIZE:
                        *(ber_len_t *)arg = ld->ld_options.ldo_sasl_secprops.maxbufsize;
                        break;
+               case LDAP_OPT_X_SASL_NOCANON:
+                       *(int *)arg = (int) LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_SASL_NOCANON );
+                       break;
+
+               case LDAP_OPT_X_SASL_USERNAME: {
+                       int sc;
+                       char *username;
+                       sasl_conn_t *ctx;
+
+                       if( ld->ld_defconn == NULL ) {
+                               return -1;
+                       }
+
+                       ctx = ld->ld_defconn->lconn_sasl_authctx;
+
+                       if ( ctx == NULL ) {
+                               return -1;
+                       }
+
+                       sc = sasl_getprop( ctx, SASL_USERNAME,
+                               (SASL_CONST void **)(char **) &username );
+
+                       if ( sc != SASL_OK ) {
+                               return -1;
+                       }
+
+                       *(char **)arg = username ? LDAP_STRDUP( username ) : NULL;
+               } break;
 
                case LDAP_OPT_X_SASL_SECPROPS:
                        /* this option is write only */
                        return -1;
 
+#ifdef SASL_GSS_CREDS
+               case LDAP_OPT_X_SASL_GSS_CREDS: {
+                       sasl_conn_t *ctx;
+                       int sc;
+
+                       if ( ld->ld_defconn == NULL )
+                               return -1;
+
+                       ctx = ld->ld_defconn->lconn_sasl_authctx;
+                       if ( ctx == NULL )
+                               return -1;
+
+                       sc = sasl_getprop( ctx, SASL_GSS_CREDS, arg );
+                       if ( sc != SASL_OK )
+                               return -1;
+                       }
+                       break;
+#endif
+
                default:
                        return -1;
        }
@@ -1010,11 +1066,15 @@ ldap_int_sasl_get_option( LDAP *ld, int option, void *arg )
 int
 ldap_int_sasl_set_option( LDAP *ld, int option, void *arg )
 {
-       if ( ld == NULL || arg == NULL )
+       if ( ld == NULL )
+               return -1;
+
+       if ( arg == NULL && option != LDAP_OPT_X_SASL_NOCANON )
                return -1;
 
        switch ( option ) {
        case LDAP_OPT_X_SASL_SSF:
+       case LDAP_OPT_X_SASL_USERNAME:
                /* This option is read-only */
                return -1;
 
@@ -1063,6 +1123,13 @@ ldap_int_sasl_set_option( LDAP *ld, int option, void *arg )
        case LDAP_OPT_X_SASL_MAXBUFSIZE:
                ld->ld_options.ldo_sasl_secprops.maxbufsize = *(ber_len_t *)arg;
                break;
+       case LDAP_OPT_X_SASL_NOCANON:
+               if ( arg == LDAP_OPT_OFF ) {
+                       LDAP_BOOL_CLR(&ld->ld_options, LDAP_BOOL_SASL_NOCANON );
+               } else {
+                       LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_SASL_NOCANON );
+               }
+               break;
 
        case LDAP_OPT_X_SASL_SECPROPS: {
                int sc;
@@ -1072,6 +1139,25 @@ ldap_int_sasl_set_option( LDAP *ld, int option, void *arg )
                return sc == LDAP_SUCCESS ? 0 : -1;
                }
 
+#ifdef SASL_GSS_CREDS
+       case LDAP_OPT_X_SASL_GSS_CREDS: {
+               sasl_conn_t *ctx;
+               int sc;
+
+               if ( ld->ld_defconn == NULL )
+                       return -1;
+
+               ctx = ld->ld_defconn->lconn_sasl_authctx;
+               if ( ctx == NULL )
+                       return -1;
+
+               sc = sasl_setprop( ctx, SASL_GSS_CREDS, arg );
+               if ( sc != SASL_OK )
+                       return -1;
+               }
+               break;
+#endif
+
        default:
                return -1;
        }