View | Details | Raw Unified | Return to bug 24989
Collapse All | Expand All

(-)a/source4/libnet/libnet_join.c (-4 / +1 lines)
Lines 909-915 NTSTATUS libnet_Join_member(struct libnet_context *ctx, Link Here
909
		return NT_STATUS_NO_MEMORY;
909
		return NT_STATUS_NO_MEMORY;
910
	}
910
	}
911
911
912
	r2 = talloc(tmp_mem, struct libnet_JoinDomain);
912
	r2 = talloc_zero(tmp_mem, struct libnet_JoinDomain);
913
	if (!r2) {
913
	if (!r2) {
914
		r->out.error_string = NULL;
914
		r->out.error_string = NULL;
915
		talloc_free(tmp_mem);
915
		talloc_free(tmp_mem);
Lines 939-945 NTSTATUS libnet_Join_member(struct libnet_context *ctx, Link Here
939
	/*
939
	/*
940
	 * join the domain
940
	 * join the domain
941
	 */
941
	 */
942
	ZERO_STRUCTP(r2);
943
	r2->in.domain_name	= r->in.domain_name;
942
	r2->in.domain_name	= r->in.domain_name;
944
	r2->in.account_name	= account_name;
943
	r2->in.account_name	= account_name;
945
	r2->in.netbios_name	= netbios_name;
944
	r2->in.netbios_name	= netbios_name;
946
- 
947
--
948
source4/torture/rpc/testjoin.c |    4 ++--
945
source4/torture/rpc/testjoin.c |    4 ++--
949
1 files changed, 2 insertions(+), 2 deletions(-)
946
1 files changed, 2 insertions(+), 2 deletions(-)
(-)a/source4/torture/rpc/testjoin.c (-4 / +2 lines)
Lines 430-439 _PUBLIC_ struct test_join *torture_join_domain(struct torture_context *tctx, Link Here
430
	struct samr_SetUserInfo s;
430
	struct samr_SetUserInfo s;
431
	union samr_UserInfo u;
431
	union samr_UserInfo u;
432
	
432
	
433
	tj = talloc(tctx, struct test_join);
433
	tj = talloc_zero(tctx, struct test_join);
434
	if (!tj) return NULL;
434
	if (!tj) return NULL;
435
435
436
	libnet_r = talloc(tj, struct libnet_JoinDomain);
436
	libnet_r = talloc_zero(tj, struct libnet_JoinDomain);
437
	if (!libnet_r) {
437
	if (!libnet_r) {
438
		talloc_free(tj);
438
		talloc_free(tj);
439
		return NULL;
439
		return NULL;
440
- 
441
--
442
source4/libnet/py_net.c |    2 ++
440
source4/libnet/py_net.c |    2 ++
443
1 files changed, 2 insertions(+), 0 deletions(-)
441
1 files changed, 2 insertions(+), 0 deletions(-)
(-)a/source4/libnet/py_net.c (-2 / +2 lines)
Lines 51-56 static PyObject *py_net_join_member(py_net_Object *self, PyObject *args, PyObjec Link Here
51
	TALLOC_CTX *mem_ctx;
51
	TALLOC_CTX *mem_ctx;
52
	const char *kwnames[] = { "domain_name", "netbios_name", "level", NULL };
52
	const char *kwnames[] = { "domain_name", "netbios_name", "level", NULL };
53
53
54
	ZERO_STRUCT(r);
55
54
	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ssi:Join", discard_const_p(char *, kwnames),
56
	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ssi:Join", discard_const_p(char *, kwnames),
55
					 &r.in.domain_name, &r.in.netbios_name, 
57
					 &r.in.domain_name, &r.in.netbios_name, 
56
					 &_level)) {
58
					 &_level)) {
57
- 
58
--
59
source4/libnet/libnet_join.c |   18 ++++++++++++++----
59
source4/libnet/libnet_join.c |   18 ++++++++++++++----
60
source4/libnet/libnet_join.h |    2 ++
60
source4/libnet/libnet_join.h |    2 ++
61
2 files changed, 16 insertions(+), 4 deletions(-)
61
2 files changed, 16 insertions(+), 4 deletions(-)
(-)a/source4/libnet/libnet_join.c (-4 / +14 lines)
Lines 821-830 NTSTATUS libnet_JoinDomain(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, stru Link Here
821
	if (NT_STATUS_IS_OK(status)) {
821
	if (NT_STATUS_IS_OK(status)) {
822
		policy_min_pw_len = pwp.out.info->min_password_length;
822
		policy_min_pw_len = pwp.out.info->min_password_length;
823
	}
823
	}
824
	
824
825
	/* Grab a password of that minimum length */
825
	if (r->in.account_pass != NULL) {
826
	
826
		password_str = talloc_strdup(tmp_ctx, r->in.account_pass);
827
	password_str = generate_random_password(tmp_ctx, MAX(8, policy_min_pw_len), 255);
827
	} else {
828
		/* Grab a password of that minimum length */
829
		password_str = generate_random_password(tmp_ctx,
830
					MAX(8, policy_min_pw_len), 255);
831
	}
832
	if (!password_str) {
833
		r->out.error_string = NULL;
834
		talloc_free(tmp_ctx);
835
		return NT_STATUS_NO_MEMORY;
836
	}
828
837
829
	/* set full_name and reset flags */
838
	/* set full_name and reset flags */
830
	ZERO_STRUCT(u_info21);
839
	ZERO_STRUCT(u_info21);
Lines 945-950 NTSTATUS libnet_Join_member(struct libnet_context *ctx, Link Here
945
	r2->in.level		= LIBNET_JOINDOMAIN_AUTOMATIC;
954
	r2->in.level		= LIBNET_JOINDOMAIN_AUTOMATIC;
946
	r2->in.acct_type	= acct_type;
955
	r2->in.acct_type	= acct_type;
947
	r2->in.recreate_account = false;
956
	r2->in.recreate_account = false;
957
	r2->in.account_pass	= r->in.account_pass;
948
	status = libnet_JoinDomain(ctx, r2, r2);
958
	status = libnet_JoinDomain(ctx, r2, r2);
949
	if (!NT_STATUS_IS_OK(status)) {
959
	if (!NT_STATUS_IS_OK(status)) {
950
		r->out.error_string = talloc_steal(mem_ctx, r2->out.error_string);
960
		r->out.error_string = talloc_steal(mem_ctx, r2->out.error_string);
(-)a/source4/libnet/libnet_join.h (-2 / +2 lines)
Lines 43-48 struct libnet_JoinDomain { Link Here
43
		enum libnet_JoinDomain_level level;
43
		enum libnet_JoinDomain_level level;
44
		uint32_t  acct_type;
44
		uint32_t  acct_type;
45
		bool recreate_account;
45
		bool recreate_account;
46
		const char *account_pass;
46
	} in;
47
	} in;
47
48
48
	struct {
49
	struct {
Lines 68-73 struct libnet_Join_member { Link Here
68
		const char *domain_name;
69
		const char *domain_name;
69
		const char *netbios_name;
70
		const char *netbios_name;
70
		enum libnet_Join_level level;
71
		enum libnet_Join_level level;
72
		const char *account_pass;
71
	} in;
73
	} in;
72
	
74
	
73
	struct {
75
	struct {
74
- 
75
--
76
source4/libnet/py_net.c |    7 ++++---
76
source4/libnet/py_net.c |    7 ++++---
77
1 files changed, 4 insertions(+), 3 deletions(-)
77
1 files changed, 4 insertions(+), 3 deletions(-)
(-)a/source4/libnet/py_net.c (-5 / +4 lines)
Lines 49-61 static PyObject *py_net_join_member(py_net_Object *self, PyObject *args, PyObjec Link Here
49
	NTSTATUS status;
49
	NTSTATUS status;
50
	PyObject *result;
50
	PyObject *result;
51
	TALLOC_CTX *mem_ctx;
51
	TALLOC_CTX *mem_ctx;
52
	const char *kwnames[] = { "domain_name", "netbios_name", "level", NULL };
52
	const char *kwnames[] = { "domain_name", "netbios_name", "level", "machinepass", NULL };
53
53
54
	ZERO_STRUCT(r);
54
	ZERO_STRUCT(r);
55
55
56
	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ssi:Join", discard_const_p(char *, kwnames),
56
	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ssi|z:Join", discard_const_p(char *, kwnames),
57
					 &r.in.domain_name, &r.in.netbios_name, 
57
					 &r.in.domain_name, &r.in.netbios_name, 
58
					 &_level)) {
58
					 &_level,
59
					 &r.in.account_pass)) {
59
		return NULL;
60
		return NULL;
60
	}
61
	}
61
	r.in.level = _level;
62
	r.in.level = _level;
62
- 
63
--
64
source4/scripting/python/samba/join.py |    8 ++++++--
63
source4/scripting/python/samba/join.py |    8 ++++++--
65
1 files changed, 6 insertions(+), 2 deletions(-)
64
1 files changed, 6 insertions(+), 2 deletions(-)
(-)a/source4/scripting/python/samba/join.py (-4 / +6 lines)
Lines 48-54 class dc_join(object): Link Here
48
    '''perform a DC join'''
48
    '''perform a DC join'''
49
49
50
    def __init__(ctx, server=None, creds=None, lp=None, site=None,
50
    def __init__(ctx, server=None, creds=None, lp=None, site=None,
51
            netbios_name=None, targetdir=None, domain=None):
51
            netbios_name=None, targetdir=None, domain=None,
52
            machinepass=None):
52
        ctx.creds = creds
53
        ctx.creds = creds
53
        ctx.lp = lp
54
        ctx.lp = lp
54
        ctx.site = site
55
        ctx.site = site
Lines 90-96 class dc_join(object): Link Here
90
        ctx.dc_dnsHostName = ctx.get_dnsHostName()
91
        ctx.dc_dnsHostName = ctx.get_dnsHostName()
91
        ctx.behavior_version = ctx.get_behavior_version()
92
        ctx.behavior_version = ctx.get_behavior_version()
92
93
93
        ctx.acct_pass = samba.generate_random_password(32, 40)
94
        if machinepass is not None:
95
            ctx.acct_pass = machinepass
96
        else:
97
            ctx.acct_pass = samba.generate_random_password(32, 40)
94
98
95
        # work out the DNs of all the objects we will be adding
99
        # work out the DNs of all the objects we will be adding
96
        ctx.server_dn = "CN=%s,CN=Servers,CN=%s,CN=Sites,%s" % (ctx.myname, ctx.site, ctx.config_dn)
100
        ctx.server_dn = "CN=%s,CN=Servers,CN=%s,CN=Sites,%s" % (ctx.myname, ctx.site, ctx.config_dn)
97
- 
98
--
99
source4/scripting/python/samba/join.py |   18 ++++++++++++------
101
source4/scripting/python/samba/join.py |   18 ++++++++++++------
100
1 files changed, 12 insertions(+), 6 deletions(-)
102
1 files changed, 12 insertions(+), 6 deletions(-)
(-)a/source4/scripting/python/samba/join.py (-8 / +12 lines)
Lines 860-869 class dc_join(object): Link Here
860
860
861
861
862
def join_RODC(server=None, creds=None, lp=None, site=None, netbios_name=None,
862
def join_RODC(server=None, creds=None, lp=None, site=None, netbios_name=None,
863
              targetdir=None, domain=None, domain_critical_only=False):
863
              targetdir=None, domain=None, domain_critical_only=False,
864
              machinepass=None):
864
    """join as a RODC"""
865
    """join as a RODC"""
865
866
866
    ctx = dc_join(server, creds, lp, site, netbios_name, targetdir, domain)
867
    ctx = dc_join(server, creds, lp, site, netbios_name, targetdir, domain,
868
                  machinepass)
867
869
868
    lp.set("workgroup", ctx.domain_name)
870
    lp.set("workgroup", ctx.domain_name)
869
    print("workgroup is %s" % ctx.domain_name)
871
    print("workgroup is %s" % ctx.domain_name)
Lines 912-920 def join_RODC(server=None, creds=None, lp=None, site=None, netbios_name=None, Link Here
912
914
913
915
914
def join_DC(server=None, creds=None, lp=None, site=None, netbios_name=None,
916
def join_DC(server=None, creds=None, lp=None, site=None, netbios_name=None,
915
            targetdir=None, domain=None, domain_critical_only=False):
917
            targetdir=None, domain=None, domain_critical_only=False,
918
            machinepass=None):
916
    """join as a DC"""
919
    """join as a DC"""
917
    ctx = dc_join(server, creds, lp, site, netbios_name, targetdir, domain)
920
    ctx = dc_join(server, creds, lp, site, netbios_name, targetdir, domain,
921
                  machinepass)
918
922
919
    lp.set("workgroup", ctx.domain_name)
923
    lp.set("workgroup", ctx.domain_name)
920
    print("workgroup is %s" % ctx.domain_name)
924
    print("workgroup is %s" % ctx.domain_name)
Lines 940-948 def join_DC(server=None, creds=None, lp=None, site=None, netbios_name=None, Link Here
940
    print "Joined domain %s (SID %s) as a DC" % (ctx.domain_name, ctx.domsid)
944
    print "Joined domain %s (SID %s) as a DC" % (ctx.domain_name, ctx.domsid)
941
945
942
def join_subdomain(server=None, creds=None, lp=None, site=None, netbios_name=None,
946
def join_subdomain(server=None, creds=None, lp=None, site=None, netbios_name=None,
943
                   targetdir=None, parent_domain=None, dnsdomain=None, netbios_domain=None):
947
                   targetdir=None, parent_domain=None, dnsdomain=None, netbios_domain=None,
948
                   machinepass=None):
944
    """join as a DC"""
949
    """join as a DC"""
945
    ctx = dc_join(server, creds, lp, site, netbios_name, targetdir, parent_domain)
950
    ctx = dc_join(server, creds, lp, site, netbios_name, targetdir, parent_domain,
951
                  machinepass)
946
    ctx.subdomain = True
952
    ctx.subdomain = True
947
    ctx.parent_domain_name = ctx.domain_name
953
    ctx.parent_domain_name = ctx.domain_name
948
    ctx.domain_name = netbios_domain
954
    ctx.domain_name = netbios_domain
949
- 
950
--
951
source4/scripting/python/samba/netcmd/domain.py |   16 +++++++++++-----
955
source4/scripting/python/samba/netcmd/domain.py |   16 +++++++++++-----
952
1 files changed, 11 insertions(+), 5 deletions(-)
956
1 files changed, 11 insertions(+), 5 deletions(-)
(-)a/source4/scripting/python/samba/netcmd/domain.py (-7 / +11 lines)
Lines 115-127 class cmd_domain_join(Command): Link Here
115
        Option("--domain-critical-only",
115
        Option("--domain-critical-only",
116
               help="only replicate critical domain objects",
116
               help="only replicate critical domain objects",
117
               action="store_true"),
117
               action="store_true"),
118
        Option("--machinepass", type=str, metavar="PASSWORD",
119
               help="choose machine password (otherwise random)")
118
        ]
120
        ]
119
121
120
    takes_args = ["domain", "role?"]
122
    takes_args = ["domain", "role?"]
121
123
122
    def run(self, domain, role=None, sambaopts=None, credopts=None,
124
    def run(self, domain, role=None, sambaopts=None, credopts=None,
123
            versionopts=None, server=None, site=None, targetdir=None,
125
            versionopts=None, server=None, site=None, targetdir=None,
124
            domain_critical_only=False, parent_domain=None):
126
            domain_critical_only=False, parent_domain=None, machinepass=None):
125
        lp = sambaopts.get_loadparm()
127
        lp = sambaopts.get_loadparm()
126
        creds = credopts.get_credentials(lp)
128
        creds = credopts.get_credentials(lp)
127
        net = Net(creds, lp, server=credopts.ipaddress)
129
        net = Net(creds, lp, server=credopts.ipaddress)
Lines 137-162 class cmd_domain_join(Command): Link Here
137
        if role is None or role == "MEMBER":
139
        if role is None or role == "MEMBER":
138
            (join_password, sid, domain_name) = net.join_member(domain,
140
            (join_password, sid, domain_name) = net.join_member(domain,
139
                                                                netbios_name,
141
                                                                netbios_name,
140
                                                                LIBNET_JOIN_AUTOMATIC)
142
                                                                LIBNET_JOIN_AUTOMATIC,
143
                                                                machinepass=machinepass)
141
144
142
            self.outf.write("Joined domain %s (%s)\n" % (domain_name, sid))
145
            self.outf.write("Joined domain %s (%s)\n" % (domain_name, sid))
143
            return
146
            return
144
        elif role == "DC":
147
        elif role == "DC":
145
            join_DC(server=server, creds=creds, lp=lp, domain=domain,
148
            join_DC(server=server, creds=creds, lp=lp, domain=domain,
146
                    site=site, netbios_name=netbios_name, targetdir=targetdir,
149
                    site=site, netbios_name=netbios_name, targetdir=targetdir,
147
                    domain_critical_only=domain_critical_only)
150
                    domain_critical_only=domain_critical_only,
151
                    machinepass=machinepass)
148
            return
152
            return
149
        elif role == "RODC":
153
        elif role == "RODC":
150
            join_RODC(server=server, creds=creds, lp=lp, domain=domain,
154
            join_RODC(server=server, creds=creds, lp=lp, domain=domain,
151
                      site=site, netbios_name=netbios_name, targetdir=targetdir,
155
                      site=site, netbios_name=netbios_name, targetdir=targetdir,
152
                      domain_critical_only=domain_critical_only)
156
                      domain_critical_only=domain_critical_only,
157
                      machinepass=machinepass)
153
            return
158
            return
154
        elif role == "SUBDOMAIN":
159
        elif role == "SUBDOMAIN":
155
            netbios_domain = lp.get("workgroup")
160
            netbios_domain = lp.get("workgroup")
156
            if parent_domain is None:
161
            if parent_domain is None:
157
                parent_domain = ".".join(domain.split(".")[1:])
162
                parent_domain = ".".join(domain.split(".")[1:])
158
            join_subdomain(server=server, creds=creds, lp=lp, dnsdomain=domain, parent_domain=parent_domain,
163
            join_subdomain(server=server, creds=creds, lp=lp, dnsdomain=domain, parent_domain=parent_domain,
159
                           site=site, netbios_name=netbios_name, netbios_domain=netbios_domain, targetdir=targetdir)
164
                           site=site, netbios_name=netbios_name, netbios_domain=netbios_domain, targetdir=targetdir,
165
                           machinepass=machinepass)
160
            return
166
            return
161
        else:
167
        else:
162
            raise CommandError("Invalid role '%s' (possible values: MEMBER, DC, RODC, SUBDOMAIN)" % role)
168
            raise CommandError("Invalid role '%s' (possible values: MEMBER, DC, RODC, SUBDOMAIN)" % role)
163
- 
164
--
165
selftest/target/Samba4.pm |    4 ++++
169
selftest/target/Samba4.pm |    4 ++++
166
1 files changed, 4 insertions(+), 0 deletions(-)
170
1 files changed, 4 insertions(+), 0 deletions(-)
(-)a/selftest/target/Samba4.pm (-1 / +4 lines)
Lines 869-874 sub provision_member($$$) Link Here
869
	$cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
869
	$cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
870
	$cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
870
	$cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
871
	$cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
871
	$cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
872
	$cmd .= " --machinepass=machine$ret->{password}";
872
873
873
	unless (system($cmd) == 0) {
874
	unless (system($cmd) == 0) {
874
		warn("Join failed\n$cmd");
875
		warn("Join failed\n$cmd");
Lines 937-942 sub provision_rpc_proxy($$$) Link Here
937
	$cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
938
	$cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
938
	$cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
939
	$cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
939
	$cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
940
	$cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
941
	$cmd .= " --machinepass=machine$ret->{password}";
940
942
941
	unless (system($cmd) == 0) {
943
	unless (system($cmd) == 0) {
942
		warn("Join failed\n$cmd");
944
		warn("Join failed\n$cmd");
Lines 1021-1026 sub provision_vampire_dc($$$) Link Here
1021
	$cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1023
	$cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1022
	$cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1024
	$cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1023
	$cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1025
	$cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1026
	$cmd .= " --machinepass=machine$ret->{password}";
1024
1027
1025
	unless (system($cmd) == 0) {
1028
	unless (system($cmd) == 0) {
1026
		warn("Join failed\n$cmd");
1029
		warn("Join failed\n$cmd");
Lines 1083-1088 sub provision_subdom_dc($$$) Link Here
1083
	$cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1086
	$cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1084
	$cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $ctx->{realm} subdomain ";
1087
	$cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $ctx->{realm} subdomain ";
1085
	$cmd .= "--parent-domain=$dcvars->{REALM} -U$dcvars->{DC_USERNAME}\@$dcvars->{REALM}\%$dcvars->{DC_PASSWORD}";
1088
	$cmd .= "--parent-domain=$dcvars->{REALM} -U$dcvars->{DC_USERNAME}\@$dcvars->{REALM}\%$dcvars->{DC_PASSWORD}";
1089
	$cmd .= " --machinepass=machine$ret->{password}";
1086
1090
1087
	unless (system($cmd) == 0) {
1091
	unless (system($cmd) == 0) {
1088
		warn("Join failed\n$cmd");
1092
		warn("Join failed\n$cmd");
1089
- 

Return to bug 24989