Fix bug #8795 - Samba does not handle the Owner Rights permissions at all
[Samba/gebeck_regimport.git] / source4 / rpc_server / unixinfo / dcesrv_unixinfo.c
blobb5b8a89c8b91debc90c1f45f92736d25b40c61bc
1 /*
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/>.
22 #include "includes.h"
23 #include "rpc_server/dcerpc_server.h"
24 #include "librpc/gen_ndr/ndr_unixinfo.h"
25 #include "libcli/wbclient/wbclient.h"
26 #include "system/passwd.h"
28 static NTSTATUS dcerpc_unixinfo_bind(struct dcesrv_call_state *dce_call,
29 const struct dcesrv_interface *iface)
31 struct wbc_context *wbc_ctx;
33 wbc_ctx = wbc_init(dce_call->context, dce_call->msg_ctx,
34 dce_call->event_ctx);
35 NT_STATUS_HAVE_NO_MEMORY(wbc_ctx);
37 dce_call->context->private_data = wbc_ctx;
39 return NT_STATUS_OK;
42 #define DCESRV_INTERFACE_UNIXINFO_BIND dcerpc_unixinfo_bind
44 static NTSTATUS dcesrv_unixinfo_SidToUid(struct dcesrv_call_state *dce_call,
45 TALLOC_CTX *mem_ctx,
46 struct unixinfo_SidToUid *r)
48 NTSTATUS status;
49 struct wbc_context *wbc_ctx = talloc_get_type_abort(
50 dce_call->context->private_data,
51 struct wbc_context);
52 struct id_map *ids;
53 struct composite_context *ctx;
55 DEBUG(5, ("dcesrv_unixinfo_SidToUid called\n"));
57 ids = talloc(mem_ctx, struct id_map);
58 NT_STATUS_HAVE_NO_MEMORY(ids);
60 ids->sid = &r->in.sid;
61 ids->status = ID_UNKNOWN;
62 ZERO_STRUCT(ids->xid);
63 ctx = wbc_sids_to_xids_send(wbc_ctx, ids, 1, ids);
64 NT_STATUS_HAVE_NO_MEMORY(ctx);
66 status = wbc_sids_to_xids_recv(ctx, &ids);
67 NT_STATUS_NOT_OK_RETURN(status);
69 if (ids->xid.type == ID_TYPE_BOTH ||
70 ids->xid.type == ID_TYPE_UID) {
71 *r->out.uid = ids->xid.id;
72 return NT_STATUS_OK;
73 } else {
74 return NT_STATUS_INVALID_SID;
78 static NTSTATUS dcesrv_unixinfo_UidToSid(struct dcesrv_call_state *dce_call,
79 TALLOC_CTX *mem_ctx,
80 struct unixinfo_UidToSid *r)
82 struct wbc_context *wbc_ctx = talloc_get_type_abort(
83 dce_call->context->private_data,
84 struct wbc_context);
85 struct id_map *ids;
86 struct composite_context *ctx;
87 uint32_t uid;
88 NTSTATUS status;
90 DEBUG(5, ("dcesrv_unixinfo_UidToSid called\n"));
92 uid = r->in.uid; /* This cuts uid to 32 bit */
93 if ((uint64_t)uid != r->in.uid) {
94 DEBUG(10, ("uid out of range\n"));
95 return NT_STATUS_INVALID_PARAMETER;
98 ids = talloc(mem_ctx, struct id_map);
99 NT_STATUS_HAVE_NO_MEMORY(ids);
101 ids->sid = NULL;
102 ids->status = ID_UNKNOWN;
104 ids->xid.id = uid;
105 ids->xid.type = ID_TYPE_UID;
107 ctx = wbc_xids_to_sids_send(wbc_ctx, ids, 1, ids);
108 NT_STATUS_HAVE_NO_MEMORY(ctx);
110 status = wbc_xids_to_sids_recv(ctx, &ids);
111 NT_STATUS_NOT_OK_RETURN(status);
113 r->out.sid = ids->sid;
114 return NT_STATUS_OK;
117 static NTSTATUS dcesrv_unixinfo_SidToGid(struct dcesrv_call_state *dce_call,
118 TALLOC_CTX *mem_ctx,
119 struct unixinfo_SidToGid *r)
121 NTSTATUS status;
122 struct wbc_context *wbc_ctx = talloc_get_type_abort(
123 dce_call->context->private_data,
124 struct wbc_context);
125 struct id_map *ids;
126 struct composite_context *ctx;
128 DEBUG(5, ("dcesrv_unixinfo_SidToGid called\n"));
130 ids = talloc(mem_ctx, struct id_map);
131 NT_STATUS_HAVE_NO_MEMORY(ids);
133 ids->sid = &r->in.sid;
134 ids->status = ID_UNKNOWN;
135 ZERO_STRUCT(ids->xid);
136 ctx = wbc_sids_to_xids_send(wbc_ctx, ids, 1, ids);
137 NT_STATUS_HAVE_NO_MEMORY(ctx);
139 status = wbc_sids_to_xids_recv(ctx, &ids);
140 NT_STATUS_NOT_OK_RETURN(status);
142 if (ids->xid.type == ID_TYPE_BOTH ||
143 ids->xid.type == ID_TYPE_GID) {
144 *r->out.gid = ids->xid.id;
145 return NT_STATUS_OK;
146 } else {
147 return NT_STATUS_INVALID_SID;
151 static NTSTATUS dcesrv_unixinfo_GidToSid(struct dcesrv_call_state *dce_call,
152 TALLOC_CTX *mem_ctx,
153 struct unixinfo_GidToSid *r)
155 struct wbc_context *wbc_ctx = talloc_get_type_abort(
156 dce_call->context->private_data,
157 struct wbc_context);
158 struct id_map *ids;
159 struct composite_context *ctx;
160 uint32_t gid;
161 NTSTATUS status;
163 DEBUG(5, ("dcesrv_unixinfo_GidToSid called\n"));
165 gid = r->in.gid; /* This cuts gid to 32 bit */
166 if ((uint64_t)gid != r->in.gid) {
167 DEBUG(10, ("gid out of range\n"));
168 return NT_STATUS_INVALID_PARAMETER;
171 ids = talloc(mem_ctx, struct id_map);
172 NT_STATUS_HAVE_NO_MEMORY(ids);
174 ids->sid = NULL;
175 ids->status = ID_UNKNOWN;
177 ids->xid.id = gid;
178 ids->xid.type = ID_TYPE_GID;
180 ctx = wbc_xids_to_sids_send(wbc_ctx, ids, 1, ids);
181 NT_STATUS_HAVE_NO_MEMORY(ctx);
183 status = wbc_xids_to_sids_recv(ctx, &ids);
184 NT_STATUS_NOT_OK_RETURN(status);
186 r->out.sid = ids->sid;
187 return NT_STATUS_OK;
190 static NTSTATUS dcesrv_unixinfo_GetPWUid(struct dcesrv_call_state *dce_call,
191 TALLOC_CTX *mem_ctx,
192 struct unixinfo_GetPWUid *r)
194 unsigned int i;
196 *r->out.count = 0;
198 r->out.infos = talloc_zero_array(mem_ctx, struct unixinfo_GetPWUidInfo,
199 *r->in.count);
200 NT_STATUS_HAVE_NO_MEMORY(r->out.infos);
201 *r->out.count = *r->in.count;
203 for (i=0; i < *r->in.count; i++) {
204 uid_t uid;
205 struct passwd *pwd;
207 uid = r->in.uids[i];
208 pwd = getpwuid(uid);
209 if (pwd == NULL) {
210 DEBUG(10, ("uid %d not found\n", uid));
211 r->out.infos[i].homedir = "";
212 r->out.infos[i].shell = "";
213 r->out.infos[i].status = NT_STATUS_NO_SUCH_USER;
214 continue;
217 r->out.infos[i].homedir = talloc_strdup(mem_ctx, pwd->pw_dir);
218 r->out.infos[i].shell = talloc_strdup(mem_ctx, pwd->pw_shell);
220 if ((r->out.infos[i].homedir == NULL) ||
221 (r->out.infos[i].shell == NULL)) {
222 r->out.infos[i].homedir = "";
223 r->out.infos[i].shell = "";
224 r->out.infos[i].status = NT_STATUS_NO_MEMORY;
225 continue;
228 r->out.infos[i].status = NT_STATUS_OK;
231 return NT_STATUS_OK;
234 /* include the generated boilerplate */
235 #include "librpc/gen_ndr/ndr_unixinfo_s.c"