2 Unix SMB/CIFS implementation.
6 Copyright (C) Simo Sorce 2003
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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "nsswitch/winbind_nss.h"
27 #define DBGC_CLASS DBGC_IDMAP
29 extern DOM_SID global_sid_NULL; /* NULL sid */
31 NSS_STATUS winbindd_request(int req_type,
32 struct winbindd_request *request,
33 struct winbindd_response *response);
35 /* Get a sid from an id */
36 static NTSTATUS db_get_sid_from_id(DOM_SID *sid, unid_t id, int id_type)
38 struct winbindd_request request;
39 struct winbindd_response response;
40 int result, operation;
43 ZERO_STRUCT(response);
45 switch (id_type & ID_TYPEMASK) {
47 request.data.uid = id.uid;
48 operation = WINBINDD_UID_TO_SID;
51 request.data.gid = id.gid;
52 operation = WINBINDD_GID_TO_SID;
55 return NT_STATUS_INVALID_PARAMETER;
58 /* Make The Request */
59 result = winbindd_request(operation, &request, &response);
60 if (result == NSS_STATUS_SUCCESS) {
61 if (!string_to_sid(sid, response.data.sid.sid)) {
62 return NT_STATUS_INVALID_SID;
66 sid_copy(sid, &global_sid_NULL);
69 return NT_STATUS_UNSUCCESSFUL;
72 /* Get an id from a sid */
73 static NTSTATUS db_get_id_from_sid(unid_t *id, int *id_type, const DOM_SID *sid)
75 struct winbindd_request request;
76 struct winbindd_response response;
77 int result, operation;
80 if (!id || !id_type) {
81 return NT_STATUS_INVALID_PARAMETER;
87 ZERO_STRUCT(response);
89 switch (*id_type & ID_TYPEMASK) {
91 operation = WINBINDD_SID_TO_UID;
94 operation = WINBINDD_SID_TO_GID;
97 return NT_STATUS_INVALID_PARAMETER;
100 sid_to_string(sid_str, sid);
101 fstrcpy(request.data.sid, sid_str);
103 /* Make The Request */
104 result = winbindd_request(operation, &request, &response);
106 if (result == NSS_STATUS_SUCCESS) {
107 if (operation == WINBINDD_SID_TO_UID) {
108 (*id).uid = response.data.uid;
110 (*id).gid = response.data.gid;
115 return NT_STATUS_UNSUCCESSFUL;
118 static NTSTATUS db_set_mapping(DOM_SID *sid, unid_t id, int id_type) {
119 return NT_STATUS_UNSUCCESSFUL;
122 /*****************************************************************************
123 Initialise idmap database.
124 *****************************************************************************/
125 static NTSTATUS db_init(void) {
130 static NTSTATUS db_close(void) {
134 static void db_status(void) {
138 struct idmap_methods winbind_methods = {
149 NTSTATUS idmap_reg_winbind(struct idmap_methods **meth)
151 *meth = &winbind_methods;