kern_xxx.c revision 184789
1139804Simp/*-
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 184789 2008-11-09 10:45:13Z ed $");
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>
41164033Srwatson#include <sys/priv.h>
421541Srgrimes#include <sys/proc.h>
4382717Sdillon#include <sys/lock.h>
4482717Sdillon#include <sys/mutex.h>
451541Srgrimes#include <sys/sysctl.h>
461549Srgrimes#include <sys/utsname.h>
47181803Sbz#include <sys/vimage.h>
481541Srgrimes
498876Srgrimes
50130344Sphk#if defined(COMPAT_43)
511541Srgrimes
5212221Sbde#ifndef _SYS_SYSPROTO_H_
531541Srgrimesstruct gethostname_args {
541541Srgrimes	char	*hostname;
551541Srgrimes	u_int	len;
561541Srgrimes};
5712221Sbde#endif
581541Srgrimes/* ARGSUSED */
591549Srgrimesint
6083366Sjulianogethostname(td, uap)
6183366Sjulian	struct thread *td;
621541Srgrimes	struct gethostname_args *uap;
631541Srgrimes{
6412171Sphk	int name[2];
6582717Sdillon	int error;
6638517Sdfr	size_t len = uap->len;
671541Srgrimes
6812171Sphk	name[0] = CTL_KERN;
6912171Sphk	name[1] = KERN_HOSTNAME;
7082717Sdillon	mtx_lock(&Giant);
71136417Sphk	error = userland_sysctl(td, name, 2, uap->hostname, &len,
72136417Sphk	    1, 0, 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
831541Srgrimes/* ARGSUSED */
841549Srgrimesint
8583366Sjulianosethostname(td, uap)
8683366Sjulian	struct thread *td;
871541Srgrimes	register struct sethostname_args *uap;
881541Srgrimes{
8912171Sphk	int name[2];
901541Srgrimes	int error;
911541Srgrimes
9212171Sphk	name[0] = CTL_KERN;
9312171Sphk	name[1] = KERN_HOSTNAME;
9482717Sdillon	mtx_lock(&Giant);
95136777Srwatson	error = userland_sysctl(td, name, 2, 0, 0, 0, uap->hostname,
96136777Srwatson	    uap->len, 0, 0);
9782717Sdillon	mtx_unlock(&Giant);
9882717Sdillon	return (error);
991541Srgrimes}
1001541Srgrimes
10112221Sbde#ifndef _SYS_SYSPROTO_H_
10212200Sbdestruct ogethostid_args {
1031541Srgrimes	int	dummy;
1041541Srgrimes};
10512221Sbde#endif
1061541Srgrimes/* ARGSUSED */
1071549Srgrimesint
10883366Sjulianogethostid(td, uap)
10983366Sjulian	struct thread *td;
11012200Sbde	struct ogethostid_args *uap;
1111541Srgrimes{
1121541Srgrimes
11383366Sjulian	*(long *)(td->td_retval) = hostid;
1141541Srgrimes	return (0);
1151541Srgrimes}
116130344Sphk#endif /* COMPAT_43 */
1171541Srgrimes
1181541Srgrimes#ifdef COMPAT_43
11912221Sbde#ifndef _SYS_SYSPROTO_H_
12012200Sbdestruct osethostid_args {
1211541Srgrimes	long	hostid;
1221541Srgrimes};
12312221Sbde#endif
1241541Srgrimes/* ARGSUSED */
1251549Srgrimesint
12683366Sjulianosethostid(td, uap)
12783366Sjulian	struct thread *td;
12812200Sbde	struct osethostid_args *uap;
1291541Srgrimes{
1301541Srgrimes	int error;
1311541Srgrimes
132164033Srwatson	error = priv_check(td, PRIV_SETHOSTID);
133164033Srwatson	if (error)
134119364Stjr		return (error);
13582717Sdillon	mtx_lock(&Giant);
136119364Stjr	hostid = uap->hostid;
13782717Sdillon	mtx_unlock(&Giant);
138119364Stjr	return (0);
1391541Srgrimes}
1401541Srgrimes
1411549Srgrimesint
14283366Sjulianoquota(td, uap)
14383366Sjulian	struct thread *td;
14412200Sbde	struct oquota_args *uap;
1451541Srgrimes{
146167232Srwatson
1471541Srgrimes	return (ENOSYS);
1481541Srgrimes}
1491541Srgrimes#endif /* COMPAT_43 */
1501549Srgrimes
151184789Sed#ifdef COMPAT_FREEBSD4
15274729Speter/*
153184789Sed * This is the FreeBSD-1.1 compatible uname(2) interface.  These days it is
154167232Srwatson * done in libc as a wrapper around a bunch of sysctl's.  This must maintain
155167232Srwatson * the old 1.1 binary ABI.
15674729Speter */
15774729Speter#if SYS_NMLN != 32
15874729Speter#error "FreeBSD-1.1 uname syscall has been broken"
15974729Speter#endif
16012221Sbde#ifndef _SYS_SYSPROTO_H_
1611549Srgrimesstruct uname_args {
162180039Sjulian	struct utsname  *name;
1631549Srgrimes};
16412221Sbde#endif
1651549Srgrimes/* ARGSUSED */
1661549Srgrimesint
167184789Sedfreebsd4_uname(struct thread *td, struct freebsd4_uname_args *uap)
1681549Srgrimes{
16982717Sdillon	int name[2], error;
17038517Sdfr	size_t len;
1711549Srgrimes	char *s, *us;
1721549Srgrimes
17312171Sphk	name[0] = CTL_KERN;
17412171Sphk	name[1] = KERN_OSTYPE;
17582717Sdillon	len = sizeof (uap->name->sysname);
17682717Sdillon	mtx_lock(&Giant);
17783366Sjulian	error = userland_sysctl(td, name, 2, uap->name->sysname, &len,
178136404Speter		1, 0, 0, 0, 0);
17982717Sdillon	if (error)
18082717Sdillon		goto done2;
1811549Srgrimes	subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0);
1821549Srgrimes
18312171Sphk	name[1] = KERN_HOSTNAME;
1841549Srgrimes	len = sizeof uap->name->nodename;
18583366Sjulian	error = userland_sysctl(td, name, 2, uap->name->nodename, &len,
186136404Speter		1, 0, 0, 0, 0);
18782717Sdillon	if (error)
18882717Sdillon		goto done2;
1891549Srgrimes	subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0);
1901549Srgrimes
19112171Sphk	name[1] = KERN_OSRELEASE;
1921549Srgrimes	len = sizeof uap->name->release;
19383366Sjulian	error = userland_sysctl(td, name, 2, uap->name->release, &len,
194136404Speter		1, 0, 0, 0, 0);
19582717Sdillon	if (error)
19682717Sdillon		goto done2;
1971549Srgrimes	subyte( uap->name->release + sizeof(uap->name->release) - 1, 0);
1981549Srgrimes
1991549Srgrimes/*
2001549Srgrimes	name = KERN_VERSION;
2011549Srgrimes	len = sizeof uap->name->version;
20283366Sjulian	error = userland_sysctl(td, name, 2, uap->name->version, &len,
203136404Speter		1, 0, 0, 0, 0);
20482717Sdillon	if (error)
20582717Sdillon		goto done2;
2061549Srgrimes	subyte( uap->name->version + sizeof(uap->name->version) - 1, 0);
2071549Srgrimes*/
2081549Srgrimes
2091549Srgrimes/*
2101549Srgrimes * this stupid hackery to make the version field look like FreeBSD 1.1
2111549Srgrimes */
2121549Srgrimes	for(s = version; *s && *s != '#'; s++);
2131549Srgrimes
2141549Srgrimes	for(us = uap->name->version; *s && *s != ':'; s++) {
21582717Sdillon		error = subyte( us++, *s);
21682717Sdillon		if (error)
21782717Sdillon			goto done2;
2181549Srgrimes	}
21982717Sdillon	error = subyte( us++, 0);
22082717Sdillon	if (error)
22182717Sdillon		goto done2;
2221549Srgrimes
22338517Sdfr	name[0] = CTL_HW;
22412171Sphk	name[1] = HW_MACHINE;
2251549Srgrimes	len = sizeof uap->name->machine;
22683366Sjulian	error = userland_sysctl(td, name, 2, uap->name->machine, &len,
227136404Speter		1, 0, 0, 0, 0);
22882717Sdillon	if (error)
22982717Sdillon		goto done2;
2301549Srgrimes	subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0);
23182717Sdillondone2:
23282717Sdillon	mtx_unlock(&Giant);
23382717Sdillon	return (error);
2341549Srgrimes}
2351549Srgrimes
23612221Sbde#ifndef _SYS_SYSPROTO_H_
2371549Srgrimesstruct getdomainname_args {
238180039Sjulian	char    *domainname;
239180039Sjulian	int     len;
2401549Srgrimes};
24112222Sbde#endif
2421549Srgrimes/* ARGSUSED */
2431549Srgrimesint
244184789Sedfreebsd4_getdomainname(struct thread *td,
245184789Sed    struct freebsd4_getdomainname_args *uap)
2461549Srgrimes{
247184789Sed	int name[2];
248184789Sed	int error;
249184789Sed	size_t len = uap->len;
25082717Sdillon
251184789Sed	name[0] = CTL_KERN;
252184789Sed	name[1] = KERN_NISDOMAINNAME;
253184789Sed	mtx_lock(&Giant);
254184789Sed	error = userland_sysctl(td, name, 2, uap->domainname, &len,
255184789Sed	    1, 0, 0, 0, 0);
256184789Sed	mtx_unlock(&Giant);
257184789Sed	return(error);
2581549Srgrimes}
2591549Srgrimes
26012221Sbde#ifndef _SYS_SYSPROTO_H_
2611549Srgrimesstruct setdomainname_args {
262180039Sjulian	char    *domainname;
263180039Sjulian	int     len;
2641549Srgrimes};
26512221Sbde#endif
2661549Srgrimes/* ARGSUSED */
2671549Srgrimesint
268184789Sedfreebsd4_setdomainname(struct thread *td,
269184789Sed    struct freebsd4_setdomainname_args *uap)
2701549Srgrimes{
271184789Sed	int name[2];
272184789Sed	int error;
2731549Srgrimes
274184789Sed	name[0] = CTL_KERN;
275184789Sed	name[1] = KERN_NISDOMAINNAME;
276184789Sed	mtx_lock(&Giant);
277184789Sed	error = userland_sysctl(td, name, 2, 0, 0, 0, uap->domainname,
278184789Sed	    uap->len, 0, 0);
279184789Sed	mtx_unlock(&Giant);
280180039Sjulian	return (error);
2811549Srgrimes}
282184789Sed#endif /* COMPAT_FREEBSD4 */
283