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