Remove more event_context_init() uses from function calls within deep down the code.
[bbaumbach/samba-autobuild/.git] / source4 / torture / rpc / samba3rpc.c
index 76df1a72c78e104b9cf3cb48b8c61faa62c34b28..40a7c156f41deb715fb75d90a77e5be33d6840b6 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 "libcli/raw/libcliraw.h"
+#include "libcli/raw/raw_proto.h"
 #include "libcli/rap/rap.h"
 #include "torture/torture.h"
 #include "torture/util.h"
 #include "libcli/composite/composite.h"
 #include "libcli/smb_composite/smb_composite.h"
 #include "libcli/auth/libcli_auth.h"
-#include "libcli/auth/credentials.h"
 #include "lib/crypto/crypto.h"
+#include "auth/ntlmssp/ntlmssp.h"
 #include "libcli/security/proto.h"
-
-static struct cli_credentials *create_anon_creds(TALLOC_CTX *mem_ctx)
-{
-       struct cli_credentials *result;
-
-       if (!(result = cli_credentials_init(mem_ctx))) {
-               return NULL;
-       }
-
-       cli_credentials_set_conf(result);
-       cli_credentials_set_anonymous(result);
-
-       return result;
-}
+#include "param/param.h"
+#include "lib/registry/registry.h"
+#include "libcli/resolve/resolve.h"
 
 /*
  * This tests a RPC call using an invalid vuid
  */
 
-BOOL torture_bind_authcontext(struct torture_context *torture) 
+bool torture_bind_authcontext(struct torture_context *torture) 
 {
        TALLOC_CTX *mem_ctx;
        NTSTATUS status;
-       BOOL ret = False;
+       bool ret = false;
        struct lsa_ObjectAttribute objectattr;
        struct lsa_OpenPolicy2 openpolicy;
        struct policy_handle handle;
@@ -84,38 +73,44 @@ BOOL torture_bind_authcontext(struct torture_context *torture)
        struct dcerpc_pipe *lsa_pipe;
        struct cli_credentials *anon_creds;
        struct smb_composite_sesssetup setup;
+       struct smbcli_options options;
 
        mem_ctx = talloc_init("torture_bind_authcontext");
 
        if (mem_ctx == NULL) {
                d_printf("talloc_init failed\n");
-               return False;
+               return false;
        }
 
+       lp_smbcli_options(torture->lp_ctx, &options);
+
        status = smbcli_full_connection(mem_ctx, &cli,
-                                       lp_parm_string(-1, "torture", "host"),
+                                       torture_setting_string(torture, "host", NULL),
+                                       lp_smb_ports(torture->lp_ctx),
                                        "IPC$", NULL, cmdline_credentials,
-                                       NULL);
+                                       lp_resolve_context(torture->lp_ctx),
+                                       torture->ev, &options);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("smbcli_full_connection failed: %s\n",
                         nt_errstr(status));
                goto done;
        }
 
-       lsa_pipe = dcerpc_pipe_init(mem_ctx, cli->transport->socket->event.ctx);
+       lsa_pipe = dcerpc_pipe_init(mem_ctx, cli->transport->socket->event.ctx,
+                                   lp_iconv_convenience(torture->lp_ctx));
        if (lsa_pipe == NULL) {
                d_printf("dcerpc_pipe_init failed\n");
                goto done;
        }
 
-       status = dcerpc_pipe_open_smb(lsa_pipe->conn, cli->tree, "\\lsarpc");
+       status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("dcerpc_pipe_open_smb failed: %s\n",
                         nt_errstr(status));
                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));
@@ -147,13 +142,13 @@ BOOL torture_bind_authcontext(struct torture_context *torture)
                goto done;
        }
 
-       session2 = smbcli_session_init(cli->transport, mem_ctx, False);
+       session2 = smbcli_session_init(cli->transport, mem_ctx, false);
        if (session2 == NULL) {
                d_printf("smbcli_session_init failed\n");
                goto done;
        }
 
-       if (!(anon_creds = create_anon_creds(mem_ctx))) {
+       if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
                d_printf("create_anon_creds failed\n");
                goto done;
        }
@@ -169,6 +164,7 @@ BOOL torture_bind_authcontext(struct torture_context *torture)
                         nt_errstr(status));
                goto done;
        }
+       session2->vuid = setup.out.vuid;
 
        tmp = cli->tree->session;
        cli->tree->session = session2;
@@ -186,7 +182,7 @@ BOOL torture_bind_authcontext(struct torture_context *torture)
                goto done;
        }
 
-       ret = True;
+       ret = true;
  done:
        talloc_free(mem_ctx);
        return ret;
@@ -196,12 +192,13 @@ BOOL torture_bind_authcontext(struct torture_context *torture)
  * Bind to lsa using a specific auth method
  */
 
-static BOOL bindtest(struct smbcli_state *cli,
+static bool bindtest(struct smbcli_state *cli,
                     struct cli_credentials *credentials,
+                    struct loadparm_context *lp_ctx,
                     uint8_t auth_type, uint8_t auth_level)
 {
        TALLOC_CTX *mem_ctx;
-       BOOL ret = False;
+       bool ret = false;
        NTSTATUS status;
 
        struct dcerpc_pipe *lsa_pipe;
@@ -213,25 +210,26 @@ static BOOL bindtest(struct smbcli_state *cli,
 
        if ((mem_ctx = talloc_init("bindtest")) == NULL) {
                d_printf("talloc_init failed\n");
-               return False;
+               return false;
        }
 
        lsa_pipe = dcerpc_pipe_init(mem_ctx,
-                                   cli->transport->socket->event.ctx);
+                                   cli->transport->socket->event.ctx,
+                                   lp_iconv_convenience(lp_ctx));
        if (lsa_pipe == NULL) {
                d_printf("dcerpc_pipe_init failed\n");
                goto done;
        }
 
-       status = dcerpc_pipe_open_smb(lsa_pipe->conn, cli->tree, "\\lsarpc");
+       status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("dcerpc_pipe_open_smb failed: %s\n",
                         nt_errstr(status));
                goto done;
        }
 
-       status = dcerpc_bind_auth(lsa_pipe, &dcerpc_table_lsarpc,
-                                 credentials, auth_type, auth_level,
+       status = dcerpc_bind_auth(lsa_pipe, &ndr_table_lsarpc,
+                                 credentials, lp_ctx, auth_type, auth_level,
                                  NULL);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("dcerpc_bind_auth failed: %s\n", nt_errstr(status));
@@ -273,7 +271,7 @@ static BOOL bindtest(struct smbcli_state *cli,
                goto done;
        }
 
-       ret = True;
+       ret = true;
  done:
        talloc_free(mem_ctx);
        return ret;
@@ -283,39 +281,44 @@ static BOOL bindtest(struct smbcli_state *cli,
  * test authenticated RPC binds with the variants Samba3 does support
  */
 
-BOOL torture_bind_samba3(struct torture_context *torture) 
+bool torture_bind_samba3(struct torture_context *torture) 
 {
        TALLOC_CTX *mem_ctx;
        NTSTATUS status;
-       BOOL ret = False;
+       bool ret = false;
        struct smbcli_state *cli;
+       struct smbcli_options options;
 
        mem_ctx = talloc_init("torture_bind_authcontext");
 
        if (mem_ctx == NULL) {
                d_printf("talloc_init failed\n");
-               return False;
+               return false;
        }
 
+       lp_smbcli_options(torture->lp_ctx, &options);
+
        status = smbcli_full_connection(mem_ctx, &cli,
-                                       lp_parm_string(-1, "torture", "host"),
+                                       torture_setting_string(torture, "host", NULL),
+                                       lp_smb_ports(torture->lp_ctx),
                                        "IPC$", NULL, cmdline_credentials,
-                                       NULL);
+                                       lp_resolve_context(torture->lp_ctx),
+                                       torture->ev, &options);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("smbcli_full_connection failed: %s\n",
                         nt_errstr(status));
                goto done;
        }
 
-       ret = True;
+       ret = true;
 
-       ret &= bindtest(cli, cmdline_credentials, DCERPC_AUTH_TYPE_NTLMSSP,
+       ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_NTLMSSP,
                        DCERPC_AUTH_LEVEL_INTEGRITY);
-       ret &= bindtest(cli, cmdline_credentials, DCERPC_AUTH_TYPE_NTLMSSP,
+       ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_NTLMSSP,
                        DCERPC_AUTH_LEVEL_PRIVACY);
-       ret &= bindtest(cli, cmdline_credentials, DCERPC_AUTH_TYPE_SPNEGO,
+       ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_SPNEGO,
                        DCERPC_AUTH_LEVEL_INTEGRITY);
-       ret &= bindtest(cli, cmdline_credentials, DCERPC_AUTH_TYPE_SPNEGO,
+       ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_SPNEGO,
                        DCERPC_AUTH_LEVEL_PRIVACY);
 
  done:
@@ -329,6 +332,7 @@ BOOL torture_bind_samba3(struct torture_context *torture)
 
 static NTSTATUS get_usr_handle(struct smbcli_state *cli,
                               TALLOC_CTX *mem_ctx,
+                              struct loadparm_context *lp_ctx,
                               struct cli_credentials *admin_creds,
                               uint8_t auth_type,
                               uint8_t auth_level,
@@ -355,14 +359,15 @@ static NTSTATUS get_usr_handle(struct smbcli_state *cli,
        uint32_t user_rid,access_granted;
 
        samr_pipe = dcerpc_pipe_init(mem_ctx,
-                                    cli->transport->socket->event.ctx);
+                                    cli->transport->socket->event.ctx,
+                                    lp_iconv_convenience(lp_ctx));
        if (samr_pipe == NULL) {
                d_printf("dcerpc_pipe_init failed\n");
                status = NT_STATUS_NO_MEMORY;
                goto fail;
        }
 
-       status = dcerpc_pipe_open_smb(samr_pipe->conn, cli->tree, "\\samr");
+       status = dcerpc_pipe_open_smb(samr_pipe, cli->tree, "\\samr");
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("dcerpc_pipe_open_smb failed: %s\n",
                         nt_errstr(status));
@@ -370,8 +375,8 @@ static NTSTATUS get_usr_handle(struct smbcli_state *cli,
        }
 
        if (admin_creds != NULL) {
-               status = dcerpc_bind_auth(samr_pipe, &dcerpc_table_samr,
-                                         admin_creds, auth_type, auth_level,
+               status = dcerpc_bind_auth(samr_pipe, &ndr_table_samr,
+                                         admin_creds, lp_ctx, auth_type, auth_level,
                                          NULL);
                if (!NT_STATUS_IS_OK(status)) {
                        d_printf("dcerpc_bind_auth failed: %s\n",
@@ -380,7 +385,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));
@@ -502,7 +507,8 @@ static NTSTATUS get_usr_handle(struct smbcli_state *cli,
  * Create a test user
  */
 
-static BOOL create_user(TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
+static bool create_user(TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
+                       struct loadparm_context *lp_ctx,
                        struct cli_credentials *admin_creds,
                        const char *username, const char *password,
                        char **domain_name,
@@ -512,20 +518,20 @@ static BOOL create_user(TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
        NTSTATUS status;
        struct dcerpc_pipe *samr_pipe;
        struct policy_handle *wks_handle;
-       BOOL ret = False;
+       bool ret = false;
 
        if (!(tmp_ctx = talloc_new(mem_ctx))) {
                d_printf("talloc_init failed\n");
-               return False;
+               return false;
        }
 
-       status = get_usr_handle(cli, tmp_ctx, admin_creds,
+       status = get_usr_handle(cli, tmp_ctx, lp_ctx, admin_creds,
                                DCERPC_AUTH_TYPE_NTLMSSP,
                                DCERPC_AUTH_LEVEL_INTEGRITY,
                                username, domain_name, &samr_pipe, &wks_handle,
                                user_sid);
        if (!NT_STATUS_IS_OK(status)) {
-               d_printf("get_wks_handle failed: %s\n", nt_errstr(status));
+               d_printf("get_usr_handle failed: %s\n", nt_errstr(status));
                goto done;
        }
 
@@ -536,24 +542,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 +593,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;
@@ -598,7 +610,7 @@ static BOOL create_user(TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
 
        *domain_name= talloc_steal(mem_ctx, *domain_name);
        *user_sid = talloc_steal(mem_ctx, *user_sid);
-       ret = True;
+       ret = true;
  done:
        talloc_free(tmp_ctx);
        return ret;
@@ -608,7 +620,8 @@ static BOOL create_user(TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
  * Delete a test user
  */
 
-static BOOL delete_user(struct smbcli_state *cli,
+static bool delete_user(struct smbcli_state *cli,
+                       struct loadparm_context *lp_ctx,
                        struct cli_credentials *admin_creds,
                        const char *username)
 {
@@ -617,14 +630,14 @@ static BOOL delete_user(struct smbcli_state *cli,
        char *dom_name;
        struct dcerpc_pipe *samr_pipe;
        struct policy_handle *user_handle;
-       BOOL ret = False;
+       bool ret = false;
 
        if ((mem_ctx = talloc_init("leave")) == NULL) {
                d_printf("talloc_init failed\n");
-               return False;
+               return false;
        }
 
-       status = get_usr_handle(cli, mem_ctx, admin_creds,
+       status = get_usr_handle(cli, mem_ctx, lp_ctx, admin_creds,
                                DCERPC_AUTH_TYPE_NTLMSSP,
                                DCERPC_AUTH_LEVEL_INTEGRITY,
                                username, &dom_name, &samr_pipe,
@@ -643,12 +656,12 @@ static BOOL delete_user(struct smbcli_state *cli,
 
                status = dcerpc_samr_DeleteUser(samr_pipe, mem_ctx, &d);
                if (!NT_STATUS_IS_OK(status)) {
-                       d_printf("samr_DeleteUser failed\n");
+                       d_printf("samr_DeleteUser failed %s\n", nt_errstr(status));
                        goto done;
                }
        }
 
-       ret = True;
+       ret = true;
 
  done:
        talloc_free(mem_ctx);
@@ -659,8 +672,9 @@ static BOOL delete_user(struct smbcli_state *cli,
  * Do a Samba3-style join
  */
 
-static BOOL join3(struct smbcli_state *cli,
-                 BOOL use_level25,
+static bool join3(struct smbcli_state *cli,
+                 struct loadparm_context *lp_ctx,
+                 bool use_level25,
                  struct cli_credentials *admin_creds,
                  struct cli_credentials *wks_creds)
 {
@@ -669,15 +683,16 @@ static BOOL join3(struct smbcli_state *cli,
        char *dom_name;
        struct dcerpc_pipe *samr_pipe;
        struct policy_handle *wks_handle;
-       BOOL ret = False;
+       bool ret = false;
+       NTTIME last_password_change;
 
        if ((mem_ctx = talloc_init("join3")) == NULL) {
                d_printf("talloc_init failed\n");
-               return False;
+               return false;
        }
 
        status = get_usr_handle(
-               cli, mem_ctx, admin_creds,
+               cli, mem_ctx, lp_ctx, admin_creds,
                DCERPC_AUTH_TYPE_NTLMSSP,
                DCERPC_AUTH_LEVEL_PRIVACY,
                talloc_asprintf(mem_ctx, "%s$",
@@ -689,6 +704,22 @@ static BOOL join3(struct smbcli_state *cli,
                goto done;
        }
 
+       {
+               struct samr_QueryUserInfo q;
+
+               q.in.user_handle = wks_handle;
+               q.in.level = 21;
+
+               status = dcerpc_samr_QueryUserInfo(samr_pipe, mem_ctx, &q);
+               if (!NT_STATUS_IS_OK(status)) {
+                       d_printf("(%s) QueryUserInfo failed: %s\n",
+                                 __location__, nt_errstr(status));
+                       goto done;
+               }
+
+               last_password_change = q.out.info->info21.last_password_change;
+       }
+
        cli_credentials_set_domain(wks_creds, dom_name, CRED_SPECIFIED);
 
        if (use_level25) {
@@ -782,7 +813,40 @@ static BOOL join3(struct smbcli_state *cli,
                }
        }
 
-       ret = True;
+       {
+               struct samr_QueryUserInfo q;
+
+               q.in.user_handle = wks_handle;
+               q.in.level = 21;
+
+               status = dcerpc_samr_QueryUserInfo(samr_pipe, mem_ctx, &q);
+               if (!NT_STATUS_IS_OK(status)) {
+                       d_printf("(%s) QueryUserInfo failed: %s\n",
+                                 __location__, nt_errstr(status));
+                       goto done;
+               }
+
+               if (use_level25) {
+                       if (last_password_change
+                           == q.out.info->info21.last_password_change) {
+                               d_printf("(%s) last_password_change unchanged "
+                                        "during join, level25 must change "
+                                        "it\n", __location__);
+                               goto done;
+                       }
+               }
+               else {
+                       if (last_password_change
+                           != q.out.info->info21.last_password_change) {
+                               d_printf("(%s) last_password_change changed "
+                                        "during join, level24 doesn't "
+                                        "change it\n", __location__);
+                               goto done;
+                       }
+               }
+       }
+
+       ret = true;
 
  done:
        talloc_free(mem_ctx);
@@ -793,12 +857,13 @@ static BOOL join3(struct smbcli_state *cli,
  * Do a ReqChallenge/Auth2 and get the wks creds
  */
 
-static BOOL auth2(struct smbcli_state *cli,
+static bool auth2(struct smbcli_state *cli,
+                 struct loadparm_context *lp_ctx,
                  struct cli_credentials *wks_cred)
 {
        TALLOC_CTX *mem_ctx;
        struct dcerpc_pipe *net_pipe;
-       BOOL result = False;
+       bool result = false;
        NTSTATUS status;
        struct netr_ServerReqChallenge r;
        struct netr_Credential netr_cli_creds;
@@ -812,24 +877,25 @@ static BOOL auth2(struct smbcli_state *cli,
        mem_ctx = talloc_new(NULL);
        if (mem_ctx == NULL) {
                d_printf("talloc_new failed\n");
-               return False;
+               return false;
        }
 
        net_pipe = dcerpc_pipe_init(mem_ctx,
-                                   cli->transport->socket->event.ctx);
+                                   cli->transport->socket->event.ctx,
+                                   lp_iconv_convenience(lp_ctx));
        if (net_pipe == NULL) {
                d_printf("dcerpc_pipe_init failed\n");
                goto done;
        }
 
-       status = dcerpc_pipe_open_smb(net_pipe->conn, cli->tree, "\\netlogon");
+       status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("dcerpc_pipe_open_smb failed: %s\n",
                         nt_errstr(status));
                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));
@@ -888,7 +954,7 @@ static BOOL auth2(struct smbcli_state *cli,
 
        cli_credentials_set_netlogon_creds(wks_cred, creds_state);
 
-       result = True;
+       result = true;
 
  done:
        talloc_free(mem_ctx);
@@ -900,30 +966,32 @@ static BOOL auth2(struct smbcli_state *cli,
  * login, and change the wks password
  */
 
-static BOOL schan(struct smbcli_state *cli,
+static bool schan(struct smbcli_state *cli,
+                 struct loadparm_context *lp_ctx,
                  struct cli_credentials *wks_creds,
                  struct cli_credentials *user_creds)
 {
        TALLOC_CTX *mem_ctx;
        NTSTATUS status;
-       BOOL ret = False;
+       bool ret = false;
        struct dcerpc_pipe *net_pipe;
        int i;
        
        mem_ctx = talloc_new(NULL);
        if (mem_ctx == NULL) {
                d_printf("talloc_new failed\n");
-               return False;
+               return false;
        }
 
        net_pipe = dcerpc_pipe_init(mem_ctx,
-                                   cli->transport->socket->event.ctx);
+                                   cli->transport->socket->event.ctx,
+                                   lp_iconv_convenience(lp_ctx));
        if (net_pipe == NULL) {
                d_printf("dcerpc_pipe_init failed\n");
                goto done;
        }
 
-       status = dcerpc_pipe_open_smb(net_pipe->conn, cli->tree, "\\netlogon");
+       status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("dcerpc_pipe_open_smb failed: %s\n",
                         nt_errstr(status));
@@ -936,12 +1004,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,
-                                 wks_creds, DCERPC_AUTH_TYPE_SCHANNEL,
+       status = dcerpc_bind_auth(net_pipe, &ndr_table_netlogon,
+                                 wks_creds, lp_ctx, 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));
@@ -969,7 +1037,8 @@ static BOOL schan(struct smbcli_state *cli,
 
                generate_random_buffer(chal.data, chal.length);
                names_blob = NTLMv2_generate_names_blob(
-                       mem_ctx, cli_credentials_get_workstation(user_creds),
+                       mem_ctx, lp_iconv_convenience(lp_ctx), 
+                       cli_credentials_get_workstation(user_creds),
                        cli_credentials_get_domain(user_creds));
                status = cli_credentials_get_ntlm_response(
                        user_creds, mem_ctx, &flags, chal, names_blob,
@@ -1087,7 +1156,7 @@ static BOOL schan(struct smbcli_state *cli,
                                             CRED_SPECIFIED);
        }
 
-       ret = True;
+       ret = true;
  done:
        talloc_free(mem_ctx);
        return ret;
@@ -1097,15 +1166,16 @@ static BOOL schan(struct smbcli_state *cli,
  * Delete the wks account again
  */
 
-static BOOL leave(struct smbcli_state *cli,
+static bool leave(struct smbcli_state *cli,
+                 struct loadparm_context *lp_ctx,
                  struct cli_credentials *admin_creds,
                  struct cli_credentials *wks_creds)
 {
        char *wks_name = talloc_asprintf(
                NULL, "%s$", cli_credentials_get_workstation(wks_creds));
-       BOOL ret;
+       bool ret;
 
-       ret = delete_user(cli, admin_creds, wks_name);
+       ret = delete_user(cli, lp_ctx, admin_creds, wks_name);
        talloc_free(wks_name);
        return ret;
 }
@@ -1114,37 +1184,43 @@ static BOOL leave(struct smbcli_state *cli,
  * Test the Samba3 DC code a bit. Join, do some schan netlogon ops, leave
  */
 
-BOOL torture_netlogon_samba3(struct torture_context *torture)
+bool torture_netlogon_samba3(struct torture_context *torture)
 {
        TALLOC_CTX *mem_ctx;
        NTSTATUS status;
-       BOOL ret = False;
+       bool ret = false;
        struct smbcli_state *cli;
        struct cli_credentials *anon_creds;
        struct cli_credentials *wks_creds;
        const char *wks_name;
        int i;
+       struct smbcli_options options;
 
-       wks_name = lp_parm_string(-1, "torture", "wksname");
+       wks_name = torture_setting_string(torture, "wksname", NULL);
        if (wks_name == NULL) {
                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");
-               return False;
+               return false;
        }
 
-       if (!(anon_creds = create_anon_creds(mem_ctx))) {
+       if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
                d_printf("create_anon_creds failed\n");
                goto done;
        }
 
+       lp_smbcli_options(torture->lp_ctx, &options);
+
        status = smbcli_full_connection(mem_ctx, &cli,
-                                       lp_parm_string(-1, "torture", "host"),
-                                       "IPC$", NULL, anon_creds, NULL);
+                                       torture_setting_string(torture, "host", NULL),
+                                       lp_smb_ports(torture->lp_ctx),
+                                       "IPC$", NULL, anon_creds, 
+                                       lp_resolve_context(torture->lp_ctx),
+                                       torture->ev, &options);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("smbcli_full_connection failed: %s\n",
                         nt_errstr(status));
@@ -1157,7 +1233,7 @@ BOOL torture_netlogon_samba3(struct torture_context *torture)
                goto done;
        }
 
-       cli_credentials_set_conf(wks_creds);
+       cli_credentials_set_conf(wks_creds, torture->lp_ctx);
        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);
@@ -1165,7 +1241,7 @@ BOOL torture_netlogon_samba3(struct torture_context *torture)
                                     generate_random_str(wks_creds, 8),
                                     CRED_SPECIFIED);
 
-       if (!join3(cli, False, cmdline_credentials, wks_creds)) {
+       if (!join3(cli, torture->lp_ctx, false, cmdline_credentials, wks_creds)) {
                d_printf("join failed\n");
                goto done;
        }
@@ -1182,25 +1258,25 @@ BOOL torture_netlogon_samba3(struct torture_context *torture)
 
                int j;
 
-               if (!auth2(cli, wks_creds)) {
+               if (!auth2(cli, torture->lp_ctx, wks_creds)) {
                        d_printf("auth2 failed\n");
                        goto done;
                }
 
                for (j=0; j<2; j++) {
-                       if (!schan(cli, wks_creds, cmdline_credentials)) {
+                       if (!schan(cli, torture->lp_ctx, wks_creds, cmdline_credentials)) {
                                d_printf("schan failed\n");
                                goto done;
                        }
                }
        }
 
-       if (!leave(cli, cmdline_credentials, wks_creds)) {
+       if (!leave(cli, torture->lp_ctx, cmdline_credentials, wks_creds)) {
                d_printf("leave failed\n");
                goto done;
        }
 
-       ret = True;
+       ret = true;
 
  done:
        talloc_free(mem_ctx);
@@ -1212,20 +1288,26 @@ BOOL torture_netlogon_samba3(struct torture_context *torture)
  * credentials
  */
 
-static BOOL test_join3(TALLOC_CTX *mem_ctx,
-                      BOOL use_level25,
+static bool test_join3(struct torture_context *tctx,
+                      bool use_level25,
                       struct cli_credentials *smb_creds,
                       struct cli_credentials *samr_creds,
                       const char *wks_name)
 {
        NTSTATUS status;
-       BOOL ret = False;
+       bool ret = false;
        struct smbcli_state *cli;
        struct cli_credentials *wks_creds;
+       struct smbcli_options options;
 
-       status = smbcli_full_connection(mem_ctx, &cli,
-                                       lp_parm_string(-1, "torture", "host"),
-                                       "IPC$", NULL, smb_creds, NULL);
+       lp_smbcli_options(tctx->lp_ctx, &options);
+
+       status = smbcli_full_connection(tctx, &cli,
+                                       torture_setting_string(tctx, "host", NULL),
+                                       lp_smb_ports(tctx->lp_ctx),
+                                       "IPC$", NULL, smb_creds, 
+                                       lp_resolve_context(tctx->lp_ctx),
+                                       tctx->ev, &options);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("smbcli_full_connection failed: %s\n",
                         nt_errstr(status));
@@ -1238,7 +1320,7 @@ static BOOL test_join3(TALLOC_CTX *mem_ctx,
                goto done;
        }
 
-       cli_credentials_set_conf(wks_creds);
+       cli_credentials_set_conf(wks_creds, tctx->lp_ctx);
        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);
@@ -1246,7 +1328,7 @@ static BOOL test_join3(TALLOC_CTX *mem_ctx,
                                     generate_random_str(wks_creds, 8),
                                     CRED_SPECIFIED);
 
-       if (!join3(cli, use_level25, samr_creds, wks_creds)) {
+       if (!join3(cli, tctx->lp_ctx, use_level25, samr_creds, wks_creds)) {
                d_printf("join failed\n");
                goto done;
        }
@@ -1255,19 +1337,19 @@ static BOOL test_join3(TALLOC_CTX *mem_ctx,
                cmdline_credentials, cli_credentials_get_domain(wks_creds),
                CRED_SPECIFIED);
 
-       if (!auth2(cli, wks_creds)) {
+       if (!auth2(cli, tctx->lp_ctx, wks_creds)) {
                d_printf("auth2 failed\n");
                goto done;
        }
 
-       if (!leave(cli, samr_creds, wks_creds)) {
+       if (!leave(cli, tctx->lp_ctx, samr_creds, wks_creds)) {
                d_printf("leave failed\n");
                goto done;
        }
 
        talloc_free(cli);
 
-       ret = True;
+       ret = true;
 
  done:
        return ret;
@@ -1278,80 +1360,71 @@ static BOOL test_join3(TALLOC_CTX *mem_ctx,
  * session key in the setpassword routine. Test the join by doing the auth2.
  */
 
-BOOL torture_samba3_sessionkey(struct torture_context *torture)
+bool torture_samba3_sessionkey(struct torture_context *torture)
 {
-       TALLOC_CTX *mem_ctx;
-       BOOL ret = False;
+       bool ret = false;
        struct cli_credentials *anon_creds;
        const char *wks_name;
 
-       wks_name = lp_parm_string(-1, "torture", "wksname");
-       if (wks_name == NULL) {
-               wks_name = get_myname();
-       }
-
-       mem_ctx = talloc_init("torture_samba3_sessionkey");
+       wks_name = torture_setting_string(torture, "wksname", get_myname());
 
-       if (mem_ctx == NULL) {
-               d_printf("talloc_init failed\n");
-               return False;
-       }
-
-       if (!(anon_creds = create_anon_creds(mem_ctx))) {
+       if (!(anon_creds = cli_credentials_init_anon(torture))) {
                d_printf("create_anon_creds failed\n");
                goto done;
        }
 
-       ret = True;
+       cli_credentials_set_workstation(anon_creds, wks_name, CRED_SPECIFIED);
+
+       ret = true;
 
-       if (!lp_parm_bool(-1, "target", "samba3", False)) {
+       if (!torture_setting_bool(torture, "samba3", false)) {
 
                /* Samba3 in the build farm right now does this happily. Need
                 * to fix :-) */
 
-               if (test_join3(mem_ctx, False, anon_creds, NULL, wks_name)) {
+               if (test_join3(torture, false, anon_creds, NULL, wks_name)) {
                        d_printf("join using anonymous bind on an anonymous smb "
                                 "connection succeeded -- HUH??\n");
-                       ret = False;
+                       ret = false;
                }
        }
 
-       if (!test_join3(mem_ctx, False, anon_creds, cmdline_credentials,
+       if (!test_join3(torture, false, anon_creds, cmdline_credentials,
                        wks_name)) {
                d_printf("join using ntlmssp bind on an anonymous smb "
                         "connection failed\n");
-               ret = False;
+               ret = false;
        }
 
-       if (!test_join3(mem_ctx, False, cmdline_credentials, NULL, wks_name)) {
+       if (!test_join3(torture, false, cmdline_credentials, NULL, wks_name)) {
                d_printf("join using anonymous bind on an authenticated smb "
                         "connection failed\n");
-               ret = False;
+               ret = false;
        }
 
-       if (!test_join3(mem_ctx, False, cmdline_credentials,
+       if (!test_join3(torture, false, cmdline_credentials,
                        cmdline_credentials,
                        wks_name)) {
                d_printf("join using ntlmssp bind on an authenticated smb "
                         "connection failed\n");
-               ret = False;
+               ret = false;
        }
 
        /*
         * The following two are tests for setuserinfolevel 25
         */
 
-       if (!test_join3(mem_ctx, True, anon_creds, cmdline_credentials,
+       if (!test_join3(torture, true, anon_creds, cmdline_credentials,
                        wks_name)) {
                d_printf("join using ntlmssp bind on an anonymous smb "
                         "connection failed\n");
-               ret = False;
+               ret = false;
        }
 
-       if (!test_join3(mem_ctx, True, cmdline_credentials, NULL, wks_name)) {
+       if (!test_join3(torture, true, cmdline_credentials, NULL, wks_name)) {
                d_printf("join using anonymous bind on an authenticated smb "
                         "connection failed\n");
-               ret = False;
+               ret = false;
        }
 
  done:
@@ -1364,20 +1437,22 @@ BOOL torture_samba3_sessionkey(struct torture_context *torture)
  */
 
 static NTSTATUS pipe_bind_smb(TALLOC_CTX *mem_ctx,
+                             struct loadparm_context *lp_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;
        NTSTATUS status;
 
        if (!(result = dcerpc_pipe_init(
-                     mem_ctx, tree->session->transport->socket->event.ctx))) {
+                     mem_ctx, tree->session->transport->socket->event.ctx, 
+                     lp_iconv_convenience(lp_ctx)))) {
                return NT_STATUS_NO_MEMORY;
        }
 
-       status = dcerpc_pipe_open_smb(result->conn, tree, pipe_name);
+       status = dcerpc_pipe_open_smb(result, tree, pipe_name);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("dcerpc_pipe_open_smb failed: %s\n",
                         nt_errstr(status));
@@ -1462,7 +1537,8 @@ static struct dom_sid *name2sid(TALLOC_CTX *mem_ctx,
 
        status = dcerpc_lsa_LookupNames(p, tmp_ctx, &l);
        if (!NT_STATUS_IS_OK(status)) {
-               printf("LookupNames failed - %s\n", nt_errstr(status));
+               printf("LookupNames of %s failed - %s\n", lsa_name.string, 
+                      nt_errstr(status));
                talloc_free(tmp_ctx);
                return NULL;
        }
@@ -1488,7 +1564,9 @@ static struct dom_sid *name2sid(TALLOC_CTX *mem_ctx,
  * Find out the user SID on this connection
  */
 
-static struct dom_sid *whoami(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree)
+static struct dom_sid *whoami(TALLOC_CTX *mem_ctx, 
+                             struct loadparm_context *lp_ctx, 
+                             struct smbcli_tree *tree)
 {
        struct dcerpc_pipe *lsa;
        struct lsa_GetUserName r;
@@ -1496,8 +1574,8 @@ static struct dom_sid *whoami(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree)
        struct lsa_StringPointer authority_name_p;
        struct dom_sid *result;
 
-       status = pipe_bind_smb(mem_ctx, tree, "\\pipe\\lsarpc",
-                              &dcerpc_table_lsarpc, &lsa);
+       status = pipe_bind_smb(mem_ctx, lp_ctx, tree, "\\pipe\\lsarpc",
+                              &ndr_table_lsarpc, &lsa);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) Could not bind to LSA: %s\n",
                         __location__, nt_errstr(status));
@@ -1525,6 +1603,12 @@ static struct dom_sid *whoami(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree)
        return result;
 }
 
+static int destroy_tree(struct smbcli_tree *tree)
+{
+       smb_tree_disconnect(tree);
+       return 0;
+}
+
 /*
  * Do a tcon, given a session
  */
@@ -1543,7 +1627,7 @@ NTSTATUS secondary_tcon(TALLOC_CTX *mem_ctx,
                return NT_STATUS_NO_MEMORY;
        }
 
-       if (!(result = smbcli_tree_init(session, mem_ctx, False))) {
+       if (!(result = smbcli_tree_init(session, mem_ctx, false))) {
                talloc_free(tmp_ctx);
                return NT_STATUS_NO_MEMORY;
        }
@@ -1564,6 +1648,7 @@ NTSTATUS secondary_tcon(TALLOC_CTX *mem_ctx,
 
        result->tid = tcon.tconx.out.tid;
        result = talloc_steal(mem_ctx, result);
+       talloc_set_destructor(result, destroy_tree);
        talloc_free(tmp_ctx);
        *res = result;
        return NT_STATUS_OK;
@@ -1573,60 +1658,69 @@ NTSTATUS secondary_tcon(TALLOC_CTX *mem_ctx,
  * Test the getusername behaviour
  */
 
-BOOL torture_samba3_rpc_getusername(struct torture_context *torture)
+bool torture_samba3_rpc_getusername(struct torture_context *torture)
 {
        NTSTATUS status;
        struct smbcli_state *cli;
        TALLOC_CTX *mem_ctx;
-       BOOL ret = True;
+       bool ret = true;
        struct dom_sid *user_sid;
        struct dom_sid *created_sid;
        struct cli_credentials *anon_creds;
        struct cli_credentials *user_creds;
        char *domain_name;
+       struct smbcli_options options;
 
        if (!(mem_ctx = talloc_new(torture))) {
-               return False;
+               return false;
        }
 
+       lp_smbcli_options(torture->lp_ctx, &options);
+
        status = smbcli_full_connection(
-               mem_ctx, &cli, lp_parm_string(-1, "torture", "host"),
-               "IPC$", NULL, cmdline_credentials, NULL);
+               mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
+               lp_smb_ports(torture->lp_ctx),
+               "IPC$", NULL, cmdline_credentials, 
+               lp_resolve_context(torture->lp_ctx),
+               torture->ev, &options);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) smbcli_full_connection failed: %s\n",
                         __location__, nt_errstr(status));
-               ret = False;
+               ret = false;
                goto done;
        }
 
-       if (!(user_sid = whoami(mem_ctx, cli->tree))) {
+       if (!(user_sid = whoami(mem_ctx, torture->lp_ctx, cli->tree))) {
                d_printf("(%s) whoami on auth'ed connection failed\n",
                         __location__);
-               ret = False;
+               ret = false;
        }
 
        talloc_free(cli);
 
-       if (!(anon_creds = create_anon_creds(mem_ctx))) {
+       if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
                d_printf("(%s) create_anon_creds failed\n", __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
        status = smbcli_full_connection(
-               mem_ctx, &cli, lp_parm_string(-1, "torture", "host"),
-               "IPC$", NULL, anon_creds, NULL);
+               mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
+               lp_smb_ports(torture->lp_ctx),
+               "IPC$", NULL, anon_creds, 
+               lp_resolve_context(torture->lp_ctx),
+               torture->ev, &options);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) anon smbcli_full_connection failed: %s\n",
                         __location__, nt_errstr(status));
-               ret = False;
+               ret = false;
                goto done;
        }
 
-       if (!(user_sid = whoami(mem_ctx, cli->tree))) {
+       if (!(user_sid = whoami(mem_ctx, torture->lp_ctx, cli->tree))) {
                d_printf("(%s) whoami on anon connection failed\n",
                         __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -1635,28 +1729,28 @@ BOOL torture_samba3_rpc_getusername(struct torture_context *torture)
                d_printf("(%s) Anon lsa_GetUserName returned %s, expected "
                         "S-1-5-7", __location__,
                         dom_sid_string(mem_ctx, user_sid));
-               ret = False;
+               ret = false;
        }
 
        if (!(user_creds = cli_credentials_init(mem_ctx))) {
                d_printf("(%s) cli_credentials_init failed\n", __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
-       cli_credentials_set_conf(user_creds);
+       cli_credentials_set_conf(user_creds, torture->lp_ctx);
        cli_credentials_set_username(user_creds, "torture_username",
                                     CRED_SPECIFIED);
        cli_credentials_set_password(user_creds,
                                     generate_random_str(user_creds, 8),
                                     CRED_SPECIFIED);
 
-       if (!create_user(mem_ctx, cli, cmdline_credentials,
+       if (!create_user(mem_ctx, cli, torture->lp_ctx, cmdline_credentials,
                         cli_credentials_get_username(user_creds),
                         cli_credentials_get_password(user_creds),
                         &domain_name, &created_sid)) {
                d_printf("(%s) create_user failed\n", __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -1668,7 +1762,7 @@ BOOL torture_samba3_rpc_getusername(struct torture_context *torture)
                struct smb_composite_sesssetup setup;
                struct smbcli_tree *tree;
 
-               session2 = smbcli_session_init(cli->transport, mem_ctx, False);
+               session2 = smbcli_session_init(cli->transport, mem_ctx, false);
                if (session2 == NULL) {
                        d_printf("(%s) smbcli_session_init failed\n",
                                 __location__);
@@ -1684,22 +1778,23 @@ BOOL torture_samba3_rpc_getusername(struct torture_context *torture)
                if (!NT_STATUS_IS_OK(status)) {
                        d_printf("(%s) session setup with new user failed: "
                                 "%s\n", __location__, nt_errstr(status));
-                       ret = False;
+                       ret = false;
                        goto done;
                }
+               session2->vuid = setup.out.vuid;
 
                if (!NT_STATUS_IS_OK(secondary_tcon(mem_ctx, session2,
                                                    "IPC$", &tree))) {
                        d_printf("(%s) secondary_tcon failed\n",
                                 __location__);
-                       ret = False;
+                       ret = false;
                        goto done;
                }
 
-               if (!(user_sid = whoami(mem_ctx, tree))) {
+               if (!(user_sid = whoami(mem_ctx, torture->lp_ctx, tree))) {
                        d_printf("(%s) whoami on user connection failed\n",
                                 __location__);
-                       ret = False;
+                       ret = false;
                        goto delete;
                }
 
@@ -1711,14 +1806,15 @@ BOOL torture_samba3_rpc_getusername(struct torture_context *torture)
                 dom_sid_string(mem_ctx, user_sid));
 
        if (!dom_sid_equal(created_sid, user_sid)) {
-               ret = False;
+               ret = false;
        }
 
  delete:
-       if (!delete_user(cli, cmdline_credentials,
+       if (!delete_user(cli, torture->lp_ctx, 
+                        cmdline_credentials,
                         cli_credentials_get_username(user_creds))) {
                d_printf("(%s) delete_user failed\n", __location__);
-               ret = False;
+               ret = false;
        }
 
  done:
@@ -1726,14 +1822,14 @@ BOOL torture_samba3_rpc_getusername(struct torture_context *torture)
        return ret;
 }
 
-static BOOL test_NetShareGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
+static bool test_NetShareGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                                 const char *sharename)
 {
        NTSTATUS status;
        struct srvsvc_NetShareGetInfo r;
        uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007, 1501 };
        int i;
-       BOOL ret = True;
+       bool ret = true;
 
        r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s",
                                          dcerpc_server_name(p));
@@ -1752,14 +1848,14 @@ static BOOL test_NetShareGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                        printf("NetShareGetInfo level %u on share '%s' failed"
                               " - %s\n", r.in.level, r.in.share_name,
                               nt_errstr(status));
-                       ret = False;
+                       ret = false;
                        continue;
                }
                if (!W_ERROR_IS_OK(r.out.result)) {
                        printf("NetShareGetInfo level %u on share '%s' failed "
                               "- %s\n", r.in.level, r.in.share_name,
                               win_errstr(r.out.result));
-                       ret = False;
+                       ret = false;
                        continue;
                }
        }
@@ -1767,7 +1863,7 @@ static BOOL test_NetShareGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        return ret;
 }
 
-static BOOL test_NetShareEnum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
+static bool test_NetShareEnum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                              const char **one_sharename)
 {
        NTSTATUS status;
@@ -1775,7 +1871,7 @@ static BOOL test_NetShareEnum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        struct srvsvc_NetShareCtr0 c0;
        uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007 };
        int i;
-       BOOL ret = True;
+       bool ret = true;
 
        r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
        r.in.ctr.ctr0 = &c0;
@@ -1794,7 +1890,7 @@ static BOOL test_NetShareEnum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                if (!NT_STATUS_IS_OK(status)) {
                        printf("NetShareEnum level %u failed - %s\n",
                               r.in.level, nt_errstr(status));
-                       ret = False;
+                       ret = false;
                        continue;
                }
                if (!W_ERROR_IS_OK(r.out.result)) {
@@ -1813,32 +1909,32 @@ static BOOL test_NetShareEnum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        return ret;
 }
 
-BOOL torture_samba3_rpc_srvsvc(struct torture_context *torture)
+bool torture_samba3_rpc_srvsvc(struct torture_context *torture)
 {
        struct dcerpc_pipe *p;
        TALLOC_CTX *mem_ctx;
-       BOOL ret = True;
+       bool ret = true;
        const char *sharename = NULL;
        struct smbcli_state *cli;
        NTSTATUS status;
 
        if (!(mem_ctx = talloc_new(torture))) {
-               return False;
+               return false;
        }
 
        if (!(torture_open_connection_share(
-                     mem_ctx, &cli, lp_parm_string(-1, "torture", "host"),
+                     mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
                      "IPC$", NULL))) {
                talloc_free(mem_ctx);
-               return False;
+               return false;
        }
 
-       status = pipe_bind_smb(mem_ctx, cli->tree, "\\pipe\\srvsvc",
-                              &dcerpc_table_srvsvc, &p);
+       status = pipe_bind_smb(mem_ctx, torture->lp_ctx, cli->tree, 
+                              "\\pipe\\srvsvc", &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));
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -1854,7 +1950,123 @@ BOOL torture_samba3_rpc_srvsvc(struct torture_context *torture)
        return ret;
 }
 
+/*
+ * Do a ReqChallenge/Auth2 with a random wks name, make sure it returns
+ * NT_STATUS_NO_SAM_ACCOUNT
+ */
+
+bool torture_samba3_rpc_randomauth2(struct torture_context *torture)
+{
+       TALLOC_CTX *mem_ctx;
+       struct dcerpc_pipe *net_pipe;
+       char *wksname;
+       bool result = false;
+       NTSTATUS status;
+       struct netr_ServerReqChallenge r;
+       struct netr_Credential netr_cli_creds;
+       struct netr_Credential netr_srv_creds;
+       uint32_t negotiate_flags;
+       struct netr_ServerAuthenticate2 a;
+       struct creds_CredentialState *creds_state;
+       struct netr_Credential netr_cred;
+       struct samr_Password mach_pw;
+       struct smbcli_state *cli;
+
+       if (!(mem_ctx = talloc_new(torture))) {
+               d_printf("talloc_new failed\n");
+               return false;
+       }
+
+       if (!(wksname = generate_random_str_list(
+                     mem_ctx, 14, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"))) {
+               d_printf("generate_random_str_list failed\n");
+               goto done;
+       }
+
+       if (!(torture_open_connection_share(
+                     mem_ctx, &cli,
+                     torture, torture_setting_string(torture, "host", NULL),
+                     "IPC$", NULL))) {
+               d_printf("IPC$ connection failed\n");
+               goto done;
+       }
+
+       if (!(net_pipe = dcerpc_pipe_init(
+                     mem_ctx, cli->transport->socket->event.ctx,
+                     lp_iconv_convenience(torture->lp_ctx)))) {
+               d_printf("dcerpc_pipe_init failed\n");
+               goto done;
+       }
+
+       status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("dcerpc_pipe_open_smb failed: %s\n",
+                        nt_errstr(status));
+               goto done;
+       }
+
+       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));
+               goto done;
+       }
+
+       r.in.computer_name = wksname;
+       r.in.server_name = talloc_asprintf(
+               mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
+       if (r.in.server_name == NULL) {
+               d_printf("talloc_asprintf failed\n");
+               goto done;
+       }
+       generate_random_buffer(netr_cli_creds.data,
+                              sizeof(netr_cli_creds.data));
+       r.in.credentials = &netr_cli_creds;
+       r.out.credentials = &netr_srv_creds;
+
+       status = dcerpc_netr_ServerReqChallenge(net_pipe, mem_ctx, &r);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("netr_ServerReqChallenge failed: %s\n",
+                        nt_errstr(status));
+               goto done;
+       }
+
+       negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
+       E_md4hash("foobar", mach_pw.hash);
+
+       creds_state = talloc(mem_ctx, struct creds_CredentialState);
+       creds_client_init(creds_state, r.in.credentials,
+                         r.out.credentials, &mach_pw,
+                         &netr_cred, negotiate_flags);
+
+       a.in.server_name = talloc_asprintf(
+               mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
+       a.in.account_name = talloc_asprintf(
+               mem_ctx, "%s$", wksname);
+       a.in.computer_name = wksname;
+       a.in.secure_channel_type = SEC_CHAN_WKSTA;
+       a.in.negotiate_flags = &negotiate_flags;
+       a.out.negotiate_flags = &negotiate_flags;
+       a.in.credentials = &netr_cred;
+       a.out.credentials = &netr_cred;
+
+       status = dcerpc_netr_ServerAuthenticate2(net_pipe, mem_ctx, &a);
+
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_NO_TRUST_SAM_ACCOUNT)) {
+               d_printf("dcerpc_netr_ServerAuthenticate2 returned %s, "
+                        "expected NT_STATUS_NO_TRUST_SAM_ACCOUNT\n",
+                        nt_errstr(status));
+               goto done;
+       }
+
+       result = true;
+ done:
+       talloc_free(mem_ctx);
+       return result;
+}
+
 static struct security_descriptor *get_sharesec(TALLOC_CTX *mem_ctx,
+                                               struct loadparm_context *lp_ctx,
                                                struct smbcli_session *sess,
                                                const char *sharename)
 {
@@ -1876,8 +2088,8 @@ static struct security_descriptor *get_sharesec(TALLOC_CTX *mem_ctx,
                return NULL;
        }
 
-       status = pipe_bind_smb(mem_ctx, tree, "\\pipe\\srvsvc",
-                              &dcerpc_table_srvsvc, &p);
+       status = pipe_bind_smb(mem_ctx, lp_ctx, tree, "\\pipe\\srvsvc",
+                              &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));
@@ -1908,6 +2120,7 @@ static struct security_descriptor *get_sharesec(TALLOC_CTX *mem_ctx,
 }
 
 static NTSTATUS set_sharesec(TALLOC_CTX *mem_ctx,
+                            struct loadparm_context *lp_ctx,
                             struct smbcli_session *sess,
                             const char *sharename,
                             struct security_descriptor *sd)
@@ -1931,8 +2144,8 @@ static NTSTATUS set_sharesec(TALLOC_CTX *mem_ctx,
                return NT_STATUS_UNSUCCESSFUL;
        }
 
-       status = pipe_bind_smb(mem_ctx, tree, "\\pipe\\srvsvc",
-                              &dcerpc_table_srvsvc, &p);
+       status = pipe_bind_smb(mem_ctx, lp_ctx, tree, "\\pipe\\srvsvc",
+                              &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));
@@ -1962,7 +2175,8 @@ static NTSTATUS set_sharesec(TALLOC_CTX *mem_ctx,
        return status;
 }
 
-BOOL try_tcon(TALLOC_CTX *mem_ctx,
+bool try_tcon(TALLOC_CTX *mem_ctx,
+             struct loadparm_context *lp_ctx,
              struct security_descriptor *orig_sd,
              struct smbcli_session *session,
              const char *sharename, const struct dom_sid *user_sid,
@@ -1975,18 +2189,18 @@ BOOL try_tcon(TALLOC_CTX *mem_ctx,
        uint32_t rid;
        struct security_descriptor *sd;
        NTSTATUS status;
-       BOOL ret = True;
+       bool ret = true;
 
        if (!(tmp_ctx = talloc_new(mem_ctx))) {
                d_printf("talloc_new failed\n");
-               return False;
+               return false;
        }
 
        status = secondary_tcon(tmp_ctx, session, sharename, &rmdir_tree);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("first tcon to delete dir failed\n");
                talloc_free(tmp_ctx);
-               return False;
+               return false;
        }
 
        smbcli_rmdir(rmdir_tree, "sharesec_testdir");
@@ -1995,34 +2209,34 @@ BOOL try_tcon(TALLOC_CTX *mem_ctx,
                                               &domain_sid, &rid))) {
                d_printf("dom_sid_split_rid failed\n");
                talloc_free(tmp_ctx);
-               return False;
+               return false;
        }
 
-       sd = security_descriptor_create(
-               tmp_ctx, "S-1-5-32-544",
+       sd = security_descriptor_dacl_create(
+               tmp_ctx, 0, "S-1-5-32-544",
                dom_sid_string(mem_ctx, dom_sid_add_rid(mem_ctx, domain_sid,
                                                        DOMAIN_RID_USERS)),
                dom_sid_string(mem_ctx, user_sid),
                SEC_ACE_TYPE_ACCESS_ALLOWED, access_mask, 0, NULL);
        if (sd == NULL) {
-               d_printf("security_descriptor_create failed\n");
+               d_printf("security_descriptor_dacl_create failed\n");
                talloc_free(tmp_ctx);
-                return False;
+                return false;
         }
 
-       status = set_sharesec(mem_ctx, session, sharename, sd);
+       status = set_sharesec(mem_ctx, lp_ctx, session, sharename, sd);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("custom set_sharesec failed: %s\n",
                         nt_errstr(status));
                talloc_free(tmp_ctx);
-                return False;
+                return false;
        }
 
        status = secondary_tcon(tmp_ctx, session, sharename, &tree);
        if (!NT_STATUS_EQUAL(status, expected_tcon)) {
                d_printf("Expected %s, got %s\n", nt_errstr(expected_tcon),
                         nt_errstr(status));
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -2033,76 +2247,76 @@ BOOL try_tcon(TALLOC_CTX *mem_ctx,
 
        status = smbcli_mkdir(tree, "sharesec_testdir");
        if (!NT_STATUS_EQUAL(status, expected_mkdir)) {
-               d_printf("Expected %s, got %s\n", nt_errstr(expected_mkdir),
-                        nt_errstr(status));
-               ret = False;
+               d_printf("(%s) Expected %s, got %s\n", __location__,
+                        nt_errstr(expected_mkdir), nt_errstr(status));
+               ret = false;
        }
 
  done:
        smbcli_rmdir(rmdir_tree, "sharesec_testdir");
 
-       status = set_sharesec(mem_ctx, session, sharename, orig_sd);
+       status = set_sharesec(mem_ctx, lp_ctx, session, sharename, orig_sd);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("custom set_sharesec failed: %s\n",
                         nt_errstr(status));
                talloc_free(tmp_ctx);
-                return False;
+                return false;
        }
 
        talloc_free(tmp_ctx);
        return ret;
 }
 
-BOOL torture_samba3_rpc_sharesec(struct torture_context *torture)
+bool torture_samba3_rpc_sharesec(struct torture_context *torture)
 {
        TALLOC_CTX *mem_ctx;
-       BOOL ret = True;
+       bool ret = true;
        struct smbcli_state *cli;
        struct security_descriptor *sd;
        struct dom_sid *user_sid;
 
        if (!(mem_ctx = talloc_new(torture))) {
-               return False;
+               return false;
        }
 
        if (!(torture_open_connection_share(
-                     mem_ctx, &cli, lp_parm_string(-1, "torture", "host"),
+                     mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
                      "IPC$", NULL))) {
                d_printf("IPC$ connection failed\n");
                talloc_free(mem_ctx);
-               return False;
+               return false;
        }
 
-       if (!(user_sid = whoami(mem_ctx, cli->tree))) {
+       if (!(user_sid = whoami(mem_ctx, torture->lp_ctx, cli->tree))) {
                d_printf("whoami failed\n");
                talloc_free(mem_ctx);
-               return False;
+               return false;
        }
 
-       sd = get_sharesec(mem_ctx, cli->session, lp_parm_string(-1, "torture",
-                                                               "share"));
+       sd = get_sharesec(mem_ctx, torture->lp_ctx, cli->session, 
+                         torture_setting_string(torture, "share", NULL));
 
-       ret &= try_tcon(mem_ctx, sd, cli->session,
-                       lp_parm_string(-1, "torture", "share"),
+       ret &= try_tcon(mem_ctx, torture->lp_ctx, sd, cli->session,
+                       torture_setting_string(torture, "share", NULL),
                        user_sid, 0, NT_STATUS_ACCESS_DENIED, NT_STATUS_OK);
 
-       ret &= try_tcon(mem_ctx, sd, cli->session,
-                       lp_parm_string(-1, "torture", "share"),
+       ret &= try_tcon(mem_ctx, torture->lp_ctx, sd, cli->session,
+                       torture_setting_string(torture, "share", NULL),
                        user_sid, SEC_FILE_READ_DATA, NT_STATUS_OK,
-                       NT_STATUS_NETWORK_ACCESS_DENIED);
+                       NT_STATUS_MEDIA_WRITE_PROTECTED);
 
-       ret &= try_tcon(mem_ctx, sd, cli->session,
-                       lp_parm_string(-1, "torture", "share"),
+       ret &= try_tcon(mem_ctx, torture->lp_ctx, sd, cli->session,
+                       torture_setting_string(torture, "share", NULL),
                        user_sid, SEC_FILE_ALL, NT_STATUS_OK, NT_STATUS_OK);
 
        talloc_free(mem_ctx);
        return ret;
 }
 
-BOOL torture_samba3_rpc_lsa(struct torture_context *torture)
+bool torture_samba3_rpc_lsa(struct torture_context *torture)
 {
        TALLOC_CTX *mem_ctx;
-       BOOL ret = True;
+       bool ret = true;
        struct smbcli_state *cli;
        struct dcerpc_pipe *p;
        struct policy_handle lsa_handle;
@@ -2110,24 +2324,24 @@ BOOL torture_samba3_rpc_lsa(struct torture_context *torture)
        struct dom_sid *domain_sid;
 
        if (!(mem_ctx = talloc_new(torture))) {
-               return False;
+               return false;
        }
 
        if (!(torture_open_connection_share(
-                     mem_ctx, &cli, lp_parm_string(-1, "torture", "host"),
+                     mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
                      "IPC$", NULL))) {
                d_printf("IPC$ connection failed\n");
                talloc_free(mem_ctx);
-               return False;
+               return false;
        }
 
-       status = pipe_bind_smb(mem_ctx, cli->tree, "\\lsarpc",
-                              &dcerpc_table_lsarpc, &p);
+       status = pipe_bind_smb(mem_ctx, torture->lp_ctx, cli->tree, "\\lsarpc",
+                              &ndr_table_lsarpc, &p);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
                         nt_errstr(status));
                talloc_free(mem_ctx);
-               return False;
+               return false;
        }
 
        {
@@ -2144,7 +2358,7 @@ BOOL torture_samba3_rpc_lsa(struct torture_context *torture)
                        d_printf("(%s) dcerpc_lsa_OpenPolicy2 failed: %s\n",
                                 __location__, nt_errstr(status));
                        talloc_free(mem_ctx);
-                       return False;
+                       return false;
                }
        }
 
@@ -2166,7 +2380,7 @@ BOOL torture_samba3_rpc_lsa(struct torture_context *torture)
                                         "failed: %s\n", __location__,
                                         levels[i], nt_errstr(status));
                                talloc_free(mem_ctx);
-                               return False;
+                               return false;
                        }
                        if (levels[i] == 5) {
                                domain_sid = r.out.info->account_domain.sid;
@@ -2178,6 +2392,7 @@ BOOL torture_samba3_rpc_lsa(struct torture_context *torture)
 }
 
 static NTSTATUS get_servername(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree,
+                              struct smb_iconv_convenience *iconv_convenience,
                               char **name)
 {
        struct rap_WserverGetInfo r;
@@ -2187,7 +2402,7 @@ static NTSTATUS get_servername(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree,
        r.in.level = 0;
        r.in.bufsize = 0xffff;
 
-       status = smbcli_rap_netservergetinfo(tree, mem_ctx, &r);
+       status = smbcli_rap_netservergetinfo(tree, iconv_convenience, mem_ctx, &r);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -2195,7 +2410,8 @@ static NTSTATUS get_servername(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree,
        memcpy(servername, r.out.info.info0.name, 16);
        servername[16] = '\0';
 
-       if (pull_ascii_talloc(mem_ctx, name, servername) < 0) {
+       if (pull_ascii_talloc(mem_ctx, iconv_convenience, 
+                             name, servername) < 0) {
                return NT_STATUS_NO_MEMORY;
        }
 
@@ -2203,7 +2419,8 @@ static NTSTATUS get_servername(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree,
 }
 
 
-static NTSTATUS find_printers(TALLOC_CTX *ctx, struct smbcli_tree *tree,
+static NTSTATUS find_printers(TALLOC_CTX *ctx, struct loadparm_context *lp_ctx,
+                             struct smbcli_tree *tree,
                              const char ***printers, int *num_printers)
 {
        TALLOC_CTX *mem_ctx;
@@ -2219,7 +2436,8 @@ 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, lp_ctx, 
+                              tree, "\\srvsvc", &ndr_table_srvsvc,
                               &p);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("could not bind to srvsvc pipe\n");
@@ -2261,7 +2479,7 @@ static NTSTATUS find_printers(TALLOC_CTX *ctx, struct smbcli_tree *tree,
        return NT_STATUS_OK;
 }
 
-static BOOL enumprinters(TALLOC_CTX *mem_ctx, struct dcerpc_pipe *pipe,
+static bool enumprinters(TALLOC_CTX *mem_ctx, struct dcerpc_pipe *pipe,
                         const char *servername, int level, int *num_printers)
 {
        struct spoolss_EnumPrinters r;
@@ -2278,20 +2496,20 @@ static BOOL enumprinters(TALLOC_CTX *mem_ctx, struct dcerpc_pipe *pipe,
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) dcerpc_spoolss_EnumPrinters failed: %s\n",
                         __location__, nt_errstr(status));
-               return False;
+               return false;
        }
 
        if (!W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
                d_printf("(%s) EnumPrinters unexpected return code %s, should "
                         "be WERR_INSUFFICIENT_BUFFER\n", __location__,
                         win_errstr(r.out.result));
-               return False;
+               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;
+               return false;
        }
 
        r.in.buffer = &blob;
@@ -2302,12 +2520,12 @@ static BOOL enumprinters(TALLOC_CTX *mem_ctx, struct dcerpc_pipe *pipe,
                d_printf("(%s) dcerpc_spoolss_EnumPrinters failed: %s, "
                         "%s\n", __location__, nt_errstr(status),
                         win_errstr(r.out.result));
-               return False;
+               return false;
        }
 
        *num_printers = r.out.count;
 
-       return True;
+       return true;
 }
 
 static NTSTATUS getprinterinfo(TALLOC_CTX *ctx, struct dcerpc_pipe *pipe,
@@ -2374,10 +2592,10 @@ static NTSTATUS getprinterinfo(TALLOC_CTX *ctx, struct dcerpc_pipe *pipe,
        return NT_STATUS_OK;
 }
 
-BOOL torture_samba3_rpc_spoolss(struct torture_context *torture)
+bool torture_samba3_rpc_spoolss(struct torture_context *torture)
 {
        TALLOC_CTX *mem_ctx;
-       BOOL ret = True;
+       bool ret = true;
        struct smbcli_state *cli;
        struct dcerpc_pipe *p;
        NTSTATUS status;
@@ -2388,49 +2606,49 @@ BOOL torture_samba3_rpc_spoolss(struct torture_context *torture)
        char *servername;
 
        if (!(mem_ctx = talloc_new(torture))) {
-               return False;
+               return false;
        }
 
        if (!(torture_open_connection_share(
-                     mem_ctx, &cli, lp_parm_string(-1, "torture", "host"),
+                     mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
                      "IPC$", NULL))) {
                d_printf("IPC$ connection failed\n");
                talloc_free(mem_ctx);
-               return False;
+               return false;
        }
 
-       status = get_servername(mem_ctx, cli->tree, &servername);
+       status = get_servername(mem_ctx, cli->tree, lp_iconv_convenience(torture->lp_ctx), &servername);
        if (!NT_STATUS_IS_OK(status)) {
                d_fprintf(stderr, "(%s) get_servername returned %s\n",
                          __location__, nt_errstr(status));
                talloc_free(mem_ctx);
-               return False;
+               return false;
        }
 
-       if (!NT_STATUS_IS_OK(find_printers(mem_ctx, cli->tree,
+       if (!NT_STATUS_IS_OK(find_printers(mem_ctx, torture->lp_ctx, cli->tree,
                                           &printers, &num_printers))) {
                talloc_free(mem_ctx);
-               return False;
+               return false;
        }
 
        if (num_printers == 0) {
                d_printf("Did not find printers\n");
                talloc_free(mem_ctx);
-               return True;
+               return true;
        }
 
-       status = pipe_bind_smb(mem_ctx, cli->tree, "\\spoolss",
-                              &dcerpc_table_spoolss, &p);
+       status = pipe_bind_smb(mem_ctx, torture->lp_ctx, cli->tree, "\\spoolss",
+                              &ndr_table_spoolss, &p);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
                         nt_errstr(status));
                talloc_free(mem_ctx);
-               return False;
+               return false;
        }
 
        ZERO_STRUCT(userlevel1);
        userlevel1.client = talloc_asprintf(
-               mem_ctx, "\\\\%s", lp_netbios_name());
+               mem_ctx, "\\\\%s", lp_netbios_name(torture->lp_ctx));
        userlevel1.user = cli_credentials_get_username(cmdline_credentials);
        userlevel1.build = 2600;
        userlevel1.major = 3;
@@ -2455,7 +2673,7 @@ BOOL torture_samba3_rpc_spoolss(struct torture_context *torture)
                                 "%s, %s\n", __location__, nt_errstr(status),
                                 win_errstr(r.out.result));
                        talloc_free(mem_ctx);
-                       return False;
+                       return false;
                }
        }
 
@@ -2471,7 +2689,7 @@ BOOL torture_samba3_rpc_spoolss(struct torture_context *torture)
                                 "%s, %s\n", __location__, nt_errstr(status),
                                 win_errstr(r.out.result));
                        talloc_free(mem_ctx);
-                       return False;
+                       return false;
                }
        }
 
@@ -2493,7 +2711,7 @@ BOOL torture_samba3_rpc_spoolss(struct torture_context *torture)
                                 "%s, %s\n", __location__, nt_errstr(status),
                                 win_errstr(r.out.result));
                        talloc_free(mem_ctx);
-                       return False;
+                       return false;
                }
        }
 
@@ -2506,7 +2724,7 @@ BOOL torture_samba3_rpc_spoolss(struct torture_context *torture)
                        if (!NT_STATUS_IS_OK(status)) {
                                d_printf("(%s) getprinterinfo %d failed: %s\n",
                                         __location__, i, nt_errstr(status));
-                               ret = False;
+                               ret = false;
                        }
                }
        }
@@ -2522,7 +2740,7 @@ BOOL torture_samba3_rpc_spoolss(struct torture_context *torture)
                        d_printf("(%s) dcerpc_spoolss_ClosePrinter failed: "
                                 "%s\n", __location__, nt_errstr(status));
                        talloc_free(mem_ctx);
-                       return False;
+                       return false;
                }
        }
 
@@ -2532,14 +2750,14 @@ BOOL torture_samba3_rpc_spoolss(struct torture_context *torture)
                                  &num_enumerated)) {
                        d_printf("(%s) enumprinters failed\n", __location__);
                        talloc_free(mem_ctx);
-                       return False;
+                       return false;
                }
                if (num_printers != num_enumerated) {
                        d_printf("(%s) netshareenum gave %d printers, "
                                 "enumprinters lvl 1 gave %d\n", __location__,
                                 num_printers, num_enumerated);
                        talloc_free(mem_ctx);
-                       return False;
+                       return false;
                }
        }
 
@@ -2549,14 +2767,14 @@ BOOL torture_samba3_rpc_spoolss(struct torture_context *torture)
                                  &num_enumerated)) {
                        d_printf("(%s) enumprinters failed\n", __location__);
                        talloc_free(mem_ctx);
-                       return False;
+                       return false;
                }
                if (num_printers != num_enumerated) {
                        d_printf("(%s) netshareenum gave %d printers, "
                                 "enumprinters lvl 2 gave %d\n", __location__,
                                 num_printers, num_enumerated);
                        talloc_free(mem_ctx);
-                       return False;
+                       return false;
                }
        }
 
@@ -2565,7 +2783,7 @@ BOOL torture_samba3_rpc_spoolss(struct torture_context *torture)
        return ret;
 }
 
-BOOL torture_samba3_rpc_wkssvc(struct torture_context *torture)
+bool torture_samba3_rpc_wkssvc(struct torture_context *torture)
 {
        TALLOC_CTX *mem_ctx;
        struct smbcli_state *cli;
@@ -2574,32 +2792,32 @@ BOOL torture_samba3_rpc_wkssvc(struct torture_context *torture)
        char *servername;
 
        if (!(mem_ctx = talloc_new(torture))) {
-               return False;
+               return false;
        }
 
        if (!(torture_open_connection_share(
-                     mem_ctx, &cli, lp_parm_string(-1, "torture", "host"),
+                     mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
                      "IPC$", NULL))) {
                d_printf("IPC$ connection failed\n");
                talloc_free(mem_ctx);
-               return False;
+               return false;
        }
 
-       status = get_servername(mem_ctx, cli->tree, &servername);
+       status = get_servername(mem_ctx, cli->tree, lp_iconv_convenience(torture->lp_ctx), &servername);
        if (!NT_STATUS_IS_OK(status)) {
                d_fprintf(stderr, "(%s) get_servername returned %s\n",
                          __location__, nt_errstr(status));
                talloc_free(mem_ctx);
-               return False;
+               return false;
        }
 
-       status = pipe_bind_smb(mem_ctx, cli->tree, "\\wkssvc",
-                              &dcerpc_table_wkssvc, &p);
+       status = pipe_bind_smb(mem_ctx, torture->lp_ctx, cli->tree, "\\wkssvc",
+                              &ndr_table_wkssvc, &p);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
                         nt_errstr(status));
                talloc_free(mem_ctx);
-               return False;
+               return false;
        }
 
        {
@@ -2618,7 +2836,7 @@ BOOL torture_samba3_rpc_wkssvc(struct torture_context *torture)
                                 "%s, %s\n", __location__, nt_errstr(status),
                                 win_errstr(r.out.result));
                        talloc_free(mem_ctx);
-                       return False;
+                       return false;
                }
 
                if (strcmp(servername,
@@ -2628,12 +2846,12 @@ BOOL torture_samba3_rpc_wkssvc(struct torture_context *torture)
                                 __location__, servername,
                                 r.out.info->info100->server_name);
                        talloc_free(mem_ctx);
-                       return False;
+                       return false;
                }
        }
 
        talloc_free(mem_ctx);
-       return True;
+       return true;
 }
 
 static NTSTATUS winreg_close(struct dcerpc_pipe *p,
@@ -2762,14 +2980,14 @@ static NTSTATUS enumkeys(struct dcerpc_pipe *p, struct policy_handle *handle,
                talloc_free(tmp_ctx);
 
                r.in.enum_index += 1;
-       } while(True);
+       } while(true);
 
        return NT_STATUS_OK;
 }
 
 typedef NTSTATUS (*winreg_open_fn)(struct dcerpc_pipe *, TALLOC_CTX *, void *);
 
-static BOOL test_Open3(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
+static bool test_Open3(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
                       const char *name, winreg_open_fn open_fn)
 {
        struct policy_handle handle;
@@ -2784,7 +3002,7 @@ static BOOL test_Open3(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
                d_printf("(%s) %s failed: %s, %s\n", __location__, name,
                         nt_errstr(status), win_errstr(r.out.result));
-               return False;
+               return false;
        }
 
        enumkeys(p, &handle, mem_ctx, 4);
@@ -2793,18 +3011,18 @@ static BOOL test_Open3(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) dcerpc_CloseKey failed: %s\n",
                         __location__, nt_errstr(status));
-               return False;
+               return false;
        }
 
-       return True;
+       return true;
 }
 
-BOOL torture_samba3_rpc_winreg(struct torture_context *torture)
+bool torture_samba3_rpc_winreg(struct torture_context *torture)
 {
         NTSTATUS status;
        struct dcerpc_pipe *p;
        TALLOC_CTX *mem_ctx;
-       BOOL ret = True;
+       bool ret = true;
        struct {
                const char *name;
                winreg_open_fn fn;
@@ -2814,15 +3032,17 @@ BOOL torture_samba3_rpc_winreg(struct torture_context *torture)
                {"OpenHKPD", (winreg_open_fn)dcerpc_winreg_OpenHKPD },
                {"OpenHKPT", (winreg_open_fn)dcerpc_winreg_OpenHKPT },
                {"OpenHKCR", (winreg_open_fn)dcerpc_winreg_OpenHKCR }};
+#if 0
        int i;
+#endif
 
        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);
-               return False;
+               return false;
        }
 
 #if 1
@@ -2830,7 +3050,7 @@ BOOL torture_samba3_rpc_winreg(struct torture_context *torture)
 #else
        for (i = 0; i < ARRAY_SIZE(open_fns); i++) {
                if (!test_Open3(p, mem_ctx, open_fns[i].name, open_fns[i].fn))
-                       ret = False;
+                       ret = false;
        }
 #endif
 
@@ -2838,3 +3058,343 @@ BOOL torture_samba3_rpc_winreg(struct torture_context *torture)
 
        return ret;
 }
+
+static NTSTATUS get_shareinfo(TALLOC_CTX *mem_ctx,
+                             struct loadparm_context *lp_ctx,
+                             struct smbcli_state *cli,
+                             const char *share,
+                             struct srvsvc_NetShareInfo502 **info)
+{
+       struct smbcli_tree *ipc;
+       struct dcerpc_pipe *p;
+       struct srvsvc_NetShareGetInfo r;
+       NTSTATUS status;
+
+       if (!(p = dcerpc_pipe_init(cli,
+                                  cli->transport->socket->event.ctx,
+                                  lp_iconv_convenience(lp_ctx)))) {
+               status = NT_STATUS_NO_MEMORY;
+               goto fail;
+       }
+
+       status = secondary_tcon(p, cli->session, "IPC$", &ipc);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto fail;
+       }
+
+       status = dcerpc_pipe_open_smb(p, ipc, "\\pipe\\srvsvc");
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("dcerpc_pipe_open_smb failed: %s\n",
+                        nt_errstr(status));
+               goto fail;
+       }
+
+       status = dcerpc_bind_auth_none(p, &ndr_table_srvsvc);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("dcerpc_bind_auth_none failed: %s\n",
+                        nt_errstr(status));
+               goto fail;
+       }
+
+       r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s",
+                                         dcerpc_server_name(p));
+       r.in.share_name = share;
+       r.in.level = 502;
+
+       status = dcerpc_srvsvc_NetShareGetInfo(p, p, &r);
+       if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
+               d_printf("(%s) OpenHKLM failed: %s, %s\n", __location__,
+                        nt_errstr(status), win_errstr(r.out.result));
+               goto fail;
+       }
+
+       *info = talloc_move(mem_ctx, &r.out.info.info502);
+       return NT_STATUS_OK;
+
+ fail:
+       talloc_free(p);
+       return status;
+}
+
+/*
+ * Get us a handle on HKLM\
+ */
+
+static NTSTATUS get_hklm_handle(TALLOC_CTX *mem_ctx,
+                               struct smbcli_state *cli,
+                               struct smb_iconv_convenience *iconv_convenience,
+                               struct dcerpc_pipe **pipe_p,
+                               struct policy_handle **handle)
+{
+       struct smbcli_tree *ipc;
+       struct dcerpc_pipe *p;
+       struct winreg_OpenHKLM r;
+       NTSTATUS status;
+       struct policy_handle *result;
+
+       result = talloc(mem_ctx, struct policy_handle);
+
+       if (result == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       if (!(p = dcerpc_pipe_init(result,
+                                  cli->transport->socket->event.ctx,
+                                  iconv_convenience))) {
+               status = NT_STATUS_NO_MEMORY;
+               goto fail;
+       }
+
+       status = secondary_tcon(p, cli->session, "IPC$", &ipc);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto fail;
+       }
+
+       status = dcerpc_pipe_open_smb(p, ipc, "\\winreg");
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("dcerpc_pipe_open_smb failed: %s\n",
+                        nt_errstr(status));
+               goto fail;
+       }
+
+       status = dcerpc_bind_auth_none(p, &ndr_table_winreg);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("dcerpc_bind_auth_none failed: %s\n",
+                        nt_errstr(status));
+               goto fail;
+       }
+
+       r.in.system_name = 0;
+        r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
+        r.out.handle = result;
+
+       status = dcerpc_winreg_OpenHKLM(p, p, &r);
+       if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
+               d_printf("(%s) OpenHKLM failed: %s, %s\n", __location__,
+                        nt_errstr(status), win_errstr(r.out.result));
+               goto fail;
+       }
+
+       *pipe_p = p;
+       *handle = result;
+       return NT_STATUS_OK;
+
+ fail:
+       talloc_free(result);
+       return status;
+}
+
+static NTSTATUS torture_samba3_createshare(struct smbcli_state *cli,
+                                          struct smb_iconv_convenience *iconv_convenience,
+                                          const char *sharename)
+{
+       struct dcerpc_pipe *p;
+       struct policy_handle *hklm = NULL;
+       struct policy_handle new_handle;
+       struct winreg_CreateKey c;
+       struct winreg_CloseKey cl;
+       enum winreg_CreateAction action_taken;
+       NTSTATUS status;
+       TALLOC_CTX *mem_ctx;
+
+       mem_ctx = talloc_new(cli);
+       NT_STATUS_HAVE_NO_MEMORY(mem_ctx);
+
+       status = get_hklm_handle(mem_ctx, cli, iconv_convenience, &p, &hklm);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
+               goto fail;
+       }
+
+       c.in.handle = hklm;
+       c.in.name.name = talloc_asprintf(
+               mem_ctx, "software\\samba\\smbconf\\%s", sharename);
+       if (c.in.name.name == NULL) {
+               d_printf("talloc_asprintf failed\n");
+               status = NT_STATUS_NO_MEMORY;
+               goto fail;
+       }
+       c.in.keyclass.name = "";
+       c.in.options = 0;
+       c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
+       c.in.secdesc = NULL;
+       c.in.action_taken = &action_taken;
+       c.out.new_handle = &new_handle;
+       c.out.action_taken = &action_taken;
+
+       status = dcerpc_winreg_CreateKey(p, p, &c);
+       if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(c.out.result)) {
+               d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
+                        nt_errstr(status), win_errstr(c.out.result));
+               goto fail;
+       }
+
+       cl.in.handle = &new_handle;
+       cl.out.handle = &new_handle;
+       status = dcerpc_winreg_CloseKey(p, p, &cl);
+       if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(cl.out.result)) {
+               d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
+                        nt_errstr(status), win_errstr(cl.out.result));
+               goto fail;
+       }
+
+
+ fail:
+       talloc_free(mem_ctx);
+       return status;
+}
+
+static NTSTATUS torture_samba3_deleteshare(struct torture_context *torture,
+                                          struct smbcli_state *cli,
+                                          const char *sharename)
+{
+       struct dcerpc_pipe *p;
+       struct policy_handle *hklm = NULL;
+       struct winreg_DeleteKey d;
+       NTSTATUS status;
+       TALLOC_CTX *mem_ctx;
+
+       mem_ctx = talloc_new(cli);
+       NT_STATUS_HAVE_NO_MEMORY(mem_ctx);
+
+       status = get_hklm_handle(cli, cli, lp_iconv_convenience(torture->lp_ctx),
+                                &p, &hklm);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
+               goto fail;
+       }
+
+       d.in.handle = hklm;
+       d.in.key.name = talloc_asprintf(
+               mem_ctx, "software\\samba\\smbconf\\%s", sharename);
+       if (d.in.key.name == NULL) {
+               d_printf("talloc_asprintf failed\n");
+               status = NT_STATUS_NO_MEMORY;
+               goto fail;
+       }
+       status = dcerpc_winreg_DeleteKey(p, p, &d);
+       if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(d.out.result)) {
+               d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
+                        nt_errstr(status), win_errstr(d.out.result));
+               goto fail;
+       }
+
+ fail:
+       talloc_free(mem_ctx);
+       return status;
+}
+
+static NTSTATUS torture_samba3_setconfig(struct smbcli_state *cli,
+                                        struct loadparm_context *lp_ctx,
+                                        const char *sharename,
+                                        const char *parameter,
+                                        const char *value)
+{
+       struct dcerpc_pipe *p = NULL;
+       struct policy_handle *hklm = NULL, key_handle;
+       struct winreg_OpenKey o;
+       struct winreg_SetValue s;
+       uint32_t type;
+       DATA_BLOB val;
+       NTSTATUS status;
+
+       status = get_hklm_handle(cli, cli, lp_iconv_convenience(lp_ctx), &p, &hklm);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
+               return status;;
+       }
+
+       o.in.parent_handle = hklm;
+       o.in.keyname.name = talloc_asprintf(
+               hklm, "software\\samba\\smbconf\\%s", sharename);
+       if (o.in.keyname.name == NULL) {
+               d_printf("talloc_asprintf failed\n");
+               status = NT_STATUS_NO_MEMORY;
+               goto done;
+       }
+       o.in.unknown = 0;
+       o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
+       o.out.handle = &key_handle;
+
+       status = dcerpc_winreg_OpenKey(p, p, &o);
+       if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(o.out.result)) {
+               d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
+                        nt_errstr(status), win_errstr(o.out.result));
+               goto done;
+       }
+
+       if (!reg_string_to_val(hklm, lp_iconv_convenience(lp_ctx), "REG_SZ", 
+                              value, &type, &val)) {
+               d_printf("(%s) reg_string_to_val failed\n", __location__);
+               goto done;
+       }
+
+       s.in.handle = &key_handle;
+       s.in.name.name = parameter;
+       s.in.type = type;
+       s.in.data = val.data;
+       s.in.size = val.length;
+
+       status = dcerpc_winreg_SetValue(p, p, &s);
+       if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(s.out.result)) {
+               d_printf("(%s) SetValue failed: %s, %s\n", __location__,
+                        nt_errstr(status), win_errstr(s.out.result));
+               goto done;
+       }
+
+ done:
+       talloc_free(hklm);
+       return status;
+}
+
+bool torture_samba3_regconfig(struct torture_context *torture)
+{
+       struct smbcli_state *cli;
+       struct srvsvc_NetShareInfo502 *i = NULL;
+       NTSTATUS status;
+       bool ret = false;
+       const char *comment = "Dummer Kommentar";
+
+       if (!(torture_open_connection(&cli, torture, 0))) {
+               return false;
+       }
+
+       status = torture_samba3_createshare(cli, lp_iconv_convenience(torture->lp_ctx), "blubber");
+       if (!NT_STATUS_IS_OK(status)) {
+               torture_warning(torture, "torture_samba3_createshare failed: "
+                               "%s\n", nt_errstr(status));
+               goto done;
+       }
+
+       status = torture_samba3_setconfig(cli, torture->lp_ctx, "blubber", "comment", comment);
+       if (!NT_STATUS_IS_OK(status)) {
+               torture_warning(torture, "torture_samba3_setconfig failed: "
+                               "%s\n", nt_errstr(status));
+               goto done;
+       }
+
+       status = get_shareinfo(torture, torture->lp_ctx, cli, "blubber", &i);
+       if (!NT_STATUS_IS_OK(status)) {
+               torture_warning(torture, "get_shareinfo failed: "
+                               "%s\n", nt_errstr(status));
+               goto done;
+       }
+
+       if (strcmp(comment, i->comment) != 0) {
+               torture_warning(torture, "Expected comment [%s], got [%s]\n",
+                               comment, i->comment);
+               goto done;
+       }
+
+       status = torture_samba3_deleteshare(torture, cli, "blubber");
+       if (!NT_STATUS_IS_OK(status)) {
+               torture_warning(torture, "torture_samba3_deleteshare failed: "
+                               "%s\n", nt_errstr(status));
+               goto done;
+       }
+
+       ret = true;
+ done:
+       talloc_free(cli);
+       return ret;
+}