Normalize the path to <host>/<path> for the statedb filename.

This should fix problem if a user uses pam_csync and csync with different
urls (#27).
This commit is contained in:
Andreas Schneider 2009-01-22 14:44:06 +01:00
parent 228a19abf4
commit ecca37d2a1
3 changed files with 40 additions and 2 deletions

View File

@ -33,7 +33,6 @@
#include <sys/types.h>
#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;

View File

@ -25,8 +25,10 @@
#endif
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include "c_jhash.h"
#include "csync_util.h"
#include "vio/csync_vio.h"
@ -287,3 +289,35 @@ out:
return rc;
}
/* Normalize the uri to <host>/<path> */
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;
}

View File

@ -23,6 +23,8 @@
#ifndef _CSYNC_UTIL_H
#define _CSYNC_UTIL_H
#include <stdint.h>
#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 <host>/<path> */
uint64_t csync_create_statedb_hash(CSYNC *ctx);
#endif /* _CSYNC_UTIL_H */