]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/sys-osf.c
Remove the requirement that redistributions in binary form reproduce
[ppp.git] / pppd / sys-osf.c
index 30930b25743cccf6d7c78efe366dc5aac111a751..e2f42184eb623a9fcfb1e192d8a63e360d8369cc 100644 (file)
@@ -1,34 +1,76 @@
 /*
  * System-dependent procedures for pppd under Digital UNIX (OSF/1).
  *
- * Copyright (c) 1994 The Australian National University.
- * All rights reserved.
+ * Copyright (c) 1994-2002 Paul Mackerras. All rights reserved.
  *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation is hereby granted, provided that the above copyright
- * notice appears in all copies.  This software is provided without any
- * warranty, express or implied. The Australian National University
- * makes no representations about the suitability of this software for
- * any purpose.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
  *
- * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
- * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
- * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
- * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
  *
- * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
- * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
- * OR MODIFICATIONS.
+ * 2. The name(s) of the authors of this software must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission.
+ *
+ * 3. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by Paul Mackerras
+ *     <paulus@samba.org>".
+ *
+ * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Derived from main.c and pppd.h, which are:
+ *
+ * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The name "Carnegie Mellon University" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For permission or any legal
+ *    details, please contact
+ *      Office of Technology Transfer
+ *      Carnegie Mellon University
+ *      5000 Forbes Avenue
+ *      Pittsburgh, PA  15213-3890
+ *      (412) 268-4387, fax: (412) 268-7395
+ *      tech-transfer@andrew.cmu.edu
+ *
+ * 4. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by Computing Services
+ *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
+ *
+ * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
+ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#ifndef lint
-static char rcsid[] = "$Id: sys-osf.c,v 1.21 1999/03/19 01:29:46 paulus Exp $";
-#endif
+#define RCSID  "$Id: sys-osf.c,v 1.33 2004/11/04 10:02:26 paulus Exp $"
 
+#include <syslog.h>
 #include <stdio.h>
 #include <stddef.h>
 #include <stdlib.h>
@@ -61,6 +103,8 @@ static char rcsid[] = "$Id: sys-osf.c,v 1.21 1999/03/19 01:29:46 paulus Exp $";
 
 #include "pppd.h"
 
+static const char rcsid[] = RCSID;
+
 static int     pppfd;
 static int     fdmuxid = -1;
 static int     iffd;
@@ -200,7 +244,7 @@ sys_check_options()
     return 1;
 }
 
-
+#if 0
 /*
  * daemon - Detach us from controlling terminal session.
  */
@@ -224,6 +268,7 @@ daemon(nochdir, noclose)
     }
     return 0;
 }
+#endif
 
 /*
  * ppp_available - check whether the system has any ppp interfaces
@@ -374,6 +419,13 @@ establish_ppp(fd)
             if (i != fd && i != sockfd)
                 close(i);
         closed_stdio = 1;
+       /* make sure 0, 1, 2 are open to /dev/null */
+       while ((i = open("/dev/null", O_RDWR)) >= 0) {
+           if (i > 2) {
+               close(i);
+               break;
+           }
+       }
     }
 
     /*
@@ -754,7 +806,8 @@ wait_input(timo)
 /*
  * add_fd - add an fd to the set that wait_input waits for.
  */
-void add_fd(int fd)
+void add_fd(fd)
+    int fd;
 {
     int n;
 
@@ -772,7 +825,8 @@ void add_fd(int fd)
 /*
  * remove_fd - remove an fd from the set that wait_input waits for.
  */
-void remove_fd(int fd)
+void remove_fd(fd)
+    int fd;
 {
     int n;
 
@@ -799,11 +853,13 @@ wait_loop_output(timo)
     wait_input(timo);
 }
 
+#endif
+
 /*
  * wait_time - wait for a given length of time or until a
- * signal is received.
+ * signal is received. Called by ccp_test
  */
-void
+static void
 wait_time(timo)
     struct timeval *timo;
 {
@@ -813,7 +869,6 @@ wait_time(timo)
     if (n < 0 && errno != EINTR)
        fatal("select: %m");
 }
-#endif
 
 /*
  * read_packet - get a PPP packet from the serial device.
@@ -834,7 +889,7 @@ read_packet(buf)
        flags = 0;
        len = getmsg(pppfd, &ctrl, &data, &flags);
        if (len < 0) {
-           if (errno = EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
+           if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
                return -1;
            fatal("Error reading packet: %m");
        }
@@ -1009,6 +1064,25 @@ get_idle_time(u, ip)
     return strioctl(pppfd, PPPIO_GIDLE, ip, 0, sizeof(struct ppp_idle)) >= 0;
 }
 
+/*
+ * get_ppp_stats - return statistics for the link.
+ */
+int
+get_ppp_stats(u, stats)
+    int u;
+    struct pppd_stats *stats;
+{
+    struct ppp_stats s;
+
+    if (strioctl(pppfd, PPPIO_GETSTAT, &s, 0, sizeof(s)) < 0) {
+       error("Couldn't get link statistics: %m");
+       return 0;
+    }
+    stats->bytes_in = s.p.ppp_ibytes;
+    stats->bytes_out = s.p.ppp_obytes;
+    return 1;
+}
+
 
 /*
  * ccp_fatal_error - returns 1 if decompression was disabled as a
@@ -1091,6 +1165,7 @@ sifdown(u)
 {
     struct ifreq ifr;
 
+    bzero(&ifr, sizeof(ifr));
     strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
     if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0) {
        error("Couldn't mark interface down (get): %m");
@@ -1183,7 +1258,8 @@ sifaddr(u, o, h, m)
         ret = 0;
     }
 
-    ifr.ifr_metric = link_mtu;
+    ifr.ifr_data = (caddr_t)&link_mtu;
+
     if (ioctl(sockfd, SIOCSIPMTU, &ifr) < 0) {
        error("Couldn't set IP MTU: %m");
         ret = 0;
@@ -1413,9 +1489,9 @@ logwtmp(line, name, host)
     if ((fd = open(WTMPFILE, O_WRONLY|O_APPEND, 0)) < 0)
        return;
     if (!fstat(fd, &buf)) {
-       strlcpy(ut.ut_line, line, sizeof(ut.ut_line));
-       strlcpy(ut.ut_name, name, sizeof(ut.ut_name));
-       strlcpy(ut.ut_host, host, sizeof(ut.ut_host));
+       strncpy(ut.ut_line, line, sizeof(ut.ut_line));
+       strncpy(ut.ut_name, name, sizeof(ut.ut_name));
+       strncpy(ut.ut_host, host, sizeof(ut.ut_host));
        (void)time(&ut.ut_time);
        if (write(fd, (char *)&ut, sizeof(struct utmp)) != sizeof(struct utmp))
            (void)ftruncate(fd, buf.st_size);
@@ -1502,61 +1578,7 @@ GetMask(addr)
  */
 int have_route_to(u_int32_t addr)
 {
-       char buf[sizeof(struct rt_msghdr) + (sizeof(struct sockaddr_in))];
-       int status;
-       int s, n;
-       struct rt_msghdr *rtm;
-       struct sockaddr_in *sin;
-       int msglen = sizeof(*rtm) + (sizeof(*sin));
-       char *cp;
-       char msg[2048];
-
-       rtm = (struct rt_msghdr *)buf;
-       memset(rtm, 0, msglen);
-       rtm->rtm_msglen = msglen;
-       rtm->rtm_version = RTM_VERSION;
-       rtm->rtm_type = RTM_GET;
-       rtm->rtm_addrs = RTA_DST;
-       /* rtm->rtm_addrs, rtm_flags  should be set on output */
-
-       sin = (struct sockaddr_in *)((u_char *)rtm + sizeof(*rtm));
-       sin->sin_len = sizeof(*sin);
-       sin->sin_family = AF_INET;
-       sin->sin_addr.s_addr = addr;
-
-        status = 0;
-
-       if ((s = socket(PF_ROUTE, SOCK_RAW, 0)) < 0)
-               return -1;
-       if (write(s, (char *)rtm, msglen) != msglen) {
-               close(s);
-               return status == ESRCH? 0: -1;
-       }
-
-       n = read(s, msg, 2048);
-       close(s);
-       if (n <= 0)
-               return -1;
-
-       rtm = (struct rt_msghdr *) msg;
-       if (rtm->rtm_version != RTM_VERSION)
-               return -1;
-
-       /* here we try to work out if the route is through our own interface */
-       cp = (char *)(rtm + 1);
-       if (rtm->rtm_addrs & RTA_DST) {
-               struct sockaddr *sa = (struct sockaddr *) cp;
-               cp = (char *)(((unsigned long)cp + sa->sa_len
-                              + sizeof(long) - 1) & ~(sizeof(long) - 1));
-       }
-       if (rtm->rtm_addrs & RTA_GATEWAY) {
-               sin = (struct sockaddr_in *) cp;
-               if (sin->sin_addr.s_addr == ifaddrs[0]
-                   || sin->sin_addr.s_addr == ifaddrs[1])
-                       return 0;       /* route is through our interface */
-       }
-
-       return 1;
+       return -1; 
 }
 
 static int
@@ -1587,6 +1609,57 @@ get_host_seed()
     return gethostid();
 }
 
+/*
+ * get_pty - get a pty master/slave pair and chown the slave side
+ * to the uid given.  Assumes slave_name points to >= 12 bytes of space.
+ */
+int
+get_pty(master_fdp, slave_fdp, slave_name, uid)
+    int *master_fdp;
+    int *slave_fdp;
+    char *slave_name;
+    int uid;
+{
+    int i, mfd, sfd;
+    char pty_name[12];
+    struct termios tios;
+
+    sfd = -1;
+    for (i = 0; i < 64; ++i) {
+       slprintf(pty_name, sizeof(pty_name), "/dev/pty%c%x",
+                'p' + i / 16, i % 16);
+       mfd = open(pty_name, O_RDWR, 0);
+       if (mfd >= 0) {
+           pty_name[5] = 't';
+           sfd = open(pty_name, O_RDWR | O_NOCTTY, 0);
+           if (sfd >= 0)
+               break;
+           close(mfd);
+       }
+    }
+    if (sfd < 0)
+       return 0;
+
+    strlcpy(slave_name, pty_name, 12);
+    *master_fdp = mfd;
+    *slave_fdp = sfd;
+    fchown(sfd, uid, -1);
+    fchmod(sfd, S_IRUSR | S_IWUSR);
+    if (tcgetattr(sfd, &tios) == 0) {
+       tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB);
+       tios.c_cflag |= CS8 | CREAD;
+       tios.c_iflag  = IGNPAR | CLOCAL;
+       tios.c_oflag  = 0;
+       tios.c_lflag  = 0;
+       if (tcsetattr(sfd, TCSAFLUSH, &tios) < 0)
+           warn("couldn't set attributes on pty: %m");
+    } else
+       warn("couldn't get attributes on pty: %m");
+
+    return 1;
+}
+
+#if 0
 /*
  * Code for locking/unlocking the serial device.
  * This code is derived from chat.c.
@@ -1690,6 +1763,7 @@ unlock()
        lock_file = NULL;
     }
 }
+#endif
 
 int
 set_filters(pass, active)