kern_environment.c (105354) | kern_environment.c (106308) |
---|---|
1/*- 2 * Copyright (c) 1998 Michael Smith 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (c) 1998 Michael Smith 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/sys/kern/kern_environment.c 105354 2002-10-17 20:03:38Z robert $ | 26 * $FreeBSD: head/sys/kern/kern_environment.c 106308 2002-11-01 20:46:53Z rwatson $ |
27 */ 28 29/* 30 * The unified bootloader passes us a pointer to a preserved copy of 31 * bootstrap/kernel environment variables. We convert them to a 32 * dynamic array of strings later when the VM subsystem is up. 33 * 34 * We make these available through the kenv(2) syscall for userland 35 * and through getenv()/freeenv() setenv() unsetenv() testenv() for 36 * the kernel. 37 */ 38 | 27 */ 28 29/* 30 * The unified bootloader passes us a pointer to a preserved copy of 31 * bootstrap/kernel environment variables. We convert them to a 32 * dynamic array of strings later when the VM subsystem is up. 33 * 34 * We make these available through the kenv(2) syscall for userland 35 * and through getenv()/freeenv() setenv() unsetenv() testenv() for 36 * the kernel. 37 */ 38 |
39#include "opt_mac.h" 40 |
|
39#include <sys/types.h> 40#include <sys/param.h> 41#include <sys/proc.h> 42#include <sys/queue.h> 43#include <sys/lock.h> | 41#include <sys/types.h> 42#include <sys/param.h> 43#include <sys/proc.h> 44#include <sys/queue.h> 45#include <sys/lock.h> |
46#include <sys/mac.h> |
|
44#include <sys/malloc.h> 45#include <sys/mutex.h> 46#include <sys/kernel.h> 47#include <sys/sx.h> 48#include <sys/systm.h> 49#include <sys/sysent.h> 50#include <sys/sysproto.h> 51#include <sys/libkern.h> --- 33 unchanged lines hidden (view full) --- 85 char *name, *value; 86 size_t len, done; 87 int error, i; 88 89 KASSERT(dynamic_kenv, ("kenv: dynamic_kenv = 0")); 90 91 error = 0; 92 if (SCARG(uap, what) == KENV_DUMP) { | 47#include <sys/malloc.h> 48#include <sys/mutex.h> 49#include <sys/kernel.h> 50#include <sys/sx.h> 51#include <sys/systm.h> 52#include <sys/sysent.h> 53#include <sys/sysproto.h> 54#include <sys/libkern.h> --- 33 unchanged lines hidden (view full) --- 88 char *name, *value; 89 size_t len, done; 90 int error, i; 91 92 KASSERT(dynamic_kenv, ("kenv: dynamic_kenv = 0")); 93 94 error = 0; 95 if (SCARG(uap, what) == KENV_DUMP) { |
96#ifdef MAC 97 error = mac_check_kenv_dump(td->td_ucred); 98 if (error) 99 return (error); 100#endif |
|
93 len = 0; 94 /* Return the size if called with a NULL buffer */ 95 if (SCARG(uap, value) == NULL) { 96 sx_slock(&kenv_lock); 97 for (i = 0; kenvp[i] != NULL; i++) 98 len += strlen(kenvp[i]) + 1; 99 sx_sunlock(&kenv_lock); 100 td->td_retval[0] = len; --- 25 unchanged lines hidden (view full) --- 126 name = malloc(KENV_MNAMELEN, M_TEMP, M_WAITOK); 127 128 error = copyinstr(SCARG(uap, name), name, KENV_MNAMELEN, NULL); 129 if (error) 130 goto done; 131 132 switch (SCARG(uap, what)) { 133 case KENV_GET: | 101 len = 0; 102 /* Return the size if called with a NULL buffer */ 103 if (SCARG(uap, value) == NULL) { 104 sx_slock(&kenv_lock); 105 for (i = 0; kenvp[i] != NULL; i++) 106 len += strlen(kenvp[i]) + 1; 107 sx_sunlock(&kenv_lock); 108 td->td_retval[0] = len; --- 25 unchanged lines hidden (view full) --- 134 name = malloc(KENV_MNAMELEN, M_TEMP, M_WAITOK); 135 136 error = copyinstr(SCARG(uap, name), name, KENV_MNAMELEN, NULL); 137 if (error) 138 goto done; 139 140 switch (SCARG(uap, what)) { 141 case KENV_GET: |
142#ifdef MAC 143 error = mac_check_kenv_get(td->td_ucred, name); 144 if (error) 145 goto done; 146#endif |
|
134 value = getenv(name); 135 if (value == NULL) { 136 error = ENOENT; 137 goto done; 138 } 139 len = strlen(value) + 1; 140 if (len > SCARG(uap, len)) 141 len = SCARG(uap, len); --- 12 unchanged lines hidden (view full) --- 154 if (len > KENV_MVALLEN) 155 len = KENV_MVALLEN; 156 value = malloc(len, M_TEMP, M_WAITOK); 157 error = copyinstr(SCARG(uap, value), value, len, NULL); 158 if (error) { 159 free(value, M_TEMP); 160 goto done; 161 } | 147 value = getenv(name); 148 if (value == NULL) { 149 error = ENOENT; 150 goto done; 151 } 152 len = strlen(value) + 1; 153 if (len > SCARG(uap, len)) 154 len = SCARG(uap, len); --- 12 unchanged lines hidden (view full) --- 167 if (len > KENV_MVALLEN) 168 len = KENV_MVALLEN; 169 value = malloc(len, M_TEMP, M_WAITOK); 170 error = copyinstr(SCARG(uap, value), value, len, NULL); 171 if (error) { 172 free(value, M_TEMP); 173 goto done; 174 } |
162 setenv(name, value); | 175#ifdef MAC 176 error = mac_check_kenv_set(td->td_ucred, name, value); 177 if (error == 0) 178#endif 179 setenv(name, value); |
163 free(value, M_TEMP); 164 break; 165 case KENV_UNSET: | 180 free(value, M_TEMP); 181 break; 182 case KENV_UNSET: |
183#ifdef MAC 184 error = mac_check_kenv_unset(td->td_ucred, name); 185 if (error) 186 goto done; 187#endif |
|
166 error = unsetenv(name); 167 if (error) 168 error = ENOENT; 169 break; 170 default: 171 error = EINVAL; 172 break; 173 } --- 287 unchanged lines hidden --- | 188 error = unsetenv(name); 189 if (error) 190 error = ENOENT; 191 break; 192 default: 193 error = EINVAL; 194 break; 195 } --- 287 unchanged lines hidden --- |