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 (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
24 * Copyright 2023 RackTop Systems, Inc.
25 */
26
27 /*
28 * Client side for the DSSETUP RPC service.
29 */
30
31 #include <string.h>
32 #include <strings.h>
33 #include <smb/wintypes.h>
34 #include <smbsrv/libsmb.h>
35 #include <smbsrv/ndl/dssetup.ndl>
36 #include <smbsrv/libmlsvc.h>
37
38 int
dssetup_get_domain_info(ds_primary_domain_info_t * ds_info)39 dssetup_get_domain_info(ds_primary_domain_info_t *ds_info)
40 {
41 dssetup_DsRoleGetPrimaryDomainInfo_t arg;
42 char user[SMB_USERNAME_MAXLEN];
43 struct dssetup_DsRolePrimaryDomInfo1 *info;
44 smb_domainex_t di;
45 mlsvc_handle_t handle;
46 int opnum;
47 int rc;
48
49 if (!smb_domain_getinfo(&di))
50 return (-1);
51
52 smb_ipc_get_user(user, sizeof (user));
53 if (ndr_rpc_bind(&handle, di.d_dci.dc_name, di.d_primary.di_nbname,
54 user, "DSSETUP") != 0)
55 return (-1);
56
57 opnum = DSSETUP_OPNUM_DsRoleGetPrimaryDomainInfo;
58 bzero(&arg, sizeof (dssetup_DsRoleGetPrimaryDomainInfo_t));
59 arg.level = DS_ROLE_BASIC_INFORMATION;
60
61 rc = ndr_rpc_call(&handle, opnum, &arg);
62 if ((rc != 0) || (arg.status != 0) || arg.info == NULL) {
63 ndr_rpc_unbind(&handle);
64 return (-1);
65 }
66
67 info = &arg.info->ru.info1;
68
69 if (info->nt_domain == NULL ||
70 info->dns_domain == NULL ||
71 info->forest == NULL) {
72 ndr_rpc_unbind(&handle);
73 return (-1);
74 }
75
76 bcopy(info, ds_info, sizeof (ds_primary_domain_info_t));
77 ds_info->nt_domain = (uint8_t *)strdup((char *)info->nt_domain);
78 ds_info->dns_domain = (uint8_t *)strdup((char *)info->dns_domain);
79 ds_info->forest = (uint8_t *)strdup((char *)info->forest);
80
81 ndr_rpc_unbind(&handle);
82 return (0);
83 }
84
85 /*
86 * Check whether our connection to the DC is working.
87 */
88 int
dssetup_check_service(void)89 dssetup_check_service(void)
90 {
91 ds_primary_domain_info_t ds_info;
92 int rc;
93
94 bzero(&ds_info, sizeof (ds_info));
95
96 if ((rc = dssetup_get_domain_info(&ds_info)) == 0) {
97 free(ds_info.nt_domain);
98 free(ds_info.dns_domain);
99 free(ds_info.forest);
100 }
101
102 return (rc);
103 }
104