2 * Copyright (c) 1994, 1995 Scott Bartram
3 * Copyright (c) 1994 Arne H Juul
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
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.
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/sysproto.h>
33 #include <sys/kernel.h>
35 #include <sys/mutex.h>
36 #include <sys/sysctl.h>
37 #include <sys/vimage.h>
39 #include <i386/ibcs2/ibcs2_socksys.h>
40 #include <i386/ibcs2/ibcs2_util.h>
42 /* Local structures */
43 struct getipdomainname_args {
48 struct setipdomainname_args {
53 /* Local prototypes */
54 static int ibcs2_getipdomainname(struct thread *,
55 struct getipdomainname_args *);
56 static int ibcs2_setipdomainname(struct thread *,
57 struct setipdomainname_args *);
60 * iBCS2 socksys calls.
64 ibcs2_socksys(td, uap)
65 register struct thread *td;
66 register struct ibcs2_socksys_args *uap;
69 int realargs[7]; /* 1 for command, 6 for recvfrom */
73 * SOCKET should only be legal on /dev/socksys.
74 * GETIPDOMAINNAME should only be legal on /dev/socksys ?
75 * The others are (and should be) only legal on sockets.
78 if ((error = copyin(uap->argsp, (caddr_t)realargs, sizeof(realargs))) != 0)
80 DPRINTF(("ibcs2_socksys: %08x %08x %08x %08x %08x %08x %08x\n",
81 realargs[0], realargs[1], realargs[2], realargs[3],
82 realargs[4], realargs[5], realargs[6]));
84 passargs = (void *)(realargs + 1);
85 switch (realargs[0]) {
87 return accept(td, passargs);
89 return bind(td, passargs);
91 return connect(td, passargs);
92 case SOCKSYS_GETPEERNAME:
93 return getpeername(td, passargs);
94 case SOCKSYS_GETSOCKNAME:
95 return getsockname(td, passargs);
96 case SOCKSYS_GETSOCKOPT:
97 return getsockopt(td, passargs);
99 return listen(td, passargs);
101 realargs[5] = realargs[6] = 0;
103 case SOCKSYS_RECVFROM:
104 return recvfrom(td, passargs);
106 realargs[5] = realargs[6] = 0;
109 return sendto(td, passargs);
110 case SOCKSYS_SETSOCKOPT:
111 return setsockopt(td, passargs);
112 case SOCKSYS_SHUTDOWN:
113 return shutdown(td, passargs);
115 return socket(td, passargs);
117 return select(td, passargs);
118 case SOCKSYS_GETIPDOMAIN:
119 return ibcs2_getipdomainname(td, passargs);
120 case SOCKSYS_SETIPDOMAIN:
121 return ibcs2_setipdomainname(td, passargs);
122 case SOCKSYS_ADJTIME:
123 return adjtime(td, passargs);
124 case SOCKSYS_SETREUID:
125 return setreuid(td, passargs);
126 case SOCKSYS_SETREGID:
127 return setregid(td, passargs);
128 case SOCKSYS_GETTIME:
129 return gettimeofday(td, passargs);
130 case SOCKSYS_SETTIME:
131 return settimeofday(td, passargs);
132 case SOCKSYS_GETITIMER:
133 return getitimer(td, passargs);
134 case SOCKSYS_SETITIMER:
135 return setitimer(td, passargs);
138 printf("socksys unknown %08x %08x %08x %08x %08x %08x %08x\n",
139 realargs[0], realargs[1], realargs[2], realargs[3],
140 realargs[4], realargs[5], realargs[6]);
148 ibcs2_getipdomainname(td, uap)
150 struct getipdomainname_args *uap;
152 char hname[MAXHOSTNAMELEN], *dptr;
155 /* Get the domain name */
156 getcredhostname(td->td_ucred, hname, sizeof(hname));
158 dptr = index(hname, '.');
162 /* Make it effectively an empty string */
163 dptr = hname + strlen(hname);
165 len = strlen(dptr) + 1;
166 if ((u_int)uap->len > len + 1)
168 return (copyout((caddr_t)dptr, (caddr_t)uap->ipdomainname, uap->len));
173 ibcs2_setipdomainname(td, uap)
175 struct setipdomainname_args *uap;
177 char hname[MAXHOSTNAMELEN], *ptr;
178 int error, sctl[2], hlen;
180 /* W/out a hostname a domain-name is nonsense */
181 mtx_lock(&hostname_mtx);
182 if ( strlen(V_hostname) == 0 ) {
183 mtx_unlock(&hostname_mtx);
187 /* Get the host's unqualified name (strip off the domain) */
188 snprintf(hname, sizeof(hname), "%s", V_hostname);
189 mtx_unlock(&hostname_mtx);
190 ptr = index(hname, '.');
195 if (strlcat(hname, ".", sizeof(hname)) >= sizeof(hname))
199 /* Set ptr to the end of the string so we can append to it */
200 hlen = strlen(hname);
202 if ((u_int)uap->len > (sizeof (hname) - hlen - 1))
205 /* Append the ipdomain to the end */
206 error = copyinstr((caddr_t)uap->ipdomainname, ptr, uap->len, NULL);
210 /* 'sethostname' with the new information */
212 sctl[1] = KERN_HOSTNAME;
213 hlen = strlen(hname) + 1;
214 return (kernel_sysctl(td, sctl, 2, 0, 0, hname, hlen, 0, 0));