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