2 * Copyright (c) 1999-2005, 2007-2010 Todd C. Miller <Todd.Miller@courtesan.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 * Sponsored in part by the Defense Advanced Research Projects
17 * Agency (DARPA) and Air Force Research Laboratory, Air Force
18 * Materiel Command, USAF, under agreement number F39502-99-1-0512.
23 #include <sys/types.h>
24 #include <sys/param.h>
33 #endif /* STDC_HEADERS */
35 # if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS)
39 #endif /* HAVE_STRING_H */
42 #endif /* HAVE_STRINGS_H */
45 #endif /* HAVE_UNISTD_H */
49 #include "sudo_plugin.h"
50 #include "sudo_plugin_int.h"
52 extern int tgetpass_flags; /* XXX */
54 #if defined(HAVE_DLOPEN) || defined(HAVE_SHL_LOAD)
55 sudo_conv_t sudo_conv; /* NULL in sudo front-end */
59 * Sudo conversation function.
62 sudo_conversation(int num_msgs, const struct sudo_conv_message msgs[],
63 struct sudo_conv_reply replies[])
65 struct sudo_conv_reply *repl;
66 const struct sudo_conv_message *msg;
68 int n, flags = tgetpass_flags;
70 for (n = 0; n < num_msgs; n++) {
73 switch (msg->msg_type & 0xff) {
74 case SUDO_CONV_PROMPT_ECHO_ON:
75 case SUDO_CONV_PROMPT_MASK:
76 if (msg->msg_type == SUDO_CONV_PROMPT_ECHO_ON)
81 case SUDO_CONV_PROMPT_ECHO_OFF:
82 if (ISSET(msg->msg_type, SUDO_CONV_PROMPT_ECHO_OK))
83 SET(flags, TGP_NOECHO_TRY);
84 /* Read the password unless interrupted. */
85 pass = tgetpass(msg->msg, msg->timeout, flags);
88 repl->reply = estrdup(pass);
89 zero_bytes(pass, strlen(pass));
91 case SUDO_CONV_INFO_MSG:
93 (void) fputs(msg->msg, stdout);
95 case SUDO_CONV_ERROR_MSG:
97 (void) fputs(msg->msg, stderr);
99 case SUDO_CONV_DEBUG_MSG:
101 sudo_debug_write(msg->msg, strlen(msg->msg), 0);
111 /* Zero and free allocated memory and return an error. */
114 if (repl->reply != NULL) {
115 zero_bytes(repl->reply, strlen(repl->reply));
125 _sudo_printf(int msg_type, const char *fmt, ...)
132 case SUDO_CONV_INFO_MSG:
135 case SUDO_CONV_ERROR_MSG:
144 len = vfprintf(fp, fmt, ap);