1/* 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. 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 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 4. Neither the name of the University nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)kern_xxx.c 8.2 (Berkeley) 11/14/93 30 */ 31 32#include <sys/cdefs.h>
| 1/* 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. 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 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 4. Neither the name of the University nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)kern_xxx.c 8.2 (Berkeley) 11/14/93 30 */ 31 32#include <sys/cdefs.h>
|
49 50#ifndef _SYS_SYSPROTO_H_ 51struct gethostname_args { 52 char *hostname; 53 u_int len; 54}; 55#endif 56/* 57 * MPSAFE 58 */ 59/* ARGSUSED */ 60int 61ogethostname(td, uap) 62 struct thread *td; 63 struct gethostname_args *uap; 64{ 65 int name[2]; 66 int error; 67 size_t len = uap->len; 68 69 name[0] = CTL_KERN; 70 name[1] = KERN_HOSTNAME; 71 mtx_lock(&Giant); 72 error = userland_sysctl(td, name, 2, uap->hostname, &len, 1, 0, 0, 0); 73 mtx_unlock(&Giant); 74 return(error); 75} 76 77#ifndef _SYS_SYSPROTO_H_ 78struct sethostname_args { 79 char *hostname; 80 u_int len; 81}; 82#endif 83/* 84 * MPSAFE 85 */ 86/* ARGSUSED */ 87int 88osethostname(td, uap) 89 struct thread *td; 90 register struct sethostname_args *uap; 91{ 92 int name[2]; 93 int error; 94 95 name[0] = CTL_KERN; 96 name[1] = KERN_HOSTNAME; 97 mtx_lock(&Giant); 98 if ((error = suser_cred(td->td_ucred, PRISON_ROOT)) == 0) { 99 error = userland_sysctl(td, name, 2, 0, 0, 0, 100 uap->hostname, uap->len, 0); 101 } 102 mtx_unlock(&Giant); 103 return (error); 104} 105 106#ifndef _SYS_SYSPROTO_H_ 107struct ogethostid_args { 108 int dummy; 109}; 110#endif 111/* 112 * MPSAFE 113 */ 114/* ARGSUSED */ 115int 116ogethostid(td, uap) 117 struct thread *td; 118 struct ogethostid_args *uap; 119{ 120 121 *(long *)(td->td_retval) = hostid; 122 return (0); 123}
| 49 50#ifndef _SYS_SYSPROTO_H_ 51struct gethostname_args { 52 char *hostname; 53 u_int len; 54}; 55#endif 56/* 57 * MPSAFE 58 */ 59/* ARGSUSED */ 60int 61ogethostname(td, uap) 62 struct thread *td; 63 struct gethostname_args *uap; 64{ 65 int name[2]; 66 int error; 67 size_t len = uap->len; 68 69 name[0] = CTL_KERN; 70 name[1] = KERN_HOSTNAME; 71 mtx_lock(&Giant); 72 error = userland_sysctl(td, name, 2, uap->hostname, &len, 1, 0, 0, 0); 73 mtx_unlock(&Giant); 74 return(error); 75} 76 77#ifndef _SYS_SYSPROTO_H_ 78struct sethostname_args { 79 char *hostname; 80 u_int len; 81}; 82#endif 83/* 84 * MPSAFE 85 */ 86/* ARGSUSED */ 87int 88osethostname(td, uap) 89 struct thread *td; 90 register struct sethostname_args *uap; 91{ 92 int name[2]; 93 int error; 94 95 name[0] = CTL_KERN; 96 name[1] = KERN_HOSTNAME; 97 mtx_lock(&Giant); 98 if ((error = suser_cred(td->td_ucred, PRISON_ROOT)) == 0) { 99 error = userland_sysctl(td, name, 2, 0, 0, 0, 100 uap->hostname, uap->len, 0); 101 } 102 mtx_unlock(&Giant); 103 return (error); 104} 105 106#ifndef _SYS_SYSPROTO_H_ 107struct ogethostid_args { 108 int dummy; 109}; 110#endif 111/* 112 * MPSAFE 113 */ 114/* ARGSUSED */ 115int 116ogethostid(td, uap) 117 struct thread *td; 118 struct ogethostid_args *uap; 119{ 120 121 *(long *)(td->td_retval) = hostid; 122 return (0); 123}
|
125 126#ifdef COMPAT_43 127#ifndef _SYS_SYSPROTO_H_ 128struct osethostid_args { 129 long hostid; 130}; 131#endif 132/* 133 * MPSAFE 134 */ 135/* ARGSUSED */ 136int 137osethostid(td, uap) 138 struct thread *td; 139 struct osethostid_args *uap; 140{ 141 int error; 142 143 if ((error = suser(td))) 144 return (error); 145 mtx_lock(&Giant); 146 hostid = uap->hostid; 147 mtx_unlock(&Giant); 148 return (0); 149} 150 151/* 152 * MPSAFE 153 */ 154int 155oquota(td, uap) 156 struct thread *td; 157 struct oquota_args *uap; 158{ 159 return (ENOSYS); 160} 161#endif /* COMPAT_43 */ 162 163/* 164 * This is the FreeBSD-1.1 compatable uname(2) interface. These 165 * days it is done in libc as a wrapper around a bunch of sysctl's. 166 * This must maintain the old 1.1 binary ABI. 167 */ 168#if SYS_NMLN != 32 169#error "FreeBSD-1.1 uname syscall has been broken" 170#endif 171#ifndef _SYS_SYSPROTO_H_ 172struct uname_args { 173 struct utsname *name; 174}; 175#endif 176 177/* 178 * MPSAFE 179 */ 180/* ARGSUSED */ 181int 182uname(td, uap) 183 struct thread *td; 184 struct uname_args *uap; 185{ 186 int name[2], error; 187 size_t len; 188 char *s, *us; 189 190 name[0] = CTL_KERN; 191 name[1] = KERN_OSTYPE; 192 len = sizeof (uap->name->sysname); 193 mtx_lock(&Giant); 194 error = userland_sysctl(td, name, 2, uap->name->sysname, &len, 195 1, 0, 0, 0); 196 if (error) 197 goto done2; 198 subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0); 199 200 name[1] = KERN_HOSTNAME; 201 len = sizeof uap->name->nodename; 202 error = userland_sysctl(td, name, 2, uap->name->nodename, &len, 203 1, 0, 0, 0); 204 if (error) 205 goto done2; 206 subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0); 207 208 name[1] = KERN_OSRELEASE; 209 len = sizeof uap->name->release; 210 error = userland_sysctl(td, name, 2, uap->name->release, &len, 211 1, 0, 0, 0); 212 if (error) 213 goto done2; 214 subyte( uap->name->release + sizeof(uap->name->release) - 1, 0); 215 216/* 217 name = KERN_VERSION; 218 len = sizeof uap->name->version; 219 error = userland_sysctl(td, name, 2, uap->name->version, &len, 220 1, 0, 0, 0); 221 if (error) 222 goto done2; 223 subyte( uap->name->version + sizeof(uap->name->version) - 1, 0); 224*/ 225 226/* 227 * this stupid hackery to make the version field look like FreeBSD 1.1 228 */ 229 for(s = version; *s && *s != '#'; s++); 230 231 for(us = uap->name->version; *s && *s != ':'; s++) { 232 error = subyte( us++, *s); 233 if (error) 234 goto done2; 235 } 236 error = subyte( us++, 0); 237 if (error) 238 goto done2; 239 240 name[0] = CTL_HW; 241 name[1] = HW_MACHINE; 242 len = sizeof uap->name->machine; 243 error = userland_sysctl(td, name, 2, uap->name->machine, &len, 244 1, 0, 0, 0); 245 if (error) 246 goto done2; 247 subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0); 248done2: 249 mtx_unlock(&Giant); 250 return (error); 251} 252 253#ifndef _SYS_SYSPROTO_H_ 254struct getdomainname_args { 255 char *domainname; 256 int len; 257}; 258#endif 259 260/* 261 * MPSAFE 262 */ 263/* ARGSUSED */ 264int 265getdomainname(td, uap) 266 struct thread *td; 267 struct getdomainname_args *uap; 268{ 269 int domainnamelen; 270 int error; 271 272 mtx_lock(&Giant); 273 domainnamelen = strlen(domainname) + 1; 274 if ((u_int)uap->len > domainnamelen) 275 uap->len = domainnamelen; 276 error = copyout(domainname, uap->domainname, uap->len); 277 mtx_unlock(&Giant); 278 return (error); 279} 280 281#ifndef _SYS_SYSPROTO_H_ 282struct setdomainname_args { 283 char *domainname; 284 int len; 285}; 286#endif 287 288/* 289 * MPSAFE 290 */ 291/* ARGSUSED */ 292int 293setdomainname(td, uap) 294 struct thread *td; 295 struct setdomainname_args *uap; 296{ 297 int error, domainnamelen; 298 299 mtx_lock(&Giant); 300 if ((error = suser(td))) 301 goto done2; 302 if ((u_int)uap->len > sizeof (domainname) - 1) { 303 error = EINVAL; 304 goto done2; 305 } 306 domainnamelen = uap->len; 307 error = copyin(uap->domainname, domainname, uap->len); 308 domainname[domainnamelen] = 0; 309done2: 310 mtx_unlock(&Giant); 311 return (error); 312} 313
| 125 126#ifdef COMPAT_43 127#ifndef _SYS_SYSPROTO_H_ 128struct osethostid_args { 129 long hostid; 130}; 131#endif 132/* 133 * MPSAFE 134 */ 135/* ARGSUSED */ 136int 137osethostid(td, uap) 138 struct thread *td; 139 struct osethostid_args *uap; 140{ 141 int error; 142 143 if ((error = suser(td))) 144 return (error); 145 mtx_lock(&Giant); 146 hostid = uap->hostid; 147 mtx_unlock(&Giant); 148 return (0); 149} 150 151/* 152 * MPSAFE 153 */ 154int 155oquota(td, uap) 156 struct thread *td; 157 struct oquota_args *uap; 158{ 159 return (ENOSYS); 160} 161#endif /* COMPAT_43 */ 162 163/* 164 * This is the FreeBSD-1.1 compatable uname(2) interface. These 165 * days it is done in libc as a wrapper around a bunch of sysctl's. 166 * This must maintain the old 1.1 binary ABI. 167 */ 168#if SYS_NMLN != 32 169#error "FreeBSD-1.1 uname syscall has been broken" 170#endif 171#ifndef _SYS_SYSPROTO_H_ 172struct uname_args { 173 struct utsname *name; 174}; 175#endif 176 177/* 178 * MPSAFE 179 */ 180/* ARGSUSED */ 181int 182uname(td, uap) 183 struct thread *td; 184 struct uname_args *uap; 185{ 186 int name[2], error; 187 size_t len; 188 char *s, *us; 189 190 name[0] = CTL_KERN; 191 name[1] = KERN_OSTYPE; 192 len = sizeof (uap->name->sysname); 193 mtx_lock(&Giant); 194 error = userland_sysctl(td, name, 2, uap->name->sysname, &len, 195 1, 0, 0, 0); 196 if (error) 197 goto done2; 198 subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0); 199 200 name[1] = KERN_HOSTNAME; 201 len = sizeof uap->name->nodename; 202 error = userland_sysctl(td, name, 2, uap->name->nodename, &len, 203 1, 0, 0, 0); 204 if (error) 205 goto done2; 206 subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0); 207 208 name[1] = KERN_OSRELEASE; 209 len = sizeof uap->name->release; 210 error = userland_sysctl(td, name, 2, uap->name->release, &len, 211 1, 0, 0, 0); 212 if (error) 213 goto done2; 214 subyte( uap->name->release + sizeof(uap->name->release) - 1, 0); 215 216/* 217 name = KERN_VERSION; 218 len = sizeof uap->name->version; 219 error = userland_sysctl(td, name, 2, uap->name->version, &len, 220 1, 0, 0, 0); 221 if (error) 222 goto done2; 223 subyte( uap->name->version + sizeof(uap->name->version) - 1, 0); 224*/ 225 226/* 227 * this stupid hackery to make the version field look like FreeBSD 1.1 228 */ 229 for(s = version; *s && *s != '#'; s++); 230 231 for(us = uap->name->version; *s && *s != ':'; s++) { 232 error = subyte( us++, *s); 233 if (error) 234 goto done2; 235 } 236 error = subyte( us++, 0); 237 if (error) 238 goto done2; 239 240 name[0] = CTL_HW; 241 name[1] = HW_MACHINE; 242 len = sizeof uap->name->machine; 243 error = userland_sysctl(td, name, 2, uap->name->machine, &len, 244 1, 0, 0, 0); 245 if (error) 246 goto done2; 247 subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0); 248done2: 249 mtx_unlock(&Giant); 250 return (error); 251} 252 253#ifndef _SYS_SYSPROTO_H_ 254struct getdomainname_args { 255 char *domainname; 256 int len; 257}; 258#endif 259 260/* 261 * MPSAFE 262 */ 263/* ARGSUSED */ 264int 265getdomainname(td, uap) 266 struct thread *td; 267 struct getdomainname_args *uap; 268{ 269 int domainnamelen; 270 int error; 271 272 mtx_lock(&Giant); 273 domainnamelen = strlen(domainname) + 1; 274 if ((u_int)uap->len > domainnamelen) 275 uap->len = domainnamelen; 276 error = copyout(domainname, uap->domainname, uap->len); 277 mtx_unlock(&Giant); 278 return (error); 279} 280 281#ifndef _SYS_SYSPROTO_H_ 282struct setdomainname_args { 283 char *domainname; 284 int len; 285}; 286#endif 287 288/* 289 * MPSAFE 290 */ 291/* ARGSUSED */ 292int 293setdomainname(td, uap) 294 struct thread *td; 295 struct setdomainname_args *uap; 296{ 297 int error, domainnamelen; 298 299 mtx_lock(&Giant); 300 if ((error = suser(td))) 301 goto done2; 302 if ((u_int)uap->len > sizeof (domainname) - 1) { 303 error = EINVAL; 304 goto done2; 305 } 306 domainnamelen = uap->len; 307 error = copyin(uap->domainname, domainname, uap->len); 308 domainname[domainnamelen] = 0; 309done2: 310 mtx_unlock(&Giant); 311 return (error); 312} 313
|