xref: /freebsd/sys/kern/kern_xxx.c (revision 0c43d89a0d8e976ca494d4837f4c1f3734d2c300)
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  * $Id: kern_xxx.c,v 1.4 1994/08/08 00:30:04 wollman Exp $
35  */
36 
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/proc.h>
41 #include <sys/reboot.h>
42 #include <vm/vm.h>
43 #include <sys/sysctl.h>
44 #include <sys/utsname.h>
45 
46 struct reboot_args {
47 	int	opt;
48 };
49 /* ARGSUSED */
50 int
51 reboot(p, uap, retval)
52 	struct proc *p;
53 	struct reboot_args *uap;
54 	int *retval;
55 {
56 	int error;
57 
58 	if (error = suser(p->p_ucred, &p->p_acflag))
59 		return (error);
60 	boot(uap->opt);
61 	return (0);
62 }
63 
64 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
65 
66 struct gethostname_args {
67 	char	*hostname;
68 	u_int	len;
69 };
70 /* ARGSUSED */
71 int
72 ogethostname(p, uap, retval)
73 	struct proc *p;
74 	struct gethostname_args *uap;
75 	int *retval;
76 {
77 	int name;
78 
79 	name = KERN_HOSTNAME;
80 	return (kern_sysctl(&name, 1, uap->hostname, &uap->len, 0, 0));
81 }
82 
83 struct sethostname_args {
84 	char	*hostname;
85 	u_int	len;
86 };
87 /* ARGSUSED */
88 int
89 osethostname(p, uap, retval)
90 	struct proc *p;
91 	register struct sethostname_args *uap;
92 	int *retval;
93 {
94 	int name;
95 	int error;
96 
97 	if (error = suser(p->p_ucred, &p->p_acflag))
98 		return (error);
99 	name = KERN_HOSTNAME;
100 	return (kern_sysctl(&name, 1, 0, 0, uap->hostname, uap->len));
101 }
102 
103 struct gethostid_args {
104 	int	dummy;
105 };
106 /* ARGSUSED */
107 int
108 ogethostid(p, uap, retval)
109 	struct proc *p;
110 	struct gethostid_args *uap;
111 	int *retval;
112 {
113 
114 	*(long *)retval = hostid;
115 	return (0);
116 }
117 #endif /* COMPAT_43 || COMPAT_SUNOS */
118 
119 #ifdef COMPAT_43
120 struct sethostid_args {
121 	long	hostid;
122 };
123 /* ARGSUSED */
124 int
125 osethostid(p, uap, retval)
126 	struct proc *p;
127 	struct sethostid_args *uap;
128 	int *retval;
129 {
130 	int error;
131 
132 	if (error = suser(p->p_ucred, &p->p_acflag))
133 		return (error);
134 	hostid = uap->hostid;
135 	return (0);
136 }
137 
138 int
139 oquota()
140 {
141 
142 	return (ENOSYS);
143 }
144 #endif /* COMPAT_43 */
145 
146 void
147 shutdown_nice(void)
148 {
149 	register struct proc *p;
150 
151 	/* Send a signal to init(8) and have it shutdown the world */
152 	p = pfind(1);
153 	psignal(p, SIGINT);
154 
155 	return;
156 }
157 
158 
159 struct uname_args {
160         struct utsname  *name;
161 };
162 
163 /* ARGSUSED */
164 int
165 uname(p, uap, retval)
166 	struct proc *p;
167 	struct uname_args *uap;
168 	int *retval;
169 {
170 	int name;
171 	int len;
172 	int rtval;
173 	char *s, *us;
174 
175 	name = KERN_OSTYPE;
176 	len = sizeof uap->name->sysname;
177 	rtval = kern_sysctl(&name, 1, uap->name->sysname, &len, 0, 0, p);
178 	if( rtval) return rtval;
179 	subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0);
180 
181 	name = KERN_HOSTNAME;
182 	len = sizeof uap->name->nodename;
183 	rtval = kern_sysctl(&name, 1, uap->name->nodename, &len, 0, 0, p);
184 	if( rtval) return rtval;
185 	subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0);
186 
187 	name = KERN_OSRELEASE;
188 	len = sizeof uap->name->release;
189 	rtval = kern_sysctl(&name, 1, uap->name->release, &len, 0, 0, p);
190 	if( rtval) return rtval;
191 	subyte( uap->name->release + sizeof(uap->name->release) - 1, 0);
192 
193 /*
194 	name = KERN_VERSION;
195 	len = sizeof uap->name->version;
196 	rtval = kern_sysctl(&name, 1, uap->name->version, &len, 0, 0, p);
197 	if( rtval) return rtval;
198 	subyte( uap->name->version + sizeof(uap->name->version) - 1, 0);
199 */
200 
201 /*
202  * this stupid hackery to make the version field look like FreeBSD 1.1
203  */
204 	for(s = version; *s && *s != '#'; s++);
205 
206 	for(us = uap->name->version; *s && *s != ':'; s++) {
207 		rtval = subyte( us++, *s);
208 		if( rtval)
209 			return rtval;
210 	}
211 	rtval = subyte( us++, 0);
212 	if( rtval)
213 		return rtval;
214 
215 	name = HW_MACHINE;
216 	len = sizeof uap->name->machine;
217 	rtval = hw_sysctl(&name, 1, uap->name->machine, &len, 0, 0, p);
218 	if( rtval) return rtval;
219 	subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0);
220 
221 	return 0;
222 }
223 
224 struct getdomainname_args {
225         char    *domainname;
226         u_int   len;
227 };
228 
229 /* ARGSUSED */
230 int
231 getdomainname(p, uap, retval)
232         struct proc *p;
233         struct getdomainname_args *uap;
234         int *retval;
235 {
236 	if (uap->len > domainnamelen + 1)
237 		uap->len = domainnamelen + 1;
238 	return (copyout((caddr_t)domainname, (caddr_t)uap->domainname, uap->len));
239 }
240 
241 struct setdomainname_args {
242         char    *domainname;
243         u_int   len;
244 };
245 
246 /* ARGSUSED */
247 int
248 setdomainname(p, uap, retval)
249         struct proc *p;
250         struct setdomainname_args *uap;
251         int *retval;
252 {
253         int error;
254 
255         if (error = suser(p->p_ucred, &p->p_acflag))
256                 return (error);
257         if (uap->len > sizeof (domainname) - 1)
258                 return EINVAL;
259         domainnamelen = uap->len;
260         error = copyin((caddr_t)uap->domainname, domainname, uap->len);
261         domainname[domainnamelen] = 0;
262         return (error);
263 }
264 
265