Move source4/lib/crypto to lib/crypto.
[ira/wip.git] / source4 / torture / rpc / samlogon.c
index 7fd5199908fc0fc46bd1cb291ee26e4498780bc6..4fbffee41ed830bb591f17a8f78e699377dd1282 100644 (file)
 #include "librpc/gen_ndr/ndr_netlogon_c.h"
 #include "librpc/gen_ndr/ndr_samr_c.h"
 #include "auth/auth.h"
-#include "lib/crypto/crypto.h"
+#include "../lib/crypto/crypto.h"
 #include "lib/cmdline/popt_common.h"
 #include "torture/rpc/rpc.h"
 #include "auth/gensec/schannel_proto.h"
+#include "auth/gensec/gensec.h"
 #include "libcli/auth/libcli_auth.h"
 #include "param/param.h"
 
@@ -64,6 +65,7 @@ struct samlogon_state {
        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;
+       struct smb_iconv_convenience *iconv_convenience;
 };
 
 /* 
@@ -591,7 +593,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, TEST_MACHINE_NAME, lp_workgroup(global_loadparm));
+       DATA_BLOB names_blob = NTLMv2_generate_names_blob(samlogon_state->mem_ctx, samlogon_state->iconv_convenience, TEST_MACHINE_NAME, lp_workgroup(global_loadparm));
 
        uint8_t lm_session_key[8];
        uint8_t user_session_key[16];
@@ -739,7 +741,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, lp_netbios_name(global_loadparm), lp_workgroup(global_loadparm));
+       DATA_BLOB names_blob = NTLMv2_generate_names_blob(samlogon_state->mem_ctx, samlogon_state->iconv_convenience, lp_netbios_name(global_loadparm), lp_workgroup(global_loadparm));
 
        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);
@@ -1158,7 +1160,7 @@ 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, 
-                             lp_iconv_convenience(global_loadparm)
+                             samlogon_state->iconv_convenience
                              &unicodepw, samlogon_state->password)) == -1) {
                DEBUG(0, ("push_ucs2_allocate failed!\n"));
                exit(1);
@@ -1169,7 +1171,7 @@ 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, 
-                                  lp_iconv_convenience(global_loadparm),
+                                  samlogon_state->iconv_convenience,
                                   CH_UNIX, CH_DOS, 
                                   password, strlen(password)+1, 
                                   (void**)&dospw)) == -1) {
@@ -1310,6 +1312,7 @@ static const struct ntlm_tests {
   try a netlogon SamLogon
 */
 static bool test_SamLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
+                         struct torture_context *tctx,
                          struct creds_CredentialState *creds, 
                          const char *comment,
                          const char *account_domain, const char *account_name, 
@@ -1340,6 +1343,7 @@ static bool test_SamLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        samlogon_state.chall = data_blob_talloc(fn_ctx, NULL, 8);
        samlogon_state.parameter_control = parameter_control;
        samlogon_state.old_password = old_password;
+       samlogon_state.iconv_convenience = lp_iconv_convenience(tctx->lp_ctx);
 
        generate_random_buffer(samlogon_state.chall.data, 8);
        samlogon_state.r_flags.in.server_name = talloc_asprintf(fn_ctx, "\\\\%s", dcerpc_server_name(p));
@@ -1598,7 +1602,7 @@ bool torture_rpc_samlogon(struct torture_context *torture)
 
        status = dcerpc_pipe_connect_b(mem_ctx, &p, b, 
                                       &ndr_table_netlogon,
-                                      machine_credentials, NULL, torture->lp_ctx);
+                                      machine_credentials, torture->ev, torture->lp_ctx);
 
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("RPC pipe connect as domain member failed: %s\n", nt_errstr(status));
@@ -1792,7 +1796,7 @@ bool torture_rpc_samlogon(struct torture_context *torture)
                        }
                
                        if (usercreds[ci].network_login) {
-                               if (!test_SamLogon(p, mem_ctx, creds, 
+                               if (!test_SamLogon(p, mem_ctx, torture, creds, 
                                                   usercreds[ci].comment,
                                                   usercreds[ci].domain,
                                                   usercreds[ci].username,
@@ -1825,7 +1829,7 @@ bool torture_rpc_samlogon(struct torture_context *torture)
                        }
                
                        if (usercreds[0].network_login) {
-                               if (!test_SamLogon(p, mem_ctx, creds,
+                               if (!test_SamLogon(p, mem_ctx, torture, creds,
                                                   usercreds[0].comment,
                                                   usercreds[0].domain,
                                                   usercreds[0].username,
@@ -1843,9 +1847,9 @@ bool torture_rpc_samlogon(struct torture_context *torture)
 failed:
        talloc_free(mem_ctx);
 
-       torture_leave_domain(join_ctx);
-       torture_leave_domain(user_ctx);
-       torture_leave_domain(user_ctx_wrong_wks);
-       torture_leave_domain(user_ctx_wrong_time);
+       torture_leave_domain(torture, join_ctx);
+       torture_leave_domain(torture, user_ctx);
+       torture_leave_domain(torture, user_ctx_wrong_wks);
+       torture_leave_domain(torture, user_ctx_wrong_time);
        return ret;
 }