From 781a054ab942e1570d7bcff5edc3ceb5c94bf6b8 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sun, 21 Feb 2010 14:19:22 -0500 Subject: [PATCH] Log input and output to temp files for proof of concept. --- plugins/sample/sample_plugin.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/plugins/sample/sample_plugin.c b/plugins/sample/sample_plugin.c index c1d0d5d92..b4f12bbc8 100644 --- a/plugins/sample/sample_plugin.c +++ b/plugins/sample/sample_plugin.c @@ -39,6 +39,10 @@ # include # endif #endif /* HAVE_STRING_H */ +#ifdef HAVE_UNISTD_H +# include +#endif /* HAVE_UNISTD_H */ +#include #include #include @@ -55,6 +59,7 @@ static struct plugin_state { char * const *user_info; } plugin_state; static sudo_conv_t sudo_conv; +static FILE *input, *output; #undef TRUE #define TRUE 1 @@ -247,14 +252,32 @@ io_open(unsigned int version, sudo_conv_t conversation, char * const settings[], char * const user_info[], char * const user_env[]) { - /* TODO: something here */ + int fd; + char path[PATH_MAX]; + + /* Open input and output files. */ + snprintf(path, sizeof(path), "/var/tmp/sample-%u.output", + (unsigned int)getpid()); + fd = open(path, O_WRONLY|O_CREAT|O_EXCL, 0644); + if (fd == -1) + return FALSE; + output = fdopen(fd, "w"); + + snprintf(path, sizeof(path), "/var/tmp/sample-%u.input", + (unsigned int)getpid()); + fd = open(path, O_WRONLY|O_CREAT|O_EXCL, 0644); + if (fd == -1) + return FALSE; + input = fdopen(fd, "w"); + return TRUE; } static void io_close(int exit_status, int error) { - /* TODO: something here */ + fclose(input); + fclose(output); } static int @@ -267,14 +290,14 @@ io_version(int verbose) static int io_log_input(const char *buf, unsigned int len) { - /* log nothing for now */ + fwrite(buf, len, 1, input); return TRUE; } static int io_log_output(const char *buf, unsigned int len) { - /* log nothing for now */ + fwrite(buf, len, 1, output); return TRUE; } -- 2.50.1