]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/sys-ultrix.c
use strlcpy, strlcat, slprintf everywhere
[ppp.git] / pppd / sys-ultrix.c
index 95bb7dd4721dc021ef2d9c72a23e5a5e42cad254..92d3bd26d771b4351038699ac19cdb6154ee05be 100644 (file)
@@ -21,7 +21,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: sys-ultrix.c,v 1.20 1997/03/04 03:43:54 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;
@@ -137,13 +137,14 @@ sys_close()
 /*
  * sys_check_options - check the options that the user specified
  */
-void
+int
 sys_check_options()
 {
     if (demand) {
        option_error("Sorry - demand-dialling is not supported under Ultrix\n");
-       exit(1);
+       return 0;
     }
+    return 1;
 }
 
 
@@ -185,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);
 
@@ -562,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)
@@ -839,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;
@@ -890,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;
@@ -925,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;
@@ -980,7 +981,7 @@ cifaddr(u, o, h)
  */
 int
 sifdefaultroute(u, l, g)
-    int unit;
+    int u;
     u_int32_t l, g;
 {
     struct rtentry rt;
@@ -1003,7 +1004,7 @@ sifdefaultroute(u, l, g)
  */
 int
 cifdefaultroute(u, l, g)
-    int unit;
+    int u;
     u_int32_t l, g;
 {
     struct rtentry rt;
@@ -1107,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.
@@ -1138,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;
@@ -1199,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))
@@ -1216,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.
@@ -1264,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);
@@ -1290,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