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 3 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, see <http://www.gnu.org/licenses/>.
23 #include "rpc_server/dcerpc_server.h"
24 #include "librpc/gen_ndr/ndr_unixinfo.h"
25 #include "libcli/wbclient/wbclient.h"
26 #include "system/passwd.h"
28 static NTSTATUS
dcerpc_unixinfo_bind(struct dcesrv_call_state
*dce_call
,
29 const struct dcesrv_interface
*iface
)
31 struct wbc_context
*wbc_ctx
;
33 wbc_ctx
= wbc_init(dce_call
->context
, dce_call
->msg_ctx
,
35 NT_STATUS_HAVE_NO_MEMORY(wbc_ctx
);
37 dce_call
->context
->private_data
= wbc_ctx
;
42 #define DCESRV_INTERFACE_UNIXINFO_BIND dcerpc_unixinfo_bind
44 static NTSTATUS
dcesrv_unixinfo_SidToUid(struct dcesrv_call_state
*dce_call
,
46 struct unixinfo_SidToUid
*r
)
49 struct wbc_context
*wbc_ctx
= talloc_get_type_abort(
50 dce_call
->context
->private_data
,
53 struct composite_context
*ctx
;
55 DEBUG(5, ("dcesrv_unixinfo_SidToUid called\n"));
57 ids
= talloc(mem_ctx
, struct id_map
);
58 NT_STATUS_HAVE_NO_MEMORY(ids
);
60 ids
->sid
= &r
->in
.sid
;
61 ids
->status
= ID_UNKNOWN
;
62 ZERO_STRUCT(ids
->xid
);
63 ctx
= wbc_sids_to_xids_send(wbc_ctx
, ids
, 1, ids
);
64 NT_STATUS_HAVE_NO_MEMORY(ctx
);
66 status
= wbc_sids_to_xids_recv(ctx
, &ids
);
67 NT_STATUS_NOT_OK_RETURN(status
);
69 if (ids
->xid
.type
== ID_TYPE_BOTH
||
70 ids
->xid
.type
== ID_TYPE_UID
) {
71 *r
->out
.uid
= ids
->xid
.id
;
74 return NT_STATUS_INVALID_SID
;
78 static NTSTATUS
dcesrv_unixinfo_UidToSid(struct dcesrv_call_state
*dce_call
,
80 struct unixinfo_UidToSid
*r
)
82 struct wbc_context
*wbc_ctx
= talloc_get_type_abort(
83 dce_call
->context
->private_data
,
86 struct composite_context
*ctx
;
90 DEBUG(5, ("dcesrv_unixinfo_UidToSid called\n"));
92 uid
= r
->in
.uid
; /* This cuts uid to 32 bit */
93 if ((uint64_t)uid
!= r
->in
.uid
) {
94 DEBUG(10, ("uid out of range\n"));
95 return NT_STATUS_INVALID_PARAMETER
;
98 ids
= talloc(mem_ctx
, struct id_map
);
99 NT_STATUS_HAVE_NO_MEMORY(ids
);
102 ids
->status
= ID_UNKNOWN
;
105 ids
->xid
.type
= ID_TYPE_UID
;
107 ctx
= wbc_xids_to_sids_send(wbc_ctx
, ids
, 1, ids
);
108 NT_STATUS_HAVE_NO_MEMORY(ctx
);
110 status
= wbc_xids_to_sids_recv(ctx
, &ids
);
111 NT_STATUS_NOT_OK_RETURN(status
);
113 r
->out
.sid
= ids
->sid
;
117 static NTSTATUS
dcesrv_unixinfo_SidToGid(struct dcesrv_call_state
*dce_call
,
119 struct unixinfo_SidToGid
*r
)
122 struct wbc_context
*wbc_ctx
= talloc_get_type_abort(
123 dce_call
->context
->private_data
,
126 struct composite_context
*ctx
;
128 DEBUG(5, ("dcesrv_unixinfo_SidToGid called\n"));
130 ids
= talloc(mem_ctx
, struct id_map
);
131 NT_STATUS_HAVE_NO_MEMORY(ids
);
133 ids
->sid
= &r
->in
.sid
;
134 ids
->status
= ID_UNKNOWN
;
135 ZERO_STRUCT(ids
->xid
);
136 ctx
= wbc_sids_to_xids_send(wbc_ctx
, ids
, 1, ids
);
137 NT_STATUS_HAVE_NO_MEMORY(ctx
);
139 status
= wbc_sids_to_xids_recv(ctx
, &ids
);
140 NT_STATUS_NOT_OK_RETURN(status
);
142 if (ids
->xid
.type
== ID_TYPE_BOTH
||
143 ids
->xid
.type
== ID_TYPE_GID
) {
144 *r
->out
.gid
= ids
->xid
.id
;
147 return NT_STATUS_INVALID_SID
;
151 static NTSTATUS
dcesrv_unixinfo_GidToSid(struct dcesrv_call_state
*dce_call
,
153 struct unixinfo_GidToSid
*r
)
155 struct wbc_context
*wbc_ctx
= talloc_get_type_abort(
156 dce_call
->context
->private_data
,
159 struct composite_context
*ctx
;
163 DEBUG(5, ("dcesrv_unixinfo_GidToSid called\n"));
165 gid
= r
->in
.gid
; /* This cuts gid to 32 bit */
166 if ((uint64_t)gid
!= r
->in
.gid
) {
167 DEBUG(10, ("gid out of range\n"));
168 return NT_STATUS_INVALID_PARAMETER
;
171 ids
= talloc(mem_ctx
, struct id_map
);
172 NT_STATUS_HAVE_NO_MEMORY(ids
);
175 ids
->status
= ID_UNKNOWN
;
178 ids
->xid
.type
= ID_TYPE_GID
;
180 ctx
= wbc_xids_to_sids_send(wbc_ctx
, ids
, 1, ids
);
181 NT_STATUS_HAVE_NO_MEMORY(ctx
);
183 status
= wbc_xids_to_sids_recv(ctx
, &ids
);
184 NT_STATUS_NOT_OK_RETURN(status
);
186 r
->out
.sid
= ids
->sid
;
190 static NTSTATUS
dcesrv_unixinfo_GetPWUid(struct dcesrv_call_state
*dce_call
,
192 struct unixinfo_GetPWUid
*r
)
198 r
->out
.infos
= talloc_zero_array(mem_ctx
, struct unixinfo_GetPWUidInfo
,
200 NT_STATUS_HAVE_NO_MEMORY(r
->out
.infos
);
201 *r
->out
.count
= *r
->in
.count
;
203 for (i
=0; i
< *r
->in
.count
; i
++) {
210 DEBUG(10, ("uid %d not found\n", uid
));
211 r
->out
.infos
[i
].homedir
= "";
212 r
->out
.infos
[i
].shell
= "";
213 r
->out
.infos
[i
].status
= NT_STATUS_NO_SUCH_USER
;
217 r
->out
.infos
[i
].homedir
= talloc_strdup(mem_ctx
, pwd
->pw_dir
);
218 r
->out
.infos
[i
].shell
= talloc_strdup(mem_ctx
, pwd
->pw_shell
);
220 if ((r
->out
.infos
[i
].homedir
== NULL
) ||
221 (r
->out
.infos
[i
].shell
== NULL
)) {
222 r
->out
.infos
[i
].homedir
= "";
223 r
->out
.infos
[i
].shell
= "";
224 r
->out
.infos
[i
].status
= NT_STATUS_NO_MEMORY
;
228 r
->out
.infos
[i
].status
= NT_STATUS_OK
;
234 /* include the generated boilerplate */
235 #include "librpc/gen_ndr/ndr_unixinfo_s.c"