19454b2d8SWarner Losh /*-
251369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause
351369649SPedro F. Giffuni *
4df8bae1dSRodney W. Grimes * Copyright (c) 1982, 1986, 1989, 1993
5df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved.
6df8bae1dSRodney W. Grimes *
7df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without
8df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions
9df8bae1dSRodney W. Grimes * are met:
10df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright
11df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer.
12df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright
13df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the
14df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution.
1569a28758SEd Maste * 3. Neither the name of the University nor the names of its contributors
16df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software
17df8bae1dSRodney W. Grimes * without specific prior written permission.
18df8bae1dSRodney W. Grimes *
19df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29df8bae1dSRodney W. Grimes * SUCH DAMAGE.
30df8bae1dSRodney W. Grimes */
31df8bae1dSRodney W. Grimes
32df8bae1dSRodney W. Grimes #include <sys/param.h>
33df8bae1dSRodney W. Grimes #include <sys/systm.h>
34d2d3e875SBruce Evans #include <sys/sysproto.h>
35df8bae1dSRodney W. Grimes #include <sys/kernel.h>
36acd3428bSRobert Watson #include <sys/priv.h>
37df8bae1dSRodney W. Grimes #include <sys/proc.h>
386f1e8c18SMatthew Dillon #include <sys/lock.h>
396f1e8c18SMatthew Dillon #include <sys/mutex.h>
4071b6d504SEd Schouten #include <sys/socket.h>
41df8bae1dSRodney W. Grimes #include <sys/sysctl.h>
4226f9a767SRodney W. Grimes #include <sys/utsname.h>
4326f9a767SRodney W. Grimes
4471b6d504SEd Schouten #include <vm/vm_param.h>
45df8bae1dSRodney W. Grimes
461930e303SPoul-Henning Kamp #if defined(COMPAT_43)
47df8bae1dSRodney W. Grimes
4826f9a767SRodney W. Grimes int
ogethostname(struct thread * td,struct ogethostname_args * uap)49d48719bdSBrooks Davis ogethostname(struct thread *td, struct ogethostname_args *uap)
50df8bae1dSRodney W. Grimes {
51b8da2396SPoul-Henning Kamp int name[2];
52069e9bc1SDoug Rabson size_t len = uap->len;
53df8bae1dSRodney W. Grimes
54b8da2396SPoul-Henning Kamp name[0] = CTL_KERN;
55b8da2396SPoul-Henning Kamp name[1] = KERN_HOSTNAME;
56ddf9d243SEd Schouten return (userland_sysctl(td, name, 2, uap->hostname, &len,
57ddf9d243SEd Schouten 1, 0, 0, 0, 0));
58df8bae1dSRodney W. Grimes }
59df8bae1dSRodney W. Grimes
6026f9a767SRodney W. Grimes int
osethostname(struct thread * td,struct osethostname_args * uap)61d48719bdSBrooks Davis osethostname(struct thread *td, struct osethostname_args *uap)
62df8bae1dSRodney W. Grimes {
63b8da2396SPoul-Henning Kamp int name[2];
64df8bae1dSRodney W. Grimes
65b8da2396SPoul-Henning Kamp name[0] = CTL_KERN;
66b8da2396SPoul-Henning Kamp name[1] = KERN_HOSTNAME;
67ddf9d243SEd Schouten return (userland_sysctl(td, name, 2, 0, 0, 0, uap->hostname,
68ddf9d243SEd Schouten uap->len, 0, 0));
69df8bae1dSRodney W. Grimes }
70df8bae1dSRodney W. Grimes
71d2d3e875SBruce Evans #ifndef _SYS_SYSPROTO_H_
722635f86cSBruce Evans struct ogethostid_args {
73df8bae1dSRodney W. Grimes int dummy;
74df8bae1dSRodney W. Grimes };
75d2d3e875SBruce Evans #endif
76df8bae1dSRodney W. Grimes /* ARGSUSED */
7726f9a767SRodney W. Grimes int
ogethostid(struct thread * td,struct ogethostid_args * uap)783e85b721SEd Maste ogethostid(struct thread *td, struct ogethostid_args *uap)
79df8bae1dSRodney W. Grimes {
8076ca6f88SJamie Gritton size_t len = sizeof(long);
8176ca6f88SJamie Gritton int name[2];
82df8bae1dSRodney W. Grimes
8376ca6f88SJamie Gritton name[0] = CTL_KERN;
8476ca6f88SJamie Gritton name[1] = KERN_HOSTID;
8576ca6f88SJamie Gritton return (kernel_sysctl(td, name, 2, (long *)td->td_retval, &len,
8676ca6f88SJamie Gritton NULL, 0, NULL, 0));
87df8bae1dSRodney W. Grimes }
88df8bae1dSRodney W. Grimes
8926f9a767SRodney W. Grimes int
osethostid(struct thread * td,struct osethostid_args * uap)903e85b721SEd Maste osethostid(struct thread *td, struct osethostid_args *uap)
91df8bae1dSRodney W. Grimes {
9276ca6f88SJamie Gritton int name[2];
93df8bae1dSRodney W. Grimes
9476ca6f88SJamie Gritton name[0] = CTL_KERN;
9576ca6f88SJamie Gritton name[1] = KERN_HOSTID;
9676ca6f88SJamie Gritton return (kernel_sysctl(td, name, 2, NULL, NULL, &uap->hostid,
9776ca6f88SJamie Gritton sizeof(uap->hostid), NULL, 0));
98df8bae1dSRodney W. Grimes }
99df8bae1dSRodney W. Grimes
10026f9a767SRodney W. Grimes int
oquota(struct thread * td,struct oquota_args * uap)1013e85b721SEd Maste oquota(struct thread *td, struct oquota_args *uap)
102df8bae1dSRodney W. Grimes {
103873fbcd7SRobert Watson
104df8bae1dSRodney W. Grimes return (ENOSYS);
105df8bae1dSRodney W. Grimes }
10671b6d504SEd Schouten
10771b6d504SEd Schouten #define KINFO_PROC (0<<8)
10871b6d504SEd Schouten #define KINFO_RT (1<<8)
10962a573d9SMateusz Guzik /* UNUSED, was KINFO_VNODE (2<<8) */
11071b6d504SEd Schouten #define KINFO_FILE (3<<8)
11171b6d504SEd Schouten #define KINFO_METER (4<<8)
11271b6d504SEd Schouten #define KINFO_LOADAVG (5<<8)
11371b6d504SEd Schouten #define KINFO_CLOCKRATE (6<<8)
11471b6d504SEd Schouten
11571b6d504SEd Schouten /* Non-standard BSDI extension - only present on their 4.3 net-2 releases */
11671b6d504SEd Schouten #define KINFO_BSDI_SYSINFO (101<<8)
11771b6d504SEd Schouten
11871b6d504SEd Schouten /*
11971b6d504SEd Schouten * XXX this is bloat, but I hope it's better here than on the potentially
12071b6d504SEd Schouten * limited kernel stack... -Peter
12171b6d504SEd Schouten */
12271b6d504SEd Schouten
12371b6d504SEd Schouten static struct {
12471b6d504SEd Schouten int bsdi_machine; /* "i386" on BSD/386 */
12571b6d504SEd Schouten /* ^^^ this is an offset to the string, relative to the struct start */
12671b6d504SEd Schouten char *pad0;
12771b6d504SEd Schouten long pad1;
12871b6d504SEd Schouten long pad2;
12971b6d504SEd Schouten long pad3;
13071b6d504SEd Schouten u_long pad4;
13171b6d504SEd Schouten u_long pad5;
13271b6d504SEd Schouten u_long pad6;
13371b6d504SEd Schouten
13471b6d504SEd Schouten int bsdi_ostype; /* "BSD/386" on BSD/386 */
13571b6d504SEd Schouten int bsdi_osrelease; /* "1.1" on BSD/386 */
13671b6d504SEd Schouten long pad7;
13771b6d504SEd Schouten long pad8;
13871b6d504SEd Schouten char *pad9;
13971b6d504SEd Schouten
14071b6d504SEd Schouten long pad10;
14171b6d504SEd Schouten long pad11;
14271b6d504SEd Schouten int pad12;
14371b6d504SEd Schouten long pad13;
14471b6d504SEd Schouten quad_t pad14;
14571b6d504SEd Schouten long pad15;
14671b6d504SEd Schouten
14771b6d504SEd Schouten struct timeval pad16;
14871b6d504SEd Schouten /* we dont set this, because BSDI's uname used gethostname() instead */
14971b6d504SEd Schouten int bsdi_hostname; /* hostname on BSD/386 */
15071b6d504SEd Schouten
15171b6d504SEd Schouten /* the actual string data is appended here */
15271b6d504SEd Schouten
15371b6d504SEd Schouten } bsdi_si;
15471b6d504SEd Schouten
15571b6d504SEd Schouten /*
15671b6d504SEd Schouten * this data is appended to the end of the bsdi_si structure during copyout.
15771b6d504SEd Schouten * The "char *" offsets are relative to the base of the bsdi_si struct.
15871b6d504SEd Schouten * This contains "FreeBSD\02.0-BUILT-nnnnnn\0i386\0", and these strings
15971b6d504SEd Schouten * should not exceed the length of the buffer here... (or else!! :-)
16071b6d504SEd Schouten */
16171b6d504SEd Schouten static char bsdi_strings[80]; /* It had better be less than this! */
16271b6d504SEd Schouten
16371b6d504SEd Schouten int
ogetkerninfo(struct thread * td,struct ogetkerninfo_args * uap)164d48719bdSBrooks Davis ogetkerninfo(struct thread *td, struct ogetkerninfo_args *uap)
16571b6d504SEd Schouten {
16671b6d504SEd Schouten int error, name[6];
16771b6d504SEd Schouten size_t size;
16871b6d504SEd Schouten u_int needed = 0;
16971b6d504SEd Schouten
17071b6d504SEd Schouten switch (uap->op & 0xff00) {
17171b6d504SEd Schouten case KINFO_RT:
17271b6d504SEd Schouten name[0] = CTL_NET;
17371b6d504SEd Schouten name[1] = PF_ROUTE;
17471b6d504SEd Schouten name[2] = 0;
17571b6d504SEd Schouten name[3] = (uap->op & 0xff0000) >> 16;
17671b6d504SEd Schouten name[4] = uap->op & 0xff;
17771b6d504SEd Schouten name[5] = uap->arg;
17871b6d504SEd Schouten error = userland_sysctl(td, name, 6, uap->where, uap->size,
17971b6d504SEd Schouten 0, 0, 0, &size, 0);
18071b6d504SEd Schouten break;
18171b6d504SEd Schouten
18271b6d504SEd Schouten case KINFO_PROC:
18371b6d504SEd Schouten name[0] = CTL_KERN;
18471b6d504SEd Schouten name[1] = KERN_PROC;
18571b6d504SEd Schouten name[2] = uap->op & 0xff;
18671b6d504SEd Schouten name[3] = uap->arg;
18771b6d504SEd Schouten error = userland_sysctl(td, name, 4, uap->where, uap->size,
18871b6d504SEd Schouten 0, 0, 0, &size, 0);
18971b6d504SEd Schouten break;
19071b6d504SEd Schouten
19171b6d504SEd Schouten case KINFO_FILE:
19271b6d504SEd Schouten name[0] = CTL_KERN;
19371b6d504SEd Schouten name[1] = KERN_FILE;
19471b6d504SEd Schouten error = userland_sysctl(td, name, 2, uap->where, uap->size,
19571b6d504SEd Schouten 0, 0, 0, &size, 0);
19671b6d504SEd Schouten break;
19771b6d504SEd Schouten
19871b6d504SEd Schouten case KINFO_METER:
19971b6d504SEd Schouten name[0] = CTL_VM;
20071b6d504SEd Schouten name[1] = VM_TOTAL;
20171b6d504SEd Schouten error = userland_sysctl(td, name, 2, uap->where, uap->size,
20271b6d504SEd Schouten 0, 0, 0, &size, 0);
20371b6d504SEd Schouten break;
20471b6d504SEd Schouten
20571b6d504SEd Schouten case KINFO_LOADAVG:
20671b6d504SEd Schouten name[0] = CTL_VM;
20771b6d504SEd Schouten name[1] = VM_LOADAVG;
20871b6d504SEd Schouten error = userland_sysctl(td, name, 2, uap->where, uap->size,
20971b6d504SEd Schouten 0, 0, 0, &size, 0);
21071b6d504SEd Schouten break;
21171b6d504SEd Schouten
21271b6d504SEd Schouten case KINFO_CLOCKRATE:
21371b6d504SEd Schouten name[0] = CTL_KERN;
21471b6d504SEd Schouten name[1] = KERN_CLOCKRATE;
21571b6d504SEd Schouten error = userland_sysctl(td, name, 2, uap->where, uap->size,
21671b6d504SEd Schouten 0, 0, 0, &size, 0);
21771b6d504SEd Schouten break;
21871b6d504SEd Schouten
21971b6d504SEd Schouten case KINFO_BSDI_SYSINFO: {
22071b6d504SEd Schouten /*
22171b6d504SEd Schouten * this is pretty crude, but it's just enough for uname()
22271b6d504SEd Schouten * from BSDI's 1.x libc to work.
22371b6d504SEd Schouten *
22471b6d504SEd Schouten * *size gives the size of the buffer before the call, and
22571b6d504SEd Schouten * the amount of data copied after a successful call.
22671b6d504SEd Schouten * If successful, the return value is the amount of data
22771b6d504SEd Schouten * available, which can be larger than *size.
22871b6d504SEd Schouten *
22971b6d504SEd Schouten * BSDI's 2.x product apparently fails with ENOMEM if *size
23071b6d504SEd Schouten * is too small.
23171b6d504SEd Schouten */
23271b6d504SEd Schouten
23371b6d504SEd Schouten u_int left;
23471b6d504SEd Schouten char *s;
23571b6d504SEd Schouten
23671b6d504SEd Schouten bzero((char *)&bsdi_si, sizeof(bsdi_si));
23771b6d504SEd Schouten bzero(bsdi_strings, sizeof(bsdi_strings));
23871b6d504SEd Schouten
23971b6d504SEd Schouten s = bsdi_strings;
24071b6d504SEd Schouten
24171b6d504SEd Schouten bsdi_si.bsdi_ostype = (s - bsdi_strings) + sizeof(bsdi_si);
24271b6d504SEd Schouten strcpy(s, ostype);
24371b6d504SEd Schouten s += strlen(s) + 1;
24471b6d504SEd Schouten
24571b6d504SEd Schouten bsdi_si.bsdi_osrelease = (s - bsdi_strings) + sizeof(bsdi_si);
24671b6d504SEd Schouten strcpy(s, osrelease);
24771b6d504SEd Schouten s += strlen(s) + 1;
24871b6d504SEd Schouten
24971b6d504SEd Schouten bsdi_si.bsdi_machine = (s - bsdi_strings) + sizeof(bsdi_si);
25071b6d504SEd Schouten strcpy(s, machine);
25171b6d504SEd Schouten s += strlen(s) + 1;
25271b6d504SEd Schouten
25371b6d504SEd Schouten needed = sizeof(bsdi_si) + (s - bsdi_strings);
25471b6d504SEd Schouten
25571b6d504SEd Schouten if ((uap->where == NULL) || (uap->size == NULL)) {
25671b6d504SEd Schouten /* process is asking how much buffer to supply.. */
25771b6d504SEd Schouten size = needed;
25871b6d504SEd Schouten error = 0;
25971b6d504SEd Schouten break;
26071b6d504SEd Schouten }
26171b6d504SEd Schouten
26271b6d504SEd Schouten if ((error = copyin(uap->size, &size, sizeof(size))) != 0)
26371b6d504SEd Schouten break;
26471b6d504SEd Schouten
26571b6d504SEd Schouten /* if too much buffer supplied, trim it down */
26671b6d504SEd Schouten if (size > needed)
26771b6d504SEd Schouten size = needed;
26871b6d504SEd Schouten
26971b6d504SEd Schouten /* how much of the buffer is remaining */
27071b6d504SEd Schouten left = size;
27171b6d504SEd Schouten
27271b6d504SEd Schouten if ((error = copyout((char *)&bsdi_si, uap->where, left)) != 0)
27371b6d504SEd Schouten break;
27471b6d504SEd Schouten
27571b6d504SEd Schouten /* is there any point in continuing? */
27671b6d504SEd Schouten if (left > sizeof(bsdi_si)) {
27771b6d504SEd Schouten left -= sizeof(bsdi_si);
27871b6d504SEd Schouten error = copyout(&bsdi_strings,
27971b6d504SEd Schouten uap->where + sizeof(bsdi_si), left);
28071b6d504SEd Schouten }
28171b6d504SEd Schouten break;
28271b6d504SEd Schouten }
28371b6d504SEd Schouten
28471b6d504SEd Schouten default:
28571b6d504SEd Schouten error = EOPNOTSUPP;
28671b6d504SEd Schouten break;
28771b6d504SEd Schouten }
28871b6d504SEd Schouten if (error == 0) {
28971b6d504SEd Schouten td->td_retval[0] = needed ? needed : size;
29071b6d504SEd Schouten if (uap->size) {
29171b6d504SEd Schouten error = copyout(&size, uap->size, sizeof(size));
29271b6d504SEd Schouten }
29371b6d504SEd Schouten }
29471b6d504SEd Schouten return (error);
29571b6d504SEd Schouten }
296df8bae1dSRodney W. Grimes #endif /* COMPAT_43 */
29726f9a767SRodney W. Grimes
298a1b5a895SEd Schouten #ifdef COMPAT_FREEBSD4
29932e47970SPeter Wemm /*
300a1b5a895SEd Schouten * This is the FreeBSD-1.1 compatible uname(2) interface. These days it is
301873fbcd7SRobert Watson * done in libc as a wrapper around a bunch of sysctl's. This must maintain
302873fbcd7SRobert Watson * the old 1.1 binary ABI.
30332e47970SPeter Wemm */
30432e47970SPeter Wemm #if SYS_NMLN != 32
30532e47970SPeter Wemm #error "FreeBSD-1.1 uname syscall has been broken"
30632e47970SPeter Wemm #endif
307d2d3e875SBruce Evans #ifndef _SYS_SYSPROTO_H_
30826f9a767SRodney W. Grimes struct uname_args {
30926f9a767SRodney W. Grimes struct utsname *name;
31026f9a767SRodney W. Grimes };
311d2d3e875SBruce Evans #endif
31226f9a767SRodney W. Grimes /* ARGSUSED */
31326f9a767SRodney W. Grimes int
freebsd4_uname(struct thread * td,struct freebsd4_uname_args * uap)314a1b5a895SEd Schouten freebsd4_uname(struct thread *td, struct freebsd4_uname_args *uap)
31526f9a767SRodney W. Grimes {
3166f1e8c18SMatthew Dillon int name[2], error;
317069e9bc1SDoug Rabson size_t len;
318*92f2a4c8SZhenlei Huang const char *s;
319*92f2a4c8SZhenlei Huang char *us;
32026f9a767SRodney W. Grimes
321b8da2396SPoul-Henning Kamp name[0] = CTL_KERN;
322b8da2396SPoul-Henning Kamp name[1] = KERN_OSTYPE;
3236f1e8c18SMatthew Dillon len = sizeof (uap->name->sysname);
324b40ce416SJulian Elischer error = userland_sysctl(td, name, 2, uap->name->sysname, &len,
325a7bc3102SPeter Wemm 1, 0, 0, 0, 0);
3266f1e8c18SMatthew Dillon if (error)
327ddf9d243SEd Schouten return (error);
3284f35450cSMark Johnston error = subyte(uap->name->sysname + sizeof(uap->name->sysname) - 1, 0);
3294f35450cSMark Johnston if (error)
3304f35450cSMark Johnston return (EFAULT);
33126f9a767SRodney W. Grimes
332b8da2396SPoul-Henning Kamp name[1] = KERN_HOSTNAME;
33326f9a767SRodney W. Grimes len = sizeof uap->name->nodename;
334b40ce416SJulian Elischer error = userland_sysctl(td, name, 2, uap->name->nodename, &len,
335a7bc3102SPeter Wemm 1, 0, 0, 0, 0);
3366f1e8c18SMatthew Dillon if (error)
337ddf9d243SEd Schouten return (error);
3384f35450cSMark Johnston error = subyte(uap->name->nodename + sizeof(uap->name->nodename) - 1, 0);
3394f35450cSMark Johnston if (error)
3404f35450cSMark Johnston return (EFAULT);
34126f9a767SRodney W. Grimes
342b8da2396SPoul-Henning Kamp name[1] = KERN_OSRELEASE;
34326f9a767SRodney W. Grimes len = sizeof uap->name->release;
344b40ce416SJulian Elischer error = userland_sysctl(td, name, 2, uap->name->release, &len,
345a7bc3102SPeter Wemm 1, 0, 0, 0, 0);
3466f1e8c18SMatthew Dillon if (error)
347ddf9d243SEd Schouten return (error);
3484f35450cSMark Johnston error = subyte(uap->name->release + sizeof(uap->name->release) - 1, 0);
3494f35450cSMark Johnston if (error)
3504f35450cSMark Johnston return (EFAULT);
35126f9a767SRodney W. Grimes
35226f9a767SRodney W. Grimes /*
35326f9a767SRodney W. Grimes name = KERN_VERSION;
35426f9a767SRodney W. Grimes len = sizeof uap->name->version;
355b40ce416SJulian Elischer error = userland_sysctl(td, name, 2, uap->name->version, &len,
356a7bc3102SPeter Wemm 1, 0, 0, 0, 0);
3576f1e8c18SMatthew Dillon if (error)
358ddf9d243SEd Schouten return (error);
35926f9a767SRodney W. Grimes subyte( uap->name->version + sizeof(uap->name->version) - 1, 0);
36026f9a767SRodney W. Grimes */
36126f9a767SRodney W. Grimes
36226f9a767SRodney W. Grimes /*
36326f9a767SRodney W. Grimes * this stupid hackery to make the version field look like FreeBSD 1.1
36426f9a767SRodney W. Grimes */
36526f9a767SRodney W. Grimes for(s = version; *s && *s != '#'; s++);
36626f9a767SRodney W. Grimes
36726f9a767SRodney W. Grimes for(us = uap->name->version; *s && *s != ':'; s++) {
368c38df501SMark Johnston if (subyte(us++, *s) != 0)
369c38df501SMark Johnston return (EFAULT);
37026f9a767SRodney W. Grimes }
371c38df501SMark Johnston if (subyte(us++, 0) != 0)
372c38df501SMark Johnston return (EFAULT);
37326f9a767SRodney W. Grimes
374069e9bc1SDoug Rabson name[0] = CTL_HW;
375b8da2396SPoul-Henning Kamp name[1] = HW_MACHINE;
37626f9a767SRodney W. Grimes len = sizeof uap->name->machine;
377b40ce416SJulian Elischer error = userland_sysctl(td, name, 2, uap->name->machine, &len,
378a7bc3102SPeter Wemm 1, 0, 0, 0, 0);
3796f1e8c18SMatthew Dillon if (error)
3806f1e8c18SMatthew Dillon return (error);
3814f35450cSMark Johnston error = subyte(uap->name->machine + sizeof(uap->name->machine) - 1, 0);
3824f35450cSMark Johnston if (error)
3834f35450cSMark Johnston return (EFAULT);
384ddf9d243SEd Schouten return (0);
38526f9a767SRodney W. Grimes }
38626f9a767SRodney W. Grimes
387d2d3e875SBruce Evans #ifndef _SYS_SYSPROTO_H_
38826f9a767SRodney W. Grimes struct getdomainname_args {
38926f9a767SRodney W. Grimes char *domainname;
390f35a53bfSBruce Evans int len;
39126f9a767SRodney W. Grimes };
392d2d3e875SBruce Evans #endif
39326f9a767SRodney W. Grimes /* ARGSUSED */
39426f9a767SRodney W. Grimes int
freebsd4_getdomainname(struct thread * td,struct freebsd4_getdomainname_args * uap)395a1b5a895SEd Schouten freebsd4_getdomainname(struct thread *td,
396a1b5a895SEd Schouten struct freebsd4_getdomainname_args *uap)
39726f9a767SRodney W. Grimes {
398a1b5a895SEd Schouten int name[2];
399a1b5a895SEd Schouten size_t len = uap->len;
4006f1e8c18SMatthew Dillon
401a1b5a895SEd Schouten name[0] = CTL_KERN;
402a1b5a895SEd Schouten name[1] = KERN_NISDOMAINNAME;
403ddf9d243SEd Schouten return (userland_sysctl(td, name, 2, uap->domainname, &len,
404ddf9d243SEd Schouten 1, 0, 0, 0, 0));
40526f9a767SRodney W. Grimes }
40626f9a767SRodney W. Grimes
407d2d3e875SBruce Evans #ifndef _SYS_SYSPROTO_H_
40826f9a767SRodney W. Grimes struct setdomainname_args {
40926f9a767SRodney W. Grimes char *domainname;
410f35a53bfSBruce Evans int len;
41126f9a767SRodney W. Grimes };
412d2d3e875SBruce Evans #endif
41326f9a767SRodney W. Grimes /* ARGSUSED */
41426f9a767SRodney W. Grimes int
freebsd4_setdomainname(struct thread * td,struct freebsd4_setdomainname_args * uap)415a1b5a895SEd Schouten freebsd4_setdomainname(struct thread *td,
416a1b5a895SEd Schouten struct freebsd4_setdomainname_args *uap)
41726f9a767SRodney W. Grimes {
418a1b5a895SEd Schouten int name[2];
41926f9a767SRodney W. Grimes
420a1b5a895SEd Schouten name[0] = CTL_KERN;
421a1b5a895SEd Schouten name[1] = KERN_NISDOMAINNAME;
422ddf9d243SEd Schouten return (userland_sysctl(td, name, 2, 0, 0, 0, uap->domainname,
423ddf9d243SEd Schouten uap->len, 0, 0));
42426f9a767SRodney W. Grimes }
425a1b5a895SEd Schouten #endif /* COMPAT_FREEBSD4 */
426