Add pointer to a printf like function to plugin open functon.

This can be used instead of the conversation function to display
info and error messages.
This commit is contained in:
Todd C. Miller
2010-05-04 19:17:31 -04:00
parent b60b28abd1
commit 9fbec34fed
11 changed files with 160 additions and 157 deletions

View File

@@ -44,6 +44,7 @@
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif /* HAVE_UNISTD_H */
#include <errno.h>
#include "sudo.h"
#include "sudo_plugin.h"
@@ -89,7 +90,7 @@ sudo_conversation(int num_msgs, const struct sudo_conv_message msgs[],
}
}
return(0);
return 0;
err:
/* Zero and free allocated memory and return an error. */
@@ -102,5 +103,30 @@ err:
}
} while (n--);
return(-1);
return -1;
}
int
sudo_printf(int msg_type, const char *fmt, ...)
{
va_list ap;
FILE *fp;
switch (msg_type) {
case SUDO_CONV_INFO_MSG:
fp = stdout;
break;
case SUDO_CONV_ERROR_MSG:
fp = stderr;
break;
default:
errno = EINVAL;
return -1;
}
va_start(ap, fmt);
vfprintf(fp, fmt, ap);
va_end(ap);
return 0;
}