xref: /titanic_41/usr/src/lib/smbsrv/libmlsvc/common/dssetup_clnt.c (revision a7df97bafe5a886e6ddb3fe8170b2d547cd3b029)
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/libsmbrdr.h>
35 #include <smbsrv/ndl/dssetup.ndl>
36 #include <smbsrv/libmlsvc.h>
37 
38 int
39 dssetup_get_domain_info(ds_primary_domain_info_t *ds_info)
40 {
41 	dssetup_DsRoleGetPrimaryDomainInfo_t arg;
42 	struct dssetup_DsRolePrimaryDomInfo1 *info;
43 	smb_domain_t di;
44 	mlsvc_handle_t handle;
45 	int opnum;
46 	int rc;
47 
48 	if (!smb_domain_getinfo(&di))
49 		return (-1);
50 
51 	if (ndr_rpc_bind(&handle, di.d_dc, di.d_info.di_nbname,
52 	    MLSVC_ANON_USER, "DSSETUP") != 0)
53 		return (-1);
54 
55 	opnum = DSSETUP_OPNUM_DsRoleGetPrimaryDomainInfo;
56 	bzero(&arg, sizeof (dssetup_DsRoleGetPrimaryDomainInfo_t));
57 	arg.level = DS_ROLE_BASIC_INFORMATION;
58 
59 	rc = ndr_rpc_call(&handle, opnum, &arg);
60 	if ((rc != 0) || (arg.status != 0) || arg.info == NULL) {
61 		ndr_rpc_unbind(&handle);
62 		return (-1);
63 	}
64 
65 	info = &arg.info->ru.info1;
66 
67 	if (info->nt_domain == NULL ||
68 	    info->dns_domain == NULL ||
69 	    info->forest == NULL) {
70 		ndr_rpc_unbind(&handle);
71 		return (-1);
72 	}
73 
74 	bcopy(info, ds_info, sizeof (ds_primary_domain_info_t));
75 	ds_info->nt_domain = (uint8_t *)strdup((char *)info->nt_domain);
76 	ds_info->dns_domain = (uint8_t *)strdup((char *)info->dns_domain);
77 	ds_info->forest = (uint8_t *)strdup((char *)info->forest);
78 
79 	ndr_rpc_unbind(&handle);
80 	return (0);
81 }
82