1#ifndef VSF_PRIVSOCK_H
2#define VSF_PRIVSOCK_H
3
4struct mystr;
5struct vsf_session;
6
7/* priv_sock_init()
8 * PURPOSE
9 * Initialize the priv_sock system, by opening the communications sockets.
10 * PARAMETERS
11 * p_sess       - the current session object
12 */
13void priv_sock_init(struct vsf_session* p_sess);
14
15/* priv_sock_send_cmd()
16 * PURPOSE
17 * Sends a command, typically to the privileged side of the channel.
18 * PARAMETERS
19 * fd           - the fd on which to send the command
20 * cmd          - the command to send
21 */
22void priv_sock_send_cmd(int fd, char cmd);
23
24/* priv_sock_send_str()
25 * PURPOSE
26 * Sends a string to the other side of the channel.
27 * PARAMETERS
28 * fd           - the fd on which to send the string
29 * p_str        - the string to send
30 */
31void priv_sock_send_str(int fd, const struct mystr* p_str);
32
33/* priv_sock_get_result()
34 * PURPOSE
35 * Receives a response, typically from the privileged side of the channel.
36 * PARAMETERS
37 * fd           - the fd on which to receive the response
38 * RETURNS
39 * The response code.
40 */
41char priv_sock_get_result(int fd);
42
43/* priv_sock_get_cmd()
44 * PURPOSE
45 * Receives a command, typically on the privileged side of the channel.
46 * PARAMETERS
47 * fd           - the fd on which to receive the command.
48 * RETURNS
49 * The command that was sent.
50 */
51char priv_sock_get_cmd(int fd);
52
53/* priv_sock_get_str()
54 * PURPOSE
55 * Receives a string from the other side of the channel.
56 * PARAMETERS
57 * fd           - the fd on which to receive the string
58 * p_dest       - where to copy the received string
59 */
60void priv_sock_get_str(int fd, struct mystr* p_dest);
61
62/* priv_sock_send_result()
63 * PURPOSE
64 * Sends a command result, typically to the unprivileged side of the channel.
65 * PARAMETERS
66 * fd           - the fd on which to send the result
67 * res          - the result to send
68 */
69void priv_sock_send_result(int fd, char res);
70
71/* priv_sock_send_fd()
72 * PURPOSE
73 * Sends a file descriptor to the other side of the channel.
74 * PARAMETERS
75 * fd           - the fd on which to send the descriptor
76 * send_fd      - the descriptor to send
77 */
78void priv_sock_send_fd(int fd, int send_fd);
79
80/* priv_sock_recv_fd()
81 * PURPOSE
82 * Receives a file descriptor from the other side of the channel.
83 * PARAMETERS
84 * fd           - the fd on which to receive the descriptor
85 * RETURNS
86 * The received file descriptor
87 */
88int priv_sock_recv_fd(int fd);
89
90/* priv_sock_send_int()
91 * PURPOSE
92 * Sends an integer to the other side of the channel.
93 * PARAMETERS
94 * fd           - the fd on which to send the integer
95 * the_int      - the integer to send
96 */
97void priv_sock_send_int(int fd, int the_int);
98
99/* priv_sock_get_int()
100 * PURPOSE
101 * Receives an integer from the other side of the channel.
102 * PARAMETERS
103 * fd           - the fd on which to receive the integer
104 * RETURNS
105 * The integer that was sent.
106 */
107int priv_sock_get_int(int fd);
108
109#define PRIV_SOCK_LOGIN             1
110#define PRIV_SOCK_CHOWN             2
111#define PRIV_SOCK_GET_DATA_SOCK     3
112#define PRIV_SOCK_GET_USER_CMD      4
113#define PRIV_SOCK_WRITE_USER_RESP   5
114
115#define PRIV_SOCK_RESULT_OK         1
116#define PRIV_SOCK_RESULT_BAD        2
117
118#endif /* VSF_PRIVSOCK_H */
119
120