r25398: Parse loadparm context to all lp_*() functions.
[kai/samba.git] / source / torture / rpc / samba3rpc.c
index 096aecea0b63423674cc4e5983e61ea48a03d210..75a7d760d91008eee2642866a42d0e56c8fe3342 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,
@@ -16,8 +16,7 @@
    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"
@@ -49,6 +48,7 @@
 #include "libcli/auth/libcli_auth.h"
 #include "lib/crypto/crypto.h"
 #include "libcli/security/proto.h"
+#include "param/param.h"
 
 static struct cli_credentials *create_anon_creds(TALLOC_CTX *mem_ctx)
 {
@@ -58,7 +58,7 @@ static struct cli_credentials *create_anon_creds(TALLOC_CTX *mem_ctx)
                return NULL;
        }
 
-       cli_credentials_set_conf(result);
+       cli_credentials_set_conf(result, global_loadparm);
        cli_credentials_set_anonymous(result);
 
        return result;
@@ -114,7 +114,7 @@ BOOL torture_bind_authcontext(struct torture_context *torture)
                goto done;
        }
 
-       status = dcerpc_bind_auth_none(lsa_pipe, &dcerpc_table_lsarpc);
+       status = dcerpc_bind_auth_none(lsa_pipe, &ndr_table_lsarpc);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("dcerpc_bind_auth_none failed: %s\n",
                         nt_errstr(status));
@@ -230,7 +230,7 @@ static BOOL bindtest(struct smbcli_state *cli,
                goto done;
        }
 
-       status = dcerpc_bind_auth(lsa_pipe, &dcerpc_table_lsarpc,
+       status = dcerpc_bind_auth(lsa_pipe, &ndr_table_lsarpc,
                                  credentials, auth_type, auth_level,
                                  NULL);
        if (!NT_STATUS_IS_OK(status)) {
@@ -370,7 +370,7 @@ static NTSTATUS get_usr_handle(struct smbcli_state *cli,
        }
 
        if (admin_creds != NULL) {
-               status = dcerpc_bind_auth(samr_pipe, &dcerpc_table_samr,
+               status = dcerpc_bind_auth(samr_pipe, &ndr_table_samr,
                                          admin_creds, auth_type, auth_level,
                                          NULL);
                if (!NT_STATUS_IS_OK(status)) {
@@ -380,7 +380,7 @@ static NTSTATUS get_usr_handle(struct smbcli_state *cli,
                }
        } else {
                /* We must have an authenticated SMB connection */
-               status = dcerpc_bind_auth_none(samr_pipe, &dcerpc_table_samr);
+               status = dcerpc_bind_auth_none(samr_pipe, &ndr_table_samr);
                if (!NT_STATUS_IS_OK(status)) {
                        d_printf("dcerpc_bind_auth_none failed: %s\n",
                                 nt_errstr(status));
@@ -536,24 +536,29 @@ static BOOL create_user(TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
                union samr_UserInfo u_info;
                DATA_BLOB session_key;
 
-               encode_pw_buffer(u_info.info24.password.data, password,
+
+               ZERO_STRUCT(u_info);
+               encode_pw_buffer(u_info.info23.password.data, password,
                                 STR_UNICODE);
-               u_info.info24.pw_len =  strlen_m(password)*2;
 
                status = dcerpc_fetch_session_key(samr_pipe, &session_key);
                if (!NT_STATUS_IS_OK(status)) {
                        d_printf("dcerpc_fetch_session_key failed\n");
                        goto done;
                }
-               arcfour_crypt_blob(u_info.info24.password.data, 516,
+               arcfour_crypt_blob(u_info.info23.password.data, 516,
                                   &session_key);
+               u_info.info23.info.password_expired = 0;
+               u_info.info23.info.fields_present = SAMR_FIELD_PASSWORD | 
+                                                   SAMR_FIELD_PASSWORD2 |
+                                                   SAMR_FIELD_EXPIRED_FLAG;
                sui2.in.user_handle = wks_handle;
                sui2.in.info = &u_info;
-               sui2.in.level = 24;
+               sui2.in.level = 23;
 
                status = dcerpc_samr_SetUserInfo2(samr_pipe, tmp_ctx, &sui2);
                if (!NT_STATUS_IS_OK(status)) {
-                       d_printf("samr_SetUserInfo(24) failed: %s\n",
+                       d_printf("samr_SetUserInfo(23) failed: %s\n",
                                 nt_errstr(status));
                        goto done;
                }
@@ -582,6 +587,7 @@ static BOOL create_user(TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
                qui.out.info->info21.force_password_change = 0;
                qui.out.info->info21.account_name.string = NULL;
                qui.out.info->info21.rid = 0;
+               qui.out.info->info21.acct_expiry = 0;
                qui.out.info->info21.fields_present = 0x81827fa; /* copy usrmgr.exe */
 
                u_info.info21 = qui.out.info->info21;
@@ -829,7 +835,7 @@ static BOOL auth2(struct smbcli_state *cli,
                goto done;
        }
 
-       status = dcerpc_bind_auth_none(net_pipe, &dcerpc_table_netlogon);
+       status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("dcerpc_bind_auth_none failed: %s\n",
                         nt_errstr(status));
@@ -936,12 +942,12 @@ static BOOL schan(struct smbcli_state *cli,
 #endif
 #if 1
        net_pipe->conn->flags |= (DCERPC_SIGN | DCERPC_SEAL);
-       status = dcerpc_bind_auth(net_pipe, &dcerpc_table_netlogon,
+       status = dcerpc_bind_auth(net_pipe, &ndr_table_netlogon,
                                  wks_creds, DCERPC_AUTH_TYPE_SCHANNEL,
                                  DCERPC_AUTH_LEVEL_PRIVACY,
                                  NULL);
 #else
-       status = dcerpc_bind_auth_none(net_pipe, &dcerpc_table_netlogon);
+       status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
 #endif
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("schannel bind failed: %s\n", nt_errstr(status));
@@ -1130,7 +1136,7 @@ BOOL torture_netlogon_samba3(struct torture_context *torture)
                wks_name = get_myname();
        }
 
-       mem_ctx = talloc_init("torture_bind_authcontext");
+       mem_ctx = talloc_init("torture_netlogon_samba3");
 
        if (mem_ctx == NULL) {
                d_printf("talloc_init failed\n");
@@ -1157,7 +1163,7 @@ BOOL torture_netlogon_samba3(struct torture_context *torture)
                goto done;
        }
 
-       cli_credentials_set_conf(wks_creds);
+       cli_credentials_set_conf(wks_creds, global_loadparm);
        cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA);
        cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
        cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
@@ -1224,7 +1230,7 @@ static BOOL test_join3(TALLOC_CTX *mem_ctx,
        struct cli_credentials *wks_creds;
 
        status = smbcli_full_connection(mem_ctx, &cli,
-                                       lp_parm_string(-1, "torture", "host"),
+                                       lp_parm_string(NULL, "torture", "host"),
                                        "IPC$", NULL, smb_creds, NULL);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("smbcli_full_connection failed: %s\n",
@@ -1238,7 +1244,7 @@ static BOOL test_join3(TALLOC_CTX *mem_ctx,
                goto done;
        }
 
-       cli_credentials_set_conf(wks_creds);
+       cli_credentials_set_conf(wks_creds, global_loadparm);
        cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA);
        cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
        cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
@@ -1363,7 +1369,7 @@ BOOL torture_samba3_sessionkey(struct torture_context *torture)
 static NTSTATUS pipe_bind_smb(TALLOC_CTX *mem_ctx,
                              struct smbcli_tree *tree,
                              const char *pipe_name,
-                             const struct dcerpc_interface_table *iface,
+                             const struct ndr_interface_table *iface,
                              struct dcerpc_pipe **p)
 {
        struct dcerpc_pipe *result;
@@ -1495,7 +1501,7 @@ static struct dom_sid *whoami(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree)
        struct dom_sid *result;
 
        status = pipe_bind_smb(mem_ctx, tree, "\\pipe\\lsarpc",
-                              &dcerpc_table_lsarpc, &lsa);
+                              &ndr_table_lsarpc, &lsa);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) Could not bind to LSA: %s\n",
                         __location__, nt_errstr(status));
@@ -1642,7 +1648,7 @@ BOOL torture_samba3_rpc_getusername(struct torture_context *torture)
                goto done;
        }
 
-       cli_credentials_set_conf(user_creds);
+       cli_credentials_set_conf(user_creds, global_loadparm);
        cli_credentials_set_username(user_creds, "torture_username",
                                     CRED_SPECIFIED);
        cli_credentials_set_password(user_creds,
@@ -1833,7 +1839,7 @@ BOOL torture_samba3_rpc_srvsvc(struct torture_context *torture)
        }
 
        status = pipe_bind_smb(mem_ctx, cli->tree, "\\pipe\\srvsvc",
-                              &dcerpc_table_srvsvc, &p);
+                              &ndr_table_srvsvc, &p);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) could not bind to srvsvc pipe: %s\n",
                         __location__, nt_errstr(status));
@@ -1876,7 +1882,7 @@ static struct security_descriptor *get_sharesec(TALLOC_CTX *mem_ctx,
        }
 
        status = pipe_bind_smb(mem_ctx, tree, "\\pipe\\srvsvc",
-                              &dcerpc_table_srvsvc, &p);
+                              &ndr_table_srvsvc, &p);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) could not bind to srvsvc pipe: %s\n",
                         __location__, nt_errstr(status));
@@ -1931,7 +1937,7 @@ static NTSTATUS set_sharesec(TALLOC_CTX *mem_ctx,
        }
 
        status = pipe_bind_smb(mem_ctx, tree, "\\pipe\\srvsvc",
-                              &dcerpc_table_srvsvc, &p);
+                              &ndr_table_srvsvc, &p);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) could not bind to srvsvc pipe: %s\n",
                         __location__, nt_errstr(status));
@@ -2121,7 +2127,7 @@ BOOL torture_samba3_rpc_lsa(struct torture_context *torture)
        }
 
        status = pipe_bind_smb(mem_ctx, cli->tree, "\\lsarpc",
-                              &dcerpc_table_lsarpc, &p);
+                              &ndr_table_lsarpc, &p);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
                         nt_errstr(status));
@@ -2218,7 +2224,7 @@ static NTSTATUS find_printers(TALLOC_CTX *ctx, struct smbcli_tree *tree,
                return NT_STATUS_NO_MEMORY;
        }
 
-       status = pipe_bind_smb(mem_ctx, tree, "\\srvsvc", &dcerpc_table_srvsvc,
+       status = pipe_bind_smb(mem_ctx, tree, "\\srvsvc", &ndr_table_srvsvc,
                               &p);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("could not bind to srvsvc pipe\n");
@@ -2287,7 +2293,7 @@ static BOOL enumprinters(TALLOC_CTX *mem_ctx, struct dcerpc_pipe *pipe,
                return False;
        }
 
-       blob = data_blob_talloc(mem_ctx, NULL, r.out.needed);
+       blob = data_blob_talloc_zero(mem_ctx, r.out.needed);
        if (blob.data == NULL) {
                d_printf("(%s) data_blob_talloc failed\n", __location__);
                return False;
@@ -2419,7 +2425,7 @@ BOOL torture_samba3_rpc_spoolss(struct torture_context *torture)
        }
 
        status = pipe_bind_smb(mem_ctx, cli->tree, "\\spoolss",
-                              &dcerpc_table_spoolss, &p);
+                              &ndr_table_spoolss, &p);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
                         nt_errstr(status));
@@ -2429,7 +2435,7 @@ BOOL torture_samba3_rpc_spoolss(struct torture_context *torture)
 
        ZERO_STRUCT(userlevel1);
        userlevel1.client = talloc_asprintf(
-               mem_ctx, "\\\\%s", lp_netbios_name());
+               mem_ctx, "\\\\%s", lp_netbios_name(global_loadparm));
        userlevel1.user = cli_credentials_get_username(cmdline_credentials);
        userlevel1.build = 2600;
        userlevel1.major = 3;
@@ -2593,7 +2599,7 @@ BOOL torture_samba3_rpc_wkssvc(struct torture_context *torture)
        }
 
        status = pipe_bind_smb(mem_ctx, cli->tree, "\\wkssvc",
-                              &dcerpc_table_wkssvc, &p);
+                              &ndr_table_wkssvc, &p);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
                         nt_errstr(status));
@@ -2819,7 +2825,7 @@ BOOL torture_samba3_rpc_winreg(struct torture_context *torture)
 
        mem_ctx = talloc_init("torture_rpc_winreg");
 
-       status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_winreg);
+       status = torture_rpc_connection(torture, &p, &ndr_table_winreg);
 
        if (!NT_STATUS_IS_OK(status)) {
                talloc_free(mem_ctx);