kern_xxx.c revision 83366
1/*
2 * Copyright (c) 1982, 1986, 1989, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *	This product includes software developed by the University of
16 *	California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 *    may be used to endorse or promote products derived from this software
19 *    without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 *	@(#)kern_xxx.c	8.2 (Berkeley) 11/14/93
34 * $FreeBSD: head/sys/kern/kern_xxx.c 83366 2001-09-12 08:38:13Z julian $
35 */
36
37#include "opt_compat.h"
38
39#include <sys/param.h>
40#include <sys/systm.h>
41#include <sys/sysproto.h>
42#include <sys/kernel.h>
43#include <sys/proc.h>
44#include <sys/lock.h>
45#include <sys/mutex.h>
46#include <sys/sysctl.h>
47#include <sys/utsname.h>
48
49
50#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
51
52#ifndef _SYS_SYSPROTO_H_
53struct gethostname_args {
54	char	*hostname;
55	u_int	len;
56};
57#endif
58/*
59 * MPSAFE
60 */
61/* ARGSUSED */
62int
63ogethostname(td, uap)
64	struct thread *td;
65	struct gethostname_args *uap;
66{
67	int name[2];
68	int error;
69	size_t len = uap->len;
70
71	name[0] = CTL_KERN;
72	name[1] = KERN_HOSTNAME;
73	mtx_lock(&Giant);
74	error = userland_sysctl(td, name, 2, uap->hostname, &len, 1, 0, 0, 0);
75	mtx_unlock(&Giant);
76	return(error);
77}
78
79#ifndef _SYS_SYSPROTO_H_
80struct sethostname_args {
81	char	*hostname;
82	u_int	len;
83};
84#endif
85/*
86 * MPSAFE
87 */
88/* ARGSUSED */
89int
90osethostname(td, uap)
91	struct thread *td;
92	register struct sethostname_args *uap;
93{
94	int name[2];
95	int error;
96
97	name[0] = CTL_KERN;
98	name[1] = KERN_HOSTNAME;
99	mtx_lock(&Giant);
100	if ((error = suser_xxx(0, td->td_proc, PRISON_ROOT)) == 0) {
101		error = userland_sysctl(td, name, 2, 0, 0, 0,
102		    uap->hostname, uap->len, 0);
103	}
104	mtx_unlock(&Giant);
105	return (error);
106}
107
108#ifndef _SYS_SYSPROTO_H_
109struct ogethostid_args {
110	int	dummy;
111};
112#endif
113/*
114 * MPSAFE
115 */
116/* ARGSUSED */
117int
118ogethostid(td, uap)
119	struct thread *td;
120	struct ogethostid_args *uap;
121{
122
123	*(long *)(td->td_retval) = hostid;
124	return (0);
125}
126#endif /* COMPAT_43 || COMPAT_SUNOS */
127
128#ifdef COMPAT_43
129#ifndef _SYS_SYSPROTO_H_
130struct osethostid_args {
131	long	hostid;
132};
133#endif
134/*
135 * MPSAFE
136 */
137/* ARGSUSED */
138int
139osethostid(td, uap)
140	struct thread *td;
141	struct osethostid_args *uap;
142{
143	int error;
144
145	mtx_lock(&Giant);
146	if ((error = suser_td(td)))
147		hostid = uap->hostid;
148	mtx_unlock(&Giant);
149	return (error);
150}
151
152/*
153 * MPSAFE
154 */
155int
156oquota(td, uap)
157	struct thread *td;
158	struct oquota_args *uap;
159{
160	return (ENOSYS);
161}
162#endif /* COMPAT_43 */
163
164/*
165 * This is the FreeBSD-1.1 compatable uname(2) interface.  These
166 * days it is done in libc as a wrapper around a bunch of sysctl's.
167 * This must maintain the old 1.1 binary ABI.
168 */
169#if SYS_NMLN != 32
170#error "FreeBSD-1.1 uname syscall has been broken"
171#endif
172#ifndef _SYS_SYSPROTO_H_
173struct uname_args {
174        struct utsname  *name;
175};
176#endif
177
178/*
179 * MPSAFE
180 */
181/* ARGSUSED */
182int
183uname(td, uap)
184	struct thread *td;
185	struct uname_args *uap;
186{
187	int name[2], error;
188	size_t len;
189	char *s, *us;
190
191	name[0] = CTL_KERN;
192	name[1] = KERN_OSTYPE;
193	len = sizeof (uap->name->sysname);
194	mtx_lock(&Giant);
195	error = userland_sysctl(td, name, 2, uap->name->sysname, &len,
196		1, 0, 0, 0);
197	if (error)
198		goto done2;
199	subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0);
200
201	name[1] = KERN_HOSTNAME;
202	len = sizeof uap->name->nodename;
203	error = userland_sysctl(td, name, 2, uap->name->nodename, &len,
204		1, 0, 0, 0);
205	if (error)
206		goto done2;
207	subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0);
208
209	name[1] = KERN_OSRELEASE;
210	len = sizeof uap->name->release;
211	error = userland_sysctl(td, name, 2, uap->name->release, &len,
212		1, 0, 0, 0);
213	if (error)
214		goto done2;
215	subyte( uap->name->release + sizeof(uap->name->release) - 1, 0);
216
217/*
218	name = KERN_VERSION;
219	len = sizeof uap->name->version;
220	error = userland_sysctl(td, name, 2, uap->name->version, &len,
221		1, 0, 0, 0);
222	if (error)
223		goto done2;
224	subyte( uap->name->version + sizeof(uap->name->version) - 1, 0);
225*/
226
227/*
228 * this stupid hackery to make the version field look like FreeBSD 1.1
229 */
230	for(s = version; *s && *s != '#'; s++);
231
232	for(us = uap->name->version; *s && *s != ':'; s++) {
233		error = subyte( us++, *s);
234		if (error)
235			goto done2;
236	}
237	error = subyte( us++, 0);
238	if (error)
239		goto done2;
240
241	name[0] = CTL_HW;
242	name[1] = HW_MACHINE;
243	len = sizeof uap->name->machine;
244	error = userland_sysctl(td, name, 2, uap->name->machine, &len,
245		1, 0, 0, 0);
246	if (error)
247		goto done2;
248	subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0);
249done2:
250	mtx_unlock(&Giant);
251	return (error);
252}
253
254#ifndef _SYS_SYSPROTO_H_
255struct getdomainname_args {
256        char    *domainname;
257        int     len;
258};
259#endif
260
261/*
262 * MPSAFE
263 */
264/* ARGSUSED */
265int
266getdomainname(td, uap)
267        struct thread *td;
268        struct getdomainname_args *uap;
269{
270	int domainnamelen;
271	int error;
272
273	mtx_lock(&Giant);
274	domainnamelen = strlen(domainname) + 1;
275	if ((u_int)uap->len > domainnamelen + 1)
276		uap->len = domainnamelen + 1;
277	error = copyout((caddr_t)domainname, (caddr_t)uap->domainname, uap->len);
278	mtx_unlock(&Giant);
279	return (error);
280}
281
282#ifndef _SYS_SYSPROTO_H_
283struct setdomainname_args {
284        char    *domainname;
285        int     len;
286};
287#endif
288
289/*
290 * MPSAFE
291 */
292/* ARGSUSED */
293int
294setdomainname(td, uap)
295        struct thread *td;
296        struct setdomainname_args *uap;
297{
298        int error, domainnamelen;
299
300	mtx_lock(&Giant);
301        if ((error = suser_td(td)))
302		goto done2;
303        if ((u_int)uap->len > sizeof (domainname) - 1) {
304		error = EINVAL;
305		goto done2;
306	}
307        domainnamelen = uap->len;
308        error = copyin((caddr_t)uap->domainname, domainname, uap->len);
309        domainname[domainnamelen] = 0;
310done2:
311	mtx_unlock(&Giant);
312        return (error);
313}
314
315