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.
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.
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]
23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
39 idmap_lsa_xlate_sid_type(const lsa_account_t
*acct
, idmap_id_type
*ret_type
)
41 switch (acct
->a_sidtype
) {
45 case SidTypeDeletedAccount
:
48 *ret_type
= IDMAP_USID
;
49 return (IDMAP_SUCCESS
);
52 case SidTypeWellKnownGroup
:
53 *ret_type
= IDMAP_GSID
;
54 return (IDMAP_SUCCESS
);
58 idmapdlog(LOG_WARNING
,
59 "LSA lookup: bad type %d for %s@%s",
60 acct
->a_sidtype
, acct
->a_name
, acct
->a_domain
);
61 return (IDMAP_ERR_OTHER
);
66 /* Given SID, look up name and type */
69 const char *sidprefix
,
73 idmap_id_type
*ret_type
)
76 char sid
[SMB_SID_STRSZ
+ 1];
80 (void) memset(&acct
, 0, sizeof (acct
));
84 (void) snprintf(sid
, sizeof (sid
), "%s-%u", sidprefix
, rid
);
86 rc
= smb_lookup_sid(sid
, &acct
);
88 idmapdlog(LOG_ERR
, "Error: smb_lookup_sid failed.");
90 "Check SMB service (svc:/network/smb/server).");
92 "Check connectivity to Active Directory.");
94 ret
= IDMAP_ERR_OTHER
;
97 if (acct
.a_status
== NT_STATUS_NONE_MAPPED
) {
98 ret
= IDMAP_ERR_NOTFOUND
;
101 if (acct
.a_status
!= NT_STATUS_SUCCESS
) {
102 idmapdlog(LOG_WARNING
,
103 "Warning: smb_lookup_sid(%s) failed (0x%x)",
106 ret
= IDMAP_ERR_NOTFOUND
;
110 ret
= idmap_lsa_xlate_sid_type(&acct
, ret_type
);
111 if (ret
!= IDMAP_SUCCESS
)
114 *ret_name
= strdup(acct
.a_name
);
115 if (*ret_name
== NULL
) {
116 ret
= IDMAP_ERR_MEMORY
;
120 *ret_domain
= strdup(acct
.a_domain
);
121 if (*ret_domain
== NULL
) {
122 ret
= IDMAP_ERR_MEMORY
;
129 if (ret
!= IDMAP_SUCCESS
) {
138 /* Given name and optional domain, look up SID, type, and canonical name */
143 char **ret_sidprefix
,
147 idmap_id_type
*ret_type
)
150 char *namedom
= NULL
;
154 (void) memset(&acct
, 0, sizeof (acct
));
155 *ret_sidprefix
= NULL
;
156 if (ret_name
!= NULL
)
158 if (ret_domain
!= NULL
)
162 (void) asprintf(&namedom
, "%s@%s", name
, domain
);
164 namedom
= strdup(name
);
165 if (namedom
== NULL
) {
166 ret
= IDMAP_ERR_MEMORY
;
170 rc
= smb_lookup_name(namedom
, SidTypeUnknown
, &acct
);
172 idmapdlog(LOG_ERR
, "Error: smb_lookup_name failed.");
174 "Check SMB service (svc:/network/smb/server).");
176 "Check connectivity to Active Directory.");
177 ret
= IDMAP_ERR_OTHER
;
180 if (acct
.a_status
== NT_STATUS_NONE_MAPPED
) {
181 ret
= IDMAP_ERR_NOTFOUND
;
184 if (acct
.a_status
!= NT_STATUS_SUCCESS
) {
185 idmapdlog(LOG_WARNING
,
186 "Warning: smb_lookup_name(%s) failed (0x%x)",
187 namedom
, acct
.a_status
);
189 ret
= IDMAP_ERR_NOTFOUND
;
193 rc
= smb_sid_splitstr(acct
.a_sid
, ret_rid
);
195 *ret_sidprefix
= strdup(acct
.a_sid
);
196 if (*ret_sidprefix
== NULL
) {
197 ret
= IDMAP_ERR_MEMORY
;
201 ret
= idmap_lsa_xlate_sid_type(&acct
, ret_type
);
202 if (ret
!= IDMAP_SUCCESS
)
205 if (ret_name
!= NULL
) {
206 *ret_name
= strdup(acct
.a_name
);
207 if (*ret_name
== NULL
) {
208 ret
= IDMAP_ERR_MEMORY
;
213 if (ret_domain
!= NULL
) {
214 *ret_domain
= strdup(acct
.a_domain
);
215 if (*ret_domain
== NULL
) {
216 ret
= IDMAP_ERR_MEMORY
;
225 if (ret
!= IDMAP_SUCCESS
) {
226 if (ret_name
!= NULL
) {
230 if (ret_domain
!= NULL
) {
234 free(*ret_sidprefix
);
235 *ret_sidprefix
= NULL
;
241 * This exists just so we can avoid exposing all of idmapd to libsmb.h.
242 * Like the above functions, it's a door call over to smbd.
245 notify_dc_changed(void)
247 smb_notify_dc_changed();