X-Git-Url: https://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fmain.c;h=84a58c465a2b1da1f9a5aabfe11646db6aa0998a;hp=aaaa5c8f8f7bcb8ba91733c2eb35ed7c97a66230;hb=a12ffcd5b0a1cf9a4920064295c9b02b127465b3;hpb=ace9c1c9bd73b7ed5777ec5b066ac61ba4ab2079 diff --git a/pppd/main.c b/pppd/main.c index aaaa5c8..84a58c4 100644 --- a/pppd/main.c +++ b/pppd/main.c @@ -66,6 +66,10 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include @@ -87,13 +91,15 @@ #include #include #include +#include +#include #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" @@ -103,24 +109,21 @@ #include "ecp.h" #include "pathnames.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 /* interface vars */ -char ifname[MAXIFNAMELEN]; /* Interface name */ +char ifname[IFNAMSIZ]; /* Interface name */ int ifunit; /* Interface unit number */ struct channel *the_channel; @@ -149,7 +152,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 @@ -243,7 +246,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 *); @@ -265,18 +268,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 @@ -296,6 +296,10 @@ main(int argc, char *argv[]) strlcpy(path_ipup, _PATH_IPUP, sizeof(path_ipup)); strlcpy(path_ipdown, _PATH_IPDOWN, sizeof(path_ipdown)); +#ifdef PPP_WITH_IPV6CP + strlcpy(path_ipv6up, _PATH_IPV6UP, MAXPATHLEN); + strlcpy(path_ipv6down, _PATH_IPV6DOWN, MAXPATHLEN); +#endif link_stats_valid = 0; new_phase(PHASE_INITIALIZE); @@ -380,7 +384,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) @@ -415,7 +419,7 @@ main(int argc, char *argv[]) */ sys_init(); -#ifdef USE_TDB +#ifdef PPP_WITH_TDB pppdb = tdb_open(_PATH_PPPDB, 0, 0, O_RDWR|O_CREAT, 0644); if (pppdb != NULL) { slprintf(db_key, sizeof(db_key), "pppd%d", getpid()); @@ -749,6 +753,7 @@ void detach(void) { int pid; + int ret; char numbuf[16]; int pipefd[2]; @@ -770,7 +775,10 @@ detach(void) exit(0); /* parent dies */ } setsid(); - chdir("/"); + ret = chdir("/"); + if (ret != 0) { + fatal("Could not change directory to '/', %m"); + } dup2(fd_devnull, 0); dup2(fd_devnull, 1); dup2(fd_devnull, 2); @@ -1173,7 +1181,7 @@ cleanup(void) (*the_channel->cleanup)(); remove_pidfiles(); -#ifdef USE_TDB +#ifdef PPP_WITH_TDB if (pppdb != NULL) cleanup_db(); #endif @@ -1228,9 +1236,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); } @@ -1409,8 +1417,12 @@ hup(int sig) /* Send the signal to the [dis]connector process(es) also */ kill_my_pg(sig); notify(sigreceived, sig); - if (waiting) + if (waiting) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-result" write(sigpipe[1], &sig, sizeof(sig)); +#pragma GCC diagnostic pop + } } @@ -1429,8 +1441,12 @@ term(int sig) /* Send the signal to the [dis]connector process(es) also */ kill_my_pg(sig); notify(sigreceived, sig); - if (waiting) + if (waiting) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-result" write(sigpipe[1], &sig, sizeof(sig)); +#pragma GCC diagnostic pop + } } @@ -1442,8 +1458,12 @@ static void chld(int sig) { got_sigchld = 1; - if (waiting) + if (waiting) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-result" write(sigpipe[1], &sig, sizeof(sig)); +#pragma GCC diagnostic pop + } } @@ -1475,8 +1495,12 @@ static void open_ccp(int sig) { got_sigusr2 = 1; - if (waiting) + if (waiting) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-result" write(sigpipe[1], &sig, sizeof(sig)); +#pragma GCC diagnostic pop + } } @@ -1538,7 +1562,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 @@ -1638,11 +1662,12 @@ device_script(char *program, int in, int out, int dont_wait) int pid; int status = -1; int errfd; + int ret; if (log_to_fd >= 0) errfd = log_to_fd; else - errfd = open(_PATH_CONNERRS, O_WRONLY | O_APPEND | O_CREAT, 0600); + errfd = open(_PATH_CONNERRS, O_WRONLY | O_APPEND | O_CREAT, 0644); ++conn_running; pid = safe_fork(in, out, errfd); @@ -1672,12 +1697,15 @@ device_script(char *program, int in, int out, int dont_wait) } /* here we are executing in the child */ - - setgid(getgid()); - setuid(uid); - if (getuid() != uid) { - fprintf(stderr, "pppd: setuid failed\n"); - exit(1); + ret = setgid(getgid()); + if (ret != 0) { + perror("pppd: setgid failed\n"); + exit(1); + } + ret = setuid(uid); + if (ret != 0 || getuid() != uid) { + perror("pppd: setuid failed\n"); + exit(1); } update_system_environment(); execl("/bin/sh", "sh", "-c", program, (char *)0); @@ -1738,7 +1766,7 @@ update_script_environment(void) pid_t run_program(char *prog, char **args, int must_exist, void (*done)(void *), void *arg, int wait) { - int pid, status; + int pid, status, ret; struct stat sbuf; /* @@ -1778,9 +1806,18 @@ run_program(char *prog, char **args, int must_exist, void (*done)(void *), void /* Leave the current location */ (void) setsid(); /* No controlling tty. */ (void) umask (S_IRWXG|S_IRWXO); - (void) chdir ("/"); /* no current directory. */ - setuid(0); /* set real UID = root */ - setgid(getegid()); + ret = chdir ("/"); /* no current directory. */ + if (ret != 0) { + fatal("Failed to change directory to '/', %m"); + } + ret = setuid(0); /* set real UID = root */ + if (ret != 0) { + fatal("Failed to set uid, %m"); + } + ret = setgid(getegid()); + if (ret != 0) { + fatal("failed to set gid, %m"); + } #ifdef BSD /* Force the priority back to zero if pppd is running higher. */ @@ -1975,13 +2012,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); @@ -2005,7 +2042,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); @@ -2029,7 +2066,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 @@ -2037,7 +2074,7 @@ script_unsetenv(char *var) break; } } -#ifdef USE_TDB +#ifdef PPP_WITH_TDB if (pppdb != NULL) update_db_entry(); #endif @@ -2055,7 +2092,7 @@ script_unsetenv(char *var) */ void lock_db(void) { -#ifdef USE_TDB +#ifdef PPP_WITH_TDB TDB_DATA key; key.dptr = PPPD_LOCK_KEY; @@ -2069,7 +2106,7 @@ void lock_db(void) */ void unlock_db(void) { -#ifdef USE_TDB +#ifdef PPP_WITH_TDB TDB_DATA key; key.dptr = PPPD_LOCK_KEY; @@ -2078,7 +2115,7 @@ void unlock_db(void) #endif } -#ifdef USE_TDB +#ifdef PPP_WITH_TDB /* * update_db_entry - update our entry in the database. */ @@ -2159,4 +2196,4 @@ cleanup_db(void) if (p[-1]) delete_db_key(p); } -#endif /* USE_TDB */ +#endif /* PPP_WITH_TDB */