3 * Privilege separation definitions
5 * (c) 2008 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Trivial IP Encryption (TrIPE).
12 * TrIPE is free software: you can redistribute it and/or modify it under
13 * the terms of the GNU General Public License as published by the Free
14 * Software Foundation; either version 3 of the License, or (at your
15 * option) any later version.
17 * TrIPE is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * You should have received a copy of the GNU General Public License
23 * along with TrIPE. If not, see <https://www.gnu.org/licenses/>.
33 /*----- Header files ------------------------------------------------------*/
42 #include <sys/types.h>
46 #include <sys/socket.h>
49 #include <mLib/dstr.h>
50 #include <mLib/fdpass.h>
51 #include <mLib/quis.h>
52 #include <mLib/report.h>
53 #include <mLib/trace.h>
59 /*----- Protocol ----------------------------------------------------------*/
63 * The protocol is synchronous. The socket is not marked as nonblocking;
64 * instead we just trust the helper to respond in good time; this is
65 * reasonable since it's not doing anything complicated. The helper is
68 * The protocol works like this. Messages begin with a request code which is
69 * a single @unsigned int@. The server sends a request @PS_TUNRQ@ to the
70 * helper, followed by a strin naming the tunnel driver of interest. The
71 * server responds with a sequence of @PS_TRACE@ and/or @PS_WARN@ messages,
72 * followed by either a @PS_TUNFD@ carrying a file descriptor, or a
73 * @PS_TUNERR@ followed by an integer @errno@ code.
75 * Simple data items are sent as native representations. A string is sent as
76 * a @size_t@ giving the string's length in bytes followed by that many
77 * characters. There is no padding for alignment.
79 * If all else fails, the helper process will just quit.
83 PS_TUNRQ
, /* Request (string) */
84 PS_TUNFD
, /* Tunnel descriptor (nothing) */
85 PS_TUNERR
, /* Error (@int errno@) */
87 PS_TRACE
, /* Trace (@unsigned mask@, string) */
89 PS_WARN
, /* Warning (string) */
92 /*----- Tracing definitions -----------------------------------------------*/
94 #define T_PRIVSEP 512u
96 /*----- Global variables --------------------------------------------------*/
98 extern int pc_fd
; /* File descriptor for comms */
100 /*----- Functions provided ------------------------------------------------*/
102 #define COMM_TYPES(_) \
104 _(uint, unsigned int) \
107 /* --- @pc_put@ --- *
109 * Arguments: @const void *p@ = pointer to buffer
110 * @size_t sz@ = size of the buffer
112 * Returns: Zero on success, @-1@ on error (and @errno@ set).
114 * Use: Writes a buffer, handling short writes and other bogosity.
117 extern int pc_put(const void */
*p*/
, size_t /*sz*/);
119 /* --- @pc_puterr@, @pc_putuint@, @pc_putsz@ --- *
121 * Arguments: @int err@ = error number to write
122 * @uint u@ = unsigned integer to write
123 * @size_t sz@ = size to write
125 * Returns: Zero on success, @-1@ on error (and @errno@ set).
127 * Use: Sends an error/integer/size.
130 #define DECL(abbr, type) extern int pc_put##abbr(type /*x*/);
134 /* --- @pc_putstring@ --- *
136 * Arguments: @const char *s@ = pointer to string to write
138 * Returns: Zero on success, @-1@ on error (and @errno@ set).
140 * Use: Sends a string.
143 extern int pc_putstring(const char */
*s*/
);
145 /* --- @pc_get@ --- *
147 * Arguments: @void *p@ = pointer to buffer
148 * @size_t sz@ = size of the buffer
150 * Returns: Zero on success, @-1@ on error (and @errno@ set).
152 * Use: Receives a buffer, handling short reads and other bogosity.
155 extern int pc_get(void */
*p*/
, size_t /*sz*/);
157 /* --- @pc_geterr@, @pc_getuint@, @pc_getsz@ --- *
159 * Arguments: @int *err@ = where to put the error number
160 * @uint *u@ = where to put the unsigned integer
161 * @size_t *sz@ = where to put the size
163 * Returns: Zero on success, @-1@ on error (and @errno@ set).
165 * Use: Receives an error/integer/size.
168 #define DECL(abbr, type) extern int pc_get##abbr(type */*x*/);
172 /* --- @pc_getstring@ --- *
174 * Arguments: @dstr *d@ = where to put the string
176 * Returns: Zero on success, @-1@ on error (and @errno@ set).
178 * Use: Receives a string.
181 extern int pc_getstring(dstr */
*d*/
);
183 /*----- That's all, folks -------------------------------------------------*/