]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/sys-ultrix.c
use strlcpy, strlcat, slprintf everywhere
[ppp.git] / pppd / sys-ultrix.c
index ec05e7fb75d7e4d98122a56a1b9b7125bbad2859..92d3bd26d771b4351038699ac19cdb6154ee05be 100644 (file)
@@ -21,7 +21,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: sys-ultrix.c,v 1.17 1996/05/26 23:58:03 paulus Exp $";
+static char rcsid[] = "$Id: sys-ultrix.c,v 1.25 1999/03/12 06:07:24 paulus Exp $";
 #endif
 
 /*
@@ -106,7 +106,7 @@ sys_cleanup()
     struct ifreq ifr;
 
     if (if_is_up) {
-       strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+       strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname);
        if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) >= 0
            && ((ifr.ifr_flags & IFF_UP) != 0)) {
            ifr.ifr_flags &= ~IFF_UP;
@@ -116,7 +116,7 @@ sys_cleanup()
     if (ifaddrs[0])
        cifaddr(0, ifaddrs[0], ifaddrs[1]);
     if (default_route_gateway)
-       cifdefaultroute(0, default_route_gateway);
+       cifdefaultroute(0, 0, default_route_gateway);
     if (proxy_arp_addr)
        cifproxyarp(0, proxy_arp_addr);
 }
@@ -137,14 +137,14 @@ sys_close()
 /*
  * sys_check_options - check the options that the user specified
  */
-void
+int
 sys_check_options()
 {
     if (demand) {
-       fprintf(stderr,
-               "Sorry - demand-dialling is not supported under Ultrix\n");
-       exit(1);
+       option_error("Sorry - demand-dialling is not supported under Ultrix\n");
+       return 0;
     }
+    return 1;
 }
 
 
@@ -186,7 +186,7 @@ ppp_available()
     if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
        return 1;               /* can't tell */
 
-    strncpy(ifr.ifr_name, "ppp0", sizeof (ifr.ifr_name));
+    strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), "ppp0");
     ok = ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) >= 0;
     close(s);
 
@@ -563,7 +563,7 @@ output(unit, p, len)
     int len;
 {
     if (debug)
-       log_packet(p, len, "sent ");
+       log_packet(p, len, "sent ", LOG_DEBUG);
 
     if (write(ttyfd, p, len) < 0) {
        if (errno != EIO)
@@ -599,6 +599,7 @@ wait_input(timo)
  * loopback, for the length of time specified by *timo (indefinite
  * if timo is NULL).
  */
+void
 wait_loop_output(timo)
     struct timeval *timo;
 {
@@ -610,6 +611,7 @@ wait_loop_output(timo)
  * wait_time - wait for a given length of time or until a
  * signal is received.
  */
+void
 wait_time(timo)
     struct timeval *timo;
 {
@@ -803,31 +805,6 @@ get_idle_time(u, ip)
 }
 
 
-/*
- * set_filters - transfer the pass and active filters to the kernel.
- */
-int
-set_filters(pass, active)
-    struct bpf_program *pass, *active;
-{
-    int ret = 1;
-
-    if (pass->bf_len > 0) {
-       if (ioctl(ppp_fd, PPPIOCSPASS, pass) < 0) {
-           syslog(LOG_ERR, "Couldn't set pass-filter in kernel: %m");
-           ret = 0;
-       }
-    }
-    if (active->bf_len > 0) {
-       if (ioctl(ppp_fd, PPPIOCSACTIVE, active) < 0) {
-           syslog(LOG_ERR, "Couldn't set active-filter in kernel: %m");
-           ret = 0;
-       }
-    }
-    return ret;
-}
-
-
 /*
  * sifvjcomp - config tcp header compression
  */
@@ -863,7 +840,7 @@ sifup(u)
 {
     struct ifreq ifr;
 
-    strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
+    strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
     if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
        syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
        return 0;
@@ -914,7 +891,7 @@ sifdown(u)
     ioctl(ppp_fd, PPPIOCSNPMODE, (caddr_t) &npi);
     /* ignore errors, because ppp_fd might have been closed by now. */
 
-    strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
+    strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
     if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
        syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
        rv = 0;
@@ -949,7 +926,7 @@ sifaddr(u, o, h, m)
     struct ifreq ifr;
 
     ret = 1;
-    strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
+    strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
     SET_SA_FAMILY(ifr.ifr_addr, AF_INET);
     if (m != 0) {
         ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = m;
@@ -1003,7 +980,9 @@ cifaddr(u, o, h)
  * sifdefaultroute - assign a default route through the address given.
  */
 int
-sifdefaultroute(u, g)
+sifdefaultroute(u, l, g)
+    int u;
+    u_int32_t l, g;
 {
     struct rtentry rt;
 
@@ -1024,7 +1003,9 @@ sifdefaultroute(u, g)
  * cifdefaultroute - delete a default route through the address given.
  */
 int
-cifdefaultroute(u, g)
+cifdefaultroute(u, l, g)
+    int u;
+    u_int32_t l, g;
 {
     struct rtentry rt;
 
@@ -1127,7 +1108,7 @@ get_ether_addr(ipaddr, hwaddr)
            ((char *)&ifr->ifr_addr + sizeof(struct sockaddr))) {
         if (ifr->ifr_addr.sa_family == AF_INET) {
             ina = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr;
-            strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
+            strlcpy(ifreq.ifr_name, sizeof(ifreq.ifr_name), ifr->ifr_name);
             /*
              * Check that the interface is up, and not point-to-point
              * or loopback.
@@ -1158,7 +1139,7 @@ get_ether_addr(ipaddr, hwaddr)
     /*
      * Grab the physical address for this interface.
      */
-    strncpy(ifdevea.ifr_name, ifr->ifr_name, sizeof(ifdevea.ifr_name));
+    strlcpy(ifdevea.ifr_name, sizeof(ifdevea.ifr_name), ifr->ifr_name);
     if (ioctl(sockfd, SIOCRPHYSADDR, &ifdevea) < 0) {
        syslog(LOG_ERR, "Couldn't get h/w address for %s: %m", ifr->ifr_name);
        return 0;
@@ -1219,7 +1200,7 @@ GetMask(addr)
        /*
         * Check that the interface is up, and not point-to-point or loopback.
         */
-       strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
+       strlcpy(ifreq.ifr_name, sizeof(ifreq.ifr_name), ifr->ifr_name);
        if (ioctl(sockfd, SIOCGIFFLAGS, &ifreq) < 0)
            continue;
        if ((ifreq.ifr_flags & (IFF_UP|IFF_POINTOPOINT|IFF_LOOPBACK))
@@ -1236,6 +1217,27 @@ GetMask(addr)
     return mask;
 }
 
+/*
+ * have_route_to - determine if the system has any route to
+ * a given IP address.
+ * For demand mode to work properly, we have to ignore routes
+ * through our own interface.
+ */
+int have_route_to(u_int32_t addr)
+{
+    return -1;
+}
+
+
+/*
+ * Use the hostid as part of the random number seed.
+ */
+int
+get_host_seed()
+{
+    return gethostid();
+}
+
 
 /*
   Seems like strdup() is not part of string package in Ultrix.
@@ -1273,9 +1275,9 @@ char *strdup( in ) char *in;
 
 #define        WTMPFILE        "/usr/adm/wtmp"
 
-int
+void
 logwtmp(line, name, host)
-    char *line, *name, *host;
+    const char *line, *name, *host;
 {
     int fd;
     struct stat buf;
@@ -1284,9 +1286,9 @@ logwtmp(line, name, host)
     if ((fd = open(WTMPFILE, O_WRONLY|O_APPEND, 0)) < 0)
        return;
     if (!fstat(fd, &buf)) {
-       (void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
-       (void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
-       (void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
+       strlcpy(ut.ut_line, sizeof(ut.ut_line), line);
+       strlcpy(ut.ut_name, sizeof(ut.ut_name), name);
+       strlcpy(ut.ut_host, sizeof(ut.ut_host), host);
        (void)time(&ut.ut_time);
        if (write(fd, (char *)&ut, sizeof(struct utmp)) != sizeof(struct utmp))
            (void)ftruncate(fd, buf.st_size);
@@ -1310,13 +1312,15 @@ lock(dev)
 {
     int fd, pid, n;
     char *p;
+    size_t l;
 
     if ((p = strrchr(dev, '/')) != NULL)
        dev = p + 1;
-    lock_file = malloc(strlen(LOCK_PREFIX) + strlen(dev) + 1);
+    l = strlen(LOCK_PREFIX) + strlen(dev) + 1;
+    lock_file = malloc(l);
     if (lock_file == NULL)
        novm("lock file name");
-    strcat(strcpy(lock_file, LOCK_PREFIX), dev);
+    slprintf(lock_file, l, "%s%s, LOCK_PREFIX, dev);
 
     while ((fd = open(lock_file, O_EXCL | O_CREAT | O_RDWR, 0644)) < 0) {
        if (errno == EEXIST