2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)kern_xxx.c 8.2 (Berkeley) 11/14/93
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include "opt_compat.h"
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/sysproto.h>
40 #include <sys/kernel.h>
43 #include <sys/mutex.h>
44 #include <sys/sysctl.h>
45 #include <sys/utsname.h>
48 #if defined(COMPAT_43)
50 #ifndef _SYS_SYSPROTO_H_
51 struct gethostname_args {
63 struct gethostname_args *uap;
67 size_t len = uap->len;
70 name[1] = KERN_HOSTNAME;
72 error = userland_sysctl(td, name, 2, uap->hostname, &len,
78 #ifndef _SYS_SYSPROTO_H_
79 struct sethostname_args {
91 register struct sethostname_args *uap;
97 name[1] = KERN_HOSTNAME;
99 error = userland_sysctl(td, name, 2, 0, 0, 0, uap->hostname,
105 #ifndef _SYS_SYSPROTO_H_
106 struct ogethostid_args {
117 struct ogethostid_args *uap;
120 *(long *)(td->td_retval) = hostid;
123 #endif /* COMPAT_43 */
126 #ifndef _SYS_SYSPROTO_H_
127 struct osethostid_args {
138 struct osethostid_args *uap;
142 if ((error = suser(td)))
145 hostid = uap->hostid;
156 struct oquota_args *uap;
160 #endif /* COMPAT_43 */
163 * This is the FreeBSD-1.1 compatable uname(2) interface. These
164 * days it is done in libc as a wrapper around a bunch of sysctl's.
165 * This must maintain the old 1.1 binary ABI.
168 #error "FreeBSD-1.1 uname syscall has been broken"
170 #ifndef _SYS_SYSPROTO_H_
172 struct utsname *name;
183 struct uname_args *uap;
190 name[1] = KERN_OSTYPE;
191 len = sizeof (uap->name->sysname);
193 error = userland_sysctl(td, name, 2, uap->name->sysname, &len,
197 subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0);
199 name[1] = KERN_HOSTNAME;
200 len = sizeof uap->name->nodename;
201 error = userland_sysctl(td, name, 2, uap->name->nodename, &len,
205 subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0);
207 name[1] = KERN_OSRELEASE;
208 len = sizeof uap->name->release;
209 error = userland_sysctl(td, name, 2, uap->name->release, &len,
213 subyte( uap->name->release + sizeof(uap->name->release) - 1, 0);
217 len = sizeof uap->name->version;
218 error = userland_sysctl(td, name, 2, uap->name->version, &len,
222 subyte( uap->name->version + sizeof(uap->name->version) - 1, 0);
226 * this stupid hackery to make the version field look like FreeBSD 1.1
228 for(s = version; *s && *s != '#'; s++);
230 for(us = uap->name->version; *s && *s != ':'; s++) {
231 error = subyte( us++, *s);
235 error = subyte( us++, 0);
240 name[1] = HW_MACHINE;
241 len = sizeof uap->name->machine;
242 error = userland_sysctl(td, name, 2, uap->name->machine, &len,
246 subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0);
252 #ifndef _SYS_SYSPROTO_H_
253 struct getdomainname_args {
264 getdomainname(td, uap)
266 struct getdomainname_args *uap;
272 domainnamelen = strlen(domainname) + 1;
273 if ((u_int)uap->len > domainnamelen)
274 uap->len = domainnamelen;
275 error = copyout(domainname, uap->domainname, uap->len);
280 #ifndef _SYS_SYSPROTO_H_
281 struct setdomainname_args {
292 setdomainname(td, uap)
294 struct setdomainname_args *uap;
296 int error, domainnamelen;
299 if ((error = suser(td)))
301 if ((u_int)uap->len > sizeof (domainname) - 1) {
305 domainnamelen = uap->len;
306 error = copyin(uap->domainname, domainname, uap->len);
307 domainname[domainnamelen] = 0;