Print this page
1575 untangle libmlrpc ... (smbsrv)
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/smbsrv/libmlsvc/common/dssetup_svc.c
+++ new/usr/src/lib/smbsrv/libmlsvc/common/dssetup_svc.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 + * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
24 25 */
25 26
26 27 /*
27 28 * Active Directory Setup RPC interface used by Windows 2000.
28 29 */
29 30
30 31 #include <synch.h>
31 32 #include <strings.h>
32 33 #include <stdlib.h>
33 34 #include <netdb.h>
34 35
36 +#include <libmlrpc/libmlrpc.h>
35 37 #include <smbsrv/libsmb.h>
36 -#include <smbsrv/libmlrpc.h>
37 38 #include <smbsrv/libmlsvc.h>
38 39 #include <smbsrv/ndl/dssetup.ndl>
39 40 #include <smbsrv/smbinfo.h>
40 41 #include <smbsrv/nmpipes.h>
41 42
42 43 int dssetup_get_domain_info(ds_primary_domain_info_t *);
43 44
44 45 static int dssetup_DsRoleGetPrimaryDomainInfo(void *, ndr_xa_t *);
45 46 static uint32_t dssetup_member_server(ds_primary_domain_info_t *, ndr_xa_t *);
46 47 static uint32_t dssetup_standalone_server(ds_primary_domain_info_t *,
47 48 ndr_xa_t *);
48 49
49 50 static ndr_stub_table_t dssetup_stub_table[] = {
50 51 { dssetup_DsRoleGetPrimaryDomainInfo,
51 52 DSSETUP_OPNUM_DsRoleGetPrimaryDomainInfo },
52 53 {0}
53 54 };
54 55
55 56 static ndr_service_t dssetup_service = {
56 57 "DSSETUP", /* name */
57 58 "Active Directory Setup", /* desc */
58 59 "\\lsarpc", /* endpoint */
59 60 PIPE_LSASS, /* sec_addr_port */
60 61 "3919286a-b10c-11d0-9ba8-00c04fd92ef5", 0, /* abstract */
61 62 NDR_TRANSFER_SYNTAX_UUID, 2, /* transfer */
62 63 0, /* no bind_instance_size */
63 64 0, /* no bind_req() */
64 65 0, /* no unbind_and_close() */
65 66 0, /* use generic_call_stub() */
66 67 &TYPEINFO(dssetup_interface), /* interface ti */
67 68 dssetup_stub_table /* stub_table */
68 69 };
69 70
70 71 static ds_primary_domain_info_t ds_info;
71 72 static mutex_t ds_info_mtx;
72 73
73 74 /*
74 75 * dssetup_initialize
75 76 *
76 77 * This function registers the DSSETUP interface with the RPC runtime
77 78 * library. It must be called in order to use either the client side
78 79 * or the server side functions.
79 80 */
80 81 void
81 82 dssetup_initialize(void)
82 83 {
83 84 dssetup_clear_domain_info();
84 85 (void) ndr_svc_register(&dssetup_service);
85 86 }
86 87
87 88 void
88 89 dssetup_clear_domain_info(void)
89 90 {
90 91 (void) mutex_lock(&ds_info_mtx);
91 92
92 93 free(ds_info.nt_domain);
93 94 free(ds_info.dns_domain);
94 95 free(ds_info.forest);
95 96 bzero(&ds_info, sizeof (ds_primary_domain_info_t));
96 97
97 98 (void) mutex_unlock(&ds_info_mtx);
98 99 }
99 100
100 101 /*
101 102 * Request for machine role and primary domain information.
102 103 */
103 104 static int
104 105 dssetup_DsRoleGetPrimaryDomainInfo(void *arg, ndr_xa_t *mxa)
105 106 {
106 107 dssetup_DsRoleGetPrimaryDomainInfo_t *param = arg;
107 108 dssetup_GetPrimaryDomainInfo_t *info;
108 109 ds_primary_domain_info_t *info1;
109 110 uint32_t status;
110 111 int security_mode;
111 112
112 113 info = NDR_MALLOC(mxa, sizeof (dssetup_GetPrimaryDomainInfo_t));
113 114 if (info == NULL) {
114 115 status = NT_STATUS_NO_MEMORY;
115 116 } else if (param->level != DS_ROLE_BASIC_INFORMATION) {
116 117 status = NT_STATUS_INVALID_LEVEL;
117 118 } else {
118 119 info->switch_value = param->level;
119 120 info1 = &info->ru.info1;
120 121
121 122 security_mode = smb_config_get_secmode();
122 123
123 124 if (security_mode == SMB_SECMODE_DOMAIN)
124 125 status = dssetup_member_server(info1, mxa);
125 126 else
126 127 status = dssetup_standalone_server(info1, mxa);
127 128 }
128 129
129 130 if (status != NT_STATUS_SUCCESS) {
130 131 bzero(param, sizeof (dssetup_DsRoleGetPrimaryDomainInfo_t));
131 132 param->status = NT_SC_ERROR(status);
132 133 } else {
133 134 param->info = info;
134 135 param->status = NT_STATUS_SUCCESS;
135 136 }
136 137
137 138 return (NDR_DRC_OK);
138 139 }
139 140
140 141 /*
141 142 * When the machine role is domain member:
142 143 * nt_domain must contain the NetBIOS domain name
143 144 * dns_domain must contain the DNS domain name (cannot be NULL)
144 145 * forest must contain the forest name (cannot be NULL)
145 146 *
146 147 * If DS_ROLE_PRIMARY_DOMAIN_GUID_PRESENT is set in flags, the domain_guid
147 148 * must contain the domain UUID. Otherwise domain_guid is ignored.
148 149 */
149 150 static uint32_t
150 151 dssetup_member_server(ds_primary_domain_info_t *info, ndr_xa_t *mxa)
151 152 {
152 153 char dns_domain[MAXHOSTNAMELEN];
153 154 char nt_domain[MAXHOSTNAMELEN];
154 155
155 156 (void) mutex_lock(&ds_info_mtx);
156 157
157 158 if ((ds_info.flags & DS_ROLE_PRIMARY_DOMAIN_GUID_PRESENT) == 0) {
158 159 /*
159 160 * If we don't have the domain GUID, try to get it from a
160 161 * domain controller. Otherwise, use local configuration.
161 162 */
162 163 free(ds_info.nt_domain);
163 164 free(ds_info.dns_domain);
164 165 free(ds_info.forest);
165 166 (void) dssetup_get_domain_info(&ds_info);
166 167 }
167 168
168 169 if (ds_info.flags & DS_ROLE_PRIMARY_DOMAIN_GUID_PRESENT) {
169 170 info->flags = DS_ROLE_PRIMARY_DOMAIN_GUID_PRESENT;
170 171 info->nt_domain = NDR_STRDUP(mxa, (char *)ds_info.nt_domain);
171 172 info->dns_domain = NDR_STRDUP(mxa, (char *)ds_info.dns_domain);
172 173 info->forest = NDR_STRDUP(mxa, (char *)ds_info.forest);
173 174 bcopy(&ds_info.domain_guid, &info->domain_guid,
174 175 sizeof (ndr_uuid_t));
175 176 } else {
176 177 if (smb_getdomainname(nt_domain, MAXHOSTNAMELEN) != 0) {
177 178 (void) mutex_unlock(&ds_info_mtx);
178 179 return (NT_STATUS_CANT_ACCESS_DOMAIN_INFO);
179 180 }
180 181
181 182 if (smb_getfqdomainname(dns_domain, MAXHOSTNAMELEN) != 0) {
182 183 (void) mutex_unlock(&ds_info_mtx);
183 184 return (NT_STATUS_CANT_ACCESS_DOMAIN_INFO);
184 185 }
185 186
186 187 (void) smb_strlwr(dns_domain);
187 188
188 189 info->flags = 0;
189 190 info->nt_domain = NDR_STRDUP(mxa, nt_domain);
190 191 info->dns_domain = NDR_STRDUP(mxa, dns_domain);
191 192 info->forest = NDR_STRDUP(mxa, dns_domain);
192 193 bzero(&info->domain_guid, sizeof (ndr_uuid_t));
193 194 }
194 195
195 196 (void) mutex_unlock(&ds_info_mtx);
196 197
197 198 if (info->nt_domain == NULL ||
198 199 info->dns_domain == NULL ||
199 200 info->forest == NULL)
200 201 return (NT_STATUS_NO_MEMORY);
201 202
202 203 info->role = DS_ROLE_MEMBER_SERVER;
203 204 return (NT_STATUS_SUCCESS);
204 205 }
205 206
206 207 /*
207 208 * When the machine role is standalone:
208 209 * nt_domain must contain the NetBIOS workgroup name
209 210 * dns_domain must be NULL
210 211 * forest must be NULL
211 212 *
212 213 * We don't maintain a domain GUID. When DS_ROLE_PRIMARY_DOMAIN_GUID_PRESENT
213 214 * is not set in flags, domain_guid is ignored.
214 215 */
215 216 static uint32_t
216 217 dssetup_standalone_server(ds_primary_domain_info_t *info, ndr_xa_t *mxa)
217 218 {
218 219 char nt_domain[MAXHOSTNAMELEN];
219 220
220 221 if (smb_getdomainname(nt_domain, MAXHOSTNAMELEN) != 0)
221 222 return (NT_STATUS_CANT_ACCESS_DOMAIN_INFO);
222 223
223 224 info->nt_domain = NDR_STRDUP(mxa, nt_domain);
224 225 if (info->nt_domain == NULL)
225 226 return (NT_STATUS_NO_MEMORY);
226 227
227 228 info->role = DS_ROLE_STANDALONE_SERVER;
228 229 info->flags = 0;
229 230 info->dns_domain = NULL;
230 231 info->forest = NULL;
231 232 bzero(&info->domain_guid, sizeof (ndr_uuid_t));
232 233 return (NT_STATUS_SUCCESS);
233 234 }
↓ open down ↓ |
187 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX