r23792: convert Samba4 to GPLv3
[kai/samba-autobuild/.git] / source4 / torture / libnet / libnet_domain.c
index 8bf175212ee4b1525eb56487da46bdae988f97f8..c337514aa6c1558abe88937d4e743fb840b14436 100644 (file)
@@ -6,7 +6,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,
@@ -15,8 +15,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 
@@ -128,17 +127,14 @@ BOOL torture_domain_open_lsa(struct torture_context *torture)
        BOOL ret = True;
        struct libnet_context *ctx;
        struct libnet_DomainOpen r;
-       struct lsa_Close close;
-       struct dcerpc_binding *binding;
+       struct lsa_Close lsa_close;
        struct policy_handle h;
-       const char *bindstr;
-       
-       bindstr = torture_setting_string(torture, "binding", NULL);
-       status = dcerpc_parse_binding(torture, bindstr, &binding);
-       if (!NT_STATUS_IS_OK(status)) {
-               d_printf("failed to parse binding string\n");
-               return False;
-       }
+       const char *domain_name;
+
+       /* we're accessing domain controller so the domain name should be
+          passed (it's going to be resolved to dc name and address) instead
+          of specific server name. */
+       domain_name = lp_workgroup();
 
        ctx = libnet_context_init(NULL);
        if (ctx == NULL) {
@@ -150,7 +146,7 @@ BOOL torture_domain_open_lsa(struct torture_context *torture)
 
        ZERO_STRUCT(r);
        r.in.type = DOMAIN_LSA;
-       r.in.domain_name = binding->host;
+       r.in.domain_name = domain_name;
        r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
 
        status = libnet_DomainOpen(ctx, torture, &r);
@@ -160,11 +156,11 @@ BOOL torture_domain_open_lsa(struct torture_context *torture)
                goto done;
        }
 
-       ZERO_STRUCT(close);
-       close.in.handle  = &ctx->lsa.handle;
-       close.out.handle = &h;
+       ZERO_STRUCT(lsa_close);
+       lsa_close.in.handle  = &ctx->lsa.handle;
+       lsa_close.out.handle = &h;
        
-       status = dcerpc_lsa_Close(ctx->lsa.pipe, ctx, &close);
+       status = dcerpc_lsa_Close(ctx->lsa.pipe, ctx, &lsa_close);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("failed to close domain on lsa service: %s\n", nt_errstr(status));
                ret = False;
@@ -229,7 +225,7 @@ BOOL torture_domain_close_lsa(struct torture_context *torture)
        ctx->lsa.access_mask = access_mask;
        ctx->lsa.handle      = h;
        /* we have to use pipe's event context, otherwise the call will
-          hang indefinately */
+          hang indefinitely */
        ctx->event_ctx       = p->conn->event_ctx;
 
        ZERO_STRUCT(r);
@@ -257,9 +253,9 @@ BOOL torture_domain_open_samr(struct torture_context *torture)
        struct event_context *evt_ctx=NULL;
        TALLOC_CTX *mem_ctx;
        struct policy_handle domain_handle, handle;
-       struct lsa_String name;
        struct libnet_DomainOpen io;
        struct samr_Close r;
+       const char *domain_name;
        BOOL ret = True;
 
        mem_ctx = talloc_init("test_domainopen_lsa");
@@ -268,7 +264,10 @@ BOOL torture_domain_open_samr(struct torture_context *torture)
        ctx = libnet_context_init(evt_ctx);
        ctx->cred = cmdline_credentials;
 
-       name.string = lp_workgroup();
+       /* we're accessing domain controller so the domain name should be
+          passed (it's going to be resolved to dc name and address) instead
+          of specific server name. */
+       domain_name = lp_workgroup();
 
        /*
         * Testing synchronous version
@@ -276,7 +275,7 @@ BOOL torture_domain_open_samr(struct torture_context *torture)
        printf("opening domain\n");
        
        io.in.type         = DOMAIN_SAMR;
-       io.in.domain_name  = name.string;
+       io.in.domain_name  = domain_name;
        io.in.access_mask  = SEC_FLAG_MAXIMUM_ALLOWED;
 
        status = libnet_DomainOpen(ctx, mem_ctx, &io);
@@ -312,7 +311,7 @@ BOOL torture_domain_close_samr(struct torture_context *torture)
 {
        BOOL ret = True;
        NTSTATUS status;
-       TALLOC_CTX *mem_ctx=NULL;
+       TALLOC_CTX *mem_ctx = NULL;
        struct libnet_context *ctx;
        struct lsa_String domain_name;
        struct dcerpc_binding *binding;
@@ -340,7 +339,7 @@ BOOL torture_domain_close_samr(struct torture_context *torture)
 
        mem_ctx = talloc_init("torture_domain_close_samr");
        status = dcerpc_pipe_connect(mem_ctx, &p, bindstr, &dcerpc_table_samr,
-                                    cmdline_credentials, NULL);
+                                    ctx->cred, NULL);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("failed to connect to server %s: %s\n", bindstr,
                         nt_errstr(status));
@@ -361,7 +360,8 @@ BOOL torture_domain_close_samr(struct torture_context *torture)
        ctx->samr.access_mask = access_mask;
        ctx->samr.handle      = h;
        /* we have to use pipe's event context, otherwise the call will
-          hang indefinately */
+          hang indefinitely - this wouldn't be the case if pipe was opened
+          by means of libnet call */
        ctx->event_ctx       = p->conn->event_ctx;
 
        ZERO_STRUCT(r);
@@ -379,3 +379,81 @@ done:
        talloc_free(ctx);
        return ret;
 }
+
+
+BOOL torture_domain_list(struct torture_context *torture)
+{
+       BOOL ret = True;
+       NTSTATUS status;
+       TALLOC_CTX *mem_ctx = NULL;
+       const char *bindstr;
+       struct dcerpc_binding *binding;
+       struct libnet_context *ctx;
+       struct libnet_DomainList r;
+       int i;
+
+       bindstr = torture_setting_string(torture, "binding", NULL);
+       status = dcerpc_parse_binding(torture, bindstr, &binding);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("failed to parse binding string\n");
+               return False;
+       }
+
+       ctx = libnet_context_init(NULL);
+       if (ctx == NULL) {
+               d_printf("failed to create libnet context\n");
+               ret = False;
+               goto done;
+       }
+
+       ctx->cred = cmdline_credentials;
+       
+       mem_ctx = talloc_init("torture_domain_close_samr");
+
+       /*
+        * querying the domain list using default buffer size
+        */
+
+       ZERO_STRUCT(r);
+       r.in.hostname = binding->host;
+
+       status = libnet_DomainList(ctx, mem_ctx, &r);
+       if (!NT_STATUS_IS_OK(status)) {
+               ret = False;
+               goto done;
+       }
+
+       d_printf("Received list or domains (everything in one piece):\n");
+       
+       for (i = 0; i < r.out.count; i++) {
+               d_printf("Name[%d]: %s\n", i, r.out.domains[i].name);
+       }
+
+       /*
+        * querying the domain list using specified (much smaller) buffer size
+        */
+
+       ctx->samr.buf_size = 32;
+
+       ZERO_STRUCT(r);
+       r.in.hostname = binding->host;
+
+       status = libnet_DomainList(ctx, mem_ctx, &r);
+       if (!NT_STATUS_IS_OK(status)) {
+               ret = False;
+               goto done;
+       }
+
+       d_printf("Received list or domains (collected in more than one round):\n");
+       
+       for (i = 0; i < r.out.count; i++) {
+               d_printf("Name[%d]: %s\n", i, r.out.domains[i].name);
+       }
+
+done:
+       d_printf("\nStatus: %s\n", nt_errstr(status));
+
+       talloc_free(mem_ctx);
+       talloc_free(ctx);
+       return ret;
+}