kern_xxx.c revision 31778
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 * 3. All advertising materials mentioning features or use of this software
141541Srgrimes *    must display the following acknowledgement:
151541Srgrimes *	This product includes software developed by the University of
161541Srgrimes *	California, Berkeley and its contributors.
171541Srgrimes * 4. Neither the name of the University nor the names of its contributors
181541Srgrimes *    may be used to endorse or promote products derived from this software
191541Srgrimes *    without specific prior written permission.
201541Srgrimes *
211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311541Srgrimes * SUCH DAMAGE.
321541Srgrimes *
331541Srgrimes *	@(#)kern_xxx.c	8.2 (Berkeley) 11/14/93
3431778Seivind * $Id: kern_xxx.c,v 1.26 1997/11/06 19:29:18 phk Exp $
351541Srgrimes */
361541Srgrimes
3731778Seivind#include "opt_compat.h"
3831778Seivind
391541Srgrimes#include <sys/param.h>
401541Srgrimes#include <sys/systm.h>
4112221Sbde#include <sys/sysproto.h>
421541Srgrimes#include <sys/kernel.h>
431541Srgrimes#include <sys/proc.h>
441541Srgrimes#include <sys/sysctl.h>
451549Srgrimes#include <sys/utsname.h>
461541Srgrimes
478876Srgrimes
481541Srgrimes#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
491541Srgrimes
5012221Sbde#ifndef _SYS_SYSPROTO_H_
511541Srgrimesstruct gethostname_args {
521541Srgrimes	char	*hostname;
531541Srgrimes	u_int	len;
541541Srgrimes};
5512221Sbde#endif
561541Srgrimes/* ARGSUSED */
571549Srgrimesint
5830994Sphkogethostname(p, uap)
591541Srgrimes	struct proc *p;
601541Srgrimes	struct gethostname_args *uap;
611541Srgrimes{
6212171Sphk	int name[2];
631541Srgrimes
6412171Sphk	name[0] = CTL_KERN;
6512171Sphk	name[1] = KERN_HOSTNAME;
6612171Sphk	return (userland_sysctl(p, name, 2, uap->hostname, &uap->len,
6712171Sphk		1, 0, 0, 0));
681541Srgrimes}
691541Srgrimes
7012221Sbde#ifndef _SYS_SYSPROTO_H_
711541Srgrimesstruct sethostname_args {
721541Srgrimes	char	*hostname;
731541Srgrimes	u_int	len;
741541Srgrimes};
7512221Sbde#endif
761541Srgrimes/* ARGSUSED */
771549Srgrimesint
7830994Sphkosethostname(p, uap)
791541Srgrimes	struct proc *p;
801541Srgrimes	register struct sethostname_args *uap;
811541Srgrimes{
8212171Sphk	int name[2];
831541Srgrimes	int error;
841541Srgrimes
8512171Sphk	name[0] = CTL_KERN;
8612171Sphk	name[1] = KERN_HOSTNAME;
873098Sphk	if ((error = suser(p->p_ucred, &p->p_acflag)))
881541Srgrimes		return (error);
8912171Sphk	return (userland_sysctl(p, name, 2, 0, 0, 0,
9012171Sphk		uap->hostname, uap->len, 0));
911541Srgrimes}
921541Srgrimes
9312221Sbde#ifndef _SYS_SYSPROTO_H_
9412200Sbdestruct ogethostid_args {
951541Srgrimes	int	dummy;
961541Srgrimes};
9712221Sbde#endif
981541Srgrimes/* ARGSUSED */
991549Srgrimesint
10030994Sphkogethostid(p, uap)
1011541Srgrimes	struct proc *p;
10212200Sbde	struct ogethostid_args *uap;
1031541Srgrimes{
1041541Srgrimes
10530994Sphk	*(long *)(p->p_retval) = hostid;
1061541Srgrimes	return (0);
1071541Srgrimes}
1081541Srgrimes#endif /* COMPAT_43 || COMPAT_SUNOS */
1091541Srgrimes
1101541Srgrimes#ifdef COMPAT_43
11112221Sbde#ifndef _SYS_SYSPROTO_H_
11212200Sbdestruct osethostid_args {
1131541Srgrimes	long	hostid;
1141541Srgrimes};
11512221Sbde#endif
1161541Srgrimes/* ARGSUSED */
1171549Srgrimesint
11830994Sphkosethostid(p, uap)
1191541Srgrimes	struct proc *p;
12012200Sbde	struct osethostid_args *uap;
1211541Srgrimes{
1221541Srgrimes	int error;
1231541Srgrimes
1243098Sphk	if ((error = suser(p->p_ucred, &p->p_acflag)))
1251541Srgrimes		return (error);
1261541Srgrimes	hostid = uap->hostid;
1271541Srgrimes	return (0);
1281541Srgrimes}
1291541Srgrimes
1301549Srgrimesint
13130994Sphkoquota(p, uap)
13212200Sbde	struct proc *p;
13312200Sbde	struct oquota_args *uap;
1341541Srgrimes{
1351541Srgrimes
1361541Srgrimes	return (ENOSYS);
1371541Srgrimes}
1381541Srgrimes#endif /* COMPAT_43 */
1391549Srgrimes
14012221Sbde#ifndef _SYS_SYSPROTO_H_
1411549Srgrimesstruct uname_args {
1421549Srgrimes        struct utsname  *name;
1431549Srgrimes};
14412221Sbde#endif
1451549Srgrimes
1461549Srgrimes/* ARGSUSED */
1471549Srgrimesint
14830994Sphkuname(p, uap)
1491549Srgrimes	struct proc *p;
1501549Srgrimes	struct uname_args *uap;
1511549Srgrimes{
15212421Sphk	int name[2], len, rtval;
1531549Srgrimes	char *s, *us;
1541549Srgrimes
15512171Sphk	name[0] = CTL_KERN;
15612171Sphk	name[1] = KERN_OSTYPE;
1571549Srgrimes	len = sizeof uap->name->sysname;
15812171Sphk	rtval = userland_sysctl(p, name, 2, uap->name->sysname, &len,
15912171Sphk		1, 0, 0, 0);
1601549Srgrimes	if( rtval) return rtval;
1611549Srgrimes	subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0);
1621549Srgrimes
16312171Sphk	name[1] = KERN_HOSTNAME;
1641549Srgrimes	len = sizeof uap->name->nodename;
16512171Sphk	rtval = userland_sysctl(p, name, 2, uap->name->nodename, &len,
16612171Sphk		1, 0, 0, 0);
1671549Srgrimes	if( rtval) return rtval;
1681549Srgrimes	subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0);
1691549Srgrimes
17012171Sphk	name[1] = KERN_OSRELEASE;
1711549Srgrimes	len = sizeof uap->name->release;
17212171Sphk	rtval = userland_sysctl(p, name, 2, uap->name->release, &len,
17312171Sphk		1, 0, 0, 0);
1741549Srgrimes	if( rtval) return rtval;
1751549Srgrimes	subyte( uap->name->release + sizeof(uap->name->release) - 1, 0);
1761549Srgrimes
1771549Srgrimes/*
1781549Srgrimes	name = KERN_VERSION;
1791549Srgrimes	len = sizeof uap->name->version;
18012171Sphk	rtval = userland_sysctl(p, name, 2, uap->name->version, &len,
18112171Sphk		1, 0, 0, 0);
1821549Srgrimes	if( rtval) return rtval;
1831549Srgrimes	subyte( uap->name->version + sizeof(uap->name->version) - 1, 0);
1841549Srgrimes*/
1851549Srgrimes
1861549Srgrimes/*
1871549Srgrimes * this stupid hackery to make the version field look like FreeBSD 1.1
1881549Srgrimes */
1891549Srgrimes	for(s = version; *s && *s != '#'; s++);
1901549Srgrimes
1911549Srgrimes	for(us = uap->name->version; *s && *s != ':'; s++) {
1921549Srgrimes		rtval = subyte( us++, *s);
1931549Srgrimes		if( rtval)
1941549Srgrimes			return rtval;
1951549Srgrimes	}
1961549Srgrimes	rtval = subyte( us++, 0);
1971549Srgrimes	if( rtval)
1981549Srgrimes		return rtval;
1991549Srgrimes
20012171Sphk	name[1] = HW_MACHINE;
2011549Srgrimes	len = sizeof uap->name->machine;
20212171Sphk	rtval = userland_sysctl(p, name, 2, uap->name->machine, &len,
20312171Sphk		1, 0, 0, 0);
2041549Srgrimes	if( rtval) return rtval;
2051549Srgrimes	subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0);
2061549Srgrimes
2071549Srgrimes	return 0;
2081549Srgrimes}
2091549Srgrimes
21012221Sbde#ifndef _SYS_SYSPROTO_H_
2111549Srgrimesstruct getdomainname_args {
2121549Srgrimes        char    *domainname;
21312222Sbde        int     len;
2141549Srgrimes};
21512222Sbde#endif
2161549Srgrimes
2171549Srgrimes/* ARGSUSED */
2181549Srgrimesint
21930994Sphkgetdomainname(p, uap)
2201549Srgrimes        struct proc *p;
2211549Srgrimes        struct getdomainname_args *uap;
2221549Srgrimes{
22312280Sphk	int domainnamelen = strlen(domainname) + 1;
22412222Sbde	if ((u_int)uap->len > domainnamelen + 1)
2251549Srgrimes		uap->len = domainnamelen + 1;
2261549Srgrimes	return (copyout((caddr_t)domainname, (caddr_t)uap->domainname, uap->len));
2271549Srgrimes}
2281549Srgrimes
22912221Sbde#ifndef _SYS_SYSPROTO_H_
2301549Srgrimesstruct setdomainname_args {
2311549Srgrimes        char    *domainname;
23212222Sbde        int     len;
2331549Srgrimes};
23412221Sbde#endif
2351549Srgrimes
2361549Srgrimes/* ARGSUSED */
2371549Srgrimesint
23830994Sphksetdomainname(p, uap)
2391549Srgrimes        struct proc *p;
2401549Srgrimes        struct setdomainname_args *uap;
2411549Srgrimes{
24212280Sphk        int error, domainnamelen;
2431549Srgrimes
2443098Sphk        if ((error = suser(p->p_ucred, &p->p_acflag)))
2451549Srgrimes                return (error);
24612222Sbde        if ((u_int)uap->len > sizeof (domainname) - 1)
2471549Srgrimes                return EINVAL;
2481549Srgrimes        domainnamelen = uap->len;
2491549Srgrimes        error = copyin((caddr_t)uap->domainname, domainname, uap->len);
2501549Srgrimes        domainname[domainnamelen] = 0;
2511549Srgrimes        return (error);
2521549Srgrimes}
2531549Srgrimes
254