Skip to content

Commit

Permalink
global: Replace realpath with path-util from core.
Browse files Browse the repository at this point in the history
path-util is a merge of realpath from Pigeonhole and abspath from core.
  • Loading branch information
mrannanj authored and stephanbosch committed Jan 30, 2017
1 parent 462a535 commit 03434fa
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 312 deletions.
8 changes: 5 additions & 3 deletions src/lib-sieve-tool/mail-raw.c
Expand Up @@ -9,7 +9,7 @@
#include "str-sanitize.h"
#include "strescape.h"
#include "safe-mkstemp.h"
#include "abspath.h"
#include "path-util.h"
#include "message-address.h"
#include "mbox-from.h"
#include "raw-storage.h"
Expand Down Expand Up @@ -153,11 +153,13 @@ static struct mail_raw *mail_raw_create
{
struct mail_raw *mailr;
struct mailbox_header_lookup_ctx *headers_ctx;
const char *envelope_sender;
const char *envelope_sender, *error;
int ret;

if ( mailfile != NULL && *mailfile != '/' )
mailfile = t_abspath(mailfile);
if (t_abspath(mailfile, &mailfile, &error) < 0)
i_fatal("t_abspath(%s) failed: %s",
mailfile, error);

mailr = i_new(struct mail_raw, 1);

Expand Down
14 changes: 12 additions & 2 deletions src/lib-sieve/storage/file/sieve-file-script.c
Expand Up @@ -3,7 +3,7 @@

#include "lib.h"
#include "mempool.h"
#include "abspath.h"
#include "path-util.h"
#include "istream.h"
#include "time-util.h"
#include "eacces-error.h"
Expand Down Expand Up @@ -55,10 +55,20 @@ static void sieve_file_script_handle_error
const char *name, enum sieve_error *error_r)
{
struct sieve_script *script = &fscript->script;
const char *abspath, *error;

switch ( errno ) {
case ENOENT:
sieve_script_sys_debug(script, "File `%s' not found", t_abspath(path));
if (t_abspath(path, &abspath, &error) < 0) {
sieve_script_set_error(script,
SIEVE_ERROR_TEMP_FAILURE,
"t_abspath(%s) failed: %s",
path, error);
*error_r = SIEVE_ERROR_TEMP_FAILURE;
break;
}
sieve_script_sys_debug(script, "File `%s' not found",
abspath);
sieve_script_set_error(script,
SIEVE_ERROR_NOT_FOUND,
"Sieve script `%s' not found", name);
Expand Down
18 changes: 9 additions & 9 deletions src/lib-sieve/storage/file/sieve-file-storage-active.c
Expand Up @@ -2,13 +2,11 @@
*/

#include "lib.h"
#include "abspath.h"
#include "path-util.h"
#include "ioloop.h"
#include "hostpid.h"
#include "file-copy.h"

#include "realpath.h"

#include "sieve-file-storage.h"

#include <unistd.h>
Expand All @@ -21,9 +19,10 @@ static int sieve_file_storage_active_read_link
(struct sieve_file_storage *fstorage, const char **link_r)
{
struct sieve_storage *storage = &fstorage->storage;
const char *error = NULL;
int ret;

ret = t_readlink(fstorage->active_path, link_r);
ret = t_readlink(fstorage->active_path, link_r, &error);

if ( ret < 0 ) {
*link_r = NULL;
Expand All @@ -49,8 +48,8 @@ static int sieve_file_storage_active_read_link

/* We do need to panic otherwise */
sieve_storage_set_critical(storage,
"Performing readlink() on active sieve symlink '%s' failed: %m",
fstorage->active_path);
"Performing t_readlink() on active sieve symlink '%s' failed: %s",
fstorage->active_path, error);
return -1;
}

Expand Down Expand Up @@ -95,11 +94,12 @@ static const char *sieve_file_storage_active_parse_link
}

/* Check whether the path is any good */
if ( t_normpath_to(scriptpath, link_dir, &scriptpath) < 0 ) {
const char *error = NULL;
if ( t_normpath_to(scriptpath, link_dir, &scriptpath, &error) < 0 ) {
sieve_storage_sys_warning(storage,
"Failed to check active Sieve script symlink %s: "
"Failed to normalize path (points to %s).",
fstorage->active_path, scriptpath);
"Failed to normalize path (points to %s): %s",
fstorage->active_path, scriptpath, error);
return NULL;
}
if ( strcmp(scriptpath, fstorage->path) != 0 ) {
Expand Down
27 changes: 16 additions & 11 deletions src/lib-sieve/storage/file/sieve-file-storage.c
Expand Up @@ -2,16 +2,14 @@
*/

#include "lib.h"
#include "abspath.h"
#include "path-util.h"
#include "home-expand.h"
#include "ioloop.h"
#include "mkdir-parents.h"
#include "eacces-error.h"
#include "unlink-old-files.h"
#include "mail-storage-private.h"

#include "realpath.h"

#include "sieve.h"
#include "sieve-common.h"
#include "sieve-settings.h"
Expand Down Expand Up @@ -54,6 +52,7 @@ static int sieve_file_storage_stat
{
struct sieve_storage *storage = &fstorage->storage;
struct stat st;
const char *abspath, *error;

if ( lstat(path, &st) == 0 ) {
fstorage->lnk_st = st;
Expand All @@ -66,8 +65,14 @@ static int sieve_file_storage_stat

switch ( errno ) {
case ENOENT:
if (t_abspath(path, &abspath, &error) < 0) {
sieve_storage_set_critical(storage,
"t_abspath(%s) failed: %s", path, error);
*error_r = SIEVE_ERROR_TEMP_FAILURE;
break;
}
sieve_storage_sys_debug(storage,
"Storage path `%s' not found", t_abspath(path));
"Storage path `%s' not found", abspath);
sieve_storage_set_internal_error(storage); // should be overriden
*error_r = SIEVE_ERROR_NOT_FOUND;
break;
Expand Down Expand Up @@ -294,7 +299,7 @@ static int sieve_file_storage_init_common
ATTR_NULL(2, 3)
{
struct sieve_storage *storage = &fstorage->storage;
const char *tmp_dir, *link_path, *active_fname, *storage_dir;
const char *tmp_dir, *link_path, *active_fname, *storage_dir, *error;
bool have_link = FALSE;
int ret;

Expand Down Expand Up @@ -333,11 +338,11 @@ static int sieve_file_storage_init_common
return -1;
}

if (t_realpath(active_dir, &active_dir) < 0) {
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): %m",
active_dir);
"Failed to normalize active script directory (path=%s): %s",
active_dir, error);
*error_r = SIEVE_ERROR_TEMP_FAILURE;
return -1;
}
Expand Down Expand Up @@ -455,10 +460,10 @@ static int sieve_file_storage_init_common
return -1;

if ( have_link ) {
if ( t_realpath(storage_path, &storage_path) < 0 ) {
if ( t_realpath(storage_path, &storage_path, &error) < 0 ) {
sieve_storage_sys_error(storage,
"Failed to normalize storage path (path=%s): %m",
storage_path);
"Failed to normalize storage path (path=%s): %s",
storage_path, error);
*error_r = SIEVE_ERROR_TEMP_FAILURE;
return -1;
}
Expand Down
6 changes: 2 additions & 4 deletions src/lib-sieve/util/Makefile.am
Expand Up @@ -9,13 +9,11 @@ libsieve_util_la_DEPENDENCIES = $(LIBDOVECOT_STORAGE_DEPS) $(LIBDOVECOT_DEPS)

libsieve_util_la_SOURCES = \
edit-mail.c \
rfc2822.c \
realpath.c
rfc2822.c

headers = \
edit-mail.h \
rfc2822.h \
realpath.h
rfc2822.h

pkginc_libdir=$(dovecot_pkgincludedir)/sieve
pkginc_lib_HEADERS = $(headers)

0 comments on commit 03434fa

Please sign in to comment.