Merge branch 'master' of ssh://git.samba.org/data/git/samba into selftest
[bbaumbach/samba-autobuild/.git] / source4 / auth / gensec / cyrus_sasl.c
index 2cb078ff36e4ab706ecc1188ce2b0d9552a7d0ae..6f82de82fcd0a9ecfa082af4815b839b17fc298f 100644 (file)
@@ -7,7 +7,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
 #include "auth/auth.h"
+#include "auth/credentials/credentials.h"
+#include "auth/gensec/gensec.h"
+#include "auth/gensec/gensec_proto.h"
 #include "lib/socket/socket.h"
 #include <sasl/sasl.h>
 
@@ -100,7 +102,7 @@ static int gensec_sasl_get_password(sasl_conn_t *conn, void *context, int id,
                return SASL_NOMEM;
        }
        secret->len = strlen(password);
-       safe_strcpy(secret->data, password, secret->len+1);
+       safe_strcpy((char*)secret->data, password, secret->len+1);
        *psecret = secret;
        return SASL_OK;
 }
@@ -108,7 +110,7 @@ static int gensec_sasl_get_password(sasl_conn_t *conn, void *context, int id,
 static int gensec_sasl_dispose(struct gensec_sasl_state *gensec_sasl_state)
 {
        sasl_dispose(&gensec_sasl_state->conn);
-       return 0;
+       return SASL_OK;
 }
 
 static NTSTATUS gensec_sasl_client_start(struct gensec_security *gensec_security)
@@ -212,8 +214,9 @@ static NTSTATUS gensec_sasl_update(struct gensec_security *gensec_security,
                sasl_ret = sasl_client_start(gensec_sasl_state->conn, gensec_security->ops->sasl_name, 
                                             NULL, &out_data, &out_len, &mech);
        } else {
-               sasl_ret = sasl_client_step(gensec_sasl_state->conn, 
-                                           in.data, in.length, NULL, &out_data, &out_len);
+               sasl_ret = sasl_client_step(gensec_sasl_state->conn,
+                                           (char*)in.data, in.length, NULL,
+                                           &out_data, &out_len);
        }
        if (sasl_ret == SASL_OK || sasl_ret == SASL_CONTINUE) {
                *out = data_blob_talloc(out_mem_ctx, out_data, out_len);
@@ -236,8 +239,9 @@ static NTSTATUS gensec_sasl_unwrap_packets(struct gensec_security *gensec_securi
        const char *out_data;
        unsigned int out_len;
 
-       int sasl_ret = sasl_decode(gensec_sasl_state->conn, 
-                                  in->data, in->length, &out_data, &out_len);
+       int sasl_ret = sasl_decode(gensec_sasl_state->conn,
+                                  (char*)in->data, in->length, &out_data,
+                                  &out_len);
        if (sasl_ret == SASL_OK) {
                *out = data_blob_talloc(out_mem_ctx, out_data, out_len);
                *len_processed = in->length;
@@ -247,6 +251,7 @@ static NTSTATUS gensec_sasl_unwrap_packets(struct gensec_security *gensec_securi
        return sasl_nt_status(sasl_ret);
 
 }
+
 static NTSTATUS gensec_sasl_wrap_packets(struct gensec_security *gensec_security, 
                                        TALLOC_CTX *out_mem_ctx, 
                                        const DATA_BLOB *in, 
@@ -258,8 +263,9 @@ static NTSTATUS gensec_sasl_wrap_packets(struct gensec_security *gensec_security
        const char *out_data;
        unsigned int out_len;
 
-       int sasl_ret = sasl_encode(gensec_sasl_state->conn, 
-                                  in->data, in->length, &out_data, &out_len);
+       int sasl_ret = sasl_encode(gensec_sasl_state->conn,
+                                  (char*)in->data, in->length, &out_data,
+                                  &out_len);
        if (sasl_ret == SASL_OK) {
                *out = data_blob_talloc(out_mem_ctx, out_data, out_len);
                *len_processed = in->length;
@@ -270,33 +276,34 @@ static NTSTATUS gensec_sasl_wrap_packets(struct gensec_security *gensec_security
 }
 
 /* Try to figure out what features we actually got on the connection */
-static BOOL gensec_sasl_have_feature(struct gensec_security *gensec_security, 
+static bool gensec_sasl_have_feature(struct gensec_security *gensec_security, 
                                     uint32_t feature) 
 {
        struct gensec_sasl_state *gensec_sasl_state = talloc_get_type(gensec_security->private_data,
                                                                      struct gensec_sasl_state);
        sasl_ssf_t ssf;
-       int sasl_ret = sasl_getprop(gensec_sasl_state->conn, SASL_SSF, &ssf);
+       int sasl_ret = sasl_getprop(gensec_sasl_state->conn, SASL_SSF,
+                       (const void**)&ssf);
        if (sasl_ret != SASL_OK) {
-               return False;
+               return false;
        }
        if (feature & GENSEC_FEATURE_SIGN) {
                if (ssf == 0) {
-                       return False;
+                       return false;
                }
                if (ssf >= 1) {
-                       return True;
+                       return true;
                }
        }
        if (feature & GENSEC_FEATURE_SEAL) {
                if (ssf <= 1) {
-                       return False;
+                       return false;
                }
                if (ssf > 1) {
-                       return True;
+                       return true;
                }
        }
-       return False;
+       return false;
 }
 
 /* This could in theory work with any SASL mech */
@@ -308,7 +315,8 @@ static const struct gensec_security_ops gensec_sasl_security_ops = {
        .wrap_packets     = gensec_sasl_wrap_packets,
        .unwrap_packets   = gensec_sasl_unwrap_packets,
        .have_feature     = gensec_sasl_have_feature,
-       .enabled          = False,
+       .enabled          = true,
+       .priority         = GENSEC_SASL
 };
 
 int gensec_sasl_log(void *context, 
@@ -355,8 +363,11 @@ int gensec_sasl_log(void *context,
 NTSTATUS gensec_sasl_init(void)
 {
        NTSTATUS ret;
-       int sasl_ret, i;
+       int sasl_ret;
+#if 0
+       int i;
        const char **sasl_mechs;
+#endif
        
        static const sasl_callback_t callbacks[] = {
                { 
@@ -398,7 +409,7 @@ NTSTATUS gensec_sasl_init(void)
                if (oldmech) {
                        continue;
                }
-               newmech = talloc(NULL, struct gensec_security_ops);
+               newmech = talloc(talloc_autofree_context(), struct gensec_security_ops);
                if (!newmech) {
                        return NT_STATUS_NO_MEMORY;
                }