~zulcss/ubuntu/lucid/likewise-open/likewise-open-sru

« back to all changes in this revision

Viewing changes to samba/source/winbindd/likewise/idmap_lwicompat_v3.c

  • Committer: Bazaar Package Importer
  • Author(s): Rick Clark
  • Date: 2008-08-27 08:56:20 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080827085620-5q0f58b9qtog9myq
Tags: 4.1.0.2956-0ubuntu1
* missing-likewise-logo.diff: removed
* fixed copyright notice
* updated Standards-Version to 3.8.0
* removed path from command in prerm
* removed stop in S runlevel

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Likewise Identity shim idmap plugin
 
3
 *
 
4
 * Copyright (C) Gerald (Jerry) Carter      2007
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
19
 *
 
20
 */
 
21
 
 
22
/* Disable the current idmap.h and support the legacy version.
 
23
   This only works if the pre-compiled version of nicludes.h
 
24
   does not exist. */
 
25
 
 
26
#define _IDMAP_H_
 
27
 
 
28
/* Version "3" was used in Samba 3.0.23 - 3.0.24 
 
29
 * But not change in VERSION interface number :-( */
 
30
 
 
31
#define SMB_IDMAP_INTERFACE_VERSION 2
 
32
 
 
33
#define ID_EMPTY        0x00
 
34
#define ID_USERID       0x01
 
35
#define ID_GROUPID      0x02
 
36
#define ID_OTHER        0x04
 
37
 
 
38
#define ID_TYPEMASK     0x0f
 
39
 
 
40
struct idmap_methods;
 
41
struct idmap_alloc_methods;
 
42
 
 
43
#include "includes.h"
 
44
 
 
45
#undef DBGC_CLASS
 
46
#define DBGC_CLASS DBGC_IDMAP
 
47
 
 
48
struct idmap_methods {
 
49
        NTSTATUS(*init) (char *params);
 
50
#if 0 
 
51
        NTSTATUS(*allocate_rid) (uint32 * rid, int rid_type);
 
52
#endif
 
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,
 
56
                                    const DOM_SID * sid);
 
57
        NTSTATUS(*set_mapping) (const DOM_SID * sid, unid_t id, int id_type);
 
58
        NTSTATUS(*close) (void);
 
59
        void (*status) (void);
 
60
};
 
61
 
 
62
/*********************************************************************
 
63
 ********************************************************************/
 
64
 
 
65
static NTSTATUS lwi_idmap_init(char *params)
 
66
{
 
67
        return NT_STATUS_OK;
 
68
}
 
69
 
 
70
/*********************************************************************
 
71
 ********************************************************************/
 
72
 
 
73
static NTSTATUS lwi_allocate_id(unid_t * id, int id_type)
 
74
{
 
75
        return NT_STATUS_NOT_IMPLEMENTED;
 
76
}
 
77
 
 
78
/*********************************************************************
 
79
 ********************************************************************/
 
80
 
 
81
static NTSTATUS lwi_get_sid_from_id(DOM_SID * sid, unid_t id, int type)
 
82
{
 
83
        NSS_STATUS result;
 
84
        struct winbindd_request request;
 
85
        struct winbindd_response response;
 
86
        int wb_cmd;
 
87
 
 
88
        ZERO_STRUCT(request);
 
89
        ZERO_STRUCT(response);
 
90
 
 
91
        switch (type) {
 
92
        case ID_USERID:
 
93
                wb_cmd = WINBINDD_UID_TO_SID;
 
94
                request.data.uid = id.uid;
 
95
                break;
 
96
        case ID_GROUPID:
 
97
                wb_cmd = WINBINDD_GID_TO_SID;
 
98
                request.data.gid = id.gid;
 
99
                break;
 
100
        default:
 
101
                DEBUG(4, ("lwi_get_sid_from_id: Invalid type (%d)\n", type));
 
102
                return NT_STATUS_INVALID_PARAMETER;
 
103
        }
 
104
 
 
105
        result = winbindd_request_response(wb_cmd, &request, &response);
 
106
 
 
107
        if (result != NSS_STATUS_SUCCESS)
 
108
                return NT_STATUS_NONE_MAPPED;
 
109
 
 
110
        if (!string_to_sid(sid, response.data.sid.sid))
 
111
                return NT_STATUS_INVALID_SID;
 
112
 
 
113
        return NT_STATUS_OK;
 
114
}
 
115
 
 
116
/*********************************************************************
 
117
 ********************************************************************/
 
118
 
 
119
const char* sid_string_static(const DOM_SID*);
 
120
 
 
121
static NTSTATUS lwi_get_id_from_sid(unid_t * id, int *type, const DOM_SID * sid)
 
122
{
 
123
        NSS_STATUS result;
 
124
        struct winbindd_request request;
 
125
        struct winbindd_response response;
 
126
        enum winbindd_cmd cmd;
 
127
        int query_type = (*type) & ID_TYPEMASK;
 
128
 
 
129
        ZERO_STRUCT(request);
 
130
        ZERO_STRUCT(response);
 
131
 
 
132
        fstrcpy(request.data.sid, sid_string_static(sid));
 
133
 
 
134
        switch (query_type) {
 
135
        case ID_USERID:
 
136
                cmd = WINBINDD_SID_TO_UID;
 
137
                break;
 
138
        case ID_GROUPID:
 
139
                cmd = WINBINDD_SID_TO_GID;
 
140
                break;
 
141
        default:
 
142
                DEBUG(4,("lwi_get_id_from_sid: Unknown query type (%u)\n", query_type));
 
143
                return NT_STATUS_INVALID_PARAMETER;
 
144
        }
 
145
 
 
146
        /* Make request */
 
147
 
 
148
        result = winbindd_request_response(cmd,
 
149
                                           &request, &response);
 
150
 
 
151
        /* Copy out result */
 
152
 
 
153
        if (result != NSS_STATUS_SUCCESS)
 
154
                return NT_STATUS_NONE_MAPPED;
 
155
 
 
156
        /* Let the union work it out */
 
157
        id->uid = response.data.uid;
 
158
 
 
159
        SAFE_FREE(response.extra_data.data);
 
160
 
 
161
        return NT_STATUS_OK;
 
162
}
 
163
 
 
164
/*********************************************************************
 
165
 ********************************************************************/
 
166
 
 
167
static NTSTATUS lwi_set_mapping(const DOM_SID * sid, unid_t id, int id_type)
 
168
{
 
169
        return NT_STATUS_NOT_IMPLEMENTED;
 
170
}
 
171
 
 
172
/*********************************************************************
 
173
 ********************************************************************/
 
174
 
 
175
static NTSTATUS lwi_idmap_close(void)
 
176
{
 
177
        return NT_STATUS_OK;
 
178
}
 
179
 
 
180
/*********************************************************************
 
181
 ********************************************************************/
 
182
 
 
183
static void lwi_idmap_status(void)
 
184
{
 
185
        return;
 
186
}
 
187
 
 
188
/*********************************************************************
 
189
 ********************************************************************/
 
190
 
 
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
 
199
};
 
200
 
 
201
NTSTATUS idmap_lwicompat_v3_init(void)
 
202
{
 
203
        return smb_register_idmap(SMB_IDMAP_INTERFACE_VERSION,
 
204
                                  "lwicompat_v3", &lwi_compat_methods);
 
205
}