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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "rpc_server/dcerpc_server.h"
25 #include "rpc_server/common/common.h"
26 #include "librpc/gen_ndr/ndr_unixinfo.h"
27 #include "lib/events/events.h"
28 #include "ntvfs/ntvfs.h"
30 #include <sys/types.h>
33 static NTSTATUS unixinfo_SidToUid(struct dcesrv_call_state *dce_call,
35 struct unixinfo_SidToUid *r)
37 struct sidmap_context *sidmap;
40 sidmap = sidmap_open(mem_ctx);
42 DEBUG(10, ("sidmap_open failed\n"));
43 return NT_STATUS_NO_MEMORY;
46 r->out.result = sidmap_sid_to_unixuid(sidmap, &r->in.sid, &uid);
48 if (NT_STATUS_IS_OK(r->out.result)) {
55 static NTSTATUS unixinfo_UidToSid(struct dcesrv_call_state *dce_call,
57 struct unixinfo_UidToSid *r)
59 struct sidmap_context *sidmap;
62 sidmap = sidmap_open(mem_ctx);
64 DEBUG(10, ("sidmap_open failed\n"));
65 return NT_STATUS_NO_MEMORY;
68 uid = r->in.uid; /* This cuts uid to (probably) 32 bit */
70 if ((uint64_t)uid != r->in.uid) {
71 DEBUG(10, ("uid out of range\n"));
72 return NT_STATUS_INVALID_PARAMETER;
76 r->out.result = sidmap_uid_to_sid(sidmap, mem_ctx, uid, &r->out.sid);
80 static NTSTATUS unixinfo_SidToGid(struct dcesrv_call_state *dce_call,
82 struct unixinfo_SidToGid *r)
84 struct sidmap_context *sidmap;
87 sidmap = sidmap_open(mem_ctx);
89 DEBUG(10, ("sidmap_open failed\n"));
90 return NT_STATUS_NO_MEMORY;
93 r->out.result = sidmap_sid_to_unixgid(sidmap, &r->in.sid, &gid);
95 if (NT_STATUS_IS_OK(r->out.result)) {
102 static NTSTATUS unixinfo_GidToSid(struct dcesrv_call_state *dce_call,
104 struct unixinfo_GidToSid *r)
106 struct sidmap_context *sidmap;
109 sidmap = sidmap_open(mem_ctx);
110 if (sidmap == NULL) {
111 DEBUG(10, ("sidmap_open failed\n"));
112 return NT_STATUS_NO_MEMORY;
115 gid = r->in.gid; /* This cuts gid to (probably) 32 bit */
117 if ((uint64_t)gid != r->in.gid) {
118 DEBUG(10, ("gid out of range\n"));
119 return NT_STATUS_INVALID_PARAMETER;
123 r->out.result = sidmap_gid_to_sid(sidmap, mem_ctx, gid, &r->out.sid);
124 return r->out.result;
127 static NTSTATUS unixinfo_GetPWUid(struct dcesrv_call_state *dce_call,
129 struct unixinfo_GetPWUid *r)
133 r->out.infos = talloc_zero_array(mem_ctx, struct unixinfo_GetPWUidInfo,
135 if (r->out.infos == NULL) {
136 DEBUG(0, ("talloc failed\n"));
137 return NT_STATUS_NO_MEMORY;
140 r->out.result = NT_STATUS_OK;
141 r->out.count = r->in.count;
143 for (i=0; i<r->in.count; i++) {
150 DEBUG(10, ("uid %d not found\n", uid));
151 r->out.infos[i].homedir = "";
152 r->out.infos[i].shell = "";
153 r->out.infos[i].status = NT_STATUS_NO_SUCH_USER;
157 r->out.infos[i].homedir = talloc_strdup(mem_ctx, pwd->pw_dir);
158 r->out.infos[i].shell = talloc_strdup(mem_ctx, pwd->pw_shell);
160 if ((r->out.infos[i].homedir == NULL) ||
161 (r->out.infos[i].shell == NULL)) {
162 r->out.infos[i].homedir = "";
163 r->out.infos[i].shell = "";
164 r->out.infos[i].status = NT_STATUS_NO_MEMORY;
168 r->out.infos[i].status = NT_STATUS_OK;
174 /* include the generated boilerplate */
175 #include "librpc/gen_ndr/ndr_unixinfo_s.c"