2
Unix SMB/CIFS implementation.
4
endpoint server for the unixinfo pipe
6
Copyright (C) Volker Lendecke 2005
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/>.
23
#include "rpc_server/dcerpc_server.h"
24
#include "rpc_server/common/common.h"
25
#include "librpc/gen_ndr/ndr_unixinfo.h"
26
#include "libcli/wbclient/wbclient.h"
27
#include "lib/events/events.h"
28
#include "system/passwd.h"
30
static NTSTATUS dcerpc_unixinfo_bind(struct dcesrv_call_state *dce_call,
31
const struct dcesrv_interface *iface)
33
struct wbc_context *wbc_ctx;
35
wbc_ctx = wbc_init(dce_call->context, dce_call->msg_ctx,
37
NT_STATUS_HAVE_NO_MEMORY(wbc_ctx);
39
dce_call->context->private_data = wbc_ctx;
44
#define DCESRV_INTERFACE_UNIXINFO_BIND dcerpc_unixinfo_bind
46
static NTSTATUS dcesrv_unixinfo_SidToUid(struct dcesrv_call_state *dce_call,
48
struct unixinfo_SidToUid *r)
51
struct wbc_context *wbc_ctx = talloc_get_type_abort(
52
dce_call->context->private_data,
54
struct id_mapping *ids;
55
struct composite_context *ctx;
57
DEBUG(5, ("dcesrv_unixinfo_SidToUid called\n"));
59
ids = talloc(mem_ctx, struct id_mapping);
60
NT_STATUS_HAVE_NO_MEMORY(ids);
62
ids->sid = &r->in.sid;
63
ids->status = NT_STATUS_NONE_MAPPED;
65
ctx = wbc_sids_to_xids_send(wbc_ctx, ids, 1, ids);
66
NT_STATUS_HAVE_NO_MEMORY(ctx);
68
status = wbc_sids_to_xids_recv(ctx, &ids);
69
NT_STATUS_NOT_OK_RETURN(status);
71
if (ids->unixid->type == ID_TYPE_BOTH ||
72
ids->unixid->type == ID_TYPE_UID) {
73
*r->out.uid = ids->unixid->id;
76
return NT_STATUS_INVALID_SID;
80
static NTSTATUS dcesrv_unixinfo_UidToSid(struct dcesrv_call_state *dce_call,
82
struct unixinfo_UidToSid *r)
84
struct wbc_context *wbc_ctx = talloc_get_type_abort(
85
dce_call->context->private_data,
87
struct id_mapping *ids;
88
struct composite_context *ctx;
92
DEBUG(5, ("dcesrv_unixinfo_UidToSid called\n"));
94
uid = r->in.uid; /* This cuts uid to 32 bit */
95
if ((uint64_t)uid != r->in.uid) {
96
DEBUG(10, ("uid out of range\n"));
97
return NT_STATUS_INVALID_PARAMETER;
100
ids = talloc(mem_ctx, struct id_mapping);
101
NT_STATUS_HAVE_NO_MEMORY(ids);
104
ids->status = NT_STATUS_NONE_MAPPED;
105
ids->unixid = talloc(ids, struct unixid);
106
NT_STATUS_HAVE_NO_MEMORY(ids->unixid);
108
ids->unixid->id = uid;
109
ids->unixid->type = ID_TYPE_UID;
111
ctx = wbc_xids_to_sids_send(wbc_ctx, ids, 1, ids);
112
NT_STATUS_HAVE_NO_MEMORY(ctx);
114
status = wbc_xids_to_sids_recv(ctx, &ids);
115
NT_STATUS_NOT_OK_RETURN(status);
117
r->out.sid = ids->sid;
121
static NTSTATUS dcesrv_unixinfo_SidToGid(struct dcesrv_call_state *dce_call,
123
struct unixinfo_SidToGid *r)
126
struct wbc_context *wbc_ctx = talloc_get_type_abort(
127
dce_call->context->private_data,
129
struct id_mapping *ids;
130
struct composite_context *ctx;
132
DEBUG(5, ("dcesrv_unixinfo_SidToGid called\n"));
134
ids = talloc(mem_ctx, struct id_mapping);
135
NT_STATUS_HAVE_NO_MEMORY(ids);
137
ids->sid = &r->in.sid;
138
ids->status = NT_STATUS_NONE_MAPPED;
140
ctx = wbc_sids_to_xids_send(wbc_ctx, ids, 1, ids);
141
NT_STATUS_HAVE_NO_MEMORY(ctx);
143
status = wbc_sids_to_xids_recv(ctx, &ids);
144
NT_STATUS_NOT_OK_RETURN(status);
146
if (ids->unixid->type == ID_TYPE_BOTH ||
147
ids->unixid->type == ID_TYPE_GID) {
148
*r->out.gid = ids->unixid->id;
151
return NT_STATUS_INVALID_SID;
155
static NTSTATUS dcesrv_unixinfo_GidToSid(struct dcesrv_call_state *dce_call,
157
struct unixinfo_GidToSid *r)
159
struct wbc_context *wbc_ctx = talloc_get_type_abort(
160
dce_call->context->private_data,
162
struct id_mapping *ids;
163
struct composite_context *ctx;
167
DEBUG(5, ("dcesrv_unixinfo_GidToSid called\n"));
169
gid = r->in.gid; /* This cuts gid to 32 bit */
170
if ((uint64_t)gid != r->in.gid) {
171
DEBUG(10, ("gid out of range\n"));
172
return NT_STATUS_INVALID_PARAMETER;
175
ids = talloc(mem_ctx, struct id_mapping);
176
NT_STATUS_HAVE_NO_MEMORY(ids);
179
ids->status = NT_STATUS_NONE_MAPPED;
180
ids->unixid = talloc(ids, struct unixid);
181
NT_STATUS_HAVE_NO_MEMORY(ids->unixid);
183
ids->unixid->id = gid;
184
ids->unixid->type = ID_TYPE_GID;
186
ctx = wbc_xids_to_sids_send(wbc_ctx, ids, 1, ids);
187
NT_STATUS_HAVE_NO_MEMORY(ctx);
189
status = wbc_xids_to_sids_recv(ctx, &ids);
190
NT_STATUS_NOT_OK_RETURN(status);
192
r->out.sid = ids->sid;
196
static NTSTATUS dcesrv_unixinfo_GetPWUid(struct dcesrv_call_state *dce_call,
198
struct unixinfo_GetPWUid *r)
204
r->out.infos = talloc_zero_array(mem_ctx, struct unixinfo_GetPWUidInfo,
206
NT_STATUS_HAVE_NO_MEMORY(r->out.infos);
207
*r->out.count = *r->in.count;
209
for (i=0; i < *r->in.count; i++) {
216
DEBUG(10, ("uid %d not found\n", uid));
217
r->out.infos[i].homedir = "";
218
r->out.infos[i].shell = "";
219
r->out.infos[i].status = NT_STATUS_NO_SUCH_USER;
223
r->out.infos[i].homedir = talloc_strdup(mem_ctx, pwd->pw_dir);
224
r->out.infos[i].shell = talloc_strdup(mem_ctx, pwd->pw_shell);
226
if ((r->out.infos[i].homedir == NULL) ||
227
(r->out.infos[i].shell == NULL)) {
228
r->out.infos[i].homedir = "";
229
r->out.infos[i].shell = "";
230
r->out.infos[i].status = NT_STATUS_NO_MEMORY;
234
r->out.infos[i].status = NT_STATUS_OK;
240
/* include the generated boilerplate */
241
#include "librpc/gen_ndr/ndr_unixinfo_s.c"