dovecot-2.2: auth passwd-file: If we fail to open passwd-file, l...

dovecot at dovecot.org dovecot at dovecot.org
Tue May 14 23:34:54 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/df20af39dc51
changeset: 16350:df20af39dc51
user:      Timo Sirainen <tss at iki.fi>
date:      Tue May 14 23:34:38 2013 +0300
description:
auth passwd-file: If we fail to open passwd-file, log a request error directly.
Instead of one error message and another info message.

diffstat:

 src/auth/db-passwd-file.c |  57 ++++++++++++++++++++++++++--------------------
 1 files changed, 32 insertions(+), 25 deletions(-)

diffs (133 lines):

diff -r bf98dc25e3e4 -r df20af39dc51 src/auth/db-passwd-file.c
--- a/src/auth/db-passwd-file.c	Tue May 14 22:23:27 2013 +0300
+++ b/src/auth/db-passwd-file.c	Tue May 14 23:34:38 2013 +0300
@@ -164,7 +164,8 @@
 	return pw;
 }
 
-static bool passwd_file_open(struct passwd_file *pw, bool startup)
+static int passwd_file_open(struct passwd_file *pw, bool startup,
+			    const char **error_r)
 {
 	const char *no_args = NULL;
 	struct istream *input;
@@ -176,20 +177,20 @@
 
 	fd = open(pw->path, O_RDONLY);
 	if (fd == -1) {
-		if (errno == EACCES) {
-			i_error("passwd-file %s: %s", pw->path,
-				eacces_error_get("open", pw->path));
-		} else {
-			i_error("passwd-file %s: Can't open file: %m",
-				pw->path);
+		if (errno == EACCES)
+			*error_r = eacces_error_get("open", pw->path);
+		else {
+			*error_r = t_strdup_printf("open(%s) failed: %m",
+						   pw->path);
 		}
-		return FALSE;
+		return -1;
 	}
 
 	if (fstat(fd, &st) != 0) {
-		i_error("passwd-file %s: fstat() failed: %m", pw->path);
+		*error_r = t_strdup_printf("fstat(%s) failed: %m",
+					   pw->path);
 		i_close_fd(&fd);
-		return FALSE;
+		return -1;
 	}
 
 	pw->fd = fd;
@@ -229,7 +230,7 @@
 		i_debug("passwd-file %s: Read %u users in %u secs",
 			pw->path, hash_table_count(pw->users), time_secs);
 	}
-	return TRUE;
+	return 0;
 }
 
 static void passwd_file_close(struct passwd_file *pw)
@@ -256,30 +257,37 @@
 	i_free(pw);
 }
 
-static bool passwd_file_sync(struct passwd_file *pw)
+static int passwd_file_sync(struct auth_request *request,
+			    struct passwd_file *pw)
 {
 	struct stat st;
+	const char *error;
 
 	if (stat(pw->path, &st) < 0) {
 		/* with variables don't give hard errors, or errors about
 		   nonexistent files */
 		if (errno == EACCES) {
-			i_error("passwd-file %s: %s", pw->path,
-				eacces_error_get("stat", pw->path));
-		} else if (errno != ENOENT) {
-			i_error("passwd-file %s: stat() failed: %m", pw->path);
+			auth_request_log_error(request, "passwd-file",
+				"%s", eacces_error_get("stat", pw->path));
+		} else {
+			auth_request_log_error(request, "passwd-file",
+				"stat(%s) failed: %m", pw->path);
 		}
 
 		if (pw->db->default_file != pw)
 			passwd_file_free(pw);
-		return FALSE;
+		return -1;
 	}
 
 	if (st.st_mtime != pw->stamp || st.st_size != pw->size) {
 		passwd_file_close(pw);
-		return passwd_file_open(pw, FALSE);
+		if (passwd_file_open(pw, FALSE, &error) < 0) {
+			auth_request_log_error(request, "passwd-file",
+				"%s", error);
+			return -1;
+		}
 	}
-	return TRUE;
+	return 0;
 }
 
 static struct db_passwd_file *db_passwd_file_find(const char *path)
@@ -359,9 +367,12 @@
 
 void db_passwd_file_parse(struct db_passwd_file *db)
 {
+	const char *error;
+
 	if (db->default_file != NULL && db->default_file->stamp == 0) {
 		/* no variables, open the file immediately */
-		(void)passwd_file_open(db->default_file, TRUE);
+		if (passwd_file_open(db->default_file, TRUE, &error) < 0)
+			i_error("passwd-file: %s", error);
 	}
 }
 
@@ -421,7 +432,6 @@
 	struct passwd_user *pu;
 	const struct var_expand_table *table;
 	string_t *username, *dest;
-	const char *path;
 
 	if (!db->vars)
 		pw = db->default_file;
@@ -437,11 +447,8 @@
 		}
 	}
 
-	path = t_strdup(pw->path);
-	if (!passwd_file_sync(pw)) {
+	if (passwd_file_sync(request, pw) < 0) {
 		/* pw may be freed now */
-		auth_request_log_info(request, "passwd-file",
-				      "no passwd file: %s", path);
 		return NULL;
 	}
 


More information about the dovecot-cvs mailing list