Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 :
4 : Winbind client API - SSSD version
5 :
6 : Copyright (C) Sumit Bose <sbose@redhat.com> 2014
7 :
8 : This library is free software; you can redistribute it and/or
9 : modify it under the terms of the GNU Lesser General Public
10 : License as published by the Free Software Foundation; either
11 : version 3 of the License, or (at your option) any later version.
12 :
13 : This library is distributed in the hope that it will be useful,
14 : but WITHOUT ANY WARRANTY; without even the implied warranty of
15 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 : Library General Public License for more details.
17 :
18 : You should have received a copy of the GNU Lesser General Public License
19 : along with this program. If not, see <http://www.gnu.org/licenses/>.
20 : */
21 :
22 : /* Required Headers */
23 : #include "config.h"
24 :
25 : #include <stdio.h>
26 :
27 : #include <errno.h>
28 :
29 : #include "sss_client/idmap/sss_nss_idmap.h"
30 :
31 : #include "libwbclient.h"
32 : #include "wbc_sssd_internal.h"
33 :
34 : #define MAX_NAME_LEN 1024
35 :
36 0 : static int sss_id_type_to_wbcSidType(enum sss_id_type sss_type,
37 : enum wbcSidType *name_type)
38 : {
39 0 : switch (sss_type) {
40 : case SSS_ID_TYPE_NOT_SPECIFIED:
41 0 : *name_type = WBC_SID_NAME_USE_NONE;
42 0 : break;
43 : case SSS_ID_TYPE_UID:
44 : case SSS_ID_TYPE_BOTH:
45 0 : *name_type = WBC_SID_NAME_USER;
46 0 : break;
47 : case SSS_ID_TYPE_GID:
48 0 : *name_type = WBC_SID_NAME_DOM_GRP;
49 0 : break;
50 : default:
51 0 : return EINVAL;
52 : }
53 :
54 0 : return 0;
55 : };
56 :
57 : /* Convert a domain and name to SID */
58 0 : wbcErr wbcLookupName(const char *domain,
59 : const char *name,
60 : struct wbcDomainSid *sid,
61 : enum wbcSidType *name_type)
62 : {
63 0 : char *fq_name = NULL;
64 : char *str_sid;
65 : enum sss_id_type type;
66 : int ret;
67 : wbcErr wbc_status;
68 :
69 0 : if (domain == NULL || name == NULL
70 0 : || strnlen(domain, MAX_NAME_LEN) == MAX_NAME_LEN
71 0 : || strnlen(name, MAX_NAME_LEN) == MAX_NAME_LEN) {
72 0 : return WBC_ERR_INVALID_PARAM;
73 : }
74 0 : ret = asprintf(&fq_name, "%s@%s", name, domain);
75 0 : if (ret == -1) {
76 0 : return WBC_ERR_NO_MEMORY;
77 : }
78 :
79 0 : ret = sss_nss_getsidbyname(fq_name, &str_sid, &type);
80 0 : free(fq_name);
81 0 : if (ret != 0) {
82 0 : return WBC_ERR_UNKNOWN_FAILURE;
83 : }
84 :
85 0 : ret = sss_id_type_to_wbcSidType(type, name_type);
86 0 : if (ret != 0) {
87 0 : return WBC_ERR_UNKNOWN_FAILURE;
88 : }
89 :
90 0 : wbc_status = wbcStringToSid(str_sid, sid);
91 0 : free(str_sid);
92 0 : if (!WBC_ERROR_IS_OK(wbc_status)) {
93 0 : return wbc_status;
94 : }
95 :
96 0 : return WBC_ERR_SUCCESS;
97 : }
98 :
99 :
100 : /* Convert a SID to a domain and name */
101 0 : wbcErr wbcLookupSid(const struct wbcDomainSid *sid,
102 : char **pdomain,
103 : char **pname,
104 : enum wbcSidType *pname_type)
105 : {
106 : char *str_sid;
107 0 : char *fq_name = NULL;
108 : enum sss_id_type type;
109 : int ret;
110 : char *p;
111 : wbcErr wbc_status;
112 :
113 0 : wbc_status = wbcSidToString(sid, &str_sid);
114 0 : if (!WBC_ERROR_IS_OK(wbc_status)) {
115 0 : return wbc_status;
116 : }
117 :
118 0 : ret = sss_nss_getnamebysid(str_sid, &fq_name, &type);
119 0 : wbcFreeMemory(str_sid);
120 0 : if (ret != 0) {
121 0 : return WBC_ERR_UNKNOWN_FAILURE;
122 : }
123 :
124 0 : ret = sss_id_type_to_wbcSidType(type, pname_type);
125 0 : if (ret != 0) {
126 0 : wbc_status = WBC_ERR_UNKNOWN_FAILURE;
127 0 : goto done;
128 : }
129 :
130 : /* TODO: it would be nice to have a sss_nss_getnamebysid() call which
131 : * return name and domain separately. */
132 0 : p = strchr(fq_name, '@');
133 0 : if (p == NULL) {
134 0 : wbc_status = WBC_ERR_UNKNOWN_FAILURE;
135 0 : goto done;
136 : }
137 :
138 0 : *p = '\0';
139 0 : *pname = wbcStrDup(fq_name);
140 0 : if (*pname == NULL) {
141 0 : wbc_status = WBC_ERR_NO_MEMORY;
142 0 : goto done;
143 : }
144 :
145 0 : *pdomain = wbcStrDup(p + 1);
146 0 : if (*pdomain == NULL) {
147 0 : wbcFreeMemory(*pname);
148 0 : wbc_status = WBC_ERR_NO_MEMORY;
149 0 : goto done;
150 : }
151 :
152 0 : wbc_status = WBC_ERR_SUCCESS;
153 : done:
154 0 : free(fq_name);
155 0 : return wbc_status;
156 : }
157 :
158 0 : wbcErr wbcLookupSids(const struct wbcDomainSid *sids, int num_sids,
159 : struct wbcDomainInfo **pdomains, int *pnum_domains,
160 : struct wbcTranslatedName **pnames)
161 : {
162 0 : WBC_SSSD_NOT_IMPLEMENTED;
163 : }
164 :
165 : /* Translate a collection of RIDs within a domain to names */
166 :
167 0 : wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
168 : int num_rids,
169 : uint32_t *rids,
170 : const char **pp_domain_name,
171 : const char ***pnames,
172 : enum wbcSidType **ptypes)
173 : {
174 0 : struct wbcDomainSid obj_sid = {0};
175 : size_t c;
176 : wbcErr err;
177 : char *domain;
178 : char *name;
179 : enum wbcSidType type;
180 0 : const char **names = NULL;
181 0 : enum wbcSidType *types = NULL;
182 :
183 0 : obj_sid.sid_rev_num = dom_sid->sid_rev_num;
184 0 : obj_sid.num_auths = dom_sid->num_auths + 1;
185 0 : for (c = 0; c < 6; c++) {
186 0 : obj_sid.id_auth[c] = dom_sid->id_auth[c];
187 : }
188 0 : for (c = 0; c < WBC_MAXSUBAUTHS; c++) {
189 0 : obj_sid.sub_auths[c] = dom_sid->sub_auths[c];
190 : }
191 :
192 0 : names = wbcAllocateStringArray(num_rids + 1);
193 0 : if (names == NULL) {
194 0 : err = WBC_ERR_NO_MEMORY;
195 0 : goto done;
196 : }
197 :
198 0 : types = wbcAllocateMemory(num_rids + 1, sizeof(enum wbcSidType), NULL);
199 0 : if (types == NULL) {
200 0 : err = WBC_ERR_NO_MEMORY;
201 0 : goto done;
202 : }
203 :
204 0 : for (c = 0; c < num_rids; c++) {
205 0 : obj_sid.sub_auths[obj_sid.num_auths - 1] = rids[c];
206 :
207 0 : err = wbcLookupSid(&obj_sid, &domain, &name, &type);
208 0 : if (err != WBC_ERR_SUCCESS) {
209 0 : goto done;
210 : }
211 :
212 0 : names[c] = strdup(name);
213 0 : wbcFreeMemory(name);
214 0 : if (names[c] == NULL) {
215 0 : err = WBC_ERR_NO_MEMORY;
216 0 : goto done;
217 : }
218 0 : types[c] = type;
219 :
220 0 : if (c == 0) {
221 0 : *pp_domain_name = domain;
222 : } else {
223 0 : wbcFreeMemory(domain);
224 : }
225 : }
226 :
227 0 : *pnames = names;
228 0 : *ptypes = types;
229 :
230 0 : err = WBC_ERR_SUCCESS;
231 :
232 : done:
233 0 : if (err != WBC_ERR_SUCCESS) {
234 0 : wbcFreeMemory(types);
235 0 : wbcFreeMemory(names);
236 : }
237 :
238 0 : return err;
239 : }
240 :
241 : /* Get the groups a user belongs to */
242 0 : wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
243 : bool domain_groups_only,
244 : uint32_t *num_sids,
245 : struct wbcDomainSid **_sids)
246 : {
247 0 : WBC_SSSD_NOT_IMPLEMENTED;
248 : }
249 :
250 : /* Get alias membership for sids */
251 0 : wbcErr wbcGetSidAliases(const struct wbcDomainSid *dom_sid,
252 : struct wbcDomainSid *sids,
253 : uint32_t num_sids,
254 : uint32_t **alias_rids,
255 : uint32_t *num_alias_rids)
256 : {
257 0 : WBC_SSSD_NOT_IMPLEMENTED;
258 : }
259 :
260 :
261 : /* Lists Users */
262 0 : wbcErr wbcListUsers(const char *domain_name,
263 : uint32_t *_num_users,
264 : const char ***_users)
265 : {
266 0 : WBC_SSSD_NOT_IMPLEMENTED;
267 : }
268 :
269 : /* Lists Groups */
270 0 : wbcErr wbcListGroups(const char *domain_name,
271 : uint32_t *_num_groups,
272 : const char ***_groups)
273 : {
274 0 : WBC_SSSD_NOT_IMPLEMENTED;
275 : }
276 :
277 0 : wbcErr wbcGetDisplayName(const struct wbcDomainSid *sid,
278 : char **pdomain,
279 : char **pfullname,
280 : enum wbcSidType *pname_type)
281 : {
282 0 : WBC_SSSD_NOT_IMPLEMENTED;
283 : }
|