]> git.ozlabs.org Git - ppp.git/commitdiff
Merge pull request #313 from Chocobo1/install
authorPaul Mackerras <paulus@ozlabs.org>
Sat, 16 Oct 2021 02:53:02 +0000 (13:53 +1100)
committerGitHub <noreply@github.com>
Sat, 16 Oct 2021 02:53:02 +0000 (13:53 +1100)
Perform installation step in the CI testing

20 files changed:
README.pppoe
chat/chat.c
pppd/Makefile.am
pppd/main.c
pppd/plugins/passprompt.c
pppd/plugins/pppoatm/pppoatm.c
pppd/plugins/pppoe/common.c
pppd/plugins/pppol2tp/pppol2tp.c
pppd/plugins/radius/avpair.c
pppd/plugins/radius/buildreq.c
pppd/plugins/radius/config.c
pppd/plugins/radius/radattr.c
pppd/plugins/radius/radius.c
pppd/plugins/radius/sendserver.c
pppd/plugins/radius/util.c
pppd/plugins/winbind.c
pppd/sys-linux.c
pppd/termios_linux.h [new file with mode: 0644]
pppd/tty.c
pppd/utils.c

index 2909e1310a31f23f62719bc97cd0538084240704..7fe0139a671cda216db5a4fb58c2486efb1f2543 100644 (file)
@@ -60,7 +60,7 @@ to connect to their ISP who is providing PPPoE based services.
 
 5.  Add the necessary authentication options to your pppd
     configuration (i.e. PAP/CHAP information).  If you wish to
-    maintain seperate configurations for different devices you may
+    maintain separate configurations for different devices you may
     place configuration options in device-specific configuration
     files: /etc/ppp/options.devname (devname=ttyS0, ttyS1, eth0, eth1
     or any other valid device name).
index d2d255a1c7c015660adb75b0f9dcc21e6953d964..64d96c230bfcd943c28e9182711c7fbaee7d20ad 100644 (file)
@@ -201,7 +201,7 @@ SIGTYPE sighup (int signo);
 void unalarm (void);
 void init (void);
 void set_tty_parameters (void);
-void echo_stderr (int);
+int  echo_stderr (int);
 void break_sequence (void);
 void terminate (int status);
 void do_file (char *chat_file);
@@ -210,7 +210,7 @@ int  put_string (register char *s);
 int  write_char (int c);
 int  put_char (int c);
 int  get_char (void);
-void chat_send (register char *s);
+int  chat_send (register char *s);
 char *character (int c);
 void chat_expect (register char *s);
 char *clean (register char *s, int sending);
@@ -983,16 +983,18 @@ char *character(int c)
 /*
  *  process the reply string
  */
-void chat_send (register char *s)
+int chat_send (register char *s)
 {
     char file_data[STR_LEN];
+    int len, ret = 0;
 
     if (say_next) {
        say_next = 0;
        s = clean(s, 1);
-       write(2, s, strlen(s));
+       len = strlen(s);
+       ret = write(2, s, len) != len;
         free(s);
-       return;
+       return ret;
     }
 
     if (hup_next) {
@@ -1001,13 +1003,13 @@ void chat_send (register char *s)
            signal(SIGHUP, SIG_IGN);
         else
            signal(SIGHUP, sighup);
-        return;
+        return 0;
     }
 
     if (echo_next) {
        echo_next = 0;
        echo = (strcmp(s, "ON") == 0);
-       return;
+       return 0;
     }
 
     if (abort_next) {
@@ -1027,7 +1029,7 @@ void chat_send (register char *s)
 
        if (verbose)
            msgf("abort on (%v)", s1);
-       return;
+       return 0;
     }
 
     if (clear_abort_next) {
@@ -1057,7 +1059,7 @@ void chat_send (register char *s)
         free(s1);
        if (pack)
            pack_array(abort_string,old_max);
-       return;
+       return 0;
     }
 
     if (report_next) {
@@ -1075,7 +1077,7 @@ void chat_send (register char *s)
        
        if (verbose)
            msgf("report (%v)", s1);
-       return;
+       return 0;
     }
 
     if (clear_report_next) {
@@ -1106,7 +1108,7 @@ void chat_send (register char *s)
         if (pack)
            pack_array(report_string,old_max);
        
-       return;
+       return 0;
     }
 
     if (timeout_next) {
@@ -1120,7 +1122,7 @@ void chat_send (register char *s)
        if (verbose)
            msgf("timeout set to %d seconds", timeout);
 
-       return;
+       return 0;
     }
 
     /*
@@ -1167,6 +1169,8 @@ void chat_send (register char *s)
 
     if (!put_string(s))
        fatal(1, "Failed");
+
+    return 0;
 }
 
 int get_char(void)
@@ -1292,10 +1296,11 @@ int put_string(register char *s)
  *     When called with -1, a '\n' character is generated when
  *     the cursor is not at the beginning of a line.
  */
-void echo_stderr(int n)
+int echo_stderr(int n)
 {
     static int need_lf;
     char *s;
+    int len, ret = 0;
 
     switch (n) {
     case '\r':         /* ignore '\r' */
@@ -1305,15 +1310,17 @@ void echo_stderr(int n)
            break;
        /* fall through */
     case '\n':
-       write(2, "\n", 1);
+       ret = write(2, "\n", 1) != 1;
        need_lf = 0;
        break;
     default:
        s = character(n);
-       write(2, s, strlen(s));
+       len = strlen(s);
+       ret = write(2, s, len) != len;
        need_lf = 1;
        break;
     }
+    return ret;
 }
 
 /*
@@ -1352,8 +1359,11 @@ int get_string(register char *string)
     while ( ! alarmed && (c = get_char()) >= 0) {
        int n, abort_len, report_len;
 
-       if (echo)
-           echo_stderr(c);
+       if (echo) {
+           if (echo_stderr(c) != 0) {
+               fatal(2, "Could not write to stderr, %m");
+           }
+       }
        if (verbose && c == '\n') {
            if (s == logged)
                msgf("");       /* blank line */
index 22445072f78b8e3add93bd7aefb8dd6ed6b47e4e..03c6fd448171eb9c80c9dccc0a79d71de55b963a 100644 (file)
@@ -72,7 +72,7 @@ pppd_LDFLAGS =
 pppd_LIBS =
 
 if LINUX
-pppd_SOURCES += sys-linux.c
+pppd_SOURCES += sys-linux.c termios_linux.h
 pppd_LIBS += $(CRYPT_LIBS) $(UTIL_LIBS)
 endif
 
index 203202fe6ed6ffcbc21cbcf7cd102c58e5b3a9a9..b1ac8b4fd68087d54c1e6b9a6eeda87ca5130bc5 100644 (file)
@@ -753,6 +753,7 @@ void
 detach(void)
 {
     int pid;
+    int ret;
     char numbuf[16];
     int pipefd[2];
 
@@ -774,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);
@@ -1413,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
+    }
 }
 
 
@@ -1433,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
+    }
 }
 
 
@@ -1446,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
+    }
 }
 
 
@@ -1479,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
+    }
 }
 
 
@@ -1642,6 +1662,7 @@ 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;
@@ -1676,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);
@@ -1742,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;
 
     /*
@@ -1782,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. */
index dae326867fcdea9b2f6190d6e01fd24fff056352..743c087b47805ea002b026dd7cf36a6b2ef5afb4 100644 (file)
@@ -35,7 +35,7 @@ static int promptpass(char *user, char *passwd)
 {
     int p[2];
     pid_t kid;
-    int readgood, wstat;
+    int readgood, wstat, ret;
     ssize_t red;
 
     if (promptprog_refused || promptprog[0] == 0 || access(promptprog, X_OK) < 0)
@@ -60,8 +60,14 @@ static int promptpass(char *user, char *passwd)
        sys_close();
        closelog();
        close(p[0]);
-       seteuid(getuid());
-       setegid(getgid());
+       ret = seteuid(getuid());
+       if (ret != 0) {
+               warn("Couldn't set effective user id");
+       }
+       ret = setegid(getgid());
+       if (ret != 0) {
+               warn("Couldn't set effective user id");
+       }
        argv[0] = promptprog;
        argv[1] = user;
        argv[2] = remote_name;
index dc825084fe2aa2066f4cc4f76ce292990bfc5ae5..09cd0b8bfb0142524d12c15971f8e13844e7e6b0 100644 (file)
@@ -187,15 +187,15 @@ void plugin_init(void)
 }
 
 struct channel pppoa_channel = {
-    options: pppoa_options,
-    process_extra_options: NULL,
-    check_options: NULL,
-    connect: &connect_pppoatm,
-    disconnect: &disconnect_pppoatm,
-    establish_ppp: &generic_establish_ppp,
-    disestablish_ppp: &generic_disestablish_ppp,
-    send_config: NULL,
-    recv_config: NULL,
-    close: NULL,
-    cleanup: NULL
+    .options = pppoa_options,
+    .process_extra_options = NULL,
+    .check_options = NULL,
+    .connect = &connect_pppoatm,
+    .disconnect = &disconnect_pppoatm,
+    .establish_ppp = &generic_establish_ppp,
+    .disestablish_ppp = &generic_disestablish_ppp,
+    .send_config = NULL,
+    .recv_config = NULL,
+    .close = NULL,
+    .cleanup = NULL
 };
index 638282184e4fb8e19b1ccbed6e0fb14bba4c518b..64bed1af6ca63df5de7344bbdc85c8ea262f22e8 100644 (file)
@@ -136,7 +136,7 @@ sendPADT(PPPoEConnection *conn, char const *msg)
        size_t elen = strlen(msg);
        err.type = htons(TAG_GENERIC_ERROR);
        err.length = htons(elen);
-       strcpy(err.payload, msg);
+       strcpy((char*) err.payload, msg);
        memcpy(cursor, &err, elen + TAG_HDR_SIZE);
        cursor += elen + TAG_HDR_SIZE;
        plen += elen + TAG_HDR_SIZE;
index 94b2f1f947896b35422bf49b8941ae3e85c6e840..ed2d7c7942a11db2ac6eb8152d0ad87507bf2886 100644 (file)
@@ -125,10 +125,10 @@ static int setdevname_pppol2tp(char **argv)
                char buffer[128];
                struct sockaddr pppol2tp;
        } s;
-       int len = sizeof(s);
+       socklen_t len = sizeof(s);
        char **a;
        int tmp;
-       int tmp_len = sizeof(tmp);
+       socklen_t tmp_len = sizeof(tmp);
 
        if (device_got_set)
                return 0;
@@ -207,8 +207,8 @@ static void send_config_pppol2tp(int mtu,
        int on = 1;
        int fd;
        char reorderto[16];
-       char tid[8];
-       char sid[8];
+       char tid[12];
+       char sid[12];
 
        if (pppol2tp_ifname[0]) {
                struct ifreq ifr;
@@ -241,10 +241,10 @@ static void send_config_pppol2tp(int mtu,
                sprintf(&reorderto[0], "%d ", pppol2tp_reorder_timeout);
        tid[0] = '\0';
        if (pppol2tp_tunnel_id > 0)
-               sprintf(&tid[0], "%hu ", pppol2tp_tunnel_id);
+               sprintf(&tid[0], "%u ", pppol2tp_tunnel_id);
        sid[0] = '\0';
        if (pppol2tp_session_id > 0)
-               sprintf(&sid[0], "%hu ", pppol2tp_session_id);
+               sprintf(&sid[0], "%u ", pppol2tp_session_id);
 
        dbglog("PPPoL2TP options: %s%s%s%s%s%s%s%s%sdebugmask %d",
               pppol2tp_recv_seq ? "recvseq " : "",
@@ -514,15 +514,15 @@ void plugin_init(void)
 }
 
 struct channel pppol2tp_channel = {
-    options: pppol2tp_options,
-    process_extra_options: NULL,
-    check_options: &pppol2tp_check_options,
-    connect: &connect_pppol2tp,
-    disconnect: &disconnect_pppol2tp,
-    establish_ppp: &generic_establish_ppp,
-    disestablish_ppp: &generic_disestablish_ppp,
-    send_config: &send_config_pppol2tp,
-    recv_config: &recv_config_pppol2tp,
-    close: NULL,
-    cleanup: NULL
+    .options = pppol2tp_options,
+    .process_extra_options = NULL,
+    .check_options = &pppol2tp_check_options,
+    .connect = &connect_pppol2tp,
+    .disconnect = &disconnect_pppol2tp,
+    .establish_ppp = &generic_establish_ppp,
+    .disestablish_ppp = &generic_disestablish_ppp,
+    .send_config = &send_config_pppol2tp,
+    .recv_config = &recv_config_pppol2tp,
+    .close = NULL,
+    .cleanup = NULL
 };
index d548b47b1d23bd5ecc4c56b6ad2081a2068463dc..0dc9a85d13a6be0b4e8e939961e754e5a7ce2b00 100644 (file)
@@ -76,7 +76,7 @@ int rc_avpair_assign (VALUE_PAIR *vp, void *pval, int len)
                                vp->strvalue[len] = '\0';
                                vp->lvalue = len;
                        } else {
-                       strncpy (vp->strvalue, (char *) pval, AUTH_STRING_LEN);
+                       strncpy ((char*) vp->strvalue, (char *) pval, AUTH_STRING_LEN);
                        vp->lvalue = strlen((char *) pval);
                        }
 
@@ -161,7 +161,7 @@ VALUE_PAIR *rc_avpair_gen (AUTH_HDR *auth)
        DICT_ATTR      *attr;
        VALUE_PAIR     *vp;
        VALUE_PAIR     *pair;
-       unsigned char   hex[3];         /* For hex string conversion. */
+       char            hex[3];         /* For hex string conversion. */
        char            buffer[512];
 
        /*
@@ -600,7 +600,7 @@ int rc_avpair_parse (char *buffer, VALUE_PAIR **first_pair)
                        {
 
                            case PW_TYPE_STRING:
-                               strcpy (pair->strvalue, valstr);
+                               strcpy ((char*) pair->strvalue, valstr);
                                pair->lvalue = strlen(valstr);
                                break;
 
@@ -725,7 +725,7 @@ int rc_avpair_tostr (VALUE_PAIR *pair, char *name, int ln, char *value, int lv)
                        }
                        else
                        {
-                               strncat(value, ptr, 1);
+                               strncat(value, (char*) ptr, 1);
                                lv--;
                                if (lv < 0) break;
                        }
index 3edd5ea92e1c0e0a864975670f5fa57b8aa87aa0..562790aa7887ea8d174021cce062a85abbcf843c 100644 (file)
@@ -94,7 +94,7 @@ unsigned char rc_get_seqnbr(void)
 {
        FILE *sf;
        int tries = 1;
-       int seq_nbr, pos;
+       int seq_nbr, pos, ret;
        char *seqfile = rc_conf_str("seqfile");
 
        if ((sf = fopen(seqfile, "a+")) == NULL)
@@ -135,7 +135,10 @@ unsigned char rc_get_seqnbr(void)
        }
 
        rewind(sf);
-       ftruncate(fileno(sf),0);
+       ret = ftruncate(fileno(sf),0);
+       if (ret != 0) {
+               error("rc_get_seqnbr: couldn't truncate sequence file, %m");
+       }
        fprintf(sf,"%d\n", (seq_nbr+1) & UCHAR_MAX);
 
        fflush(sf); /* fflush because a process may read it between the do_unlock and fclose */
index 871cea060cb0e68cbccd99957ca1e800b55b0e8c..47c172cccf00234b9bcc135a63a14e9a30c7006b 100644 (file)
@@ -525,7 +525,6 @@ int rc_find_server (char *server_name, UINT4 *ip_addr, char *secret)
        if (result == 0)
        {
                memset (buffer, '\0', sizeof (buffer));
-               memset (secret, '\0', sizeof (secret));
                error("rc_find_server: couldn't find RADIUS server %s in %s",
                      server_name, rc_conf_str("servers"));
                return (-1);
index 1dee313bc1cb04a84b46e4f09d86ec6735a3518e..f6a787424afc4fc304f605fb02467b4d055d9700 100644 (file)
@@ -24,6 +24,8 @@ static char const RCSID[] =
 #include "pppd.h"
 #include "radiusclient.h"
 #include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 extern void (*radius_attributes_hook)(VALUE_PAIR *);
 static void print_attributes(VALUE_PAIR *);
@@ -75,9 +77,12 @@ print_attributes(VALUE_PAIR *vp)
     char name[2048];
     char value[2048];
     int cnt = 0;
+    mode_t old_umask;
 
     slprintf(fname, sizeof(fname), "/var/run/radattr.%s", ifname);
+    old_umask = umask(077);
     fp = fopen(fname, "w");
+    umask(old_umask);
     if (!fp) {
        warn("radattr plugin: Could not open %s for writing: %m", fname);
        return;
index 44120e16d0ba120238c30ba9f5b4f11a9bd15b40..254ed904184f150330a0696a532f83a23a8d8f08 100644 (file)
@@ -206,7 +206,7 @@ add_avp(char **argv)
 *  1 -- we are ALWAYS willing to supply a secret. :-)
 * %DESCRIPTION:
 * Tells pppd that we will try to authenticate the peer, and not to
-* worry about looking in /etc/ppp/*-secrets
+* worry about looking in *-secrets file(s)
 ***********************************************************************/
 static int
 radius_secret_check(void)
@@ -597,11 +597,11 @@ radius_setparams(VALUE_PAIR *vp, char *msg, REQUEST_INFO *req_info,
                break;
            case PW_FILTER_ID:
                /* packet filter, will be handled via ip-(up|down) script */
-               script_setenv("RADIUS_FILTER_ID", vp->strvalue, 1);
+               script_setenv("RADIUS_FILTER_ID", (char*) vp->strvalue, 1);
                break;
            case PW_FRAMED_ROUTE:
                /* route, will be handled via ip-(up|down) script */
-               script_setenv("RADIUS_FRAMED_ROUTE", vp->strvalue, 1);
+               script_setenv("RADIUS_FRAMED_ROUTE", (char*) vp->strvalue, 1);
                break;
            case PW_IDLE_TIMEOUT:
                /* idle parameter */
@@ -665,12 +665,12 @@ radius_setparams(VALUE_PAIR *vp, char *msg, REQUEST_INFO *req_info,
 #ifdef CHAPMS
            switch (vp->attribute) {
            case PW_MS_CHAP2_SUCCESS:
-               if ((vp->lvalue != 43) || strncmp(vp->strvalue + 1, "S=", 2)) {
+               if ((vp->lvalue != 43) || strncmp((char*) vp->strvalue + 1, "S=", 2)) {
                    slprintf(msg,BUF_LEN,"RADIUS: bad MS-CHAP2-Success packet");
                    return -1;
                }
                if (message != NULL)
-                   strlcpy(message, vp->strvalue + 1, message_space);
+                   strlcpy(message, (char*) vp->strvalue + 1, message_space);
                ms_chap2_success = 1;
                break;
 
index 0c0ef30f8d37f41309cc395a9d3fad5153130f08..f6012868e2dbbbcb6de5f3a4806088d0c9f761a9 100644 (file)
@@ -104,7 +104,7 @@ static int rc_pack_list (VALUE_PAIR *vp, char *secret, AUTH_HDR *auth)
                    memcpy ((char *) passbuf, vp->strvalue, (size_t) length);
 
                    secretlen = strlen (secret);
-                   vector = (char *)auth->vector;
+                   vector = auth->vector;
                    for(i = 0; i < padded_length; i += AUTH_VECTOR_LEN) {
                        /* Calculate the MD5 digest*/
                        strcpy ((char *) md5buf, secret);
@@ -200,10 +200,10 @@ int rc_send_server (SEND_DATA *data, char *msg, REQUEST_INFO *info)
        AUTH_HDR       *auth, *recv_auth;
        UINT4           auth_ipaddr;
        char           *server_name;    /* Name of server to query */
-       int             salen;
+       socklen_t       salen;
        int             result;
        int             total_length;
-       int             length;
+       socklen_t       length;
        int             retry_max;
        int             secretlen;
        char            secret[MAX_SECRET_LENGTH + 1];
@@ -228,6 +228,7 @@ int rc_send_server (SEND_DATA *data, char *msg, REQUEST_INFO *info)
        {
                if (rc_find_server (server_name, &auth_ipaddr, secret) != 0)
                {
+                       memset (secret, '\0', sizeof (secret));
                        return (ERROR_RC);
                }
        }
@@ -272,7 +273,7 @@ int rc_send_server (SEND_DATA *data, char *msg, REQUEST_INFO *info)
                memset((char *) auth->vector, 0, AUTH_VECTOR_LEN);
                secretlen = strlen (secret);
                memcpy ((char *) auth + total_length, secret, secretlen);
-               rc_md5_calc (vector, (char *) auth, total_length + secretlen);
+               rc_md5_calc (vector, (unsigned char *) auth, total_length + secretlen);
                memcpy ((char *) auth->vector, (char *) vector, AUTH_VECTOR_LEN);
        }
        else
@@ -362,7 +363,7 @@ int rc_send_server (SEND_DATA *data, char *msg, REQUEST_INFO *info)
        {
                if ((vp = rc_avpair_get(vp, PW_REPLY_MESSAGE)))
                {
-                       strcat(msg, vp->strvalue);
+                       strcat(msg, (char*) vp->strvalue);
                        strcat(msg, "\n");
                        vp = vp->next;
                }
@@ -428,7 +429,7 @@ static int rc_check_reply (AUTH_HDR *auth, int bufferlen, char *secret,
        memcpy ((char *) reply_digest, (char *) auth->vector, AUTH_VECTOR_LEN);
        memcpy ((char *) auth->vector, (char *) vector, AUTH_VECTOR_LEN);
        memcpy ((char *) auth + totallen, secret, secretlen);
-       rc_md5_calc (calc_digest, (char *) auth, totallen + secretlen);
+       rc_md5_calc (calc_digest, (unsigned char *) auth, totallen + secretlen);
 
 #ifdef DIGEST_DEBUG
        {
index 751f819ede511e929b98b490a1154769cd778ee1..4065724926ae44a1a1433a2b0ef25e01e9ec35bc 100644 (file)
@@ -78,7 +78,7 @@ rc_mksid (void)
   snprintf(buf, sizeof(buf), "%08lX%04X%02hX",
           (unsigned long int) time (NULL),
           (unsigned int) getpid (),
-          cnt & 0xFF);
+          (unsigned short) (cnt & 0xFF));
   cnt++;
   return buf;
 }
index 8c98e2a82972797219be4ab6c9de814caadb3e14..76db234737e93876f38d97171ab3877aea19c729 100644 (file)
@@ -167,7 +167,7 @@ plugin_init(void)
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-size_t strhex_to_str(char *p, size_t len, const char *strhex)
+size_t strhex_to_str(unsigned char *p, size_t len, const char *strhex)
 {
        size_t i;
        size_t num_chars = 0;
@@ -299,15 +299,20 @@ unsigned int run_ntlm_auth(const char *username,
        if (forkret == 0) {
                /* child process */
                uid_t uid;
+               gid_t gid;
 
                close(child_out[0]);
                close(child_in[1]);
 
                /* run winbind as the user that invoked pppd */
-               setgid(getgid());
+               gid = getgid();
+               if (setgid(gid) == -1 || getgid() != gid) {
+                       fatal("pppd/winbind: could not setgid to %d: %m", gid);
+               }
                uid = getuid();
-               if (setuid(uid) == -1 || getuid() != uid)
+               if (setuid(uid) == -1 || getuid() != uid) {
                        fatal("pppd/winbind: could not setuid to %d: %m", uid);
+               }
                execl("/bin/sh", "sh", "-c", ntlm_auth, NULL);  
                fatal("pppd/winbind: could not exec /bin/sh: %m");
        }
@@ -522,7 +527,7 @@ winbind_chap_verify(char *user, char *ourname, int id,
        char *domain;
        char *username;
        char *p;
-       char saresponse[MS_AUTH_RESPONSE_LENGTH+1];
+       unsigned char saresponse[MS_AUTH_RESPONSE_LENGTH+1];
 
        /* The first byte of each of these strings contains their length */
        challenge_len = *challenge++;
index e1bb8108ea0964d81d0c4b64ead2132e97aa5889..1e00366ba2914f5c1fba36fabd98e17edecaef72 100644 (file)
@@ -96,7 +96,6 @@
 #include <signal.h>
 #include <fcntl.h>
 #include <ctype.h>
-#include <termios.h>
 #include <unistd.h>
 
 /* This is in netdevice.h. However, this compile will fail miserably if
 
 #if !defined(__GLIBC__) || __GLIBC__ >= 2
 #include <asm/types.h>         /* glibc 2 conflicts with linux/types.h */
-#include <asm/ioctls.h>
 #include <net/if.h>
 #include <net/if_arp.h>
 #include <net/route.h>
 #include <sys/locks.h>
 #endif
 
-#ifndef BOTHER
-#define BOTHER 0010000
-#endif
-struct termios2 {
-       unsigned int c_iflag;
-       unsigned int c_oflag;
-       unsigned int c_cflag;
-       unsigned int c_lflag;
-       unsigned char c_line;
-       unsigned char c_cc[19];
-       unsigned int c_ispeed;
-       unsigned int c_ospeed;
-};
+/*
+ * Instead of system header file <termios.h> use local "termios_linux.h" header
+ * file as it provides additional support for arbitrary baud rates via BOTHER.
+ */
+#include "termios_linux.h"
 
 #ifdef INET6
 #ifndef _LINUX_IN6_H
@@ -1053,40 +1043,32 @@ void set_up_tty(int tty_fd, int local)
            cfsetospeed (&tios, speed);
            cfsetispeed (&tios, speed);
            speed = cfgetospeed(&tios);
+           baud_rate = baud_rate_of(speed);
+       } else {
+#ifdef BOTHER
+           tios.c_cflag &= ~CBAUD;
+           tios.c_cflag |= BOTHER;
+           tios.c_ospeed = inspeed;
+#ifdef IBSHIFT
+           /* B0 sets input baudrate to the output baudrate */
+           tios.c_cflag &= ~(CBAUD << IBSHIFT);
+           tios.c_cflag |= B0 << IBSHIFT;
+           tios.c_ispeed = inspeed;
+#endif
+           baud_rate = inspeed;
+#else
+           baud_rate = 0;
+#endif
        }
-       baud_rate = baud_rate_of(speed);
     }
     else {
        speed = cfgetospeed(&tios);
        baud_rate = baud_rate_of(speed);
-    }
-
-    while (tcsetattr(tty_fd, TCSAFLUSH, &tios) < 0 && !ok_error(errno))
-       if (errno != EINTR)
-           fatal("tcsetattr: %m (line %d)", __LINE__);
-    restore_term = 1;
-
-/* Most Linux architectures and drivers support arbitrary baud rate values via BOTHER */
-#ifdef TCGETS2
-    if (!baud_rate) {
-       struct termios2 tios2;
-       if (ioctl(tty_fd, TCGETS2, &tios2) == 0) {
-           if (inspeed) {
-               tios2.c_cflag &= ~CBAUD;
-               tios2.c_cflag |= BOTHER;
-               tios2.c_ispeed = inspeed;
-               tios2.c_ospeed = inspeed;
-#ifdef TCSETS2
-               if (ioctl(tty_fd, TCSETS2, &tios2) == 0)
-                   baud_rate = inspeed;
+#ifdef BOTHER
+       if (!baud_rate)
+           baud_rate = tios.c_ospeed;
 #endif
-           } else {
-               if ((tios2.c_cflag & CBAUD) == BOTHER && tios2.c_ospeed)
-                   baud_rate = tios2.c_ospeed;
-           }
-       }
     }
-#endif
 
 /*
  * We can't proceed if the serial port baud rate is unknown,
@@ -1098,6 +1080,11 @@ void set_up_tty(int tty_fd, int local)
        else
            fatal("Baud rate for %s is 0; need explicit baud rate", devnam);
     }
+
+    while (tcsetattr(tty_fd, TCSAFLUSH, &tios) < 0 && !ok_error(errno))
+       if (errno != EINTR)
+           fatal("tcsetattr: %m (line %d)", __LINE__);
+    restore_term = 1;
 }
 
 /********************************************************************
@@ -3143,7 +3130,7 @@ int cif6addr (int unit, eui64_t our_eui64, eui64_t his_eui64)
 int
 get_pty(int *master_fdp, int *slave_fdp, char *slave_name, int uid)
 {
-    int i, mfd, sfd = -1;
+    int i, mfd, ret, sfd = -1;
     char pty_name[16];
     struct termios tios;
 
@@ -3181,8 +3168,14 @@ get_pty(int *master_fdp, int *slave_fdp, char *slave_name, int uid)
                pty_name[5] = 't';
                sfd = open(pty_name, O_RDWR | O_NOCTTY, 0);
                if (sfd >= 0) {
-                   fchown(sfd, uid, -1);
-                   fchmod(sfd, S_IRUSR | S_IWUSR);
+                   ret = fchown(sfd, uid, -1);
+                   if (ret != 0) {
+                       warn("Couldn't change ownership of %s, %m", pty_name);
+                   }
+                   ret = fchmod(sfd, S_IRUSR | S_IWUSR);
+                   if (ret != 0) {
+                       warn("Couldn't change permissions of %s, %m", pty_name);
+                   }
                    break;
                }
                close(mfd);
diff --git a/pppd/termios_linux.h b/pppd/termios_linux.h
new file mode 100644 (file)
index 0000000..9c79d16
--- /dev/null
@@ -0,0 +1,194 @@
+/* SPDX-License-Identifier: GPL-2.0+ OR BSD-4-Clause OR BSD-3-Clause OR BSD-2-Clause */
+/*
+ * termios fuctions to support arbitrary baudrates (on Linux)
+ *
+ * Copyright (c) 2021 Pali Rohár <pali@kernel.org>
+ * Copyright (c) 2021 Marek Behún <kabel@kernel.org>
+ */
+
+#ifndef _TERMIOS_LINUX_H_
+#define _TERMIOS_LINUX_H_
+
+/*
+ * We need to use raw TCGETS2/TCSETS2 or TCGETS/TCSETS ioctls with the BOTHER
+ * flag in struct termios2/termios, defined in Linux headers <asm/ioctls.h>
+ * and <asm/termbits.h>. Since these headers conflict with glibc's header file
+ * <termios.h>, it is not possible to use libc's termios functions and we need
+ * to reimplement them via ioctl() calls.
+ *
+ * An arbitrary baudrate is supported when the macro BOTHER is defined. The
+ * baudrate value itself is then stored into the c_ospeed and c_ispeed members.
+ * If ioctls TCGETS2/TCSETS2 are defined and supported then these fields are
+ * present in struct termios2, otherwise these fields are present in struct
+ * termios.
+ *
+ * Note that the Bnnn constants from <termios.h> need not be compatible with
+ * Bnnn constants from <asm/termbits.h>.
+ */
+
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <asm/ioctls.h>
+#include <asm/termbits.h>
+
+#if defined(BOTHER) && defined(TCGETS2)
+#define termios termios2
+#endif
+
+static inline int tcgetattr(int fd, struct termios *t)
+{
+#if defined(BOTHER) && defined(TCGETS2)
+       return ioctl(fd, TCGETS2, t);
+#else
+       return ioctl(fd, TCGETS, t);
+#endif
+}
+
+static inline int tcsetattr(int fd, int a, const struct termios *t)
+{
+       int cmd;
+
+       switch (a) {
+#if defined(BOTHER) && defined(TCGETS2)
+       case TCSANOW:
+               cmd = TCSETS2;
+               break;
+       case TCSADRAIN:
+               cmd = TCSETSW2;
+               break;
+       case TCSAFLUSH:
+               cmd = TCSETSF2;
+               break;
+#else
+       case TCSANOW:
+               cmd = TCSETS;
+               break;
+       case TCSADRAIN:
+               cmd = TCSETSW;
+               break;
+       case TCSAFLUSH:
+               cmd = TCSETSF;
+               break;
+#endif
+       default:
+               errno = EINVAL;
+               return -1;
+       }
+
+       return ioctl(fd, cmd, t);
+}
+
+static inline int tcdrain(int fd)
+{
+       return ioctl(fd, TCSBRK, 1);
+}
+
+static inline int tcflush(int fd, int q)
+{
+       return ioctl(fd, TCFLSH, q);
+}
+
+static inline int tcsendbreak(int fd, int d)
+{
+#ifdef TCSBRKP
+       return ioctl(fd, TCSBRKP, d);
+#else
+       return ioctl(fd, TCSBRK, 0);
+#endif
+}
+
+static inline int tcflow(int fd, int a)
+{
+       return ioctl(fd, TCXONC, a);
+}
+
+static inline pid_t tcgetsid(int fd)
+{
+       pid_t sid;
+
+       if (ioctl(fd, TIOCGSID, &sid) < 0)
+               return (pid_t)-1;
+
+       return sid;
+}
+
+static inline speed_t cfgetospeed(const struct termios *t)
+{
+       return t->c_cflag & CBAUD;
+}
+
+static inline int cfsetospeed(struct termios *t, speed_t s)
+{
+       if (s & ~CBAUD) {
+               errno = EINVAL;
+               return -1;
+       }
+
+       t->c_cflag &= ~CBAUD;
+       t->c_cflag |= s;
+
+       return 0;
+}
+
+#ifdef IBSHIFT
+static inline speed_t cfgetispeed(const struct termios *t)
+{
+       speed_t s = (t->c_cflag >> IBSHIFT) & CBAUD;
+
+       if (s == B0)
+               return cfgetospeed(t);
+       else
+               return s;
+}
+
+static inline int cfsetispeed(struct termios *t, speed_t s)
+{
+       if (s == 0)
+               s = B0;
+
+       if (s & ~CBAUD) {
+               errno = EINVAL;
+               return -1;
+       }
+
+       t->c_cflag &= ~(CBAUD << IBSHIFT);
+       t->c_cflag |= s << IBSHIFT;
+
+       return 0;
+}
+#else /* !IBSHIFT */
+static inline speed_t cfgetispeed(const struct termios *t)
+{
+       return cfgetospeed(t);
+}
+
+static inline int cfsetispeed(struct termios *t, speed_t s)
+{
+       return cfsetospeed(t, s);
+}
+#endif /* !IBSHIFT */
+
+static inline int cfsetspeed(struct termios *t, speed_t s)
+{
+       if (cfsetospeed(t, s))
+               return -1;
+#ifdef IBSHIFT
+       if (cfsetispeed(t, s))
+               return -1;
+#endif
+
+       return 0;
+}
+
+static void cfmakeraw(struct termios *t)
+{
+       t->c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR |
+                       ICRNL | IXON);
+       t->c_oflag &= ~OPOST;
+       t->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
+       t->c_cflag &= ~(CSIZE | PARENB);
+       t->c_cflag |= CS8;
+}
+
+#endif /* _TERMIOS_LINUX_H_ */
index 41328fbaacdbb202c68a80a4f75b1e8887a85506..7e208badaff078c20c3ed8345c12778c769f5fbf 100644 (file)
@@ -909,7 +909,7 @@ open_socket(char *dest)
 static int
 start_charshunt(int ifd, int ofd)
 {
-    int cpid;
+    int cpid, ret;
 
     cpid = safe_fork(ifd, ofd, (log_to_fd >= 0? log_to_fd: 2));
     if (cpid == -1) {
@@ -923,10 +923,14 @@ start_charshunt(int ifd, int ofd)
            log_to_fd = -1;
        else if (log_to_fd >= 0)
            log_to_fd = 2;
-       setgid(getgid());
-       setuid(uid);
-       if (getuid() != uid)
-           fatal("setuid failed");
+       ret = setgid(getgid());
+       if (ret != 0) {
+               fatal("setgid failed, %m");
+       }
+       ret = setuid(uid);
+       if (ret != 0 || getuid() != uid) {
+               fatal("setuid failed, %m");
+       }
        charshunt(0, 1, record_file);
        exit(0);
     }
index fd213c2044725993565f8352d9e6e05959d70292..e75bb9c8eecd21279a999c18f8c0bc4f132ef1e3 100644 (file)
@@ -819,7 +819,7 @@ lock(char *dev)
 #else /* LOCKLIB */
 
     char lock_buffer[12];
-    int fd, pid, n;
+    int fd, pid, n, siz;
 
 #ifdef SVR4
     struct stat sbuf;
@@ -906,11 +906,16 @@ lock(char *dev)
 
     pid = getpid();
 #ifndef LOCK_BINARY
+    siz = 11;
     slprintf(lock_buffer, sizeof(lock_buffer), "%10d\n", pid);
-    write (fd, lock_buffer, 11);
+    n = write (fd, lock_buffer, siz);
 #else
-    write(fd, &pid, sizeof (pid));
+    siz = sizeof (pid);
+    n = write(fd, &pid, siz);
 #endif
+    if (n != siz) {
+       error("Could not write pid to lock file when locking");
+    }
     close(fd);
     return 0;
 
@@ -934,7 +939,7 @@ relock(int pid)
     return -1;
 #else /* LOCKLIB */
 
-    int fd;
+    int fd, n, siz;
     char lock_buffer[12];
 
     if (lock_file[0] == 0)
@@ -947,11 +952,16 @@ relock(int pid)
     }
 
 #ifndef LOCK_BINARY
+    siz = 11;
     slprintf(lock_buffer, sizeof(lock_buffer), "%10d\n", pid);
-    write (fd, lock_buffer, 11);
+    n = write (fd, lock_buffer, siz);
 #else
-    write(fd, &pid, sizeof(pid));
+    siz = sizeof(pid);
+    n = write(fd, &pid, siz);
 #endif /* LOCK_BINARY */
+    if (n != siz) {
+       error("Could not write pid to lock file when locking");
+    }
     close(fd);
     return 0;