Print this page
10125 smatch fixes for cmd-inet
   1 /*
   2  * passprompt.c - pppd plugin to invoke an external PAP password prompter
   3  *
   4  * Copyright 1999 Paul Mackerras, Alan Curry.
   5  *
   6  *  This program is free software; you can redistribute it and/or
   7  *  modify it under the terms of the GNU General Public License
   8  *  as published by the Free Software Foundation; either version
   9  *  2 of the License, or (at your option) any later version.
  10  */





  11 #include <errno.h>
  12 #include <unistd.h>
  13 #include <fcntl.h>
  14 #include <sys/wait.h>
  15 #include <syslog.h>
  16 #include "pppd.h"
  17 
  18 static char promptprog[PATH_MAX+1];
  19 
  20 static option_t options[] = {
  21     { "promptprog", o_string, promptprog,
  22       "External PAP password prompting program",
  23       OPT_STATIC, NULL, PATH_MAX },
  24     { NULL }
  25 };
  26 
  27 static int promptpass(char *user, char *passwd)
  28 {
  29     int p[2];
  30     pid_t kid;


  53         char *argv[5], fdstr[32];
  54 
  55         sys_close();
  56         closelog();
  57         if (detached && p[1] <= 2) {
  58             (void) dup2(p[1], 3);
  59             p[1] = 3;
  60         }
  61         (void) close(p[0]);
  62         if (detached) {
  63             red = open("/etc/ppp/prompt-errors", O_WRONLY | O_APPEND | O_CREAT,
  64                 0600);
  65             (void) dup2(red, 1);
  66             (void) dup2(red, 2);
  67         }
  68         (void) seteuid(getuid());
  69         (void) setegid(getgid());
  70         argv[0] = promptprog;
  71         argv[1] = user == NULL ? "" : user;
  72         argv[2] = remote_name;
  73         slprintf(fdstr, sizeof (fdstr), "%d", p[1]);
  74         argv[3] = fdstr;
  75         argv[4] = NULL;
  76         (void) execv(*argv, argv);
  77         _exit(127);
  78     }
  79 
  80     /* we are the parent, read the password from the pipe */
  81     (void) close(p[1]);
  82     readgood = 0;
  83     do {
  84         red = read(p[0], passwd + readgood, MAXSECRETLEN-1 - readgood);
  85         if (red == 0)
  86             break;
  87         if (red < 0) {
  88             if (errno == EINTR)
  89                 continue;
  90             error("Can't read secret from %s: %m", promptprog);
  91             readgood = -1;
  92             break;
  93         }


   1 /*
   2  * passprompt.c - pppd plugin to invoke an external PAP password prompter
   3  *
   4  * Copyright 1999 Paul Mackerras, Alan Curry.
   5  *
   6  *  This program is free software; you can redistribute it and/or
   7  *  modify it under the terms of the GNU General Public License
   8  *  as published by the Free Software Foundation; either version
   9  *  2 of the License, or (at your option) any later version.
  10  */
  11 
  12 /*
  13  * Copyright (c) 2018, Joyent, Inc.
  14  */
  15 
  16 #include <errno.h>
  17 #include <unistd.h>
  18 #include <fcntl.h>
  19 #include <sys/wait.h>
  20 #include <syslog.h>
  21 #include "pppd.h"
  22 
  23 static char promptprog[PATH_MAX+1];
  24 
  25 static option_t options[] = {
  26     { "promptprog", o_string, promptprog,
  27       "External PAP password prompting program",
  28       OPT_STATIC, NULL, PATH_MAX },
  29     { NULL }
  30 };
  31 
  32 static int promptpass(char *user, char *passwd)
  33 {
  34     int p[2];
  35     pid_t kid;


  58         char *argv[5], fdstr[32];
  59 
  60         sys_close();
  61         closelog();
  62         if (detached && p[1] <= 2) {
  63             (void) dup2(p[1], 3);
  64             p[1] = 3;
  65         }
  66         (void) close(p[0]);
  67         if (detached) {
  68             red = open("/etc/ppp/prompt-errors", O_WRONLY | O_APPEND | O_CREAT,
  69                 0600);
  70             (void) dup2(red, 1);
  71             (void) dup2(red, 2);
  72         }
  73         (void) seteuid(getuid());
  74         (void) setegid(getgid());
  75         argv[0] = promptprog;
  76         argv[1] = user == NULL ? "" : user;
  77         argv[2] = remote_name;
  78         (void) slprintf(fdstr, sizeof (fdstr), "%d", p[1]);
  79         argv[3] = fdstr;
  80         argv[4] = NULL;
  81         (void) execv(*argv, argv);
  82         _exit(127);
  83     }
  84 
  85     /* we are the parent, read the password from the pipe */
  86     (void) close(p[1]);
  87     readgood = 0;
  88     do {
  89         red = read(p[0], passwd + readgood, MAXSECRETLEN-1 - readgood);
  90         if (red == 0)
  91             break;
  92         if (red < 0) {
  93             if (errno == EINTR)
  94                 continue;
  95             error("Can't read secret from %s: %m", promptprog);
  96             readgood = -1;
  97             break;
  98         }