From 84c3a8f52deced7429f9d72276232ee282b3b823 Mon Sep 17 00:00:00 2001 From: Frank Lahm Date: Fri, 17 Feb 2012 17:22:43 +0100 Subject: [PATCH] Convert ad file suite and CNID daemons to use new config code --- bin/ad/ad.c | 10 ++- bin/ad/ad.h | 7 +- bin/ad/ad_cp.c | 25 +++--- bin/ad/ad_find.c | 13 ++- bin/ad/ad_ls.c | 5 +- bin/ad/ad_mv.c | 13 ++- bin/ad/ad_rm.c | 21 +++-- bin/ad/ad_util.c | 90 ++++++++++----------- etc/afpd/afp_avahi.c | 1 + etc/afpd/afp_config.c | 23 +++--- etc/afpd/auth.c | 15 ++-- etc/afpd/catsearch.c | 8 +- etc/afpd/directory.c | 36 ++++----- etc/afpd/extattrs.c | 1 + etc/afpd/fce_api.c | 2 +- etc/afpd/file.c | 26 +++--- etc/afpd/filedir.c | 8 +- etc/afpd/fork.c | 6 +- etc/afpd/mangle.c | 2 +- etc/afpd/uam.c | 5 +- etc/afpd/volume.c | 20 ++--- etc/cnid_dbd/cmd_dbd.c | 54 ++++++++----- etc/cnid_dbd/cmd_dbd.h | 4 +- etc/cnid_dbd/cmd_dbd_scanvol.c | 99 ++++++++++------------- etc/cnid_dbd/cnid_metad.c | 109 +++++++++++-------------- etc/cnid_dbd/main.c | 141 ++++++++++++++++++--------------- etc/cnid_dbd/pack.c | 16 ++-- etc/cnid_dbd/pack.h | 11 +-- include/atalk/directory.h | 1 + include/atalk/globals.h | 3 +- include/atalk/netatalk_conf.h | 1 + include/atalk/volume.h | 6 +- libatalk/util/cnid.c | 1 - libatalk/util/netatalk_conf.c | 32 ++++++-- 34 files changed, 411 insertions(+), 404 deletions(-) diff --git a/bin/ad/ad.c b/bin/ad/ad.c index 2287ee6a..ea312fa9 100644 --- a/bin/ad/ad.c +++ b/bin/ad/ad.c @@ -27,9 +27,9 @@ #include #include -#include #include #include +#include #include "ad.h" @@ -46,6 +46,8 @@ static void show_version(void) int main(int argc, char **argv) { + AFPObj obj = { 0 }; + setuplog("default:note", "/dev/tty"); if (argc < 2) { @@ -53,6 +55,12 @@ int main(int argc, char **argv) return 1; } + if (afp_config_parse(&obj) != 0) + return 1; + + if (load_volumes(&obj, NULL) != 0) + return 1; + if (STRCMP(argv[1], ==, "ls")) return ad_ls(argc - 1, argv + 1); else if (STRCMP(argv[1], ==, "cp")) diff --git a/bin/ad/ad.h b/bin/ad/ad.h index b0e8efba..d97f4b06 100644 --- a/bin/ad/ad.h +++ b/bin/ad/ad.h @@ -23,9 +23,9 @@ #include #include -#include #include #include +#include #define DIR_DOT_OR_DOTDOT(a) \ ((strcmp(a, ".") == 0) || (strcmp(a, "..") == 0)) @@ -49,8 +49,7 @@ enum logtype {STD, DBG}; } while (0) typedef struct { - struct volinfo volinfo; - struct vol volume; + struct vol *vol; char db_stamp[ADEDLEN_PRIVSYN]; } afpvol_t; @@ -68,7 +67,7 @@ extern int openvol(const char *path, afpvol_t *vol); extern void closevol(afpvol_t *vol); extern cnid_t cnid_for_path(const afpvol_t *vol, const char *path, cnid_t *did); extern cnid_t cnid_for_paths_parent(const afpvol_t *vol, const char *path, cnid_t *did); -extern char *utompath(const struct volinfo *volinfo, const char *upath); +extern char *utompath(const struct vol *, const char *); extern int convert_dots_encoding(const afpvol_t *svol, const afpvol_t *dvol, char *path, size_t buflen); typedef struct { diff --git a/bin/ad/ad_cp.c b/bin/ad/ad_cp.c index f280aeb9..40500441 100644 --- a/bin/ad/ad_cp.c +++ b/bin/ad/ad_cp.c @@ -67,7 +67,6 @@ #include #include #include -#include #include #include #include @@ -475,7 +474,7 @@ static int copy(const char *path, } /* Convert basename to appropiate volume encoding */ - if (dvolume.volinfo.v_path) { + if (dvolume.vol->v_path) { if ((convert_dots_encoding(&svolume, &dvolume, to.p_path, MAXPATHLEN)) == -1) { SLOG("Error converting name for %s", to.p_path); badcp = rval = 1; @@ -511,7 +510,7 @@ static int copy(const char *path, } /* Create ad dir and copy ".Parent" */ - if (dvolume.volinfo.v_path && dvolume.volinfo.v_adouble == AD_VERSION2) { + if (dvolume.vol->v_path && dvolume.vol->v_adouble == AD_VERSION2) { /* Create ".AppleDouble" dir */ mode_t omask = umask(0); @@ -520,9 +519,9 @@ static int copy(const char *path, mkdir(cfrombstr(addir), 02777); bdestroy(addir); - if (svolume.volinfo.v_path && svolume.volinfo.v_adouble == AD_VERSION2) { + if (svolume.vol->v_path && svolume.vol->v_adouble == AD_VERSION2) { /* copy ".Parent" file */ - if (dvolume.volume.vfs->vfs_copyfile(&dvolume.volume, -1, path, to.p_path)) { + if (dvolume.vol->vfs->vfs_copyfile(dvolume.vol, -1, path, to.p_path)) { SLOG("Error copying adouble for %s -> %s", path, to.p_path); badcp = rval = 1; break; @@ -543,12 +542,12 @@ static int copy(const char *path, badcp = rval = 1; break; } - ad_init_old(&ad, dvolume.volinfo.v_adouble, dvolume.volinfo.v_ad_options); + ad_init(&ad, dvolume.vol); if (ad_open(&ad, to.p_path, ADFLAGS_HF | ADFLAGS_DIR | ADFLAGS_RDWR | ADFLAGS_CREATE, 0666) != 0) { ERROR("Error opening adouble for: %s", to.p_path); } ad_setid( &ad, st.st_dev, st.st_ino, did, pdid, dvolume.db_stamp); - ad_setname(&ad, utompath(&dvolume.volinfo, basename(to.p_path))); + ad_setname(&ad, utompath(dvolume.vol, basename(to.p_path))); ad_setdate(&ad, AD_DATE_CREATE | AD_DATE_UNIX, st.st_mtime); ad_setdate(&ad, AD_DATE_MODIFY | AD_DATE_UNIX, st.st_mtime); ad_setdate(&ad, AD_DATE_ACCESS | AD_DATE_UNIX, st.st_mtime); @@ -583,12 +582,12 @@ static int copy(const char *path, if (ftw_copy_file(ftw, path, statp, dne)) badcp = rval = 1; - if (dvolume.volinfo.v_path && dvolume.volinfo.v_adouble == AD_VERSION2) { + if (dvolume.vol->v_path && dvolume.vol->v_adouble == AD_VERSION2) { mode_t omask = umask(0); - if (svolume.volinfo.v_path && svolume.volinfo.v_adouble == AD_VERSION2) { + if (svolume.vol->v_path && svolume.vol->v_adouble == AD_VERSION2) { /* copy ad-file */ - if (dvolume.volume.vfs->vfs_copyfile(&dvolume.volume, -1, path, to.p_path)) { + if (dvolume.vol->vfs->vfs_copyfile(dvolume.vol, -1, path, to.p_path)) { SLOG("Error copying adouble for %s -> %s", path, to.p_path); badcp = rval = 1; break; @@ -610,12 +609,12 @@ static int copy(const char *path, badcp = rval = 1; break; } - ad_init_old(&ad, dvolume.volinfo.v_adouble, dvolume.volinfo.v_ad_options); + ad_init(&ad, dvolume.vol); if (ad_open(&ad, to.p_path, ADFLAGS_HF | ADFLAGS_RDWR | ADFLAGS_CREATE, 0666) != 0) { ERROR("Error opening adouble for: %s", to.p_path); } ad_setid( &ad, st.st_dev, st.st_ino, cnid, did, dvolume.db_stamp); - ad_setname(&ad, utompath(&dvolume.volinfo, basename(to.p_path))); + ad_setname(&ad, utompath(dvolume.vol, basename(to.p_path))); ad_setdate(&ad, AD_DATE_CREATE | AD_DATE_UNIX, st.st_mtime); ad_setdate(&ad, AD_DATE_MODIFY | AD_DATE_UNIX, st.st_mtime); ad_setdate(&ad, AD_DATE_ACCESS | AD_DATE_UNIX, st.st_mtime); @@ -693,7 +692,7 @@ static int ftw_copy_file(const struct FTW *entp, /* remove existing destination file name, * create a new file */ (void)unlink(to.p_path); - (void)dvolume.volume.vfs->vfs_deletefile(&dvolume.volume, -1, to.p_path); + (void)dvolume.vol->vfs->vfs_deletefile(dvolume.vol, -1, to.p_path); to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT, sp->st_mode & ~(S_ISUID | S_ISGID)); } else { diff --git a/bin/ad/ad_find.c b/bin/ad/ad_find.c index 8501500c..20c67afb 100644 --- a/bin/ad/ad_find.c +++ b/bin/ad/ad_find.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -117,9 +116,9 @@ int ad_find(int argc, char **argv) uint16_t flags = CONV_TOLOWER; char namebuf[MAXPATHLEN + 1]; - if (convert_charset(vol.volinfo.v_volcharset, - vol.volinfo.v_volcharset, - vol.volinfo.v_maccharset, + if (convert_charset(vol.vol->v_volcharset, + vol.vol->v_volcharset, + vol.vol->v_maccharset, argv[optind], strlen(argv[optind]), namebuf, @@ -130,7 +129,7 @@ int ad_find(int argc, char **argv) int count; char resbuf[DBD_MAX_SRCH_RSLTS * sizeof(cnid_t)]; - if ((count = cnid_find(vol.volume.v_cdb, + if ((count = cnid_find(vol.vol->v_cdb, namebuf, strlen(namebuf), resbuf, @@ -146,7 +145,7 @@ int ad_find(int argc, char **argv) bufp += sizeof(cnid_t); bstring path = NULL; - bstring volpath = bfromcstr(vol.volinfo.v_path); + bstring volpath = bfromcstr(vol.vol->v_path); BSTRING_STRIP_SLASH(volpath); char buffer[12 + MAXPATHLEN + 1]; int buflen = 12 + MAXPATHLEN + 1; @@ -155,7 +154,7 @@ int ad_find(int argc, char **argv) struct bstrList *pathlist = bstrListCreateMin(32); while (did != DIRDID_ROOT) { - if ((name = cnid_resolve(vol.volume.v_cdb, &did, buffer, buflen)) == NULL) + if ((name = cnid_resolve(vol.vol->v_cdb, &did, buffer, buflen)) == NULL) goto next; bstrListPush(pathlist, bfromcstr(name)); } diff --git a/bin/ad/ad_ls.c b/bin/ad/ad_ls.c index ef3f4c33..8cda318a 100644 --- a/bin/ad/ad_ls.c +++ b/bin/ad/ad_ls.c @@ -33,7 +33,6 @@ #include #include -#include #include "ad.h" #define ADv2_DIRNAME ".AppleDouble" @@ -228,10 +227,10 @@ static void print_flags(char *path, afpvol_t *vol, const struct stat *st) if (S_ISDIR(st->st_mode)) adflags = ADFLAGS_DIR; - if (vol->volinfo.v_path == NULL) + if (vol->vol->v_path == NULL) return; - ad_init_old(&ad, vol->volinfo.v_adouble, vol->volinfo.v_ad_options); + ad_init(&ad, vol->vol); if ( ad_metadata(path, adflags, &ad) < 0 ) return; diff --git a/bin/ad/ad_mv.c b/bin/ad/ad_mv.c index 7dab6c6f..6991b276 100644 --- a/bin/ad/ad_mv.c +++ b/bin/ad/ad_mv.c @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -295,9 +294,9 @@ static int do_move(const char *from, const char *to) * 1) source AFP volume != dest AFP volume * 2) either source or dest isn't even an AFP volume */ - if (!svolume.volinfo.v_path - || !dvolume.volinfo.v_path - || strcmp(svolume.volinfo.v_path, dvolume.volinfo.v_path) != 0) + if (!svolume.vol->v_path + || !dvolume.vol->v_path + || strcmp(svolume.vol->v_path, dvolume.vol->v_path) != 0) mustcopy = 1; cnid_t cnid = 0; @@ -340,7 +339,7 @@ static int do_move(const char *from, const char *to) switch (sb.st_mode & S_IFMT) { case S_IFREG: - if (dvolume.volume.vfs->vfs_renamefile(&dvolume.volume, -1, from, to) != 0) { + if (dvolume.vol->vfs->vfs_renamefile(dvolume.vol, -1, from, to) != 0) { SLOG("Error moving adouble file for %s", from); return -1; } @@ -366,14 +365,14 @@ static int do_move(const char *from, const char *to) char *p = strdup(to); char *name = basename(p); - if (cnid_update(dvolume.volume.v_cdb, cnid, &sb, newdid, name, strlen(name)) != 0) { + if (cnid_update(dvolume.vol->v_cdb, cnid, &sb, newdid, name, strlen(name)) != 0) { SLOG("Cant update CNID for: %s", to); return 1; } free(p); struct adouble ad; - ad_init_old(&ad, dvolume.volinfo.v_adouble, dvolume.volinfo.v_ad_options); + ad_init(&ad, dvolume.vol); if (ad_open(&ad, to, S_ISDIR(sb.st_mode) ? (ADFLAGS_DIR | ADFLAGS_HF | ADFLAGS_RDWR) : ADFLAGS_HF | ADFLAGS_RDWR) != 0) { SLOG("Error opening adouble for: %s", to); return 1; diff --git a/bin/ad/ad_rm.c b/bin/ad/ad_rm.c index b9ef2c3c..e65d6f27 100644 --- a/bin/ad/ad_rm.c +++ b/bin/ad/ad_rm.c @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -201,8 +200,8 @@ static int rm(const char *path, switch (statp->st_mode & S_IFMT) { case S_IFLNK: - if (volume.volinfo.v_path) { - if ((volume.volinfo.v_adouble == AD_VERSION2) + if (volume.vol->v_path) { + if ((volume.vol->v_adouble == AD_VERSION2) && (strstr(path, ".AppleDouble") != NULL)) { /* symlink inside adouble dir */ if (unlink(path) != 0) @@ -216,7 +215,7 @@ static int rm(const char *path, SLOG("Error resolving CNID for %s", path); return -1; } - if (cnid_delete(volume.volume.v_cdb, cnid) != 0) { + if (cnid_delete(volume.vol->v_cdb, cnid) != 0) { SLOG("Error removing CNID %u for %s", ntohl(cnid), path); return -1; } @@ -235,8 +234,8 @@ static int rm(const char *path, return FTW_SKIP_SUBTREE; } - if (volume.volinfo.v_path) { - if ((volume.volinfo.v_adouble == AD_VERSION2) + if (volume.vol->v_path) { + if ((volume.vol->v_adouble == AD_VERSION2) && (strstr(path, ".AppleDouble") != NULL)) { /* should be adouble dir itself */ if (rmdir(path) != 0) { @@ -252,7 +251,7 @@ static int rm(const char *path, SLOG("Error resolving CNID for %s", path); return -1; } - if (cnid_delete(volume.volume.v_cdb, did) != 0) { + if (cnid_delete(volume.vol->v_cdb, did) != 0) { SLOG("Error removing CNID %u for %s", ntohl(did), path); return -1; } @@ -283,8 +282,8 @@ static int rm(const char *path, break; default: - if (volume.volinfo.v_path) { - if ((volume.volinfo.v_adouble == AD_VERSION2) + if (volume.vol->v_path) { + if ((volume.vol->v_adouble == AD_VERSION2) && (strstr(path, ".AppleDouble") != NULL)) { /* file in adouble dir */ if (unlink(path) != 0) @@ -298,13 +297,13 @@ static int rm(const char *path, SLOG("Error resolving CNID for %s", path); return -1; } - if (cnid_delete(volume.volume.v_cdb, cnid) != 0) { + if (cnid_delete(volume.vol->v_cdb, cnid) != 0) { SLOG("Error removing CNID %u for %s", ntohl(cnid), path); return -1; } /* Ignore errors, because with -R adouble stuff is always alread gone */ - volume.volume.vfs->vfs_deletefile(&volume.volume, -1, path); + volume.vol->vfs->vfs_deletefile(volume.vol, -1, path); } if (unlink(path) != 0) { diff --git a/bin/ad/ad_util.c b/bin/ad/ad_util.c index 4a8ff11b..d7e9fee5 100644 --- a/bin/ad/ad_util.c +++ b/bin/ad/ad_util.c @@ -59,12 +59,12 @@ #include #include -#include #include #include #include #include #include +#include #include "ad.h" @@ -103,39 +103,31 @@ int openvol(const char *path, afpvol_t *vol) memset(vol, 0, sizeof(afpvol_t)); /* try to find a .AppleDesktop/.volinfo */ - if (loadvolinfo((char *)path, &vol->volinfo) != 0) + if ((vol->vol = getvolbypath(path)) == NULL) return -1; - if (STRCMP(vol->volinfo.v_cnidscheme, != , "dbd")) - ERROR("\"%s\" isn't a \"dbd\" CNID volume!", vol->volinfo.v_path); - - if (vol_load_charsets(&vol->volinfo) == -1) - ERROR("Error loading charsets!"); + if (STRCMP(vol->vol->v_cnidscheme, != , "dbd")) + ERROR("\"%s\" isn't a \"dbd\" CNID volume!", vol->vol->v_path); /* Sanity checks to ensure we can touch this volume */ - if (vol->volinfo.v_adouble != AD_VERSION2) - ERROR("Unsupported adouble versions: %u", vol->volinfo.v_adouble); - - if (vol->volinfo.v_vfs_ea != AFPVOL_EA_SYS) - ERROR("Unsupported Extended Attributes option: %u", vol->volinfo.v_vfs_ea); + if (vol->vol->v_adouble != AD_VERSION2) + ERROR("Unsupported adouble versions: %u", vol->vol->v_adouble); - /* initialize sufficient struct vol for VFS initialisation */ - vol->volume.v_adouble = AD_VERSION2; - vol->volume.v_vfs_ea = AFPVOL_EA_SYS; - initvol_vfs(&vol->volume); + if (vol->vol->v_vfs_ea != AFPVOL_EA_SYS) + ERROR("Unsupported Extended Attributes option: %u", vol->vol->v_vfs_ea); - if ((vol->volinfo.v_flags & AFPVOL_NODEV)) + if ((vol->vol->v_flags & AFPVOL_NODEV)) flags |= CNID_FLAG_NODEV; - if ((vol->volume.v_cdb = cnid_open(vol->volinfo.v_path, - 0000, - "dbd", - flags, - vol->volinfo.v_dbd_host, - vol->volinfo.v_dbd_port)) == NULL) - ERROR("Cant initialize CNID database connection for %s", vol->volinfo.v_path); + if ((vol->vol->v_cdb = cnid_open(vol->vol->v_path, + 0000, + "dbd", + flags, + vol->vol->v_cnidserver, + vol->vol->v_cnidport)) == NULL) + ERROR("Cant initialize CNID database connection for %s", vol->vol->v_path); - cnid_getstamp(vol->volume.v_cdb, + cnid_getstamp(vol->vol->v_cdb, vol->db_stamp, sizeof(vol->db_stamp)); @@ -144,8 +136,8 @@ int openvol(const char *path, afpvol_t *vol) void closevol(afpvol_t *vol) { - if (vol->volume.v_cdb) - cnid_close(vol->volume.v_cdb); + if (vol->vol->v_cdb) + cnid_close(vol->vol->v_cdb); memset(vol, 0, sizeof(afpvol_t)); } @@ -153,7 +145,7 @@ void closevol(afpvol_t *vol) /* Taken form afpd/desktop.c */ -char *utompath(const struct volinfo *volinfo, const char *upath) +char *utompath(const struct vol *vol, const char *upath) { static char mpath[ MAXPATHLEN + 2]; /* for convert_charset dest_len parameter +2 */ char *m; @@ -168,22 +160,22 @@ char *utompath(const struct volinfo *volinfo, const char *upath) u = upath; outlen = strlen(upath); - if ((volinfo->v_casefold & AFPVOL_UTOMUPPER)) + if ((vol->v_casefold & AFPVOL_UTOMUPPER)) flags |= CONV_TOUPPER; - else if ((volinfo->v_casefold & AFPVOL_UTOMLOWER)) + else if ((vol->v_casefold & AFPVOL_UTOMLOWER)) flags |= CONV_TOLOWER; - if ((volinfo->v_flags & AFPVOL_EILSEQ)) { + if ((vol->v_flags & AFPVOL_EILSEQ)) { flags |= CONV__EILSEQ; } /* convert charsets */ - if ((size_t)-1 == ( outlen = convert_charset(volinfo->v_volcharset, + if ((size_t)-1 == ( outlen = convert_charset(vol->v_volcharset, CH_UTF8_MAC, - volinfo->v_maccharset, + vol->v_maccharset, u, outlen, mpath, MAXPATHLEN, &flags)) ) { SLOG("Conversion from %s to %s for %s failed.", - volinfo->v_volcodepage, volinfo->v_maccodepage, u); + vol->v_volcodepage, vol->v_maccodepage, u); return NULL; } @@ -213,26 +205,26 @@ int convert_dots_encoding(const afpvol_t *svol, const afpvol_t *dvol, char *path int pos = bname - path; uint16_t flags = 0; - if ( ! svol->volinfo.v_path) { + if ( ! svol->vol->v_path) { /* no source volume: escape special chars (eg ':') */ - from = dvol->volinfo.v_volcharset; /* src = dst charset */ + from = dvol->vol->v_volcharset; /* src = dst charset */ flags |= CONV_ESCAPEHEX; } else { - from = svol->volinfo.v_volcharset; + from = svol->vol->v_volcharset; } - if ( (svol->volinfo.v_path) - && ! (svol->volinfo.v_flags & AFPVOL_USEDOTS) - && (dvol->volinfo.v_flags & AFPVOL_USEDOTS)) { + if ( (svol->vol->v_path) + && ! (svol->vol->v_flags & AFPVOL_USEDOTS) + && (dvol->vol->v_flags & AFPVOL_USEDOTS)) { /* source is without dots, destination is with */ flags |= CONV_UNESCAPEHEX; - } else if (! (dvol->volinfo.v_flags & AFPVOL_USEDOTS)) { + } else if (! (dvol->vol->v_flags & AFPVOL_USEDOTS)) { flags |= CONV_ESCAPEDOTS; } int len = convert_charset(from, - dvol->volinfo.v_volcharset, - dvol->volinfo.v_maccharset, + dvol->vol->v_volcharset, + dvol->vol->v_maccharset, bname, strlen(bname), buf, MAXPATHLEN, &flags); @@ -276,8 +268,8 @@ cnid_t cnid_for_path(const afpvol_t *vol, cnid = htonl(2); - EC_NULL(rpath = rel_path_in_vol(path, vol->volinfo.v_path)); - EC_NULL(statpath = bfromcstr(vol->volinfo.v_path)); + EC_NULL(rpath = rel_path_in_vol(path, vol->vol->v_path)); + EC_NULL(statpath = bfromcstr(vol->vol->v_path)); EC_ZERO(bcatcstr(statpath, "/")); l = bsplit(rpath, '/'); @@ -290,7 +282,7 @@ cnid_t cnid_for_path(const afpvol_t *vol, cfrombstr(rpath), cfrombstr(l->entry[i]), cfrombstr(statpath), strerror(errno)); - if ((cnid = cnid_add(vol->volume.v_cdb, + if ((cnid = cnid_add(vol->vol->v_cdb, &st, *did, cfrombstr(l->entry[i]), @@ -344,8 +336,8 @@ cnid_t cnid_for_paths_parent(const afpvol_t *vol, *did = htonl(1); cnid = htonl(2); - EC_NULL(rpath = rel_path_in_vol(path, vol->volinfo.v_path)); - EC_NULL(statpath = bfromcstr(vol->volinfo.v_path)); + EC_NULL(rpath = rel_path_in_vol(path, vol->vol->v_path)); + EC_NULL(statpath = bfromcstr(vol->vol->v_path)); l = bsplit(rpath, '/'); if (l->qty == 1) @@ -359,7 +351,7 @@ cnid_t cnid_for_paths_parent(const afpvol_t *vol, cfrombstr(rpath), cfrombstr(l->entry[i]), cfrombstr(statpath), strerror(errno)); - if ((cnid = cnid_add(vol->volume.v_cdb, + if ((cnid = cnid_add(vol->vol->v_cdb, &st, *did, cfrombstr(l->entry[i]), diff --git a/etc/afpd/afp_avahi.c b/etc/afpd/afp_avahi.c index 7ed4b11e..f5eb73cd 100644 --- a/etc/afpd/afp_avahi.c +++ b/etc/afpd/afp_avahi.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "afp_avahi.h" #include "afp_config.h" diff --git a/etc/afpd/afp_config.c b/etc/afpd/afp_config.c index 27767c10..cdc9e4f0 100644 --- a/etc/afpd/afp_config.c +++ b/etc/afpd/afp_config.c @@ -26,6 +26,8 @@ #include #include #include +#include +#include #ifdef HAVE_LDAP #include @@ -74,6 +76,7 @@ int configinit(AFPObj *obj) EC_INIT; DSI *dsi, **next = &obj->dsi; char *p = NULL, *q = NULL; + const char *r; auth_load(obj->options.uampath, obj->options.uamlist); set_signature(&obj->options); @@ -120,21 +123,21 @@ int configinit(AFPObj *obj) /* Now register with zeroconf, we also need the volumes for that */ if (! (obj->options.flags & OPTION_NOZEROCONF)) { - load_volumes(obj); + load_volumes(obj, NULL); zeroconf_register(obj); } - if ((p = iniparser_getstring(obj->iniconfig, INISEC_AFP, "fcelistener", NULL))) { - LOG(log_note, logtype_afpd, "Adding FCE listener: %s", p); - fce_add_udp_socket(p); + if ((r = iniparser_getstring(obj->iniconfig, INISEC_AFP, "fcelistener", NULL))) { + LOG(log_note, logtype_afpd, "Adding FCE listener: %s", r); + fce_add_udp_socket(r); } - if ((p = iniparser_getstring(obj->iniconfig, INISEC_AFP, "fcecoalesce", NULL))) { - LOG(log_note, logtype_afpd, "Fce coalesce: %s", p); - fce_set_coalesce(p); + if ((r = iniparser_getstring(obj->iniconfig, INISEC_AFP, "fcecoalesce", NULL))) { + LOG(log_note, logtype_afpd, "Fce coalesce: %s", r); + fce_set_coalesce(r); } - if ((p = iniparser_getstring(obj->iniconfig, INISEC_AFP, "fceevents", NULL))) { - LOG(log_note, logtype_afpd, "Fce events: %s", p); - fce_set_events(p); + if ((r = iniparser_getstring(obj->iniconfig, INISEC_AFP, "fceevents", NULL))) { + LOG(log_note, logtype_afpd, "Fce events: %s", r); + fce_set_events(r); } diff --git a/etc/afpd/auth.c b/etc/afpd/auth.c index d6054f54..9f5034dc 100644 --- a/etc/afpd/auth.c +++ b/etc/afpd/auth.c @@ -50,7 +50,6 @@ extern void afp_get_cmdline( int *ac, char ***av ); #include "acls.h" #endif -int afp_version = 11; static int afp_version_index; static struct uam_mod uam_modules = {NULL, NULL, &uam_modules, &uam_modules}; static struct uam_obj uam_login = {"", "", 0, {{NULL, NULL, NULL, NULL }}, &uam_login, @@ -146,7 +145,7 @@ static int afp_null_nolog(AFPObj *obj _U_, char *ibuf _U_, size_t ibuflen _U_, return( AFPERR_NOOP ); } -static int set_auth_switch(int expired) +static int set_auth_switch(const AFPObj *obj, int expired) { int i; @@ -167,7 +166,7 @@ static int set_auth_switch(int expired) } else { afp_switch = postauth_switch; - switch (afp_version) { + switch (obj->afp_version) { case 33: case 32: @@ -336,7 +335,7 @@ static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void), int expi #endif /* ADMIN_GRP */ obj->uid = geteuid(); - set_auth_switch(expired); + set_auth_switch(obj, expired); /* save our euid, we need it for preexec_close */ obj->uid = geteuid(); obj->logout = logout; @@ -631,7 +630,7 @@ static int get_version(AFPObj *obj, char *ibuf, size_t ibuflen, size_t len) num = sizeof( afp_versions ) / sizeof( afp_versions[ 0 ]); for ( i = 0; i < num; i++ ) { if ( strncmp( ibuf, afp_versions[ i ].av_name , len ) == 0 ) { - afp_version = afp_versions[ i ].av_number; + obj->afp_version = afp_versions[ i ].av_number; afp_version_index = i; break; } @@ -640,7 +639,7 @@ static int get_version(AFPObj *obj, char *ibuf, size_t ibuflen, size_t len) return AFPERR_BADVERS ; /* FIXME Hack */ - if (afp_version >= 30 && sizeof(off_t) != 8) { + if (obj->afp_version >= 30 && sizeof(off_t) != 8) { LOG(log_error, logtype_afpd, "get_version: no LARGE_FILE support recompile!" ); return AFPERR_BADVERS ; } @@ -892,7 +891,7 @@ int afp_changepw(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rb if ((len + 1) & 1) /* pad byte */ ibuf++; - if ( afp_version < 30) { + if (obj->afp_version < 30) { len = (unsigned char) *ibuf++; if ( len > sizeof(username) - 1) { return AFPERR_PARAM; @@ -929,7 +928,7 @@ int afp_changepw(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rb (ret == AFPERR_AUTHCONT) ? "continued" : (ret ? "failed" : "succeeded")); if ( ret == AFP_OK ) - set_auth_switch(0); + set_auth_switch(obj, 0); return ret; } diff --git a/etc/afpd/catsearch.c b/etc/afpd/catsearch.c index 3a6f4cc9..d3dfc7d4 100644 --- a/etc/afpd/catsearch.c +++ b/etc/afpd/catsearch.c @@ -281,7 +281,7 @@ static int crit_check(struct vol *vol, struct path *path) { * An other option would be to call get_id in utompath but * we need to pass parent dir */ - if (!(path->m_name = utompath(vol, path->u_name, 0 , utf8_encoding()) )) { + if (!(path->m_name = utompath(vol, path->u_name, 0 , utf8_encoding(vol->v_obj)) )) { /*retry with the right id */ cnid_t id; @@ -294,7 +294,7 @@ static int crit_check(struct vol *vol, struct path *path) { } /* save the id for getfilparm */ path->id = id; - if (!(path->m_name = utompath(vol, path->u_name, id , utf8_encoding()))) { + if (!(path->m_name = utompath(vol, path->u_name, id , utf8_encoding(vol->v_obj)))) { return 0; } } @@ -784,7 +784,7 @@ static int catsearch_db(const AFPObj *obj, memset(&path, 0, sizeof(path)); path.u_name = name; - path.m_name = utompath(vol, name, cnid, utf8_encoding()); + path.m_name = utompath(vol, name, cnid, utf8_encoding(vol->v_obj)); if (of_stat(&path) != 0) { switch (errno) { @@ -1037,7 +1037,7 @@ static int catsearch_afp(AFPObj *obj _U_, char *ibuf, size_t ibuflen, memcpy (c1.utf8name, spec1+2, namelen); c1.utf8name[namelen] = 0; - if ((uname = mtoupath(vol, c1.utf8name, 0, utf8_encoding())) == NULL) + if ((uname = mtoupath(vol, c1.utf8name, 0, utf8_encoding(obj))) == NULL) return AFPERR_PARAM; /* convert charset */ diff --git a/etc/afpd/directory.c b/etc/afpd/directory.c index 844d346a..1e1e97a9 100644 --- a/etc/afpd/directory.c +++ b/etc/afpd/directory.c @@ -307,7 +307,7 @@ static int cname_mtouname(const struct vol *vol, const struct dir *dir, struct p char *t; cnid_t fileid = 0; - if (afp_version >= 30) { + if (vol->v_obj->afp_version >= 30) { if (toUTF8) { if (dir->d_did == DIRDID_ROOT_PARENT) { /* @@ -339,7 +339,7 @@ static int cname_mtouname(const struct vol *vol, const struct dir *dir, struct p /* duplicate work but we can't reuse all convert_char we did in demangle_osx * flags weren't the same */ - if ( (t = utompath(vol, ret->u_name, fileid, utf8_encoding())) ) { + if ( (t = utompath(vol, ret->u_name, fileid, utf8_encoding(vol->v_obj))) ) { /* at last got our view of mac name */ strcpy(ret->m_name, t); } @@ -348,7 +348,7 @@ static int cname_mtouname(const struct vol *vol, const struct dir *dir, struct p /* If we haven't got it by now, get it */ if (ret->u_name == NULL) { - if ((ret->u_name = mtoupath(vol, ret->m_name, dir->d_did, utf8_encoding())) == NULL) { + if ((ret->u_name = mtoupath(vol, ret->m_name, dir->d_did, utf8_encoding(vol->v_obj))) == NULL) { afp_errno = AFPERR_PARAM; return -1; } @@ -601,7 +601,7 @@ struct dir *dirlookup(const struct vol *vol, cnid_t did) goto exit; } - utf8 = utf8_encoding(); + utf8 = utf8_encoding(vol->v_obj); maxpath = (utf8) ? MAXPATHLEN - 7 : 255; /* Get it from the database */ @@ -823,7 +823,7 @@ struct dir *dir_new(const char *m_name, return NULL; } - if (convert_string_allocate( (utf8_encoding()) ? CH_UTF8_MAC : vol->v_maccharset, + if (convert_string_allocate( (utf8_encoding(vol->v_obj)) ? CH_UTF8_MAC : vol->v_maccharset, CH_UCS2, m_name, -1, (char **)&dir->d_m_name_ucs2) == (size_t)-1 ) { @@ -929,7 +929,7 @@ struct dir *dir_add(struct vol *vol, const struct dir *dir, struct path *path, i /* Get macname from unixname */ if (path->m_name == NULL) { - if ((path->m_name = utompath(vol, path->u_name, id, utf8_encoding())) == NULL) { + if ((path->m_name = utompath(vol, path->u_name, id, utf8_encoding(vol->v_obj))) == NULL) { LOG(log_error, logtype_afpd, "dir_add(\"%s\"): can't assign macname", path->u_name); err = 2; goto exit; @@ -1161,13 +1161,13 @@ struct path *cname(struct vol *vol, struct dir *dir, char **cpath) data++; len = (unsigned char) *data++; size = 2; - if (afp_version >= 30) { + if (vol->v_obj->afp_version >= 30) { ret.m_type = 3; toUTF8 = 1; } break; case 3: - if (afp_version >= 30) { + if (vol->v_obj->afp_version >= 30) { data++; memcpy(&hint, data, sizeof(hint)); hint = ntohl(hint); @@ -1509,7 +1509,7 @@ int getdirparams(const AFPObj *obj, if ((s_path->m_name = utompath(vol, upath, dir->d_did, - utf8_encoding())) == NULL) { + utf8_encoding(obj))) == NULL) { LOG(log_error, logtype_afpd, "getdirparams(\"%s\"): can't assign macname", cfrombstr(dir->d_fullpath)); @@ -1654,7 +1654,7 @@ int getdirparams(const AFPObj *obj, Just pass back the same basic block for all directories. */ case DIRPBIT_PDINFO : - if (afp_version >= 30) { /* UTF8 name */ + if (obj->afp_version >= 30) { /* UTF8 name */ utf8 = kTextEncodingUTF8; if (dir->d_m_name) /* root of parent can have a null name */ utf_nameoff = data; @@ -1878,7 +1878,7 @@ int setdirparams(struct vol *vol, struct path *path, uint16_t d_bitmap, char *bu ProDOS information block. Skip over the data and report nothing amiss. */ case DIRPBIT_PDINFO : - if (afp_version < 30) { + if (vol->v_obj->afp_version < 30) { buf += 6; } else { @@ -2007,7 +2007,7 @@ int setdirparams(struct vol *vol, struct path *path, uint16_t d_bitmap, char *bu case DIRPBIT_ACCESS : break; case DIRPBIT_PDINFO : - if (afp_version >= 30) { + if (vol->v_obj->afp_version >= 30) { err = AFPERR_BITMAP; goto setdirparam_done; } @@ -2439,7 +2439,7 @@ int afp_mapid(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *r *rbuflen = 0; if (sfunc >= 3 && sfunc <= 6) { - if (afp_version < 30) { + if (obj->afp_version < 30) { return( AFPERR_PARAM ); } utf8 = 1; @@ -2479,7 +2479,7 @@ int afp_mapid(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *r case 5 : /* UUID -> username */ case 6 : /* UUID -> groupname */ - if ((afp_version < 32) || !(obj->options.flags & OPTION_UUID )) + if ((obj->afp_version < 32) || !(obj->options.flags & OPTION_UUID )) return AFPERR_PARAM; LOG(log_debug, logtype_afpd, "afp_mapid: valid UUID request"); uuidtype_t type; @@ -2542,7 +2542,7 @@ int afp_mapid(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *r return( AFP_OK ); } -int afp_mapname(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen) +int afp_mapname(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen) { struct passwd *pw; struct group *gr; @@ -2553,11 +2553,11 @@ int afp_mapname(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, siz ibuf++; sfunc = (unsigned char) *ibuf++; *rbuflen = 0; - LOG(log_debug, logtype_afpd, "afp_mapname: sfunc: %d, afp_version: %d", sfunc, afp_version); + LOG(log_debug, logtype_afpd, "afp_mapname: sfunc: %d", sfunc); switch ( sfunc ) { case 1 : case 2 : /* unicode */ - if (afp_version < 30) { + if (obj->afp_version < 30) { return( AFPERR_PARAM ); } memcpy(&ulen, ibuf, sizeof(ulen)); @@ -2571,7 +2571,7 @@ int afp_mapname(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, siz break; case 5 : /* username -> UUID */ case 6 : /* groupname -> UUID */ - if ((afp_version < 32) || !(obj->options.flags & OPTION_UUID )) + if ((obj->afp_version < 32) || !(obj->options.flags & OPTION_UUID )) return AFPERR_PARAM; memcpy(&ulen, ibuf, sizeof(ulen)); len = ntohs(ulen); diff --git a/etc/afpd/extattrs.c b/etc/afpd/extattrs.c index c9747f27..4cbeb642 100644 --- a/etc/afpd/extattrs.c +++ b/etc/afpd/extattrs.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "volume.h" #include "desktop.h" diff --git a/etc/afpd/fce_api.c b/etc/afpd/fce_api.c index 87d25035..6f6bd0fe 100644 --- a/etc/afpd/fce_api.c +++ b/etc/afpd/fce_api.c @@ -527,7 +527,7 @@ int fce_register_file_modification( struct ofork *ofork ) vol = ofork->of_vol; - if (NULL == (u_name = mtoupath(vol, of_name(ofork), ofork->of_did, utf8_encoding()))) + if (NULL == (u_name = mtoupath(vol, of_name(ofork), ofork->of_did, utf8_encoding(vol->v_obj)))) { return AFPERR_MISC; } diff --git a/etc/afpd/file.c b/etc/afpd/file.c index 07813ef4..c24d296b 100644 --- a/etc/afpd/file.c +++ b/etc/afpd/file.c @@ -119,7 +119,7 @@ char *set_name(const struct vol *vol, char *data, cnid_t pid, char *name, cnid_t if (!utf8) { /* want mac name */ - if (utf8_encoding()) { + if (utf8_encoding(vol->v_obj)) { /* but name is an utf8 mac name */ char *u, *m; @@ -299,7 +299,7 @@ int getmetadata(const AFPObj *obj, data = buf; if ( ((bitmap & ( (1 << FILPBIT_FINFO)|(1 << FILPBIT_LNAME)|(1 <m_name) - || (bitmap & ( (1 << FILPBIT_LNAME) ) && utf8_encoding()) /* FIXME should be m_name utf8 filename */ + || (bitmap & ( (1 << FILPBIT_LNAME) ) && utf8_encoding(obj)) /* FIXME should be m_name utf8 filename */ || (bitmap & (1 << FILPBIT_FNUM))) { if (!path->id) { bstring fullpath; @@ -316,7 +316,7 @@ int getmetadata(const AFPObj *obj, /* Get macname from unixname first */ if (path->m_name == NULL) { - if ((path->m_name = utompath(vol, upath, id, utf8_encoding())) == NULL) { + if ((path->m_name = utompath(vol, upath, id, utf8_encoding(obj))) == NULL) { LOG(log_error, logtype_afpd, "getmetadata: utompath error"); return AFPERR_MISC; } @@ -348,7 +348,7 @@ int getmetadata(const AFPObj *obj, return afp_errno; if (!path->m_name) { - path->m_name = utompath(vol, upath, id, utf8_encoding()); + path->m_name = utompath(vol, upath, id, utf8_encoding(vol->v_obj)); } } while ( bitmap != 0 ) { @@ -467,7 +467,7 @@ int getmetadata(const AFPObj *obj, to "pXYZ" when we created it. See IA, Ver 2. */ case FILPBIT_PDINFO : - if (afp_version >= 30) { /* UTF8 name */ + if (obj->afp_version >= 30) { /* UTF8 name */ utf8 = kTextEncodingUTF8; utf_nameoff = data; data += sizeof( uint16_t ); @@ -919,7 +919,7 @@ int setfilparams(const AFPObj *obj, struct vol *vol, } break; case FILPBIT_PDINFO : - if (afp_version < 30) { /* else it's UTF8 name */ + if (obj->afp_version < 30) { /* else it's UTF8 name */ achar = *buf; buf += 2; /* Keep special case to support crlf translations */ @@ -1004,7 +1004,7 @@ int setfilparams(const AFPObj *obj, struct vol *vol, } break; case FILPBIT_PDINFO : - if (afp_version < 30) { /* else it's UTF8 name */ + if (obj->afp_version < 30) { /* else it's UTF8 name */ memcpy(ad_entry( adp, ADEID_FINDERI ), fdType, 4 ); memcpy(ad_entry( adp, ADEID_FINDERI ) + 4, "pdos", 4 ); break; @@ -1148,14 +1148,14 @@ size_t plen = 0; uint16_t len16; uint32_t hint; - if ( type != 2 && !(afp_version >= 30 && type == 3) ) { + if ( type != 2 && !(vol->v_obj->afp_version >= 30 && type == 3) ) { return -1; } ibuf++; switch (type) { case 2: if (( plen = (unsigned char)*ibuf++ ) != 0 ) { - if (afp_version >= 30) { + if (vol->v_obj->afp_version >= 30) { /* convert it to UTF8 */ if ((plen = mtoUTF8(vol, ibuf, plen, newname, AFPOBJ_TMPSIZ)) == (size_t)-1) @@ -1299,7 +1299,7 @@ int afp_copyfile(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, si /* newname is always only a filename so curdir *is* its * parent folder */ - if (NULL == (upath = mtoupath(d_vol, newname, curdir->d_did, utf8_encoding()))) { + if (NULL == (upath = mtoupath(d_vol, newname, curdir->d_did, utf8_encoding(d_vol->v_obj)))) { retvalue =AFPERR_PARAM; goto copy_exit; } @@ -1676,7 +1676,7 @@ reenumerate_id(struct vol *vol, char *name, struct dir *dir) /* ------------------------------ resolve a file id */ -int afp_resolveid(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen) +int afp_resolveid(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen) { struct vol *vol; struct dir *dir; @@ -1762,12 +1762,12 @@ retry: /* directories are bad */ if (S_ISDIR(path.st.st_mode)) { /* OS9 and OSX don't return the same error code */ - return (afp_version >=30)?AFPERR_NOID:AFPERR_BADTYPE; + return (obj->afp_version >=30)?AFPERR_NOID:AFPERR_BADTYPE; } memcpy(&bitmap, ibuf, sizeof(bitmap)); bitmap = ntohs( bitmap ); - if (NULL == (path.m_name = utompath(vol, upath, cnid, utf8_encoding()))) { + if (NULL == (path.m_name = utompath(vol, upath, cnid, utf8_encoding(obj)))) { return AFPERR_NOID; } path.id = cnid; diff --git a/etc/afpd/filedir.c b/etc/afpd/filedir.c index e4b88d95..8f1109c9 100644 --- a/etc/afpd/filedir.c +++ b/etc/afpd/filedir.c @@ -249,7 +249,7 @@ static int moveandrename(const struct vol *vol, adflags = 0; if (!isdir) { - if ((oldunixname = strdup(mtoupath(vol, oldname, sdir->d_did, utf8_encoding()))) == NULL) + if ((oldunixname = strdup(mtoupath(vol, oldname, sdir->d_did, utf8_encoding(vol->v_obj)))) == NULL) return AFPERR_PARAM; /* can't convert */ id = cnid_get(vol->v_cdb, sdir->d_did, oldunixname, strlen(oldunixname)); @@ -316,7 +316,7 @@ static int moveandrename(const struct vol *vol, } } - if (NULL == (upath = mtoupath(vol, newname, curdir->d_did, utf8_encoding()))){ + if (NULL == (upath = mtoupath(vol, newname, curdir->d_did, utf8_encoding(vol->v_obj)))){ rc = AFPERR_PARAM; goto exit; } @@ -600,7 +600,7 @@ char *ctoupath(const struct vol *vol, struct dir *dir, char *name) { if (vol == NULL || dir == NULL || name == NULL) return NULL; - return absupath(vol, dir, mtoupath(vol, name, dir->d_did, utf8_encoding())); + return absupath(vol, dir, mtoupath(vol, name, dir->d_did, utf8_encoding(vol->v_obj))); } /* ------------------------- */ @@ -696,7 +696,7 @@ int afp_moveandrename(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U rc = moveandrename(vol, sdir, sdir_fd, oldname, newname, isdir); if ( rc == AFP_OK ) { - char *upath = mtoupath(vol, newname, pdid, utf8_encoding()); + char *upath = mtoupath(vol, newname, pdid, utf8_encoding(obj)); if (NULL == upath) { rc = AFPERR_PARAM; diff --git a/etc/afpd/fork.c b/etc/afpd/fork.c index 3f8018d0..f0ccf003 100644 --- a/etc/afpd/fork.c +++ b/etc/afpd/fork.c @@ -64,7 +64,7 @@ static int getforkparams(const AFPObj *obj, struct ofork *ofork, uint16_t bitmap vol = ofork->of_vol; dir = dirlookup(vol, ofork->of_did); - if (NULL == (path.u_name = mtoupath(vol, of_name(ofork), dir->d_did, utf8_encoding()))) { + if (NULL == (path.u_name = mtoupath(vol, of_name(ofork), dir->d_did, utf8_encoding(obj)))) { return( AFPERR_MISC ); } path.m_name = of_name(ofork); @@ -488,7 +488,7 @@ openfork_err: return ret; } -int afp_setforkparams(AFPObj *obj _U_, char *ibuf, size_t ibuflen, char *rbuf _U_, size_t *rbuflen) +int afp_setforkparams(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf _U_, size_t *rbuflen) { struct ofork *ofork; off_t size; @@ -536,7 +536,7 @@ int afp_setforkparams(AFPObj *obj _U_, char *ibuf, size_t ibuflen, char *rbuf _U is64 = 0; if ((bitmap & ( (1<= 30) { + if (obj->afp_version >= 30) { is64 = 4; } else diff --git a/etc/afpd/mangle.c b/etc/afpd/mangle.c index e4cbd311..21bd80f3 100644 --- a/etc/afpd/mangle.c +++ b/etc/afpd/mangle.c @@ -193,7 +193,7 @@ private_demangle(const struct vol *vol, char *mfilename, cnid_t did, cnid_t *osx } if (!osx) { /* convert back to mac name and check it's the same */ - t = utompath(vol, u_name, file_id, utf8_encoding()); + t = utompath(vol, u_name, file_id, utf8_encoding(vol->v_obj)); if (!strcmp(t, mfilename)) { return u_name; } diff --git a/etc/afpd/uam.c b/etc/afpd/uam.c index 0d7b6b2b..d99d381e 100644 --- a/etc/afpd/uam.c +++ b/etc/afpd/uam.c @@ -30,13 +30,12 @@ #include #include #include +#include #include "afp_config.h" #include "auth.h" #include "uam_auth.h" -#define utf8_encoding() (afp_version >= 30) - #ifdef TRU64 #include #include @@ -233,7 +232,7 @@ struct passwd *uam_getname(void *private, char *name, const int len) } #ifndef NO_REAL_USER_NAME - if ( (size_t) -1 == (namelen = convert_string((utf8_encoding())?CH_UTF8_MAC:obj->options.maccharset, + if ( (size_t) -1 == (namelen = convert_string((utf8_encoding(obj))?CH_UTF8_MAC:obj->options.maccharset, CH_UCS2, name, -1, username, sizeof(username)))) return NULL; diff --git a/etc/afpd/volume.c b/etc/afpd/volume.c index 11a43b95..af492528 100644 --- a/etc/afpd/volume.c +++ b/etc/afpd/volume.c @@ -262,7 +262,7 @@ static int getvolspace(const AFPObj *obj, struct vol *vol, spaceflag = AFPVOL_GVSMASK & vol->v_flags; /* report up to 2GB if afp version is < 2.2 (4GB if not) */ - maxsize = (afp_version < 22) ? 0x7fffffffL : 0xffffffffL; + maxsize = (obj->afp_version < 22) ? 0x7fffffffL : 0xffffffffL; #ifdef AFS if ( spaceflag == AFPVOL_NONE || spaceflag == AFPVOL_AFSGVS ) { @@ -423,12 +423,12 @@ static int getvolparams(const AFPObj *obj, uint16_t bitmap, struct vol *vol, str ashort |= VOLPBIT_ATTR_RO; } /* prior 2.1 only VOLPBIT_ATTR_RO is defined */ - if (afp_version > 20) { + if (obj->afp_version > 20) { if (vol->v_cdb != NULL && (vol->v_cdb->flags & CNID_FLAG_PERSISTENT)) ashort |= VOLPBIT_ATTR_FILEID; ashort |= VOLPBIT_ATTR_CATSEARCH; - if (afp_version >= 30) { + if (obj->afp_version >= 30) { ashort |= VOLPBIT_ATTR_UTF8; if (vol->v_flags & AFPVOL_UNIX_PRIV) ashort |= VOLPBIT_ATTR_UNIXPRIV; @@ -436,7 +436,7 @@ static int getvolparams(const AFPObj *obj, uint16_t bitmap, struct vol *vol, str ashort |= VOLPBIT_ATTR_TM; if (vol->v_flags & AFPVOL_NONETIDS) ashort |= VOLPBIT_ATTR_NONETIDS; - if (afp_version >= 32) { + if (obj->afp_version >= 32) { if (vol->v_vfs_ea) ashort |= VOLPBIT_ATTR_EXT_ATTRS; if (vol->v_flags & AFPVOL_ACLS) @@ -610,7 +610,7 @@ int afp_getsrvrparms(AFPObj *obj, char *ibuf _U_, size_t ibuflen _U_, char *rbuf continue; /* config file changed but the volume was mounted */ } - if (utf8_encoding()) { + if (utf8_encoding(obj)) { len = ucs2_to_charset_allocate(CH_UTF8_MAC, &namebuf, volume->v_u8mname); } else { len = ucs2_to_charset_allocate(obj->options.maccharset, &namebuf, volume->v_macname); @@ -761,7 +761,7 @@ int afp_openvol(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t if ((volname_tmp = strchr(volname,'+')) != NULL) volname = volname_tmp+1; - if (utf8_encoding()) { + if (utf8_encoding(obj)) { namelen = convert_string(CH_UTF8_MAC, CH_UCS2, ibuf, len, volname, sizeof(obj->oldtmp)); } else { namelen = convert_string(obj->options.maccharset, CH_UCS2, ibuf, len, volname, sizeof(obj->oldtmp)); @@ -854,7 +854,7 @@ int afp_openvol(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t /* initialize volume variables * FIXME file size */ - if (utf8_encoding()) { + if (utf8_encoding(obj)) { volume->max_filename = UTF8FILELEN_EARLY; } else { @@ -864,7 +864,7 @@ int afp_openvol(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t volume->v_flags |= AFPVOL_OPEN; volume->v_cdb = NULL; - if (utf8_encoding()) { + if (utf8_encoding(obj)) { len = convert_string_allocate(CH_UCS2, CH_UTF8_MAC, volume->v_u8mname, namelen, &vol_mname); } else { len = convert_string_allocate(CH_UCS2, obj->options.maccharset, volume->v_macname, namelen, &vol_mname); @@ -994,7 +994,7 @@ int pollvoltime(AFPObj *obj) struct timeval tv; struct stat st; - if (!(afp_version > 21 && obj->options.flags & OPTION_SERVERNOTIF)) + if (!(obj->afp_version > 21 && obj->options.flags & OPTION_SERVERNOTIF)) return 0; if ( gettimeofday( &tv, NULL ) < 0 ) @@ -1034,7 +1034,7 @@ void setvoltime(AFPObj *obj, struct vol *vol) /* or finder doesn't update free space * AFP 3.2 and above clients seem to be ok without so many notification */ - if (afp_version < 32 && obj->options.flags & OPTION_SERVERNOTIF) { + if (obj->afp_version < 32 && obj->options.flags & OPTION_SERVERNOTIF) { obj->attention(obj->dsi, AFPATTN_NOTIFY | AFPATTN_VOLCHANGED); } } diff --git a/etc/cnid_dbd/cmd_dbd.c b/etc/cnid_dbd/cmd_dbd.c index ad0e22b4..8eb9c576 100644 --- a/etc/cnid_dbd/cmd_dbd.c +++ b/etc/cnid_dbd/cmd_dbd.c @@ -28,18 +28,19 @@ #include #include -#include +#include +#include #include #include "cmd_dbd.h" #include "dbd.h" #include "dbif.h" #include "db_param.h" +#include "pack.h" #define DBOPTIONS (DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN) int nocniddb = 0; /* Dont open CNID database, only scan filesystem */ -struct volinfo volinfo; /* needed by pack.c:idxname() */ volatile sig_atomic_t alarmed; /* flags for signals */ int db_locked; /* have we got the fcntl lock on lockfile ? */ @@ -128,7 +129,7 @@ static void set_signal(void) static void usage (void) { printf("dbd (Netatalk %s)\n" - "Usage: dbd [-e|-t|-v|-x] -d [-i] | -s [-c|-n]| -r [-c|-f] | -u \n" + "Usage: dbd [-etvxF] -d [-i] | -s [-c|-n]| -r [-c|-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" @@ -162,6 +163,7 @@ static void usage (void) " Opens the database which triggers any necessary upgrades,\n" " then closes and exits.\n\n" "General options:\n" + " -F location of the afp.conf config file\n" " -e only work on inactive volumes and lock them (exclusive)\n" " -x rebuild indexes (just for completeness, mostly useless!)\n" " -t show statistics while running\n" @@ -180,6 +182,8 @@ int main(int argc, char **argv) dbd_flags_t flags = 0; char *volpath; int cdir; + AFPObj obj = { 0 }; + struct vol *vol; if (geteuid() != 0) { usage(); @@ -188,7 +192,7 @@ int main(int argc, char **argv) /* Inhereting perms in ad_mkdir etc requires this */ ad_setfuid(0); - while ((c = getopt(argc, argv, ":cdefinrstuvx")) != -1) { + while ((c = getopt(argc, argv, ":cdefFinrstuvx")) != -1) { switch(c) { case 'c': flags |= DBD_FLAGS_CLEANUP; @@ -230,6 +234,9 @@ int main(int argc, char **argv) exclusive = 1; flags |= DBD_FLAGS_FORCE | DBD_FLAGS_EXCL; break; + case 'F': + obj.cmdlineconfigfile = strdup(optarg); + break; case ':': case '?': usage(); @@ -266,19 +273,26 @@ int main(int argc, char **argv) else setuplog("default:debug", "/dev/tty"); - /* Load .volinfo file */ - if (loadvolinfo(volpath, &volinfo) == -1) { - dbd_log( LOGSTD, "Not a Netatalk volume at '%s', no .volinfo file at '%s/.AppleDesktop/.volinfo' or unknown volume options", volpath, volpath); + /* Load config */ + if (afp_config_parse(&obj) != 0) { + dbd_log( LOGSTD, "Couldn't load afp.conf"); + exit(EXIT_FAILURE); + } + + if (load_volumes(&obj, NULL) != 0) { + dbd_log( LOGSTD, "Couldn't load volumes"); exit(EXIT_FAILURE); } - if (vol_load_charsets(&volinfo) == -1) { - dbd_log( LOGSTD, "Error loading charsets!"); + + if ((vol = getvolbypath(volpath)) == NULL) { + dbd_log( LOGSTD, "Couldn't find volume for '%s'", volpath); exit(EXIT_FAILURE); } + pack_setvol(vol); - if (volinfo.v_adouble == AD_VERSION_EA) + if (vol->v_adouble == AD_VERSION_EA) dbd_log( LOGDEBUG, "adouble:ea volume"); - else if (volinfo.v_adouble == AD_VERSION2) + else if (vol->v_adouble == AD_VERSION2) dbd_log( LOGDEBUG, "adouble:v2 volume"); else { dbd_log( LOGSTD, "unknown adouble volume"); @@ -286,30 +300,30 @@ int main(int argc, char **argv) } /* 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); + if (vol->v_vfs_ea != AFPVOL_EA_AD && vol->v_vfs_ea != AFPVOL_EA_SYS) { + dbd_log( LOGSTD, "Unknown Extended Attributes option: %u", vol->v_vfs_ea); exit(EXIT_FAILURE); } /* Enuser dbpath is there, create if necessary */ struct stat st; - if (stat(volinfo.v_dbpath, &st) != 0) { + if (stat(vol->v_dbpath, &st) != 0) { if (errno != ENOENT) { - dbd_log( LOGSTD, "Can't stat dbpath \"%s\": %s", volinfo.v_dbpath, strerror(errno)); + dbd_log( LOGSTD, "Can't stat dbpath \"%s\": %s", vol->v_dbpath, strerror(errno)); exit(EXIT_FAILURE); } - if ((mkdir(volinfo.v_dbpath, 0755)) != 0) { - dbd_log( LOGSTD, "Can't create dbpath \"%s\": %s", dbpath, strerror(errno)); + if ((mkdir(vol->v_dbpath, 0755)) != 0) { + dbd_log( LOGSTD, "Can't create dbpath \"%s\": %s", vol->v_dbpath, strerror(errno)); exit(EXIT_FAILURE); } } /* Put "/.AppleDB" at end of volpath, get path from volinfo file */ - if ( (strlen(volinfo.v_dbpath) + strlen("/.AppleDB")) > MAXPATHLEN ) { + if ( (strlen(vol->v_dbpath) + strlen("/.AppleDB")) > MAXPATHLEN ) { dbd_log( LOGSTD, "Volume pathname too long"); exit(EXIT_FAILURE); } - strncpy(dbpath, volinfo.v_dbpath, MAXPATHLEN - strlen("/.AppleDB")); + strncpy(dbpath, vol->v_dbpath, MAXPATHLEN - strlen("/.AppleDB")); strcat(dbpath, "/.AppleDB"); /* Check or create dbpath */ @@ -402,7 +416,7 @@ int main(int argc, char **argv) dbd_log( LOGSTD, "Error dumping database"); } } else if ((rebuild && ! nocniddb) || scan) { - if (cmd_dbd_scanvol(dbd, &volinfo, flags) < 0) { + if (cmd_dbd_scanvol(dbd, vol, flags) < 0) { dbd_log( LOGSTD, "Error repairing database."); } } diff --git a/etc/cnid_dbd/cmd_dbd.h b/etc/cnid_dbd/cmd_dbd.h index ef782988..e94c8618 100644 --- a/etc/cnid_dbd/cmd_dbd.h +++ b/etc/cnid_dbd/cmd_dbd.h @@ -4,7 +4,7 @@ #include #include -#include +#include #include "dbif.h" enum logtype {LOGSTD, LOGDEBUG}; @@ -29,7 +29,7 @@ extern int db_locked; /* have we got the fcntl lock on lockfd ? */ extern volatile sig_atomic_t alarmed; extern void dbd_log(enum logtype lt, char *fmt, ...); -extern int cmd_dbd_scanvol(DBD *dbd, struct volinfo *volinfo, dbd_flags_t flags); +extern int cmd_dbd_scanvol(DBD *dbd, struct vol *vol, dbd_flags_t flags); /* Functions for querying the database which couldn't be reused from the existing diff --git a/etc/cnid_dbd/cmd_dbd_scanvol.c b/etc/cnid_dbd/cmd_dbd_scanvol.c index 90293a48..90421a93 100644 --- a/etc/cnid_dbd/cmd_dbd_scanvol.c +++ b/etc/cnid_dbd/cmd_dbd_scanvol.c @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include #include @@ -46,7 +46,7 @@ #define ADFILE_OK (adfile_ok == 0) -static struct volinfo *myvolinfo; +static struct vol *myvol; static char cwdbuf[MAXPATHLEN+1]; static DBD *dbd; static DBD *dbd_rebuild; @@ -64,7 +64,6 @@ static char *special_dirs[] = { static struct cnid_dbd_rqst rqst; static struct cnid_dbd_rply rply; static jmp_buf jmp; -static struct vol volume; /* fake it for ea_open */ static char pname[MAXPATHLEN] = "../"; /* @@ -84,22 +83,22 @@ static char *utompath(char *upath) u = upath; outlen = strlen(upath); - if ((myvolinfo->v_casefold & AFPVOL_UTOMUPPER)) + if ((myvol->v_casefold & AFPVOL_UTOMUPPER)) flags |= CONV_TOUPPER; - else if ((myvolinfo->v_casefold & AFPVOL_UTOMLOWER)) + else if ((myvol->v_casefold & AFPVOL_UTOMLOWER)) flags |= CONV_TOLOWER; - if ((myvolinfo->v_flags & AFPVOL_EILSEQ)) { + if ((myvol->v_flags & AFPVOL_EILSEQ)) { flags |= CONV__EILSEQ; } /* convert charsets */ - if ((size_t)-1 == ( outlen = convert_charset(myvolinfo->v_volcharset, + if ((size_t)-1 == ( outlen = convert_charset(myvol->v_volcharset, CH_UTF8_MAC, - myvolinfo->v_maccharset, + myvol->v_maccharset, u, outlen, mpath, MAXPATHLEN, &flags)) ) { dbd_log( LOGSTD, "Conversion from %s to %s for %s failed.", - myvolinfo->v_volcodepage, myvolinfo->v_maccodepage, u); + myvol->v_volcodepage, myvol->v_maccodepage, u); return NULL; } @@ -125,17 +124,17 @@ static char *mtoupath(char *mpath) } /* set conversion flags */ - if (!(myvolinfo->v_flags & AFPVOL_NOHEX)) + if (!(myvol->v_flags & AFPVOL_NOHEX)) flags |= CONV_ESCAPEHEX; - if (!(myvolinfo->v_flags & AFPVOL_USEDOTS)) + if (!(myvol->v_flags & AFPVOL_USEDOTS)) flags |= CONV_ESCAPEDOTS; - if ((myvolinfo->v_casefold & AFPVOL_MTOUUPPER)) + if ((myvol->v_casefold & AFPVOL_MTOUUPPER)) flags |= CONV_TOUPPER; - else if ((myvolinfo->v_casefold & AFPVOL_MTOULOWER)) + else if ((myvol->v_casefold & AFPVOL_MTOULOWER)) flags |= CONV_TOLOWER; - if ((myvolinfo->v_flags & AFPVOL_EILSEQ)) { + if ((myvol->v_flags & AFPVOL_EILSEQ)) { flags |= CONV__EILSEQ; } @@ -146,11 +145,11 @@ static char *mtoupath(char *mpath) outlen = MAXPATHLEN; if ((size_t)-1 == (outlen = convert_charset(CH_UTF8_MAC, - myvolinfo->v_volcharset, - myvolinfo->v_maccharset, + myvol->v_volcharset, + myvol->v_maccharset, m, inplen, u, outlen, &flags)) ) { dbd_log( LOGSTD, "conversion from UTF8-MAC to %s for %s failed.", - myvolinfo->v_volcodepage, mpath); + myvol->v_volcodepage, mpath); return NULL; } @@ -219,7 +218,7 @@ static int check_adfile(const char *fname, const struct stat *st) struct adouble ad; const char *adname; - if (volume.v_adouble == AD_VERSION_EA) + if (myvol->v_adouble == AD_VERSION_EA) return 0; if (dbd_flags & DBD_FLAGS_CLEANUP) @@ -228,7 +227,7 @@ static int check_adfile(const char *fname, const struct stat *st) if (S_ISREG(st->st_mode)) adflags |= ADFLAGS_DIR; - adname = volume.ad_path(fname, adflags); + adname = myvol->ad_path(fname, adflags); if ((ret = access( adname, F_OK)) != 0) { if (errno != ENOENT) { @@ -244,7 +243,7 @@ static int check_adfile(const char *fname, const struct stat *st) return -1; /* Create ad file */ - ad_init(&ad, &volume); + ad_init(&ad, myvol); if ((ret = ad_open(&ad, fname, adflags | ADFLAGS_CREATE | ADFLAGS_RDWR, 0666)) != 0) { dbd_log( LOGSTD, "Error creating AppleDouble file '%s/%s': %s", @@ -264,7 +263,7 @@ static int check_adfile(const char *fname, const struct stat *st) chmod(adname, st->st_mode); #endif } else { - ad_init(&ad, &volume); + ad_init(&ad, myvol); if (ad_open(&ad, fname, adflags | ADFLAGS_RDONLY) != 0) { dbd_log( LOGSTD, "Error opening AppleDouble file for '%s/%s'", cwdbuf, fname); return -1; @@ -333,7 +332,7 @@ static int check_eafiles(const char *fname) struct stat st; char *eaname; - if ((ret = ea_open(&volume, fname, EA_RDWR, &ea)) != 0) { + if ((ret = ea_open(myvol, fname, EA_RDWR, &ea)) != 0) { if (errno == ENOENT) return 0; dbd_log(LOGSTD, "Error calling ea_open for file: %s/%s, removing EA files", cwdbuf, fname); @@ -389,7 +388,7 @@ static int check_addir(int volroot) if (dbd_flags & DBD_FLAGS_CLEANUP) return 0; - if (volume.v_adouble == AD_VERSION_EA) + if (myvol->v_adouble == AD_VERSION_EA) return 0; /* Check for ad-dir */ @@ -402,10 +401,10 @@ static int check_addir(int volroot) } /* Check for ".Parent" */ - if ( (adpar_ok = access(volume.ad_path(".", ADFLAGS_DIR), F_OK)) != 0) { + if ( (adpar_ok = access(myvol->ad_path(".", ADFLAGS_DIR), F_OK)) != 0) { if (errno != ENOENT) { dbd_log(LOGSTD, "Access error on '%s/%s': %s", - cwdbuf, volume.ad_path(".", ADFLAGS_DIR), strerror(errno)); + cwdbuf, myvol->ad_path(".", ADFLAGS_DIR), strerror(errno)); return -1; } dbd_log(LOGSTD, "Missing .AppleDouble/.Parent for '%s'", cwdbuf); @@ -424,7 +423,7 @@ static int check_addir(int volroot) } /* Create ad dir and set name */ - ad_init(&ad, &volume); + ad_init(&ad, myvol); if (ad_open(&ad, ".", ADFLAGS_HF | ADFLAGS_DIR | ADFLAGS_CREATE | ADFLAGS_RDWR, 0777) != 0) { dbd_log( LOGSTD, "Error creating AppleDouble dir in %s: %s", cwdbuf, strerror(errno)); @@ -445,7 +444,7 @@ static int check_addir(int volroot) return -1; } chown(ADv2_DIRNAME, st.st_uid, st.st_gid); - chown(volume.ad_path(".", ADFLAGS_DIR), st.st_uid, st.st_gid); + chown(myvol->ad_path(".", ADFLAGS_DIR), st.st_uid, st.st_gid); } return 0; @@ -464,7 +463,7 @@ static int check_eafile_in_adouble(const char *name) char *namep, *namedup = NULL; /* Check if this is an AFPVOL_EA_AD vol */ - if (myvolinfo->v_vfs_ea == AFPVOL_EA_AD) { + if (myvol->v_vfs_ea == AFPVOL_EA_AD) { /* Does the filename contain "::EA" ? */ namedup = strdup(name); if ((namep = strstr(namedup, "::EA")) == NULL) { @@ -522,7 +521,7 @@ static int read_addir(void) struct dirent *ep; struct stat st; - if (volume.v_adouble == AD_VERSION_EA) + if (myvol->v_adouble == AD_VERSION_EA) return 0; if ((chdir(ADv2_DIRNAME)) != 0) { @@ -627,13 +626,13 @@ static cnid_t check_cnid(const char *name, cnid_t did, struct stat *st, int adfi /* Get CNID from ad-file */ ad_cnid = 0; if (ADFILE_OK) { - ad_init(&ad, &volume); + ad_init(&ad, myvol); if (ad_open(&ad, name, adflags | ADFLAGS_RDWR) != 0) { if (dbd_flags & DBD_FLAGS_CLEANUP) return CNID_INVALID; - if (volume.v_adouble != AD_VERSION_EA) { + if (myvol->v_adouble != AD_VERSION_EA) { dbd_log( LOGSTD, "Error opening AppleDouble file for '%s/%s': %s", cwdbuf, name, strerror(errno)); return CNID_INVALID; } @@ -664,7 +663,7 @@ static cnid_t check_cnid(const char *name, cnid_t did, struct stat *st, int adfi memset(&rply, 0, sizeof(struct cnid_dbd_rply)); rqst.did = did; rqst.cnid = ad_cnid; - if ( ! (myvolinfo->v_flags & AFPVOL_NODEV)) + if ( ! (myvol->v_flags & AFPVOL_NODEV)) rqst.dev = st->st_dev; rqst.ino = st->st_ino; rqst.type = S_ISDIR(st->st_mode)?1:0; @@ -696,7 +695,7 @@ static cnid_t check_cnid(const char *name, cnid_t did, struct stat *st, int adfi if ( ! (dbd_flags & DBD_FLAGS_SCAN)) { dbd_log(LOGSTD, "Updating AppleDouble file for '%s/%s' with CNID: %u from database", cwdbuf, name, ntohl(db_cnid)); - ad_init(&ad, &volume); + ad_init(&ad, myvol); if (ad_open(&ad, name, adflags | ADFLAGS_HF | ADFLAGS_RDWR) != 0) { dbd_log(LOGSTD, "Error opening AppleDouble file for '%s/%s': %s", cwdbuf, name, strerror(errno)); @@ -727,7 +726,7 @@ static cnid_t check_cnid(const char *name, cnid_t did, struct stat *st, int adfi if (ADFILE_OK && ( ! (dbd_flags & DBD_FLAGS_SCAN))) { dbd_log(LOGSTD, "Writing CNID data for '%s/%s' to AppleDouble file", cwdbuf, name, ntohl(db_cnid)); - ad_init(&ad, &volume); + ad_init(&ad, myvol); if (ad_open(&ad, name, adflags | ADFLAGS_RDWR) != 0) { dbd_log(LOGSTD, "Error opening AppleDouble file for '%s/%s': %s", cwdbuf, name, strerror(errno)); @@ -766,7 +765,7 @@ static cnid_t check_cnid(const char *name, cnid_t did, struct stat *st, int adfi if (ADFILE_OK && ! (dbd_flags & DBD_FLAGS_SCAN)) { dbd_log(LOGSTD, "Writing CNID data for '%s/%s' to AppleDouble file", cwdbuf, name, ntohl(db_cnid)); - ad_init(&ad, &volume); + ad_init(&ad, myvol); if (ad_open(&ad, name, adflags | ADFLAGS_RDWR) != 0) { dbd_log(LOGSTD, "Error opening AppleDouble file for '%s/%s': %s", cwdbuf, name, strerror(errno)); @@ -804,7 +803,7 @@ static int dbd_readdir(int volroot, cnid_t did) return -1; /* Check AppleDouble files in AppleDouble folder, but only if it exists or could be created */ - if (volume.v_adouble == AD_VERSION2 && ADDIR_OK) + if (myvol->v_adouble == AD_VERSION2 && ADDIR_OK) if ((read_addir()) != 0) if ( ! (dbd_flags & DBD_FLAGS_SCAN)) /* Fatal on rebuild run, continue if only scanning ! */ @@ -926,7 +925,7 @@ static int dbd_readdir(int volroot, cnid_t did) } /* Check EA files */ - if (myvolinfo->v_vfs_ea == AFPVOL_EA_AD) + if (myvol->v_vfs_ea == AFPVOL_EA_AD) check_eafiles(ep->d_name); /************************************************************************** @@ -964,27 +963,17 @@ static int dbd_readdir(int volroot, cnid_t did) return ret; } -static int scanvol(struct volinfo *vi, dbd_flags_t flags) +static int scanvol(struct vol *vol, dbd_flags_t flags) { /* Make this stuff accessible from all funcs easily */ - myvolinfo = vi; + myvol = vol; dbd_flags = flags; - /* Init a fake struct vol so that we can call ad_init(.., &volume) and initvol_vfs(&volume) */ - volume.v_adouble = vi->v_adouble; - volume.v_ad_options = vi->v_flags; - volume.ad_path = vi->ad_path; - volume.v_vfs_ea = myvolinfo->v_vfs_ea; - initvol_vfs(&volume); - /* Run with umask 0 */ umask(0); - /* Remove trailing slash from volume, chdir to vol */ - if (myvolinfo->v_path[strlen(myvolinfo->v_path) - 1] == '/') - myvolinfo->v_path[strlen(myvolinfo->v_path) - 1] = 0; - strcpy(cwdbuf, myvolinfo->v_path); - chdir(myvolinfo->v_path); + strcpy(cwdbuf, myvol->v_path); + chdir(myvol->v_path); /* Start recursion */ if (dbd_readdir(1, htonl(2)) < 0) /* 2 = volumeroot CNID */ @@ -1107,7 +1096,7 @@ static const char *get_tmpdb_path(void) /* Main func called from cmd_dbd.c */ -int cmd_dbd_scanvol(DBD *dbd_ref, struct volinfo *vi, dbd_flags_t flags) +int cmd_dbd_scanvol(DBD *dbd_ref, struct vol *vol, dbd_flags_t flags) { int ret = 0; struct db_param db_param = { 0 }; @@ -1123,8 +1112,8 @@ int cmd_dbd_scanvol(DBD *dbd_ref, struct volinfo *vi, dbd_flags_t flags) dbd = dbd_ref; /* We only support unicode volumes ! */ - if ( vi->v_volcharset != CH_UTF8) { - dbd_log( LOGSTD, "Not a Unicode volume: %s, %u != %u", vi->v_volcodepage, vi->v_volcharset, CH_UTF8); + if (vol->v_volcharset != CH_UTF8) { + dbd_log( LOGSTD, "Not a Unicode volume: %s, %u != %u", vol->v_volcodepage, vol->v_volcharset, CH_UTF8); return -1; } @@ -1168,7 +1157,7 @@ int cmd_dbd_scanvol(DBD *dbd_ref, struct volinfo *vi, dbd_flags_t flags) } /* scanvol */ - if ( (scanvol(vi, flags)) != 0) { + if ((scanvol(vol, flags)) != 0) { ret = -1; goto exit; } diff --git a/etc/cnid_dbd/cnid_metad.c b/etc/cnid_dbd/cnid_metad.c index 580c36cd..aa214be6 100644 --- a/etc/cnid_dbd/cnid_metad.c +++ b/etc/cnid_dbd/cnid_metad.c @@ -89,8 +89,11 @@ #include #include #include -#include #include +#include +#include +#include +#include #include "usockfd.h" @@ -110,7 +113,7 @@ static uint maxvol; #define DEFAULTPORT "4700" struct server { - struct volinfo *volinfo; + struct vol *vol; pid_t pid; time_t tm; /* When respawned last */ int count; /* Times respawned in the last TESTTIME secondes */ @@ -119,9 +122,6 @@ struct server { static struct server srv[MAXVOLS]; -/* Default logging config: log to syslog with level log_note */ -static char logconfig[MAXPATHLEN + 21 + 1] = "default log_note"; - static void daemon_exit(int i) { server_unlock(_PATH_CNID_METAD_LOCK); @@ -141,19 +141,23 @@ static void sigterm_handler(int sig) daemon_exit(0); } -static struct server *test_usockfn(struct volinfo *volinfo) +static struct server *test_usockfn(const struct vol *vol) { int i; + + if (!(vol->v_flags & AFPVOL_OPEN)) + return NULL; + for (i = 0; i < maxvol; i++) { - if ((srv[i].volinfo) && (strcmp(srv[i].volinfo->v_path, volinfo->v_path) == 0)) { + if (vol->v_vid == srv[i].vol->v_vid) return &srv[i]; - } } + return NULL; } /* -------------------- */ -static int maybe_start_dbd(char *dbdpn, struct volinfo *volinfo) +static int maybe_start_dbd(const AFPObj *obj, char *dbdpn, struct vol *vol) { pid_t pid; struct server *up; @@ -162,11 +166,11 @@ static int maybe_start_dbd(char *dbdpn, struct volinfo *volinfo) time_t t; char buf1[8]; char buf2[8]; - char *volpath = volinfo->v_path; + char *volpath = vol->v_path; LOG(log_debug, logtype_cnid, "maybe_start_dbd: Volume: \"%s\"", volpath); - up = test_usockfn(volinfo); + up = test_usockfn(vol); if (up && up->pid) { /* we already have a process, send our fd */ if (send_fd(up->control_fd, rqstfd) < 0) { @@ -182,10 +186,10 @@ static int maybe_start_dbd(char *dbdpn, struct volinfo *volinfo) if (!up) { /* find an empty slot (i < maxvol) or the first free slot (i == maxvol)*/ for (i = 0; i <= maxvol; i++) { - if (srv[i].volinfo == NULL && i < MAXVOLS) { + if (srv[i].vol == NULL && i < MAXVOLS) { up = &srv[i]; - up->volinfo = volinfo; - retainvolinfo(volinfo); + up->vol = vol; + vol->v_flags |= AFPVOL_OPEN; up->tm = t; up->count = 0; if (i == maxvol) @@ -257,10 +261,10 @@ static int maybe_start_dbd(char *dbdpn, struct volinfo *volinfo) /* there's a pb with the db inform child, it will delete the db */ LOG(log_warning, logtype_cnid, "Multiple attempts to start CNID db daemon for \"%s\" failed, wiping the slate clean...", - up->volinfo->v_path); - ret = execlp(dbdpn, dbdpn, "-d", volpath, buf1, buf2, logconfig, NULL); + up->vol->v_path); + ret = execlp(dbdpn, dbdpn, "-F", obj->options.configfile, "-p", volpath, "-t", buf1, "-l", buf2, "-d", NULL); } else { - ret = execlp(dbdpn, dbdpn, volpath, buf1, buf2, logconfig, NULL); + ret = execlp(dbdpn, dbdpn, "-F", obj->options.configfile, "-p", volpath, "-t", buf1, "-l", buf2, NULL); } /* Yikes! We're still here, so exec failed... */ LOG(log_error, logtype_cnid, "Fatal error in exec: %s", strerror(errno)); @@ -445,45 +449,23 @@ int main(int argc, char *argv[]) int debug = 0; int ret; sigset_t set; - struct volinfo *volinfo; - - set_processname("cnid_metad"); + AFPObj obj = { 0 }; + struct vol *vol; - while (( cc = getopt( argc, argv, "vVds:p:h:u:g:l:f:")) != -1 ) { + while (( cc = getopt( argc, argv, "dF:v")) != -1 ) { switch (cc) { - case 'v': - case 'V': - printf("cnid_metad (Netatalk %s)\n", VERSION); - return -1; case 'd': debug = 1; break; - case 'h': - host = strdup(optarg); - break; - case 'u': - uid = user_to_uid (optarg); - if (!uid) { - LOG(log_error, logtype_cnid, "main: bad user %s", optarg); - err++; - } - break; - case 'g': - gid =group_to_gid (optarg); - if (!gid) { - LOG(log_error, logtype_cnid, "main: bad group %s", optarg); - err++; - } - break; - case 'p': - port = strdup(optarg); - break; - case 's': - dbdpn = strdup(optarg); + case 'F': + obj.cmdlineconfigfile = strdup(optarg); break; + case 'v': + printf("cnid_metad (Netatalk %s)\n", VERSION); + return -1; default: - err++; - break; + printf("cnid_metad [-dv] [-F alternate configfile ]\n"); + return -1; } } @@ -498,12 +480,14 @@ int main(int argc, char *argv[]) if (create_lockfile("cnid_metad", _PATH_CNID_METAD_LOCK)) return -1; - setuplog("default:note", NULL); + if (afp_config_parse(&obj) != 0) + daemon_exit(1); + + set_processname("cnid_metad"); + setuplog(obj.options.logconfig, obj.options.logfile); - if (err) { - LOG(log_error, logtype_cnid, "main: bad arguments"); + if (load_volumes(&obj, NULL) != 0) daemon_exit(1); - } (void)setlimits(); @@ -541,15 +525,16 @@ int main(int argc, char *argv[]) if (srv[i].pid == pid) { srv[i].pid = 0; close(srv[i].control_fd); + srv[i].vol->v_flags &= ~AFPVOL_OPEN; break; } } if (WIFEXITED(status)) { - LOG(log_info, logtype_cnid, "cnid_dbd pid %i exited with exit code %i", + LOG(log_info, logtype_cnid, "cnid_dbd[%i] exited with exit code %i", pid, WEXITSTATUS(status)); } else if (WIFSIGNALED(status)) { - LOG(log_info, logtype_cnid, "cnid_dbd pid %i exited with signal %i", + LOG(log_info, logtype_cnid, "cnid_dbd[%i] got signal %i", pid, WTERMSIG(status)); } sigchild = 0; @@ -591,21 +576,17 @@ int main(int argc, char *argv[]) } volpath[len] = '\0'; - /* Load .volinfo file */ - if ((volinfo = allocvolinfo(volpath)) == NULL) { - LOG(log_severe, logtype_cnid, "allocvolinfo(\"%s\"): %s", - volpath, strerror(errno)); + + if ((vol = getvolbypath(volpath)) == NULL) { + LOG(log_severe, logtype_cnid, "getvolbypath(\"%s\"): %s", volpath, strerror(errno)); goto loop_end; } - if (set_dbdir(volinfo->v_dbpath) < 0) { + if (set_dbdir(vol->v_dbpath) < 0) { goto loop_end; } - maybe_start_dbd(dbdpn, volinfo); - - (void)closevolinfo(volinfo); - + maybe_start_dbd(&obj, dbdpn, vol); loop_end: close(rqstfd); } diff --git a/etc/cnid_dbd/main.c b/etc/cnid_dbd/main.c index 000abbf0..b8906f90 100644 --- a/etc/cnid_dbd/main.c +++ b/etc/cnid_dbd/main.c @@ -24,12 +24,15 @@ #include #include -#include +#include +#include +#include #include "db_param.h" #include "dbif.h" #include "dbd.h" #include "comm.h" +#include "pack.h" /* Note: DB_INIT_LOCK is here so we can run the db_* utilities while netatalk is running. @@ -37,9 +40,6 @@ */ #define DBOPTIONS (DB_CREATE | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN) -/* Global, needed by pack.c:idxname() */ -struct volinfo volinfo; - static DBD *dbd; static int exit_sig = 0; static int db_locked; @@ -273,77 +273,81 @@ static void set_signal(void) /* ------------------------ */ int main(int argc, char *argv[]) { + EC_INIT; struct db_param *dbp; - int err = 0, ret, delete_bdb = 0; - int ctrlfd, clntfd; + int delete_bdb = 0; + int ctrlfd = -1, clntfd = -1; char *logconfig; + AFPObj obj = { 0 }; + struct vol *vol; + char *volpath = NULL; + bstring dbpath; - set_processname("cnid_dbd"); - - while (( ret = getopt( argc, argv, "vVd")) != -1 ) { + while (( ret = getopt( argc, argv, "dF:l:p:t:v")) != -1 ) { switch (ret) { - case 'v': - case 'V': - printf("cnid_dbd (Netatalk %s)\n", VERSION); - return -1; case 'd': delete_bdb = 1; break; + case 'F': + obj.cmdlineconfigfile = strdup(optarg); + break; + case 'p': + volpath = strdup(optarg); + break; + case 'l': + clntfd = atoi(optarg); + break; + case 't': + ctrlfd = atoi(optarg); + break; + case 'v': + printf("cnid_dbd (Netatalk %s)\n", VERSION); + return -1; } } - if (argc - optind != 4) { - LOG(log_error, logtype_cnid, "main: not enough arguments"); + if (ctrlfd == -1 || clntfd == -1 || !volpath) { + LOG(log_error, logtype_cnid, "main: bad IPC fds"); exit(EXIT_FAILURE); } - /* Load .volinfo file */ - if (loadvolinfo(argv[optind], &volinfo) == -1) { - LOG(log_error, logtype_cnid, "Cant load volinfo for \"%s\"", argv[1]); - exit(EXIT_FAILURE); - } - /* Put "/.AppleDB" at end of volpath, get path from volinfo file */ - char dbpath[MAXPATHLEN+1]; - if ((strlen(volinfo.v_dbpath) + strlen("/.AppleDB")) > MAXPATHLEN ) { - LOG(log_error, logtype_cnid, "CNID db pathname too long: \"%s\"", volinfo.v_dbpath); - exit(EXIT_FAILURE); - } - strncpy(dbpath, volinfo.v_dbpath, MAXPATHLEN - strlen("/.AppleDB")); - strcat(dbpath, "/.AppleDB"); + EC_ZERO( afp_config_parse(&obj) ); - ctrlfd = atoi(argv[optind + 1]); - clntfd = atoi(argv[optind + 2]); + set_processname("cnid_dbd"); + setuplog(obj.options.logconfig, obj.options.logfile); - setuplog("default:note", NULL); + EC_ZERO( load_volumes(&obj, NULL) ); + EC_NULL( vol = getvolbypath(volpath) ); - if (vol_load_charsets(&volinfo) == -1) { - LOG(log_error, logtype_cnid, "Error loading charsets!"); - exit(EXIT_FAILURE); - } - LOG(log_debug, logtype_cnid, "db dir: \"%s\"", dbpath); + pack_setvol(vol); + + EC_NULL( dbpath = bfromcstr(vol->v_dbpath) ); + EC_ZERO( bcatcstr(dbpath, "/.AppleDB") ); - switch_to_user(dbpath); + LOG(log_debug, logtype_cnid, "db dir: \"%s\"", bdata(dbpath)); + + switch_to_user(bdata(dbpath)); /* Get db lock */ - if ((db_locked = get_lock(LOCK_EXCL, dbpath)) == -1) { + if ((db_locked = get_lock(LOCK_EXCL, bdata(dbpath))) == -1) { LOG(log_error, logtype_cnid, "main: fatal db lock error"); - exit(1); + EC_FAIL; } if (db_locked != LOCK_EXCL) { /* Couldn't get exclusive lock, try shared lock */ if ((db_locked = get_lock(LOCK_SHRD, NULL)) != LOCK_SHRD) { LOG(log_error, logtype_cnid, "main: fatal db lock error"); - exit(1); + EC_FAIL; } } if (delete_bdb && (db_locked == LOCK_EXCL)) { LOG(log_warning, logtype_cnid, "main: too many CNID db opening attempts, wiping the slate clean"); - chdir(dbpath); + chdir(bdata(dbpath)); system("rm -f cnid2.db lock log.* __db.*"); - if ((db_locked = get_lock(LOCK_EXCL, dbpath)) != LOCK_EXCL) { + if ((db_locked = get_lock(LOCK_EXCL, bdata(dbpath))) != LOCK_EXCL) { LOG(log_error, logtype_cnid, "main: fatal db lock error"); - exit(EXIT_FAILURE); + EC_FAIL; } } @@ -352,59 +356,66 @@ int main(int argc, char *argv[]) /* SIGINT and SIGTERM are always off, unless we are in pselect */ block_sigs_onoff(1); - if ((dbp = db_param_read(dbpath)) == NULL) - exit(1); + if ((dbp = db_param_read(bdata(dbpath))) == NULL) + EC_FAIL; LOG(log_maxdebug, logtype_cnid, "Finished parsing db_param config file"); - if (NULL == (dbd = dbif_init(dbpath, "cnid2.db"))) - exit(2); + if (NULL == (dbd = dbif_init(bdata(dbpath), "cnid2.db"))) + EC_FAIL; /* Only recover if we got the lock */ if (dbif_env_open(dbd, dbp, (db_locked == LOCK_EXCL) ? DBOPTIONS | DB_RECOVER : DBOPTIONS) < 0) - exit(2); /* FIXME: same exit code as failure for dbif_open() */ + EC_FAIL; LOG(log_debug, logtype_cnid, "Finished initializing BerkeleyDB environment"); if (dbif_open(dbd, dbp, 0) < 0) { - dbif_close(dbd); - exit(2); + ret = -1; + goto close_db; } + LOG(log_debug, logtype_cnid, "Finished opening BerkeleyDB databases"); /* Downgrade db lock */ if (db_locked == LOCK_EXCL) { if (get_lock(LOCK_UNLOCK, NULL) != 0) { - dbif_close(dbd); - exit(2); + ret = -1; + goto close_db; } + if (get_lock(LOCK_SHRD, NULL) != LOCK_SHRD) { - dbif_close(dbd); - exit(2); + ret = -1; + goto close_db; } } if (comm_init(dbp, ctrlfd, clntfd) < 0) { - dbif_close(dbd); - exit(3); + ret = -1; + goto close_db; } - if (loop(dbp) < 0) - err++; + if (loop(dbp) < 0) { + ret = -1; + goto close_db; + } +close_db: if (dbif_close(dbd) < 0) - err++; + ret = -1; + + if (dbif_env_remove(bdata(dbpath)) < 0) + ret = -1; - if (dbif_env_remove(dbpath) < 0) - err++; +EC_CLEANUP: + if (ret != 0) + exit(1); - if (err) - exit(4); - else if (exit_sig) + if (exit_sig) LOG(log_info, logtype_cnid, "main: Exiting on signal %i", exit_sig); else LOG(log_info, logtype_cnid, "main: Idle timeout, exiting"); - return 0; + EC_EXIT; } diff --git a/etc/cnid_dbd/pack.c b/etc/cnid_dbd/pack.c index 69f5fa62..2e9a32ee 100644 --- a/etc/cnid_dbd/pack.c +++ b/etc/cnid_dbd/pack.c @@ -16,13 +16,12 @@ #include #include -#include #include #include +#include #include "pack.h" -/* in main.c for `cnid_dbd` or cmd_dbd.c for `dbd` */ -extern struct volinfo volinfo; +static const struct vol *volume; /* --------------- */ /* @@ -81,9 +80,9 @@ int idxname(DB *dbp _U_, const DBT *pkey _U_, const DBT *pdata, DBT *skey) uint16_t flags = CONV_TOLOWER; memset(skey, 0, sizeof(DBT)); - if (convert_charset(volinfo.v_volcharset, - volinfo.v_volcharset, - volinfo.v_maccharset, + if (convert_charset(volume->v_volcharset, + volume->v_volcharset, + volume->v_maccharset, (char *)pdata->data + CNID_NAME_OFS, strlen((char *)pdata->data + CNID_NAME_OFS), buffer, @@ -97,6 +96,11 @@ int idxname(DB *dbp _U_, const DBT *pkey _U_, const DBT *pdata, DBT *skey) return (0); } +void pack_setvol(const struct vol *vol) +{ + volume = vol; +} + /* The equivalent to make_cnid_data in the cnid library. Non re-entrant. We differ from make_cnid_data in that we never return NULL, rqst->name cannot ever cause start[] to overflow because name length is checked in libatalk. */ diff --git a/etc/cnid_dbd/pack.h b/etc/cnid_dbd/pack.h index e94ef0d9..9894d49a 100644 --- a/etc/cnid_dbd/pack.h +++ b/etc/cnid_dbd/pack.h @@ -10,18 +10,9 @@ #include #include -#define ntoh64(x) (((uint64_t)(x) << 56) | \ - (((uint64_t)(x) << 40) & 0xff000000000000ULL) | \ - (((uint64_t)(x) << 24) & 0xff0000000000ULL) | \ - (((uint64_t)(x) << 8) & 0xff00000000ULL) | \ - (((uint64_t)(x) >> 8) & 0xff000000ULL) | \ - (((uint64_t)(x) >> 24) & 0xff0000ULL) | \ - (((uint64_t)(x) >> 40) & 0xff00ULL) | \ - ((uint64_t)(x) >> 56)) - extern unsigned char *pack_cnid_data(struct cnid_dbd_rqst *); extern int didname(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey); extern int devino(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey); extern int idxname(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey); - +extern void pack_setvol(const struct vol *vol); #endif /* CNID_DBD_PACK_H */ diff --git a/include/atalk/directory.h b/include/atalk/directory.h index e474faf5..a2759aa1 100644 --- a/include/atalk/directory.h +++ b/include/atalk/directory.h @@ -32,6 +32,7 @@ #include #include #include +#include /* setgid directories */ #ifndef DIRBITS diff --git a/include/atalk/globals.h b/include/atalk/globals.h index ad90c1c2..69a60aaa 100644 --- a/include/atalk/globals.h +++ b/include/atalk/globals.h @@ -121,10 +121,9 @@ typedef struct AFPObj { struct session_info sinfo; uid_t uid; /* client running user id */ int ipc_fd; /* anonymous PF_UNIX socket for IPC with afpd parent */ - gid_t *groups; int ngroups; - + int afp_version; /* Functions */ void (*logout)(void); void (*exit)(int); diff --git a/include/atalk/netatalk_conf.h b/include/atalk/netatalk_conf.h index 5b6ab571..3384f3d5 100644 --- a/include/atalk/netatalk_conf.h +++ b/include/atalk/netatalk_conf.h @@ -26,6 +26,7 @@ extern int load_volumes(AFPObj *obj, void (*delvol_fn)(const struct vol * extern void unload_volumes(void); extern struct vol *getvolumes(void); extern struct vol *getvolbyvid(const uint16_t); +extern struct vol *getvolbypath(const char *path); extern void volume_free(struct vol *vol); extern void volume_unlink(struct vol *volume); #endif diff --git a/include/atalk/volume.h b/include/atalk/volume.h index c179e74b..e495fe54 100644 --- a/include/atalk/volume.h +++ b/include/atalk/volume.h @@ -13,6 +13,7 @@ #include #include #include +#include #define AFPVOL_U8MNAMELEN 255 /* AFP3 sepc */ #define AFPVOL_MACNAMELEN 27 /* AFP2 spec */ @@ -21,6 +22,7 @@ typedef uint64_t VolSpace; struct vol { struct vol *v_next; + AFPObj *v_obj; uint16_t v_vid; int v_flags; char *v_path; @@ -179,10 +181,10 @@ struct vol { #define VOLPBIT_XBTOTAL 10 #define VOLPBIT_BSIZE 11 /* block size */ -#define utf8_encoding() (afp_version >= 30) +#define utf8_encoding(obj) ((obj)->afp_version >= 30) #define vol_nodev(vol) (((vol)->v_flags & AFPVOL_NODEV) ? 1 : 0) -#define vol_unix_priv(vol) (afp_version >= 30 && ((vol)->v_flags & AFPVOL_UNIX_PRIV)) +#define vol_unix_priv(vol) ((vol)->v_obj->afp_version >= 30 && ((vol)->v_flags & AFPVOL_UNIX_PRIV)) #define vol_inv_dots(vol) (((vol)->v_flags & AFPVOL_INV_DOTS) ? 1 : 0) diff --git a/libatalk/util/cnid.c b/libatalk/util/cnid.c index 37530907..0cc56d49 100644 --- a/libatalk/util/cnid.c +++ b/libatalk/util/cnid.c @@ -48,7 +48,6 @@ #include #include -#include #include #include #include diff --git a/libatalk/util/netatalk_conf.c b/libatalk/util/netatalk_conf.c index 9baf18f2..ba5e70aa 100644 --- a/libatalk/util/netatalk_conf.c +++ b/libatalk/util/netatalk_conf.c @@ -42,6 +42,7 @@ #include #include #include +#include #define VOLOPT_ALLOW 0 /* user allow list */ #define VOLOPT_DENY 1 /* user deny list */ @@ -717,9 +718,9 @@ static int creatvol(const AFPObj *obj, const struct passwd *pwd, /* check duplicate */ for ( volume = Volumes; volume; volume = volume->v_next ) { - if ((utf8_encoding() && (strcasecmp_w(volume->v_u8mname, u8mtmpname) == 0)) + if ((utf8_encoding(obj) && (strcasecmp_w(volume->v_u8mname, u8mtmpname) == 0)) || - (!utf8_encoding() && (strcasecmp_w(volume->v_macname, mactmpname) == 0))) { + (!utf8_encoding(obj) && (strcasecmp_w(volume->v_macname, mactmpname) == 0))) { LOG (log_error, logtype_afpd, "Duplicate volume name, check AppleVolumes files: previous: \"%s\", new: \"%s\"", volume->v_localname, name); @@ -761,7 +762,7 @@ static int creatvol(const AFPObj *obj, const struct passwd *pwd, return -1; } - volume->v_name = utf8_encoding()?volume->v_u8mname:volume->v_macname; + volume->v_name = utf8_encoding(obj)?volume->v_u8mname:volume->v_macname; volume->v_hide = hide; strcpy( volume->v_path, path ); @@ -899,6 +900,7 @@ static int creatvol(const AFPObj *obj, const struct passwd *pwd, volume->v_next = Volumes; Volumes = volume; + volume->v_obj = obj; return 0; } @@ -1236,7 +1238,9 @@ int load_volumes(AFPObj *obj, void (*delvol_fn)(const struct vol *)) if (Volumes) { if (!volfile_changed(&obj->options)) goto EC_CLEANUP; - free_volumes(); + /* TODO: volume reloading */ +// free_volumes(); + goto EC_CLEANUP; } /* try putting a read lock on the volume file twice, sleep 1 second if first attempt fails */ @@ -1286,12 +1290,11 @@ void unload_volumes(void) free_volumes(); } -const struct vol *getvolumes(void) +struct vol *getvolumes(void) { return Volumes; } -/* ------------------------- */ struct vol *getvolbyvid(const uint16_t vid ) { struct vol *vol; @@ -1308,6 +1311,20 @@ struct vol *getvolbyvid(const uint16_t vid ) return( vol ); } +struct vol *getvolbypath(const char *path) +{ + struct vol *vol = NULL; + struct vol *tmp; + + for (tmp = Volumes; tmp; tmp = tmp->v_next) { + if (strncmp(path, tmp->v_path, strlen(tmp->v_path)) == 0) { + vol = tmp; + break; + } + } + return vol; +} + #define MAXVAL 1024 /*! * Initialize an AFPObj and options from ini config file @@ -1322,11 +1339,12 @@ int afp_config_parse(AFPObj *AFPObj) char *q, *r; char val[MAXVAL]; + AFPObj->afp_version = 11; options->configfile = AFPObj->cmdlineconfigfile ? strdup(AFPObj->cmdlineconfigfile) : strdup(_PATH_CONFDIR "afp.conf"); options->sigconffile = strdup(_PATH_CONFDIR "afp_signature.conf"); options->uuidconf = strdup(_PATH_CONFDIR "afp_voluuid.conf"); options->flags = OPTION_ACL2MACCESS | OPTION_UUID | OPTION_SERVERNOTIF | AFPObj->cmdlineflags; - + if ((config = iniparser_load(AFPObj->options.configfile)) == NULL) return -1; AFPObj->iniconfig = config; -- 2.39.2