diff --git a/src/imap-urlauth/imap-urlauth.c b/src/imap-urlauth/imap-urlauth.c index 181c123856..17ec764ae1 100644 --- a/src/imap-urlauth/imap-urlauth.c +++ b/src/imap-urlauth/imap-urlauth.c @@ -233,7 +233,9 @@ int main(int argc, char *argv[]) if (imap_urlauth_settings->verbose_proctitle) verbose_proctitle = TRUE; - login_set.auth_socket_path = t_abspath(auth_socket_path); + if (t_abspath(auth_socket_path, &login_set.auth_socket_path, &error) < 0) { + i_fatal("t_abspath(%s) failed: %s", auth_socket_path, error); + } login_set.callback = login_client_connected; login_set.failure_callback = login_client_failed; diff --git a/src/imap/main.c b/src/imap/main.c index cd066cd255..132d3cff69 100644 --- a/src/imap/main.c +++ b/src/imap/main.c @@ -451,10 +451,17 @@ int main(int argc, char *argv[]) main_stdio_run(username); } T_END; } else T_BEGIN { - login_set.auth_socket_path = t_abspath(auth_socket_path); + const char *error; + if (t_abspath(auth_socket_path, &login_set.auth_socket_path, + &error) < 0) { + i_fatal("t_abspath(%s) failed: %s", auth_socket_path, + error); + } + if (argv[optind] != NULL) { - login_set.postlogin_socket_path = - t_abspath(argv[optind]); + if (t_abspath(argv[optind], &login_set.postlogin_socket_path, &error) < 0) { + i_fatal("t_abspath(%s) failed: %s", argv[optind], error); + } } login_set.callback = login_client_connected; login_set.failure_callback = login_client_failed; diff --git a/src/lda/main.c b/src/lda/main.c index 5947c513ed..1dda36d012 100644 --- a/src/lda/main.c +++ b/src/lda/main.c @@ -353,7 +353,10 @@ int main(int argc, char *argv[]) break; case 'p': /* input path */ - path = t_abspath(optarg); + if (t_abspath(optarg, &path, &errstr) < 0) { + i_fatal("t_abspath(%s) failed: %s", + optarg, errstr); + } break; case 'r': /* final recipient address */ diff --git a/src/lib/path-util.c b/src/lib/path-util.c index b0f04b2c56..cc1696b810 100644 --- a/src/lib/path-util.c +++ b/src/lib/path-util.c @@ -270,17 +270,25 @@ int t_realpath_to(const char *path, const char *root, const char **npath_r, return t_realpath(t_strconcat(root, "/", path, NULL), npath_r, error_r); } -const char *t_abspath(const char *path) +int t_abspath(const char *path, const char **abspath_r, const char **error_r) { i_assert(path != NULL); + i_assert(abspath_r != NULL); + i_assert(error_r != NULL); - if (*path == '/') - return path; + if (*path == '/') { + *abspath_r = path; + return 0; + } const char *dir, *error; - if (t_get_working_dir(&dir, &error) < 0) - i_fatal("Failed to get working directory: %s", error); - return t_strconcat(dir, "/", path, NULL); + if (t_get_working_dir(&dir, &error) < 0) { + *error_r = t_strconcat("Failed to get working directory: ", + error, NULL); + return -1; + } + *abspath_r = t_strconcat(dir, "/", path, NULL); + return 0; } const char *t_abspath_to(const char *path, const char *root) @@ -336,7 +344,12 @@ bool t_binary_abspath(const char **binpath) return TRUE; } else if (strchr(*binpath, '/') != NULL) { /* relative to current directory */ - *binpath = t_abspath(*binpath); + const char *error; + if (t_abspath(*binpath, binpath, &error) < 0) { + i_error("t_abspath(%s) failed: %s", + *binpath, error); + return FALSE; + } return TRUE; } else if ((path_env = getenv("PATH")) != NULL) { /* we have to find our executable from path */ diff --git a/src/lib/path-util.h b/src/lib/path-util.h index 0ac0a07e00..6758af8177 100644 --- a/src/lib/path-util.h +++ b/src/lib/path-util.h @@ -41,8 +41,11 @@ int t_realpath_to(const char *path, const char *root, const char **npath_r, * In the t_abspath functions, the returned paths are not normalized. This * means that './' and '../' are not resolved, but they left in the returned * path as given in the parameters. Symbolic links are not resolved either. + * + * Returns 0 on success, and -1 on failure. error_r is set on failure, and + * cannot be NULL. */ -const char *t_abspath(const char *path); +int t_abspath(const char *path, const char **abspath_r, const char **error_r); /* Like t_abspath(), but path is relative to given root. */ const char *t_abspath_to(const char *path, const char *root); diff --git a/src/lmtp/main.c b/src/lmtp/main.c index 5a4f4f9bbd..5f7841453a 100644 --- a/src/lmtp/main.c +++ b/src/lmtp/main.c @@ -62,7 +62,12 @@ static void main_init(void) i_zero(&conn); (void)client_create(STDIN_FILENO, STDOUT_FILENO, &conn); } - dns_client_socket_path = i_strdup(t_abspath(DNS_CLIENT_SOCKET_PATH)); + + const char *error, *tmp_socket_path; + if (t_abspath(DNS_CLIENT_SOCKET_PATH, &tmp_socket_path, &error) < 0) { + i_fatal("t_abspath(%s) failed: %s", DNS_CLIENT_SOCKET_PATH, error); + } + dns_client_socket_path = i_strdup(tmp_socket_path); } static void main_deinit(void) diff --git a/src/master/main.c b/src/master/main.c index de2cc24178..aab942eb44 100644 --- a/src/master/main.c +++ b/src/master/main.c @@ -556,7 +556,11 @@ static const char *get_full_config_path(struct service_list *list) if (*path == '/') return path; - return p_strdup(list->pool, t_abspath(path)); + const char *abspath, *error; + if (t_abspath(path, &abspath, &error) < 0) { + i_fatal("t_abspath(%s) failed: %s", path, error); + } + return p_strdup(list->pool, abspath); } static void master_time_moved(time_t old_time, time_t new_time) diff --git a/src/pop3/main.c b/src/pop3/main.c index 3ad7746fb1..381b057765 100644 --- a/src/pop3/main.c +++ b/src/pop3/main.c @@ -259,9 +259,15 @@ int main(int argc, char *argv[]) } } - login_set.auth_socket_path = t_abspath(auth_socket_path); - if (argv[optind] != NULL) - login_set.postlogin_socket_path = t_abspath(argv[optind]); + const char *error; + if (t_abspath(auth_socket_path, &login_set.auth_socket_path, &error) < 0) { + i_fatal("t_abspath(%s) failed: %s", auth_socket_path, error); + } + if (argv[optind] != NULL) { + if (t_abspath(argv[optind], &login_set.postlogin_socket_path, &error) < 0) { + i_fatal("t_abspath(%s) failed: %s", argv[optind], error); + } + } login_set.callback = login_client_connected; login_set.failure_callback = login_client_failed;