1/*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License as
4 * published by the Free Software Foundation; either version 2 of
5 * the License, or (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
15 * MA 02111-1307 USA
16 */
17#ifndef VSF_PRIVSOCK_H
18#define VSF_PRIVSOCK_H
19
20struct mystr;
21struct vsf_session;
22
23/* priv_sock_init()
24 * PURPOSE
25 * Initialize the priv_sock system, by opening the communications sockets.
26 * PARAMETERS
27 * p_sess       - the current session object
28 */
29void priv_sock_init(struct vsf_session* p_sess);
30
31/* priv_sock_send_cmd()
32 * PURPOSE
33 * Sends a command, typically to the privileged side of the channel.
34 * PARAMETERS
35 * fd           - the fd on which to send the command
36 * cmd          - the command to send
37 */
38void priv_sock_send_cmd(int fd, char cmd);
39
40/* priv_sock_send_str()
41 * PURPOSE
42 * Sends a string to the other side of the channel.
43 * PARAMETERS
44 * fd           - the fd on which to send the string
45 * p_str        - the string to send
46 */
47void priv_sock_send_str(int fd, const struct mystr* p_str);
48
49/* priv_sock_get_result()
50 * PURPOSE
51 * Receives a response, typically from the privileged side of the channel.
52 * PARAMETERS
53 * fd           - the fd on which to receive the response
54 * RETURNS
55 * The response code.
56 */
57char priv_sock_get_result(int fd);
58
59/* priv_sock_get_cmd()
60 * PURPOSE
61 * Receives a command, typically on the privileged side of the channel.
62 * PARAMETERS
63 * fd           - the fd on which to receive the command.
64 * RETURNS
65 * The command that was sent.
66 */
67char priv_sock_get_cmd(int fd);
68
69/* priv_sock_get_str()
70 * PURPOSE
71 * Receives a string from the other side of the channel.
72 * PARAMETERS
73 * fd           - the fd on which to receive the string
74 * p_dest       - where to copy the received string
75 */
76void priv_sock_get_str(int fd, struct mystr* p_dest);
77
78/* priv_sock_send_result()
79 * PURPOSE
80 * Sends a command result, typically to the unprivileged side of the channel.
81 * PARAMETERS
82 * fd           - the fd on which to send the result
83 * res          - the result to send
84 */
85void priv_sock_send_result(int fd, char res);
86
87/* priv_sock_send_fd()
88 * PURPOSE
89 * Sends a file descriptor to the other side of the channel.
90 * PARAMETERS
91 * fd           - the fd on which to send the descriptor
92 * send_fd      - the descriptor to send
93 */
94void priv_sock_send_fd(int fd, int send_fd);
95
96/* priv_sock_recv_fd()
97 * PURPOSE
98 * Receives a file descriptor from the other side of the channel.
99 * PARAMETERS
100 * fd           - the fd on which to receive the descriptor
101 * RETURNS
102 * The received file descriptor
103 */
104int priv_sock_recv_fd(int fd);
105
106/* priv_sock_send_int()
107 * PURPOSE
108 * Sends an integer to the other side of the channel.
109 * PARAMETERS
110 * fd           - the fd on which to send the integer
111 * the_int      - the integer to send
112 */
113void priv_sock_send_int(int fd, int the_int);
114
115/* priv_sock_get_int()
116 * PURPOSE
117 * Receives an integer from the other side of the channel.
118 * PARAMETERS
119 * fd           - the fd on which to receive the integer
120 * RETURNS
121 * The integer that was sent.
122 */
123int priv_sock_get_int(int fd);
124
125#define PRIV_SOCK_LOGIN             1
126#define PRIV_SOCK_CHOWN             2
127#define PRIV_SOCK_GET_DATA_SOCK     3
128#define PRIV_SOCK_GET_USER_CMD      4
129#define PRIV_SOCK_WRITE_USER_RESP   5
130
131#define PRIV_SOCK_RESULT_OK         1
132#define PRIV_SOCK_RESULT_BAD        2
133
134#endif /* VSF_PRIVSOCK_H */
135
136