s4: fix various warnings (not "const" related ones)
[sfrench/samba-autobuild/.git] / source4 / torture / rpc / samlogon.c
index b7028e660959d5e74d46ea0fa6db585ab742c206..8e6c88425ce9e15886053b5bba0be3056f42658f 100644 (file)
@@ -29,7 +29,7 @@
 #include "../lib/crypto/crypto.h"
 #include "lib/cmdline/popt_common.h"
 #include "torture/rpc/rpc.h"
-#include "auth/gensec/schannel_proto.h"
+#include "../libcli/auth/schannel.h"
 #include "auth/gensec/gensec.h"
 #include "libcli/auth/libcli_auth.h"
 #include "param/param.h"
@@ -63,7 +63,7 @@ struct samlogon_state {
        struct netr_LogonSamLogonEx r_ex;
        struct netr_LogonSamLogonWithFlags r_flags;
        struct netr_Authenticator auth, auth2;
-       struct creds_CredentialState *creds;
+       struct netlogon_creds_CredentialState *creds;
        NTSTATUS expected_error;
        bool old_password; /* Allow an old password to be accepted or rejected without error, as well as session key bugs */
        DATA_BLOB chall;
@@ -92,9 +92,9 @@ static NTSTATUS check_samlogon(struct samlogon_state *samlogon_state,
        struct netr_SamBaseInfo *base = NULL;
        uint16_t validation_level = 0;
        
-       samlogon_state->r.in.logon.network = &ninfo;
-       samlogon_state->r_ex.in.logon.network = &ninfo;
-       samlogon_state->r_flags.in.logon.network = &ninfo;
+       samlogon_state->r.in.logon->network = &ninfo;
+       samlogon_state->r_ex.in.logon->network = &ninfo;
+       samlogon_state->r_flags.in.logon->network = &ninfo;
        
        ninfo.identity_info.domain_name.string = samlogon_state->account_domain;
        ninfo.identity_info.parameter_control = parameter_control;
@@ -153,12 +153,12 @@ static NTSTATUS check_samlogon(struct samlogon_state *samlogon_state,
        switch (samlogon_state->function_level) {
        case NDR_NETR_LOGONSAMLOGON: 
                ZERO_STRUCT(samlogon_state->auth2);
-               creds_client_authenticator(samlogon_state->creds, &samlogon_state->auth);
+               netlogon_creds_client_authenticator(samlogon_state->creds, &samlogon_state->auth);
 
                r->out.return_authenticator = NULL;
                status = dcerpc_netr_LogonSamLogon(samlogon_state->p, samlogon_state->mem_ctx, r);
                if (!r->out.return_authenticator || 
-                   !creds_client_check(samlogon_state->creds, &r->out.return_authenticator->cred)) {
+                   !netlogon_creds_client_check(samlogon_state->creds, &r->out.return_authenticator->cred)) {
                        d_printf("Credential chaining failed\n");
                }
                if (!NT_STATUS_IS_OK(status)) {
@@ -170,17 +170,17 @@ static NTSTATUS check_samlogon(struct samlogon_state *samlogon_state,
 
                validation_level = r->in.validation_level;
 
-               creds_decrypt_samlogon(samlogon_state->creds, validation_level, &r->out.validation);
+               netlogon_creds_decrypt_samlogon(samlogon_state->creds, validation_level, r->out.validation);
 
                switch (validation_level) {
                case 2:
-                       base = &r->out.validation.sam2->base;
+                       base = &r->out.validation->sam2->base;
                        break;
                case 3:
-                       base = &r->out.validation.sam3->base;
+                       base = &r->out.validation->sam3->base;
                        break;
                case 6:
-                       base = &r->out.validation.sam6->base;
+                       base = &r->out.validation->sam6->base;
                        break;
                }
                break;
@@ -195,28 +195,28 @@ static NTSTATUS check_samlogon(struct samlogon_state *samlogon_state,
 
                validation_level = r_ex->in.validation_level;
 
-               creds_decrypt_samlogon(samlogon_state->creds, validation_level, &r_ex->out.validation);
+               netlogon_creds_decrypt_samlogon(samlogon_state->creds, validation_level, r_ex->out.validation);
 
                switch (validation_level) {
                case 2:
-                       base = &r_ex->out.validation.sam2->base;
+                       base = &r_ex->out.validation->sam2->base;
                        break;
                case 3:
-                       base = &r_ex->out.validation.sam3->base;
+                       base = &r_ex->out.validation->sam3->base;
                        break;
                case 6:
-                       base = &r_ex->out.validation.sam6->base;
+                       base = &r_ex->out.validation->sam6->base;
                        break;
                }
                break;
        case NDR_NETR_LOGONSAMLOGONWITHFLAGS: 
                ZERO_STRUCT(samlogon_state->auth2);
-               creds_client_authenticator(samlogon_state->creds, &samlogon_state->auth);
+               netlogon_creds_client_authenticator(samlogon_state->creds, &samlogon_state->auth);
 
                r_flags->out.return_authenticator = NULL;
                status = dcerpc_netr_LogonSamLogonWithFlags(samlogon_state->p, samlogon_state->mem_ctx, r_flags);
                if (!r_flags->out.return_authenticator || 
-                   !creds_client_check(samlogon_state->creds, &r_flags->out.return_authenticator->cred)) {
+                   !netlogon_creds_client_check(samlogon_state->creds, &r_flags->out.return_authenticator->cred)) {
                        d_printf("Credential chaining failed\n");
                }
                if (!NT_STATUS_IS_OK(status)) {
@@ -228,17 +228,17 @@ static NTSTATUS check_samlogon(struct samlogon_state *samlogon_state,
                
                validation_level = r_flags->in.validation_level;
 
-               creds_decrypt_samlogon(samlogon_state->creds, validation_level, &r_flags->out.validation);
+               netlogon_creds_decrypt_samlogon(samlogon_state->creds, validation_level, r_flags->out.validation);
 
                switch (validation_level) {
                case 2:
-                       base = &r_flags->out.validation.sam2->base;
+                       base = &r_flags->out.validation->sam2->base;
                        break;
                case 3:
-                       base = &r_flags->out.validation.sam3->base;
+                       base = &r_flags->out.validation->sam3->base;
                        break;
                case 6:
-                       base = &r_flags->out.validation.sam6->base;
+                       base = &r_flags->out.validation->sam6->base;
                        break;
                }
                break;
@@ -595,7 +595,7 @@ static bool test_lmv2_ntlmv2_broken(struct samlogon_state *samlogon_state,
        DATA_BLOB lmv2_response = data_blob(NULL, 0);
        DATA_BLOB lmv2_session_key = data_blob(NULL, 0);
        DATA_BLOB ntlmv2_session_key = data_blob(NULL, 0);
-       DATA_BLOB names_blob = NTLMv2_generate_names_blob(samlogon_state->mem_ctx, samlogon_state->iconv_convenience, TEST_MACHINE_NAME, samlogon_state->workgroup);
+       DATA_BLOB names_blob = NTLMv2_generate_names_blob(samlogon_state->mem_ctx, TEST_MACHINE_NAME, samlogon_state->workgroup);
 
        uint8_t lm_session_key[8];
        uint8_t user_session_key[16];
@@ -743,7 +743,7 @@ static bool test_lmv2_ntlm_broken(struct samlogon_state *samlogon_state,
        DATA_BLOB lmv2_response = data_blob(NULL, 0);
        DATA_BLOB lmv2_session_key = data_blob(NULL, 0);
        DATA_BLOB ntlmv2_session_key = data_blob(NULL, 0);
-       DATA_BLOB names_blob = NTLMv2_generate_names_blob(samlogon_state->mem_ctx, samlogon_state->iconv_convenience, samlogon_state->netbios_name, samlogon_state->workgroup);
+       DATA_BLOB names_blob = NTLMv2_generate_names_blob(samlogon_state->mem_ctx, samlogon_state->netbios_name, samlogon_state->workgroup);
 
        DATA_BLOB ntlm_response = data_blob_talloc(samlogon_state->mem_ctx, NULL, 24);
        DATA_BLOB ntlm_session_key = data_blob_talloc(samlogon_state->mem_ctx, NULL, 16);
@@ -1150,7 +1150,7 @@ static bool test_plaintext(struct samlogon_state *samlogon_state, enum ntlm_brea
        DATA_BLOB lm_response = data_blob(NULL, 0);
        char *password;
        char *dospw;
-       void *unicodepw;
+       smb_ucs2_t *unicodepw;
 
        uint8_t user_session_key[16];
        uint8_t lm_key[16];
@@ -1161,9 +1161,8 @@ static bool test_plaintext(struct samlogon_state *samlogon_state, enum ntlm_brea
 
        ZERO_STRUCT(user_session_key);
        
-       if ((push_ucs2_talloc(samlogon_state->mem_ctx, 
-                             samlogon_state->iconv_convenience, 
-                             &unicodepw, samlogon_state->password)) == -1) {
+       if (!push_ucs2_talloc(samlogon_state->mem_ctx, 
+                             &unicodepw, samlogon_state->password, NULL)) {
                DEBUG(0, ("push_ucs2_allocate failed!\n"));
                exit(1);
        }
@@ -1172,11 +1171,11 @@ static bool test_plaintext(struct samlogon_state *samlogon_state, enum ntlm_brea
 
        password = strupper_talloc(samlogon_state->mem_ctx, samlogon_state->password);
 
-       if ((convert_string_talloc(samlogon_state->mem_ctx, 
+       if (!convert_string_talloc_convenience(samlogon_state->mem_ctx, 
                                   samlogon_state->iconv_convenience,
                                   CH_UNIX, CH_DOS, 
                                   password, strlen(password)+1, 
-                                  (void**)&dospw)) == -1) {
+                                  (void**)&dospw, NULL, false)) {
                DEBUG(0, ("convert_string_talloc failed!\n"));
                exit(1);
        }
@@ -1315,7 +1314,7 @@ static const struct ntlm_tests {
 */
 static bool test_SamLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
                          struct torture_context *tctx,
-                         struct creds_CredentialState *creds, 
+                         struct netlogon_creds_CredentialState *creds, 
                          const char *comment,
                          const char *account_domain, const char *account_name, 
                          const char *plain_pass, uint32_t parameter_control,
@@ -1332,7 +1331,14 @@ static bool test_SamLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                NDR_NETR_LOGONSAMLOGONEX,
                NDR_NETR_LOGONSAMLOGONWITHFLAGS };
        struct samlogon_state samlogon_state;
-       
+
+       union netr_LogonLevel logon;
+       union netr_Validation validation;
+       uint8_t authoritative = 0;
+       uint32_t flags = 0;
+
+       ZERO_STRUCT(logon);
+
        d_printf("testing netr_LogonSamLogon and netr_LogonSamLogonWithFlags\n");
        
        samlogon_state.comment = comment;
@@ -1354,16 +1360,28 @@ static bool test_SamLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        samlogon_state.r_flags.in.computer_name = TEST_MACHINE_NAME;
        samlogon_state.r_flags.in.credential = &samlogon_state.auth;
        samlogon_state.r_flags.in.return_authenticator = &samlogon_state.auth2;
-       samlogon_state.r_flags.in.flags = 0;
+       samlogon_state.r_flags.in.flags = &flags;
+       samlogon_state.r_flags.in.logon = &logon;
+       samlogon_state.r_flags.out.validation = &validation;
+       samlogon_state.r_flags.out.authoritative = &authoritative;
+       samlogon_state.r_flags.out.flags = &flags;
 
        samlogon_state.r_ex.in.server_name = talloc_asprintf(fn_ctx, "\\\\%s", dcerpc_server_name(p));
        samlogon_state.r_ex.in.computer_name = TEST_MACHINE_NAME;
-       samlogon_state.r_ex.in.flags = 0;
+       samlogon_state.r_ex.in.flags = &flags;
+       samlogon_state.r_ex.in.logon = &logon;
+       samlogon_state.r_ex.out.validation = &validation;
+       samlogon_state.r_ex.out.authoritative = &authoritative;
+       samlogon_state.r_ex.out.flags = &flags;
 
        samlogon_state.r.in.server_name = talloc_asprintf(fn_ctx, "\\\\%s", dcerpc_server_name(p));
        samlogon_state.r.in.computer_name = TEST_MACHINE_NAME;
        samlogon_state.r.in.credential = &samlogon_state.auth;
        samlogon_state.r.in.return_authenticator = &samlogon_state.auth2;
+       samlogon_state.r.in.logon = &logon;
+       samlogon_state.r.out.validation = &validation;
+       samlogon_state.r.out.authoritative = &authoritative;
+
 
        for (f=0;f<ARRAY_SIZE(function_levels);f++) {
                for (i=0; test_table[i].fn; i++) {
@@ -1411,7 +1429,7 @@ static bool test_SamLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
   test an ADS style interactive domain logon
 */
 bool test_InteractiveLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
-                          struct creds_CredentialState *creds, 
+                          struct netlogon_creds_CredentialState *creds, 
                           const char *comment,
                           const char *workstation_name,
                           const char *account_domain, const char *account_name,
@@ -1423,21 +1441,34 @@ bool test_InteractiveLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        struct netr_LogonSamLogonWithFlags r;
        struct netr_Authenticator a, ra;
        struct netr_PasswordInfo pinfo;
+       uint32_t flags = 0;
+
+       union netr_LogonLevel logon;
+       union netr_Validation validation;
+       uint8_t authoritative = 0;
 
        ZERO_STRUCT(a);
        ZERO_STRUCT(r);
        ZERO_STRUCT(ra);
 
-       creds_client_authenticator(creds, &a);
+       ZERO_STRUCT(logon);
+       ZERO_STRUCT(validation);
+
+       netlogon_creds_client_authenticator(creds, &a);
+
+       logon.password = &pinfo;
 
        r.in.server_name = talloc_asprintf(fn_ctx, "\\\\%s", dcerpc_server_name(p));
        r.in.computer_name = TEST_MACHINE_NAME;
        r.in.credential = &a;
        r.in.return_authenticator = &ra;
        r.in.logon_level = 5;
-       r.in.logon.password = &pinfo;
+       r.in.logon = &logon;
        r.in.validation_level = 6;
-       r.in.flags = 0;
+       r.in.flags = &flags;
+       r.out.validation = &validation;
+       r.out.authoritative = &authoritative;
+       r.out.flags = &flags;
 
        pinfo.identity_info.domain_name.string = account_domain;
        pinfo.identity_info.parameter_control = parameter_control;
@@ -1452,18 +1483,18 @@ bool test_InteractiveLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        E_md4hash(plain_pass, pinfo.ntpassword.hash);
 
        if (creds->negotiate_flags & NETLOGON_NEG_ARCFOUR) {
-               creds_arcfour_crypt(creds, pinfo.lmpassword.hash, 16);
-               creds_arcfour_crypt(creds, pinfo.ntpassword.hash, 16);
+               netlogon_creds_arcfour_crypt(creds, pinfo.lmpassword.hash, 16);
+               netlogon_creds_arcfour_crypt(creds, pinfo.ntpassword.hash, 16);
        } else {
-               creds_des_encrypt(creds, &pinfo.lmpassword);
-               creds_des_encrypt(creds, &pinfo.ntpassword);
+               netlogon_creds_des_encrypt(creds, &pinfo.lmpassword);
+               netlogon_creds_des_encrypt(creds, &pinfo.ntpassword);
        }
 
        d_printf("Testing netr_LogonSamLogonWithFlags '%s' (Interactive Logon)\n", comment);
 
        status = dcerpc_netr_LogonSamLogonWithFlags(p, fn_ctx, &r);
        if (!r.out.return_authenticator 
-           || !creds_client_check(creds, &r.out.return_authenticator->cred)) {
+           || !netlogon_creds_client_check(creds, &r.out.return_authenticator->cred)) {
                d_printf("Credential chaining failed\n");
                talloc_free(fn_ctx);
                return false;
@@ -1509,7 +1540,7 @@ bool torture_rpc_samlogon(struct torture_context *torture)
                0 /* yes, this is a valid flag, causes the use of DES */ 
        };
 
-       struct creds_CredentialState *creds;
+       struct netlogon_creds_CredentialState *creds;
 
        test_machine_account = talloc_asprintf(mem_ctx, "%s$", TEST_MACHINE_NAME);
        /* We only need to join as a workstation here, and in future,
@@ -1536,7 +1567,7 @@ bool torture_rpc_samlogon(struct torture_context *torture)
 
        old_user_password = user_password;
 
-       test_ChangePasswordUser3(torture_join_samr_pipe(user_ctx), mem_ctx,
+       test_ChangePasswordUser3(torture_join_samr_pipe(user_ctx), torture,
                                 TEST_USER_NAME, 16 /* > 14 */, &user_password, 
                                 NULL, 0, false);