r24900: - if we use try to create a 3rd dcerpc_pipe then use a 3rd variable
[kai/samba.git] / source4 / torture / rpc / alter_context.c
index 62cfcf758d3b708072c45c5389ff530a9f3f6da9..78437130746708ca32620a089d294bfd3315bab1 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 "torture/torture.h"
 #include "librpc/gen_ndr/ndr_lsa.h"
 #include "librpc/gen_ndr/ndr_dssetup.h"
+#include "librpc/rpc/dcerpc.h"
 #include "torture/rpc/rpc.h"
 
-BOOL torture_rpc_alter_context(void)
+bool torture_rpc_alter_context(struct torture_context *torture)
 {
-        NTSTATUS status;
-        struct dcerpc_pipe *p, *p2;
-       TALLOC_CTX *mem_ctx;
-       BOOL ret = True;
+       NTSTATUS status;
+       struct dcerpc_pipe *p, *p2, *p3;
        struct policy_handle *handle;
-       struct dcerpc_interface_table tmptbl;
-       struct dcerpc_syntax_id syntax;
-       struct dcerpc_syntax_id transfer_syntax;
+       struct ndr_interface_table tmptbl;
+       struct ndr_syntax_id syntax;
+       struct ndr_syntax_id transfer_syntax;
+       bool ret = true;
 
-       mem_ctx = talloc_init("torture_rpc_alter_context");
+       torture_comment(torture, "opening LSA connection\n");
+       status = torture_rpc_connection(torture, &p, &ndr_table_lsarpc);
+       torture_assert_ntstatus_ok(torture, status, "connecting");
 
-       printf("opening LSA connection\n");
-       status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_lsarpc);
-       if (!NT_STATUS_IS_OK(status)) {
-               talloc_free(mem_ctx);
-               return False;
+       if (!test_lsa_OpenPolicy2(p, torture, &handle)) {
+               ret = false;
        }
 
-       if (!test_lsa_OpenPolicy2(p, mem_ctx, &handle)) {
-               ret = False;
-       }
-
-       printf("Opening secondary DSSETUP context\n");
-       status = dcerpc_secondary_context(p, &p2, &dcerpc_table_dssetup);
-       if (!NT_STATUS_IS_OK(status)) {
-               talloc_free(mem_ctx);
-               printf("dcerpc_alter_context failed - %s\n", nt_errstr(status));
-               return False;
-       }
+       torture_comment(torture, "Opening secondary DSSETUP context\n");
+       status = dcerpc_secondary_context(p, &p2, &ndr_table_dssetup);
+       torture_assert_ntstatus_ok(torture, status, "dcerpc_alter_context failed");
 
-       tmptbl = dcerpc_table_dssetup;
-       tmptbl.if_version += 100;
-       printf("Opening bad secondary connection\n");
-       status = dcerpc_secondary_context(p, &p2, &tmptbl);
-       if (NT_STATUS_IS_OK(status)) {
-               talloc_free(mem_ctx);
-               printf("dcerpc_alter_context with wrong version should fail\n");
-               return False;
-       }
+       tmptbl = ndr_table_dssetup;
+       tmptbl.syntax_id.if_version += 100;
+       torture_comment(torture, "Opening bad secondary connection\n");
+       status = dcerpc_secondary_context(p, &p3, &tmptbl);
+       torture_assert_ntstatus_equal(torture, status, NT_STATUS_RPC_UNSUPPORTED_NAME_SYNTAX,
+                                     "dcerpc_alter_context with wrong version should fail");
 
-       printf("testing DSSETUP pipe operations\n");
-       ret &= test_DsRoleGetPrimaryDomainInformation(p2, mem_ctx);
+       torture_comment(torture, "testing DSSETUP pipe operations\n");
+       ret &= test_DsRoleGetPrimaryDomainInformation(torture, p2);
 
        if (handle) {
-               if (!test_lsa_Close(p, mem_ctx, handle)) {
-                       ret = False;
-               }
+               ret &= test_lsa_Close(p, torture, handle);
        }
 
        syntax = p->syntax;
        transfer_syntax = p->transfer_syntax;
 
-       printf("Testing change of primary context\n");
-       status = dcerpc_alter_context(p, mem_ctx, &p2->syntax, &p2->transfer_syntax);
-       if (!NT_STATUS_IS_OK(status)) {
-               talloc_free(mem_ctx);
-               printf("dcerpc_alter_context failed - %s\n", nt_errstr(status));
-               return False;
-       }
+       torture_comment(torture, "Testing change of primary context\n");
+       status = dcerpc_alter_context(p, torture, &p2->syntax, &p2->transfer_syntax);
+       torture_assert_ntstatus_ok(torture, status, "dcerpc_alter_context failed");
 
-       printf("testing DSSETUP pipe operations - should fault\n");
-       if (test_DsRoleGetPrimaryDomainInformation(p, mem_ctx)) {
-               ret = False;
-       }
+       torture_comment(torture, "testing DSSETUP pipe operations - should fault\n");
+       ret &= test_DsRoleGetPrimaryDomainInformation_ext(torture, p, NT_STATUS_NET_WRITE_FAULT);
 
-       if (!test_lsa_OpenPolicy2(p, mem_ctx, &handle)) {
-               ret = False;
-       }
+       ret &= test_lsa_OpenPolicy2(p, torture, &handle);
 
        if (handle) {
-               if (!test_lsa_Close(p, mem_ctx, handle)) {
-                       ret = False;
-               }
+               ret &= test_lsa_Close(p, torture, handle);
        }
 
-       printf("testing DSSETUP pipe operations\n");
-       ret &= test_DsRoleGetPrimaryDomainInformation(p2, mem_ctx);
+       torture_comment(torture, "testing DSSETUP pipe operations\n");
 
-       talloc_free(mem_ctx);
+       ret &= test_DsRoleGetPrimaryDomainInformation(torture, p2);
 
        return ret;
 }