r23792: convert Samba4 to GPLv3
[samba.git] / source4 / torture / rpc / testjoin.c
index 690388f6689ea95a983320179c591174af78de61..a4f6a3207c3c93208d083cd6ebc4896394eb703f 100644 (file)
@@ -7,7 +7,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -16,8 +16,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 /*
@@ -43,7 +42,11 @@ struct test_join {
        struct policy_handle user_handle;
        struct libnet_JoinDomain *libnet_r;
        struct dom_sid *dom_sid;
+       const char *dom_netbios_name;
+       const char *dom_dns_name;
        struct dom_sid *user_sid;
+       struct GUID user_guid;
+       const char *netbios_name;
 };
 
 
@@ -121,6 +124,7 @@ struct test_join *torture_create_testuser(const char *username,
        int policy_min_pw_len = 0;
        struct test_join *join;
        char *random_pw;
+       const char *dc_binding = lp_parm_string(-1, "torture", "dc_binding");
 
        join = talloc(NULL, struct test_join);
        if (join == NULL) {
@@ -130,10 +134,19 @@ struct test_join *torture_create_testuser(const char *username,
        ZERO_STRUCTP(join);
 
        printf("Connecting to SAMR\n");
-
-       status = torture_rpc_connection(join, 
-                                       &join->p, 
-                                       &dcerpc_table_samr);
+       
+       if (dc_binding) {
+               status = dcerpc_pipe_connect(join,
+                                            &join->p,
+                                            dc_binding,
+                                            &dcerpc_table_samr,
+                                            cmdline_credentials, NULL);
+                                            
+       } else {
+               status = torture_rpc_connection(join, 
+                                               &join->p, 
+                                               &dcerpc_table_samr);
+       }
        if (!NT_STATUS_IS_OK(status)) {
                return NULL;
        }
@@ -166,6 +179,8 @@ struct test_join *torture_create_testuser(const char *username,
 
        talloc_steal(join, l.out.sid);
        join->dom_sid = l.out.sid;
+       join->dom_netbios_name = talloc_strdup(join, domain);
+       if (!join->dom_netbios_name) goto failed;
 
        o.in.connect_handle = &handle;
        o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
@@ -245,7 +260,7 @@ again:
        s.in.info = &u;
        s.in.level = 21;
 
-       u.info21.acct_flags = acct_type;
+       u.info21.acct_flags = acct_type | ACB_PWNOEXP;
        u.info21.fields_present = SAMR_FIELD_ACCT_FLAGS | SAMR_FIELD_DESCRIPTION | SAMR_FIELD_COMMENT | SAMR_FIELD_FULL_NAME;
 
        u.info21.comment.string = talloc_asprintf(join, 
@@ -338,6 +353,16 @@ _PUBLIC_ struct test_join *torture_join_domain(const char *machine_name,
        tj->user_handle = *libnet_r->out.user_handle;
        tj->dom_sid = libnet_r->out.domain_sid;
        talloc_steal(tj, libnet_r->out.domain_sid);
+       tj->dom_netbios_name    = libnet_r->out.domain_name;
+       talloc_steal(tj, libnet_r->out.domain_name);
+       tj->dom_dns_name        = libnet_r->out.realm;
+       talloc_steal(tj, libnet_r->out.realm);
+       tj->user_guid = libnet_r->out.account_guid;
+       tj->netbios_name = talloc_strdup(tj, machine_name);
+       if (!tj->netbios_name) {
+               talloc_free(tj);
+               return NULL;
+       }
 
        ZERO_STRUCT(u);
        s.in.user_handle = &tj->user_handle;
@@ -503,6 +528,26 @@ const struct dom_sid *torture_join_user_sid(struct test_join *join)
        return join->user_sid;
 }
 
+const char *torture_join_netbios_name(struct test_join *join)
+{
+       return join->netbios_name;
+}
+
+const struct GUID *torture_join_user_guid(struct test_join *join)
+{
+       return &join->user_guid;
+}
+
+const char *torture_join_dom_netbios_name(struct test_join *join)
+{
+       return join->dom_netbios_name;
+}
+
+const char *torture_join_dom_dns_name(struct test_join *join)
+{
+       return join->dom_dns_name;
+}
+
 
 struct test_join_ads_dc {
        struct test_join *join;
@@ -620,59 +665,13 @@ struct test_join_ads_dc *torture_join_domain_ads_dc(const char *machine_name,
         * CN=NTDS Settings,CN=<machine_name>,CN=Servers,CN=Default-First-Site-Name, ...
         */
 
-/* W2K3: */
-
-       /* DsAddEntry to create the CN=NTDS Settings,CN=<machine_name>,CN=Servers,CN=Default-First-Site-Name, ...
-        *
-        */
-
-       /* replicate CN=Schema,CN=Configuration,...
-        * using DRSUAPI_DS_BIND_GUID_W2K3 ("6afab99c-6e26-464a-975f-f58f105218bc")
-        *
-        */
-
-       /* replicate CN=Configuration,...
-        * using DRSUAPI_DS_BIND_GUID_W2K3 ("6afab99c-6e26-464a-975f-f58f105218bc")
-        *
-        */
-
-       /* W2K3: modify userAccountControl from 4096 to 532480 */
-       
-       /* W2K3: modify RDN to OU=Domain Controllers and skip the $ from server name */
-
-       /* replicate Domain Partition
-        * using DRSUAPI_DS_BIND_GUID_W2K3 ("6afab99c-6e26-464a-975f-f58f105218bc")
-        *
-        */
-
-       /* call DsReplicaUpdateRefs() for all partitions like this:
-        *     req1: struct drsuapi_DsReplicaUpdateRefsRequest1
-        *           naming_context           : *
-        *                 naming_context: struct drsuapi_DsReplicaObjectIdentifier
-        *                     __ndr_size               : 0x000000ae (174)
-        *                     __ndr_size_sid           : 0x00000000 (0)
-        *                     guid                     : 00000000-0000-0000-0000-000000000000
-        *                     sid                      : S-0-0
-        *                     dn                       : 'CN=Schema,CN=Configuration,DC=w2k3,DC=vmnet1,DC=vm,DC=base'
-        *           dest_dsa_dns_name        : *
-        *                 dest_dsa_dns_name        : '4a0df188-a0b8-47ea-bbe5-e614723f16dd._msdcs.w2k3.vmnet1.vm.base'
-        *           dest_dsa_guid            : 4a0df188-a0b8-47ea-bbe5-e614723f16dd
-        *           options                  : 0x0000001c (28)
-        *                 0: DRSUAPI_DS_REPLICA_UPDATE_ASYNCHRONOUS_OPERATION
-        *                 0: DRSUAPI_DS_REPLICA_UPDATE_WRITEABLE
-        *                 1: DRSUAPI_DS_REPLICA_UPDATE_ADD_REFERENCE
-        *                 1: DRSUAPI_DS_REPLICA_UPDATE_DELETE_REFERENCE
-        *                 1: DRSUAPI_DS_REPLICA_UPDATE_0x00000010      
-        *
-        * 4a0df188-a0b8-47ea-bbe5-e614723f16dd is the objectGUID the DsAddEntry() returned for the
-        * CN=NTDS Settings,CN=<machine_name>,CN=Servers,CN=Default-First-Site-Name, ...
-        */
-
+/* W2K3: see libnet/libnet_become_dc.c */
        return join;
 }
                
 void torture_leave_domain_ads_dc(struct test_join_ads_dc *join)
 {
+/* W2K3: see libnet/libnet_unbecome_dc.c */
 
        if (join->join) {
                torture_leave_domain(join->join);