From: Timo Sirainen Date: Sun, 24 Aug 2003 09:35:19 +0000 (+0300) Subject: fixes X-Git-Tag: 1.1.alpha1~4380 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=09a3ac52e2a6db14920e648116ffcd23624b5f23;p=thirdparty%2Fdovecot%2Fcore.git fixes --HG-- branch : HEAD --- diff --git a/src/util/rawlog.c b/src/util/rawlog.c index 369e5a673a..894405271e 100644 --- a/src/util/rawlog.c +++ b/src/util/rawlog.c @@ -6,6 +6,7 @@ #include "network.h" #include "write-full.h" #include "process-title.h" +#include "restrict-access.h" #include #include @@ -99,14 +100,36 @@ static void rawlog_open(void) /* 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 @@ static void rawlog_open(void) 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 @@ int main(int argc, char *argv[], char *envp[]) char *executable, *p; lib_init(); - process_title_init(argv, envp); + process_title_init(argv, envp); if (argc < 2) i_fatal("Usage: rawlog ");