2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines for unixinfo-pipe
4 * Copyright (C) Volker Lendecke 2005
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. */
27 #define DBGC_CLASS DBGC_RPC_SRV
29 /* Map a sid to a uid */
31 NTSTATUS _unixinfo_sid_to_uid(pipes_struct *p,
32 UNIXINFO_Q_SID_TO_UID *q_u,
33 UNIXINFO_R_SID_TO_UID *r_u)
40 r_u->status = sid_to_uid(&q_u->sid, &uid) ? NT_STATUS_OK : NT_STATUS_NONE_MAPPED;
41 if (NT_STATUS_IS_OK(r_u->status))
47 /* Map a uid to a sid */
49 NTSTATUS _unixinfo_uid_to_sid(pipes_struct *p,
50 UNIXINFO_Q_UID_TO_SID *q_u,
51 UNIXINFO_R_UID_TO_SID *r_u)
55 r_u->status = NT_STATUS_NO_SUCH_USER;
57 if (q_u->uid.high == 0) {
58 uid_to_sid(&sid, q_u->uid.low);
59 r_u->status = NT_STATUS_OK;
62 init_r_unixinfo_uid_to_sid(r_u,
63 NT_STATUS_IS_OK(r_u->status) ? &sid : NULL);
68 /* Map a sid to a gid */
70 NTSTATUS _unixinfo_sid_to_gid(pipes_struct *p,
71 UNIXINFO_Q_SID_TO_GID *q_u,
72 UNIXINFO_R_SID_TO_GID *r_u)
79 r_u->status = sid_to_gid(&q_u->sid, &gid) ? NT_STATUS_OK : NT_STATUS_NONE_MAPPED;
80 if (NT_STATUS_IS_OK(r_u->status))
86 /* Map a gid to a sid */
88 NTSTATUS _unixinfo_gid_to_sid(pipes_struct *p,
89 UNIXINFO_Q_GID_TO_SID *q_u,
90 UNIXINFO_R_GID_TO_SID *r_u)
94 r_u->status = NT_STATUS_NO_SUCH_USER;
96 if (q_u->gid.high == 0) {
97 gid_to_sid(&sid, q_u->gid.low);
98 r_u->status = NT_STATUS_OK;
101 init_r_unixinfo_gid_to_sid(r_u,
102 NT_STATUS_IS_OK(r_u->status) ? &sid : NULL);
107 /* Get unix struct passwd information */
109 NTSTATUS _unixinfo_getpwuid(pipes_struct *p,
110 UNIXINFO_Q_GETPWUID *q_u,
111 UNIXINFO_R_GETPWUID *r_u)
115 if (r_u->count > 1023) {
116 return NT_STATUS_INVALID_PARAMETER;
119 r_u->info = TALLOC_ARRAY(p->mem_ctx, struct unixinfo_getpwuid,
122 if ((r_u->count > 0) && (r_u->info == NULL)) {
123 return NT_STATUS_NO_MEMORY;
126 r_u->status = NT_STATUS_OK;
127 r_u->count = q_u->count;
129 for (i=0; i<r_u->count; i++) {
131 char *homedir, *shell;
134 r_u->info[i].status = NT_STATUS_NO_SUCH_USER;
135 r_u->info[i].homedir = "";
136 r_u->info[i].shell = "";
138 if (q_u->uid[i].high != 0) {
139 DEBUG(10, ("64-bit uids not yet supported...\n"));
143 pw = getpwuid(q_u->uid[i].low);
146 DEBUG(10, ("Did not find uid %d\n", q_u->uid[i].low));
150 len1 = push_utf8_talloc(p->mem_ctx, &homedir, pw->pw_dir);
151 len2 = push_utf8_talloc(p->mem_ctx, &shell, pw->pw_shell);
153 if ((len1 < 0) || (len2 < 0) || (homedir == NULL) ||
155 DEBUG(3, ("push_utf8_talloc failed\n"));
156 r_u->info[i].status = NT_STATUS_NO_MEMORY;
160 r_u->info[i].status = NT_STATUS_OK;
161 r_u->info[i].homedir = homedir;
162 r_u->info[i].shell = shell;