From ecca37d2a19046bb8389b440a7bce55bf5cd8e2c Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 22 Jan 2009 14:44:06 +0100 Subject: [PATCH] Normalize the path to / for the statedb filename. This should fix problem if a user uses pam_csync and csync with different urls (#27). --- src/csync.c | 3 +-- src/csync_util.c | 34 ++++++++++++++++++++++++++++++++++ src/csync_util.h | 5 +++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/csync.c b/src/csync.c index 3b6c52f88b..f2e2ac9e2e 100644 --- a/src/csync.c +++ b/src/csync.c @@ -33,7 +33,6 @@ #include #include "c_lib.h" -#include "c_jhash.h" #include "csync_private.h" #include "csync_config.h" #include "csync_exclude.h" @@ -220,7 +219,7 @@ int csync_init(CSYNC *ctx) { /* create/load statedb */ if (! csync_is_statedb_disabled(ctx)) { - uint64_t h = c_jhash64((uint8_t *) ctx->remote.uri, strlen(ctx->remote.uri), 0); + uint64_t h = csync_create_statedb_hash(ctx); if (asprintf(&ctx->statedb.file, "%s/csync_statedb_%llu.db", ctx->options.config_dir, (long long unsigned int) h) < 0) { rc = -1; diff --git a/src/csync_util.c b/src/csync_util.c index 96f15b9a73..7aa2e0dcfa 100644 --- a/src/csync_util.c +++ b/src/csync_util.c @@ -25,8 +25,10 @@ #endif #include +#include #include +#include "c_jhash.h" #include "csync_util.h" #include "vio/csync_vio.h" @@ -287,3 +289,35 @@ out: return rc; } +/* Normalize the uri to / */ +uint64_t csync_create_statedb_hash(CSYNC *ctx) { + char *p = NULL; + char *host = NULL; + char *path = NULL; + char name[PATH_MAX] = {0}; + uint64_t hash = 0; + + if (c_parse_uri(ctx->remote.uri, NULL, NULL, NULL, &host, NULL, &path) < 0) { + SAFE_FREE(host); + SAFE_FREE(path); + return 0; + } + + if ((p = strchr(host, '.'))) { + *p = '\0'; + } + + /* len + 1 for \0 */ + snprintf(name, PATH_MAX, "%s%s", host, path); + + CSYNC_LOG(CSYNC_LOG_PRIORITY_INFO, + "Normalized path for the statedb hash: %s", name); + + hash = c_jhash64((uint8_t *) name, strlen(name), 0); + + SAFE_FREE(host); + SAFE_FREE(path); + + return hash; +} + diff --git a/src/csync_util.h b/src/csync_util.h index e119c1e9b8..c5ffc6938c 100644 --- a/src/csync_util.h +++ b/src/csync_util.h @@ -23,6 +23,8 @@ #ifndef _CSYNC_UTIL_H #define _CSYNC_UTIL_H +#include + #include "csync_private.h" const char *csync_instruction_str(enum csync_instructions_e instr); @@ -33,4 +35,7 @@ int csync_merge_file_trees(CSYNC *ctx); int csync_unix_extensions(CSYNC *ctx); +/* Normalize the uri to / */ +uint64_t csync_create_statedb_hash(CSYNC *ctx); + #endif /* _CSYNC_UTIL_H */