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
);
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 r_u
->status
= uid_to_sid(&sid
, q_u
->uid
.low
);
61 init_r_unixinfo_uid_to_sid(r_u
,
62 NT_STATUS_IS_OK(r_u
->status
) ? &sid
: NULL
);
67 /* Map a sid to a gid */
69 NTSTATUS
_unixinfo_sid_to_gid(pipes_struct
*p
,
70 UNIXINFO_Q_SID_TO_GID
*q_u
,
71 UNIXINFO_R_SID_TO_GID
*r_u
)
78 r_u
->status
= sid_to_gid(&q_u
->sid
, &gid
);
79 if (NT_STATUS_IS_OK(r_u
->status
))
85 /* Map a gid to a sid */
87 NTSTATUS
_unixinfo_gid_to_sid(pipes_struct
*p
,
88 UNIXINFO_Q_GID_TO_SID
*q_u
,
89 UNIXINFO_R_GID_TO_SID
*r_u
)
93 r_u
->status
= NT_STATUS_NO_SUCH_USER
;
95 if (q_u
->gid
.high
== 0) {
96 r_u
->status
= gid_to_sid(&sid
, q_u
->gid
.low
);
99 init_r_unixinfo_gid_to_sid(r_u
,
100 NT_STATUS_IS_OK(r_u
->status
) ? &sid
: NULL
);
105 /* Get unix struct passwd information */
107 NTSTATUS
_unixinfo_getpwuid(pipes_struct
*p
,
108 UNIXINFO_Q_GETPWUID
*q_u
,
109 UNIXINFO_R_GETPWUID
*r_u
)
113 if (r_u
->count
> 1023) {
114 return NT_STATUS_INVALID_PARAMETER
;
117 r_u
->info
= TALLOC_ARRAY(p
->mem_ctx
, struct unixinfo_getpwuid
,
120 if ((r_u
->count
> 0) && (r_u
->info
== NULL
)) {
121 return NT_STATUS_NO_MEMORY
;
124 r_u
->status
= NT_STATUS_OK
;
125 r_u
->count
= q_u
->count
;
127 for (i
=0; i
<r_u
->count
; i
++) {
129 char *homedir
, *shell
;
132 r_u
->info
[i
].status
= NT_STATUS_NO_SUCH_USER
;
133 r_u
->info
[i
].homedir
= "";
134 r_u
->info
[i
].shell
= "";
136 if (q_u
->uid
[i
].high
!= 0) {
137 DEBUG(10, ("64-bit uids not yet supported...\n"));
141 pw
= getpwuid(q_u
->uid
[i
].low
);
144 DEBUG(10, ("Did not find uid %d\n", q_u
->uid
[i
].low
));
148 len1
= push_utf8_talloc(p
->mem_ctx
, &homedir
, pw
->pw_dir
);
149 len2
= push_utf8_talloc(p
->mem_ctx
, &shell
, pw
->pw_shell
);
151 if ((len1
< 0) || (len2
< 0) || (homedir
== NULL
) ||
153 DEBUG(3, ("push_utf8_talloc failed\n"));
154 r_u
->info
[i
].status
= NT_STATUS_NO_MEMORY
;
158 r_u
->info
[i
].status
= NT_STATUS_OK
;
159 r_u
->info
[i
].homedir
= homedir
;
160 r_u
->info
[i
].shell
= shell
;