16007da5fSBjoern A. Zeeb /*- 26007da5fSBjoern A. Zeeb * Copyright (c) 2007 Bjoern A. Zeeb 36007da5fSBjoern A. Zeeb * All rights reserved. 46007da5fSBjoern A. Zeeb * 56007da5fSBjoern A. Zeeb * Redistribution and use in source and binary forms, with or without 66007da5fSBjoern A. Zeeb * modification, are permitted provided that the following conditions 76007da5fSBjoern A. Zeeb * are met: 86007da5fSBjoern A. Zeeb * 1. Redistributions of source code must retain the above copyright 96007da5fSBjoern A. Zeeb * notice, this list of conditions and the following disclaimer. 106007da5fSBjoern A. Zeeb * 2. Redistributions in binary form must reproduce the above copyright 116007da5fSBjoern A. Zeeb * notice, this list of conditions and the following disclaimer in the 126007da5fSBjoern A. Zeeb * documentation and/or other materials provided with the distribution. 136007da5fSBjoern A. Zeeb * 146007da5fSBjoern A. Zeeb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 156007da5fSBjoern A. Zeeb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 166007da5fSBjoern A. Zeeb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 176007da5fSBjoern A. Zeeb * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR, NCIRCLE NETWORK SECURITY, 186007da5fSBjoern A. Zeeb * INC., OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 196007da5fSBjoern A. Zeeb * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 206007da5fSBjoern A. Zeeb * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 216007da5fSBjoern A. Zeeb * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 226007da5fSBjoern A. Zeeb * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 236007da5fSBjoern A. Zeeb * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 246007da5fSBjoern A. Zeeb * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 256007da5fSBjoern A. Zeeb * 266007da5fSBjoern A. Zeeb * $FreeBSD$ 276007da5fSBjoern A. Zeeb */ 286007da5fSBjoern A. Zeeb 296007da5fSBjoern A. Zeeb /* 306007da5fSBjoern A. Zeeb * Confirm that privilege is required to open a pfkey socket, and that this 316007da5fSBjoern A. Zeeb * is not allowed in jail. 326007da5fSBjoern A. Zeeb */ 336007da5fSBjoern A. Zeeb 346007da5fSBjoern A. Zeeb #include <sys/types.h> 356007da5fSBjoern A. Zeeb #include <sys/socket.h> 366007da5fSBjoern A. Zeeb #include <net/pfkeyv2.h> 376007da5fSBjoern A. Zeeb 386007da5fSBjoern A. Zeeb #include <errno.h> 396007da5fSBjoern A. Zeeb #include <unistd.h> 406007da5fSBjoern A. Zeeb 416007da5fSBjoern A. Zeeb #include "main.h" 426007da5fSBjoern A. Zeeb 436007da5fSBjoern A. Zeeb int 446007da5fSBjoern A. Zeeb priv_netinet_ipsec_pfkey_setup(int asroot, int injail, struct test *test) 456007da5fSBjoern A. Zeeb { 466007da5fSBjoern A. Zeeb 476007da5fSBjoern A. Zeeb return (0); 486007da5fSBjoern A. Zeeb } 496007da5fSBjoern A. Zeeb 506007da5fSBjoern A. Zeeb void 516007da5fSBjoern A. Zeeb priv_netinet_ipsec_pfkey(int asroot, int injail, struct test *test) 526007da5fSBjoern A. Zeeb { 536007da5fSBjoern A. Zeeb int error, fd; 546007da5fSBjoern A. Zeeb 556007da5fSBjoern A. Zeeb fd = socket(PF_KEY, SOCK_RAW, PF_KEY_V2); 566007da5fSBjoern A. Zeeb if (fd < 0) 576007da5fSBjoern A. Zeeb error = -1; 586007da5fSBjoern A. Zeeb else 596007da5fSBjoern A. Zeeb error = 0; 606007da5fSBjoern A. Zeeb /* 616007da5fSBjoern A. Zeeb * The injail checks are not really priv checks but making sure 626007da5fSBjoern A. Zeeb * sys/kern/uipc_socket.c:socreate cred checks are working correctly. 636007da5fSBjoern A. Zeeb */ 646007da5fSBjoern A. Zeeb if (asroot && injail) 656007da5fSBjoern A. Zeeb expect("priv_netinet_ipsec_pfkey(asroot, injail)", error, 666007da5fSBjoern A. Zeeb -1, EPROTONOSUPPORT); 676007da5fSBjoern A. Zeeb if (asroot && !injail) 686007da5fSBjoern A. Zeeb expect("priv_netinet_ipsec_pfkey(asroot, !injail)", error, 696007da5fSBjoern A. Zeeb 0, 0); 706007da5fSBjoern A. Zeeb if (!asroot && injail) 716007da5fSBjoern A. Zeeb expect("priv_netinet_ipsec_pfkey(!asroot, injail)", error, 726007da5fSBjoern A. Zeeb -1, EPROTONOSUPPORT); 736007da5fSBjoern A. Zeeb if (!asroot && !injail) 746007da5fSBjoern A. Zeeb expect("priv_netinet_ipsec_pfkey(!asroot, !injail)", error, 756007da5fSBjoern A. Zeeb -1, EPERM); 766007da5fSBjoern A. Zeeb if (fd >= 0) 776007da5fSBjoern A. Zeeb (void)close(fd); 786007da5fSBjoern A. Zeeb } 796007da5fSBjoern A. Zeeb 806007da5fSBjoern A. Zeeb void 816007da5fSBjoern A. Zeeb priv_netinet_ipsec_pfkey_cleanup(int asroot, int injail, struct test *test) 826007da5fSBjoern A. Zeeb { 836007da5fSBjoern A. Zeeb 846007da5fSBjoern A. Zeeb } 856007da5fSBjoern A. Zeeb 86