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"
29 #include "param/param.h"
31 static NTSTATUS dcerpc_unixinfo_bind(struct dcesrv_call_state *dce_call,
32 const struct dcesrv_interface *iface)
34 struct wbc_context *wbc_ctx;
36 wbc_ctx = wbc_init(dce_call->context, dce_call->msg_ctx,
38 NT_STATUS_HAVE_NO_MEMORY(wbc_ctx);
40 dce_call->context->private = wbc_ctx;
45 #define DCESRV_INTERFACE_UNIXINFO_BIND dcerpc_unixinfo_bind
47 static NTSTATUS dcesrv_unixinfo_SidToUid(struct dcesrv_call_state *dce_call,
49 struct unixinfo_SidToUid *r)
52 struct wbc_context *wbc_ctx = talloc_get_type_abort(
53 dce_call->context->private,
55 struct id_mapping *ids;
56 struct composite_context *ctx;
58 DEBUG(5, ("dcesrv_unixinfo_SidToUid called\n"));
60 ids = talloc(mem_ctx, struct id_mapping);
61 NT_STATUS_HAVE_NO_MEMORY(ids);
63 ids->sid = &r->in.sid;
64 ids->status = NT_STATUS_NONE_MAPPED;
66 ctx = wbc_sids_to_xids_send(wbc_ctx, ids, 1, ids);
67 NT_STATUS_HAVE_NO_MEMORY(ctx);
69 status = wbc_sids_to_xids_recv(ctx, &ids);
70 NT_STATUS_NOT_OK_RETURN(status);
72 if (ids->unixid->type == ID_TYPE_BOTH ||
73 ids->unixid->type == ID_TYPE_UID) {
74 *r->out.uid = ids->unixid->id;
77 return NT_STATUS_INVALID_SID;
81 static NTSTATUS dcesrv_unixinfo_UidToSid(struct dcesrv_call_state *dce_call,
83 struct unixinfo_UidToSid *r)
85 struct wbc_context *wbc_ctx = talloc_get_type_abort(
86 dce_call->context->private,
88 struct id_mapping *ids;
89 struct composite_context *ctx;
93 DEBUG(5, ("dcesrv_unixinfo_UidToSid called\n"));
95 uid = r->in.uid; /* This cuts uid to 32 bit */
96 if ((uint64_t)uid != r->in.uid) {
97 DEBUG(10, ("uid out of range\n"));
98 return NT_STATUS_INVALID_PARAMETER;
101 ids = talloc(mem_ctx, struct id_mapping);
102 NT_STATUS_HAVE_NO_MEMORY(ids);
105 ids->status = NT_STATUS_NONE_MAPPED;
106 ids->unixid = talloc(ids, struct unixid);
107 NT_STATUS_HAVE_NO_MEMORY(ids->unixid);
109 ids->unixid->id = uid;
110 ids->unixid->type = ID_TYPE_UID;
112 ctx = wbc_xids_to_sids_send(wbc_ctx, ids, 1, ids);
113 NT_STATUS_HAVE_NO_MEMORY(ctx);
115 status = wbc_xids_to_sids_recv(ctx, &ids);
116 NT_STATUS_NOT_OK_RETURN(status);
118 r->out.sid = ids->sid;
122 static NTSTATUS dcesrv_unixinfo_SidToGid(struct dcesrv_call_state *dce_call,
124 struct unixinfo_SidToGid *r)
127 struct wbc_context *wbc_ctx = talloc_get_type_abort(
128 dce_call->context->private,
130 struct id_mapping *ids;
131 struct composite_context *ctx;
133 DEBUG(5, ("dcesrv_unixinfo_SidToGid called\n"));
135 ids = talloc(mem_ctx, struct id_mapping);
136 NT_STATUS_HAVE_NO_MEMORY(ids);
138 ids->sid = &r->in.sid;
139 ids->status = NT_STATUS_NONE_MAPPED;
141 ctx = wbc_sids_to_xids_send(wbc_ctx, ids, 1, ids);
142 NT_STATUS_HAVE_NO_MEMORY(ctx);
144 status = wbc_sids_to_xids_recv(ctx, &ids);
145 NT_STATUS_NOT_OK_RETURN(status);
147 if (ids->unixid->type == ID_TYPE_BOTH ||
148 ids->unixid->type == ID_TYPE_GID) {
149 *r->out.gid = ids->unixid->id;
152 return NT_STATUS_INVALID_SID;
156 static NTSTATUS dcesrv_unixinfo_GidToSid(struct dcesrv_call_state *dce_call,
158 struct unixinfo_GidToSid *r)
160 struct wbc_context *wbc_ctx = talloc_get_type_abort(
161 dce_call->context->private,
163 struct id_mapping *ids;
164 struct composite_context *ctx;
168 DEBUG(5, ("dcesrv_unixinfo_GidToSid called\n"));
170 gid = r->in.gid; /* This cuts gid to 32 bit */
171 if ((uint64_t)gid != r->in.gid) {
172 DEBUG(10, ("gid out of range\n"));
173 return NT_STATUS_INVALID_PARAMETER;
176 ids = talloc(mem_ctx, struct id_mapping);
177 NT_STATUS_HAVE_NO_MEMORY(ids);
180 ids->status = NT_STATUS_NONE_MAPPED;
181 ids->unixid = talloc(ids, struct unixid);
182 NT_STATUS_HAVE_NO_MEMORY(ids->unixid);
184 ids->unixid->id = gid;
185 ids->unixid->type = ID_TYPE_GID;
187 ctx = wbc_xids_to_sids_send(wbc_ctx, ids, 1, ids);
188 NT_STATUS_HAVE_NO_MEMORY(ctx);
190 status = wbc_xids_to_sids_recv(ctx, &ids);
191 NT_STATUS_NOT_OK_RETURN(status);
193 r->out.sid = ids->sid;
197 static NTSTATUS dcesrv_unixinfo_GetPWUid(struct dcesrv_call_state *dce_call,
199 struct unixinfo_GetPWUid *r)
205 r->out.infos = talloc_zero_array(mem_ctx, struct unixinfo_GetPWUidInfo,
207 NT_STATUS_HAVE_NO_MEMORY(r->out.infos);
208 *r->out.count = *r->in.count;
210 for (i=0; i < *r->in.count; i++) {
217 DEBUG(10, ("uid %d not found\n", uid));
218 r->out.infos[i].homedir = "";
219 r->out.infos[i].shell = "";
220 r->out.infos[i].status = NT_STATUS_NO_SUCH_USER;
224 r->out.infos[i].homedir = talloc_strdup(mem_ctx, pwd->pw_dir);
225 r->out.infos[i].shell = talloc_strdup(mem_ctx, pwd->pw_shell);
227 if ((r->out.infos[i].homedir == NULL) ||
228 (r->out.infos[i].shell == NULL)) {
229 r->out.infos[i].homedir = "";
230 r->out.infos[i].shell = "";
231 r->out.infos[i].status = NT_STATUS_NO_MEMORY;
235 r->out.infos[i].status = NT_STATUS_OK;
241 /* include the generated boilerplate */
242 #include "librpc/gen_ndr/ndr_unixinfo_s.c"