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
dcesrv_unixinfo_SidToUid(struct dcesrv_call_state
*dce_call
,
30 struct unixinfo_SidToUid
*r
)
35 DEBUG(5, ("dcesrv_unixinfo_SidToUid called\n"));
37 ids
= talloc(mem_ctx
, struct id_map
);
38 NT_STATUS_HAVE_NO_MEMORY(ids
);
40 ids
->sid
= &r
->in
.sid
;
41 ids
->status
= ID_UNKNOWN
;
42 ZERO_STRUCT(ids
->xid
);
43 status
= wbc_sids_to_xids(dce_call
->event_ctx
, ids
, 1);
44 NT_STATUS_NOT_OK_RETURN(status
);
46 if (ids
->xid
.type
== ID_TYPE_BOTH
||
47 ids
->xid
.type
== ID_TYPE_UID
) {
48 *r
->out
.uid
= ids
->xid
.id
;
51 return NT_STATUS_INVALID_SID
;
55 static NTSTATUS
dcesrv_unixinfo_UidToSid(struct dcesrv_call_state
*dce_call
,
57 struct unixinfo_UidToSid
*r
)
63 DEBUG(5, ("dcesrv_unixinfo_UidToSid called\n"));
65 uid
= r
->in
.uid
; /* This cuts uid to 32 bit */
66 if ((uint64_t)uid
!= r
->in
.uid
) {
67 DEBUG(10, ("uid out of range\n"));
68 return NT_STATUS_INVALID_PARAMETER
;
71 ids
= talloc(mem_ctx
, struct id_map
);
72 NT_STATUS_HAVE_NO_MEMORY(ids
);
75 ids
->status
= ID_UNKNOWN
;
78 ids
->xid
.type
= ID_TYPE_UID
;
80 status
= wbc_xids_to_sids(dce_call
->event_ctx
, ids
, 1);
81 NT_STATUS_NOT_OK_RETURN(status
);
83 r
->out
.sid
= ids
->sid
;
87 static NTSTATUS
dcesrv_unixinfo_SidToGid(struct dcesrv_call_state
*dce_call
,
89 struct unixinfo_SidToGid
*r
)
94 DEBUG(5, ("dcesrv_unixinfo_SidToGid called\n"));
96 ids
= talloc(mem_ctx
, struct id_map
);
97 NT_STATUS_HAVE_NO_MEMORY(ids
);
99 ids
->sid
= &r
->in
.sid
;
100 ids
->status
= ID_UNKNOWN
;
101 ZERO_STRUCT(ids
->xid
);
102 status
= wbc_sids_to_xids(dce_call
->event_ctx
, ids
, 1);
103 NT_STATUS_NOT_OK_RETURN(status
);
105 if (ids
->xid
.type
== ID_TYPE_BOTH
||
106 ids
->xid
.type
== ID_TYPE_GID
) {
107 *r
->out
.gid
= ids
->xid
.id
;
110 return NT_STATUS_INVALID_SID
;
114 static NTSTATUS
dcesrv_unixinfo_GidToSid(struct dcesrv_call_state
*dce_call
,
116 struct unixinfo_GidToSid
*r
)
122 DEBUG(5, ("dcesrv_unixinfo_GidToSid called\n"));
124 gid
= r
->in
.gid
; /* This cuts gid to 32 bit */
125 if ((uint64_t)gid
!= r
->in
.gid
) {
126 DEBUG(10, ("gid out of range\n"));
127 return NT_STATUS_INVALID_PARAMETER
;
130 ids
= talloc(mem_ctx
, struct id_map
);
131 NT_STATUS_HAVE_NO_MEMORY(ids
);
134 ids
->status
= ID_UNKNOWN
;
137 ids
->xid
.type
= ID_TYPE_GID
;
139 status
= wbc_xids_to_sids(dce_call
->event_ctx
, ids
, 1);
140 NT_STATUS_NOT_OK_RETURN(status
);
142 r
->out
.sid
= ids
->sid
;
146 static NTSTATUS
dcesrv_unixinfo_GetPWUid(struct dcesrv_call_state
*dce_call
,
148 struct unixinfo_GetPWUid
*r
)
154 r
->out
.infos
= talloc_zero_array(mem_ctx
, struct unixinfo_GetPWUidInfo
,
156 NT_STATUS_HAVE_NO_MEMORY(r
->out
.infos
);
157 *r
->out
.count
= *r
->in
.count
;
159 for (i
=0; i
< *r
->in
.count
; i
++) {
166 DEBUG(10, ("uid %d not found\n", uid
));
167 r
->out
.infos
[i
].homedir
= "";
168 r
->out
.infos
[i
].shell
= "";
169 r
->out
.infos
[i
].status
= NT_STATUS_NO_SUCH_USER
;
173 r
->out
.infos
[i
].homedir
= talloc_strdup(mem_ctx
, pwd
->pw_dir
);
174 r
->out
.infos
[i
].shell
= talloc_strdup(mem_ctx
, pwd
->pw_shell
);
176 if ((r
->out
.infos
[i
].homedir
== NULL
) ||
177 (r
->out
.infos
[i
].shell
== NULL
)) {
178 r
->out
.infos
[i
].homedir
= "";
179 r
->out
.infos
[i
].shell
= "";
180 r
->out
.infos
[i
].status
= NT_STATUS_NO_MEMORY
;
184 r
->out
.infos
[i
].status
= NT_STATUS_OK
;
190 /* include the generated boilerplate */
191 #include "librpc/gen_ndr/ndr_unixinfo_s.c"