From 17b4a1f572b19624d86d90f5a04e0662c483eac3 Mon Sep 17 00:00:00 2001 From: Stephan Bosch <stephan.bosch@dovecot.fi> Date: Tue, 9 Apr 2019 19:21:44 +0200 Subject: [PATCH] lib-sieve: Replace sieve_storage_sys_error() with e_error(). --- src/lib-sieve/sieve-script.c | 2 +- src/lib-sieve/sieve-storage.c | 26 +++---- .../storage/file/sieve-file-script-sequence.c | 14 ++-- .../storage/file/sieve-file-storage-list.c | 9 +-- .../storage/file/sieve-file-storage-save.c | 8 +- .../storage/file/sieve-file-storage.c | 42 +++++----- src/lib-sieve/storage/ldap/sieve-ldap-db.c | 78 +++++++++---------- .../ldap/sieve-ldap-storage-settings.c | 2 +- 8 files changed, 88 insertions(+), 93 deletions(-) diff --git a/src/lib-sieve/sieve-script.c b/src/lib-sieve/sieve-script.c index 8df9db568..698f6fed1 100644 --- a/src/lib-sieve/sieve-script.c +++ b/src/lib-sieve/sieve-script.c @@ -608,7 +608,7 @@ int sieve_script_rename(struct sieve_script *script, const char *newname) sieve_script_unref(&newscript); if (ret < 0) { - sieve_storage_sys_error(storage, + e_error(storage->event, "Failed to implicitly activate script `%s' " "after rename", newname); sieve_storage_copy_error( diff --git a/src/lib-sieve/sieve-storage.c b/src/lib-sieve/sieve-storage.c index 0cbe8fcc8..20165f8b8 100644 --- a/src/lib-sieve/sieve-storage.c +++ b/src/lib-sieve/sieve-storage.c @@ -192,7 +192,7 @@ sieve_storage_data_parse(struct sieve_storage *storage, const char *data, if (strncasecmp(option, "name=", 5) == 0) { if (option[5] == '\0') { - sieve_storage_sys_error(storage, + e_error(storage->event, "Failed to parse storage location: " "Empty name not allowed"); return -1; @@ -200,7 +200,7 @@ sieve_storage_data_parse(struct sieve_storage *storage, const char *data, if (storage->script_name == NULL) { if (!sieve_script_name_is_valid(option+5)) { - sieve_storage_sys_error(storage, + e_error(storage->event, "Failed to parse storage location: " "Invalid script name `%s'.", str_sanitize(option+5, 80)); @@ -213,7 +213,7 @@ sieve_storage_data_parse(struct sieve_storage *storage, const char *data, const char *bin_dir = option+7; if (bin_dir[0] == '\0') { - sieve_storage_sys_error(storage, + e_error(storage->event, "Failed to parse storage location: " "Empty bindir not allowed"); return -1; @@ -226,7 +226,7 @@ sieve_storage_data_parse(struct sieve_storage *storage, const char *data, if (home != NULL) { bin_dir = home_expand_tilde(bin_dir, home); } else if (bin_dir[1] == '/' || bin_dir[1] == '\0') { - sieve_storage_sys_error(storage, + e_error(storage->event, "Failed to parse storage location: " "bindir is relative to home directory (~/), " "but home directory cannot be determined"); @@ -322,9 +322,7 @@ sieve_storage_init(struct sieve_instance *svinst, if ((flags & SIEVE_STORAGE_FLAG_READWRITE) != 0 && storage_class->v.save_init == NULL) { - e_error(svinst->event, "%s storage: " - "Storage does not support write access", - storage_class->driver_name); + e_error(event, "Storage does not support write access"); *error_r = SIEVE_ERROR_TEMP_FAILURE; event_unref(&event); return NULL; @@ -548,7 +546,7 @@ sieve_storage_create_main(struct sieve_instance *svinst, struct mail_user *user, sieve_setting_get(svinst, "sieve_default_name"); if (set_default_name != NULL && *set_default_name != '\0' && !sieve_script_name_is_valid(set_default_name)) { - sieve_storage_sys_error(storage, + e_error(storage->event, "Invalid script name `%s' for `sieve_default_name' setting.", str_sanitize(set_default_name, 80)); set_default_name = NULL; @@ -648,12 +646,12 @@ int sieve_storage_setup_bindir(struct sieve_storage *storage, mode_t mode) return 0; if (errno == EACCES) { - sieve_storage_sys_error(storage, + e_error(storage->event, "Failed to setup directory for binaries: " "%s", eacces_error_get("stat", bin_dir)); return -1; } else if (errno != ENOENT) { - sieve_storage_sys_error(storage, + e_error(storage->event, "Failed to setup directory for binaries: " "stat(%s) failed: %m", bin_dir); @@ -671,15 +669,15 @@ int sieve_storage_setup_bindir(struct sieve_storage *storage, mode_t mode) case EEXIST: return 0; case ENOENT: - sieve_storage_sys_error(storage, + e_error(storage->event, "Directory for binaries was deleted while it was being created"); break; case EACCES: - sieve_storage_sys_error(storage, + e_error(storage->event, "%s", eacces_error_get_creating("mkdir_parents_chgrp", bin_dir)); break; default: - sieve_storage_sys_error(storage, + e_error(storage->event, "mkdir_parents_chgrp(%s) failed: %m", bin_dir); break; } @@ -1220,7 +1218,7 @@ int sieve_storage_save_commit(struct sieve_storage_save_context **_sctx) sieve_script_unref(&script); if (ret < 0) { - sieve_storage_sys_error(storage, + e_error(storage->event, "Failed to implicitly activate script `%s' " "while replacing the default active script", scriptname); diff --git a/src/lib-sieve/storage/file/sieve-file-script-sequence.c b/src/lib-sieve/storage/file/sieve-file-script-sequence.c index 7906ab613..a1ae75d37 100644 --- a/src/lib-sieve/storage/file/sieve-file-script-sequence.c +++ b/src/lib-sieve/storage/file/sieve-file-script-sequence.c @@ -47,9 +47,9 @@ static int sieve_file_script_sequence_read_dir sieve_storage_set_error(storage, SIEVE_ERROR_NO_PERMISSION, "Script sequence location not accessible"); - sieve_storage_sys_error(storage, - "Failed to open sieve sequence: " - "%s", eacces_error_get("stat", path)); + e_error(storage->event, + "Failed to open sieve sequence: %s", + eacces_error_get("stat", path)); break; default: sieve_storage_set_critical(storage, @@ -113,7 +113,7 @@ static int sieve_file_script_sequence_read_dir /* Close the directory */ if ( dirp != NULL && closedir(dirp) < 0 ) { - sieve_storage_sys_error(storage, + e_error(storage->event, "Failed to close sequence directory: " "closedir(%s) failed: %m", path); } @@ -143,9 +143,9 @@ struct sieve_script_sequence *sieve_file_storage_get_script_sequence sieve_storage_set_error(storage, SIEVE_ERROR_NO_PERMISSION, "Script sequence location not accessible"); - sieve_storage_sys_error(storage, - "Failed to open sieve sequence: " - "%s", eacces_error_get("stat", fstorage->path)); + e_error(storage->event, + "Failed to open sieve sequence: %s", + eacces_error_get("stat", fstorage->path)); break; default: sieve_storage_set_critical(storage, diff --git a/src/lib-sieve/storage/file/sieve-file-storage-list.c b/src/lib-sieve/storage/file/sieve-file-storage-list.c index 0aa16dade..75a34c9d2 100644 --- a/src/lib-sieve/storage/file/sieve-file-storage-list.c +++ b/src/lib-sieve/storage/file/sieve-file-storage-list.c @@ -44,9 +44,8 @@ struct sieve_storage_list_context *sieve_file_storage_list_init sieve_storage_set_error(storage, SIEVE_ERROR_NO_PERMISSION, "Script storage not accessible"); - sieve_storage_sys_error(storage, - "Failed to list scripts: " - "%s", eacces_error_get("opendir", fstorage->path)); + e_error(storage->event, "Failed to list scripts: %s", + eacces_error_get("opendir", fstorage->path)); break; default: sieve_storage_set_critical(storage, @@ -72,7 +71,7 @@ struct sieve_storage_list_context *sieve_file_storage_list_init if ( flctx == NULL ) { if ( closedir(dirp) < 0) { - sieve_storage_sys_error(storage, + e_error(storage->event, "closedir(%s) failed: %m", fstorage->path); } return NULL; @@ -126,7 +125,7 @@ int sieve_file_storage_list_deinit(struct sieve_storage_list_context *lctx) (const struct sieve_file_storage *)lctx->storage; if (closedir(flctx->dirp) < 0) { - sieve_storage_sys_error(lctx->storage, + e_error(lctx->storage->event, "closedir(%s) failed: %m", fstorage->path); } diff --git a/src/lib-sieve/storage/file/sieve-file-storage-save.c b/src/lib-sieve/storage/file/sieve-file-storage-save.c index 563356df5..a22333040 100644 --- a/src/lib-sieve/storage/file/sieve-file-storage-save.c +++ b/src/lib-sieve/storage/file/sieve-file-storage-save.c @@ -368,12 +368,12 @@ static void sieve_file_storage_update_mtime case ENOENT: break; case EACCES: - sieve_storage_sys_error(storage, "save: " - "%s", eacces_error_get("utime", path)); + e_error(storage->event, "save: %s", + eacces_error_get("utime", path)); break; default: - sieve_storage_sys_error(storage, "save: " - "utime(%s) failed: %m", path); + e_error(storage->event, + "save: utime(%s) failed: %m", path); } } } diff --git a/src/lib-sieve/storage/file/sieve-file-storage.c b/src/lib-sieve/storage/file/sieve-file-storage.c index d37521b83..d2d969d8a 100644 --- a/src/lib-sieve/storage/file/sieve-file-storage.c +++ b/src/lib-sieve/storage/file/sieve-file-storage.c @@ -151,12 +151,12 @@ static int mkdir_verify return 0; if ( errno == EACCES ) { - sieve_storage_sys_error(storage, - "mkdir_verify: %s", eacces_error_get("stat", dir)); + e_error(storage->event, "mkdir_verify: %s", + eacces_error_get("stat", dir)); return -1; } else if ( errno != ENOENT ) { - sieve_storage_sys_error(storage, - "mkdir_verify: stat(%s) failed: %m", dir); + e_error(storage->event, "mkdir_verify: " + "stat(%s) failed: %m", dir); return -1; } @@ -170,15 +170,15 @@ static int mkdir_verify case EEXIST: return 0; case ENOENT: - sieve_storage_sys_error(storage, + e_error(storage->event, "Storage was deleted while it was being created"); break; case EACCES: - sieve_storage_sys_error(storage, - "%s", eacces_error_get_creating("mkdir_parents_chgrp", dir)); + e_error(storage->event, "%s", + eacces_error_get_creating("mkdir_parents_chgrp", dir)); break; default: - sieve_storage_sys_error(storage, + e_error(storage->event, "mkdir_parents_chgrp(%s) failed: %m", dir); break; } @@ -195,12 +195,11 @@ static int check_tmp(struct sieve_storage *storage, const char *path) if ( errno == ENOENT ) return 0; if ( errno == EACCES ) { - sieve_storage_sys_error(storage, - "check_tmp: %s", eacces_error_get("stat", path)); + e_error(storage->event, "check_tmp: %s", + eacces_error_get("stat", path)); return -1; } - sieve_storage_sys_error(storage, - "check_tmp: stat(%s) failed: %m", path); + e_error(storage->event, "check_tmp: stat(%s) failed: %m", path); return -1; } @@ -340,9 +339,9 @@ static int sieve_file_storage_init_common if (t_realpath(active_dir, &active_dir, &error) < 0) { if (errno != ENOENT) { - sieve_storage_sys_error(storage, - "Failed to normalize active script directory (path=%s): %s", - active_dir, error); + e_error(storage->event, + "Failed to normalize active script directory " + "(path=%s): %s", active_dir, error); *error_r = SIEVE_ERROR_TEMP_FAILURE; return -1; } @@ -461,7 +460,7 @@ static int sieve_file_storage_init_common if ( have_link ) { if ( t_realpath(storage_path, &storage_path, &error) < 0 ) { - sieve_storage_sys_error(storage, + e_error(storage->event, "Failed to normalize storage path (path=%s): %s", storage_path, error); *error_r = SIEVE_ERROR_TEMP_FAILURE; @@ -796,8 +795,9 @@ static int sieve_file_storage_get_last_change /* Get the storage mtime before we modify it ourself */ if ( stat(fstorage->path, &st) < 0 ) { if ( errno != ENOENT ) { - sieve_storage_sys_error(storage, - "stat(%s) failed: %m", fstorage->path); + e_error(storage->event, + "stat(%s) failed: %m", + fstorage->path); return -1; } st.st_mtime = 0; @@ -842,11 +842,11 @@ static void sieve_file_storage_set_modified case ENOENT: break; case EACCES: - sieve_storage_sys_error(storage, - "%s", eacces_error_get("utime", fstorage->path)); + e_error(storage->event, "%s", + eacces_error_get("utime", fstorage->path)); break; default: - sieve_storage_sys_error(storage, + e_error(storage->event, "utime(%s) failed: %m", fstorage->path); } } else { diff --git a/src/lib-sieve/storage/ldap/sieve-ldap-db.c b/src/lib-sieve/storage/ldap/sieve-ldap-db.c index 925876498..a8823864d 100644 --- a/src/lib-sieve/storage/ldap/sieve-ldap-db.c +++ b/src/lib-sieve/storage/ldap/sieve-ldap-db.c @@ -115,7 +115,7 @@ static int ldap_get_errno(struct ldap_connection *conn) ret = ldap_get_option(conn->ld, LDAP_OPT_ERROR_NUMBER, (void *) &err); if (ret != LDAP_SUCCESS) { - sieve_storage_sys_error(storage, "db: " + e_error(storage->event, "db: " "Can't get error number: %s", ldap_err2string(ret)); return LDAP_UNAVAILABLE; @@ -200,7 +200,7 @@ static int db_ldap_request_search(struct ldap_connection *conn, request->base, request->scope, request->filter, request->attributes, 0); if (request->msgid == -1) { - sieve_storage_sys_error(storage, "db: " + e_error(storage->event, "db: " "ldap_search(%s) parsing failed: %s", request->filter, ldap_get_error(conn)); if (ldap_handle_error(conn) < 0) { @@ -279,7 +279,7 @@ db_ldap_check_limits(struct ldap_connection *conn) aqueue_idx(conn->request_queue, 0)); secs_diff = ioloop_time - (*first_requestp)->create_time; if (secs_diff > DB_LDAP_REQUEST_LOST_TIMEOUT_SECS) { - sieve_storage_sys_error(storage, "db: " + e_error(storage->event, "db: " "Connection appears to be hanging, reconnecting"); ldap_conn_reconnect(conn); return TRUE; @@ -308,14 +308,14 @@ static int db_ldap_connect_finish(struct ldap_connection *conn, int ret) const struct sieve_ldap_storage_settings *set = &conn->lstorage->set; if (ret == LDAP_SERVER_DOWN) { - sieve_storage_sys_error(storage, "db: " + e_error(storage->event, "db: " "Can't connect to server: %s", set->uris != NULL ? set->uris : set->hosts); return -1; } if (ret != LDAP_SUCCESS) { - sieve_storage_sys_error(storage, "db: " + e_error(storage->event, "db: " "binding failed (dn %s): %s", set->dn == NULL ? "(none)" : set->dn, ldap_get_error(conn)); @@ -372,10 +372,9 @@ static void db_ldap_abort_requests(struct ldap_connection *conn, i_assert(conn->pending_count > 0); conn->pending_count--; } - if (error) { - sieve_storage_sys_error(storage, "db: " - "%s", reason); - } else { + if (error) + e_error(storage->event, "db: %s", reason); + else { sieve_storage_sys_debug(storage, "db: " "%s", reason); } @@ -427,8 +426,7 @@ db_ldap_handle_request_result(struct ldap_connection *conn, /* we're going to ignore this */ return FALSE; default: - sieve_storage_sys_error(storage, "db: " - "Reply with unexpected type %d", + e_error(storage->event, "db: Reply with unexpected type %d", ldap_msgtype(res->msg)); return TRUE; } @@ -442,7 +440,7 @@ db_ldap_handle_request_result(struct ldap_connection *conn, } if (ret != LDAP_SUCCESS) { /* handle search failures here */ - sieve_storage_sys_error(storage, "db: " + e_error(storage->event, "db: " "ldap_search(base=%s filter=%s) failed: %s", request->base, request->filter, ldap_err2string(ret)); @@ -515,8 +513,8 @@ db_ldap_handle_result(struct ldap_connection *conn, struct db_ldap_result *res) request = db_ldap_find_request(conn, msgid, &idx); if (request == NULL) { - sieve_storage_sys_error(storage, "db: " - "Reply with unknown msgid %d", msgid); + e_error(storage->event, + "db: Reply with unknown msgid %d", msgid); return; } @@ -567,13 +565,13 @@ static void ldap_input(struct ldap_connection *conn) while (db_ldap_request_queue_next(conn)) ; } else if (ldap_get_errno(conn) != LDAP_SERVER_DOWN) { - sieve_storage_sys_error(storage, "db: " - "ldap_result() failed: %s", ldap_get_error(conn)); + e_error(storage->event, "db: ldap_result() failed: %s", + ldap_get_error(conn)); ldap_conn_reconnect(conn); } else if (aqueue_count(conn->request_queue) > 0 || prev_reply_diff < DB_LDAP_IDLE_RECONNECT_SECS) { - sieve_storage_sys_error(storage, "db: " - "Connection lost to LDAP server, reconnecting"); + e_error(storage->event, + "db: Connection lost to LDAP server, reconnecting"); ldap_conn_reconnect(conn); } else { /* server probably disconnected an idle connection. don't @@ -624,8 +622,7 @@ static void ldap_connection_timeout(struct ldap_connection *conn) struct sieve_storage *storage = &conn->lstorage->storage; i_assert(conn->conn_state == LDAP_CONN_STATE_BINDING); - sieve_storage_sys_error(storage, "db: " - "Initial binding to LDAP server timed out"); + e_error(storage->event, "db: Initial binding to LDAP server timed out"); db_ldap_conn_close(conn); } @@ -666,14 +663,15 @@ static int db_ldap_get_fd(struct ldap_connection *conn) /* get the connection's fd */ ret = ldap_get_option(conn->ld, LDAP_OPT_DESC, (void *)&conn->fd); if (ret != LDAP_SUCCESS) { - sieve_storage_sys_error(storage, "db: " - "Can't get connection fd: %s", ldap_err2string(ret)); + e_error(storage->event, "db: Can't get connection fd: %s", + ldap_err2string(ret)); return -1; } if (conn->fd <= STDERR_FILENO) { /* Solaris LDAP library seems to be broken */ - sieve_storage_sys_error(storage, "db: " - "Buggy LDAP library returned wrong fd: %d", conn->fd); + e_error(storage->event, + "db: Buggy LDAP library returned wrong fd: %d", + conn->fd); return -1; } i_assert(conn->fd != -1); @@ -690,8 +688,7 @@ db_ldap_set_opt(struct ldap_connection *conn, int opt, const void *value, ret = ldap_set_option(conn->ld, opt, value); if (ret != LDAP_SUCCESS) { - sieve_storage_sys_error(storage, "db: " - "Can't set option %s to %s: %s", + e_error(storage->event, "db: Can't set option %s to %s: %s", optname, value_str, ldap_err2string(ret)); return -1; } @@ -770,13 +767,13 @@ static int db_ldap_set_options(struct ldap_connection *conn) if (set->ldap_version < 3) { if (set->sasl_bind) { - sieve_storage_sys_error(storage, "db: " - "sasl_bind=yes requires ldap_version=3"); + e_error(storage->event, + "db: sasl_bind=yes requires ldap_version=3"); return -1; } if (set->tls) { - sieve_storage_sys_error(storage, "db: " - "tls=yes requires ldap_version=3"); + e_error(storage->event, + "db: tls=yes requires ldap_version=3"); return -1; } } @@ -819,7 +816,7 @@ int sieve_ldap_db_connect(struct ldap_connection *conn) if (ldap_initialize(&conn->ld, set->uris) != LDAP_SUCCESS) conn->ld = NULL; #else - sieve_storage_sys_error(storage, "db: " + e_error(storage->event, "db: " "Your LDAP library doesn't support " "'uris' setting, use 'hosts' instead."); return -1; @@ -828,7 +825,7 @@ int sieve_ldap_db_connect(struct ldap_connection *conn) conn->ld = ldap_init(set->hosts, LDAP_PORT); if (conn->ld == NULL) { - sieve_storage_sys_error(storage, "db: " + e_error(storage->event, "db: " "ldap_init() failed with hosts: %s", set->hosts); return -1; } @@ -844,15 +841,16 @@ int sieve_ldap_db_connect(struct ldap_connection *conn) if (ret == LDAP_OPERATIONS_ERROR && set->uris != NULL && str_begins(set->uris, "ldaps:")) { - sieve_storage_sys_error(storage, "db: " + e_error(storage->event, "db: " "Don't use both tls=yes and ldaps URI"); } - sieve_storage_sys_error(storage, "db: " - "ldap_start_tls_s() failed: %s", ldap_err2string(ret)); + e_error(storage->event, "db: " + "ldap_start_tls_s() failed: %s", + ldap_err2string(ret)); return -1; } #else - sieve_storage_sys_error(storage, "db: " + e_error(storage->event, "db: " "Your LDAP library doesn't support TLS"); return -1; #endif @@ -877,7 +875,7 @@ int sieve_ldap_db_connect(struct ldap_connection *conn) if (db_ldap_connect_finish(conn, ret) < 0) return -1; #else - sieve_storage_sys_error(storage, "db: " + e_error(storage->event, "db: " "sasl_bind=yes but no SASL support compiled in"); return -1; #endif @@ -1274,7 +1272,7 @@ int sieve_ldap_db_lookup_script(struct ldap_connection *conn, str = t_str_new(512); if (var_expand(str, set->base, tab, &error) <= 0) { - sieve_storage_sys_error(storage, "db: " + e_error(storage->event, "db: " "Failed to expand base=%s: %s", set->base, error); return -1; @@ -1286,7 +1284,7 @@ int sieve_ldap_db_lookup_script(struct ldap_connection *conn, str_truncate(str, 0); if (var_expand(str, set->sieve_ldap_filter, tab, &error) <= 0) { - sieve_storage_sys_error(storage, "db: " + e_error(storage->event, "db: " "Failed to expand sieve_ldap_filter=%s: %s", set->sieve_ldap_filter, error); return -1; @@ -1337,7 +1335,7 @@ sieve_ldap_read_script_callback(struct ldap_connection *conn, if (srequest->result == NULL) { (void)sieve_ldap_db_get_script(conn, res, &srequest->result); } else { - sieve_storage_sys_error(storage, "db: " + e_error(storage->event, "db: " "Search returned more than one entry for Sieve script DN"); i_stream_unref(&srequest->result); } diff --git a/src/lib-sieve/storage/ldap/sieve-ldap-storage-settings.c b/src/lib-sieve/storage/ldap/sieve-ldap-storage-settings.c index 765f21468..9846d9ce7 100644 --- a/src/lib-sieve/storage/ldap/sieve-ldap-storage-settings.c +++ b/src/lib-sieve/storage/ldap/sieve-ldap-storage-settings.c @@ -94,7 +94,7 @@ int sieve_ldap_storage_read_settings struct stat st; if ( stat(config_path, &st) < 0 ) { - sieve_storage_sys_error(storage, + e_error(storage->event, "Failed to read LDAP storage config: " "stat(%s) failed: %m", config_path); return -1; -- GitLab