From 04c2931bb963fefd4654ef2de2cf0667cf8a333d Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Tue, 7 Dec 2010 17:58:15 +0200 Subject: Rewrite prog stream support. Two interfaces are provided: mu_prog_stream_create offers full control over the program execution environment (i.e. running privileges, cwd, resource limits) via a set of hints. A simpler interface, mu_command_stream_create, runs the command in the current environment. mu_filter_prog_stream_create is removed, because its functionality can be achieved by a correspondingly crafted set of hints to mu_prog_stream_create. * include/mailutils/prog.h: New file. * include/mailutils/mailutils.h: Include mailutils/prog.h * include/mailutils/Makefile.am (pkginclude_HEADERS): Add prog.h * include/mailutils/stream.h (mu_prog_stream_create) (mu_filter_prog_stream_create): Remove prototypes. * include/mailutils/sys/prog_stream.h (_mu_prog_stream): Change structure. (_mu_prog_limit_codes, _mu_prog_limit_flags): New externs. * include/mailutils/util.h (mu_set_user_privileges) (mu_switch_to_privs): New prototypes. * lib/userprivs.c: Move to libmailutils/base. * lib/Makefile.am (libmuaux_a_SOURCES): Remove userprivs.c * libmailutils/base/Makefile.am (libbase_la_SOURCES): Add userprivs.c * libmailutils/base/userprivs.c (mu_set_user_privileges): New function. (mu_switch_to_privs): Rewrite as another entry point to mu_set_user_privileges. * libmailutils/stream/prog_stream.c (_mu_prog_limit_flags) (_mu_prog_limit_codes): New global variables. (start_program_filter): Use hints to control execution environment. (_prog_stream_create): Save hints. (mu_prog_stream_create): Change signature. (mu_command_stream_create): New function (corresponds to the prior mu_prog_stream_create). (mu_filter_prog_stream_create): Remove function. * comsat/action.c (action_exec): Use new mu_prog_stream_create calling convention. * examples/murun.c: Rewrite. * mh/mhn.c (show_internal): Use new mu_prog_stream_create calling convention. * mh/tests/mhn.at: Reflect changes to mhn. * imap4d/preauth.c: Use mu_command_stream_create. * libmu_sieve/extensions/pipe.c * mail/decode.c * mail/pipe.c * mail/send.c * mh/mhl.c * mu/shell.c * mail/mail.h: Include mailutils/prog.h * mh/mh.h * po/POTFILES.in: Add libmailutils/base/userprivs.c. --- comsat/action.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'comsat') diff --git a/comsat/action.c b/comsat/action.c index 97f961c7f..dcb256304 100644 --- a/comsat/action.c +++ b/comsat/action.c @@ -18,6 +18,7 @@ #include "comsat.h" #include #include +#include #define obstack_chunk_alloc malloc #define obstack_chunk_free free #include @@ -225,7 +226,6 @@ action_exec (mu_stream_t tty, int argc, char **argv) { mu_stream_t pstream; struct stat stb; - char *command; int status; if (argc == 0) @@ -249,25 +249,19 @@ action_exec (mu_stream_t tty, int argc, char **argv) if (stb.st_mode & (S_ISUID|S_ISGID)) { - mu_diag_output (MU_DIAG_ERROR, _("will not execute set[ug]id programs")); + mu_diag_output (MU_DIAG_ERROR, + _("will not execute set[ug]id programs")); return; } - /* FIXME: Redirect stderr to out */ - /* FIXME: need this: - status = mu_prog_stream_create_argv (&pstream, argv[0], argv, - MU_STREAM_READ); - */ - status = mu_argcv_join (argc, argv, " ", mu_argcv_escape_no, &command); + status = mu_prog_stream_create (&pstream, + argv[0], argc, argv, + MU_PROG_HINT_ERRTOOUT, + NULL, + MU_STREAM_READ); if (status) { - mu_diag_funcall (MU_DIAG_ERROR, "mu_argcv_join", NULL, status); - return; - } - status = mu_prog_stream_create (&pstream, command, MU_STREAM_READ); - if (status) - { - mu_diag_funcall (MU_DIAG_ERROR, "mu_prog_stream_create_argv", argv[0], + mu_diag_funcall (MU_DIAG_ERROR, "mu_prog_stream_create", argv[0], status); return; } -- cgit v1.2.1