Mercurial > dovecot > original-hg > dovecot-1.2
changeset 9216:23f676bada8c HEAD
master: Give better error messages if UNIX uid/gid is too high/low.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 09 Jul 2009 13:28:47 -0400 |
parents | 572cd188f6da |
children | dd49cf3fd2c9 |
files | src/master/mail-process.c |
diffstat | 1 files changed, 29 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/master/mail-process.c Wed Jul 08 17:56:59 2009 -0400 +++ b/src/master/mail-process.c Thu Jul 09 13:28:47 2009 -0400 @@ -23,6 +23,8 @@ #include <grp.h> #include <syslog.h> #include <sys/stat.h> +#include <pwd.h> +#include <grp.h> #ifdef HAVE_SYS_RESOURCE_H # include <sys/resource.h> @@ -117,30 +119,47 @@ const char *user) { if (uid == 0) { - i_error("user %s: Logins with UID 0 not permitted", user); + i_error("User %s not allowed to log in using UNIX UID 0 " + "(root logins are never allowed)", user); return FALSE; } if (set->login_uid == uid && master_uid != uid) { - i_error("user %s: Logins with login_user's UID %s " - "not permitted (see http://wiki.dovecot.org/UserIds).", - user, dec2str(uid)); + struct passwd *pw; + + pw = getpwuid(uid); + i_error("User %s not allowed to log in using login_user's " + "UNIX UID %s%s (see http://wiki.dovecot.org/UserIds)", + user, dec2str(uid), pw == NULL ? "" : + t_strdup_printf("(%s)", pw->pw_name)); return FALSE; } if (uid < (uid_t)set->first_valid_uid || (set->last_valid_uid != 0 && uid > (uid_t)set->last_valid_uid)) { - i_error("user %s: Logins with UID %s not permitted " - "(see first_valid_uid in config file).", - user, dec2str(uid)); + struct passwd *pw; + + pw = getpwuid(uid); + i_error("User %s not allowed to log in using too %s " + "UNIX UID %s%s (see first_valid_uid in config file)", + user, + uid < (uid_t)set->first_valid_uid ? "low" : "high", + dec2str(uid), pw == NULL ? "" : + t_strdup_printf("(%s)", pw->pw_name)); return FALSE; } if (gid < (gid_t)set->first_valid_gid || (set->last_valid_gid != 0 && gid > (gid_t)set->last_valid_gid)) { - i_error("user %s: Logins for users with primary group ID %s " - "not permitted (see first_valid_gid in config file).", - user, dec2str(gid)); + struct group *gr; + + gr = getgrgid(gid); + i_error("User %s not allowed to log in using too %s primary " + "UNIX group ID %s%s (see first_valid_gid in config file)", + user, + gid < (gid_t)set->first_valid_gid ? "low" : "high", + dec2str(gid), gr == NULL ? "" : + t_strdup_printf("(%s)", gr->gr_name)); return FALSE; }