Print this page
10125 smatch fixes for cmd-inet
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/cmd-inet/usr.bin/pppd/plugins/passprompt.c
+++ new/usr/src/cmd/cmd-inet/usr.bin/pppd/plugins/passprompt.c
1 1 /*
2 2 * passprompt.c - pppd plugin to invoke an external PAP password prompter
3 3 *
4 4 * Copyright 1999 Paul Mackerras, Alan Curry.
5 5 *
6 6 * This program is free software; you can redistribute it and/or
7 7 * modify it under the terms of the GNU General Public License
8 8 * as published by the Free Software Foundation; either version
9 9 * 2 of the License, or (at your option) any later version.
10 10 */
11 +
12 +/*
13 + * Copyright (c) 2018, Joyent, Inc.
14 + */
15 +
11 16 #include <errno.h>
12 17 #include <unistd.h>
13 18 #include <fcntl.h>
14 19 #include <sys/wait.h>
15 20 #include <syslog.h>
16 21 #include "pppd.h"
17 22
18 23 static char promptprog[PATH_MAX+1];
19 24
20 25 static option_t options[] = {
21 26 { "promptprog", o_string, promptprog,
22 27 "External PAP password prompting program",
23 28 OPT_STATIC, NULL, PATH_MAX },
24 29 { NULL }
25 30 };
26 31
27 32 static int promptpass(char *user, char *passwd)
28 33 {
29 34 int p[2];
30 35 pid_t kid;
31 36 int readgood, wstat;
32 37 int red;
33 38
34 39 if (promptprog[0] == 0 || access(promptprog, X_OK) < 0)
35 40 return -1; /* sorry, can't help */
36 41
37 42 /* This occurs when we're probed for the ability to supply a password */
38 43 if (user != NULL && passwd == NULL)
39 44 return 1;
40 45
41 46 if (pipe(p)) {
42 47 warn("Can't make a pipe for %s", promptprog);
43 48 return 0;
44 49 }
45 50 if ((kid = fork()) == (pid_t) -1) {
46 51 warn("Can't fork to run %s", promptprog);
47 52 (void) close(p[0]);
48 53 (void) close(p[1]);
49 54 return 0;
50 55 }
51 56 if (kid == (pid_t)0) {
52 57 /* we are the child, exec the program */
53 58 char *argv[5], fdstr[32];
54 59
55 60 sys_close();
56 61 closelog();
57 62 if (detached && p[1] <= 2) {
58 63 (void) dup2(p[1], 3);
59 64 p[1] = 3;
60 65 }
61 66 (void) close(p[0]);
62 67 if (detached) {
↓ open down ↓ |
42 lines elided |
↑ open up ↑ |
63 68 red = open("/etc/ppp/prompt-errors", O_WRONLY | O_APPEND | O_CREAT,
64 69 0600);
65 70 (void) dup2(red, 1);
66 71 (void) dup2(red, 2);
67 72 }
68 73 (void) seteuid(getuid());
69 74 (void) setegid(getgid());
70 75 argv[0] = promptprog;
71 76 argv[1] = user == NULL ? "" : user;
72 77 argv[2] = remote_name;
73 - slprintf(fdstr, sizeof (fdstr), "%d", p[1]);
78 + (void) slprintf(fdstr, sizeof (fdstr), "%d", p[1]);
74 79 argv[3] = fdstr;
75 80 argv[4] = NULL;
76 81 (void) execv(*argv, argv);
77 82 _exit(127);
78 83 }
79 84
80 85 /* we are the parent, read the password from the pipe */
81 86 (void) close(p[1]);
82 87 readgood = 0;
83 88 do {
84 89 red = read(p[0], passwd + readgood, MAXSECRETLEN-1 - readgood);
85 90 if (red == 0)
86 91 break;
87 92 if (red < 0) {
88 93 if (errno == EINTR)
89 94 continue;
90 95 error("Can't read secret from %s: %m", promptprog);
91 96 readgood = -1;
92 97 break;
93 98 }
94 99 readgood += red;
95 100 } while (readgood < MAXSECRETLEN - 1);
96 101 passwd[readgood] = 0;
97 102 (void) close(p[0]);
98 103
99 104 /* now wait for child to exit */
100 105 while (waitpid(kid, &wstat, 0) < 0) {
101 106 if (errno != EINTR) {
102 107 warn("error waiting for %s: %m", promptprog);
103 108 break;
104 109 }
105 110 }
106 111
107 112 if (readgood < 0)
108 113 return 0;
109 114 if (readgood > 0 && passwd[--readgood] == '\n')
110 115 passwd[readgood] = '\0';
111 116 if (!WIFEXITED(wstat))
112 117 warn("%s terminated abnormally", promptprog);
113 118 if (WEXITSTATUS(wstat) != 0)
114 119 warn("%s exited with code %d", promptprog, WEXITSTATUS(wstat));
115 120
116 121 return 1;
117 122 }
118 123
119 124 void plugin_init(void)
120 125 {
121 126 add_options(options);
122 127 pap_passwd_hook = promptpass;
123 128 }
↓ open down ↓ |
40 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX