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 "lib/events/events.h"
27 #include "dsdb/samdb/samdb.h"
28 #include "system/passwd.h"
30 static NTSTATUS dcesrv_unixinfo_SidToUid(struct dcesrv_call_state *dce_call,
32 struct unixinfo_SidToUid *r)
35 struct sidmap_context *sidmap;
38 sidmap = sidmap_open(mem_ctx);
40 DEBUG(10, ("sidmap_open failed\n"));
41 return NT_STATUS_NO_MEMORY;
44 status = sidmap_sid_to_unixuid(sidmap, &r->in.sid, &uid);
45 NT_STATUS_NOT_OK_RETURN(status);
51 static NTSTATUS dcesrv_unixinfo_UidToSid(struct dcesrv_call_state *dce_call,
53 struct unixinfo_UidToSid *r)
55 struct sidmap_context *sidmap;
58 sidmap = sidmap_open(mem_ctx);
60 DEBUG(10, ("sidmap_open failed\n"));
61 return NT_STATUS_NO_MEMORY;
64 uid = r->in.uid; /* This cuts uid to (probably) 32 bit */
66 if ((uint64_t)uid != r->in.uid) {
67 DEBUG(10, ("uid out of range\n"));
68 return NT_STATUS_INVALID_PARAMETER;
71 return sidmap_uid_to_sid(sidmap, mem_ctx, uid, &r->out.sid);
74 static NTSTATUS dcesrv_unixinfo_SidToGid(struct dcesrv_call_state *dce_call,
76 struct unixinfo_SidToGid *r)
79 struct sidmap_context *sidmap;
82 sidmap = sidmap_open(mem_ctx);
84 DEBUG(10, ("sidmap_open failed\n"));
85 return NT_STATUS_NO_MEMORY;
88 status = sidmap_sid_to_unixgid(sidmap, &r->in.sid, &gid);
89 NT_STATUS_NOT_OK_RETURN(status);
95 static NTSTATUS dcesrv_unixinfo_GidToSid(struct dcesrv_call_state *dce_call,
97 struct unixinfo_GidToSid *r)
99 struct sidmap_context *sidmap;
102 sidmap = sidmap_open(mem_ctx);
103 if (sidmap == NULL) {
104 DEBUG(10, ("sidmap_open failed\n"));
105 return NT_STATUS_NO_MEMORY;
108 gid = r->in.gid; /* This cuts gid to (probably) 32 bit */
110 if ((uint64_t)gid != r->in.gid) {
111 DEBUG(10, ("gid out of range\n"));
112 return NT_STATUS_INVALID_PARAMETER;
115 return sidmap_gid_to_sid(sidmap, mem_ctx, gid, &r->out.sid);
118 static NTSTATUS dcesrv_unixinfo_GetPWUid(struct dcesrv_call_state *dce_call,
120 struct unixinfo_GetPWUid *r)
126 r->out.infos = talloc_zero_array(mem_ctx, struct unixinfo_GetPWUidInfo,
128 NT_STATUS_HAVE_NO_MEMORY(r->out.infos);
129 *r->out.count = *r->in.count;
131 for (i=0; i < *r->in.count; i++) {
138 DEBUG(10, ("uid %d not found\n", uid));
139 r->out.infos[i].homedir = "";
140 r->out.infos[i].shell = "";
141 r->out.infos[i].status = NT_STATUS_NO_SUCH_USER;
145 r->out.infos[i].homedir = talloc_strdup(mem_ctx, pwd->pw_dir);
146 r->out.infos[i].shell = talloc_strdup(mem_ctx, pwd->pw_shell);
148 if ((r->out.infos[i].homedir == NULL) ||
149 (r->out.infos[i].shell == NULL)) {
150 r->out.infos[i].homedir = "";
151 r->out.infos[i].shell = "";
152 r->out.infos[i].status = NT_STATUS_NO_MEMORY;
156 r->out.infos[i].status = NT_STATUS_OK;
162 /* include the generated boilerplate */
163 #include "librpc/gen_ndr/ndr_unixinfo_s.c"