19454b2d8SWarner Losh /*- 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 * 4. Neither the name of the University nor the names of its contributors 14df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 15df8bae1dSRodney W. Grimes * without specific prior written permission. 16df8bae1dSRodney W. Grimes * 17df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27df8bae1dSRodney W. Grimes * SUCH DAMAGE. 28df8bae1dSRodney W. Grimes * 29df8bae1dSRodney W. Grimes * @(#)kern_xxx.c 8.2 (Berkeley) 11/14/93 30df8bae1dSRodney W. Grimes */ 31df8bae1dSRodney W. Grimes 32677b542eSDavid E. O'Brien #include <sys/cdefs.h> 33677b542eSDavid E. O'Brien __FBSDID("$FreeBSD$"); 34677b542eSDavid E. O'Brien 355591b823SEivind Eklund #include "opt_compat.h" 365591b823SEivind Eklund 37df8bae1dSRodney W. Grimes #include <sys/param.h> 38df8bae1dSRodney W. Grimes #include <sys/systm.h> 39d2d3e875SBruce Evans #include <sys/sysproto.h> 40df8bae1dSRodney W. Grimes #include <sys/kernel.h> 41acd3428bSRobert Watson #include <sys/priv.h> 42df8bae1dSRodney W. Grimes #include <sys/proc.h> 436f1e8c18SMatthew Dillon #include <sys/lock.h> 446f1e8c18SMatthew Dillon #include <sys/mutex.h> 45df8bae1dSRodney W. Grimes #include <sys/sysctl.h> 4626f9a767SRodney W. Grimes #include <sys/utsname.h> 47603724d3SBjoern A. Zeeb #include <sys/vimage.h> 4826f9a767SRodney W. Grimes 49df8bae1dSRodney W. Grimes 501930e303SPoul-Henning Kamp #if defined(COMPAT_43) 51df8bae1dSRodney W. Grimes 52d2d3e875SBruce Evans #ifndef _SYS_SYSPROTO_H_ 53df8bae1dSRodney W. Grimes struct gethostname_args { 54df8bae1dSRodney W. Grimes char *hostname; 55df8bae1dSRodney W. Grimes u_int len; 56df8bae1dSRodney W. Grimes }; 57d2d3e875SBruce Evans #endif 58df8bae1dSRodney W. Grimes /* ARGSUSED */ 5926f9a767SRodney W. Grimes int 60b40ce416SJulian Elischer ogethostname(td, uap) 61b40ce416SJulian Elischer struct thread *td; 62df8bae1dSRodney W. Grimes struct gethostname_args *uap; 63df8bae1dSRodney W. Grimes { 64b8da2396SPoul-Henning Kamp int name[2]; 65069e9bc1SDoug Rabson size_t len = uap->len; 66df8bae1dSRodney W. Grimes 67b8da2396SPoul-Henning Kamp name[0] = CTL_KERN; 68b8da2396SPoul-Henning Kamp name[1] = KERN_HOSTNAME; 69ddf9d243SEd Schouten return (userland_sysctl(td, name, 2, uap->hostname, &len, 70ddf9d243SEd Schouten 1, 0, 0, 0, 0)); 71df8bae1dSRodney W. Grimes } 72df8bae1dSRodney W. Grimes 73d2d3e875SBruce Evans #ifndef _SYS_SYSPROTO_H_ 74df8bae1dSRodney W. Grimes struct sethostname_args { 75df8bae1dSRodney W. Grimes char *hostname; 76df8bae1dSRodney W. Grimes u_int len; 77df8bae1dSRodney W. Grimes }; 78d2d3e875SBruce Evans #endif 79df8bae1dSRodney W. Grimes /* ARGSUSED */ 8026f9a767SRodney W. Grimes int 81b40ce416SJulian Elischer osethostname(td, uap) 82b40ce416SJulian Elischer struct thread *td; 83df8bae1dSRodney W. Grimes register struct sethostname_args *uap; 84df8bae1dSRodney W. Grimes { 85b8da2396SPoul-Henning Kamp int name[2]; 86df8bae1dSRodney W. Grimes int error; 87df8bae1dSRodney W. Grimes 88b8da2396SPoul-Henning Kamp name[0] = CTL_KERN; 89b8da2396SPoul-Henning Kamp name[1] = KERN_HOSTNAME; 90ddf9d243SEd Schouten return (userland_sysctl(td, name, 2, 0, 0, 0, uap->hostname, 91ddf9d243SEd Schouten uap->len, 0, 0)); 92df8bae1dSRodney W. Grimes } 93df8bae1dSRodney W. Grimes 94d2d3e875SBruce Evans #ifndef _SYS_SYSPROTO_H_ 952635f86cSBruce Evans struct ogethostid_args { 96df8bae1dSRodney W. Grimes int dummy; 97df8bae1dSRodney W. Grimes }; 98d2d3e875SBruce Evans #endif 99df8bae1dSRodney W. Grimes /* ARGSUSED */ 10026f9a767SRodney W. Grimes int 101b40ce416SJulian Elischer ogethostid(td, uap) 102b40ce416SJulian Elischer struct thread *td; 1032635f86cSBruce Evans struct ogethostid_args *uap; 104df8bae1dSRodney W. Grimes { 105df8bae1dSRodney W. Grimes 106b40ce416SJulian Elischer *(long *)(td->td_retval) = hostid; 107df8bae1dSRodney W. Grimes return (0); 108df8bae1dSRodney W. Grimes } 1091930e303SPoul-Henning Kamp #endif /* COMPAT_43 */ 110df8bae1dSRodney W. Grimes 111df8bae1dSRodney W. Grimes #ifdef COMPAT_43 112d2d3e875SBruce Evans #ifndef _SYS_SYSPROTO_H_ 1132635f86cSBruce Evans struct osethostid_args { 114df8bae1dSRodney W. Grimes long hostid; 115df8bae1dSRodney W. Grimes }; 116d2d3e875SBruce Evans #endif 117df8bae1dSRodney W. Grimes /* ARGSUSED */ 11826f9a767SRodney W. Grimes int 119b40ce416SJulian Elischer osethostid(td, uap) 120b40ce416SJulian Elischer struct thread *td; 1212635f86cSBruce Evans struct osethostid_args *uap; 122df8bae1dSRodney W. Grimes { 123df8bae1dSRodney W. Grimes int error; 124df8bae1dSRodney W. Grimes 125acd3428bSRobert Watson error = priv_check(td, PRIV_SETHOSTID); 126acd3428bSRobert Watson if (error) 127c89d555cSTim J. Robbins return (error); 128c89d555cSTim J. Robbins mtx_lock(&Giant); 129df8bae1dSRodney W. Grimes hostid = uap->hostid; 1306f1e8c18SMatthew Dillon mtx_unlock(&Giant); 131c89d555cSTim J. Robbins return (0); 132df8bae1dSRodney W. Grimes } 133df8bae1dSRodney W. Grimes 13426f9a767SRodney W. Grimes int 135b40ce416SJulian Elischer oquota(td, uap) 136b40ce416SJulian Elischer struct thread *td; 1372635f86cSBruce Evans struct oquota_args *uap; 138df8bae1dSRodney W. Grimes { 139873fbcd7SRobert Watson 140df8bae1dSRodney W. Grimes return (ENOSYS); 141df8bae1dSRodney W. Grimes } 142df8bae1dSRodney W. Grimes #endif /* COMPAT_43 */ 14326f9a767SRodney W. Grimes 144a1b5a895SEd Schouten #ifdef COMPAT_FREEBSD4 14532e47970SPeter Wemm /* 146a1b5a895SEd Schouten * This is the FreeBSD-1.1 compatible uname(2) interface. These days it is 147873fbcd7SRobert Watson * done in libc as a wrapper around a bunch of sysctl's. This must maintain 148873fbcd7SRobert Watson * the old 1.1 binary ABI. 14932e47970SPeter Wemm */ 15032e47970SPeter Wemm #if SYS_NMLN != 32 15132e47970SPeter Wemm #error "FreeBSD-1.1 uname syscall has been broken" 15232e47970SPeter Wemm #endif 153d2d3e875SBruce Evans #ifndef _SYS_SYSPROTO_H_ 15426f9a767SRodney W. Grimes struct uname_args { 15526f9a767SRodney W. Grimes struct utsname *name; 15626f9a767SRodney W. Grimes }; 157d2d3e875SBruce Evans #endif 15826f9a767SRodney W. Grimes /* ARGSUSED */ 15926f9a767SRodney W. Grimes int 160a1b5a895SEd Schouten freebsd4_uname(struct thread *td, struct freebsd4_uname_args *uap) 16126f9a767SRodney W. Grimes { 1626f1e8c18SMatthew Dillon int name[2], error; 163069e9bc1SDoug Rabson size_t len; 16426f9a767SRodney W. Grimes char *s, *us; 16526f9a767SRodney W. Grimes 166b8da2396SPoul-Henning Kamp name[0] = CTL_KERN; 167b8da2396SPoul-Henning Kamp name[1] = KERN_OSTYPE; 1686f1e8c18SMatthew Dillon len = sizeof (uap->name->sysname); 169b40ce416SJulian Elischer error = userland_sysctl(td, name, 2, uap->name->sysname, &len, 170a7bc3102SPeter Wemm 1, 0, 0, 0, 0); 1716f1e8c18SMatthew Dillon if (error) 172ddf9d243SEd Schouten return (error); 17326f9a767SRodney W. Grimes subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0); 17426f9a767SRodney W. Grimes 175b8da2396SPoul-Henning Kamp name[1] = KERN_HOSTNAME; 17626f9a767SRodney W. Grimes len = sizeof uap->name->nodename; 177b40ce416SJulian Elischer error = userland_sysctl(td, name, 2, uap->name->nodename, &len, 178a7bc3102SPeter Wemm 1, 0, 0, 0, 0); 1796f1e8c18SMatthew Dillon if (error) 180ddf9d243SEd Schouten return (error); 18126f9a767SRodney W. Grimes subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0); 18226f9a767SRodney W. Grimes 183b8da2396SPoul-Henning Kamp name[1] = KERN_OSRELEASE; 18426f9a767SRodney W. Grimes len = sizeof uap->name->release; 185b40ce416SJulian Elischer error = userland_sysctl(td, name, 2, uap->name->release, &len, 186a7bc3102SPeter Wemm 1, 0, 0, 0, 0); 1876f1e8c18SMatthew Dillon if (error) 188ddf9d243SEd Schouten return (error); 18926f9a767SRodney W. Grimes subyte( uap->name->release + sizeof(uap->name->release) - 1, 0); 19026f9a767SRodney W. Grimes 19126f9a767SRodney W. Grimes /* 19226f9a767SRodney W. Grimes name = KERN_VERSION; 19326f9a767SRodney W. Grimes len = sizeof uap->name->version; 194b40ce416SJulian Elischer error = userland_sysctl(td, name, 2, uap->name->version, &len, 195a7bc3102SPeter Wemm 1, 0, 0, 0, 0); 1966f1e8c18SMatthew Dillon if (error) 197ddf9d243SEd Schouten return (error); 19826f9a767SRodney W. Grimes subyte( uap->name->version + sizeof(uap->name->version) - 1, 0); 19926f9a767SRodney W. Grimes */ 20026f9a767SRodney W. Grimes 20126f9a767SRodney W. Grimes /* 20226f9a767SRodney W. Grimes * this stupid hackery to make the version field look like FreeBSD 1.1 20326f9a767SRodney W. Grimes */ 20426f9a767SRodney W. Grimes for(s = version; *s && *s != '#'; s++); 20526f9a767SRodney W. Grimes 20626f9a767SRodney W. Grimes for(us = uap->name->version; *s && *s != ':'; s++) { 2076f1e8c18SMatthew Dillon error = subyte( us++, *s); 2086f1e8c18SMatthew Dillon if (error) 209ddf9d243SEd Schouten return (error); 21026f9a767SRodney W. Grimes } 2116f1e8c18SMatthew Dillon error = subyte( us++, 0); 2126f1e8c18SMatthew Dillon if (error) 213ddf9d243SEd Schouten return (error); 21426f9a767SRodney W. Grimes 215069e9bc1SDoug Rabson name[0] = CTL_HW; 216b8da2396SPoul-Henning Kamp name[1] = HW_MACHINE; 21726f9a767SRodney W. Grimes len = sizeof uap->name->machine; 218b40ce416SJulian Elischer error = userland_sysctl(td, name, 2, uap->name->machine, &len, 219a7bc3102SPeter Wemm 1, 0, 0, 0, 0); 2206f1e8c18SMatthew Dillon if (error) 2216f1e8c18SMatthew Dillon return (error); 222ddf9d243SEd Schouten subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0); 223ddf9d243SEd Schouten return (0); 22426f9a767SRodney W. Grimes } 22526f9a767SRodney W. Grimes 226d2d3e875SBruce Evans #ifndef _SYS_SYSPROTO_H_ 22726f9a767SRodney W. Grimes struct getdomainname_args { 22826f9a767SRodney W. Grimes char *domainname; 229f35a53bfSBruce Evans int len; 23026f9a767SRodney W. Grimes }; 231d2d3e875SBruce Evans #endif 23226f9a767SRodney W. Grimes /* ARGSUSED */ 23326f9a767SRodney W. Grimes int 234a1b5a895SEd Schouten freebsd4_getdomainname(struct thread *td, 235a1b5a895SEd Schouten struct freebsd4_getdomainname_args *uap) 23626f9a767SRodney W. Grimes { 237a1b5a895SEd Schouten int name[2]; 238a1b5a895SEd Schouten size_t len = uap->len; 2396f1e8c18SMatthew Dillon 240a1b5a895SEd Schouten name[0] = CTL_KERN; 241a1b5a895SEd Schouten name[1] = KERN_NISDOMAINNAME; 242ddf9d243SEd Schouten return (userland_sysctl(td, name, 2, uap->domainname, &len, 243ddf9d243SEd Schouten 1, 0, 0, 0, 0)); 24426f9a767SRodney W. Grimes } 24526f9a767SRodney W. Grimes 246d2d3e875SBruce Evans #ifndef _SYS_SYSPROTO_H_ 24726f9a767SRodney W. Grimes struct setdomainname_args { 24826f9a767SRodney W. Grimes char *domainname; 249f35a53bfSBruce Evans int len; 25026f9a767SRodney W. Grimes }; 251d2d3e875SBruce Evans #endif 25226f9a767SRodney W. Grimes /* ARGSUSED */ 25326f9a767SRodney W. Grimes int 254a1b5a895SEd Schouten freebsd4_setdomainname(struct thread *td, 255a1b5a895SEd Schouten struct freebsd4_setdomainname_args *uap) 25626f9a767SRodney W. Grimes { 257a1b5a895SEd Schouten int name[2]; 25826f9a767SRodney W. Grimes 259a1b5a895SEd Schouten name[0] = CTL_KERN; 260a1b5a895SEd Schouten name[1] = KERN_NISDOMAINNAME; 261ddf9d243SEd Schouten return (userland_sysctl(td, name, 2, 0, 0, 0, uap->domainname, 262ddf9d243SEd Schouten uap->len, 0, 0)); 26326f9a767SRodney W. Grimes } 264a1b5a895SEd Schouten #endif /* COMPAT_FREEBSD4 */ 265