chiark / gitweb /
doc/tripe-service.5: New manpage describing service providers.
[tripe] / priv / priv.h
CommitLineData
388e0319
MW
1/* -*-c-*-
2 *
3 * Privilege separation definitions
4 *
5 * (c) 2008 Straylight/Edgeware
6 */
7
8/*----- Licensing notice --------------------------------------------------*
9 *
10 * This file is part of Trivial IP Encryption (TrIPE).
11 *
12 * TrIPE is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * TrIPE is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with TrIPE; if not, write to the Free Software Foundation,
24 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 */
26
27#ifndef PRIV_H
28#define PRIV_H
29
30#ifdef __cplusplus
31 extern "C" {
32#endif
33
34/*----- Header files ------------------------------------------------------*/
35
36#include "config.h"
37
38#include <errno.h>
39#include <stdio.h>
40#include <stdlib.h>
41#include <string.h>
42
43#include <sys/types.h>
44#include <unistd.h>
45#include <fcntl.h>
46
47#include <sys/socket.h>
48#include <sys/un.h>
49
50#include <mLib/dstr.h>
51#include <mLib/fdpass.h>
52#include <mLib/quis.h>
53#include <mLib/report.h>
54#include <mLib/trace.h>
55
56#include "util.h"
57
58#undef sun
59
60/*----- Protocol ----------------------------------------------------------*/
61
62/* --- Notes --- *
63 *
64 * The protocol is synchronous. The socket is not marked as nonblocking;
65 * instead we just trust the helper to respond in good time; this is
66 * reasonable since it's not doing anything complicated. The helper is
67 * completely trusted.
68 *
69 * The protocol works like this. Messages begin with a request code which is
70 * a single @unsigned int@. The server sends a request @PS_TUNRQ@ to the
71 * helper, followed by a @const tunnel_ops *@ referring to the tunnel driver
72 * of interest. The server responds with a sequence of @PS_TRACE@ and/or
73 * @PS_WARN@ messages, followed by either a @PS_TUNFD@ carrying a file
74 * descriptor, or a @PS_TUNERR@ followed by an integer @errno@ code.
75 *
76 * If all else fails, the helper process will just quit.
77 */
78
79enum {
80 PS_TUNRQ, /* Request (@tunnel_ops *@) */
81 PS_TUNFD, /* Tunnel descriptor (string) */
82 PS_TUNERR, /* Error (@int errno@) */
83#ifndef NTRACE
84 PS_TRACE, /* Trace (@unsigned mask@, string) */
85#endif
86 PS_WARN, /* Warning (string) */
87};
88
89/*----- Tracing definitions -----------------------------------------------*/
90
91#define T_PRIVSEP 512u
92
93/*----- Global variables --------------------------------------------------*/
94
95extern int pc_fd; /* File descriptor for comms */
96
97/*----- Functions provided ------------------------------------------------*/
98
99#define COMM_TYPES(_) \
100 _(err, int) \
101 _(uint, unsigned int) \
102 _(sz, size_t)
103
104/* --- @put@ --- *
105 *
106 * Arguments: @const void *p@ = pointer to buffer
107 * @size_t sz@ = size of the buffer
108 *
109 * Returns: Zero on success, @-1@ on error (and @errno@ set).
110 *
111 * Use: Writes a buffer, handling short writes and other bogosity.
112 */
113
114extern int pc_put(const void */*p*/, size_t /*sz*/);
115
116/* --- @puterr@, @putuint@, @putsz@, @puttops@ --- *
117 *
118 * Arguments: @int err@ = error number to write
119 * @uint u@ = unsigned integer to write
120 * @size_t sz@ = size to write
121 * @const tunnel_ops *tops@ = tunnel pointer to write
122 *
123 * Returns: Zero on success, @-1@ on error (and @errno@ set).
124 *
125 * Use: Sends an error/integer/size/tunnel-ops pointer.
126 */
127
128#define DECL(abbr, type) extern int pc_put##abbr(type /*x*/);
129COMM_TYPES(DECL)
130#undef DECL
131
132/* --- @putstring@ --- *
133 *
134 * Arguments: @const char *s@ = pointer to string to write
135 *
136 * Returns: Zero on success, @-1@ on error (and @errno@ set).
137 *
138 * Use: Sends a string/error/integer/tunnel-ops pointer.
139 */
140
141extern int pc_putstring(const char */*s*/);
142
143/* --- @get@ --- *
144 *
145 * Arguments: @void *p@ = pointer to buffer
146 * @size_t sz@ = size of the buffer
147 *
148 * Returns: Zero on success, @-1@ on error (and @errno@ set).
149 *
150 * Use: Receives a buffer, handling short reads and other bogosity.
151 */
152
153extern int pc_get(void */*p*/, size_t /*sz*/);
154
155/* --- @geterr@, @getuint@, @getsz@, @getops@ --- *
156 *
157 * Arguments: @int *err@ = where to put the error number
158 * @uint *u@ = where to put the unsigned integer
159 * @size_t *sz@ = where to put the size
160 * @const tunnel_ops **tops@ = where to put the tunnel pointer
161 *
162 * Returns: Zero on success, @-1@ on error (and @errno@ set).
163 *
164 * Use: Receives an error/integer/size/tunnel-ops pointer.
165 */
166
167#define DECL(abbr, type) extern int pc_get##abbr(type */*x*/);
168COMM_TYPES(DECL)
169#undef DECL
170
171/* --- @gettring@ --- *
172 *
173 * Arguments: @dstr *d@ = where to put the string
174 *
175 * Returns: Zero on success, @-1@ on error (and @errno@ set).
176 *
177 * Use: Receives a string.
178 */
179
180extern int pc_getstring(dstr */*d*/);
181
182/*----- That's all, folks -------------------------------------------------*/
183
184#ifdef __cplusplus
185 }
186#endif
187
188#endif