/*
- * $Id: cnid.c,v 1.1.4.8 2004-01-14 23:15:19 lenneis Exp $
+ * $Id: cnid.c,v 1.1.4.9 2004-03-19 13:18:51 bfernhomberg Exp $
*
* Copyright (c) 2003 the Netatalk Team
* Copyright (c) 2003 Rafal Lewczuk <rlewczuk@pronet.pl>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
+#include <sys/param.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
#include <signal.h>
#include <unistd.h>
#include <errno.h>
#include <atalk/cnid.h>
#include <atalk/list.h>
#include <atalk/logger.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
+#include <atalk/util.h>
/* List of all registered modules. */
static struct list_head modules = ATALK_LIST_HEAD_INIT(modules);
/* --------------- */
static int cnid_dir(const char *dir, mode_t mask)
{
- struct stat st;
+ struct stat st, st1;
+ char tmp[MAXPATHLEN];
if (stat(dir, &st) < 0) {
if (errno != ENOENT)
if (mkdir(dir, 0777 & ~mask) < 0)
return -1;
} else {
- LOG(log_info, logtype_cnid, "Setting uid/gid to %d/%d", st.st_uid, st.st_gid);
- if (setegid(st.st_gid) < 0 || seteuid(st.st_uid) < 0) {
+ strlcpy(tmp, dir, sizeof(tmp));
+ strlcat(tmp, "/.AppleDB", sizeof(tmp));
+ if (stat(tmp, &st1) < 0) /* use .AppleDB owner, if folder already exists */
+ st1 = st;
+ LOG(log_info, logtype_cnid, "Setting uid/gid to %d/%d", st1.st_uid, st1.st_gid);
+ if (setegid(st1.st_gid) < 0 || seteuid(st1.st_uid) < 0) {
LOG(log_error, logtype_cnid, "uid/gid: %s", strerror(errno));
return -1;
}
}
db = mod->cnid_open(volpath, mask);
- /* FIXME should module know about it ? */
- if (flags) {
- db->flags |= CNID_FLAG_NODEV;
- }
if ((mod->flags & CNID_FLAG_SETUID)) {
seteuid(0);
LOG(log_error, logtype_afpd, "Cannot open CNID db at [%s].", volpath);
return NULL;
}
+ /* FIXME should module know about it ? */
+ if (flags) {
+ db->flags |= CNID_FLAG_NODEV;
+ }
db->flags |= mod->flags;
if ((db->flags & CNID_FLAG_BLOCK)) {