2 Unix SMB/CIFS implementation.
4 Winbind client library.
6 Copyright (C) 2008 Kai Blin <kai@samba.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program 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
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "nsswitch/winbind_client.h"
25 #include "libcli/wbclient/wbclient.h"
26 #include "libcli/security/dom_sid.h"
27 #include "nsswitch/libwbclient/wbclient.h"
29 NTSTATUS
wbc_sids_to_xids(struct tevent_context
*ev
, struct id_map
*ids
,
34 struct wbcDomainSid
*sids
;
35 struct wbcUnixId
*xids
;
39 mem_ctx
= talloc_new(NULL
);
40 if (mem_ctx
== NULL
) {
41 return NT_STATUS_NO_MEMORY
;
44 sids
= talloc_array(mem_ctx
, struct wbcDomainSid
, count
);
47 return NT_STATUS_NO_MEMORY
;
50 xids
= talloc_array(mem_ctx
, struct wbcUnixId
, count
);
53 return NT_STATUS_NO_MEMORY
;
56 for (i
=0; i
<count
; i
++) {
57 memcpy(&sids
[i
], ids
[i
].sid
, sizeof(struct dom_sid
));
60 wb_off
= winbind_env_set();
65 result
= wbcSidsToUnixIds(sids
, count
, xids
);
71 if (!WBC_ERROR_IS_OK(result
)) {
73 return NT_STATUS_INTERNAL_ERROR
;
76 for (i
=0; i
<count
; i
++) {
77 struct wbcUnixId
*xid
= &xids
[i
];
78 struct unixid
*id
= &ids
[i
].xid
;
82 id
->type
= ID_TYPE_UID
;
86 id
->type
= ID_TYPE_GID
;
89 case WBC_ID_TYPE_BOTH
:
90 id
->type
= ID_TYPE_BOTH
;
93 case WBC_ID_TYPE_NOT_SPECIFIED
:
94 id
->type
= ID_TYPE_NOT_SPECIFIED
;
98 ids
[i
].status
= ID_MAPPED
;
101 TALLOC_FREE(mem_ctx
);
106 NTSTATUS
wbc_xids_to_sids(struct tevent_context
*ev
, struct id_map
*ids
,
111 struct wbcDomainSid
*sids
;
112 struct wbcUnixId
*xids
;
116 mem_ctx
= talloc_new(NULL
);
117 if (mem_ctx
== NULL
) {
118 return NT_STATUS_NO_MEMORY
;
121 sids
= talloc_array(mem_ctx
, struct wbcDomainSid
, count
);
123 TALLOC_FREE(mem_ctx
);
124 return NT_STATUS_NO_MEMORY
;
127 xids
= talloc_array(mem_ctx
, struct wbcUnixId
, count
);
129 TALLOC_FREE(mem_ctx
);
130 return NT_STATUS_NO_MEMORY
;
133 for (i
=0; i
<count
; i
++) {
134 struct id_map
*id
= &ids
[i
];
135 struct wbcUnixId
*xid
= &xids
[i
];
137 switch (id
->xid
.type
) {
139 *xid
= (struct wbcUnixId
) {
140 .type
= WBC_ID_TYPE_UID
,
145 *xid
= (struct wbcUnixId
) {
146 .type
= WBC_ID_TYPE_GID
,
151 TALLOC_FREE(mem_ctx
);
152 return NT_STATUS_NOT_FOUND
;
156 wb_off
= winbind_env_set();
161 result
= wbcUnixIdsToSids(xids
, count
, sids
);
167 if (!WBC_ERROR_IS_OK(result
)) {
168 TALLOC_FREE(mem_ctx
);
169 return NT_STATUS_INTERNAL_ERROR
;
172 for (i
=0; i
<count
; i
++) {
173 struct wbcDomainSid
*sid
= &sids
[i
];
174 struct wbcDomainSid null_sid
= { 0 };
175 struct id_map
*id
= &ids
[i
];
177 if (memcmp(sid
, &null_sid
, sizeof(*sid
)) != 0) {
178 struct dom_sid domsid
;
179 id
->status
= ID_MAPPED
;
181 memcpy(&domsid
, sid
, sizeof(struct dom_sid
));
182 id
->sid
= dom_sid_dup(ids
, &domsid
);
183 if (id
->sid
== NULL
) {
184 TALLOC_FREE(mem_ctx
);
185 return NT_STATUS_NO_MEMORY
;
188 id
->status
= ID_UNMAPPED
;
193 TALLOC_FREE(mem_ctx
);