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 id_map
*ids
, uint32_t count
)
33 struct wbcDomainSid
*sids
;
34 struct wbcUnixId
*xids
;
38 mem_ctx
= talloc_new(NULL
);
39 if (mem_ctx
== NULL
) {
40 return NT_STATUS_NO_MEMORY
;
43 sids
= talloc_array(mem_ctx
, struct wbcDomainSid
, count
);
46 return NT_STATUS_NO_MEMORY
;
49 xids
= talloc_array(mem_ctx
, struct wbcUnixId
, count
);
52 return NT_STATUS_NO_MEMORY
;
55 for (i
=0; i
<count
; i
++) {
56 memcpy(&sids
[i
], ids
[i
].sid
, sizeof(struct dom_sid
));
59 wb_off
= winbind_env_set();
64 result
= wbcSidsToUnixIds(sids
, count
, xids
);
70 if (!WBC_ERROR_IS_OK(result
)) {
72 return NT_STATUS_INTERNAL_ERROR
;
75 for (i
=0; i
<count
; i
++) {
76 struct wbcUnixId
*xid
= &xids
[i
];
77 struct unixid
*id
= &ids
[i
].xid
;
81 id
->type
= ID_TYPE_UID
;
85 id
->type
= ID_TYPE_GID
;
88 case WBC_ID_TYPE_BOTH
:
89 id
->type
= ID_TYPE_BOTH
;
92 case WBC_ID_TYPE_NOT_SPECIFIED
:
93 id
->type
= ID_TYPE_NOT_SPECIFIED
;
97 ids
[i
].status
= ID_MAPPED
;
100 TALLOC_FREE(mem_ctx
);
105 NTSTATUS
wbc_xids_to_sids(struct id_map
*ids
, uint32_t count
)
109 struct wbcDomainSid
*sids
;
110 struct wbcUnixId
*xids
;
114 mem_ctx
= talloc_new(NULL
);
115 if (mem_ctx
== NULL
) {
116 return NT_STATUS_NO_MEMORY
;
119 sids
= talloc_array(mem_ctx
, struct wbcDomainSid
, count
);
121 TALLOC_FREE(mem_ctx
);
122 return NT_STATUS_NO_MEMORY
;
125 xids
= talloc_array(mem_ctx
, struct wbcUnixId
, count
);
127 TALLOC_FREE(mem_ctx
);
128 return NT_STATUS_NO_MEMORY
;
131 for (i
=0; i
<count
; i
++) {
132 struct id_map
*id
= &ids
[i
];
133 struct wbcUnixId
*xid
= &xids
[i
];
135 switch (id
->xid
.type
) {
137 *xid
= (struct wbcUnixId
) {
138 .type
= WBC_ID_TYPE_UID
,
143 *xid
= (struct wbcUnixId
) {
144 .type
= WBC_ID_TYPE_GID
,
149 TALLOC_FREE(mem_ctx
);
150 return NT_STATUS_NOT_FOUND
;
154 wb_off
= winbind_env_set();
159 result
= wbcUnixIdsToSids(xids
, count
, sids
);
165 if (!WBC_ERROR_IS_OK(result
)) {
166 TALLOC_FREE(mem_ctx
);
167 return NT_STATUS_INTERNAL_ERROR
;
170 for (i
=0; i
<count
; i
++) {
171 struct wbcDomainSid
*sid
= &sids
[i
];
172 struct wbcDomainSid null_sid
= { 0 };
173 struct id_map
*id
= &ids
[i
];
175 if (memcmp(sid
, &null_sid
, sizeof(*sid
)) != 0) {
176 struct dom_sid domsid
;
177 id
->status
= ID_MAPPED
;
179 memcpy(&domsid
, sid
, sizeof(struct dom_sid
));
180 id
->sid
= dom_sid_dup(ids
, &domsid
);
181 if (id
->sid
== NULL
) {
182 TALLOC_FREE(mem_ctx
);
183 return NT_STATUS_NO_MEMORY
;
186 id
->status
= ID_UNMAPPED
;
191 TALLOC_FREE(mem_ctx
);