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