2
* Likewise Identity shim idmap plugin
4
* Copyright (C) Gerald (Jerry) Carter 2007
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version
9
* 2 of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
/* Disable the current idmap.h and support the legacy version.
23
This only works if the pre-compiled version of nicludes.h
28
/* Version "3" was used in Samba 3.0.23 - 3.0.24
29
* But not change in VERSION interface number :-( */
31
#define SMB_IDMAP_INTERFACE_VERSION 2
34
#define ID_USERID 0x01
35
#define ID_GROUPID 0x02
38
#define ID_TYPEMASK 0x0f
41
struct idmap_alloc_methods;
46
#define DBGC_CLASS DBGC_IDMAP
48
struct idmap_methods {
49
NTSTATUS(*init) (char *params);
51
NTSTATUS(*allocate_rid) (uint32 * rid, int rid_type);
53
NTSTATUS(*allocate_id) (unid_t * id, int id_type);
54
NTSTATUS(*get_sid_from_id) (DOM_SID * sid, unid_t id, int id_type);
55
NTSTATUS(*get_id_from_sid) (unid_t * id, int *id_type,
57
NTSTATUS(*set_mapping) (const DOM_SID * sid, unid_t id, int id_type);
58
NTSTATUS(*close) (void);
59
void (*status) (void);
62
/*********************************************************************
63
********************************************************************/
65
static NTSTATUS lwi_idmap_init(char *params)
70
/*********************************************************************
71
********************************************************************/
73
static NTSTATUS lwi_allocate_id(unid_t * id, int id_type)
75
return NT_STATUS_NOT_IMPLEMENTED;
78
/*********************************************************************
79
********************************************************************/
81
static NTSTATUS lwi_get_sid_from_id(DOM_SID * sid, unid_t id, int type)
84
struct winbindd_request request;
85
struct winbindd_response response;
89
ZERO_STRUCT(response);
93
wb_cmd = WINBINDD_UID_TO_SID;
94
request.data.uid = id.uid;
97
wb_cmd = WINBINDD_GID_TO_SID;
98
request.data.gid = id.gid;
101
DEBUG(4, ("lwi_get_sid_from_id: Invalid type (%d)\n", type));
102
return NT_STATUS_INVALID_PARAMETER;
105
result = winbindd_request_response(wb_cmd, &request, &response);
107
if (result != NSS_STATUS_SUCCESS)
108
return NT_STATUS_NONE_MAPPED;
110
if (!string_to_sid(sid, response.data.sid.sid))
111
return NT_STATUS_INVALID_SID;
116
/*********************************************************************
117
********************************************************************/
119
const char* sid_string_static(const DOM_SID*);
121
static NTSTATUS lwi_get_id_from_sid(unid_t * id, int *type, const DOM_SID * sid)
124
struct winbindd_request request;
125
struct winbindd_response response;
126
enum winbindd_cmd cmd;
127
int query_type = (*type) & ID_TYPEMASK;
129
ZERO_STRUCT(request);
130
ZERO_STRUCT(response);
132
fstrcpy(request.data.sid, sid_string_static(sid));
134
switch (query_type) {
136
cmd = WINBINDD_SID_TO_UID;
139
cmd = WINBINDD_SID_TO_GID;
142
DEBUG(4,("lwi_get_id_from_sid: Unknown query type (%u)\n", query_type));
143
return NT_STATUS_INVALID_PARAMETER;
148
result = winbindd_request_response(cmd,
149
&request, &response);
151
/* Copy out result */
153
if (result != NSS_STATUS_SUCCESS)
154
return NT_STATUS_NONE_MAPPED;
156
/* Let the union work it out */
157
id->uid = response.data.uid;
159
SAFE_FREE(response.extra_data.data);
164
/*********************************************************************
165
********************************************************************/
167
static NTSTATUS lwi_set_mapping(const DOM_SID * sid, unid_t id, int id_type)
169
return NT_STATUS_NOT_IMPLEMENTED;
172
/*********************************************************************
173
********************************************************************/
175
static NTSTATUS lwi_idmap_close(void)
180
/*********************************************************************
181
********************************************************************/
183
static void lwi_idmap_status(void)
188
/*********************************************************************
189
********************************************************************/
191
static struct idmap_methods lwi_compat_methods = {
192
.init = lwi_idmap_init,
193
.allocate_id = lwi_allocate_id,
194
.get_sid_from_id = lwi_get_sid_from_id,
195
.get_id_from_sid = lwi_get_id_from_sid,
196
.set_mapping = lwi_set_mapping,
197
.close = lwi_idmap_close,
198
.status = lwi_idmap_status
201
NTSTATUS idmap_lwicompat_v3_init(void)
203
return smb_register_idmap(SMB_IDMAP_INTERFACE_VERSION,
204
"lwicompat_v3", &lwi_compat_methods);