r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need
[vlendec/samba-autobuild/.git] / source3 / rpc_server / srv_unixinfo.c
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.
10  *  
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.
15  *  
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.
19  */
20
21 /* This is the interface to the rpcunixinfo pipe. */
22
23 #include "includes.h"
24 #include "nterr.h"
25
26 #undef DBGC_CLASS
27 #define DBGC_CLASS DBGC_RPC_SRV
28
29 static BOOL api_sid_to_uid(pipes_struct *p)
30 {
31         UNIXINFO_Q_SID_TO_UID q_u;
32         UNIXINFO_R_SID_TO_UID r_u;
33
34         prs_struct *data = &p->in_data.data;
35         prs_struct *rdata = &p->out_data.rdata;
36
37         ZERO_STRUCT(q_u);
38         ZERO_STRUCT(r_u);
39
40         if (!unixinfo_io_q_unixinfo_sid_to_uid("", &q_u, data, 0))
41                 return False;
42
43         r_u.status = _unixinfo_sid_to_uid(p, &q_u, &r_u);
44
45         if (!unixinfo_io_r_unixinfo_sid_to_uid("", &r_u, rdata, 0))
46                 return False;
47
48         return True;
49 }
50
51 static BOOL api_uid_to_sid(pipes_struct *p)
52 {
53         UNIXINFO_Q_UID_TO_SID q_u;
54         UNIXINFO_R_UID_TO_SID r_u;
55
56         prs_struct *data = &p->in_data.data;
57         prs_struct *rdata = &p->out_data.rdata;
58
59         ZERO_STRUCT(q_u);
60         ZERO_STRUCT(r_u);
61
62         if (!unixinfo_io_q_unixinfo_uid_to_sid("", &q_u, data, 0))
63                 return False;
64
65         r_u.status = _unixinfo_uid_to_sid(p, &q_u, &r_u);
66
67         if (!unixinfo_io_r_unixinfo_uid_to_sid("", &r_u, rdata, 0))
68                 return False;
69
70         return True;
71 }
72
73 static BOOL api_sid_to_gid(pipes_struct *p)
74 {
75         UNIXINFO_Q_SID_TO_GID q_u;
76         UNIXINFO_R_SID_TO_GID r_u;
77
78         prs_struct *data = &p->in_data.data;
79         prs_struct *rdata = &p->out_data.rdata;
80
81         ZERO_STRUCT(q_u);
82         ZERO_STRUCT(r_u);
83
84         if (!unixinfo_io_q_unixinfo_sid_to_gid("", &q_u, data, 0))
85                 return False;
86
87         r_u.status = _unixinfo_sid_to_gid(p, &q_u, &r_u);
88
89         if (!unixinfo_io_r_unixinfo_sid_to_gid("", &r_u, rdata, 0))
90                 return False;
91
92         return True;
93 }
94
95 static BOOL api_gid_to_sid(pipes_struct *p)
96 {
97         UNIXINFO_Q_GID_TO_SID q_u;
98         UNIXINFO_R_GID_TO_SID r_u;
99
100         prs_struct *data = &p->in_data.data;
101         prs_struct *rdata = &p->out_data.rdata;
102
103         ZERO_STRUCT(q_u);
104         ZERO_STRUCT(r_u);
105
106         if (!unixinfo_io_q_unixinfo_gid_to_sid("", &q_u, data, 0))
107                 return False;
108
109         r_u.status = _unixinfo_gid_to_sid(p, &q_u, &r_u);
110
111         if (!unixinfo_io_r_unixinfo_gid_to_sid("", &r_u, rdata, 0))
112                 return False;
113
114         return True;
115 }
116
117 static BOOL api_getpwuid(pipes_struct *p)
118 {
119         UNIXINFO_Q_GETPWUID q_u;
120         UNIXINFO_R_GETPWUID r_u;
121
122         prs_struct *data = &p->in_data.data;
123         prs_struct *rdata = &p->out_data.rdata;
124
125         ZERO_STRUCT(q_u);
126         ZERO_STRUCT(r_u);
127
128         if (!unixinfo_io_q_unixinfo_getpwuid("", &q_u, data, 0))
129                 return False;
130
131         r_u.status = _unixinfo_getpwuid(p, &q_u, &r_u);
132
133         if (!unixinfo_io_r_unixinfo_getpwuid("", &r_u, rdata, 0))
134                 return False;
135
136         return True;
137 }
138
139 /*******************************************************************
140 \pipe\unixinfo commands
141 ********************************************************************/
142
143 struct api_struct api_unixinfo_cmds[] = {
144         {"SID_TO_UID",       UNIXINFO_SID_TO_UID,     api_sid_to_uid },
145         {"UID_TO_SID",       UNIXINFO_UID_TO_SID,     api_uid_to_sid },
146         {"SID_TO_GID",       UNIXINFO_SID_TO_GID,     api_sid_to_gid },
147         {"GID_TO_SID",       UNIXINFO_GID_TO_SID,     api_gid_to_sid },
148         {"GETPWUID",         UNIXINFO_GETPWUID,       api_getpwuid },
149 };
150
151
152 void unixinfo_get_pipe_fns( struct api_struct **fns, int *n_fns )
153 {
154         *fns = api_unixinfo_cmds;
155         *n_fns = sizeof(api_unixinfo_cmds) / sizeof(struct api_struct);
156 }
157
158 NTSTATUS rpc_unixinfo_init(void)
159 {
160         return rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION,
161                 "unixinfo", "unixinfo", api_unixinfo_cmds,
162                 sizeof(api_unixinfo_cmds) / sizeof(struct api_struct));
163 }