The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/i386/ibcs2/ibcs2_socksys.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    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: releng/11.2/sys/i386/ibcs2/ibcs2_socksys.c 331722 2018-03-29 02:50:57Z eadler $");
   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/sysctl.h>
   35 
   36 #include <i386/ibcs2/ibcs2_socksys.h>
   37 #include <i386/ibcs2/ibcs2_util.h>
   38 
   39 /* Local structures */
   40 struct getipdomainname_args {
   41         char    *ipdomainname;
   42         int     len;
   43 };
   44 
   45 struct setipdomainname_args {
   46         char    *ipdomainname;
   47         int     len;
   48 };
   49 
   50 /* Local prototypes */
   51 static int ibcs2_getipdomainname(struct thread *,
   52                                       struct getipdomainname_args *);
   53 static int ibcs2_setipdomainname(struct thread *,
   54                                       struct setipdomainname_args *);
   55 
   56 /*
   57  * iBCS2 socksys calls.
   58  */
   59 
   60 int
   61 ibcs2_socksys(struct thread *td, struct ibcs2_socksys_args *uap)
   62 {
   63         int error;
   64         int realargs[7]; /* 1 for command, 6 for recvfrom */
   65         void *passargs;
   66 
   67         /*
   68          * SOCKET should only be legal on /dev/socksys.
   69          * GETIPDOMAINNAME should only be legal on /dev/socksys ?
   70          * The others are (and should be) only legal on sockets.
   71          */
   72 
   73         if ((error = copyin(uap->argsp, (caddr_t)realargs, sizeof(realargs))) != 0)
   74                 return error;
   75         DPRINTF(("ibcs2_socksys: %08x %08x %08x %08x %08x %08x %08x\n",
   76                realargs[0], realargs[1], realargs[2], realargs[3], 
   77                realargs[4], realargs[5], realargs[6]));
   78 
   79         passargs = (void *)(realargs + 1);
   80         switch (realargs[0]) {
   81         case SOCKSYS_ACCEPT:
   82                 return sys_accept(td, passargs);
   83         case SOCKSYS_BIND:
   84                 return sys_bind(td, passargs);
   85         case SOCKSYS_CONNECT:
   86                 return sys_connect(td, passargs);
   87         case SOCKSYS_GETPEERNAME:
   88                 return sys_getpeername(td, passargs);
   89         case SOCKSYS_GETSOCKNAME:
   90                 return sys_getsockname(td, passargs);
   91         case SOCKSYS_GETSOCKOPT:
   92                 return sys_getsockopt(td, passargs);
   93         case SOCKSYS_LISTEN:
   94                 return sys_listen(td, passargs);
   95         case SOCKSYS_RECV:
   96                 realargs[5] = realargs[6] = 0;
   97                 /* FALLTHROUGH */
   98         case SOCKSYS_RECVFROM:
   99                 return sys_recvfrom(td, passargs);
  100         case SOCKSYS_SEND:
  101                 realargs[5] = realargs[6] = 0;
  102                 /* FALLTHROUGH */
  103         case SOCKSYS_SENDTO:
  104                 return sys_sendto(td, passargs);
  105         case SOCKSYS_SETSOCKOPT:
  106                 return sys_setsockopt(td, passargs);
  107         case SOCKSYS_SHUTDOWN:
  108                 return sys_shutdown(td, passargs);
  109         case SOCKSYS_SOCKET:
  110                 return sys_socket(td, passargs);
  111         case SOCKSYS_SELECT:
  112                 return sys_select(td, passargs);
  113         case SOCKSYS_GETIPDOMAIN:
  114                 return ibcs2_getipdomainname(td, passargs);
  115         case SOCKSYS_SETIPDOMAIN:
  116                 return ibcs2_setipdomainname(td, passargs);
  117         case SOCKSYS_ADJTIME:
  118                 return sys_adjtime(td, passargs);
  119         case SOCKSYS_SETREUID:
  120                 return sys_setreuid(td, passargs);
  121         case SOCKSYS_SETREGID:
  122                 return sys_setregid(td, passargs);
  123         case SOCKSYS_GETTIME:
  124                 return sys_gettimeofday(td, passargs);
  125         case SOCKSYS_SETTIME:
  126                 return sys_settimeofday(td, passargs);
  127         case SOCKSYS_GETITIMER:
  128                 return sys_getitimer(td, passargs);
  129         case SOCKSYS_SETITIMER:
  130                 return sys_setitimer(td, passargs);
  131 
  132         default:
  133                 printf("socksys unknown %08x %08x %08x %08x %08x %08x %08x\n",
  134                        realargs[0], realargs[1], realargs[2], realargs[3], 
  135                        realargs[4], realargs[5], realargs[6]);
  136                 return EINVAL;
  137         }
  138         /* NOTREACHED */
  139 }
  140 
  141 /* ARGSUSED */
  142 static int
  143 ibcs2_getipdomainname(struct thread *td, struct getipdomainname_args *uap)
  144 {
  145         char hname[MAXHOSTNAMELEN], *dptr;
  146         int len;
  147 
  148         /* Get the domain name. */
  149         getcredhostname(td->td_ucred, hname, sizeof(hname));
  150 
  151         dptr = strchr(hname, '.');
  152         if ( dptr )
  153                 dptr++;
  154         else
  155                 /* Make it effectively an empty string */
  156                 dptr = hname + strlen(hname);
  157         
  158         len = strlen(dptr) + 1;
  159         if ((u_int)uap->len > len + 1)
  160                 uap->len = len + 1;
  161         return (copyout((caddr_t)dptr, (caddr_t)uap->ipdomainname, uap->len));
  162 }
  163 
  164 /* ARGSUSED */
  165 static int
  166 ibcs2_setipdomainname(struct thread *td, struct setipdomainname_args *uap)
  167 {
  168         char hname[MAXHOSTNAMELEN], *ptr;
  169         int error, sctl[2], hlen;
  170 
  171         /* Get the domain name */
  172         getcredhostname(td->td_ucred, hname, sizeof(hname));
  173 
  174         /* W/out a hostname a domain-name is nonsense */
  175         if ( strlen(hname) == 0 )
  176                 return EINVAL;
  177 
  178         /* Get the host's unqualified name (strip off the domain) */
  179         ptr = strchr(hname, '.');
  180         if ( ptr != NULL ) {
  181                 ptr++;
  182                 *ptr = '\0';
  183         } else {
  184                 if (strlcat(hname, ".", sizeof(hname)) >= sizeof(hname))
  185                         return (EINVAL);
  186         }
  187 
  188         /* Set ptr to the end of the string so we can append to it */
  189         hlen = strlen(hname);
  190         ptr = hname + hlen;
  191         if ((u_int)uap->len > (sizeof (hname) - hlen - 1))
  192                 return EINVAL;
  193 
  194         /* Append the ipdomain to the end */
  195         error = copyinstr((caddr_t)uap->ipdomainname, ptr, uap->len, NULL);
  196         if (error)
  197                 return (error);
  198 
  199         /* 'sethostname' with the new information */
  200         sctl[0] = CTL_KERN;
  201         sctl[1] = KERN_HOSTNAME;
  202         hlen = strlen(hname) + 1;
  203         return (kernel_sysctl(td, sctl, 2, 0, 0, hname, hlen, 0, 0));
  204 }

Cache object: 132444dfe1f72845adde6f4a2319b186


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.