]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/main.c
Merge pull request #366 from pali/rtnetlink-register
[ppp.git] / pppd / main.c
index b1ac8b4fd68087d54c1e6b9a6eeda87ca5130bc5..b302c08e0659379fd23896e20bdd287d3c7041d9 100644 (file)
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <limits.h>
+#include <inttypes.h>
+#include <net/if.h>
 
 #include "pppd.h"
 #include "magic.h"
 #include "fsm.h"
 #include "lcp.h"
 #include "ipcp.h"
-#ifdef INET6
+#ifdef PPP_WITH_IPV6CP
 #include "ipv6cp.h"
 #endif
 #include "upap.h"
 #include "ccp.h"
 #include "ecp.h"
 #include "pathnames.h"
+#include "ppp-crypto.h"
 
-#ifdef USE_TDB
+#ifdef PPP_WITH_TDB
 #include "tdb.h"
 #endif
 
-#ifdef CBCP_SUPPORT
+#ifdef PPP_WITH_CBCP
 #include "cbcp.h"
 #endif
 
-#ifdef IPX_CHANGE
-#include "ipxcp.h"
-#endif /* IPX_CHANGE */
 #ifdef AT_CHANGE
 #include "atcp.h"
 #endif
@@ -153,7 +154,7 @@ int ppp_session_number;             /* Session number, for channels with such a
                                   concept (eg PPPoE) */
 int childwait_done;            /* have timed out waiting for children */
 
-#ifdef USE_TDB
+#ifdef PPP_WITH_TDB
 TDB_CONTEXT *pppdb;            /* database for storing status etc. */
 #endif
 
@@ -247,7 +248,7 @@ static void forget_child(int pid, int status);
 static int reap_kids(void);
 static void childwait_end(void *);
 
-#ifdef USE_TDB
+#ifdef PPP_WITH_TDB
 static void update_db_entry(void);
 static void add_db_key(const char *);
 static void delete_db_key(const char *);
@@ -269,18 +270,15 @@ struct protent *protocols[] = {
     &lcp_protent,
     &pap_protent,
     &chap_protent,
-#ifdef CBCP_SUPPORT
+#ifdef PPP_WITH_CBCP
     &cbcp_protent,
 #endif
     &ipcp_protent,
-#ifdef INET6
+#ifdef PPP_WITH_IPV6CP
     &ipv6cp_protent,
 #endif
     &ccp_protent,
     &ecp_protent,
-#ifdef IPX_CHANGE
-    &ipxcp_protent,
-#endif
 #ifdef AT_CHANGE
     &atcp_protent,
 #endif
@@ -297,9 +295,15 @@ main(int argc, char *argv[])
     struct protent *protp;
     char numbuf[16];
 
-    strlcpy(path_ipup, _PATH_IPUP, sizeof(path_ipup));
-    strlcpy(path_ipdown, _PATH_IPDOWN, sizeof(path_ipdown));
+    PPP_crypto_init();
+
+    strlcpy(path_ipup, PPP_PATH_IPUP, MAXPATHLEN);
+    strlcpy(path_ipdown, PPP_PATH_IPDOWN, MAXPATHLEN);
 
+#ifdef PPP_WITH_IPV6CP
+    strlcpy(path_ipv6up, PPP_PATH_IPV6UP, MAXPATHLEN);
+    strlcpy(path_ipv6down, PPP_PATH_IPV6DOWN, MAXPATHLEN);
+#endif
     link_stats_valid = 0;
     new_phase(PHASE_INITIALIZE);
 
@@ -347,7 +351,7 @@ main(int argc, char *argv[])
      * Parse, in order, the system options file, the user's options file,
      * and the command line arguments.
      */
-    if (!options_from_file(_PATH_SYSOPTIONS, !privileged, 0, 1)
+    if (!options_from_file(PPP_PATH_SYSOPTIONS, !privileged, 0, 1)
        || !options_from_user()
        || !parse_args(argc-1, argv+1))
        exit(EXIT_OPTION_ERROR);
@@ -363,6 +367,11 @@ main(int argc, char *argv[])
     if (debug)
        setlogmask(LOG_UPTO(LOG_DEBUG));
 
+    if (show_options) {
+       showopts();
+       die(0);
+    }
+
     /*
      * Check that we are running as root.
      */
@@ -384,7 +393,7 @@ main(int argc, char *argv[])
     if (!sys_check_options())
        exit(EXIT_OPTION_ERROR);
     auth_check_options();
-#ifdef HAVE_MULTILINK
+#ifdef PPP_WITH_MULTILINK
     mp_check_options();
 #endif
     for (i = 0; (protp = protocols[i]) != NULL; ++i)
@@ -404,9 +413,9 @@ main(int argc, char *argv[])
        die(0);
 
     /* Make sure fds 0, 1, 2 are open to somewhere. */
-    fd_devnull = open(_PATH_DEVNULL, O_RDWR);
+    fd_devnull = open(PPP_DEVNULL, O_RDWR);
     if (fd_devnull < 0)
-       fatal("Couldn't open %s: %m", _PATH_DEVNULL);
+       fatal("Couldn't open %s: %m", PPP_DEVNULL);
     while (fd_devnull <= 2) {
        i = dup(fd_devnull);
        if (i < 0)
@@ -419,13 +428,13 @@ main(int argc, char *argv[])
      */
     sys_init();
 
-#ifdef USE_TDB
-    pppdb = tdb_open(_PATH_PPPDB, 0, 0, O_RDWR|O_CREAT, 0644);
+#ifdef PPP_WITH_TDB
+    pppdb = tdb_open(PPP_PATH_PPPDB, 0, 0, O_RDWR|O_CREAT, 0644);
     if (pppdb != NULL) {
        slprintf(db_key, sizeof(db_key), "pppd%d", getpid());
        update_db_entry();
     } else {
-       warn("Warning: couldn't open ppp database %s", _PATH_PPPDB);
+       warn("Warning: couldn't open ppp database %s", PPP_PATH_PPPDB);
        if (multilink) {
            warn("Warning: disabling multilink");
            multilink = 0;
@@ -580,6 +589,7 @@ main(int argc, char *argv[])
        }
     }
 
+    PPP_crypto_deinit();
     die(status);
     return 0;
 }
@@ -813,7 +823,7 @@ create_pidfile(int pid)
     FILE *pidfile;
 
     slprintf(pidfilename, sizeof(pidfilename), "%s%s.pid",
-            _PATH_VARRUN, ifname);
+            PPP_PATH_VARRUN, ifname);
     if ((pidfile = fopen(pidfilename, "w")) != NULL) {
        fprintf(pidfile, "%d\n", pid);
        (void) fclose(pidfile);
@@ -832,7 +842,7 @@ create_linkpidfile(int pid)
        return;
     script_setenv("LINKNAME", linkname, 1);
     slprintf(linkpidfile, sizeof(linkpidfile), "%sppp-%s.pid",
-            _PATH_VARRUN, linkname);
+            PPP_PATH_VARRUN, linkname);
     if ((pidfile = fopen(linkpidfile, "w")) != NULL) {
        fprintf(pidfile, "%d\n", pid);
        if (ifname[0])
@@ -1181,7 +1191,7 @@ cleanup(void)
        (*the_channel->cleanup)();
     remove_pidfiles();
 
-#ifdef USE_TDB
+#ifdef PPP_WITH_TDB
     if (pppdb != NULL)
        cleanup_db();
 #endif
@@ -1236,9 +1246,9 @@ update_link_stats(int u)
 
     slprintf(numbuf, sizeof(numbuf), "%u", link_connect_time);
     script_setenv("CONNECT_TIME", numbuf, 0);
-    slprintf(numbuf, sizeof(numbuf), "%u", link_stats.bytes_out);
+    snprintf(numbuf, sizeof(numbuf), "%" PRIu64, link_stats.bytes_out);
     script_setenv("BYTES_SENT", numbuf, 0);
-    slprintf(numbuf, sizeof(numbuf), "%u", link_stats.bytes_in);
+    snprintf(numbuf, sizeof(numbuf), "%" PRIu64, link_stats.bytes_in);
     script_setenv("BYTES_RCVD", numbuf, 0);
 }
 
@@ -1562,7 +1572,7 @@ safe_fork(int infd, int outfd, int errfd)
 
        /* Executing in the child */
        sys_close();
-#ifdef USE_TDB
+#ifdef PPP_WITH_TDB
        if (pppdb != NULL)
                tdb_close(pppdb);
 #endif
@@ -1654,7 +1664,7 @@ update_system_environment(void)
 /*
  * device_script - run a program to talk to the specified fds
  * (e.g. to run the connector or disconnector script).
- * stderr gets connected to the log fd or to the _PATH_CONNERRS file.
+ * stderr gets connected to the log fd or to the PPP_PATH_CONNERRS file.
  */
 int
 device_script(char *program, int in, int out, int dont_wait)
@@ -1667,7 +1677,7 @@ device_script(char *program, int in, int out, int dont_wait)
     if (log_to_fd >= 0)
        errfd = log_to_fd;
     else
-       errfd = open(_PATH_CONNERRS, O_WRONLY | O_APPEND | O_CREAT, 0644);
+       errfd = open(PPP_PATH_CONNERRS, O_WRONLY | O_APPEND | O_CREAT, 0644);
 
     ++conn_running;
     pid = safe_fork(in, out, errfd);
@@ -2012,13 +2022,13 @@ script_setenv(char *var, char *value, int iskey)
     if (script_env != 0) {
        for (i = 0; (p = script_env[i]) != 0; ++i) {
            if (strncmp(p, var, varl) == 0 && p[varl] == '=') {
-#ifdef USE_TDB
+#ifdef PPP_WITH_TDB
                if (p[-1] && pppdb != NULL)
                    delete_db_key(p);
 #endif
                free(p-1);
                script_env[i] = newstring;
-#ifdef USE_TDB
+#ifdef PPP_WITH_TDB
                if (pppdb != NULL) {
                    if (iskey)
                        add_db_key(newstring);
@@ -2042,7 +2052,7 @@ script_setenv(char *var, char *value, int iskey)
     if (!add_script_env(i, newstring))
        return;
 
-#ifdef USE_TDB
+#ifdef PPP_WITH_TDB
     if (pppdb != NULL) {
        if (iskey)
            add_db_key(newstring);
@@ -2066,7 +2076,7 @@ script_unsetenv(char *var)
        return;
     for (i = 0; (p = script_env[i]) != 0; ++i) {
        if (strncmp(p, var, vl) == 0 && p[vl] == '=') {
-#ifdef USE_TDB
+#ifdef PPP_WITH_TDB
            if (p[-1] && pppdb != NULL)
                delete_db_key(p);
 #endif
@@ -2074,7 +2084,7 @@ script_unsetenv(char *var)
            break;
        }
     }
-#ifdef USE_TDB
+#ifdef PPP_WITH_TDB
     if (pppdb != NULL)
        update_db_entry();
 #endif
@@ -2092,7 +2102,7 @@ script_unsetenv(char *var)
  */
 void lock_db(void)
 {
-#ifdef USE_TDB
+#ifdef PPP_WITH_TDB
        TDB_DATA key;
 
        key.dptr = PPPD_LOCK_KEY;
@@ -2106,7 +2116,7 @@ void lock_db(void)
  */
 void unlock_db(void)
 {
-#ifdef USE_TDB
+#ifdef PPP_WITH_TDB
        TDB_DATA key;
 
        key.dptr = PPPD_LOCK_KEY;
@@ -2115,7 +2125,7 @@ void unlock_db(void)
 #endif
 }
 
-#ifdef USE_TDB
+#ifdef PPP_WITH_TDB
 /*
  * update_db_entry - update our entry in the database.
  */
@@ -2196,4 +2206,4 @@ cleanup_db(void)
        if (p[-1])
            delete_db_key(p);
 }
-#endif /* USE_TDB */
+#endif /* PPP_WITH_TDB */