2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 1994, 1995 Scott Bartram
5 * Copyright (c) 1994 Arne H Juul
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/sysproto.h>
35 #include <sys/kernel.h>
36 #include <sys/sysctl.h>
38 #include <i386/ibcs2/ibcs2_socksys.h>
39 #include <i386/ibcs2/ibcs2_util.h>
41 /* Local structures */
42 struct getipdomainname_args {
47 struct setipdomainname_args {
52 /* Local prototypes */
53 static int ibcs2_getipdomainname(struct thread *,
54 struct getipdomainname_args *);
55 static int ibcs2_setipdomainname(struct thread *,
56 struct setipdomainname_args *);
59 * iBCS2 socksys calls.
63 ibcs2_socksys(struct thread *td, struct ibcs2_socksys_args *uap)
66 int realargs[7]; /* 1 for command, 6 for recvfrom */
70 * SOCKET should only be legal on /dev/socksys.
71 * GETIPDOMAINNAME should only be legal on /dev/socksys ?
72 * The others are (and should be) only legal on sockets.
75 if ((error = copyin(uap->argsp, (caddr_t)realargs, sizeof(realargs))) != 0)
77 DPRINTF(("ibcs2_socksys: %08x %08x %08x %08x %08x %08x %08x\n",
78 realargs[0], realargs[1], realargs[2], realargs[3],
79 realargs[4], realargs[5], realargs[6]));
81 passargs = (void *)(realargs + 1);
82 switch (realargs[0]) {
84 return sys_accept(td, passargs);
86 return sys_bind(td, passargs);
88 return sys_connect(td, passargs);
89 case SOCKSYS_GETPEERNAME:
90 return sys_getpeername(td, passargs);
91 case SOCKSYS_GETSOCKNAME:
92 return sys_getsockname(td, passargs);
93 case SOCKSYS_GETSOCKOPT:
94 return sys_getsockopt(td, passargs);
96 return sys_listen(td, passargs);
98 realargs[5] = realargs[6] = 0;
100 case SOCKSYS_RECVFROM:
101 return sys_recvfrom(td, passargs);
103 realargs[5] = realargs[6] = 0;
106 return sys_sendto(td, passargs);
107 case SOCKSYS_SETSOCKOPT:
108 return sys_setsockopt(td, passargs);
109 case SOCKSYS_SHUTDOWN:
110 return sys_shutdown(td, passargs);
112 return sys_socket(td, passargs);
114 return sys_select(td, passargs);
115 case SOCKSYS_GETIPDOMAIN:
116 return ibcs2_getipdomainname(td, passargs);
117 case SOCKSYS_SETIPDOMAIN:
118 return ibcs2_setipdomainname(td, passargs);
119 case SOCKSYS_ADJTIME:
120 return sys_adjtime(td, passargs);
121 case SOCKSYS_SETREUID:
122 return sys_setreuid(td, passargs);
123 case SOCKSYS_SETREGID:
124 return sys_setregid(td, passargs);
125 case SOCKSYS_GETTIME:
126 return sys_gettimeofday(td, passargs);
127 case SOCKSYS_SETTIME:
128 return sys_settimeofday(td, passargs);
129 case SOCKSYS_GETITIMER:
130 return sys_getitimer(td, passargs);
131 case SOCKSYS_SETITIMER:
132 return sys_setitimer(td, passargs);
135 printf("socksys unknown %08x %08x %08x %08x %08x %08x %08x\n",
136 realargs[0], realargs[1], realargs[2], realargs[3],
137 realargs[4], realargs[5], realargs[6]);
145 ibcs2_getipdomainname(struct thread *td, struct getipdomainname_args *uap)
147 char hname[MAXHOSTNAMELEN], *dptr;
150 /* Get the domain name. */
151 getcredhostname(td->td_ucred, hname, sizeof(hname));
153 dptr = strchr(hname, '.');
157 /* Make it effectively an empty string */
158 dptr = hname + strlen(hname);
160 len = strlen(dptr) + 1;
161 if ((u_int)uap->len > len + 1)
163 return (copyout((caddr_t)dptr, (caddr_t)uap->ipdomainname, uap->len));
168 ibcs2_setipdomainname(struct thread *td, struct setipdomainname_args *uap)
170 char hname[MAXHOSTNAMELEN], *ptr;
171 int error, sctl[2], hlen;
173 /* Get the domain name */
174 getcredhostname(td->td_ucred, hname, sizeof(hname));
176 /* W/out a hostname a domain-name is nonsense */
177 if ( strlen(hname) == 0 )
180 /* Get the host's unqualified name (strip off the domain) */
181 ptr = strchr(hname, '.');
186 if (strlcat(hname, ".", sizeof(hname)) >= sizeof(hname))
190 /* Set ptr to the end of the string so we can append to it */
191 hlen = strlen(hname);
193 if ((u_int)uap->len > (sizeof (hname) - hlen - 1))
196 /* Append the ipdomain to the end */
197 error = copyinstr((caddr_t)uap->ipdomainname, ptr, uap->len, NULL);
201 /* 'sethostname' with the new information */
203 sctl[1] = KERN_HOSTNAME;
204 hlen = strlen(hname) + 1;
205 return (kernel_sysctl(td, sctl, 2, 0, 0, hname, hlen, 0, 0));