Finish removal of iconv_convenience in public API's.
[bbaumbach/samba-autobuild/.git] / source4 / torture / rpc / samlogon.c
index 8e6c88425ce9e15886053b5bba0be3056f42658f..c59e4474435994fe5d07b55cf68988ad0d2dc855 100644 (file)
 #include "librpc/gen_ndr/ndr_netlogon.h"
 #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/cmdline/popt_common.h"
-#include "torture/rpc/rpc.h"
-#include "../libcli/auth/schannel.h"
+#include "torture/rpc/torture_rpc.h"
 #include "auth/gensec/gensec.h"
 #include "libcli/auth/libcli_auth.h"
 #include "param/param.h"
@@ -67,7 +65,6 @@ 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;
 };
 
 /* 
@@ -156,16 +153,23 @@ static NTSTATUS check_samlogon(struct samlogon_state *samlogon_state,
                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);
+               status = dcerpc_netr_LogonSamLogon_r(samlogon_state->p->binding_handle,
+                                                    samlogon_state->mem_ctx, r);
+               if (!NT_STATUS_IS_OK(status)) {
+                       if (error_string) {
+                               *error_string = strdup(nt_errstr(status));
+                       }
+                       return status;
+               }
                if (!r->out.return_authenticator || 
                    !netlogon_creds_client_check(samlogon_state->creds, &r->out.return_authenticator->cred)) {
                        d_printf("Credential chaining failed\n");
                }
-               if (!NT_STATUS_IS_OK(status)) {
+               if (!NT_STATUS_IS_OK(r->out.result)) {
                        if (error_string) {
-                               *error_string = strdup(nt_errstr(status));
+                               *error_string = strdup(nt_errstr(r->out.result));
                        }
-                       return status;
+                       return r->out.result;
                }
 
                validation_level = r->in.validation_level;
@@ -185,13 +189,20 @@ static NTSTATUS check_samlogon(struct samlogon_state *samlogon_state,
                }
                break;
        case NDR_NETR_LOGONSAMLOGONEX: 
-               status = dcerpc_netr_LogonSamLogonEx(samlogon_state->p, samlogon_state->mem_ctx, r_ex);
+               status = dcerpc_netr_LogonSamLogonEx_r(samlogon_state->p->binding_handle,
+                                                      samlogon_state->mem_ctx, r_ex);
                if (!NT_STATUS_IS_OK(status)) {
                        if (error_string) {
                                *error_string = strdup(nt_errstr(status));
                        }
                        return status;
                }
+               if (!NT_STATUS_IS_OK(r_ex->out.result)) {
+                       if (error_string) {
+                               *error_string = strdup(nt_errstr(r_ex->out.result));
+                       }
+                       return r_ex->out.result;
+               }
 
                validation_level = r_ex->in.validation_level;
 
@@ -214,16 +225,23 @@ static NTSTATUS check_samlogon(struct samlogon_state *samlogon_state,
                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);
+               status = dcerpc_netr_LogonSamLogonWithFlags_r(samlogon_state->p->binding_handle,
+                                                             samlogon_state->mem_ctx, r_flags);
+               if (!NT_STATUS_IS_OK(status)) {
+                       if (error_string) {
+                               *error_string = strdup(nt_errstr(status));
+                       }
+                       return status;
+               }
                if (!r_flags->out.return_authenticator || 
                    !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)) {
+               if (!NT_STATUS_IS_OK(r_flags->out.result)) {
                        if (error_string) {
-                               *error_string = strdup(nt_errstr(status));
+                               *error_string = strdup(nt_errstr(r_flags->out.result));
                        }
-                       return status;
+                       return r_flags->out.result;
                }
                
                validation_level = r_flags->in.validation_level;
@@ -1171,8 +1189,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_convenience(samlogon_state->mem_ctx, 
-                                  samlogon_state->iconv_convenience,
+       if (!convert_string_talloc(samlogon_state->mem_ctx, 
                                   CH_UNIX, CH_DOS, 
                                   password, strlen(password)+1, 
                                   (void**)&dospw, NULL, false)) {
@@ -1339,7 +1356,7 @@ static bool test_SamLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
 
        ZERO_STRUCT(logon);
 
-       d_printf("testing netr_LogonSamLogon and netr_LogonSamLogonWithFlags\n");
+       d_printf("Testing netr_LogonSamLogon and netr_LogonSamLogonWithFlags\n");
        
        samlogon_state.comment = comment;
        samlogon_state.account_name = account_name;
@@ -1353,7 +1370,6 @@ 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));
@@ -1446,6 +1462,7 @@ bool test_InteractiveLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        union netr_LogonLevel logon;
        union netr_Validation validation;
        uint8_t authoritative = 0;
+       struct dcerpc_binding_handle *b = p->binding_handle;
 
        ZERO_STRUCT(a);
        ZERO_STRUCT(r);
@@ -1492,7 +1509,12 @@ bool test_InteractiveLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
 
        d_printf("Testing netr_LogonSamLogonWithFlags '%s' (Interactive Logon)\n", comment);
 
-       status = dcerpc_netr_LogonSamLogonWithFlags(p, fn_ctx, &r);
+       status = dcerpc_netr_LogonSamLogonWithFlags_r(b, fn_ctx, &r);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("%s: netr_LogonSamLogonWithFlags - %s\n",
+                        __location__, nt_errstr(status));
+               return false;
+       }
        if (!r.out.return_authenticator 
            || !netlogon_creds_client_check(creds, &r.out.return_authenticator->cred)) {
                d_printf("Credential chaining failed\n");
@@ -1502,9 +1524,9 @@ bool test_InteractiveLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
 
        talloc_free(fn_ctx);
 
-       if (!NT_STATUS_EQUAL(expected_error, status)) {
+       if (!NT_STATUS_EQUAL(expected_error, r.out.result)) {
                d_printf("[%s]\\[%s] netr_LogonSamLogonWithFlags - expected %s got %s\n", 
-                      account_domain, account_name, nt_errstr(expected_error), nt_errstr(status));
+                      account_domain, account_name, nt_errstr(expected_error), nt_errstr(r.out.result));
                return false;
        }
 
@@ -1541,6 +1563,7 @@ bool torture_rpc_samlogon(struct torture_context *torture)
        };
 
        struct netlogon_creds_CredentialState *creds;
+       struct dcerpc_pipe *tmp_p = NULL;
 
        test_machine_account = talloc_asprintf(mem_ctx, "%s$", TEST_MACHINE_NAME);
        /* We only need to join as a workstation here, and in future,
@@ -1567,7 +1590,8 @@ bool torture_rpc_samlogon(struct torture_context *torture)
 
        old_user_password = user_password;
 
-       test_ChangePasswordUser3(torture_join_samr_pipe(user_ctx), torture,
+       tmp_p = torture_join_samr_pipe(user_ctx);
+       test_ChangePasswordUser3(tmp_p, torture,
                                 TEST_USER_NAME, 16 /* > 14 */, &user_password, 
                                 NULL, 0, false);
 
@@ -1589,12 +1613,18 @@ bool torture_rpc_samlogon(struct torture_context *torture)
        u.info21.fields_present = SAMR_FIELD_WORKSTATIONS;
        u.info21.workstations.string = "not" TEST_MACHINE_NAME;
 
-       status = dcerpc_samr_SetUserInfo(torture_join_samr_pipe(user_ctx_wrong_wks), mem_ctx, &s);
+       tmp_p = torture_join_samr_pipe(user_ctx_wrong_wks);
+       status = dcerpc_samr_SetUserInfo_r(tmp_p->binding_handle, mem_ctx, &s);
        if (!NT_STATUS_IS_OK(status)) {
                printf("SetUserInfo (list of workstations) failed - %s\n", nt_errstr(status));
                ret = false;
                goto failed;
        }
+       if (!NT_STATUS_IS_OK(s.out.result)) {
+               printf("SetUserInfo (list of workstations) failed - %s\n", nt_errstr(s.out.result));
+               ret = false;
+               goto failed;
+       }
 
        user_ctx_wrong_time
                = torture_create_testuser(torture, TEST_USER_NAME_WRONG_TIME,
@@ -1616,12 +1646,18 @@ bool torture_rpc_samlogon(struct torture_context *torture)
        u.info21.logon_hours.units_per_week = 168;
        u.info21.logon_hours.bits = talloc_zero_array(mem_ctx, uint8_t, 168);
 
-       status = dcerpc_samr_SetUserInfo(torture_join_samr_pipe(user_ctx_wrong_time), mem_ctx, &s);
+       tmp_p = torture_join_samr_pipe(user_ctx_wrong_time);
+       status = dcerpc_samr_SetUserInfo_r(tmp_p->binding_handle, mem_ctx, &s);
        if (!NT_STATUS_IS_OK(status)) {
                printf("SetUserInfo (logon times and list of workstations) failed - %s\n", nt_errstr(status));
                ret = false;
                goto failed;
        }
+       if (!NT_STATUS_IS_OK(s.out.result)) {
+               printf("SetUserInfo (list of workstations) failed - %s\n", nt_errstr(s.out.result));
+               ret = false;
+               goto failed;
+       }
 
        status = torture_rpc_binding(torture, &b);
        if (!NT_STATUS_IS_OK(status)) {