1 /*
2  * $Id$
3  *
4  * Copyright (c) 2008, 2009
5  *      Sten Spans <sten@blinkenlights.nl>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include <setjmp.h>
21 
22 #define FAIL_SETRESGID	(1 << 0)
23 #define FAIL_SETRESUID	(1 << 1)
24 #define FAIL_SETGRP	(1 << 2)
25 #define FAIL_CHDIR	(1 << 3)
26 #define FAIL_CHROOT	(1 << 4)
27 #define FAIL_IOCTL	(1 << 5)
28 #define FAIL_SOCKET	(1 << 6)
29 #define FAIL_BIND	(1 << 7)
30 #define FAIL_CONNECT	(1 << 8)
31 #define FAIL_SETSOCKOPT	(1 << 9)
32 #define FAIL_OPEN	(1 << 10)
33 #define FAIL_KILL	(1 << 11)
34 #define FAIL_CALLOC	(1 << 30)
35 #define FAIL_STRDUP	(1 << 31)
36 
37 #define FAKE_SETRESGID	(1 << 0)
38 #define FAKE_SETRESUID	(1 << 1)
39 #define FAKE_SETGRP	(1 << 2)
40 #define FAKE_CHDIR	(1 << 3)
41 #define FAKE_CHROOT	(1 << 4)
42 #define FAKE_IOCTL	(1 << 5)
43 #define FAKE_SOCKET	(1 << 6)
44 #define FAKE_BIND	(1 << 7)
45 #define FAKE_CONNECT	(1 << 8)
46 #define FAKE_SETSOCKOPT	(1 << 9)
47 #define FAKE_OPEN	(1 << 10)
48 #define FAKE_KILL	(1 << 11)
49 #define FAKE_EXIT	(1 << 31)
50 
51 #define WRAP_FATAL_START() \
52     if (!setjmp(check_wrap_env)) { \
53 	check_wrap_fake |= FAKE_EXIT;
54 #define WRAP_FATAL_END() \
55     } \
56     check_wrap_fake &= ~FAKE_EXIT;
57 
58 extern jmp_buf check_wrap_env;
59 extern uint32_t check_wrap_fake;
60 extern uint32_t check_wrap_fail;
61 extern char check_wrap_errstr[];
62 
63 #define WRAP_WRITE(sock, msg, size)	\
64     fail_unless(write(sock, msg, size) == size, "message write failed");
65 #define WRAP_REQ_READ(sock, mreq, len)	\
66     len = read(sock, mreq, PARENT_REQ_MAX); \
67     fail_if(len < PARENT_REQ_MIN, "message read failed"); \
68     fail_if(len != PARENT_REQ_LEN(mreq->len), "message read failed");
69 
70 void read_packet(struct parent_msg *msg, const char *suffix);
71