1df8bae1dSRodney W. Grimes /* 2df8bae1dSRodney W. Grimes * Copyright (c) 1982, 1986, 1989, 1993 3df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 4df8bae1dSRodney W. Grimes * 5df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 6df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 7df8bae1dSRodney W. Grimes * are met: 8df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 9df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 10df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 11df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 12df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 13df8bae1dSRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 14df8bae1dSRodney W. Grimes * must display the following acknowledgement: 15df8bae1dSRodney W. Grimes * This product includes software developed by the University of 16df8bae1dSRodney W. Grimes * California, Berkeley and its contributors. 17df8bae1dSRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 18df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 19df8bae1dSRodney W. Grimes * without specific prior written permission. 20df8bae1dSRodney W. Grimes * 21df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31df8bae1dSRodney W. Grimes * SUCH DAMAGE. 32df8bae1dSRodney W. Grimes * 33df8bae1dSRodney W. Grimes * @(#)kern_xxx.c 8.2 (Berkeley) 11/14/93 34df8bae1dSRodney W. Grimes */ 35df8bae1dSRodney W. Grimes 36677b542eSDavid E. O'Brien #include <sys/cdefs.h> 37677b542eSDavid E. O'Brien __FBSDID("$FreeBSD$"); 38677b542eSDavid E. O'Brien 395591b823SEivind Eklund #include "opt_compat.h" 405591b823SEivind Eklund 41df8bae1dSRodney W. Grimes #include <sys/param.h> 42df8bae1dSRodney W. Grimes #include <sys/systm.h> 43d2d3e875SBruce Evans #include <sys/sysproto.h> 44df8bae1dSRodney W. Grimes #include <sys/kernel.h> 45df8bae1dSRodney W. Grimes #include <sys/proc.h> 466f1e8c18SMatthew Dillon #include <sys/lock.h> 476f1e8c18SMatthew Dillon #include <sys/mutex.h> 48df8bae1dSRodney W. Grimes #include <sys/sysctl.h> 4926f9a767SRodney W. Grimes #include <sys/utsname.h> 5026f9a767SRodney W. Grimes 51df8bae1dSRodney W. Grimes 52df8bae1dSRodney W. Grimes #if defined(COMPAT_43) || defined(COMPAT_SUNOS) 53df8bae1dSRodney W. Grimes 54d2d3e875SBruce Evans #ifndef _SYS_SYSPROTO_H_ 55df8bae1dSRodney W. Grimes struct gethostname_args { 56df8bae1dSRodney W. Grimes char *hostname; 57df8bae1dSRodney W. Grimes u_int len; 58df8bae1dSRodney W. Grimes }; 59d2d3e875SBruce Evans #endif 606f1e8c18SMatthew Dillon /* 616f1e8c18SMatthew Dillon * MPSAFE 626f1e8c18SMatthew Dillon */ 63df8bae1dSRodney W. Grimes /* ARGSUSED */ 6426f9a767SRodney W. Grimes int 65b40ce416SJulian Elischer ogethostname(td, uap) 66b40ce416SJulian Elischer struct thread *td; 67df8bae1dSRodney W. Grimes struct gethostname_args *uap; 68df8bae1dSRodney W. Grimes { 69b8da2396SPoul-Henning Kamp int name[2]; 706f1e8c18SMatthew Dillon int error; 71069e9bc1SDoug Rabson size_t len = uap->len; 72df8bae1dSRodney W. Grimes 73b8da2396SPoul-Henning Kamp name[0] = CTL_KERN; 74b8da2396SPoul-Henning Kamp name[1] = KERN_HOSTNAME; 756f1e8c18SMatthew Dillon mtx_lock(&Giant); 76b40ce416SJulian Elischer error = userland_sysctl(td, name, 2, uap->hostname, &len, 1, 0, 0, 0); 776f1e8c18SMatthew Dillon mtx_unlock(&Giant); 786f1e8c18SMatthew Dillon return(error); 79df8bae1dSRodney W. Grimes } 80df8bae1dSRodney W. Grimes 81d2d3e875SBruce Evans #ifndef _SYS_SYSPROTO_H_ 82df8bae1dSRodney W. Grimes struct sethostname_args { 83df8bae1dSRodney W. Grimes char *hostname; 84df8bae1dSRodney W. Grimes u_int len; 85df8bae1dSRodney W. Grimes }; 86d2d3e875SBruce Evans #endif 876f1e8c18SMatthew Dillon /* 886f1e8c18SMatthew Dillon * MPSAFE 896f1e8c18SMatthew Dillon */ 90df8bae1dSRodney W. Grimes /* ARGSUSED */ 9126f9a767SRodney W. Grimes int 92b40ce416SJulian Elischer osethostname(td, uap) 93b40ce416SJulian Elischer struct thread *td; 94df8bae1dSRodney W. Grimes register struct sethostname_args *uap; 95df8bae1dSRodney W. Grimes { 96b8da2396SPoul-Henning Kamp int name[2]; 97df8bae1dSRodney W. Grimes int error; 98df8bae1dSRodney W. Grimes 99b8da2396SPoul-Henning Kamp name[0] = CTL_KERN; 100b8da2396SPoul-Henning Kamp name[1] = KERN_HOSTNAME; 1016f1e8c18SMatthew Dillon mtx_lock(&Giant); 10244731cabSJohn Baldwin if ((error = suser_cred(td->td_ucred, PRISON_ROOT)) == 0) { 103b40ce416SJulian Elischer error = userland_sysctl(td, name, 2, 0, 0, 0, 1046f1e8c18SMatthew Dillon uap->hostname, uap->len, 0); 1056f1e8c18SMatthew Dillon } 1066f1e8c18SMatthew Dillon mtx_unlock(&Giant); 107df8bae1dSRodney W. Grimes return (error); 108df8bae1dSRodney W. Grimes } 109df8bae1dSRodney W. Grimes 110d2d3e875SBruce Evans #ifndef _SYS_SYSPROTO_H_ 1112635f86cSBruce Evans struct ogethostid_args { 112df8bae1dSRodney W. Grimes int dummy; 113df8bae1dSRodney W. Grimes }; 114d2d3e875SBruce Evans #endif 1156f1e8c18SMatthew Dillon /* 1166f1e8c18SMatthew Dillon * MPSAFE 1176f1e8c18SMatthew Dillon */ 118df8bae1dSRodney W. Grimes /* ARGSUSED */ 11926f9a767SRodney W. Grimes int 120b40ce416SJulian Elischer ogethostid(td, uap) 121b40ce416SJulian Elischer struct thread *td; 1222635f86cSBruce Evans struct ogethostid_args *uap; 123df8bae1dSRodney W. Grimes { 124df8bae1dSRodney W. Grimes 125b40ce416SJulian Elischer *(long *)(td->td_retval) = hostid; 126df8bae1dSRodney W. Grimes return (0); 127df8bae1dSRodney W. Grimes } 128df8bae1dSRodney W. Grimes #endif /* COMPAT_43 || COMPAT_SUNOS */ 129df8bae1dSRodney W. Grimes 130df8bae1dSRodney W. Grimes #ifdef COMPAT_43 131d2d3e875SBruce Evans #ifndef _SYS_SYSPROTO_H_ 1322635f86cSBruce Evans struct osethostid_args { 133df8bae1dSRodney W. Grimes long hostid; 134df8bae1dSRodney W. Grimes }; 135d2d3e875SBruce Evans #endif 1366f1e8c18SMatthew Dillon /* 1376f1e8c18SMatthew Dillon * MPSAFE 1386f1e8c18SMatthew Dillon */ 139df8bae1dSRodney W. Grimes /* ARGSUSED */ 14026f9a767SRodney W. Grimes int 141b40ce416SJulian Elischer osethostid(td, uap) 142b40ce416SJulian Elischer struct thread *td; 1432635f86cSBruce Evans struct osethostid_args *uap; 144df8bae1dSRodney W. Grimes { 145df8bae1dSRodney W. Grimes int error; 146df8bae1dSRodney W. Grimes 1476f1e8c18SMatthew Dillon mtx_lock(&Giant); 14844731cabSJohn Baldwin if ((error = suser(td))) 149df8bae1dSRodney W. Grimes hostid = uap->hostid; 1506f1e8c18SMatthew Dillon mtx_unlock(&Giant); 1516f1e8c18SMatthew Dillon return (error); 152df8bae1dSRodney W. Grimes } 153df8bae1dSRodney W. Grimes 1546f1e8c18SMatthew Dillon /* 1556f1e8c18SMatthew Dillon * MPSAFE 1566f1e8c18SMatthew Dillon */ 15726f9a767SRodney W. Grimes int 158b40ce416SJulian Elischer oquota(td, uap) 159b40ce416SJulian Elischer struct thread *td; 1602635f86cSBruce Evans struct oquota_args *uap; 161df8bae1dSRodney W. Grimes { 162df8bae1dSRodney W. Grimes return (ENOSYS); 163df8bae1dSRodney W. Grimes } 164df8bae1dSRodney W. Grimes #endif /* COMPAT_43 */ 16526f9a767SRodney W. Grimes 16632e47970SPeter Wemm /* 16732e47970SPeter Wemm * This is the FreeBSD-1.1 compatable uname(2) interface. These 16832e47970SPeter Wemm * days it is done in libc as a wrapper around a bunch of sysctl's. 16932e47970SPeter Wemm * This must maintain the old 1.1 binary ABI. 17032e47970SPeter Wemm */ 17132e47970SPeter Wemm #if SYS_NMLN != 32 17232e47970SPeter Wemm #error "FreeBSD-1.1 uname syscall has been broken" 17332e47970SPeter Wemm #endif 174d2d3e875SBruce Evans #ifndef _SYS_SYSPROTO_H_ 17526f9a767SRodney W. Grimes struct uname_args { 17626f9a767SRodney W. Grimes struct utsname *name; 17726f9a767SRodney W. Grimes }; 178d2d3e875SBruce Evans #endif 17926f9a767SRodney W. Grimes 1806f1e8c18SMatthew Dillon /* 1816f1e8c18SMatthew Dillon * MPSAFE 1826f1e8c18SMatthew Dillon */ 18326f9a767SRodney W. Grimes /* ARGSUSED */ 18426f9a767SRodney W. Grimes int 185b40ce416SJulian Elischer uname(td, uap) 186b40ce416SJulian Elischer struct thread *td; 18726f9a767SRodney W. Grimes struct uname_args *uap; 18826f9a767SRodney W. Grimes { 1896f1e8c18SMatthew Dillon int name[2], error; 190069e9bc1SDoug Rabson size_t len; 19126f9a767SRodney W. Grimes char *s, *us; 19226f9a767SRodney W. Grimes 193b8da2396SPoul-Henning Kamp name[0] = CTL_KERN; 194b8da2396SPoul-Henning Kamp name[1] = KERN_OSTYPE; 1956f1e8c18SMatthew Dillon len = sizeof (uap->name->sysname); 1966f1e8c18SMatthew Dillon mtx_lock(&Giant); 197b40ce416SJulian Elischer error = userland_sysctl(td, name, 2, uap->name->sysname, &len, 198b8da2396SPoul-Henning Kamp 1, 0, 0, 0); 1996f1e8c18SMatthew Dillon if (error) 2006f1e8c18SMatthew Dillon goto done2; 20126f9a767SRodney W. Grimes subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0); 20226f9a767SRodney W. Grimes 203b8da2396SPoul-Henning Kamp name[1] = KERN_HOSTNAME; 20426f9a767SRodney W. Grimes len = sizeof uap->name->nodename; 205b40ce416SJulian Elischer error = userland_sysctl(td, name, 2, uap->name->nodename, &len, 206b8da2396SPoul-Henning Kamp 1, 0, 0, 0); 2076f1e8c18SMatthew Dillon if (error) 2086f1e8c18SMatthew Dillon goto done2; 20926f9a767SRodney W. Grimes subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0); 21026f9a767SRodney W. Grimes 211b8da2396SPoul-Henning Kamp name[1] = KERN_OSRELEASE; 21226f9a767SRodney W. Grimes len = sizeof uap->name->release; 213b40ce416SJulian Elischer error = userland_sysctl(td, name, 2, uap->name->release, &len, 214b8da2396SPoul-Henning Kamp 1, 0, 0, 0); 2156f1e8c18SMatthew Dillon if (error) 2166f1e8c18SMatthew Dillon goto done2; 21726f9a767SRodney W. Grimes subyte( uap->name->release + sizeof(uap->name->release) - 1, 0); 21826f9a767SRodney W. Grimes 21926f9a767SRodney W. Grimes /* 22026f9a767SRodney W. Grimes name = KERN_VERSION; 22126f9a767SRodney W. Grimes len = sizeof uap->name->version; 222b40ce416SJulian Elischer error = userland_sysctl(td, name, 2, uap->name->version, &len, 223b8da2396SPoul-Henning Kamp 1, 0, 0, 0); 2246f1e8c18SMatthew Dillon if (error) 2256f1e8c18SMatthew Dillon goto done2; 22626f9a767SRodney W. Grimes subyte( uap->name->version + sizeof(uap->name->version) - 1, 0); 22726f9a767SRodney W. Grimes */ 22826f9a767SRodney W. Grimes 22926f9a767SRodney W. Grimes /* 23026f9a767SRodney W. Grimes * this stupid hackery to make the version field look like FreeBSD 1.1 23126f9a767SRodney W. Grimes */ 23226f9a767SRodney W. Grimes for(s = version; *s && *s != '#'; s++); 23326f9a767SRodney W. Grimes 23426f9a767SRodney W. Grimes for(us = uap->name->version; *s && *s != ':'; s++) { 2356f1e8c18SMatthew Dillon error = subyte( us++, *s); 2366f1e8c18SMatthew Dillon if (error) 2376f1e8c18SMatthew Dillon goto done2; 23826f9a767SRodney W. Grimes } 2396f1e8c18SMatthew Dillon error = subyte( us++, 0); 2406f1e8c18SMatthew Dillon if (error) 2416f1e8c18SMatthew Dillon goto done2; 24226f9a767SRodney W. Grimes 243069e9bc1SDoug Rabson name[0] = CTL_HW; 244b8da2396SPoul-Henning Kamp name[1] = HW_MACHINE; 24526f9a767SRodney W. Grimes len = sizeof uap->name->machine; 246b40ce416SJulian Elischer error = userland_sysctl(td, name, 2, uap->name->machine, &len, 247b8da2396SPoul-Henning Kamp 1, 0, 0, 0); 2486f1e8c18SMatthew Dillon if (error) 2496f1e8c18SMatthew Dillon goto done2; 25026f9a767SRodney W. Grimes subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0); 2516f1e8c18SMatthew Dillon done2: 2526f1e8c18SMatthew Dillon mtx_unlock(&Giant); 2536f1e8c18SMatthew Dillon return (error); 25426f9a767SRodney W. Grimes } 25526f9a767SRodney W. Grimes 256d2d3e875SBruce Evans #ifndef _SYS_SYSPROTO_H_ 25726f9a767SRodney W. Grimes struct getdomainname_args { 25826f9a767SRodney W. Grimes char *domainname; 259f35a53bfSBruce Evans int len; 26026f9a767SRodney W. Grimes }; 261d2d3e875SBruce Evans #endif 262f35a53bfSBruce Evans 2636f1e8c18SMatthew Dillon /* 2646f1e8c18SMatthew Dillon * MPSAFE 2656f1e8c18SMatthew Dillon */ 26626f9a767SRodney W. Grimes /* ARGSUSED */ 26726f9a767SRodney W. Grimes int 268b40ce416SJulian Elischer getdomainname(td, uap) 269b40ce416SJulian Elischer struct thread *td; 27026f9a767SRodney W. Grimes struct getdomainname_args *uap; 27126f9a767SRodney W. Grimes { 2726f1e8c18SMatthew Dillon int domainnamelen; 2736f1e8c18SMatthew Dillon int error; 2746f1e8c18SMatthew Dillon 2756f1e8c18SMatthew Dillon mtx_lock(&Giant); 2766f1e8c18SMatthew Dillon domainnamelen = strlen(domainname) + 1; 277f35a53bfSBruce Evans if ((u_int)uap->len > domainnamelen + 1) 27826f9a767SRodney W. Grimes uap->len = domainnamelen + 1; 27901609114SAlfred Perlstein error = copyout(domainname, uap->domainname, uap->len); 2806f1e8c18SMatthew Dillon mtx_unlock(&Giant); 2816f1e8c18SMatthew Dillon return (error); 28226f9a767SRodney W. Grimes } 28326f9a767SRodney W. Grimes 284d2d3e875SBruce Evans #ifndef _SYS_SYSPROTO_H_ 28526f9a767SRodney W. Grimes struct setdomainname_args { 28626f9a767SRodney W. Grimes char *domainname; 287f35a53bfSBruce Evans int len; 28826f9a767SRodney W. Grimes }; 289d2d3e875SBruce Evans #endif 29026f9a767SRodney W. Grimes 2916f1e8c18SMatthew Dillon /* 2926f1e8c18SMatthew Dillon * MPSAFE 2936f1e8c18SMatthew Dillon */ 29426f9a767SRodney W. Grimes /* ARGSUSED */ 29526f9a767SRodney W. Grimes int 296b40ce416SJulian Elischer setdomainname(td, uap) 297b40ce416SJulian Elischer struct thread *td; 29826f9a767SRodney W. Grimes struct setdomainname_args *uap; 29926f9a767SRodney W. Grimes { 30027aef046SPoul-Henning Kamp int error, domainnamelen; 30126f9a767SRodney W. Grimes 3026f1e8c18SMatthew Dillon mtx_lock(&Giant); 30344731cabSJohn Baldwin if ((error = suser(td))) 3046f1e8c18SMatthew Dillon goto done2; 3056f1e8c18SMatthew Dillon if ((u_int)uap->len > sizeof (domainname) - 1) { 3066f1e8c18SMatthew Dillon error = EINVAL; 3076f1e8c18SMatthew Dillon goto done2; 3086f1e8c18SMatthew Dillon } 30926f9a767SRodney W. Grimes domainnamelen = uap->len; 31001609114SAlfred Perlstein error = copyin(uap->domainname, domainname, uap->len); 31126f9a767SRodney W. Grimes domainname[domainnamelen] = 0; 3126f1e8c18SMatthew Dillon done2: 3136f1e8c18SMatthew Dillon mtx_unlock(&Giant); 31426f9a767SRodney W. Grimes return (error); 31526f9a767SRodney W. Grimes } 31626f9a767SRodney W. Grimes 317