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-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
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/param.h>
   27 #include <sys/systm.h>
   28 #include <sys/proc.h>
   29 #include <sys/file.h>
   30 #include <sys/filedesc.h>
   31 #include <sys/ioctl.h>
   32 #include <sys/termios.h>
   33 #include <sys/tty.h>
   34 #include <sys/socket.h>
   35 #include <sys/ioctl.h>
   36 #include <sys/sysproto.h>
   37 #include <net/if.h>
   38 #include <sys/kernel.h>
   39 #include <sys/sysctl.h>
   40 
   41 #include <i386/ibcs2/ibcs2_socksys.h>
   42 #include <i386/ibcs2/ibcs2_util.h>
   43 
   44 /* Local structures */
   45 struct getipdomainname_args {
   46         char    *ipdomainname;
   47         int     len;
   48 };
   49 
   50 struct setipdomainname_args {
   51         char    *ipdomainname;
   52         int     len;
   53 };
   54 
   55 /* Local prototypes */
   56 static int ibcs2_getipdomainname __P((struct proc *,
   57                                       struct getipdomainname_args *, int *));
   58 static int ibcs2_setipdomainname __P((struct proc *,
   59                                       struct setipdomainname_args *, int *));
   60 
   61 /*
   62  * iBCS2 socksys calls.
   63  */
   64 
   65 int
   66 ibcs2_socksys(p, uap, retval)
   67         register struct proc *p;
   68         register struct ibcs2_socksys_args *uap;
   69         int *retval;
   70 {
   71         int error;
   72         int realargs[7]; /* 1 for command, 6 for recvfrom */
   73         void *passargs;
   74 
   75         /*
   76          * SOCKET should only be legal on /dev/socksys.
   77          * GETIPDOMAINNAME should only be legal on /dev/socksys ?
   78          * The others are (and should be) only legal on sockets.
   79          */
   80 
   81         if (error = copyin(uap->argsp, (caddr_t)realargs, sizeof(realargs)))
   82                 return error;
   83         DPRINTF(("ibcs2_socksys: %08x %08x %08x %08x %08x %08x %08x\n",
   84                realargs[0], realargs[1], realargs[2], realargs[3], 
   85                realargs[4], realargs[5], realargs[6]));
   86 
   87         passargs = (void *)(realargs + 1);
   88         switch (realargs[0]) {
   89         case SOCKSYS_ACCEPT:
   90                 return accept(p, passargs, retval);
   91         case SOCKSYS_BIND:
   92                 return bind(p, passargs, retval);
   93         case SOCKSYS_CONNECT:
   94                 return connect(p, passargs, retval);
   95         case SOCKSYS_GETPEERNAME:
   96                 return getpeername(p, passargs, retval);
   97         case SOCKSYS_GETSOCKNAME:
   98                 return getsockname(p, passargs, retval);
   99         case SOCKSYS_GETSOCKOPT:
  100                 return getsockopt(p, passargs, retval);
  101         case SOCKSYS_LISTEN:
  102                 return listen(p, passargs, retval);
  103         case SOCKSYS_RECV:
  104                 realargs[5] = realargs[6] = 0;
  105                 /* FALLTHROUGH */
  106         case SOCKSYS_RECVFROM:
  107                 return recvfrom(p, passargs, retval);
  108         case SOCKSYS_SEND:
  109                 realargs[5] = realargs[6] = 0;
  110                 /* FALLTHROUGH */
  111         case SOCKSYS_SENDTO:
  112                 return sendto(p, passargs, retval);
  113         case SOCKSYS_SETSOCKOPT:
  114                 return setsockopt(p, passargs, retval);
  115         case SOCKSYS_SHUTDOWN:
  116                 return shutdown(p, passargs, retval);
  117         case SOCKSYS_SOCKET:
  118                 return socket(p, passargs, retval);
  119         case SOCKSYS_SELECT:
  120                 return select(p, passargs, retval);
  121         case SOCKSYS_GETIPDOMAIN:
  122                 return ibcs2_getipdomainname(p, passargs, retval);
  123         case SOCKSYS_SETIPDOMAIN:
  124                 return ibcs2_setipdomainname(p, passargs, retval);
  125         case SOCKSYS_ADJTIME:
  126                 return adjtime(p, passargs, retval);
  127         case SOCKSYS_SETREUID:
  128                 return setreuid(p, passargs, retval);
  129         case SOCKSYS_SETREGID:
  130                 return setregid(p, passargs, retval);
  131         case SOCKSYS_GETTIME:
  132                 return gettimeofday(p, passargs, retval);
  133         case SOCKSYS_SETTIME:
  134                 return settimeofday(p, passargs, retval);
  135         case SOCKSYS_GETITIMER:
  136                 return getitimer(p, passargs, retval);
  137         case SOCKSYS_SETITIMER:
  138                 return setitimer(p, passargs, retval);
  139 
  140         default:
  141                 printf("socksys unknown %08x %08x %08x %08x %08x %08x %08x\n",
  142                        realargs[0], realargs[1], realargs[2], realargs[3], 
  143                        realargs[4], realargs[5], realargs[6]);
  144                 return EINVAL;
  145         }
  146         /* NOTREACHED */
  147 }
  148 
  149 /* ARGSUSED */
  150 static int
  151 ibcs2_getipdomainname(p, uap, retval)
  152         struct proc *p;
  153         struct getipdomainname_args *uap;
  154         int *retval;
  155 {
  156         char hname[MAXHOSTNAMELEN], *dptr;
  157         int len;
  158 
  159         /* Get the domain name */
  160         strcpy(hname, hostname);
  161         dptr = index(hname, '.');
  162         if ( dptr )
  163                 dptr++;
  164         else
  165                 /* Make it effectively an empty string */
  166                 dptr = hname + strlen(hname);
  167         
  168         len = strlen(dptr) + 1;
  169         if ((u_int)uap->len > len + 1)
  170                 uap->len = len + 1;
  171         return (copyout((caddr_t)dptr, (caddr_t)uap->ipdomainname, uap->len));
  172 }
  173 
  174 /* ARGSUSED */
  175 static int
  176 ibcs2_setipdomainname(p, uap, retval)
  177         struct proc *p;
  178         struct setipdomainname_args *uap;
  179         int *retval;
  180 {
  181         char hname[MAXHOSTNAMELEN], *ptr;
  182         int error, sctl[2], hlen;
  183 
  184         if ((error = suser(p->p_ucred, &p->p_acflag)))
  185                 return (error);
  186 
  187         /* W/out a hostname a domain-name is nonsense */
  188         if ( strlen(hostname) == 0 )
  189                 return EINVAL;
  190 
  191         /* Get the host's unqualified name (strip off the domain) */
  192         strcpy(hname, hostname);
  193         ptr = index(hname, '.');
  194         if ( ptr != NULL ) {
  195                 ptr++;
  196                 *ptr = '\0';
  197         } else
  198                 strcat(hname, ".");
  199 
  200         /* Set ptr to the end of the string so we can append to it */
  201         hlen = strlen(hname);
  202         ptr = hname + hlen;
  203         if ((u_int)uap->len > (sizeof (hname) - hlen - 1))
  204                 return EINVAL;
  205 
  206         /* Append the ipdomain to the end */
  207         error = copyin((caddr_t)uap->ipdomainname, ptr, uap->len);
  208         if (error)
  209                 return (error);
  210 
  211         /* 'sethostname' with the new information */
  212         sctl[0] = CTL_KERN;
  213         sctl[1] = KERN_HOSTNAME;
  214         hlen = strlen(hname) + 1;
  215         return (kernel_sysctl(p, sctl, 2, 0, 0, hname, hlen, 0));
  216 }

Cache object: e5762984ad17dd0820e5ba119d3456bd


[ 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.