X-Git-Url: https://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fmain.c;h=cba4a925a58b82ff5a471a5b2acf563fcdefa05c;hp=099c0505a4217ff942e75ffe3fb419996a0e7b57;hb=80b8744eb42c;hpb=75870d7b55e36af526a0786fff94912989c73fd1 diff --git a/pppd/main.c b/pppd/main.c index 099c050..cba4a92 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" @@ -111,16 +117,13 @@ #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; @@ -269,14 +272,11 @@ struct protent *protocols[] = { &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 @@ -293,6 +293,13 @@ 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)); + +#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); @@ -746,6 +753,7 @@ void detach(void) { int pid; + int ret; char numbuf[16]; int pipefd[2]; @@ -763,12 +771,14 @@ detach(void) /* update pid files if they have been written already */ if (pidfilename[0]) create_pidfile(pid); - if (linkpidfile[0]) - create_linkpidfile(pid); + create_linkpidfile(pid); 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); @@ -1226,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); } @@ -1407,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 + } } @@ -1427,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 + } } @@ -1440,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 + } } @@ -1473,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 + } } @@ -1636,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); @@ -1670,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); @@ -1736,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; /* @@ -1776,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. */