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 /*
23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
25 */
26
27 /*
28 * LSA lookups
29 */
30
31 #include <stdio.h>
32 #include <note.h>
33 #include <assert.h>
34
35 #include "idmapd.h"
36 #include "libsmb.h"
37
38 idmap_retcode
39 idmap_lsa_xlate_sid_type(const lsa_account_t *acct, idmap_id_type *ret_type)
40 {
41 switch (acct->a_sidtype) {
42 case SidTypeUser:
43 case SidTypeComputer:
44 case SidTypeDomain:
66 /* Given SID, look up name and type */
67 idmap_retcode
68 lookup_lsa_by_sid(
69 const char *sidprefix,
70 uint32_t rid,
71 char **ret_name,
72 char **ret_domain,
73 idmap_id_type *ret_type)
74 {
75 lsa_account_t acct;
76 char sid[SMB_SID_STRSZ + 1];
77 idmap_retcode ret;
78 int rc;
79
80 (void) memset(&acct, 0, sizeof (acct));
81 *ret_name = NULL;
82 *ret_domain = NULL;
83
84 (void) snprintf(sid, sizeof (sid), "%s-%u", sidprefix, rid);
85
86 rc = smb_lookup_sid(sid, &acct);
87 if (rc != 0) {
88 idmapdlog(LOG_ERR, "Error: smb_lookup_sid failed.");
89 idmapdlog(LOG_ERR,
90 "Check SMB service (svc:/network/smb/server).");
91 idmapdlog(LOG_ERR,
92 "Check connectivity to Active Directory.");
93
94 ret = IDMAP_ERR_OTHER;
95 goto out;
96 }
97 if (acct.a_status == NT_STATUS_NONE_MAPPED) {
98 ret = IDMAP_ERR_NOTFOUND;
99 goto out;
100 }
101 if (acct.a_status != NT_STATUS_SUCCESS) {
102 idmapdlog(LOG_WARNING,
103 "Warning: smb_lookup_sid(%s) failed (0x%x)",
104 sid, acct.a_status);
105 /* Fail soft */
106 ret = IDMAP_ERR_NOTFOUND;
150 char *namedom = NULL;
151 idmap_retcode ret;
152 int rc;
153
154 (void) memset(&acct, 0, sizeof (acct));
155 *ret_sidprefix = NULL;
156 if (ret_name != NULL)
157 *ret_name = NULL;
158 if (ret_domain != NULL)
159 *ret_domain = NULL;
160
161 if (domain != NULL)
162 (void) asprintf(&namedom, "%s@%s", name, domain);
163 else
164 namedom = strdup(name);
165 if (namedom == NULL) {
166 ret = IDMAP_ERR_MEMORY;
167 goto out;
168 }
169
170 rc = smb_lookup_name(namedom, SidTypeUnknown, &acct);
171 if (rc != 0) {
172 idmapdlog(LOG_ERR, "Error: smb_lookup_name failed.");
173 idmapdlog(LOG_ERR,
174 "Check SMB service (svc:/network/smb/server).");
175 idmapdlog(LOG_ERR,
176 "Check connectivity to Active Directory.");
177 ret = IDMAP_ERR_OTHER;
178 goto out;
179 }
180 if (acct.a_status == NT_STATUS_NONE_MAPPED) {
181 ret = IDMAP_ERR_NOTFOUND;
182 goto out;
183 }
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);
188 /* Fail soft */
189 ret = IDMAP_ERR_NOTFOUND;
190 goto out;
|
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 /*
23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2019 Nexenta Systems, Inc. All rights reserved.
25 */
26
27 /*
28 * LSA lookups
29 */
30
31 #include <stdio.h>
32 #include <note.h>
33 #include <assert.h>
34
35 #include "idmapd.h"
36 #include "libsmb.h"
37
38 idmap_retcode
39 idmap_lsa_xlate_sid_type(const lsa_account_t *acct, idmap_id_type *ret_type)
40 {
41 switch (acct->a_sidtype) {
42 case SidTypeUser:
43 case SidTypeComputer:
44 case SidTypeDomain:
66 /* Given SID, look up name and type */
67 idmap_retcode
68 lookup_lsa_by_sid(
69 const char *sidprefix,
70 uint32_t rid,
71 char **ret_name,
72 char **ret_domain,
73 idmap_id_type *ret_type)
74 {
75 lsa_account_t acct;
76 char sid[SMB_SID_STRSZ + 1];
77 idmap_retcode ret;
78 int rc;
79
80 (void) memset(&acct, 0, sizeof (acct));
81 *ret_name = NULL;
82 *ret_domain = NULL;
83
84 (void) snprintf(sid, sizeof (sid), "%s-%u", sidprefix, rid);
85
86 rc = smb_lookup_lsid(sid, &acct);
87 if (rc != 0) {
88 idmapdlog(LOG_ERR, "Error: smb_lookup_sid failed.");
89 idmapdlog(LOG_ERR,
90 "Check SMB service (svc:/network/smb/server).");
91 idmapdlog(LOG_ERR,
92 "Check connectivity to Active Directory.");
93
94 ret = IDMAP_ERR_OTHER;
95 goto out;
96 }
97 if (acct.a_status == NT_STATUS_NONE_MAPPED) {
98 ret = IDMAP_ERR_NOTFOUND;
99 goto out;
100 }
101 if (acct.a_status != NT_STATUS_SUCCESS) {
102 idmapdlog(LOG_WARNING,
103 "Warning: smb_lookup_sid(%s) failed (0x%x)",
104 sid, acct.a_status);
105 /* Fail soft */
106 ret = IDMAP_ERR_NOTFOUND;
150 char *namedom = NULL;
151 idmap_retcode ret;
152 int rc;
153
154 (void) memset(&acct, 0, sizeof (acct));
155 *ret_sidprefix = NULL;
156 if (ret_name != NULL)
157 *ret_name = NULL;
158 if (ret_domain != NULL)
159 *ret_domain = NULL;
160
161 if (domain != NULL)
162 (void) asprintf(&namedom, "%s@%s", name, domain);
163 else
164 namedom = strdup(name);
165 if (namedom == NULL) {
166 ret = IDMAP_ERR_MEMORY;
167 goto out;
168 }
169
170 rc = smb_lookup_lname(namedom, SidTypeUnknown, &acct);
171 if (rc != 0) {
172 idmapdlog(LOG_ERR, "Error: smb_lookup_name failed.");
173 idmapdlog(LOG_ERR,
174 "Check SMB service (svc:/network/smb/server).");
175 idmapdlog(LOG_ERR,
176 "Check connectivity to Active Directory.");
177 ret = IDMAP_ERR_OTHER;
178 goto out;
179 }
180 if (acct.a_status == NT_STATUS_NONE_MAPPED) {
181 ret = IDMAP_ERR_NOTFOUND;
182 goto out;
183 }
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);
188 /* Fail soft */
189 ret = IDMAP_ERR_NOTFOUND;
190 goto out;
|