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