X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=etc%2Fcnid_dbd%2Fcmd_dbd.c;h=78e5cd4763493312c741f8068bca091d7529a136;hb=7bd0ab8692a994665b52d5680359e64866526fc1;hp=c77bf79a2eaa64aa4c7b7ca107f992fdb2b413f1;hpb=0c29e4237a1dd813188cb6429ffd11acee4e4dc7;p=netatalk.git diff --git a/etc/cnid_dbd/cmd_dbd.c b/etc/cnid_dbd/cmd_dbd.c index c77bf79a..78e5cd47 100644 --- a/etc/cnid_dbd/cmd_dbd.c +++ b/etc/cnid_dbd/cmd_dbd.c @@ -1,5 +1,5 @@ /* - $Id: cmd_dbd.c,v 1.8 2009-10-12 11:30:52 franklahm Exp $ + $Id: cmd_dbd.c,v 1.21 2009-12-21 06:41:09 franklahm Exp $ Copyright (c) 2009 Frank Lahm @@ -91,7 +91,7 @@ static int exclusive; /* Exclusive volume access */ static struct db_param db_param = { NULL, /* Volume dirpath */ 1, /* bdb logfile autoremove */ - 16384, /* bdb cachesize */ + 64 * 1024 * 1024, /* bdb cachesize */ -1, /* not used ... */ -1, "", @@ -131,7 +131,7 @@ static void sig_handler(int signo) return; } -void set_signal(void) +static void set_signal(void) { struct sigaction sv; @@ -165,7 +165,7 @@ void set_signal(void) } } -int get_lock(const char *dbpath) +static int get_lock(const char *dbpath) { int lockfd; char lockpath[PATH_MAX]; @@ -215,7 +215,7 @@ int get_lock(const char *dbpath) return lockfd; } -void free_lock(int lockfd) +static void free_lock(int lockfd) { struct flock lock; @@ -227,9 +227,9 @@ void free_lock(int lockfd) close(lockfd); } -static void usage () +static void usage (void) { - printf("Usage: dbd [-e|-v|-x|-u] -d [-i] | -s [-n]| -r [-f] \n" + printf("Usage: dbd [-e|-v|-x] -d [-i] | -s [-n]| -r [-f] | -u \n" "dbd can dump, scan, reindex and rebuild Netatalk dbd CNID databases.\n" "dbd must be run with appropiate permissions i.e. as root.\n\n" "Main commands are:\n" @@ -255,7 +255,7 @@ static void usage () " 7. Check for orphaned CNIDs in database (requires -e)\n" " 8. Open and close adouble files\n" " Option: -f wipe database and rebuild from IDs stored in AppleDouble files,\n" - " only available for volumes with 'cachecnid' option. Implies -e.\n" + " only available for volumes without 'nocnidcache' option. Implies -e.\n" " -u Prepare upgrade:\n" " Before installing an upgraded version of Netatalk that is linked against\n" " a newer BerkeleyDB lib, run `dbd -u ...` from the OLD Netatalk pior to\n" @@ -266,9 +266,8 @@ static void usage () " -x rebuild indexes (just for completeness, mostly useless!)\n" " -v verbose\n\n" "WARNING:\n" - "If you want/need to run an -r -f rebuild after adding 'cachecnid' to a volume configuration,\n" - "you must run a rebuild with -r alone at first in order to sync all existing CNIDs from the db\n" - "to the AppleDouble files!\n" + "For -r -f restore of the CNID database from the adouble files, the CNID must of course\n" + "be synched to them files first with a plain -r rebuild !\n" ); } @@ -285,6 +284,8 @@ int main(int argc, char **argv) usage(); exit(EXIT_FAILURE); } + /* Inhereting perms in ad_mkdir etc requires this */ + ad_setfuid(0); while ((c = getopt(argc, argv, ":dsnruvxife")) != -1) { switch(c) { @@ -352,13 +353,13 @@ int main(int argc, char **argv) /* Setup logging. Should be portable among *NIXes */ if (!verbose) - setuplog("default log_info /dev/tty"); + setuplog("console log_info /dev/tty"); else - setuplog("default log_debug /dev/tty"); + setuplog("console log_debug /dev/tty"); /* Load .volinfo file */ if (loadvolinfo(volpath, &volinfo) == -1) { - dbd_log( LOGSTD, "Unkown volume options!"); + dbd_log( LOGSTD, "Not a Netatalk volume at '%s', no .volinfo file at '%s/.AppleDesktop/.volinfo' or unknown volume options", volpath, volpath); exit(EXIT_FAILURE); } if (vol_load_charsets(&volinfo) == -1) { @@ -366,6 +367,12 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } + /* Sanity checks to ensure we can touch this volume */ + if (volinfo.v_vfs_ea != AFPVOL_EA_AD && volinfo.v_vfs_ea != AFPVOL_EA_SYS) { + dbd_log( LOGSTD, "Unknown Extended Attributes option: %u", volinfo.v_vfs_ea); + exit(EXIT_FAILURE); + } + /* Put "/.AppleDB" at end of volpath, get path from volinfo file */ if ( (strlen(volinfo.v_dbpath) + strlen("/.AppleDB")) > (PATH_MAX - 1) ) { dbd_log( LOGSTD, "Volume pathname too long"); @@ -374,6 +381,22 @@ int main(int argc, char **argv) strncpy(dbpath, volinfo.v_dbpath, PATH_MAX - 9 - 1); strcat(dbpath, "/.AppleDB"); + /* Check or create dbpath */ + int dbdirfd = open(dbpath, O_RDONLY); + if (dbdirfd == -1 && errno == ENOENT) { + if (errno == ENOENT) { + if ((mkdir(dbpath, 0755)) != 0) { + dbd_log( LOGSTD, "Can't create .AppleDB for \"%s\": %s", dbpath, strerror(errno)); + exit(EXIT_FAILURE); + } + } else { + dbd_log( LOGSTD, "Somethings wrong with .AppleDB for \"%s\", giving up: %s", dbpath, strerror(errno)); + exit(EXIT_FAILURE); + } + } else { + close(dbdirfd); + } + /* Before we do anything else, check if there is an instance of cnid_dbd running already and silently exit if yes. @@ -411,7 +434,7 @@ int main(int argc, char **argv) if (exclusive) dbd_log( LOGDEBUG, "Finished recovery."); - if (dbif_open(dbd, &db_param, rebuildindexes) < 0) { + if (dbif_open(dbd, NULL, rebuildindexes) < 0) { dbif_close(dbd); goto exit_failure; } @@ -427,7 +450,7 @@ int main(int argc, char **argv) if (dbif_dump(dbd, dumpindexes) < 0) { dbd_log( LOGSTD, "Error dumping database"); } - } else if ((rebuild && ! nocniddb) || (scan && nocniddb)) { + } else if ((rebuild && ! nocniddb) || scan) { if (cmd_dbd_scanvol(dbd, &volinfo, flags) < 0) { dbd_log( LOGSTD, "Error repairing database."); }