[Dovecot] xexec and dovecot 1.1
subscriber@viliar.net.ru schreef:
I'll test very interesting plugin xexec. It seems very nice and can be used in many things. It's compiled perfect with dovecot 1.0, but certanly not with dovecot 1.1. It's stopped with next error:
I did not write that module, but tonight I got a bit bored, so I gave it a quick try to port it to Dovecot 1.1. The attached patch provides a compile fix to make it compile without warnings for dovecot-1.1. I only tested whether the module is successfully loaded by Dovecot and not whether XEXEC still does what it is supposed to. It does not segfault on the xexec command, but that is all I tested. I got a backend command error and now it is bed time for me, but there is a good chance that this works if you bother to read the wiki page properly ;) So, consider this to be more like an 'It compiles! Ship it!' kind of fix. But, anyways, it should help you to get where you want.
Just apply inside the xexec directory using the usual patch -p1. Let me know what you find out.
Regards,
Stephan.
Thank you, Stephan, for your help. Patch applies without any problem and compilation was successful. According maillog, Dovecot load it without problems too:
Mar 19 09:06:37 mx3 dovecot: IMAP(alx@skymail.alx.in): Module loaded: /usr/lib/dovecot/imap/lib10_xexec_plugin.so I have activate it in config as for dovecot 1.0. But "sub commands" does not started:
[root@mx3 rpms]# telnet 127.0.0.1 143 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'.
- OK Dovecot ready. 001 login alx@xxx xxxxxxx 001 OK Logged in. 002 noop 003 OK NOOP completed. 003 noop 003 OK NOOP completed. 004 xexec user 004 NO command failed
same command exucuted ok with dovecot 1.0. from config: plugin { xexec2 = user:/usr/local/bin/user %u }
According strace -vfF -p there is segfault :-(
read(0, "004 xexec user\r\n", 4044) = 16
pipe([6, 7]) = 0
pipe([8, 9]) = 0
pipe([10, 11]) = 0
clone(Process 4093 attached
child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD,
child_tidptr=0xb7f17708) = 4093
[pid 4061] close(6) = 0
[pid 4061] close(9) = 0
[pid 4061] close(11) = 0
[pid 4061] _llseek(7, 0, 0xbfb8ca40, SEEK_CUR) = -1 ESPIPE (Illegal seek)
[pid 4061] getsockname(7, 0xbfb8ca34, [28]) = -1 ENOTSOCK (Socket
operation on non-socket)
[pid 4061] fstat64(8, {st_dev=makedev(0, 5), st_ino=5022779,
st_mode=S_IFIFO|0600, st_nlink=1, st_uid=2004, st_gid=12, st_blksize=4096,
st_blocks=0, st_size=0, st_atime=2008/03/19-09:08:00,
st_mtime=2008/03/19-09:08:00, st_ctime=2008/03/19-09:08:00}) = 0
[pid 4061] fstat64(10, {st_dev=makedev(0, 5), st_ino=5022780,
st_mode=S_IFIFO|0600, st_nlink=1, st_uid=2004, st_gid=12, st_blksize=4096,
st_blocks=0, st_size=0, st_atime=2008/03/19-09:08:00,
st_mtime=2008/03/19-09:08:00, st_ctime=2008/03/19-09:08:00}) = 0
[pid 4061] gettimeofday({1205932080, 941409}, {4294967116, 0}) = 0 [pid
4061] select(11, [8 10], [], [8 10], {2147483, 0}
I will try to use gdb to attach proccess and found something.
DOH! Forgot to CC to the mailinglist: subscriber@viliar.net.ru schreef:subscriber@viliar.net.ru schreef:
subscriber@viliar.net.ru schreef: Thank you, Stephan, for your help. Patch applies without any problem and compilation was successful. According maillog, Dovecot load it without problems too:
Mar 19 09:06:37 mx3 dovecot: IMAP(alx@skymail.alx.in): Module loaded: /usr/lib/dovecot/imap/lib10_xexec_plugin.so I have activate it in config as for dovecot 1.0. But "sub commands" does not started:
...
[pid 4093] --- SIGSEGV (Segmentation fault) @ 0 (0) --- Process 4093 detached <... select resumed> ) = 2 (in [8 10], left {2147482, 996000}) --- SIGCHLD (Child exited) @ 0 (0) -- Found it, apparently dovecot-1.1 does not like a NULL parameter to the array_get function anymore:
- execvp(*(char **)array_idx(&command, 0), array_get(&command, NULL)); + execvp(*(char **)array_idx(&command, 0), array_idx(&command, 0)); With this additional change, the attached full patch manages to update the XEXEC plugin to dovecot-1.1. This was tested with the 'average' example and that worked flawlessly. Regards, Stephan Updated module to dovecot-1.1 diff -r 7cafabf38524 cmd-xexec.c --- a/cmd-xexec.c Wed Mar 19 00:58:24 2008 +0100 +++ b/cmd-xexec.c Fri Mar 21 18:12:26 2008 +0100 @@ -128,10 +128,10 @@ static void cmd_xexec_stderr(void *conte bool cmd_xexec(struct client_command_context *cmd) { - struct imap_arg * imap_args; + const struct imap_arg *imap_args; const char *imap_command; char **backend_command; - array_t ARRAY_DEFINE(command, char *); + ARRAY_DEFINE(command, char *); pid_t pid; int status; int pipe_in[2]; @@ -177,12 +177,13 @@ bool cmd_xexec(struct client_command_con return FALSE; } - ARRAY_CREATE(&command, unsafe_data_stack_pool, char *, 8); + t_array_init(&command, 8); - array_append(&command, backend_command, strarray_length((char const * const *)backend_command)); + array_append(&command, backend_command, + str_array_length((char const * const *)backend_command)); for (i = 1; imap_args[i].type != IMAP_ARG_EOL; i++) { - const char *str = imap_arg_string(&imap_args[i]); + char *str = p_strdup(cmd->pool, imap_arg_string(&imap_args[i])); if (str == NULL) { client_send_command_error(cmd, "Invalid arguments."); t_pop(); @@ -236,7 +237,7 @@ bool cmd_xexec(struct client_command_con } close(pipe_err[1]); - execvp(*(char **)array_idx(&command, 0), array_get(&command, NULL)); + execvp(*(char **)array_idx(&command, 0), array_idx(&command, 0)); exit(1); } @@ -246,11 +247,11 @@ bool cmd_xexec(struct client_command_con close(pipe_out[1]); close(pipe_err[1]); - ctx->in = o_stream_create_file(pipe_in[1], default_pool, 0, TRUE); - ctx->out = i_stream_create_file(pipe_out[0], default_pool, 1024, TRUE); - ctx->err = i_stream_create_file(pipe_err[0], default_pool, 1024, TRUE); + ctx->in = o_stream_create_fd(pipe_in[1], 0, TRUE); + ctx->out = i_stream_create_fd(pipe_out[0], 1024, TRUE); + ctx->err = i_stream_create_fd(pipe_err[0], 1024, TRUE); - ctx->loop = io_loop_create(default_pool); + ctx->loop = io_loop_create(); ctx->io_out = io_add(i_stream_get_fd(ctx->out), IO_READ, cmd_xexec_stdout, ctx); ctx->io_err = io_add(i_stream_get_fd(ctx->err), IO_READ, diff -r 7cafabf38524 xexec.h --- a/xexec.h Wed Mar 19 00:58:24 2008 +0100 +++ b/xexec.h Fri Mar 21 18:12:26 2008 +0100 @@ -5,7 +5,7 @@ struct xexec { - array_t ARRAY_DEFINE(setups, struct xexec_setups *); + ARRAY_DEFINE(setups, struct xexec_setup *); }; struct xexec_setup { diff -r 7cafabf38524 xexec_plugin.c --- a/xexec_plugin.c Wed Mar 19 00:58:24 2008 +0100 +++ b/xexec_plugin.c Fri Mar 21 18:12:26 2008 +0100 @@ -75,7 +75,7 @@ static struct xexec *xexec_init(void) struct xexec *xexec; xexec = i_new(struct xexec, 1); - ARRAY_CREATE(&xexec->setups, default_pool, struct xexec_setup *, 4); + i_array_init(&xexec->setups, 4); return xexec; } @@ -122,7 +122,7 @@ void xexec_plugin_init(void) } t_pop(); - command_register("XEXEC", cmd_xexec); + command_register("XEXEC", cmd_xexec, 0); str_append(capability_string, " XEXEC"); }
participants (2)
-
Stephan Bosch
-
subscriber@viliar.net.ru