"Fossies" - the Fresh Open Source Software Archive

Member "dhcpcd-9.4.1/src/privsep-sun.c" (22 Oct 2021, 3221 Bytes) of package /linux/misc/dhcpcd-9.4.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "privsep-sun.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 9.4.0_vs_9.4.1.

    1 /* SPDX-License-Identifier: BSD-2-Clause */
    2 /*
    3  * Privilege Separation for dhcpcd, Solaris driver
    4  * Copyright (c) 2006-2021 Roy Marples <roy@marples.name>
    5  * All rights reserved
    6 
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  *
   16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   26  * SUCH DAMAGE.
   27  */
   28 
   29 #include <sys/ioctl.h>
   30 
   31 #include <errno.h>
   32 #include <unistd.h>
   33 
   34 #include "dhcpcd.h"
   35 #include "logerr.h"
   36 #include "privsep.h"
   37 
   38 #warning Solaris privsep should compile but wont work,
   39 #warning no DLPI support, ioctl support need rework
   40 /* We should implement privileges(5) as well.
   41  * https://illumos.org/man/5/privileges */
   42 
   43 static ssize_t
   44 ps_root_doioctl6(unsigned long req, void *data, size_t len)
   45 {
   46     int s, err;
   47 
   48     s = socket(PF_INET6, SOCK_DGRAM, 0);
   49     if (s != -1)
   50         err = ioctl(s, req, data, len);
   51     else
   52         err = -1;
   53     if (err == -1)
   54         logerr(__func__);
   55     if (s != -1)
   56         close(s);
   57     return err;
   58 }
   59 
   60 static ssize_t
   61 ps_root_doroute(void *data, size_t len)
   62 {
   63     int s;
   64     ssize_t err;
   65 
   66     s = socket(PF_ROUTE, SOCK_RAW, 0);
   67     if (s != -1)
   68         err = write(s, data, len);
   69     else
   70         err = -1;
   71     if (err == -1)
   72         logerr(__func__);
   73     if (s != -1)
   74         close(s);
   75     return err;
   76 }
   77 
   78 ssize_t
   79 ps_root_os(struct ps_msghdr *psm, struct msghdr *msg,
   80     void **rdata, size_t *rlen)
   81 {
   82     struct iovec *iov = msg->msg_iov;
   83     void *data = iov->iov_base;
   84     size_t len = iov->iov_len;
   85     ssize_t err;
   86 
   87     switch (psm->ps_cmd) {
   88     case PS_IOCTL6:
   89         err = ps_root_doioctl6(psm->ps_flags, data, len);
   90     case PS_ROUTE:
   91         return ps_root_doroute(data, len);
   92     default:
   93         errno = ENOTSUP;
   94         return -1;
   95     }
   96 
   97     if (err != -1) {
   98         *rdata = data;
   99         *rlen = len;
  100     }
  101     return err;
  102 }
  103 
  104 ssize_t
  105 ps_root_ioctl6(struct dhcpcd_ctx *ctx, unsigned long request, void *data, size_t len)
  106 {
  107 
  108     if (ps_sendcmd(ctx, ctx->ps_root_fd, PS_IOCTL6,
  109         request, data, len) == -1)
  110         return -1;
  111     return ps_root_readerror(ctx, data, len);
  112 }
  113 
  114 ssize_t
  115 ps_root_route(struct dhcpcd_ctx *ctx, void *data, size_t len)
  116 {
  117 
  118     if (ps_sendcmd(ctx, ctx->ps_root_fd, PS_ROUTE, 0, data, len) == -1)
  119         return -1;
  120     return ps_root_readerror(ctx, data, len);
  121 }