Mercurial > dovecot > core-2.2
changeset 1193:206190c8c66f HEAD
Use getlogin() alternatively if USER environment isn't found.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 18 Feb 2003 22:50:09 +0200 |
parents | 76321f65960d |
children | 31deba59422f |
files | src/imap/main.c |
diffstat | 1 files changed, 17 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/imap/main.c Tue Feb 18 21:24:44 2003 +0200 +++ b/src/imap/main.c Tue Feb 18 22:50:09 2003 +0200 @@ -10,6 +10,7 @@ #include "mail-storage.h" #include <stdlib.h> +#include <unistd.h> #include <syslog.h> #define IS_STANDALONE() \ @@ -30,7 +31,12 @@ const char *user; user = getenv("USER"); - if (user == NULL) user = "??"; + if (user == NULL) { + if (!IS_STANDALONE()) + user = getlogin(); + if (user == NULL) + user = "??"; + } if (strlen(user) >= sizeof(log_prefix)-6) { /* quite a long user name, cut it */ user = t_strndup(user, sizeof(log_prefix)-6-2); @@ -63,13 +69,18 @@ { struct client *client; struct mail_storage *storage; - const char *mail, *str; + const char *user, *mail, *str; int hin, hout; lib_init_signals(sig_quit); - if (getenv("USER") == NULL) - i_fatal("USER environment missing"); + user = getenv("USER"); + if (user == NULL) { + if (!IS_STANDALONE()) + user = getlogin(); + if (user == NULL) + i_fatal("USER environment missing"); + } hin = 0; hout = 1; rawlog_open(&hin, &hout); @@ -86,7 +97,7 @@ mail = t_strconcat("maildir:", mail, NULL); } - storage = mail_storage_create_with_data(mail, getenv("USER")); + storage = mail_storage_create_with_data(mail, user); if (storage == NULL) { /* failed */ if (mail != NULL && *mail != '\0') @@ -116,7 +127,7 @@ if (IS_STANDALONE()) { client_send_line(client, t_strconcat( "* PREAUTH [CAPABILITY "CAPABILITY_STRING"] " - "Logged in as ", getenv("USER"), NULL)); + "Logged in as ", user, NULL)); } }