1/*- 2 * Copyright (c) 1994, 1995 Scott Bartram 3 * Copyright (c) 1994 Arne H Juul 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. The name of the author may not be used to endorse or promote products 12 * derived from this software without specific prior written permission 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#include <sys/cdefs.h>
|
27__FBSDID("$FreeBSD: head/sys/i386/ibcs2/ibcs2_socksys.c 164033 2006-11-06 13:42:10Z rwatson $");
|
27__FBSDID("$FreeBSD: head/sys/i386/ibcs2/ibcs2_socksys.c 180291 2008-07-05 13:10:10Z rwatson $"); |
28 29#include <sys/param.h> 30#include <sys/systm.h> 31#include <sys/sysproto.h> 32#include <sys/jail.h> 33#include <sys/kernel.h>
|
34#include <sys/lock.h> 35#include <sys/mutex.h> |
36#include <sys/sysctl.h> 37 38#include <i386/ibcs2/ibcs2_socksys.h> 39#include <i386/ibcs2/ibcs2_util.h> 40 41/* Local structures */ 42struct getipdomainname_args { 43 char *ipdomainname; 44 int len; 45}; 46 47struct setipdomainname_args { 48 char *ipdomainname; 49 int len; 50}; 51 52/* Local prototypes */ 53static int ibcs2_getipdomainname(struct thread *, 54 struct getipdomainname_args *); 55static int ibcs2_setipdomainname(struct thread *, 56 struct setipdomainname_args *); 57 58/* 59 * iBCS2 socksys calls. 60 */ 61 62int 63ibcs2_socksys(td, uap) 64 register struct thread *td; 65 register struct ibcs2_socksys_args *uap; 66{ 67 int error; 68 int realargs[7]; /* 1 for command, 6 for recvfrom */ 69 void *passargs; 70 71 /* 72 * SOCKET should only be legal on /dev/socksys. 73 * GETIPDOMAINNAME should only be legal on /dev/socksys ? 74 * The others are (and should be) only legal on sockets. 75 */ 76 77 if ((error = copyin(uap->argsp, (caddr_t)realargs, sizeof(realargs))) != 0) 78 return error; 79 DPRINTF(("ibcs2_socksys: %08x %08x %08x %08x %08x %08x %08x\n", 80 realargs[0], realargs[1], realargs[2], realargs[3], 81 realargs[4], realargs[5], realargs[6])); 82 83 passargs = (void *)(realargs + 1); 84 switch (realargs[0]) { 85 case SOCKSYS_ACCEPT: 86 return accept(td, passargs); 87 case SOCKSYS_BIND: 88 return bind(td, passargs); 89 case SOCKSYS_CONNECT: 90 return connect(td, passargs); 91 case SOCKSYS_GETPEERNAME: 92 return getpeername(td, passargs); 93 case SOCKSYS_GETSOCKNAME: 94 return getsockname(td, passargs); 95 case SOCKSYS_GETSOCKOPT: 96 return getsockopt(td, passargs); 97 case SOCKSYS_LISTEN: 98 return listen(td, passargs); 99 case SOCKSYS_RECV: 100 realargs[5] = realargs[6] = 0; 101 /* FALLTHROUGH */ 102 case SOCKSYS_RECVFROM: 103 return recvfrom(td, passargs); 104 case SOCKSYS_SEND: 105 realargs[5] = realargs[6] = 0; 106 /* FALLTHROUGH */ 107 case SOCKSYS_SENDTO: 108 return sendto(td, passargs); 109 case SOCKSYS_SETSOCKOPT: 110 return setsockopt(td, passargs); 111 case SOCKSYS_SHUTDOWN: 112 return shutdown(td, passargs); 113 case SOCKSYS_SOCKET: 114 return socket(td, passargs); 115 case SOCKSYS_SELECT: 116 return select(td, passargs); 117 case SOCKSYS_GETIPDOMAIN: 118 return ibcs2_getipdomainname(td, passargs); 119 case SOCKSYS_SETIPDOMAIN: 120 return ibcs2_setipdomainname(td, passargs); 121 case SOCKSYS_ADJTIME: 122 return adjtime(td, passargs); 123 case SOCKSYS_SETREUID: 124 return setreuid(td, passargs); 125 case SOCKSYS_SETREGID: 126 return setregid(td, passargs); 127 case SOCKSYS_GETTIME: 128 return gettimeofday(td, passargs); 129 case SOCKSYS_SETTIME: 130 return settimeofday(td, passargs); 131 case SOCKSYS_GETITIMER: 132 return getitimer(td, passargs); 133 case SOCKSYS_SETITIMER: 134 return setitimer(td, passargs); 135 136 default: 137 printf("socksys unknown %08x %08x %08x %08x %08x %08x %08x\n", 138 realargs[0], realargs[1], realargs[2], realargs[3], 139 realargs[4], realargs[5], realargs[6]); 140 return EINVAL; 141 } 142 /* NOTREACHED */ 143} 144 145/* ARGSUSED */ 146static int 147ibcs2_getipdomainname(td, uap) 148 struct thread *td; 149 struct getipdomainname_args *uap; 150{ 151 char hname[MAXHOSTNAMELEN], *dptr; 152 int len; 153 154 /* Get the domain name */ 155 getcredhostname(td->td_ucred, hname, sizeof(hname)); 156 157 dptr = index(hname, '.'); 158 if ( dptr ) 159 dptr++; 160 else 161 /* Make it effectively an empty string */ 162 dptr = hname + strlen(hname); 163 164 len = strlen(dptr) + 1; 165 if ((u_int)uap->len > len + 1) 166 uap->len = len + 1; 167 return (copyout((caddr_t)dptr, (caddr_t)uap->ipdomainname, uap->len)); 168} 169 170/* ARGSUSED */ 171static int 172ibcs2_setipdomainname(td, uap) 173 struct thread *td; 174 struct setipdomainname_args *uap; 175{ 176 char hname[MAXHOSTNAMELEN], *ptr; 177 int error, sctl[2], hlen; 178 179 /* W/out a hostname a domain-name is nonsense */
|
178 if ( strlen(hostname) == 0 )
|
180 mtx_lock(&hostname_mtx); 181 if ( strlen(hostname) == 0 ) { 182 mtx_unlock(&hostname_mtx); |
183 return EINVAL;
|
184 } |
185 186 /* Get the host's unqualified name (strip off the domain) */ 187 snprintf(hname, sizeof(hname), "%s", hostname);
|
188 mtx_unlock(&hostname_mtx); |
189 ptr = index(hname, '.'); 190 if ( ptr != NULL ) { 191 ptr++; 192 *ptr = '\0'; 193 } else { 194 if (strlcat(hname, ".", sizeof(hname)) >= sizeof(hname)) 195 return (EINVAL); 196 } 197 198 /* Set ptr to the end of the string so we can append to it */ 199 hlen = strlen(hname); 200 ptr = hname + hlen; 201 if ((u_int)uap->len > (sizeof (hname) - hlen - 1)) 202 return EINVAL; 203 204 /* Append the ipdomain to the end */ 205 error = copyinstr((caddr_t)uap->ipdomainname, ptr, uap->len, NULL); 206 if (error) 207 return (error); 208 209 /* 'sethostname' with the new information */ 210 sctl[0] = CTL_KERN; 211 sctl[1] = KERN_HOSTNAME; 212 hlen = strlen(hname) + 1; 213 return (kernel_sysctl(td, sctl, 2, 0, 0, hname, hlen, 0, 0)); 214}
|