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"
29 #include <sys/types.h>
32 static NTSTATUS unixinfo_SidToUid(struct dcesrv_call_state *dce_call,
34 struct unixinfo_SidToUid *r)
36 struct sidmap_context *sidmap;
39 sidmap = sidmap_open(mem_ctx);
41 DEBUG(10, ("sidmap_open failed\n"));
42 return NT_STATUS_NO_MEMORY;
45 r->out.result = sidmap_sid_to_unixuid(sidmap, &r->in.sid, &uid);
47 if (NT_STATUS_IS_OK(r->out.result)) {
54 static NTSTATUS unixinfo_UidToSid(struct dcesrv_call_state *dce_call,
56 struct unixinfo_UidToSid *r)
58 struct sidmap_context *sidmap;
61 sidmap = sidmap_open(mem_ctx);
63 DEBUG(10, ("sidmap_open failed\n"));
64 return NT_STATUS_NO_MEMORY;
67 uid = r->in.uid; /* This cuts uid to (probably) 32 bit */
69 if ((uint64_t)uid != r->in.uid) {
70 DEBUG(10, ("uid out of range\n"));
71 return NT_STATUS_INVALID_PARAMETER;
75 r->out.result = sidmap_uid_to_sid(sidmap, mem_ctx, uid, &r->out.sid);
79 static NTSTATUS unixinfo_SidToGid(struct dcesrv_call_state *dce_call,
81 struct unixinfo_SidToGid *r)
83 struct sidmap_context *sidmap;
86 sidmap = sidmap_open(mem_ctx);
88 DEBUG(10, ("sidmap_open failed\n"));
89 return NT_STATUS_NO_MEMORY;
92 r->out.result = sidmap_sid_to_unixgid(sidmap, &r->in.sid, &gid);
94 if (NT_STATUS_IS_OK(r->out.result)) {
101 static NTSTATUS unixinfo_GidToSid(struct dcesrv_call_state *dce_call,
103 struct unixinfo_GidToSid *r)
105 struct sidmap_context *sidmap;
108 sidmap = sidmap_open(mem_ctx);
109 if (sidmap == NULL) {
110 DEBUG(10, ("sidmap_open failed\n"));
111 return NT_STATUS_NO_MEMORY;
114 gid = r->in.gid; /* This cuts gid to (probably) 32 bit */
116 if ((uint64_t)gid != r->in.gid) {
117 DEBUG(10, ("gid out of range\n"));
118 return NT_STATUS_INVALID_PARAMETER;
122 r->out.result = sidmap_gid_to_sid(sidmap, mem_ctx, gid, &r->out.sid);
123 return r->out.result;
126 static NTSTATUS unixinfo_GetPWUid(struct dcesrv_call_state *dce_call,
128 struct unixinfo_GetPWUid *r)
132 r->out.infos = talloc_zero_array(mem_ctx, struct unixinfo_GetPWUidInfo,
134 if (r->out.infos == NULL) {
135 DEBUG(0, ("talloc failed\n"));
136 return NT_STATUS_NO_MEMORY;
139 r->out.result = NT_STATUS_OK;
140 r->out.count = r->in.count;
142 for (i=0; i<r->in.count; i++) {
149 DEBUG(10, ("uid %d not found\n", uid));
150 r->out.infos[i].homedir = "";
151 r->out.infos[i].shell = "";
152 r->out.infos[i].status = NT_STATUS_NO_SUCH_USER;
156 r->out.infos[i].homedir = talloc_strdup(mem_ctx, pwd->pw_dir);
157 r->out.infos[i].shell = talloc_strdup(mem_ctx, pwd->pw_shell);
159 if ((r->out.infos[i].homedir == NULL) ||
160 (r->out.infos[i].shell == NULL)) {
161 r->out.infos[i].homedir = "";
162 r->out.infos[i].shell = "";
163 r->out.infos[i].status = NT_STATUS_NO_MEMORY;
167 r->out.infos[i].status = NT_STATUS_OK;
173 /* include the generated boilerplate */
174 #include "librpc/gen_ndr/ndr_unixinfo_s.c"