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