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>
|
33__FBSDID("$FreeBSD: head/sys/kern/kern_xxx.c 183550 2008-10-02 15:37:58Z zec $");
| 33__FBSDID("$FreeBSD: head/sys/kern/kern_xxx.c 184789 2008-11-09 10:45:13Z ed $");
|
34 35#include "opt_compat.h" 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/sysproto.h> 40#include <sys/kernel.h> 41#include <sys/priv.h> 42#include <sys/proc.h> 43#include <sys/lock.h> 44#include <sys/mutex.h> 45#include <sys/sysctl.h> 46#include <sys/utsname.h> 47#include <sys/vimage.h> 48 49 50#if defined(COMPAT_43) 51 52#ifndef _SYS_SYSPROTO_H_ 53struct gethostname_args { 54 char *hostname; 55 u_int len; 56}; 57#endif 58/* ARGSUSED */ 59int 60ogethostname(td, uap) 61 struct thread *td; 62 struct gethostname_args *uap; 63{ 64 int name[2]; 65 int error; 66 size_t len = uap->len; 67 68 name[0] = CTL_KERN; 69 name[1] = KERN_HOSTNAME; 70 mtx_lock(&Giant); 71 error = userland_sysctl(td, name, 2, uap->hostname, &len, 72 1, 0, 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/* ARGSUSED */ 84int 85osethostname(td, uap) 86 struct thread *td; 87 register struct sethostname_args *uap; 88{ 89 int name[2]; 90 int error; 91 92 name[0] = CTL_KERN; 93 name[1] = KERN_HOSTNAME; 94 mtx_lock(&Giant); 95 error = userland_sysctl(td, name, 2, 0, 0, 0, uap->hostname, 96 uap->len, 0, 0); 97 mtx_unlock(&Giant); 98 return (error); 99} 100 101#ifndef _SYS_SYSPROTO_H_ 102struct ogethostid_args { 103 int dummy; 104}; 105#endif 106/* ARGSUSED */ 107int 108ogethostid(td, uap) 109 struct thread *td; 110 struct ogethostid_args *uap; 111{ 112 113 *(long *)(td->td_retval) = hostid; 114 return (0); 115} 116#endif /* COMPAT_43 */ 117 118#ifdef COMPAT_43 119#ifndef _SYS_SYSPROTO_H_ 120struct osethostid_args { 121 long hostid; 122}; 123#endif 124/* ARGSUSED */ 125int 126osethostid(td, uap) 127 struct thread *td; 128 struct osethostid_args *uap; 129{ 130 int error; 131 132 error = priv_check(td, PRIV_SETHOSTID); 133 if (error) 134 return (error); 135 mtx_lock(&Giant); 136 hostid = uap->hostid; 137 mtx_unlock(&Giant); 138 return (0); 139} 140 141int 142oquota(td, uap) 143 struct thread *td; 144 struct oquota_args *uap; 145{ 146 147 return (ENOSYS); 148} 149#endif /* COMPAT_43 */ 150
| 34 35#include "opt_compat.h" 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/sysproto.h> 40#include <sys/kernel.h> 41#include <sys/priv.h> 42#include <sys/proc.h> 43#include <sys/lock.h> 44#include <sys/mutex.h> 45#include <sys/sysctl.h> 46#include <sys/utsname.h> 47#include <sys/vimage.h> 48 49 50#if defined(COMPAT_43) 51 52#ifndef _SYS_SYSPROTO_H_ 53struct gethostname_args { 54 char *hostname; 55 u_int len; 56}; 57#endif 58/* ARGSUSED */ 59int 60ogethostname(td, uap) 61 struct thread *td; 62 struct gethostname_args *uap; 63{ 64 int name[2]; 65 int error; 66 size_t len = uap->len; 67 68 name[0] = CTL_KERN; 69 name[1] = KERN_HOSTNAME; 70 mtx_lock(&Giant); 71 error = userland_sysctl(td, name, 2, uap->hostname, &len, 72 1, 0, 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/* ARGSUSED */ 84int 85osethostname(td, uap) 86 struct thread *td; 87 register struct sethostname_args *uap; 88{ 89 int name[2]; 90 int error; 91 92 name[0] = CTL_KERN; 93 name[1] = KERN_HOSTNAME; 94 mtx_lock(&Giant); 95 error = userland_sysctl(td, name, 2, 0, 0, 0, uap->hostname, 96 uap->len, 0, 0); 97 mtx_unlock(&Giant); 98 return (error); 99} 100 101#ifndef _SYS_SYSPROTO_H_ 102struct ogethostid_args { 103 int dummy; 104}; 105#endif 106/* ARGSUSED */ 107int 108ogethostid(td, uap) 109 struct thread *td; 110 struct ogethostid_args *uap; 111{ 112 113 *(long *)(td->td_retval) = hostid; 114 return (0); 115} 116#endif /* COMPAT_43 */ 117 118#ifdef COMPAT_43 119#ifndef _SYS_SYSPROTO_H_ 120struct osethostid_args { 121 long hostid; 122}; 123#endif 124/* ARGSUSED */ 125int 126osethostid(td, uap) 127 struct thread *td; 128 struct osethostid_args *uap; 129{ 130 int error; 131 132 error = priv_check(td, PRIV_SETHOSTID); 133 if (error) 134 return (error); 135 mtx_lock(&Giant); 136 hostid = uap->hostid; 137 mtx_unlock(&Giant); 138 return (0); 139} 140 141int 142oquota(td, uap) 143 struct thread *td; 144 struct oquota_args *uap; 145{ 146 147 return (ENOSYS); 148} 149#endif /* COMPAT_43 */ 150
|
| 151#ifdef COMPAT_FREEBSD4
|
151/*
| 152/*
|
152 * This is the FreeBSD-1.1 compatable uname(2) interface. These days it is
| 153 * This is the FreeBSD-1.1 compatible uname(2) interface. These days it is
|
153 * done in libc as a wrapper around a bunch of sysctl's. This must maintain 154 * the old 1.1 binary ABI. 155 */ 156#if SYS_NMLN != 32 157#error "FreeBSD-1.1 uname syscall has been broken" 158#endif 159#ifndef _SYS_SYSPROTO_H_ 160struct uname_args { 161 struct utsname *name; 162}; 163#endif 164/* ARGSUSED */ 165int
| 154 * done in libc as a wrapper around a bunch of sysctl's. This must maintain 155 * the old 1.1 binary ABI. 156 */ 157#if SYS_NMLN != 32 158#error "FreeBSD-1.1 uname syscall has been broken" 159#endif 160#ifndef _SYS_SYSPROTO_H_ 161struct uname_args { 162 struct utsname *name; 163}; 164#endif 165/* ARGSUSED */ 166int
|
166uname(td, uap) 167 struct thread *td; 168 struct uname_args *uap;
| 167freebsd4_uname(struct thread *td, struct freebsd4_uname_args *uap)
|
169{ 170 int name[2], error; 171 size_t len; 172 char *s, *us; 173 174 name[0] = CTL_KERN; 175 name[1] = KERN_OSTYPE; 176 len = sizeof (uap->name->sysname); 177 mtx_lock(&Giant); 178 error = userland_sysctl(td, name, 2, uap->name->sysname, &len, 179 1, 0, 0, 0, 0); 180 if (error) 181 goto done2; 182 subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0); 183 184 name[1] = KERN_HOSTNAME; 185 len = sizeof uap->name->nodename; 186 error = userland_sysctl(td, name, 2, uap->name->nodename, &len, 187 1, 0, 0, 0, 0); 188 if (error) 189 goto done2; 190 subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0); 191 192 name[1] = KERN_OSRELEASE; 193 len = sizeof uap->name->release; 194 error = userland_sysctl(td, name, 2, uap->name->release, &len, 195 1, 0, 0, 0, 0); 196 if (error) 197 goto done2; 198 subyte( uap->name->release + sizeof(uap->name->release) - 1, 0); 199 200/* 201 name = KERN_VERSION; 202 len = sizeof uap->name->version; 203 error = userland_sysctl(td, name, 2, uap->name->version, &len, 204 1, 0, 0, 0, 0); 205 if (error) 206 goto done2; 207 subyte( uap->name->version + sizeof(uap->name->version) - 1, 0); 208*/ 209 210/* 211 * this stupid hackery to make the version field look like FreeBSD 1.1 212 */ 213 for(s = version; *s && *s != '#'; s++); 214 215 for(us = uap->name->version; *s && *s != ':'; s++) { 216 error = subyte( us++, *s); 217 if (error) 218 goto done2; 219 } 220 error = subyte( us++, 0); 221 if (error) 222 goto done2; 223 224 name[0] = CTL_HW; 225 name[1] = HW_MACHINE; 226 len = sizeof uap->name->machine; 227 error = userland_sysctl(td, name, 2, uap->name->machine, &len, 228 1, 0, 0, 0, 0); 229 if (error) 230 goto done2; 231 subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0); 232done2: 233 mtx_unlock(&Giant); 234 return (error); 235} 236 237#ifndef _SYS_SYSPROTO_H_ 238struct getdomainname_args { 239 char *domainname; 240 int len; 241}; 242#endif 243/* ARGSUSED */ 244int
| 168{ 169 int name[2], error; 170 size_t len; 171 char *s, *us; 172 173 name[0] = CTL_KERN; 174 name[1] = KERN_OSTYPE; 175 len = sizeof (uap->name->sysname); 176 mtx_lock(&Giant); 177 error = userland_sysctl(td, name, 2, uap->name->sysname, &len, 178 1, 0, 0, 0, 0); 179 if (error) 180 goto done2; 181 subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0); 182 183 name[1] = KERN_HOSTNAME; 184 len = sizeof uap->name->nodename; 185 error = userland_sysctl(td, name, 2, uap->name->nodename, &len, 186 1, 0, 0, 0, 0); 187 if (error) 188 goto done2; 189 subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0); 190 191 name[1] = KERN_OSRELEASE; 192 len = sizeof uap->name->release; 193 error = userland_sysctl(td, name, 2, uap->name->release, &len, 194 1, 0, 0, 0, 0); 195 if (error) 196 goto done2; 197 subyte( uap->name->release + sizeof(uap->name->release) - 1, 0); 198 199/* 200 name = KERN_VERSION; 201 len = sizeof uap->name->version; 202 error = userland_sysctl(td, name, 2, uap->name->version, &len, 203 1, 0, 0, 0, 0); 204 if (error) 205 goto done2; 206 subyte( uap->name->version + sizeof(uap->name->version) - 1, 0); 207*/ 208 209/* 210 * this stupid hackery to make the version field look like FreeBSD 1.1 211 */ 212 for(s = version; *s && *s != '#'; s++); 213 214 for(us = uap->name->version; *s && *s != ':'; s++) { 215 error = subyte( us++, *s); 216 if (error) 217 goto done2; 218 } 219 error = subyte( us++, 0); 220 if (error) 221 goto done2; 222 223 name[0] = CTL_HW; 224 name[1] = HW_MACHINE; 225 len = sizeof uap->name->machine; 226 error = userland_sysctl(td, name, 2, uap->name->machine, &len, 227 1, 0, 0, 0, 0); 228 if (error) 229 goto done2; 230 subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0); 231done2: 232 mtx_unlock(&Giant); 233 return (error); 234} 235 236#ifndef _SYS_SYSPROTO_H_ 237struct getdomainname_args { 238 char *domainname; 239 int len; 240}; 241#endif 242/* ARGSUSED */ 243int
|
245getdomainname(td, uap) 246 struct thread *td; 247 struct getdomainname_args *uap;
| 244freebsd4_getdomainname(struct thread *td, 245 struct freebsd4_getdomainname_args *uap)
|
248{
| 246{
|
249 INIT_VPROCG(TD_TO_VPROCG(td)); 250 char tmpdomainname[MAXHOSTNAMELEN]; 251 int domainnamelen;
| 247 int name[2]; 248 int error; 249 size_t len = uap->len;
|
252
| 250
|
253 mtx_lock(&hostname_mtx); 254 bcopy(V_domainname, tmpdomainname, sizeof(tmpdomainname)); 255 mtx_unlock(&hostname_mtx); 256 257 domainnamelen = strlen(tmpdomainname) + 1; 258 if ((u_int)uap->len > domainnamelen) 259 uap->len = domainnamelen; 260 return (copyout(tmpdomainname, uap->domainname, uap->len));
| 251 name[0] = CTL_KERN; 252 name[1] = KERN_NISDOMAINNAME; 253 mtx_lock(&Giant); 254 error = userland_sysctl(td, name, 2, uap->domainname, &len, 255 1, 0, 0, 0, 0); 256 mtx_unlock(&Giant); 257 return(error);
|
261} 262 263#ifndef _SYS_SYSPROTO_H_ 264struct setdomainname_args { 265 char *domainname; 266 int len; 267}; 268#endif 269/* ARGSUSED */ 270int
| 258} 259 260#ifndef _SYS_SYSPROTO_H_ 261struct setdomainname_args { 262 char *domainname; 263 int len; 264}; 265#endif 266/* ARGSUSED */ 267int
|
271setdomainname(td, uap) 272 struct thread *td; 273 struct setdomainname_args *uap;
| 268freebsd4_setdomainname(struct thread *td, 269 struct freebsd4_setdomainname_args *uap)
|
274{
| 270{
|
275 INIT_VPROCG(TD_TO_VPROCG(td)); 276 char tmpdomainname[MAXHOSTNAMELEN]; 277 int error, domainnamelen;
| 271 int name[2]; 272 int error;
|
278
| 273
|
279 error = priv_check(td, PRIV_SETDOMAINNAME); 280 if (error) 281 return (error); 282 if ((u_int)uap->len > sizeof(tmpdomainname) - 1) 283 return (EINVAL); 284 domainnamelen = uap->len; 285 error = copyin(uap->domainname, tmpdomainname, uap->len); 286 if (error == 0) { 287 tmpdomainname[domainnamelen] = 0; 288 mtx_lock(&hostname_mtx); 289 bcopy(tmpdomainname, V_domainname, sizeof(V_domainname)); 290 mtx_unlock(&hostname_mtx); 291 }
| 274 name[0] = CTL_KERN; 275 name[1] = KERN_NISDOMAINNAME; 276 mtx_lock(&Giant); 277 error = userland_sysctl(td, name, 2, 0, 0, 0, uap->domainname, 278 uap->len, 0, 0); 279 mtx_unlock(&Giant);
|
292 return (error); 293}
| 280 return (error); 281}
|
| 282#endif /* COMPAT_FREEBSD4 */
|
| |