kern_xxx.c (32e479705ac00771f4fffb87368e38c760129722) kern_xxx.c (6f1e8c186f9f87a6c385927f111f521470b00fff)
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

--- 27 unchanged lines hidden (view full) ---

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>
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

--- 27 unchanged lines hidden (view full) ---

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>
44#include <sys/sysctl.h>
45#include <sys/utsname.h>
46
47
48#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
49
50#ifndef _SYS_SYSPROTO_H_
51struct gethostname_args {
52 char *hostname;
53 u_int len;
54};
55#endif
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 */
56/* ARGSUSED */
57int
58ogethostname(p, uap)
59 struct proc *p;
60 struct gethostname_args *uap;
61{
62 int name[2];
61/* ARGSUSED */
62int
63ogethostname(p, uap)
64 struct proc *p;
65 struct gethostname_args *uap;
66{
67 int name[2];
68 int error;
63 size_t len = uap->len;
64
65 name[0] = CTL_KERN;
66 name[1] = KERN_HOSTNAME;
69 size_t len = uap->len;
70
71 name[0] = CTL_KERN;
72 name[1] = KERN_HOSTNAME;
67 return (userland_sysctl(p, name, 2, uap->hostname, &len,
68 1, 0, 0, 0));
73 mtx_lock(&Giant);
74 error = userland_sysctl(p, name, 2, uap->hostname, &len, 1, 0, 0, 0);
75 mtx_unlock(&Giant);
76 return(error);
69}
70
71#ifndef _SYS_SYSPROTO_H_
72struct sethostname_args {
73 char *hostname;
74 u_int len;
75};
76#endif
77}
78
79#ifndef _SYS_SYSPROTO_H_
80struct sethostname_args {
81 char *hostname;
82 u_int len;
83};
84#endif
85/*
86 * MPSAFE
87 */
77/* ARGSUSED */
78int
79osethostname(p, uap)
80 struct proc *p;
81 register struct sethostname_args *uap;
82{
83 int name[2];
84 int error;
85
86 name[0] = CTL_KERN;
87 name[1] = KERN_HOSTNAME;
88/* ARGSUSED */
89int
90osethostname(p, uap)
91 struct proc *p;
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;
88 if ((error = suser_xxx(0, p, PRISON_ROOT)))
89 return (error);
90 return (userland_sysctl(p, name, 2, 0, 0, 0,
91 uap->hostname, uap->len, 0));
99 mtx_lock(&Giant);
100 if ((error = suser_xxx(0, p, PRISON_ROOT)) == 0) {
101 error = userland_sysctl(p, name, 2, 0, 0, 0,
102 uap->hostname, uap->len, 0);
103 }
104 mtx_unlock(&Giant);
105 return (error);
92}
93
94#ifndef _SYS_SYSPROTO_H_
95struct ogethostid_args {
96 int dummy;
97};
98#endif
106}
107
108#ifndef _SYS_SYSPROTO_H_
109struct ogethostid_args {
110 int dummy;
111};
112#endif
113/*
114 * MPSAFE
115 */
99/* ARGSUSED */
100int
101ogethostid(p, uap)
102 struct proc *p;
103 struct ogethostid_args *uap;
104{
105
106 *(long *)(p->p_retval) = hostid;
107 return (0);
108}
109#endif /* COMPAT_43 || COMPAT_SUNOS */
110
111#ifdef COMPAT_43
112#ifndef _SYS_SYSPROTO_H_
113struct osethostid_args {
114 long hostid;
115};
116#endif
116/* ARGSUSED */
117int
118ogethostid(p, uap)
119 struct proc *p;
120 struct ogethostid_args *uap;
121{
122
123 *(long *)(p->p_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 */
117/* ARGSUSED */
118int
119osethostid(p, uap)
120 struct proc *p;
121 struct osethostid_args *uap;
122{
123 int error;
124
137/* ARGSUSED */
138int
139osethostid(p, uap)
140 struct proc *p;
141 struct osethostid_args *uap;
142{
143 int error;
144
125 if ((error = suser(p)))
126 return (error);
127 hostid = uap->hostid;
128 return (0);
145 mtx_lock(&Giant);
146 if ((error = suser(p)) == 0)
147 hostid = uap->hostid;
148 mtx_unlock(&Giant);
149 return (error);
129}
130
150}
151
152/*
153 * MPSAFE
154 */
131int
132oquota(p, uap)
133 struct proc *p;
134 struct oquota_args *uap;
135{
155int
156oquota(p, uap)
157 struct proc *p;
158 struct oquota_args *uap;
159{
136
137 return (ENOSYS);
138}
139#endif /* COMPAT_43 */
140
141/*
142 * This is the FreeBSD-1.1 compatable uname(2) interface. These
143 * days it is done in libc as a wrapper around a bunch of sysctl's.
144 * This must maintain the old 1.1 binary ABI.
145 */
146#if SYS_NMLN != 32
147#error "FreeBSD-1.1 uname syscall has been broken"
148#endif
149#ifndef _SYS_SYSPROTO_H_
150struct uname_args {
151 struct utsname *name;
152};
153#endif
154
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 */
155/* ARGSUSED */
156int
157uname(p, uap)
158 struct proc *p;
159 struct uname_args *uap;
160{
181/* ARGSUSED */
182int
183uname(p, uap)
184 struct proc *p;
185 struct uname_args *uap;
186{
161 int name[2], rtval;
187 int name[2], error;
162 size_t len;
163 char *s, *us;
164
165 name[0] = CTL_KERN;
166 name[1] = KERN_OSTYPE;
188 size_t len;
189 char *s, *us;
190
191 name[0] = CTL_KERN;
192 name[1] = KERN_OSTYPE;
167 len = sizeof uap->name->sysname;
168 rtval = userland_sysctl(p, name, 2, uap->name->sysname, &len,
193 len = sizeof (uap->name->sysname);
194 mtx_lock(&Giant);
195 error = userland_sysctl(p, name, 2, uap->name->sysname, &len,
169 1, 0, 0, 0);
196 1, 0, 0, 0);
170 if( rtval) return rtval;
197 if (error)
198 goto done2;
171 subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0);
172
173 name[1] = KERN_HOSTNAME;
174 len = sizeof uap->name->nodename;
199 subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0);
200
201 name[1] = KERN_HOSTNAME;
202 len = sizeof uap->name->nodename;
175 rtval = userland_sysctl(p, name, 2, uap->name->nodename, &len,
203 error = userland_sysctl(p, name, 2, uap->name->nodename, &len,
176 1, 0, 0, 0);
204 1, 0, 0, 0);
177 if( rtval) return rtval;
205 if (error)
206 goto done2;
178 subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0);
179
180 name[1] = KERN_OSRELEASE;
181 len = sizeof uap->name->release;
207 subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0);
208
209 name[1] = KERN_OSRELEASE;
210 len = sizeof uap->name->release;
182 rtval = userland_sysctl(p, name, 2, uap->name->release, &len,
211 error = userland_sysctl(p, name, 2, uap->name->release, &len,
183 1, 0, 0, 0);
212 1, 0, 0, 0);
184 if( rtval) return rtval;
213 if (error)
214 goto done2;
185 subyte( uap->name->release + sizeof(uap->name->release) - 1, 0);
186
187/*
188 name = KERN_VERSION;
189 len = sizeof uap->name->version;
215 subyte( uap->name->release + sizeof(uap->name->release) - 1, 0);
216
217/*
218 name = KERN_VERSION;
219 len = sizeof uap->name->version;
190 rtval = userland_sysctl(p, name, 2, uap->name->version, &len,
220 error = userland_sysctl(p, name, 2, uap->name->version, &len,
191 1, 0, 0, 0);
221 1, 0, 0, 0);
192 if( rtval) return rtval;
222 if (error)
223 goto done2;
193 subyte( uap->name->version + sizeof(uap->name->version) - 1, 0);
194*/
195
196/*
197 * this stupid hackery to make the version field look like FreeBSD 1.1
198 */
199 for(s = version; *s && *s != '#'; s++);
200
201 for(us = uap->name->version; *s && *s != ':'; s++) {
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++) {
202 rtval = subyte( us++, *s);
203 if( rtval)
204 return rtval;
233 error = subyte( us++, *s);
234 if (error)
235 goto done2;
205 }
236 }
206 rtval = subyte( us++, 0);
207 if( rtval)
208 return rtval;
237 error = subyte( us++, 0);
238 if (error)
239 goto done2;
209
210 name[0] = CTL_HW;
211 name[1] = HW_MACHINE;
212 len = sizeof uap->name->machine;
240
241 name[0] = CTL_HW;
242 name[1] = HW_MACHINE;
243 len = sizeof uap->name->machine;
213 rtval = userland_sysctl(p, name, 2, uap->name->machine, &len,
244 error = userland_sysctl(p, name, 2, uap->name->machine, &len,
214 1, 0, 0, 0);
245 1, 0, 0, 0);
215 if( rtval) return rtval;
246 if (error)
247 goto done2;
216 subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0);
248 subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0);
217
218 return 0;
249done2:
250 mtx_unlock(&Giant);
251 return (error);
219}
220
221#ifndef _SYS_SYSPROTO_H_
222struct getdomainname_args {
223 char *domainname;
224 int len;
225};
226#endif
227
252}
253
254#ifndef _SYS_SYSPROTO_H_
255struct getdomainname_args {
256 char *domainname;
257 int len;
258};
259#endif
260
261/*
262 * MPSAFE
263 */
228/* ARGSUSED */
229int
230getdomainname(p, uap)
231 struct proc *p;
232 struct getdomainname_args *uap;
233{
264/* ARGSUSED */
265int
266getdomainname(p, uap)
267 struct proc *p;
268 struct getdomainname_args *uap;
269{
234 int domainnamelen = strlen(domainname) + 1;
270 int domainnamelen;
271 int error;
272
273 mtx_lock(&Giant);
274 domainnamelen = strlen(domainname) + 1;
235 if ((u_int)uap->len > domainnamelen + 1)
236 uap->len = domainnamelen + 1;
275 if ((u_int)uap->len > domainnamelen + 1)
276 uap->len = domainnamelen + 1;
237 return (copyout((caddr_t)domainname, (caddr_t)uap->domainname, uap->len));
277 error = copyout((caddr_t)domainname, (caddr_t)uap->domainname, uap->len);
278 mtx_unlock(&Giant);
279 return (error);
238}
239
240#ifndef _SYS_SYSPROTO_H_
241struct setdomainname_args {
242 char *domainname;
243 int len;
244};
245#endif
246
280}
281
282#ifndef _SYS_SYSPROTO_H_
283struct setdomainname_args {
284 char *domainname;
285 int len;
286};
287#endif
288
289/*
290 * MPSAFE
291 */
247/* ARGSUSED */
248int
249setdomainname(p, uap)
250 struct proc *p;
251 struct setdomainname_args *uap;
252{
253 int error, domainnamelen;
254
292/* ARGSUSED */
293int
294setdomainname(p, uap)
295 struct proc *p;
296 struct setdomainname_args *uap;
297{
298 int error, domainnamelen;
299
300 mtx_lock(&Giant);
255 if ((error = suser(p)))
301 if ((error = suser(p)))
256 return (error);
257 if ((u_int)uap->len > sizeof (domainname) - 1)
258 return EINVAL;
302 goto done2;
303 if ((u_int)uap->len > sizeof (domainname) - 1) {
304 error = EINVAL;
305 goto done2;
306 }
259 domainnamelen = uap->len;
260 error = copyin((caddr_t)uap->domainname, domainname, uap->len);
261 domainname[domainnamelen] = 0;
307 domainnamelen = uap->len;
308 error = copyin((caddr_t)uap->domainname, domainname, uap->len);
309 domainname[domainnamelen] = 0;
310done2:
311 mtx_unlock(&Giant);
262 return (error);
263}
264
312 return (error);
313}
314