Mercurial > dovecot > core-2.2
changeset 1726:f5e6f29731c4 HEAD
fixes
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 24 Aug 2003 12:35:19 +0300 |
parents | cc0690f92d96 |
children | 6d10ece6cf9f |
files | src/util/rawlog.c |
diffstat | 1 files changed, 27 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/src/util/rawlog.c Sun Aug 24 10:55:23 2003 +0300 +++ b/src/util/rawlog.c Sun Aug 24 12:35:19 2003 +0300 @@ -6,6 +6,7 @@ #include "network.h" #include "write-full.h" #include "process-title.h" +#include "restrict-access.h" #include <stdlib.h> #include <unistd.h> @@ -99,14 +100,36 @@ /* see if we want rawlog */ path = t_strconcat(home, "/dovecot.rawlog", NULL); - if (stat(path, &st) < 0) { + if (lstat(path, &st) < 0) { if (errno != ENOENT) i_warning("stat() failed for %s: %m", path); return; } - /* yes, open the files. Do it before forking to make sure we don't - unneededly do it. */ + if (socketpair(AF_UNIX, SOCK_STREAM, 0, sfd) < 0) + i_fatal("socketpair() failed: %m"); + + parent_pid = getpid(); + + pid = fork(); + if (pid < 0) + i_fatal("fork() failed: %m"); + + if (pid > 0) { + /* parent */ + if (dup2(sfd[1], 0) < 0) + i_fatal("dup2(sfd, 0)"); + if (dup2(sfd[1], 1) < 0) + i_fatal("dup2(sfd, 1)"); + close(sfd[0]); + close(sfd[1]); + return; + } + close(sfd[1]); + + restrict_access_by_env(TRUE); + + /* open the files after dropping privileges */ tm = localtime(&ioloop_time); if (strftime(timestamp, sizeof(timestamp), "%Y%m%d-%H%M%S", tm) <= 0) i_fatal("strftime() failed"); @@ -128,29 +151,6 @@ return; } - /* we need to fork the rawlog writer to separate process since - imap process does blocking writes. */ - if (socketpair(AF_UNIX, SOCK_STREAM, 0, sfd) < 0) - i_fatal("socketpair() failed: %m"); - - parent_pid = getpid(); - - pid = fork(); - if (pid < 0) - i_fatal("fork() failed: %m"); - - if (pid > 0) { - /* parent */ - close(log_in); close(log_out); - close(sfd[0]); - if (dup2(sfd[1], 0) < 0) - i_fatal("dup2(sfd, 0)"); - if (dup2(sfd[1], 1) < 0) - i_fatal("dup2(sfd, 1)"); - return; - } - close(sfd[1]); - process_title_set(t_strdup_printf("[%s:%s rawlog]", getenv("USER"), dec2str(parent_pid))); @@ -179,7 +179,7 @@ char *executable, *p; lib_init(); - process_title_init(argv, envp); + process_title_init(argv, envp); if (argc < 2) i_fatal("Usage: rawlog <binary> <arguments>");