1d903306aSRobert Watson /*-
2d903306aSRobert Watson  * Copyright (c) 2007 Robert M. M. Watson
3d903306aSRobert Watson  * All rights reserved.
4d903306aSRobert Watson  *
5d903306aSRobert Watson  * This software was developed by Robert N. M. Watson for the TrustedBSD
6d903306aSRobert Watson  * Project.
7d903306aSRobert Watson  *
8d903306aSRobert Watson  * Redistribution and use in source and binary forms, with or without
9d903306aSRobert Watson  * modification, are permitted provided that the following conditions
10d903306aSRobert Watson  * are met:
11d903306aSRobert Watson  * 1. Redistributions of source code must retain the above copyright
12d903306aSRobert Watson  *    notice, this list of conditions and the following disclaimer.
13d903306aSRobert Watson  * 2. Redistributions in binary form must reproduce the above copyright
14d903306aSRobert Watson  *    notice, this list of conditions and the following disclaimer in the
15d903306aSRobert Watson  *    documentation and/or other materials provided with the distribution.
16d903306aSRobert Watson  *
17d903306aSRobert Watson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18d903306aSRobert Watson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19d903306aSRobert Watson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20d903306aSRobert Watson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR, NCIRCLE NETWORK SECURITY,
21d903306aSRobert Watson  * INC., OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22d903306aSRobert Watson  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
23d903306aSRobert Watson  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24d903306aSRobert Watson  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25d903306aSRobert Watson  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26d903306aSRobert Watson  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27d903306aSRobert Watson  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28d903306aSRobert Watson  */
29d903306aSRobert Watson 
30d903306aSRobert Watson /*
31d903306aSRobert Watson  * Confirm that privilege is required to open a raw IP socket, and that this
32d903306aSRobert Watson  * is not allowed in jail.
33d903306aSRobert Watson  */
34d903306aSRobert Watson 
35d903306aSRobert Watson #include <sys/types.h>
36d903306aSRobert Watson #include <sys/socket.h>
37d903306aSRobert Watson 
38d903306aSRobert Watson #include <err.h>
39d903306aSRobert Watson #include <errno.h>
40d903306aSRobert Watson #include <stdio.h>
41d903306aSRobert Watson #include <unistd.h>
42d903306aSRobert Watson 
43d903306aSRobert Watson #include "main.h"
44d903306aSRobert Watson 
45d903306aSRobert Watson int
priv_netinet_raw_setup(int asroot,int injail,struct test * test)46d903306aSRobert Watson priv_netinet_raw_setup(int asroot, int injail, struct test *test)
47d903306aSRobert Watson {
48d903306aSRobert Watson 
49d903306aSRobert Watson 	return (0);
50d903306aSRobert Watson }
51d903306aSRobert Watson 
52d903306aSRobert Watson void
priv_netinet_raw(int asroot,int injail,struct test * test)53d903306aSRobert Watson priv_netinet_raw(int asroot, int injail, struct test *test)
54d903306aSRobert Watson {
55d903306aSRobert Watson 	int error, fd;
56d903306aSRobert Watson 
57d903306aSRobert Watson 	fd = socket(PF_INET, SOCK_RAW, 0);
58d903306aSRobert Watson 	if (fd < 0)
59d903306aSRobert Watson 		error = -1;
60d903306aSRobert Watson 	else
61d903306aSRobert Watson 		error = 0;
62d903306aSRobert Watson 	if (asroot && injail)
63d903306aSRobert Watson 		expect("priv_netinet_raw(asroot, injail)", error, -1, EPERM);
64d903306aSRobert Watson 	if (asroot && !injail)
65d903306aSRobert Watson 		expect("priv_netinet_raw(asroot, !injail)", error, 0, 0);
66d903306aSRobert Watson 	if (!asroot && injail)
67d903306aSRobert Watson 		expect("priv_netinet_raw(!asroot, injail)", error, -1,
68d903306aSRobert Watson 		    EPERM);
69d903306aSRobert Watson 	if (!asroot && !injail)
70d903306aSRobert Watson 		expect("priv_netinet_raw(!asroot, !injail)", error,
71d903306aSRobert Watson 		    -1, EPERM);
72d903306aSRobert Watson 	if (fd >= 0)
73d903306aSRobert Watson 		(void)close(fd);
74d903306aSRobert Watson }
75d903306aSRobert Watson 
76d903306aSRobert Watson void
priv_netinet_raw_cleanup(int asroot,int injail,struct test * test)77d903306aSRobert Watson priv_netinet_raw_cleanup(int asroot, int injail, struct test *test)
78d903306aSRobert Watson {
79d903306aSRobert Watson 
80d903306aSRobert Watson }
81