xref: /titanic_41/usr/src/lib/smbsrv/libmlsvc/common/dssetup_clnt.c (revision 635216b673cf196ac523ff2a7ab715717e553292)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * Client side for the DSSETUP RPC service.
28  */
29 
30 #include <string.h>
31 #include <strings.h>
32 #include <smbsrv/wintypes.h>
33 #include <smbsrv/libsmb.h>
34 #include <smbsrv/ndl/dssetup.ndl>
35 #include <smbsrv/libmlsvc.h>
36 
37 int
38 dssetup_get_domain_info(ds_primary_domain_info_t *ds_info)
39 {
40 	dssetup_DsRoleGetPrimaryDomainInfo_t arg;
41 	struct dssetup_DsRolePrimaryDomInfo1 *info;
42 	smb_domainex_t di;
43 	mlsvc_handle_t handle;
44 	int opnum;
45 	int rc;
46 
47 	if (!smb_domain_getinfo(&di))
48 		return (-1);
49 
50 	if (ndr_rpc_bind(&handle, di.d_dc, di.d_primary.di_nbname,
51 	    MLSVC_ANON_USER, "DSSETUP") != 0)
52 		return (-1);
53 
54 	opnum = DSSETUP_OPNUM_DsRoleGetPrimaryDomainInfo;
55 	bzero(&arg, sizeof (dssetup_DsRoleGetPrimaryDomainInfo_t));
56 	arg.level = DS_ROLE_BASIC_INFORMATION;
57 
58 	rc = ndr_rpc_call(&handle, opnum, &arg);
59 	if ((rc != 0) || (arg.status != 0) || arg.info == NULL) {
60 		ndr_rpc_unbind(&handle);
61 		return (-1);
62 	}
63 
64 	info = &arg.info->ru.info1;
65 
66 	if (info->nt_domain == NULL ||
67 	    info->dns_domain == NULL ||
68 	    info->forest == NULL) {
69 		ndr_rpc_unbind(&handle);
70 		return (-1);
71 	}
72 
73 	bcopy(info, ds_info, sizeof (ds_primary_domain_info_t));
74 	ds_info->nt_domain = (uint8_t *)strdup((char *)info->nt_domain);
75 	ds_info->dns_domain = (uint8_t *)strdup((char *)info->dns_domain);
76 	ds_info->forest = (uint8_t *)strdup((char *)info->forest);
77 
78 	ndr_rpc_unbind(&handle);
79 	return (0);
80 }
81