From 2144a4eb0f37f8812ccbe9d3e134a50ffcc2444e Mon Sep 17 00:00:00 2001 From: Frank Lahm Date: Wed, 6 Oct 2010 17:11:51 +0200 Subject: [PATCH] Rename cfrombstring to cfrombstr and msic --- bin/Makefile.am | 2 +- bin/ad/.gitignore | 6 +++ bin/ad/Makefile.am | 19 +++++++++ bin/{cnid => ad}/ad.c | 0 bin/{cnid => ad}/ad.h | 2 +- bin/{cnid => ad}/ad_cp.c | 8 ++-- bin/{cnid => ad}/ad_ls.c | 0 bin/{cnid => ad}/ad_util.c | 42 ++++++++++++++++--- bin/cnid/Makefile.am | 12 ------ configure.in | 1 + etc/afpd/appl.c | 2 +- etc/afpd/catsearch.c | 2 +- etc/afpd/dircache.c | 16 +++---- etc/afpd/directory.c | 85 ++++++++++++++++++++------------------ etc/afpd/enumerate.c | 2 +- etc/afpd/filedir.c | 12 +++--- etc/afpd/mangle.c | 6 +-- etc/afpd/ofork.c | 6 +-- include/atalk/bstradd.h | 9 +++- 19 files changed, 145 insertions(+), 87 deletions(-) create mode 100644 bin/ad/.gitignore create mode 100644 bin/ad/Makefile.am rename bin/{cnid => ad}/ad.c (100%) rename bin/{cnid => ad}/ad.h (95%) rename bin/{cnid => ad}/ad_cp.c (98%) rename bin/{cnid => ad}/ad_ls.c (100%) rename bin/{cnid => ad}/ad_util.c (94%) diff --git a/bin/Makefile.am b/bin/Makefile.am index 5e368486..86978ace 100644 --- a/bin/Makefile.am +++ b/bin/Makefile.am @@ -1,6 +1,6 @@ # Makefile.am for bin/ -SUBDIRS = adv1tov2 afile afppasswd cnid megatron uniconv misc +SUBDIRS = ad adv1tov2 afile afppasswd cnid megatron uniconv misc if USE_APPLETALK SUBDIRS += aecho getzones nbp pap psorder diff --git a/bin/ad/.gitignore b/bin/ad/.gitignore new file mode 100644 index 00000000..28432ec5 --- /dev/null +++ b/bin/ad/.gitignore @@ -0,0 +1,6 @@ +Makefile +Makefile.in +ad +.deps +.libs +*.o diff --git a/bin/ad/Makefile.am b/bin/ad/Makefile.am new file mode 100644 index 00000000..20dec080 --- /dev/null +++ b/bin/ad/Makefile.am @@ -0,0 +1,19 @@ +# Makefile.am for bin/ad/ + +noinst_HEADERS = ad.h + +if USE_BDB +bin_PROGRAMS = ad + +ad_SOURCES = \ + ad.c \ + ad_util.c \ + ad_ls.c \ + ad_cp.c + +ad_LDADD = \ + $(top_builddir)/libatalk/cnid/libcnid.la \ + $(top_builddir)/libatalk/libatalk.la \ + @ACL_LIBS@ + +endif diff --git a/bin/cnid/ad.c b/bin/ad/ad.c similarity index 100% rename from bin/cnid/ad.c rename to bin/ad/ad.c diff --git a/bin/cnid/ad.h b/bin/ad/ad.h similarity index 95% rename from bin/cnid/ad.h rename to bin/ad/ad.h index fe26bc51..e47c384a 100644 --- a/bin/cnid/ad.h +++ b/bin/ad/ad.h @@ -57,7 +57,7 @@ extern int ad_cp(int argc, char **argv); /* ad_util.c */ extern int newvol(const char *path, afpvol_t *vol); extern void freevol(afpvol_t *vol); -extern cnid_t get_parent_cnid_for_path(const struct volinfo *vi, const struct vol *vol, const char *path); +extern cnid_t cnid_for_path(const struct volinfo *vi, const struct vol *vol, const char *path); extern char *utompath(const struct volinfo *volinfo, char *upath); struct FTWELEM { diff --git a/bin/cnid/ad_cp.c b/bin/ad/ad_cp.c similarity index 98% rename from bin/cnid/ad_cp.c rename to bin/ad/ad_cp.c index 91cb762b..25a36542 100644 --- a/bin/cnid/ad_cp.c +++ b/bin/ad/ad_cp.c @@ -481,21 +481,21 @@ static int copy(const char *path, mode_t omask = umask(0); bstring addir = bfromcstr(to.p_path); bcatcstr(addir, "/.AppleDouble"); - mkdir(cfrombstring(addir), 02777); + mkdir(cfrombstr(addir), 02777); /* copy ".Parent" file */ bcatcstr(addir, "/.Parent"); bstring sdir = bfromcstr(path); bcatcstr(sdir, "/.AppleDouble/.Parent"); - if (copy_file(-1, cfrombstring(sdir), cfrombstring(addir), 0666) != 0) { - SLOG("Error copying %s -> %s", cfrombstring(sdir), cfrombstring(addir)); + if (copy_file(-1, cfrombstr(sdir), cfrombstr(addir), 0666) != 0) { + SLOG("Error copying %s -> %s", cfrombstr(sdir), cfrombstr(addir)); badcp = rval = 1; break; } umask(omask); /* Get CNID of Parent and add new childir to CNID database */ - did = get_parent_cnid_for_path(&dvolinfo, &dvolume, to.p_path); + did = cnid_for_path(&dvolinfo, &dvolume, to.p_path); } if (pflag) { diff --git a/bin/cnid/ad_ls.c b/bin/ad/ad_ls.c similarity index 100% rename from bin/cnid/ad_ls.c rename to bin/ad/ad_ls.c diff --git a/bin/cnid/ad_util.c b/bin/ad/ad_util.c similarity index 94% rename from bin/cnid/ad_util.c rename to bin/ad/ad_util.c index 1814ae74..9f862a4d 100644 --- a/bin/cnid/ad_util.c +++ b/bin/ad/ad_util.c @@ -50,6 +50,9 @@ #include #include +#include +#include +#include #include "ad.h" #define cp_pct(x, y)((y == 0) ? 0 : (int)(100.0 * (x) / (y))) @@ -156,8 +159,38 @@ char *utompath(const struct volinfo *volinfo, char *upath) return(m); } +/* + * path might be: + * (a) relative: + * "dir/subdir" with cwd: "/afp_volume/topdir" + * (b) absolute: + * "/afp_volume/dir/subdir" + */ +static const char *relative_path_for_volume(const char *path, const char *volpath) +{ + static char buf[MAXPATHLEN+1]; + bstring fpath; + + /* Make path absolute by concetanating for case (a) */ + if (path[0] != '/') { + fpath = bfromcstr(getcwdpath()); + if (fpath->data[fpath->slen - 1] != '/') + bcatcstr(fpath, "/"); + bcatcstr(fpath, path); + if (fpath->data[fpath->slen - 1] == '/') + bdelete(fpath, fpath->slen - 1, 1); + } else { + fpath = bfromcstr(path); + if (fpath->data[fpath->slen - 1] == '/') + bdelete(fpath, fpath->slen - 1, 1); + + } + + return NULL; +} + /*! - * Resolves CNID of a given paths parent directory + * ResolvesCNID of a given paths * * path might be: * (a) relative: @@ -166,7 +199,6 @@ char *utompath(const struct volinfo *volinfo, char *upath) * "/afp_volume/dir/subdir" * * 1) in case a) concatenate both paths - * 2) strip last element * 3) strip volume root * 4) start recursive CNID search with * a) DID:2, "topdir" @@ -175,9 +207,9 @@ char *utompath(const struct volinfo *volinfo, char *upath) * a) "/afp_volume/topdir/dir" * b) "/afp_volume/dir" (no recursion required) */ -cnid_t get_parent_cnid_for_path(const struct volinfo *vi, - const struct vol *vol, - const char *path) +cnid_t cnid_for_path(const struct volinfo *vi, + const struct vol *vol, + const char *path) { return 0; diff --git a/bin/cnid/Makefile.am b/bin/cnid/Makefile.am index 0de86aa9..2ade6f5d 100644 --- a/bin/cnid/Makefile.am +++ b/bin/cnid/Makefile.am @@ -1,19 +1,7 @@ # Makefile.am for bin/cnid/ EXTRA_DIST = cnid2_create.in -noinst_HEADERS = ad.h if USE_BDB -bin_PROGRAMS = ad bin_SCRIPTS = cnid2_create - -ad_SOURCES = ad.c ad_util.c \ - ad_ls.c \ - ad_cp.c - -ad_LDADD = \ - $(top_builddir)/libatalk/cnid/libcnid.la \ - $(top_builddir)/libatalk/libatalk.la \ - @ACL_LIBS@ - endif diff --git a/configure.in b/configure.in index 20d613ca..75162bd6 100644 --- a/configure.in +++ b/configure.in @@ -1275,6 +1275,7 @@ dnl --------------------- generate files AC_OUTPUT([Makefile bin/Makefile + bin/ad/Makefile bin/adv1tov2/Makefile bin/aecho/Makefile bin/afile/Makefile diff --git a/etc/afpd/appl.c b/etc/afpd/appl.c index d7e72f23..fe9ff250 100644 --- a/etc/afpd/appl.c +++ b/etc/afpd/appl.c @@ -138,7 +138,7 @@ makemacpath(const struct vol *vol, char *mpath, int mpathlen, struct dir *dir, c /* FIXME: pathname too long */ return NULL; } - memcpy(p, cfrombstring(dir->d_m_name), blength(dir->d_m_name) + 1); + memcpy(p, cfrombstr(dir->d_m_name), blength(dir->d_m_name) + 1); if ((dir = dirlookup(vol, dir->d_pdid)) == NULL) return NULL; } diff --git a/etc/afpd/catsearch.c b/etc/afpd/catsearch.c index b266348c..3aa04349 100644 --- a/etc/afpd/catsearch.c +++ b/etc/afpd/catsearch.c @@ -608,7 +608,7 @@ static int catsearch(struct vol *vol, struct dir *dir, goto catsearch_end; } } - path.m_name = cfrombstring(path.d_dir->d_m_name); + path.m_name = cfrombstr(path.d_dir->d_m_name); if (addstack(path.u_name, path.d_dir, cidx) == -1) { result = AFPERR_MISC; diff --git a/etc/afpd/dircache.c b/etc/afpd/dircache.c index c641f249..323a7371 100644 --- a/etc/afpd/dircache.c +++ b/etc/afpd/dircache.c @@ -285,7 +285,7 @@ struct dir *dircache_search_by_did(const struct vol *vol, cnid_t did) if (cdir) LOG(log_debug, logtype_afpd, "dircache(did:%u): {cached: path:'%s'}", - ntohl(did), cfrombstring(cdir->d_u_name)); + ntohl(did), cfrombstr(cdir->d_u_name)); else LOG(log_debug, logtype_afpd, "dircache(did:%u): {not in cache}", ntohl(did)); @@ -380,7 +380,7 @@ int dircache_add(struct dir *dir) } LOG(log_debug, logtype_afpd, "dircache(did:%u,'%s'): {added}", - ntohl(dir->d_did), cfrombstring(dir->d_u_name)); + ntohl(dir->d_did), cfrombstr(dir->d_u_name)); AFP_ASSERT(queue_count == index_didname->hash_nodecount && queue_count == dircache->hash_nodecount); @@ -413,7 +413,7 @@ void dircache_remove(const struct vol *vol _U_, struct dir *dir, int flags) if (flags & DIDNAME_INDEX) { if ((hn = hash_lookup(index_didname, dir)) == NULL) { LOG(log_error, logtype_default, "dircache_remove(%u,\"%s\"): not in didname index", - ntohl(dir->d_did), cfrombstring(dir->d_u_name)); + ntohl(dir->d_did), cfrombstr(dir->d_u_name)); dircache_dump(); AFP_PANIC("dircache_remove"); } @@ -423,7 +423,7 @@ void dircache_remove(const struct vol *vol _U_, struct dir *dir, int flags) if (flags & DIRCACHE) { if ((hn = hash_lookup(dircache, dir)) == NULL) { LOG(log_error, logtype_default, "dircache_remove(%u,\"%s\"): not in dircache", - ntohl(dir->d_did), cfrombstring(dir->d_u_name)); + ntohl(dir->d_did), cfrombstr(dir->d_u_name)); dircache_dump(); AFP_PANIC("dircache_remove"); } @@ -431,7 +431,7 @@ void dircache_remove(const struct vol *vol _U_, struct dir *dir, int flags) } LOG(log_debug, logtype_afpd, "dircache(did:%u,\"%s\"): {removed}", - ntohl(dir->d_did), cfrombstring(dir->d_u_name)); + ntohl(dir->d_did), cfrombstr(dir->d_u_name)); AFP_ASSERT(queue_count == index_didname->hash_nodecount && queue_count == dircache->hash_nodecount); @@ -524,7 +524,7 @@ void dircache_dump(void) dir->d_fullpath ? "d" : "f", (dir->d_flags & DIRF_CACHELOCK) ? "l" : "-", dir->d_ofork ? "o" : "-", - cfrombstring(dir->d_u_name)); + cfrombstr(dir->d_u_name)); } fprintf(dump, "\nSecondary DID/name index:\n"); @@ -542,7 +542,7 @@ void dircache_dump(void) dir->d_fullpath ? "d" : "f", (dir->d_flags & DIRF_CACHELOCK) ? "l" : "-", dir->d_ofork ? "o" : "-", - cfrombstring(dir->d_u_name)); + cfrombstr(dir->d_u_name)); } fprintf(dump, "\nLRU Queue:\n"); @@ -561,7 +561,7 @@ void dircache_dump(void) dir->d_fullpath ? "d" : "f", (dir->d_flags & DIRF_CACHELOCK) ? "l" : "-", dir->d_ofork ? "o" : "-", - cfrombstring(dir->d_u_name)); + cfrombstr(dir->d_u_name)); n = n->next; } diff --git a/etc/afpd/directory.c b/etc/afpd/directory.c index ad76bd09..cadcdb02 100644 --- a/etc/afpd/directory.c +++ b/etc/afpd/directory.c @@ -369,19 +369,19 @@ static struct path *path_from_dir(struct vol *vol, struct dir *dir, struct path if (movecwd( vol, dirlookup(vol, dir->d_pdid)) < 0 ) /* 1 */ return NULL; - memcpy(ret->m_name, cfrombstring(dir->d_m_name), blength(dir->d_m_name) + 1); /* 3 */ + memcpy(ret->m_name, cfrombstr(dir->d_m_name), blength(dir->d_m_name) + 1); /* 3 */ if (dir->d_m_name == dir->d_u_name) { ret->u_name = ret->m_name; } else { ret->u_name = ret->m_name + blength(dir->d_m_name) + 1; - memcpy(ret->u_name, cfrombstring(dir->d_u_name), blength(dir->d_u_name) + 1); + memcpy(ret->u_name, cfrombstr(dir->d_u_name), blength(dir->d_u_name) + 1); } ret->d_dir = dir; LOG(log_debug, logtype_afpd, "cname('%s') {path-from-dir: AFPERR_ACCESS. curdir:'%s', path:'%s'}", - cfrombstring(dir->d_fullpath), - cfrombstring(curdir->d_fullpath), + cfrombstr(dir->d_fullpath), + cfrombstr(curdir->d_fullpath), ret->u_name); return ret; @@ -390,12 +390,12 @@ static struct path *path_from_dir(struct vol *vol, struct dir *dir, struct path if (movecwd(vol, dirlookup(vol, dir->d_pdid)) < 0 ) /* 1 */ return NULL; - memcpy(ret->m_name, cfrombstring(dir->d_m_name), blength(dir->d_m_name) + 1); + memcpy(ret->m_name, cfrombstr(dir->d_m_name), blength(dir->d_m_name) + 1); if (dir->d_m_name == dir->d_u_name) { ret->u_name = ret->m_name; } else { ret->u_name = ret->m_name + blength(dir->d_m_name) + 1; - memcpy(ret->u_name, cfrombstring(dir->d_u_name), blength(dir->d_u_name) + 1); + memcpy(ret->u_name, cfrombstr(dir->d_u_name), blength(dir->d_u_name) + 1); } ret->d_dir = NULL; /* 4 */ @@ -475,7 +475,7 @@ struct dir *dirlookup(const struct vol *vol, cnid_t did) afp_errno = AFPERR_BADTYPE; return NULL; } - if (lstat(cfrombstring(ret->d_fullpath), &st) != 0) { + if (lstat(cfrombstr(ret->d_fullpath), &st) != 0) { LOG(log_debug, logtype_afpd, "dirlookup(did: %u) {lstat: %s}", ntohl(did), strerror(errno)); switch (errno) { case ENOENT: @@ -526,9 +526,9 @@ struct dir *dirlookup(const struct vol *vol, cnid_t did) } /* stat it and check if it's a dir */ - LOG(log_debug, logtype_afpd, "dirlookup: {stating %s}", cfrombstring(fullpath)); + LOG(log_debug, logtype_afpd, "dirlookup: {stating %s}", cfrombstr(fullpath)); - if (stat(cfrombstring(fullpath), &st) != 0) { /* 5a */ + if (stat(cfrombstr(fullpath), &st) != 0) { /* 5a */ switch (errno) { case ENOENT: afp_errno = AFPERR_NOOBJ; @@ -572,7 +572,7 @@ struct dir *dirlookup(const struct vol *vol, cnid_t did) } LOG(log_debug, logtype_afpd, "dirlookup(did: %u) {end: did:%u, path:'%s'}", - ntohl(did), ntohl(pdid), cfrombstring(ret->d_fullpath)); + ntohl(did), ntohl(pdid), cfrombstr(ret->d_fullpath)); exit: if (err) { @@ -783,8 +783,8 @@ struct dir *dir_add(struct vol *vol, const struct dir *dir, struct path *path, i if ((cdir = dircache_search_by_name(vol, dir, path->u_name, strlen(path->u_name))) != NULL) { /* there's a stray entry in the dircache */ LOG(log_debug, logtype_afpd, "dir_add(did:%u,'%s/%s'): {stray cache entry: did:%u,'%s', removing}", - ntohl(dir->d_did), cfrombstring(dir->d_fullpath), path->u_name, - ntohl(cdir->d_did), cfrombstring(dir->d_fullpath)); + ntohl(dir->d_did), cfrombstr(dir->d_fullpath), path->u_name, + ntohl(cdir->d_did), cfrombstr(dir->d_fullpath)); if (dir_remove(vol, cdir) != 0) { dircache_dump(); AFP_PANIC("dir_add"); @@ -829,14 +829,14 @@ struct dir *dir_add(struct vol *vol, const struct dir *dir, struct path *path, i } if ((dircache_add(cdir)) != 0) { /* 4 */ - LOG(log_error, logtype_afpd, "dir_add: fatal dircache error: %s", cfrombstring(fullpath)); + LOG(log_error, logtype_afpd, "dir_add: fatal dircache error: %s", cfrombstr(fullpath)); exit(EXITERR_SYS); } exit: if (err != 0) { LOG(log_debug, logtype_afpd, "dir_add('%s/%s'): error: %u", - cfrombstring(dir->d_u_name), path->u_name, err); + cfrombstr(dir->d_u_name), path->u_name, err); if (adp) ad_close_metadata(adp); @@ -848,8 +848,8 @@ exit: } else { /* no error */ LOG(log_debug, logtype_afpd, "dir_add(did:%u,'%s/%s'): {cached: %u,'%s'}", - ntohl(dir->d_did), cfrombstring(dir->d_fullpath), path->u_name, - ntohl(cdir->d_did), cfrombstring(cdir->d_fullpath)); + ntohl(dir->d_did), cfrombstr(dir->d_fullpath), path->u_name, + ntohl(cdir->d_did), cfrombstr(cdir->d_fullpath)); } return(cdir); @@ -876,7 +876,7 @@ int dir_remove(const struct vol *vol, struct dir *dir) if (dir->d_flags & DIRF_CACHELOCK || dir->d_ofork) { /* 1 */ LOG(log_warning, logtype_afpd, "dir_remove(did:%u,'%s'): dir is locked or has opened forks", - ntohl(dir->d_did), cfrombstring(dir->d_fullpath)); + ntohl(dir->d_did), cfrombstr(dir->d_fullpath)); return 0; } @@ -887,7 +887,7 @@ int dir_remove(const struct vol *vol, struct dir *dir) } LOG(log_debug, logtype_afpd, "dir_remove(did:%u,'%s'): {removing}", - ntohl(dir->d_did), cfrombstring(dir->d_fullpath)); + ntohl(dir->d_did), cfrombstr(dir->d_fullpath)); dircache_remove(vol, dir, DIRCACHE | DIDNAME_INDEX | QUEUE_INDEX); /* 3 */ dir_free(dir); /* 4 */ @@ -1013,7 +1013,7 @@ struct path *cname(struct vol *vol, struct dir *dir, char **cpath) int size = 0; int toUTF8 = 0; - LOG(log_maxdebug, logtype_afpd, "came('%s'): {start}", cfrombstring(dir->d_fullpath)); + LOG(log_maxdebug, logtype_afpd, "came('%s'): {start}", cfrombstr(dir->d_fullpath)); data = *cpath; afp_errno = AFPERR_NOOBJ; @@ -1054,7 +1054,7 @@ struct path *cname(struct vol *vol, struct dir *dir, char **cpath) if (movecwd(vol, dir) < 0 ) { LOG(log_debug, logtype_afpd, "cname(did:%u): failed to chdir to '%s'", - ntohl(dir->d_did), cfrombstring(dir->d_fullpath)); + ntohl(dir->d_did), cfrombstr(dir->d_fullpath)); if (len == 0) return path_from_dir(vol, dir, &ret); else @@ -1095,7 +1095,7 @@ struct path *cname(struct vol *vol, struct dir *dir, char **cpath) return NULL; } - LOG(log_maxdebug, logtype_afpd, "came('%s'): {node: '%s}", cfrombstring(dir->d_fullpath), ret.u_name); + LOG(log_maxdebug, logtype_afpd, "came('%s'): {node: '%s}", cfrombstr(dir->d_fullpath), ret.u_name); /* Prevent access to our special folders like .AppleDouble */ if (check_name(vol, ret.u_name)) { @@ -1111,7 +1111,7 @@ struct path *cname(struct vol *vol, struct dir *dir, char **cpath) * root parent (did 1) has one child: the volume. Requests for did=1 with * some must check against the volume name. */ - if ((strcmp(cfrombstring(vol->v_root->d_m_name), ret.m_name)) == 0) + if ((strcmp(cfrombstr(vol->v_root->d_m_name), ret.m_name)) == 0) cdir = vol->v_root; else return NULL; @@ -1138,13 +1138,15 @@ struct path *cname(struct vol *vol, struct dir *dir, char **cpath) * this will terminate clean in while (1) because len == 0, * probably afp_createfile|dir */ - LOG(log_maxdebug, logtype_afpd, "came('%s'): {leave-cnode ENOENT (possile create request): '%s'}", cfrombstring(dir->d_fullpath), ret.u_name); + LOG(log_maxdebug, logtype_afpd, "came('%s'): {leave-cnode ENOENT (possile create request): '%s'}", + cfrombstr(dir->d_fullpath), ret.u_name); continue; /* 10 */ } switch (ret.st.st_mode & S_IFMT) { case S_IFREG: /* 11 */ - LOG(log_debug, logtype_afpd, "came('%s'): {file: '%s'}", cfrombstring(dir->d_fullpath), ret.u_name); + LOG(log_debug, logtype_afpd, "came('%s'): {file: '%s'}", + cfrombstr(dir->d_fullpath), ret.u_name); if (len > 0) { /* it wasn't the last part, so we have a bogus path request */ afp_errno = AFPERR_PARAM; @@ -1152,9 +1154,11 @@ struct path *cname(struct vol *vol, struct dir *dir, char **cpath) } continue; /* continues while loop */ case S_IFLNK: /* 12 */ - LOG(log_debug, logtype_afpd, "came('%s'): {link: '%s'}", cfrombstring(dir->d_fullpath), ret.u_name); + LOG(log_debug, logtype_afpd, "came('%s'): {link: '%s'}", + cfrombstr(dir->d_fullpath), ret.u_name); if (len > 0) { - LOG(log_warning, logtype_afpd, "came('%s'): {symlinked dir: '%s'}", cfrombstring(dir->d_fullpath), ret.u_name); + LOG(log_warning, logtype_afpd, "came('%s'): {symlinked dir: '%s'}", + cfrombstr(dir->d_fullpath), ret.u_name); afp_errno = AFPERR_PARAM; return NULL; } @@ -1183,7 +1187,7 @@ struct path *cname(struct vol *vol, struct dir *dir, char **cpath) /* Now chdir to the evaluated dir */ if (movecwd( vol, cdir ) < 0 ) { /* 16 */ LOG(log_debug, logtype_afpd, "cname(cwd:'%s'): failed to chdir to new subdir '%s': %s", - cfrombstring(curdir->d_fullpath), cfrombstring(cdir->d_fullpath), strerror(errno)); + cfrombstr(curdir->d_fullpath), cfrombstr(cdir->d_fullpath), strerror(errno)); if (len == 0) return path_from_dir(vol, cdir, &ret); else @@ -1205,8 +1209,8 @@ struct path *cname(struct vol *vol, struct dir *dir, char **cpath) } LOG(log_debug, logtype_afpd, "came('%s') {end: curdir:'%s', path:'%s'}", - cfrombstring(dir->d_fullpath), - cfrombstring(curdir->d_fullpath), + cfrombstr(dir->d_fullpath), + cfrombstr(curdir->d_fullpath), ret.u_name); return &ret; @@ -1228,7 +1232,7 @@ int movecwd(const struct vol *vol, struct dir *dir) AFP_ASSERT(dir); LOG(log_maxdebug, logtype_afpd, "movecwd(curdir:'%s', cwd:'%s')", - cfrombstring(curdir->d_fullpath), getcwdpath()); + cfrombstr(curdir->d_fullpath), getcwdpath()); if ( dir == curdir) return( 0 ); @@ -1237,11 +1241,12 @@ int movecwd(const struct vol *vol, struct dir *dir) return 0; } - LOG(log_debug, logtype_afpd, "movecwd(did:%u, '%s')", ntohl(dir->d_did), cfrombstring(dir->d_fullpath)); + LOG(log_debug, logtype_afpd, "movecwd(did:%u, '%s')", + ntohl(dir->d_did), cfrombstr(dir->d_fullpath)); - if ((ret = lchdir(cfrombstring(dir->d_fullpath))) != 0 ) { + if ((ret = lchdir(cfrombstr(dir->d_fullpath))) != 0 ) { LOG(log_debug, logtype_afpd, "movecwd('%s'): ret: %u, %s", - cfrombstring(dir->d_fullpath), ret, strerror(errno)); + cfrombstr(dir->d_fullpath), ret, strerror(errno)); if (ret == 1) { /* p is a symlink or getcwd failed */ afp_errno = AFPERR_BADTYPE; @@ -1384,7 +1389,7 @@ int getdirparams(const struct vol *vol, case DIRPBIT_ATTR : if ( isad ) { ad_getattr(&ad, &ashort); - } else if (invisible_dots(vol, cfrombstring(dir->d_u_name))) { + } else if (invisible_dots(vol, cfrombstr(dir->d_u_name))) { ashort = htons(ATTRBIT_INVISIBLE); } else ashort = 0; @@ -1430,7 +1435,7 @@ int getdirparams(const struct vol *vol, memcpy(data + FINDERINFO_FRVIEWOFF, &ashort, sizeof(ashort)); /* dot files are by default visible */ - if (invisible_dots(vol, cfrombstring(dir->d_u_name))) { + if (invisible_dots(vol, cfrombstr(dir->d_u_name))) { ashort = htons(FINDERINFO_INVISIBLE); memcpy(data + FINDERINFO_FRFLAGOFF, &ashort, sizeof(ashort)); } @@ -1553,12 +1558,12 @@ int getdirparams(const struct vol *vol, if ( l_nameoff ) { ashort = htons( data - buf ); memcpy( l_nameoff, &ashort, sizeof( ashort )); - data = set_name(vol, data, pdid, cfrombstring(dir->d_m_name), dir->d_did, 0); + data = set_name(vol, data, pdid, cfrombstr(dir->d_m_name), dir->d_did, 0); } if ( utf_nameoff ) { ashort = htons( data - buf ); memcpy( utf_nameoff, &ashort, sizeof( ashort )); - data = set_name(vol, data, pdid, cfrombstring(dir->d_m_name), dir->d_did, utf8); + data = set_name(vol, data, pdid, cfrombstr(dir->d_m_name), dir->d_did, utf8); } if ( isad ) { ad_close_metadata( &ad ); @@ -1795,7 +1800,7 @@ int setdirparams(struct vol *vol, struct path *path, u_int16_t d_bitmap, char *b * to set our name, etc. */ if ( (ad_get_HF_flags( &ad ) & O_CREAT)) { - ad_setname(&ad, cfrombstring(curdir->d_m_name)); + ad_setname(&ad, cfrombstr(curdir->d_m_name)); } } @@ -2057,7 +2062,7 @@ int afp_syncdir(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, if ( fsync(dfd) < 0 ) LOG(log_error, logtype_afpd, "afp_syncdir(%s): %s", - vol->ad_path(cfrombstring(dir->d_u_name), ADFLAGS_DIR), strerror(errno) ); + vol->ad_path(cfrombstr(dir->d_u_name), ADFLAGS_DIR), strerror(errno) ); close(dfd); } @@ -2262,7 +2267,7 @@ int deletecurdir(struct vol *vol) goto delete_done; } - err = netatalk_rmdir_all_errors(-1, cfrombstring(fdir->d_u_name)); + err = netatalk_rmdir_all_errors(-1, cfrombstr(fdir->d_u_name)); if ( err == AFP_OK || err == AFPERR_NOOBJ) { cnid_delete(vol->v_cdb, fdir->d_did); dir_remove( vol, fdir ); diff --git a/etc/afpd/enumerate.c b/etc/afpd/enumerate.c index b8a403bd..49625bdc 100644 --- a/etc/afpd/enumerate.c +++ b/etc/afpd/enumerate.c @@ -270,7 +270,7 @@ static int enumerate(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, LOG(log_debug, logtype_afpd, "enumerate(vid:%u, did:%u, cwddid:%u, cwd:'%s', name:'%s', f/d:%04x/%04x, rc:%u, i:%u, max:%u)", ntohs(vid), ntohl(did), ntohl(curdir->d_did), - cfrombstring(curdir->d_fullpath), o_path->u_name, + cfrombstr(curdir->d_fullpath), o_path->u_name, fbitmap, dbitmap, reqcnt, sindex, maxsz); data = rbuf + 3 * sizeof( u_int16_t ); diff --git a/etc/afpd/filedir.c b/etc/afpd/filedir.c index 095189ce..46c0bf30 100644 --- a/etc/afpd/filedir.c +++ b/etc/afpd/filedir.c @@ -176,7 +176,7 @@ int afp_getfildirparams(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *r LOG(log_debug, logtype_afpd, "getfildirparams(vid:%u, did:%u, f/d:%04x/%04x) {cwdid:%u, cwd: %s, name:'%s'}", ntohs(vid), ntohl(dir->d_did), fbitmap, dbitmap, - ntohl(curdir->d_did), cfrombstring(curdir->d_fullpath), s_path->u_name); + ntohl(curdir->d_did), cfrombstr(curdir->d_fullpath), s_path->u_name); st = &s_path->st; if (!s_path->st_valid) { @@ -523,7 +523,7 @@ int afp_rename(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size if ( movecwd( vol, dirlookup(vol, sdir->d_pdid) ) < 0 ) { return afp_errno; } - memcpy(oldname, cfrombstring(sdir->d_m_name), blength(sdir->d_m_name) +1); + memcpy(oldname, cfrombstr(sdir->d_m_name), blength(sdir->d_m_name) +1); } /* another place where we know about the path type */ @@ -596,7 +596,7 @@ int afp_delete(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size rc = deletefile(vol, -1, upath, 1); struct dir *cachedfile; - if (cachedfile = dircache_search_by_name(vol, dir, upath, strlen(upath))) { + if ((cachedfile = dircache_search_by_name(vol, dir, upath, strlen(upath)))) { dircache_remove(vol, cachedfile, DIRCACHE | DIDNAME_INDEX | QUEUE_INDEX); dir_free(cachedfile); } @@ -627,9 +627,9 @@ char *absupath(const struct vol *vol, struct dir *dir, char *u) if (path->slen > MAXPATHLEN) return NULL; - LOG(log_debug, logtype_afpd, "absupath: %s", cfrombstring(path)); + LOG(log_debug, logtype_afpd, "absupath: %s", cfrombstr(path)); - strncpy(pathbuf, cfrombstring(path), blength(path) + 1); + strncpy(pathbuf, cfrombstr(path), blength(path) + 1); bdestroy(path); return(pathbuf); @@ -699,7 +699,7 @@ int afp_moveandrename(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U } strcpy(oldname, path->m_name); /* an extra copy for of_rename */ } else { - memcpy(oldname, cfrombstring(sdir->d_m_name), blength(sdir->d_m_name) + 1); + memcpy(oldname, cfrombstr(sdir->d_m_name), blength(sdir->d_m_name) + 1); } #ifdef HAVE_RENAMEAT diff --git a/etc/afpd/mangle.c b/etc/afpd/mangle.c index 7769542d..91533e61 100644 --- a/etc/afpd/mangle.c +++ b/etc/afpd/mangle.c @@ -182,11 +182,11 @@ private_demangle(const struct vol *vol, char *mfilename, cnid_t did, cnid_t *osx } if (!osx) { /* it's not from cname so mfilename and dir must be the same */ - if (strcmp(cfrombstring(dir->d_m_name), mfilename) == 0) { - return cfrombstring(dir->d_u_name); + if (strcmp(cfrombstr(dir->d_m_name), mfilename) == 0) { + return cfrombstr(dir->d_u_name); } } else { - return demangle_checks(vol, cfrombstring(dir->d_u_name), mfilename, prefix, t); + return demangle_checks(vol, cfrombstr(dir->d_u_name), mfilename, prefix, t); } } else if (NULL != (u_name = cnid_resolve(vol->v_cdb, &id, buffer, len)) ) { diff --git a/etc/afpd/ofork.c b/etc/afpd/ofork.c index a6359ad2..b82eabcb 100644 --- a/etc/afpd/ofork.c +++ b/etc/afpd/ofork.c @@ -290,7 +290,7 @@ int of_stat(struct path *path) if ((ret = lstat(path->u_name, &path->st)) < 0) { LOG(log_debug, logtype_afpd, "of_stat('%s/%s': %s)", - cfrombstring(curdir->d_fullpath), path->u_name, strerror(errno)); + cfrombstr(curdir->d_fullpath), path->u_name, strerror(errno)); path->st_errno = errno; } @@ -335,7 +335,7 @@ int of_statdir(struct vol *vol, struct path *path) len = blength(path->d_dir->d_u_name); if (len > (MAXPATHLEN - 3)) len = MAXPATHLEN - 3; - strncpy(pathname + 3, cfrombstring(path->d_dir->d_u_name), len + 1); + strncpy(pathname + 3, cfrombstr(path->d_dir->d_u_name), len + 1); LOG(log_debug, logtype_afpd, "of_statdir: stating: '%s'", pathname); @@ -350,7 +350,7 @@ int of_statdir(struct vol *vol, struct path *path) return -1; path->st_errno = 0; - if ((ret = lstat(cfrombstring(path->d_dir->d_u_name), &path->st)) < 0) + if ((ret = lstat(cfrombstr(path->d_dir->d_u_name), &path->st)) < 0) path->st_errno = errno; } diff --git a/include/atalk/bstradd.h b/include/atalk/bstradd.h index a402339a..df8262ca 100644 --- a/include/atalk/bstradd.h +++ b/include/atalk/bstradd.h @@ -27,7 +27,14 @@ #include -#define cfrombstring(b) ((char *)((b)->data)) +#define cfrombstr(b) ((char *)((b)->data)) + +/* strip slashes from end of a bstring */ +#define BSTRING_STRIP_SLASH(a) \ + do { \ + while ((a)->data[(a)->slen - 1] == '/') \ + bdelete((a), (a)->slen - 1, 1); \ + } while (0); typedef struct tagbstring static_bstring; -- 2.39.2