kern_xxx.c revision 130344
11541Srgrimes/* 21541Srgrimes * Copyright (c) 1982, 1986, 1989, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 4. Neither the name of the University nor the names of its contributors 141541Srgrimes * may be used to endorse or promote products derived from this software 151541Srgrimes * without specific prior written permission. 161541Srgrimes * 171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271541Srgrimes * SUCH DAMAGE. 281541Srgrimes * 291541Srgrimes * @(#)kern_xxx.c 8.2 (Berkeley) 11/14/93 301541Srgrimes */ 311541Srgrimes 32116182Sobrien#include <sys/cdefs.h> 33116182Sobrien__FBSDID("$FreeBSD: head/sys/kern/kern_xxx.c 130344 2004-06-11 11:16:26Z phk $"); 34116182Sobrien 3531778Seivind#include "opt_compat.h" 3631778Seivind 371541Srgrimes#include <sys/param.h> 381541Srgrimes#include <sys/systm.h> 3912221Sbde#include <sys/sysproto.h> 401541Srgrimes#include <sys/kernel.h> 411541Srgrimes#include <sys/proc.h> 4282717Sdillon#include <sys/lock.h> 4382717Sdillon#include <sys/mutex.h> 441541Srgrimes#include <sys/sysctl.h> 451549Srgrimes#include <sys/utsname.h> 461541Srgrimes 478876Srgrimes 48130344Sphk#if defined(COMPAT_43) 491541Srgrimes 5012221Sbde#ifndef _SYS_SYSPROTO_H_ 511541Srgrimesstruct gethostname_args { 521541Srgrimes char *hostname; 531541Srgrimes u_int len; 541541Srgrimes}; 5512221Sbde#endif 5682717Sdillon/* 5782717Sdillon * MPSAFE 5882717Sdillon */ 591541Srgrimes/* ARGSUSED */ 601549Srgrimesint 6183366Sjulianogethostname(td, uap) 6283366Sjulian struct thread *td; 631541Srgrimes struct gethostname_args *uap; 641541Srgrimes{ 6512171Sphk int name[2]; 6682717Sdillon int error; 6738517Sdfr size_t len = uap->len; 681541Srgrimes 6912171Sphk name[0] = CTL_KERN; 7012171Sphk name[1] = KERN_HOSTNAME; 7182717Sdillon mtx_lock(&Giant); 7283366Sjulian error = userland_sysctl(td, name, 2, uap->hostname, &len, 1, 0, 0, 0); 7382717Sdillon mtx_unlock(&Giant); 7482717Sdillon return(error); 751541Srgrimes} 761541Srgrimes 7712221Sbde#ifndef _SYS_SYSPROTO_H_ 781541Srgrimesstruct sethostname_args { 791541Srgrimes char *hostname; 801541Srgrimes u_int len; 811541Srgrimes}; 8212221Sbde#endif 8382717Sdillon/* 8482717Sdillon * MPSAFE 8582717Sdillon */ 861541Srgrimes/* ARGSUSED */ 871549Srgrimesint 8883366Sjulianosethostname(td, uap) 8983366Sjulian struct thread *td; 901541Srgrimes register struct sethostname_args *uap; 911541Srgrimes{ 9212171Sphk int name[2]; 931541Srgrimes int error; 941541Srgrimes 9512171Sphk name[0] = CTL_KERN; 9612171Sphk name[1] = KERN_HOSTNAME; 9782717Sdillon mtx_lock(&Giant); 9893593Sjhb if ((error = suser_cred(td->td_ucred, PRISON_ROOT)) == 0) { 9983366Sjulian error = userland_sysctl(td, name, 2, 0, 0, 0, 10082717Sdillon uap->hostname, uap->len, 0); 10182717Sdillon } 10282717Sdillon mtx_unlock(&Giant); 10382717Sdillon return (error); 1041541Srgrimes} 1051541Srgrimes 10612221Sbde#ifndef _SYS_SYSPROTO_H_ 10712200Sbdestruct ogethostid_args { 1081541Srgrimes int dummy; 1091541Srgrimes}; 11012221Sbde#endif 11182717Sdillon/* 11282717Sdillon * MPSAFE 11382717Sdillon */ 1141541Srgrimes/* ARGSUSED */ 1151549Srgrimesint 11683366Sjulianogethostid(td, uap) 11783366Sjulian struct thread *td; 11812200Sbde struct ogethostid_args *uap; 1191541Srgrimes{ 1201541Srgrimes 12183366Sjulian *(long *)(td->td_retval) = hostid; 1221541Srgrimes return (0); 1231541Srgrimes} 124130344Sphk#endif /* COMPAT_43 */ 1251541Srgrimes 1261541Srgrimes#ifdef COMPAT_43 12712221Sbde#ifndef _SYS_SYSPROTO_H_ 12812200Sbdestruct osethostid_args { 1291541Srgrimes long hostid; 1301541Srgrimes}; 13112221Sbde#endif 13282717Sdillon/* 13382717Sdillon * MPSAFE 13482717Sdillon */ 1351541Srgrimes/* ARGSUSED */ 1361549Srgrimesint 13783366Sjulianosethostid(td, uap) 13883366Sjulian struct thread *td; 13912200Sbde struct osethostid_args *uap; 1401541Srgrimes{ 1411541Srgrimes int error; 1421541Srgrimes 143119364Stjr if ((error = suser(td))) 144119364Stjr return (error); 14582717Sdillon mtx_lock(&Giant); 146119364Stjr hostid = uap->hostid; 14782717Sdillon mtx_unlock(&Giant); 148119364Stjr return (0); 1491541Srgrimes} 1501541Srgrimes 15182717Sdillon/* 15282717Sdillon * MPSAFE 15382717Sdillon */ 1541549Srgrimesint 15583366Sjulianoquota(td, uap) 15683366Sjulian struct thread *td; 15712200Sbde struct oquota_args *uap; 1581541Srgrimes{ 1591541Srgrimes return (ENOSYS); 1601541Srgrimes} 1611541Srgrimes#endif /* COMPAT_43 */ 1621549Srgrimes 16374729Speter/* 16474729Speter * This is the FreeBSD-1.1 compatable uname(2) interface. These 16574729Speter * days it is done in libc as a wrapper around a bunch of sysctl's. 16674729Speter * This must maintain the old 1.1 binary ABI. 16774729Speter */ 16874729Speter#if SYS_NMLN != 32 16974729Speter#error "FreeBSD-1.1 uname syscall has been broken" 17074729Speter#endif 17112221Sbde#ifndef _SYS_SYSPROTO_H_ 1721549Srgrimesstruct uname_args { 1731549Srgrimes struct utsname *name; 1741549Srgrimes}; 17512221Sbde#endif 1761549Srgrimes 17782717Sdillon/* 17882717Sdillon * MPSAFE 17982717Sdillon */ 1801549Srgrimes/* ARGSUSED */ 1811549Srgrimesint 18283366Sjulianuname(td, uap) 18383366Sjulian struct thread *td; 1841549Srgrimes struct uname_args *uap; 1851549Srgrimes{ 18682717Sdillon int name[2], error; 18738517Sdfr size_t len; 1881549Srgrimes char *s, *us; 1891549Srgrimes 19012171Sphk name[0] = CTL_KERN; 19112171Sphk name[1] = KERN_OSTYPE; 19282717Sdillon len = sizeof (uap->name->sysname); 19382717Sdillon mtx_lock(&Giant); 19483366Sjulian error = userland_sysctl(td, name, 2, uap->name->sysname, &len, 19512171Sphk 1, 0, 0, 0); 19682717Sdillon if (error) 19782717Sdillon goto done2; 1981549Srgrimes subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0); 1991549Srgrimes 20012171Sphk name[1] = KERN_HOSTNAME; 2011549Srgrimes len = sizeof uap->name->nodename; 20283366Sjulian error = userland_sysctl(td, name, 2, uap->name->nodename, &len, 20312171Sphk 1, 0, 0, 0); 20482717Sdillon if (error) 20582717Sdillon goto done2; 2061549Srgrimes subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0); 2071549Srgrimes 20812171Sphk name[1] = KERN_OSRELEASE; 2091549Srgrimes len = sizeof uap->name->release; 21083366Sjulian error = userland_sysctl(td, name, 2, uap->name->release, &len, 21112171Sphk 1, 0, 0, 0); 21282717Sdillon if (error) 21382717Sdillon goto done2; 2141549Srgrimes subyte( uap->name->release + sizeof(uap->name->release) - 1, 0); 2151549Srgrimes 2161549Srgrimes/* 2171549Srgrimes name = KERN_VERSION; 2181549Srgrimes len = sizeof uap->name->version; 21983366Sjulian error = userland_sysctl(td, name, 2, uap->name->version, &len, 22012171Sphk 1, 0, 0, 0); 22182717Sdillon if (error) 22282717Sdillon goto done2; 2231549Srgrimes subyte( uap->name->version + sizeof(uap->name->version) - 1, 0); 2241549Srgrimes*/ 2251549Srgrimes 2261549Srgrimes/* 2271549Srgrimes * this stupid hackery to make the version field look like FreeBSD 1.1 2281549Srgrimes */ 2291549Srgrimes for(s = version; *s && *s != '#'; s++); 2301549Srgrimes 2311549Srgrimes for(us = uap->name->version; *s && *s != ':'; s++) { 23282717Sdillon error = subyte( us++, *s); 23382717Sdillon if (error) 23482717Sdillon goto done2; 2351549Srgrimes } 23682717Sdillon error = subyte( us++, 0); 23782717Sdillon if (error) 23882717Sdillon goto done2; 2391549Srgrimes 24038517Sdfr name[0] = CTL_HW; 24112171Sphk name[1] = HW_MACHINE; 2421549Srgrimes len = sizeof uap->name->machine; 24383366Sjulian error = userland_sysctl(td, name, 2, uap->name->machine, &len, 24412171Sphk 1, 0, 0, 0); 24582717Sdillon if (error) 24682717Sdillon goto done2; 2471549Srgrimes subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0); 24882717Sdillondone2: 24982717Sdillon mtx_unlock(&Giant); 25082717Sdillon return (error); 2511549Srgrimes} 2521549Srgrimes 25312221Sbde#ifndef _SYS_SYSPROTO_H_ 2541549Srgrimesstruct getdomainname_args { 2551549Srgrimes char *domainname; 25612222Sbde int len; 2571549Srgrimes}; 25812222Sbde#endif 2591549Srgrimes 26082717Sdillon/* 26182717Sdillon * MPSAFE 26282717Sdillon */ 2631549Srgrimes/* ARGSUSED */ 2641549Srgrimesint 26583366Sjuliangetdomainname(td, uap) 26683366Sjulian struct thread *td; 2671549Srgrimes struct getdomainname_args *uap; 2681549Srgrimes{ 26982717Sdillon int domainnamelen; 27082717Sdillon int error; 27182717Sdillon 27282717Sdillon mtx_lock(&Giant); 27382717Sdillon domainnamelen = strlen(domainname) + 1; 274120029Snectar if ((u_int)uap->len > domainnamelen) 275120029Snectar uap->len = domainnamelen; 27699012Salfred error = copyout(domainname, uap->domainname, uap->len); 27782717Sdillon mtx_unlock(&Giant); 27882717Sdillon return (error); 2791549Srgrimes} 2801549Srgrimes 28112221Sbde#ifndef _SYS_SYSPROTO_H_ 2821549Srgrimesstruct setdomainname_args { 2831549Srgrimes char *domainname; 28412222Sbde int len; 2851549Srgrimes}; 28612221Sbde#endif 2871549Srgrimes 28882717Sdillon/* 28982717Sdillon * MPSAFE 29082717Sdillon */ 2911549Srgrimes/* ARGSUSED */ 2921549Srgrimesint 29383366Sjuliansetdomainname(td, uap) 29483366Sjulian struct thread *td; 2951549Srgrimes struct setdomainname_args *uap; 2961549Srgrimes{ 29712280Sphk int error, domainnamelen; 2981549Srgrimes 29982717Sdillon mtx_lock(&Giant); 30093593Sjhb if ((error = suser(td))) 30182717Sdillon goto done2; 30282717Sdillon if ((u_int)uap->len > sizeof (domainname) - 1) { 30382717Sdillon error = EINVAL; 30482717Sdillon goto done2; 30582717Sdillon } 3061549Srgrimes domainnamelen = uap->len; 30799012Salfred error = copyin(uap->domainname, domainname, uap->len); 3081549Srgrimes domainname[domainnamelen] = 0; 30982717Sdillondone2: 31082717Sdillon mtx_unlock(&Giant); 3111549Srgrimes return (error); 3121549Srgrimes} 3131549Srgrimes 314