priv_kenv_set.c revision 172106
11556Srgrimes/*- 21556Srgrimes * Copyright (c) 2006 nCircle Network Security, Inc. 31556Srgrimes * Copyright (c) 2007 Robert N. M. Watson 41556Srgrimes * All rights reserved. 51556Srgrimes * 61556Srgrimes * This software was developed by Robert N. M. Watson for the TrustedBSD 71556Srgrimes * Project under contract to nCircle Network Security, Inc. 81556Srgrimes * 91556Srgrimes * Redistribution and use in source and binary forms, with or without 101556Srgrimes * modification, are permitted provided that the following conditions 111556Srgrimes * are met: 121556Srgrimes * 1. Redistributions of source code must retain the above copyright 131556Srgrimes * notice, this list of conditions and the following disclaimer. 141556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 151556Srgrimes * notice, this list of conditions and the following disclaimer in the 161556Srgrimes * documentation and/or other materials provided with the distribution. 171556Srgrimes * 181556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 191556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 201556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 211556Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR, NCIRCLE NETWORK SECURITY, 221556Srgrimes * INC., OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 231556Srgrimes * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 241556Srgrimes * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 251556Srgrimes * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 261556Srgrimes * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 271556Srgrimes * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 281556Srgrimes * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 291556Srgrimes * 301556Srgrimes * $FreeBSD: head/tools/regression/priv/priv_kenv_set.c 172106 2007-09-09 23:08:39Z rwatson $ 3128642Ssteve */ 3228642Ssteve 3328642Ssteve/* 341556Srgrimes * Test that setting a kernel environment variable requires privilege. 3599110Sobrien */ 3699110Sobrien 371556Srgrimes#include <sys/types.h> 381556Srgrimes 391556Srgrimes#include <err.h> 401556Srgrimes#include <errno.h> 411556Srgrimes#include <kenv.h> 421556Srgrimes#include <string.h> 431556Srgrimes#include <unistd.h> 441556Srgrimes 451556Srgrimes#include "main.h" 461556Srgrimes 471556Srgrimesint 481556Srgrimespriv_kenv_set_setup(int asroot, int injail, struct test *test) 491556Srgrimes{ 5090111Simp 5190111Simp (void)kenv(KENV_UNSET, KENV_VAR_NAME, NULL, 0); 5290111Simp return (0); 5390111Simp} 5490111Simp 5590111Simpvoid 5690111Simppriv_kenv_set(int asroot, int injail, struct test *test) 5790111Simp{ 5890111Simp int error; 5990111Simp 6090111Simp error = kenv(KENV_SET, KENV_VAR_NAME, KENV_VAR_VALUE, KENV_VAR_LEN); 6190111Simp if (asroot && injail) 6290111Simp expect("priv_kenv_set(asroot, injail)", error, -1, EPERM); 6390111Simp if (asroot && !injail) 6490111Simp expect("priv_kenv_set(asroot, !injail)", error, 0, 0); 6590111Simp if (!asroot && injail) 6690111Simp expect("priv_kenv_set(!asroot, injail)", error, -1, EPERM); 671556Srgrimes if (!asroot && !injail) 681556Srgrimes expect("priv_kenv_set(!asroot, !injail)", error, -1, EPERM); 691556Srgrimes} 7076810Skris 7190111Simpvoid 721556Srgrimespriv_kenv_set_cleanup(int asroot, int injail, struct test *test) 731556Srgrimes{ 741556Srgrimes 751556Srgrimes (void)kenv(KENV_UNSET, KENV_VAR_NAME, NULL, 0); 761556Srgrimes} 771556Srgrimes