r25068: Older samba3 DCs will return DCERPC_FAULT_OP_RNG_ERROR for every opcode on the
[Samba.git] / source / rpc_server / srv_unixinfo_nt.c
blob565d96e1fceffdada7335ae0d4b8e27d67344e1f
1 /*
2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines for unixinfo-pipe
4 * Copyright (C) Volker Lendecke 2005
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 /* This is the interface to the rpcunixinfo pipe. */
23 #include "includes.h"
24 #include "nterr.h"
28 #undef DBGC_CLASS
29 #define DBGC_CLASS DBGC_RPC_SRV
31 /* Map a sid to a uid */
33 NTSTATUS _unixinfo_SidToUid(pipes_struct *p, struct unixinfo_SidToUid *r)
35 uid_t real_uid;
36 NTSTATUS status;
37 *r->out.uid = 0;
39 status = sid_to_uid(&r->in.sid, &real_uid) ? NT_STATUS_OK : NT_STATUS_NONE_MAPPED;
40 if (NT_STATUS_IS_OK(status))
41 *r->out.uid = real_uid;
43 return status;
46 /* Map a uid to a sid */
48 NTSTATUS _unixinfo_UidToSid(pipes_struct *p, struct unixinfo_UidToSid *r)
50 NTSTATUS status = NT_STATUS_NO_SUCH_USER;
52 uid_to_sid(r->out.sid, (uid_t)r->in.uid);
53 status = NT_STATUS_OK;
55 return status;
58 /* Map a sid to a gid */
60 NTSTATUS _unixinfo_SidToGid(pipes_struct *p, struct unixinfo_SidToGid *r)
62 gid_t real_gid;
63 NTSTATUS status;
65 *r->out.gid = 0;
67 status = sid_to_gid(&r->in.sid, &real_gid) ? NT_STATUS_OK : NT_STATUS_NONE_MAPPED;
68 if (NT_STATUS_IS_OK(status))
69 *r->out.gid = real_gid;
71 return status;
74 /* Map a gid to a sid */
76 NTSTATUS _unixinfo_GidToSid(pipes_struct *p, struct unixinfo_GidToSid *r)
78 NTSTATUS status = NT_STATUS_NO_SUCH_GROUP;
80 gid_to_sid(r->out.sid, (gid_t)r->in.gid);
81 status = NT_STATUS_OK;
83 return status;
86 /* Get unix struct passwd information */
88 NTSTATUS _unixinfo_GetPWUid(pipes_struct *p, struct unixinfo_GetPWUid *r)
90 int i;
91 NTSTATUS status;
93 if (*r->in.count > 1023)
94 return NT_STATUS_INVALID_PARAMETER;
96 status = NT_STATUS_OK;
98 for (i=0; i<*r->in.count; i++) {
99 struct passwd *pw;
100 char *homedir, *shell;
101 ssize_t len1, len2;
103 r->out.infos[i].status = NT_STATUS_NO_SUCH_USER;
104 r->out.infos[i].homedir = "";
105 r->out.infos[i].shell = "";
107 pw = getpwuid(r->in.uids[i]);
109 if (pw == NULL) {
110 DEBUG(10, ("Did not find uid %lld\n",
111 (long long int)r->in.uids[i]));
112 continue;
115 len1 = push_utf8_talloc(p->mem_ctx, &homedir, pw->pw_dir);
116 len2 = push_utf8_talloc(p->mem_ctx, &shell, pw->pw_shell);
118 if ((len1 < 0) || (len2 < 0) || (homedir == NULL) ||
119 (shell == NULL)) {
120 DEBUG(3, ("push_utf8_talloc failed\n"));
121 r->out.infos[i].status = NT_STATUS_NO_MEMORY;
122 continue;
125 r->out.infos[i].status = NT_STATUS_OK;
126 r->out.infos[i].homedir = homedir;
127 r->out.infos[i].shell = shell;
130 return status;