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"
51 extern int tgetpass_flags; /* XXX */
54 * Sudo conversation function.
57 sudo_conversation(int num_msgs, const struct sudo_conv_message msgs[],
58 struct sudo_conv_reply replies[])
60 struct sudo_conv_reply *repl;
61 const struct sudo_conv_message *msg;
63 int n, flags = tgetpass_flags;
65 for (n = 0; n < num_msgs; n++) {
68 switch (msg->msg_type & 0xff) {
69 case SUDO_CONV_PROMPT_ECHO_ON:
70 case SUDO_CONV_PROMPT_MASK:
71 if (msg->msg_type == SUDO_CONV_PROMPT_ECHO_ON)
76 case SUDO_CONV_PROMPT_ECHO_OFF:
77 if (ISSET(msg->msg_type, SUDO_CONV_PROMPT_ECHO_OK))
78 SET(flags, TGP_NOECHO_TRY);
79 /* Read the password unless interrupted. */
80 pass = tgetpass(msg->msg, msg->timeout, flags);
83 repl->reply = estrdup(pass);
84 zero_bytes(pass, strlen(pass));
86 case SUDO_CONV_INFO_MSG:
88 (void) fputs(msg->msg, stdout);
90 case SUDO_CONV_ERROR_MSG:
92 (void) fputs(msg->msg, stderr);
102 /* Zero and free allocated memory and return an error. */
105 if (repl->reply != NULL) {
106 zero_bytes(repl->reply, strlen(repl->reply));
116 _sudo_printf(int msg_type, const char *fmt, ...)
123 case SUDO_CONV_INFO_MSG:
126 case SUDO_CONV_ERROR_MSG:
135 len = vfprintf(fp, fmt, ap);