2 * Copyright (c) 1990,1993 Regents of The University of Michigan.
3 * All Rights Reserved. See COPYRIGHT.
8 #endif /* HAVE_CONFIG_H */
15 #include <sys/param.h>
21 #include <atalk/adouble.h>
22 #include <atalk/vfs.h>
23 #include <atalk/afp.h>
24 #include <atalk/util.h>
25 #include <atalk/cnid.h>
26 #include <atalk/logger.h>
27 #include <atalk/uuid.h>
28 #include <atalk/unix.h>
29 #include <atalk/bstrlib.h>
30 #include <atalk/bstradd.h>
31 #include <atalk/errchk.h>
32 #include <atalk/globals.h>
33 #include <atalk/fce_api.h>
35 #include "directory.h"
47 * FIXMEs, loose ends after the dircache rewrite:
48 * o merge dircache_search_by_name and dir_add ??
49 * o case-insensitivity is gone from cname
53 /*******************************************************************************************
55 ******************************************************************************************/
58 /* As long as directory.c hasn't got its own init call, this get initialized in dircache_init */
59 struct dir rootParent = {
60 NULL, NULL, NULL, NULL, /* path, d_m_name, d_u_name, d_m_name_ucs2 */
61 NULL, 0, 0, /* qidx_node, ctime, d_flags */
62 0, 0, 0, 0 /* pdid, did, offcnt, d_vid */
64 struct dir *curdir = &rootParent;
65 struct path Cur_Path = {
70 NULL,/* struct dir * */
71 0, /* stat is not set */
77 * dir_remove queues struct dirs to be freed here. We can't just delete them immeidately
78 * eg in dircache_search_by_id, because a caller somewhere up the stack might be
81 * - we mark it as invalid by setting d_did to CNID_INVALID (ie 0)
82 * - queue it in "invalid_dircache_entries" queue
83 * - which is finally freed at the end of every AFP func in afp_dsi.c.
85 q_t *invalid_dircache_entries;
88 /*******************************************************************************************
90 ******************************************************************************************/
93 /* -------------------------
94 appledouble mkdir afp error code.
96 static int netatalk_mkdir(const struct vol *vol, const char *name)
101 if (vol->v_flags & AFPVOL_UNIX_PRIV) {
102 if (lstat(".", &st) < 0)
104 int mode = (DIRBITS & (~S_ISGID & st.st_mode)) | (0777 & ~vol->v_umask);
105 LOG(log_maxdebug, logtype_afpd, "netatalk_mkdir(\"%s\") {parent mode: %04o, vol umask: %04o}",
106 name, st.st_mode, vol->v_umask);
108 ret = mkdir(name, mode);
110 ret = ad_mkdir(name, DIRBITS | 0777);
116 return( AFPERR_NOOBJ );
118 return( AFPERR_VLOCK );
121 return( AFPERR_ACCESS );
123 return( AFPERR_EXIST );
126 return( AFPERR_DFULL );
128 return( AFPERR_PARAM );
134 /* ------------------- */
135 static int deletedir(int dirfd, char *dir)
137 char path[MAXPATHLEN + 1];
145 if ((len = strlen(dir)) +2 > sizeof(path))
149 if ((dp = opendirat(dirfd, dir)) == NULL)
155 remain = sizeof(path) -len -1;
156 while ((de = readdir(dp)) && err == AFP_OK) {
157 /* skip this and previous directory */
158 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
161 if (strlen(de->d_name) > remain) {
165 strcpy(path + len, de->d_name);
166 if (lstatat(dirfd, path, &st)) {
169 if (S_ISDIR(st.st_mode)) {
170 err = deletedir(dirfd, path);
172 err = netatalk_unlinkat(dirfd, path);
177 /* okay. the directory is empty. delete it. note: we already got rid
180 err = netatalk_rmdir(dirfd, dir);
185 /* do a recursive copy. */
186 static int copydir(const struct vol *vol, int dirfd, char *src, char *dst)
188 char spath[MAXPATHLEN + 1], dpath[MAXPATHLEN + 1];
197 /* doesn't exist or the path is too long. */
198 if (((slen = strlen(src)) > sizeof(spath) - 2) ||
199 ((dlen = strlen(dst)) > sizeof(dpath) - 2) ||
200 ((dp = opendirat(dirfd, src)) == NULL))
203 /* try to create the destination directory */
204 if (AFP_OK != (err = netatalk_mkdir(vol, dst)) ) {
209 /* set things up to copy */
213 srem = sizeof(spath) - slen -1;
218 drem = sizeof(dpath) - dlen -1;
221 while ((de = readdir(dp))) {
222 /* skip this and previous directory */
223 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
226 if (strlen(de->d_name) > srem) {
230 strcpy(spath + slen, de->d_name);
232 if (lstatat(dirfd, spath, &st) == 0) {
233 if (strlen(de->d_name) > drem) {
237 strcpy(dpath + dlen, de->d_name);
239 if (S_ISDIR(st.st_mode)) {
240 if (AFP_OK != (err = copydir(vol, dirfd, spath, dpath)))
242 } else if (AFP_OK != (err = copyfile(vol, vol, dirfd, spath, dpath, NULL, NULL))) {
246 /* keep the same time stamp. */
247 ut.actime = ut.modtime = st.st_mtime;
253 /* keep the same time stamp. */
254 if (lstatat(dirfd, src, &st) == 0) {
255 ut.actime = ut.modtime = st.st_mtime;
264 /* ---------------------
265 * is our cached offspring count valid?
267 static int diroffcnt(struct dir *dir, struct stat *st)
269 return st->st_ctime == dir->d_ctime;
272 /* --------------------- */
273 static int invisible_dots(const struct vol *vol, const char *name)
275 return vol_inv_dots(vol) && *name == '.' && strcmp(name, ".") && strcmp(name, "..");
278 /* ------------------ */
279 static int set_dir_errors(struct path *path, const char *where, int err)
284 return AFPERR_ACCESS;
288 LOG(log_error, logtype_afpd, "setdirparam(%s): %s: %s", fullpathname(path->u_name), where, strerror(err) );
293 * @brief Convert name in client encoding to server encoding
295 * Convert ret->m_name to ret->u_name from client encoding to server encoding.
296 * This only gets called from cname().
298 * @returns 0 on success, -1 on error
300 * @note If the passed ret->m_name is mangled, we'll demangle it
302 static int cname_mtouname(const struct vol *vol, const struct dir *dir, struct path *ret, int toUTF8)
304 static char temp[ MAXPATHLEN + 1];
308 if (afp_version >= 30) {
310 if (dir->d_did == DIRDID_ROOT_PARENT) {
312 * With uft8 volume name is utf8-mac, but requested path may be a mangled longname. See #2611981.
313 * So we compare it with the longname from the current volume and if they match
314 * we overwrite the requested path with the utf8 volume name so that the following
317 ucs2_to_charset(vol->v_maccharset, vol->v_macname, temp, AFPVOL_MACNAMELEN + 1);
318 if (strcasecmp(ret->m_name, temp) == 0)
319 ucs2_to_charset(CH_UTF8_MAC, vol->v_u8mname, ret->m_name, AFPVOL_U8MNAMELEN);
322 if (mtoUTF8(vol, ret->m_name, strlen(ret->m_name), temp, MAXPATHLEN) == (size_t)-1) {
323 afp_errno = AFPERR_PARAM;
326 strcpy(ret->m_name, temp);
330 /* check for OS X mangled filename :( */
331 t = demangle_osx(vol, ret->m_name, dir->d_did, &fileid);
332 LOG(log_maxdebug, logtype_afpd, "cname_mtouname('%s',did:%u) {demangled:'%s', fileid:%u}",
333 ret->m_name, ntohl(dir->d_did), t, ntohl(fileid));
335 if (t != ret->m_name) {
337 /* duplicate work but we can't reuse all convert_char we did in demangle_osx
338 * flags weren't the same
340 if ( (t = utompath(vol, ret->u_name, fileid, utf8_encoding())) ) {
341 /* at last got our view of mac name */
342 strcpy(ret->m_name, t);
345 } /* afp_version >= 30 */
347 /* If we haven't got it by now, get it */
348 if (ret->u_name == NULL) {
349 if ((ret->u_name = mtoupath(vol, ret->m_name, dir->d_did, utf8_encoding())) == NULL) {
350 afp_errno = AFPERR_PARAM;
359 * @brief Build struct path from struct dir
361 * The final movecwd in cname failed, possibly with EPERM or ENOENT. We:
362 * 1. move cwd into parent dir (we're often already there, but not always)
363 * 2. set struct path to the dirname
365 * AFPERR_ACCESS: the dir is there, we just cant chdir into it
366 * AFPERR_NOOBJ: the dir was there when we stated it in cname, so we have a race
367 * 4. indicate there's no dir for this path
370 static struct path *path_from_dir(struct vol *vol, struct dir *dir, struct path *ret)
372 if (dir->d_did == DIRDID_ROOT_PARENT || dir->d_did == DIRDID_ROOT)
378 if (movecwd( vol, dirlookup(vol, dir->d_pdid)) < 0 ) /* 1 */
381 memcpy(ret->m_name, cfrombstr(dir->d_m_name), blength(dir->d_m_name) + 1); /* 3 */
382 if (dir->d_m_name == dir->d_u_name) {
383 ret->u_name = ret->m_name;
385 ret->u_name = ret->m_name + blength(dir->d_m_name) + 1;
386 memcpy(ret->u_name, cfrombstr(dir->d_u_name), blength(dir->d_u_name) + 1);
391 LOG(log_debug, logtype_afpd, "cname('%s') {path-from-dir: AFPERR_ACCESS. curdir:'%s', path:'%s'}",
392 cfrombstr(dir->d_fullpath),
393 cfrombstr(curdir->d_fullpath),
399 if (movecwd(vol, dirlookup(vol, dir->d_pdid)) < 0 ) /* 1 */
402 memcpy(ret->m_name, cfrombstr(dir->d_m_name), blength(dir->d_m_name) + 1);
403 if (dir->d_m_name == dir->d_u_name) {
404 ret->u_name = ret->m_name;
406 ret->u_name = ret->m_name + blength(dir->d_m_name) + 1;
407 memcpy(ret->u_name, cfrombstr(dir->d_u_name), blength(dir->d_u_name) + 1);
410 ret->d_dir = NULL; /* 4 */
411 dir_remove(vol, dir); /* 5 */
418 /* DEADC0DE: never get here */
423 /*********************************************************************************************
425 ********************************************************************************************/
427 int get_afp_errno(const int param)
429 if (afp_errno != AFPERR_DID1)
435 * Resolve struct dir for an absolute path
437 * Given a path like "/Volumes/volume/dir/subdir" in a volume "/Volumes/volume" return
438 * a pointer to struct dir of "subdir".
439 * 1. Remove volue path from absolute path
441 * 3. loop through all elements of the remaining path from 1.
442 * 4. we only allow dirs
444 * 6. if not found in the dircache query the CNID database for the DID
445 * 7. and use dirlookup to resolve the DID to a it's struct dir *
447 * @param vol (r) volume the path is in, must be known
448 * @param path (r) absoule path
450 * @returns pointer to struct dir or NULL on error
452 struct dir *dirlookup_bypath(const struct vol *vol, const char *path)
456 struct dir *dir = NULL;
458 bstring rpath = NULL;
459 bstring statpath = NULL;
460 struct bstrList *l = NULL;
466 LOG(log_debug, logtype_afpd, "dirlookup_bypath(\"%s\")", path);
468 if (strcmp(vol->v_path, path) == 0)
471 EC_NULL(rpath = rel_path_in_vol(path, vol->v_path)); /* 1. */
473 LOG(log_debug, logtype_afpd, "dirlookup_bypath: rpath: \"%s\"", cfrombstr(rpath));
475 EC_NULL(statpath = bfromcstr(vol->v_path)); /* 2. */
477 l = bsplit(rpath, '/');
478 for (int i = 0; i < l->qty ; i++) { /* 3. */
480 EC_ZERO(bcatcstr(statpath, "/"));
481 EC_ZERO(bconcat(statpath, l->entry[i]));
483 LOG(log_debug, logtype_afpd, "dirlookup_bypath: statpath: \"%s\"", cfrombstr(statpath));
485 EC_ZERO_LOGSTR(lstat(cfrombstr(statpath), &st),
486 "lstat(rpath: %s, elem: %s): %s: %s",
487 cfrombstr(rpath), cfrombstr(l->entry[i]),
488 cfrombstr(statpath), strerror(errno));
490 if (!(S_ISDIR(st.st_mode))) /* 4. */
493 if ((dir = dircache_search_by_name(vol, /* 5. */
495 cfrombstr(l->entry[i]),
496 blength(l->entry[i]))) == NULL) {
498 if ((cnid = cnid_add(vol->v_cdb, /* 6. */
501 cfrombstr(l->entry[i]),
502 blength(l->entry[i]),
506 if ((dir = dirlookup(vol, cnid)) == NULL) /* 7. */
518 LOG(log_debug, logtype_afpd, "dirlookup_bypath: result: \"%s\"",
519 cfrombstr(dir->d_fullpath));
525 * @brief Resolve a DID
527 * Resolve a DID, allocate a struct dir for it
528 * 1. Check for special CNIDs 0 (invalid), 1 and 2.
529 * 2a. Check if the DID is in the cache.
530 * 2b. Check if it's really a dir because we cache files too.
531 * 3. If it's not in the cache resolve it via the database.
532 * 4. Build complete server-side path to the dir.
533 * 5. Check if it exists and is a directory.
534 * 6. Create the struct dir and populate it.
535 * 7. Add it to the cache.
537 * @param vol (r) pointer to struct vol
538 * @param did (r) DID to resolve
540 * @returns pointer to struct dir
542 struct dir *dirlookup(const struct vol *vol, cnid_t did)
544 static char buffer[12 + MAXPATHLEN + 1];
546 struct dir *ret = NULL, *pdir;
547 bstring fullpath = NULL;
548 char *upath = NULL, *mpath;
551 int buflen = 12 + MAXPATHLEN + 1;
555 LOG(log_debug, logtype_afpd, "dirlookup(did: %u): START", ntohl(did));
557 /* check for did 0, 1 and 2 */
558 if (did == 0 || vol == NULL) { /* 1 */
559 afp_errno = AFPERR_PARAM;
562 } else if (did == DIRDID_ROOT_PARENT) {
563 rootParent.d_vid = vol->v_vid;
566 } else if (did == DIRDID_ROOT) {
571 /* Search the cache */
572 if ((ret = dircache_search_by_did(vol, did)) != NULL) { /* 2a */
573 if (ret->d_flags & DIRF_ISFILE) { /* 2b */
574 afp_errno = AFPERR_BADTYPE;
578 if (lstat(cfrombstr(ret->d_fullpath), &st) != 0) {
579 LOG(log_debug, logtype_afpd, "dirlookup(did: %u, path: \"%s\"): lstat: %s",
580 ntohl(did), cfrombstr(ret->d_fullpath), strerror(errno));
584 /* It's not there anymore, so remove it */
585 LOG(log_debug, logtype_afpd, "dirlookup(did: %u): calling dir_remove", ntohl(did));
586 dir_remove(vol, ret);
587 afp_errno = AFPERR_NOOBJ;
602 utf8 = utf8_encoding();
603 maxpath = (utf8) ? MAXPATHLEN - 7 : 255;
605 /* Get it from the database */
607 LOG(log_debug, logtype_afpd, "dirlookup(did: %u): querying CNID database", ntohl(did));
608 if ((upath = cnid_resolve(vol->v_cdb, &cnid, buffer, buflen)) == NULL) {
609 afp_errno = AFPERR_NOOBJ;
613 if ((upath = strdup(upath)) == NULL) { /* 3 */
614 afp_errno = AFPERR_NOOBJ;
621 * Recurse up the tree, terminates in dirlookup when either
622 * - DIRDID_ROOT is hit
623 * - a cached entry is found
625 LOG(log_debug, logtype_afpd, "dirlookup(did: %u): recursion for did: %u",
626 ntohl(did), ntohl(pdid));
627 if ((pdir = dirlookup(vol, pdid)) == NULL) {
632 /* build the fullpath */
633 if ((fullpath = bstrcpy(pdir->d_fullpath)) == NULL
634 || bconchar(fullpath, '/') != BSTR_OK
635 || bcatcstr(fullpath, upath) != BSTR_OK) {
640 /* stat it and check if it's a dir */
641 LOG(log_debug, logtype_afpd, "dirlookup(did: %u): stating \"%s\"",
642 ntohl(did), cfrombstr(fullpath));
644 if (lstat(cfrombstr(fullpath), &st) != 0) { /* 5a */
647 afp_errno = AFPERR_NOOBJ;
651 afp_errno = AFPERR_ACCESS;
655 afp_errno = AFPERR_MISC;
660 if ( ! S_ISDIR(st.st_mode)) { /* 5b */
661 afp_errno = AFPERR_BADTYPE;
667 /* Get macname from unix name */
668 if ( (mpath = utompath(vol, upath, did, utf8)) == NULL ) {
669 afp_errno = AFPERR_NOOBJ;
674 /* Create struct dir */
675 if ((ret = dir_new(mpath, upath, vol, pdid, did, fullpath, &st)) == NULL) { /* 6 */
676 LOG(log_error, logtype_afpd, "dirlookup(did: %u) {%s, %s}: %s", ntohl(did), mpath, upath, strerror(errno));
681 /* Add it to the cache only if it's a dir */
682 if (dircache_add(vol, ret) != 0) { /* 7 */
688 if (upath) free(upath);
690 LOG(log_debug, logtype_afpd, "dirlookup(did: %u) {exit_error: %s}",
691 ntohl(did), AfpErr2name(afp_errno));
700 LOG(log_debug, logtype_afpd, "dirlookup(did: %u): RESULT: pdid: %u, path: \"%s\"",
701 ntohl(ret->d_did), ntohl(ret->d_pdid), cfrombstr(ret->d_fullpath));
706 #define ENUMVETO "./../Network Trash Folder/TheVolumeSettingsFolder/TheFindByContentFolder/:2eDS_Store/Contents/Desktop Folder/Trash/Benutzer/"
708 int caseenumerate(const struct vol *vol, struct path *path, struct dir *dir)
713 static u_int32_t did = 0;
714 static char cname[MAXPATHLEN];
715 static char lname[MAXPATHLEN];
716 ucs2_t u2_path[MAXPATHLEN];
717 ucs2_t u2_dename[MAXPATHLEN];
718 char *tmp, *savepath;
720 if (!(vol->v_flags & AFPVOL_CASEINSEN))
723 if (veto_file(ENUMVETO, path->u_name))
726 savepath = path->u_name;
728 /* very simple cache */
729 if ( dir->d_did == did && strcmp(lname, path->u_name) == 0) {
730 path->u_name = cname;
732 if (of_stat( path ) == 0 ) {
735 /* something changed, we cannot stat ... */
739 if (NULL == ( dp = opendir( "." )) ) {
740 LOG(log_debug, logtype_afpd, "caseenumerate: opendir failed: %s", dir->d_u_name);
745 /* LOG(log_debug, logtype_afpd, "caseenumerate: for %s", path->u_name); */
746 if ((size_t) -1 == convert_string(vol->v_volcharset, CH_UCS2, path->u_name, -1, u2_path, sizeof(u2_path)) )
747 LOG(log_debug, logtype_afpd, "caseenumerate: conversion failed for %s", path->u_name);
749 /*LOG(log_debug, logtype_afpd, "caseenumerate: dir: %s, path: %s", dir->d_u_name, path->u_name); */
751 for ( de = readdir( dp ); de != NULL; de = readdir( dp )) {
752 if (NULL == check_dirent(vol, de->d_name))
755 if ((size_t) -1 == convert_string(vol->v_volcharset, CH_UCS2, de->d_name, -1, u2_dename, sizeof(u2_dename)) )
758 if (strcasecmp_w( u2_path, u2_dename) == 0) {
760 strlcpy(cname, de->d_name, sizeof(cname));
761 path->u_name = cname;
763 if (of_stat( path ) == 0 ) {
764 LOG(log_debug, logtype_afpd, "caseenumerate: using dir: %s, path: %s", de->d_name, path->u_name);
765 strlcpy(lname, tmp, sizeof(lname));
778 /* invalidate cache */
781 path->u_name = savepath;
783 /* LOG(log_debug, logtype_afpd, "caseenumerate: path on ret: %s", path->u_name); */
789 * @brief Construct struct dir
791 * Construct struct dir from parameters.
793 * @param m_name (r) directory name in UTF8-dec
794 * @param u_name (r) directory name in server side encoding
795 * @param vol (r) pointer to struct vol
796 * @param pdid (r) Parent CNID
797 * @param did (r) CNID
798 * @param path (r) Full unix path to object
799 * @param st (r) struct stat of object
801 * @returns pointer to new struct dir or NULL on error
803 * @note Most of the time mac name and unix name are the same.
805 struct dir *dir_new(const char *m_name,
807 const struct vol *vol,
815 dir = (struct dir *) calloc(1, sizeof( struct dir ));
819 if ((dir->d_m_name = bfromcstr(m_name)) == NULL) {
824 if (convert_string_allocate( (utf8_encoding()) ? CH_UTF8_MAC : vol->v_maccharset,
827 -1, (char **)&dir->d_m_name_ucs2) == (size_t)-1 ) {
828 LOG(log_error, logtype_afpd, "dir_new(did: %u) {%s, %s}: couldn't set UCS2 name", ntohl(did), m_name, u_name);
829 dir->d_m_name_ucs2 = NULL;
832 if (m_name == u_name || !strcmp(m_name, u_name)) {
833 dir->d_u_name = dir->d_m_name;
835 else if ((dir->d_u_name = bfromcstr(u_name)) == NULL) {
836 bdestroy(dir->d_m_name);
843 dir->d_vid = vol->v_vid;
844 dir->d_fullpath = path;
845 dir->dcache_ctime = st->st_ctime;
846 dir->dcache_ino = st->st_ino;
847 if (!S_ISDIR(st->st_mode))
848 dir->d_flags = DIRF_ISFILE;
849 dir->d_rights_cache = 0xffffffff;
854 * @brief Free a struct dir and all its members
856 * @param (rw) pointer to struct dir
858 void dir_free(struct dir *dir)
860 if (dir->d_u_name != dir->d_m_name) {
861 bdestroy(dir->d_u_name);
863 if (dir->d_m_name_ucs2)
864 free(dir->d_m_name_ucs2);
865 bdestroy(dir->d_m_name);
866 bdestroy(dir->d_fullpath);
871 * @brief Create struct dir from struct path
873 * Create a new struct dir from struct path. Then add it to the cache.
875 * 1. Open adouble file, get CNID from it.
876 * 2. Search the database, hinting with the CNID from (1).
877 * 3. Build fullpath and create struct dir.
878 * 4. Add it to the cache.
880 * @param vol (r) pointer to struct vol, possibly modified in callee
881 * @param dir (r) pointer to parrent directory
882 * @param path (rw) pointer to struct path with valid path->u_name
883 * @param len (r) strlen of path->u_name
885 * @returns Pointer to new struct dir or NULL on error.
887 * @note Function also assigns path->m_name from path->u_name.
889 struct dir *dir_add(struct vol *vol, const struct dir *dir, struct path *path, int len)
892 struct dir *cdir = NULL;
895 struct adouble *adp = NULL;
903 if ((cdir = dircache_search_by_name(vol, dir, path->u_name, strlen(path->u_name))) != NULL) {
904 /* there's a stray entry in the dircache */
905 LOG(log_debug, logtype_afpd, "dir_add(did:%u,'%s/%s'): {stray cache entry: did:%u,'%s', removing}",
906 ntohl(dir->d_did), cfrombstr(dir->d_fullpath), path->u_name,
907 ntohl(cdir->d_did), cfrombstr(dir->d_fullpath));
908 if (dir_remove(vol, cdir) != 0) {
910 AFP_PANIC("dir_add");
914 /* get_id needs adp for reading CNID from adouble file */
915 ad_init(&ad, vol->v_adouble, vol->v_ad_options);
916 if ((ad_open_metadata(path->u_name, ADFLAGS_DIR, 0, &ad)) == 0) /* 1 */
920 if ((id = get_id(vol, adp, &path->st, dir->d_did, path->u_name, len)) == 0) { /* 2 */
926 ad_close_metadata(adp);
928 /* Get macname from unixname */
929 if (path->m_name == NULL) {
930 if ((path->m_name = utompath(vol, path->u_name, id, utf8_encoding())) == NULL) {
931 LOG(log_error, logtype_afpd, "dir_add(\"%s\"): can't assign macname", path->u_name);
938 if ( ((fullpath = bstrcpy(dir->d_fullpath)) == NULL) /* 3 */
939 || (bconchar(fullpath, '/') != BSTR_OK)
940 || (bcatcstr(fullpath, path->u_name)) != BSTR_OK) {
941 LOG(log_error, logtype_afpd, "dir_add: fullpath: %s", strerror(errno) );
946 /* Allocate and initialize struct dir */
947 if ((cdir = dir_new(path->m_name,
953 &path->st)) == NULL) { /* 3 */
958 if ((dircache_add(vol, cdir)) != 0) { /* 4 */
959 LOG(log_error, logtype_afpd, "dir_add: fatal dircache error: %s", cfrombstr(fullpath));
965 LOG(log_debug, logtype_afpd, "dir_add('%s/%s'): error: %u",
966 cfrombstr(dir->d_u_name), path->u_name, err);
969 ad_close_metadata(adp);
970 if (!cdir && fullpath)
977 LOG(log_debug, logtype_afpd, "dir_add(did:%u,'%s/%s'): {cached: %u,'%s'}",
978 ntohl(dir->d_did), cfrombstr(dir->d_fullpath), path->u_name,
979 ntohl(cdir->d_did), cfrombstr(cdir->d_fullpath));
986 * Free the queue with invalid struct dirs
988 * This gets called at the end of every AFP func.
990 void dir_free_invalid_q(void)
993 while (dir = (struct dir *)dequeue(invalid_dircache_entries))
998 * @brief Remove a dir from a cache and queue it for freeing
1000 * 1. Check if the dir is locked or has opened forks
1001 * 2. Remove it from the cache
1002 * 3. Queue it for removal
1003 * 4. If it's a request to remove curdir, mark curdir as invalid
1004 * 5. Mark it as invalid
1006 * @param (r) pointer to struct vol
1007 * @param (rw) pointer to struct dir
1009 int dir_remove(const struct vol *vol, struct dir *dir)
1014 if (dir->d_did == DIRDID_ROOT_PARENT || dir->d_did == DIRDID_ROOT)
1017 LOG(log_debug, logtype_afpd, "dir_remove(did:%u,'%s'): {removing}",
1018 ntohl(dir->d_did), cfrombstr(dir->d_u_name));
1020 dircache_remove(vol, dir, DIRCACHE | DIDNAME_INDEX | QUEUE_INDEX); /* 2 */
1021 enqueue(invalid_dircache_entries, dir); /* 3 */
1023 if (curdir == dir) /* 4 */
1026 dir->d_did = CNID_INVALID; /* 5 */
1033 * @brief Modify a struct dir, adjust cache
1035 * Any value that is 0 or NULL is not changed. If new_uname is NULL it is set to new_mname.
1036 * If given new_uname == new_mname, new_uname will point to new_mname.
1038 * @param vol (r) pointer to struct vol
1039 * @param dir (rw) pointer to struct dir
1040 * @param pdid (r) new parent DID
1041 * @param did (r) new DID
1042 * @param new_mname (r) new mac-name
1043 * @param new_uname (r) new unix-name
1044 * @param pdir_fullpath (r) new fullpath of parent dir
1046 int dir_modify(const struct vol *vol,
1050 const char *new_mname,
1051 const char *new_uname,
1052 bstring pdir_fullpath)
1056 /* Remove it from the cache */
1057 dircache_remove(vol, dir, DIRCACHE | DIDNAME_INDEX | QUEUE_INDEX);
1065 /* free uname if it's not the same as mname */
1066 if (dir->d_m_name != dir->d_u_name)
1067 bdestroy(dir->d_u_name);
1069 if (new_uname == NULL)
1070 new_uname = new_mname;
1072 /* assign new name */
1073 if ((bassigncstr(dir->d_m_name, new_mname)) != BSTR_OK) {
1074 LOG(log_error, logtype_afpd, "dir_modify: bassigncstr: %s", strerror(errno) );
1078 if (new_mname == new_uname || (strcmp(new_mname, new_uname) == 0)) {
1079 dir->d_u_name = dir->d_m_name;
1081 if ((dir->d_u_name = bfromcstr(new_uname)) == NULL) {
1082 LOG(log_error, logtype_afpd, "dir_modify: bassigncstr: %s", strerror(errno) );
1088 if (pdir_fullpath) {
1089 if (bassign(dir->d_fullpath, pdir_fullpath) != BSTR_OK)
1091 if (bcatcstr(dir->d_fullpath, "/") != BSTR_OK)
1093 if (bcatcstr(dir->d_fullpath, new_uname) != BSTR_OK)
1097 if (dir->d_m_name_ucs2)
1098 free(dir->d_m_name_ucs2);
1099 if ((size_t)-1 == convert_string_allocate((utf8_encoding())?CH_UTF8_MAC:vol->v_maccharset, CH_UCS2, dir->d_m_name, -1, (char**)&dir->d_m_name_ucs2))
1100 dir->d_m_name_ucs2 = NULL;
1102 /* Re-add it to the cache */
1103 if ((dircache_add(vol, dir)) != 0) {
1105 AFP_PANIC("dir_modify");
1113 * @brief Resolve a catalog node name path
1115 * 1. Evaluate path type
1116 * 2. Move to start dir, if we cant, it might eg because of EACCES, build
1117 * path from dirname, so eg getdirparams has sth it can chew on. curdir
1118 * is dir parent then. All this is done in path_from_dir().
1119 * 3. Parse next cnode name in path, cases:
1120 * 4. single "\0" -> do nothing
1121 * 5. two or more consecutive "\0" -> chdir("..") one or more times
1122 * 6. cnode name -> copy it to path.m_name
1123 * 7. Get unix name from mac name
1124 * 8. Special handling of request with did 1
1125 * 9. stat the cnode name
1126 * 10. If it's not there, it's probably an afp_createfile|dir,
1127 * return with curdir = dir parent, struct path = dirname
1128 * 11. If it's there and it's a file, it must should be the last element of the requested
1129 * path. Return with curdir = cnode name parent dir, struct path = filename
1130 * 12. Treat symlinks like files, dont follow them
1131 * 13. If it's a dir:
1132 * 14. Search the dircache for it
1133 * 15. If it's not in the cache, create a struct dir for it and add it to the cache
1134 * 16. chdir into the dir and
1135 * 17. set m_name to the mac equivalent of "."
1138 struct path *cname(struct vol *vol, struct dir *dir, char **cpath)
1140 static char path[ MAXPATHLEN + 1];
1141 static struct path ret;
1151 LOG(log_maxdebug, logtype_afpd, "came('%s'): {start}", cfrombstr(dir->d_fullpath));
1154 afp_errno = AFPERR_NOOBJ;
1155 memset(&ret, 0, sizeof(ret));
1157 switch (ret.m_type = *data) { /* 1 */
1160 len = (unsigned char) *data++;
1162 if (afp_version >= 30) {
1168 if (afp_version >= 30) {
1170 memcpy(&hint, data, sizeof(hint));
1172 data += sizeof(hint);
1174 memcpy(&len16, data, sizeof(len16));
1180 /* else it's an error */
1182 afp_errno = AFPERR_PARAM;
1185 *cpath += len + size;
1190 if (movecwd(vol, dir) < 0 ) {
1191 LOG(log_debug, logtype_afpd, "cname(did:%u): failed to chdir to '%s'",
1192 ntohl(dir->d_did), cfrombstr(dir->d_fullpath));
1194 return path_from_dir(vol, dir, &ret);
1199 while (len) { /* 3 */
1200 if (*data == 0) { /* 4 or 5 */
1203 while (len > 0 && *data == 0) { /* 5 */
1204 /* chdir to parrent dir */
1205 if ((dir = dirlookup(vol, dir->d_pdid)) == NULL)
1207 if (movecwd( vol, dir ) < 0 ) {
1208 dir_remove(vol, dir);
1218 for ( p = path; *data != 0 && len > 0; len-- ) {
1220 if (p > &path[UTF8FILELEN_EARLY]) { /* FIXME safeguard, limit of early Mac OS X */
1221 afp_errno = AFPERR_PARAM;
1225 *p = 0; /* Terminate string */
1228 if (cname_mtouname(vol, dir, &ret, toUTF8) != 0) { /* 7 */
1229 LOG(log_error, logtype_afpd, "cname('%s'): error from cname_mtouname", path);
1233 LOG(log_maxdebug, logtype_afpd, "came('%s'): {node: '%s}", cfrombstr(dir->d_fullpath), ret.u_name);
1235 /* Prevent access to our special folders like .AppleDouble */
1236 if (check_name(vol, ret.u_name)) {
1237 /* the name is illegal */
1238 LOG(log_info, logtype_afpd, "cname: illegal path: '%s'", ret.u_name);
1239 afp_errno = AFPERR_PARAM;
1243 if (dir->d_did == DIRDID_ROOT_PARENT) { /* 8 */
1245 * Special case: CNID 1
1246 * root parent (did 1) has one child: the volume. Requests for did=1 with
1247 * some <name> must check against the volume name.
1249 if ((strcmp(cfrombstr(vol->v_root->d_m_name), ret.m_name)) == 0)
1255 * CNID != 1, eg. most of the times we take this way.
1256 * Now check if current path-part is a file or dir:
1257 * o if it's dir we have to step into it
1258 * o if it's a file we expect it to be the last part of the requested path
1259 * and thus call continue which should terminate the while loop because
1262 if (of_stat(&ret) != 0) { /* 9 */
1264 * ret.u_name doesn't exist, might be afp_createfile|dir
1265 * that means it should have been the last part
1268 /* it wasn't the last part, so we have a bogus path request */
1269 afp_errno = AFPERR_NOOBJ;
1273 * this will terminate clean in while (1) because len == 0,
1274 * probably afp_createfile|dir
1276 LOG(log_maxdebug, logtype_afpd, "came('%s'): {leave-cnode ENOENT (possile create request): '%s'}",
1277 cfrombstr(dir->d_fullpath), ret.u_name);
1281 switch (ret.st.st_mode & S_IFMT) {
1282 case S_IFREG: /* 11 */
1283 LOG(log_debug, logtype_afpd, "came('%s'): {file: '%s'}",
1284 cfrombstr(dir->d_fullpath), ret.u_name);
1286 /* it wasn't the last part, so we have a bogus path request */
1287 afp_errno = AFPERR_PARAM;
1290 continue; /* continues while loop */
1291 case S_IFLNK: /* 12 */
1292 LOG(log_debug, logtype_afpd, "came('%s'): {link: '%s'}",
1293 cfrombstr(dir->d_fullpath), ret.u_name);
1295 LOG(log_warning, logtype_afpd, "came('%s'): {symlinked dir: '%s'}",
1296 cfrombstr(dir->d_fullpath), ret.u_name);
1297 afp_errno = AFPERR_PARAM;
1300 continue; /* continues while loop */
1301 case S_IFDIR: /* 13 */
1304 LOG(log_info, logtype_afpd, "cname: special file: '%s'", ret.u_name);
1305 afp_errno = AFPERR_NODIR;
1309 /* Search the cache */
1310 int unamelen = strlen(ret.u_name);
1311 cdir = dircache_search_by_name(vol, dir, ret.u_name, unamelen); /* 14 */
1313 /* Not in cache, create one */
1314 if ((cdir = dir_add(vol, dir, &ret, unamelen)) == NULL) { /* 15 */
1315 LOG(log_error, logtype_afpd, "cname(did:%u, name:'%s', cwd:'%s'): failed to add dir",
1316 ntohl(dir->d_did), ret.u_name, getcwdpath());
1320 } /* if/else cnid==1 */
1322 /* Now chdir to the evaluated dir */
1323 if (movecwd( vol, cdir ) < 0 ) { /* 16 */
1324 LOG(log_debug, logtype_afpd, "cname(cwd:'%s'): failed to chdir to new subdir '%s': %s",
1325 cfrombstr(curdir->d_fullpath), cfrombstr(cdir->d_fullpath), strerror(errno));
1327 return path_from_dir(vol, cdir, &ret);
1332 ret.m_name[0] = 0; /* 17, so we later know last token was a dir */
1335 if (curdir->d_did == DIRDID_ROOT_PARENT) {
1336 afp_errno = AFPERR_DID1;
1340 if (ret.m_name[0] == 0) {
1341 /* Last part was a dir */
1342 ret.u_name = mtoupath(vol, ret.m_name, 0, 1); /* Force "." into a useable static buffer */
1346 LOG(log_debug, logtype_afpd, "came('%s') {end: curdir:'%s', path:'%s'}",
1347 cfrombstr(dir->d_fullpath),
1348 cfrombstr(curdir->d_fullpath),
1355 * @brief chdir() to dir
1357 * @param vol (r) pointer to struct vol
1358 * @param dir (r) pointer to struct dir
1360 * @returns 0 on success, -1 on error with afp_errno set appropiately
1362 int movecwd(const struct vol *vol, struct dir *dir)
1369 LOG(log_maxdebug, logtype_afpd, "movecwd: from: curdir:\"%s\", cwd:\"%s\"",
1370 curdir ? cfrombstr(curdir->d_fullpath) : "INVALID", getcwdpath());
1372 if (dir->d_did == DIRDID_ROOT_PARENT) {
1373 curdir = &rootParent;
1377 LOG(log_debug, logtype_afpd, "movecwd(to: did: %u, \"%s\")",
1378 ntohl(dir->d_did), cfrombstr(dir->d_fullpath));
1380 if ((ret = lchdir(cfrombstr(dir->d_fullpath))) != 0 ) {
1381 LOG(log_debug, logtype_afpd, "movecwd(\"%s\"): %s",
1382 cfrombstr(dir->d_fullpath), strerror(errno));
1384 /* p is a symlink or getcwd failed */
1385 afp_errno = AFPERR_BADTYPE;
1387 if (chdir(vol->v_path ) < 0) {
1388 LOG(log_error, logtype_afpd, "can't chdir back'%s': %s", vol->v_path, strerror(errno));
1389 /* XXX what do we do here? */
1391 curdir = vol->v_root;
1398 afp_errno = AFPERR_ACCESS;
1401 afp_errno = AFPERR_NOOBJ;
1411 * We can't use unix file's perm to support Apple's inherited protection modes.
1412 * If we aren't the file's owner we can't change its perms when moving it and smb
1413 * nfs,... don't even try.
1415 #define AFP_CHECK_ACCESS
1417 int check_access(char *path, int mode)
1419 #ifdef AFP_CHECK_ACCESS
1427 accessmode(current_vol, p, &ma, curdir, NULL);
1428 if ((mode & OPENACC_WR) && !(ma.ma_user & AR_UWRITE))
1430 if ((mode & OPENACC_RD) && !(ma.ma_user & AR_UREAD))
1436 /* --------------------- */
1437 int file_access(struct path *path, int mode)
1441 accessmode(current_vol, path->u_name, &ma, curdir, &path->st);
1443 LOG(log_debug, logtype_afpd, "file_access(\"%s\"): mapped user mode: 0x%02x",
1444 path->u_name, ma.ma_user);
1446 if ((mode & OPENACC_WR) && !(ma.ma_user & AR_UWRITE)) {
1447 LOG(log_debug, logtype_afpd, "file_access(\"%s\"): write access denied", path->u_name);
1450 if ((mode & OPENACC_RD) && !(ma.ma_user & AR_UREAD)) {
1451 LOG(log_debug, logtype_afpd, "file_access(\"%s\"): read access denied", path->u_name);
1458 /* --------------------- */
1459 void setdiroffcnt(struct dir *dir, struct stat *st, u_int32_t count)
1461 dir->d_offcnt = count;
1462 dir->d_ctime = st->st_ctime;
1463 dir->d_flags &= ~DIRF_CNID;
1467 /* ---------------------
1468 * is our cached also for reenumerate id?
1470 int dirreenumerate(struct dir *dir, struct stat *st)
1472 return st->st_ctime == dir->d_ctime && (dir->d_flags & DIRF_CNID);
1475 /* ------------------------------
1477 (name, dir) with curdir:name == dir, from afp_enumerate
1480 int getdirparams(const struct vol *vol,
1481 u_int16_t bitmap, struct path *s_path,
1483 char *buf, size_t *buflen )
1487 char *data, *l_nameoff = NULL, *utf_nameoff = NULL;
1488 int bit = 0, isad = 0;
1494 struct stat *st = &s_path->st;
1495 char *upath = s_path->u_name;
1497 if ((bitmap & ((1 << DIRPBIT_ATTR) |
1498 (1 << DIRPBIT_CDATE) |
1499 (1 << DIRPBIT_MDATE) |
1500 (1 << DIRPBIT_BDATE) |
1501 (1 << DIRPBIT_FINFO)))) {
1503 ad_init(&ad, vol->v_adouble, vol->v_ad_options);
1504 if ( !ad_metadata( upath, ADFLAGS_CREATE|ADFLAGS_DIR, &ad) ) {
1506 if (ad.ad_md->adf_flags & O_CREAT) {
1507 /* We just created it */
1508 if (s_path->m_name == NULL) {
1509 if ((s_path->m_name = utompath(vol,
1512 utf8_encoding())) == NULL) {
1513 LOG(log_error, logtype_afpd,
1514 "getdirparams(\"%s\"): can't assign macname",
1515 cfrombstr(dir->d_fullpath));
1519 ad_setname(&ad, s_path->m_name);
1534 while ( bitmap != 0 ) {
1535 while (( bitmap & 1 ) == 0 ) {
1543 ad_getattr(&ad, &ashort);
1544 } else if (invisible_dots(vol, cfrombstr(dir->d_u_name))) {
1545 ashort = htons(ATTRBIT_INVISIBLE);
1548 memcpy( data, &ashort, sizeof( ashort ));
1549 data += sizeof( ashort );
1553 memcpy( data, &pdid, sizeof( pdid ));
1554 data += sizeof( pdid );
1555 LOG(log_debug, logtype_afpd, "metadata('%s'): Parent DID: %u",
1556 s_path->u_name, ntohl(pdid));
1559 case DIRPBIT_CDATE :
1560 if (!isad || (ad_getdate(&ad, AD_DATE_CREATE, &aint) < 0))
1561 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1562 memcpy( data, &aint, sizeof( aint ));
1563 data += sizeof( aint );
1566 case DIRPBIT_MDATE :
1567 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1568 memcpy( data, &aint, sizeof( aint ));
1569 data += sizeof( aint );
1572 case DIRPBIT_BDATE :
1573 if (!isad || (ad_getdate(&ad, AD_DATE_BACKUP, &aint) < 0))
1574 aint = AD_DATE_START;
1575 memcpy( data, &aint, sizeof( aint ));
1576 data += sizeof( aint );
1579 case DIRPBIT_FINFO :
1581 memcpy( data, ad_entry( &ad, ADEID_FINDERI ), 32 );
1582 } else { /* no appledouble */
1583 memset( data, 0, 32 );
1584 /* set default view -- this also gets done in ad_open() */
1585 ashort = htons(FINDERINFO_CLOSEDVIEW);
1586 memcpy(data + FINDERINFO_FRVIEWOFF, &ashort, sizeof(ashort));
1588 /* dot files are by default visible */
1589 if (invisible_dots(vol, cfrombstr(dir->d_u_name))) {
1590 ashort = htons(FINDERINFO_INVISIBLE);
1591 memcpy(data + FINDERINFO_FRFLAGOFF, &ashort, sizeof(ashort));
1597 case DIRPBIT_LNAME :
1598 if (dir->d_m_name) /* root of parent can have a null name */
1601 memset(data, 0, sizeof(u_int16_t));
1602 data += sizeof( u_int16_t );
1605 case DIRPBIT_SNAME :
1606 memset(data, 0, sizeof(u_int16_t));
1607 data += sizeof( u_int16_t );
1611 memcpy( data, &dir->d_did, sizeof( aint ));
1612 data += sizeof( aint );
1613 LOG(log_debug, logtype_afpd, "metadata('%s'): DID: %u",
1614 s_path->u_name, ntohl(dir->d_did));
1617 case DIRPBIT_OFFCNT :
1619 /* this needs to handle current directory access rights */
1620 if (diroffcnt(dir, st)) {
1621 ashort = (dir->d_offcnt > 0xffff)?0xffff:dir->d_offcnt;
1623 else if ((ret = for_each_dirent(vol, upath, NULL,NULL)) >= 0) {
1624 setdiroffcnt(dir, st, ret);
1625 ashort = (dir->d_offcnt > 0xffff)?0xffff:dir->d_offcnt;
1627 ashort = htons( ashort );
1628 memcpy( data, &ashort, sizeof( ashort ));
1629 data += sizeof( ashort );
1633 aint = htonl(st->st_uid);
1634 memcpy( data, &aint, sizeof( aint ));
1635 data += sizeof( aint );
1639 aint = htonl(st->st_gid);
1640 memcpy( data, &aint, sizeof( aint ));
1641 data += sizeof( aint );
1644 case DIRPBIT_ACCESS :
1645 accessmode(vol, upath, &ma, dir , st);
1647 *data++ = ma.ma_user;
1648 *data++ = ma.ma_world;
1649 *data++ = ma.ma_group;
1650 *data++ = ma.ma_owner;
1653 /* Client has requested the ProDOS information block.
1654 Just pass back the same basic block for all
1655 directories. <shirsch@ibm.net> */
1656 case DIRPBIT_PDINFO :
1657 if (afp_version >= 30) { /* UTF8 name */
1658 utf8 = kTextEncodingUTF8;
1659 if (dir->d_m_name) /* root of parent can have a null name */
1662 memset(data, 0, sizeof(u_int16_t));
1663 data += sizeof( u_int16_t );
1665 memcpy(data, &aint, sizeof( aint ));
1666 data += sizeof( aint );
1668 else { /* ProDOS Info Block */
1671 ashort = htons( 0x0200 );
1672 memcpy( data, &ashort, sizeof( ashort ));
1673 data += sizeof( ashort );
1674 memset( data, 0, sizeof( ashort ));
1675 data += sizeof( ashort );
1679 case DIRPBIT_UNIXPR :
1680 /* accessmode may change st_mode with ACLs */
1681 accessmode(vol, upath, &ma, dir, st);
1683 aint = htonl(st->st_uid);
1684 memcpy( data, &aint, sizeof( aint ));
1685 data += sizeof( aint );
1686 aint = htonl(st->st_gid);
1687 memcpy( data, &aint, sizeof( aint ));
1688 data += sizeof( aint );
1691 aint = htonl ( aint & ~S_ISGID ); /* Remove SGID, OSX doesn't like it ... */
1692 memcpy( data, &aint, sizeof( aint ));
1693 data += sizeof( aint );
1695 *data++ = ma.ma_user;
1696 *data++ = ma.ma_world;
1697 *data++ = ma.ma_group;
1698 *data++ = ma.ma_owner;
1703 ad_close_metadata( &ad );
1705 return( AFPERR_BITMAP );
1711 ashort = htons( data - buf );
1712 memcpy( l_nameoff, &ashort, sizeof( ashort ));
1713 data = set_name(vol, data, pdid, cfrombstr(dir->d_m_name), dir->d_did, 0);
1715 if ( utf_nameoff ) {
1716 ashort = htons( data - buf );
1717 memcpy( utf_nameoff, &ashort, sizeof( ashort ));
1718 data = set_name(vol, data, pdid, cfrombstr(dir->d_m_name), dir->d_did, utf8);
1721 ad_close_metadata( &ad );
1723 *buflen = data - buf;
1727 /* ----------------------------- */
1728 int path_error(struct path *path, int error)
1730 /* - a dir with access error
1731 * - no error it's a file
1734 if (path_isadir(path))
1736 if (path->st_valid && path->st_errno)
1738 return AFPERR_BADTYPE ;
1741 /* ----------------------------- */
1742 int afp_setdirparams(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
1747 u_int16_t vid, bitmap;
1753 memcpy( &vid, ibuf, sizeof( vid ));
1754 ibuf += sizeof( vid );
1756 if (NULL == ( vol = getvolbyvid( vid )) ) {
1757 return( AFPERR_PARAM );
1760 if (vol->v_flags & AFPVOL_RO)
1761 return AFPERR_VLOCK;
1763 memcpy( &did, ibuf, sizeof( did ));
1764 ibuf += sizeof( int );
1766 if (NULL == ( dir = dirlookup( vol, did )) ) {
1770 memcpy( &bitmap, ibuf, sizeof( bitmap ));
1771 bitmap = ntohs( bitmap );
1772 ibuf += sizeof( bitmap );
1774 if (NULL == ( path = cname( vol, dir, &ibuf )) ) {
1775 return get_afp_errno(AFPERR_NOOBJ);
1778 if ( *path->m_name != '\0' ) {
1779 rc = path_error(path, AFPERR_NOOBJ);
1780 /* maybe we are trying to set perms back */
1781 if (rc != AFPERR_ACCESS)
1786 * If ibuf is odd, make it even.
1788 if ((u_long)ibuf & 1 ) {
1792 if (AFP_OK == ( rc = setdirparams(vol, path, bitmap, ibuf )) ) {
1793 setvoltime(obj, vol );
1799 * cf AFP3.0.pdf page 244 for change_mdate and change_parent_mdate logic
1801 * assume path == '\0' eg. it's a directory in canonical form
1803 int setdirparams(struct vol *vol, struct path *path, u_int16_t d_bitmap, char *buf )
1815 u_int16_t ashort, bshort, oshort;
1817 int change_mdate = 0;
1818 int change_parent_mdate = 0;
1820 u_int16_t bitmap = d_bitmap;
1821 u_char finder_buf[32];
1824 u_int16_t upriv_bit = 0;
1827 upath = path->u_name;
1829 while ( bitmap != 0 ) {
1830 while (( bitmap & 1 ) == 0 ) {
1838 memcpy( &ashort, buf, sizeof( ashort ));
1839 buf += sizeof( ashort );
1841 case DIRPBIT_CDATE :
1843 memcpy(&cdate, buf, sizeof(cdate));
1844 buf += sizeof( cdate );
1846 case DIRPBIT_MDATE :
1847 memcpy(&newdate, buf, sizeof(newdate));
1848 buf += sizeof( newdate );
1850 case DIRPBIT_BDATE :
1852 memcpy(&bdate, buf, sizeof(bdate));
1853 buf += sizeof( bdate );
1855 case DIRPBIT_FINFO :
1857 memcpy( finder_buf, buf, 32 );
1860 case DIRPBIT_UID : /* What kind of loser mounts as root? */
1861 change_parent_mdate = 1;
1862 memcpy( &owner, buf, sizeof(owner));
1863 buf += sizeof( owner );
1866 change_parent_mdate = 1;
1867 memcpy( &group, buf, sizeof( group ));
1868 buf += sizeof( group );
1870 case DIRPBIT_ACCESS :
1872 change_parent_mdate = 1;
1873 ma.ma_user = *buf++;
1874 ma.ma_world = *buf++;
1875 ma.ma_group = *buf++;
1876 ma.ma_owner = *buf++;
1877 mpriv = mtoumode( &ma ) | vol->v_dperm;
1878 if (dir_rx_set(mpriv) && setdirmode( vol, upath, mpriv) < 0 ) {
1879 err = set_dir_errors(path, "setdirmode", errno);
1883 /* Ignore what the client thinks we should do to the
1884 ProDOS information block. Skip over the data and
1885 report nothing amiss. <shirsch@ibm.net> */
1886 case DIRPBIT_PDINFO :
1887 if (afp_version < 30) {
1891 err = AFPERR_BITMAP;
1895 case DIRPBIT_UNIXPR :
1896 if (vol_unix_priv(vol)) {
1897 memcpy( &owner, buf, sizeof(owner)); /* FIXME need to change owner too? */
1898 buf += sizeof( owner );
1899 memcpy( &group, buf, sizeof( group ));
1900 buf += sizeof( group );
1903 change_parent_mdate = 1;
1904 memcpy( &upriv, buf, sizeof( upriv ));
1905 buf += sizeof( upriv );
1906 upriv = ntohl (upriv) | vol->v_dperm;
1907 if (dir_rx_set(upriv)) {
1908 /* maybe we are trying to set perms back */
1909 if ( setdirunixmode(vol, upath, upriv) < 0 ) {
1911 err = set_dir_errors(path, "setdirunixmode", errno);
1922 err = AFPERR_BITMAP;
1930 ad_init(&ad, vol->v_adouble, vol->v_ad_options);
1932 if (ad_open_metadata( upath, ADFLAGS_DIR, O_CREAT, &ad) < 0) {
1934 * Check to see what we're trying to set. If it's anything
1935 * but ACCESS, UID, or GID, give an error. If it's any of those
1936 * three, we don't need the ad to be open, so just continue.
1938 * note: we also don't need to worry about mdate. also, be quiet
1939 * if we're using the noadouble option.
1941 if (!vol_noadouble(vol) && (d_bitmap &
1942 ~((1<<DIRPBIT_ACCESS)|(1<<DIRPBIT_UNIXPR)|
1943 (1<<DIRPBIT_UID)|(1<<DIRPBIT_GID)|
1944 (1<<DIRPBIT_MDATE)|(1<<DIRPBIT_PDINFO)))) {
1945 return AFPERR_ACCESS;
1951 * Check to see if a create was necessary. If it was, we'll want
1952 * to set our name, etc.
1954 if ( (ad_get_HF_flags( &ad ) & O_CREAT)) {
1955 ad_setname(&ad, cfrombstr(curdir->d_m_name));
1961 while ( bitmap != 0 ) {
1962 while (( bitmap & 1 ) == 0 ) {
1970 ad_getattr(&ad, &bshort);
1972 if ( ntohs( ashort ) & ATTRBIT_SETCLR ) {
1973 bshort |= htons( ntohs( ashort ) & ~ATTRBIT_SETCLR );
1977 if ((bshort & htons(ATTRBIT_INVISIBLE)) != (oshort & htons(ATTRBIT_INVISIBLE)))
1978 change_parent_mdate = 1;
1979 ad_setattr(&ad, bshort);
1982 case DIRPBIT_CDATE :
1984 ad_setdate(&ad, AD_DATE_CREATE, cdate);
1987 case DIRPBIT_MDATE :
1989 case DIRPBIT_BDATE :
1991 ad_setdate(&ad, AD_DATE_BACKUP, bdate);
1994 case DIRPBIT_FINFO :
1996 /* Fixes #2802236 */
1997 u_int16_t *fflags = (u_int16_t *)(finder_buf + FINDERINFO_FRFLAGOFF);
1998 *fflags &= htons(~FINDERINFO_ISHARED);
2000 if ( dir->d_did == DIRDID_ROOT ) {
2002 * Alright, we admit it, this is *really* sick!
2003 * The 4 bytes that we don't copy, when we're dealing
2004 * with the root of a volume, are the directory's
2005 * location information. This eliminates that annoying
2006 * behavior one sees when mounting above another mount
2009 memcpy( ad_entry( &ad, ADEID_FINDERI ), finder_buf, 10 );
2010 memcpy( ad_entry( &ad, ADEID_FINDERI ) + 14, finder_buf + 14, 18 );
2012 memcpy( ad_entry( &ad, ADEID_FINDERI ), finder_buf, 32 );
2016 case DIRPBIT_UID : /* What kind of loser mounts as root? */
2017 if ( (dir->d_did == DIRDID_ROOT) &&
2018 (setdeskowner( ntohl(owner), -1 ) < 0)) {
2019 err = set_dir_errors(path, "setdeskowner", errno);
2020 if (isad && err == AFPERR_PARAM) {
2021 err = AFP_OK; /* ???*/
2024 goto setdirparam_done;
2027 if ( setdirowner(vol, upath, ntohl(owner), -1 ) < 0 ) {
2028 err = set_dir_errors(path, "setdirowner", errno);
2029 goto setdirparam_done;
2033 if (dir->d_did == DIRDID_ROOT)
2034 setdeskowner( -1, ntohl(group) );
2035 if ( setdirowner(vol, upath, -1, ntohl(group) ) < 0 ) {
2036 err = set_dir_errors(path, "setdirowner", errno);
2037 goto setdirparam_done;
2040 case DIRPBIT_ACCESS :
2041 if (dir->d_did == DIRDID_ROOT) {
2043 if (!dir_rx_set(mpriv)) {
2044 /* we can't remove read and search for owner on volume root */
2045 err = AFPERR_ACCESS;
2046 goto setdirparam_done;
2050 if (!dir_rx_set(mpriv) && setdirmode( vol, upath, mpriv) < 0 ) {
2051 err = set_dir_errors(path, "setdirmode", errno);
2052 goto setdirparam_done;
2055 case DIRPBIT_PDINFO :
2056 if (afp_version >= 30) {
2057 err = AFPERR_BITMAP;
2058 goto setdirparam_done;
2061 case DIRPBIT_UNIXPR :
2062 if (vol_unix_priv(vol)) {
2063 if (dir->d_did == DIRDID_ROOT) {
2064 if (!dir_rx_set(upriv)) {
2065 /* we can't remove read and search for owner on volume root */
2066 err = AFPERR_ACCESS;
2067 goto setdirparam_done;
2069 setdeskowner( -1, ntohl(group) );
2070 setdeskmode( upriv );
2072 if ( setdirowner(vol, upath, -1, ntohl(group) ) < 0 ) {
2073 err = set_dir_errors(path, "setdirowner", errno);
2074 goto setdirparam_done;
2077 if ( upriv_bit && setdirunixmode(vol, upath, upriv) < 0 ) {
2078 err = set_dir_errors(path, "setdirunixmode", errno);
2079 goto setdirparam_done;
2083 err = AFPERR_BITMAP;
2084 goto setdirparam_done;
2088 err = AFPERR_BITMAP;
2089 goto setdirparam_done;
2098 if (change_mdate && newdate == 0 && gettimeofday(&tv, NULL) == 0) {
2099 newdate = AD_DATE_FROM_UNIX(tv.tv_sec);
2103 ad_setdate(&ad, AD_DATE_MODIFY, newdate);
2104 ut.actime = ut.modtime = AD_DATE_TO_UNIX(newdate);
2109 if (path->st_valid && !path->st_errno) {
2110 struct stat *st = &path->st;
2112 if (dir && dir->d_pdid) {
2113 ad_setid(&ad, st->st_dev, st->st_ino, dir->d_did, dir->d_pdid, vol->v_stamp);
2117 ad_close_metadata( &ad);
2120 if (change_parent_mdate && dir->d_did != DIRDID_ROOT
2121 && gettimeofday(&tv, NULL) == 0) {
2122 if (movecwd(vol, dirlookup(vol, dir->d_pdid)) == 0) {
2123 newdate = AD_DATE_FROM_UNIX(tv.tv_sec);
2124 /* be careful with bitmap because now dir is null */
2125 bitmap = 1<<DIRPBIT_MDATE;
2126 setdirparams(vol, &Cur_Path, bitmap, (char *)&newdate);
2127 /* should we reset curdir ?*/
2134 int afp_syncdir(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
2148 memcpy( &vid, ibuf, sizeof( vid ));
2149 ibuf += sizeof( vid );
2150 if (NULL == (vol = getvolbyvid( vid )) ) {
2151 return( AFPERR_PARAM );
2154 memcpy( &did, ibuf, sizeof( did ));
2155 ibuf += sizeof( did );
2159 * if it's CNID 2 our only choice to meet the specs is call sync.
2160 * For any other CNID just sync that dir. To my knowledge the
2161 * intended use of FPSyncDir is to sync the volume so all we're
2162 * ever going to see here is probably CNID 2. Anyway, we' prepared.
2165 if ( ntohl(did) == 2 ) {
2168 if (NULL == ( dir = dirlookup( vol, did )) ) {
2169 return afp_errno; /* was AFPERR_NOOBJ */
2172 if (movecwd( vol, dir ) < 0 )
2173 return ( AFPERR_NOOBJ );
2176 * Assuming only OSens that have dirfd also may require fsyncing directories
2177 * in order to flush metadata e.g. Linux.
2181 if (NULL == ( dp = opendir( "." )) ) {
2184 return( AFPERR_NOOBJ );
2186 return( AFPERR_ACCESS );
2188 return( AFPERR_PARAM );
2192 LOG(log_debug, logtype_afpd, "afp_syncdir: dir: '%s'", dir->d_u_name);
2195 if ( fsync ( dfd ) < 0 )
2196 LOG(log_error, logtype_afpd, "afp_syncdir(%s): %s",
2197 dir->d_u_name, strerror(errno) );
2198 closedir(dp); /* closes dfd too */
2201 if ( -1 == (dfd = open(vol->ad_path(".", ADFLAGS_DIR), O_RDWR))) {
2204 return( AFPERR_NOOBJ );
2206 return( AFPERR_ACCESS );
2208 return( AFPERR_PARAM );
2212 LOG(log_debug, logtype_afpd, "afp_syncdir: ad-file: '%s'",
2213 vol->ad_path(".", ADFLAGS_DIR) );
2215 if ( fsync(dfd) < 0 )
2216 LOG(log_error, logtype_afpd, "afp_syncdir(%s): %s",
2217 vol->ad_path(cfrombstr(dir->d_u_name), ADFLAGS_DIR), strerror(errno) );
2224 int afp_createdir(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
2230 struct path *s_path;
2238 memcpy( &vid, ibuf, sizeof( vid ));
2239 ibuf += sizeof( vid );
2240 if (NULL == ( vol = getvolbyvid( vid )) ) {
2241 return( AFPERR_PARAM );
2244 if (vol->v_flags & AFPVOL_RO)
2245 return AFPERR_VLOCK;
2247 memcpy( &did, ibuf, sizeof( did ));
2248 ibuf += sizeof( did );
2249 if (NULL == ( dir = dirlookup( vol, did )) ) {
2250 return afp_errno; /* was AFPERR_NOOBJ */
2252 /* for concurrent access we need to be sure we are not in the
2253 * folder we want to create...
2257 if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
2258 return get_afp_errno(AFPERR_PARAM);
2260 /* cname was able to move curdir to it! */
2261 if (*s_path->m_name == '\0')
2262 return AFPERR_EXIST;
2264 upath = s_path->u_name;
2266 if (AFP_OK != (err = netatalk_mkdir(vol, upath))) {
2270 if (of_stat(s_path) < 0) {
2276 if ((dir = dir_add(vol, curdir, s_path, strlen(s_path->u_name))) == NULL) {
2280 if ( movecwd( vol, dir ) < 0 ) {
2281 return( AFPERR_PARAM );
2284 ad_init(&ad, vol->v_adouble, vol->v_ad_options);
2285 if (ad_open_metadata( ".", ADFLAGS_DIR, O_CREAT, &ad ) < 0) {
2286 if (vol_noadouble(vol))
2287 goto createdir_done;
2288 return( AFPERR_ACCESS );
2290 ad_setname(&ad, s_path->m_name);
2291 ad_setid( &ad, s_path->st.st_dev, s_path->st.st_ino, dir->d_did, did, vol->v_stamp);
2293 fce_register_new_dir(s_path);
2296 ad_close_metadata( &ad);
2299 memcpy( rbuf, &dir->d_did, sizeof( u_int32_t ));
2300 *rbuflen = sizeof( u_int32_t );
2301 setvoltime(obj, vol );
2306 * dst new unix filename (not a pathname)
2307 * newname new mac name
2309 * dirfd -1 means ignore dirfd (or use AT_FDCWD), otherwise src is relative to dirfd
2311 int renamedir(const struct vol *vol,
2316 struct dir *newparent,
2322 /* existence check moved to afp_moveandrename */
2323 if ( unix_rename(dirfd, src, -1, dst ) < 0 ) {
2326 return( AFPERR_NOOBJ );
2328 return( AFPERR_ACCESS );
2330 return AFPERR_VLOCK;
2332 /* tried to move directory into a subdirectory of itself */
2333 return AFPERR_CANTMOVE;
2335 /* this needs to copy and delete. bleah. that means we have
2336 * to deal with entire directory hierarchies. */
2337 if ((err = copydir(vol, dirfd, src, dst)) < 0) {
2341 if ((err = deletedir(dirfd, src)) < 0)
2345 return( AFPERR_PARAM );
2349 vol->vfs->vfs_renamedir(vol, dirfd, src, dst);
2351 ad_init(&ad, vol->v_adouble, vol->v_ad_options);
2353 if (!ad_open_metadata( dst, ADFLAGS_DIR, 0, &ad)) {
2354 ad_setname(&ad, newname);
2356 ad_close_metadata( &ad);
2362 /* delete an empty directory */
2363 int deletecurdir(struct vol *vol)
2367 struct dir *fdir, *pdir;
2373 if ((pdir = dirlookup(vol, curdir->d_pdid)) == NULL) {
2374 return( AFPERR_ACCESS );
2379 ad_init(&ad, vol->v_adouble, vol->v_ad_options);
2380 /* we never want to create a resource fork here, we are going to delete it */
2381 if ( ad_metadata( ".", ADFLAGS_DIR, &ad) == 0 ) {
2383 ad_getattr(&ad, &ashort);
2384 ad_close_metadata(&ad);
2385 if ((ashort & htons(ATTRBIT_NODELETE))) {
2386 return AFPERR_OLOCK;
2389 err = vol->vfs->vfs_deletecurdir(vol);
2391 LOG(log_error, logtype_afpd, "deletecurdir: error deleting .AppleDouble in \"%s\"",
2392 curdir->d_fullpath);
2396 /* now get rid of dangling symlinks */
2397 if ((dp = opendir("."))) {
2398 while ((de = readdir(dp))) {
2399 /* skip this and previous directory */
2400 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
2403 /* bail if it's not a symlink */
2404 if ((lstat(de->d_name, &st) == 0) && !S_ISLNK(st.st_mode)) {
2405 LOG(log_error, logtype_afpd, "deletecurdir(\"%s\"): not empty",
2406 curdir->d_fullpath);
2408 return AFPERR_DIRNEMPT;
2411 if ((err = netatalk_unlink(de->d_name))) {
2418 if (movecwd(vol, pdir) < 0) {
2423 LOG(log_debug, logtype_afpd, "deletecurdir: moved to \"%s\"",
2424 cfrombstr(curdir->d_fullpath));
2426 err = netatalk_rmdir_all_errors(-1, cfrombstr(fdir->d_u_name));
2427 if ( err == AFP_OK || err == AFPERR_NOOBJ) {
2428 cnid_delete(vol->v_cdb, fdir->d_did);
2429 dir_remove( vol, fdir );
2431 LOG(log_error, logtype_afpd, "deletecurdir(\"%s\"): netatalk_rmdir_all_errors error",
2432 cfrombstr(curdir->d_fullpath));
2437 /* inode is used as key for cnid.
2438 * Close the descriptor only after cnid_delete
2446 int afp_mapid(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
2456 sfunc = (unsigned char) *ibuf++;
2459 if (sfunc >= 3 && sfunc <= 6) {
2460 if (afp_version < 30) {
2461 return( AFPERR_PARAM );
2468 case 3 :/* unicode */
2469 memcpy( &id, ibuf, sizeof( id ));
2472 if (( pw = getpwuid( id )) == NULL ) {
2473 return( AFPERR_NOITEM );
2475 len = convert_string_allocate( obj->options.unixcharset, ((!utf8)?obj->options.maccharset:CH_UTF8_MAC),
2476 pw->pw_name, -1, &name);
2483 case 4 : /* unicode */
2484 memcpy( &id, ibuf, sizeof( id ));
2487 if (NULL == ( gr = (struct group *)getgrgid( id ))) {
2488 return( AFPERR_NOITEM );
2490 len = convert_string_allocate( obj->options.unixcharset, (!utf8)?obj->options.maccharset:CH_UTF8_MAC,
2491 gr->gr_name, -1, &name);
2498 case 5 : /* UUID -> username */
2499 case 6 : /* UUID -> groupname */
2500 if ((afp_version < 32) || !(obj->options.flags & OPTION_UUID ))
2501 return AFPERR_PARAM;
2502 LOG(log_debug, logtype_afpd, "afp_mapid: valid UUID request");
2504 len = getnamefromuuid((unsigned char*) ibuf, &name, &type);
2505 if (len != 0) /* its a error code, not len */
2506 return AFPERR_NOITEM;
2509 if (( pw = getpwnam( name )) == NULL )
2510 return( AFPERR_NOITEM );
2511 LOG(log_debug, logtype_afpd, "afp_mapid: name:%s -> uid:%d", name, pw->pw_uid);
2512 id = htonl(UUID_USER);
2513 memcpy( rbuf, &id, sizeof( id ));
2514 id = htonl( pw->pw_uid);
2515 rbuf += sizeof( id );
2516 memcpy( rbuf, &id, sizeof( id ));
2517 rbuf += sizeof( id );
2518 *rbuflen = 2 * sizeof( id );
2521 if (( gr = getgrnam( name )) == NULL )
2522 return( AFPERR_NOITEM );
2523 LOG(log_debug, logtype_afpd, "afp_mapid: group:%s -> gid:%d", name, gr->gr_gid);
2524 id = htonl(UUID_GROUP);
2525 memcpy( rbuf, &id, sizeof( id ));
2526 rbuf += sizeof( id );
2527 id = htonl( gr->gr_gid);
2528 memcpy( rbuf, &id, sizeof( id ));
2529 rbuf += sizeof( id );
2530 *rbuflen = 2 * sizeof( id );
2538 return( AFPERR_PARAM );
2542 len = strlen( name );
2545 u_int16_t tp = htons(len);
2546 memcpy(rbuf, &tp, sizeof(tp));
2555 memcpy( rbuf, name, len );
2563 int afp_mapname(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
2572 sfunc = (unsigned char) *ibuf++;
2574 LOG(log_debug, logtype_afpd, "afp_mapname: sfunc: %d, afp_version: %d", sfunc, afp_version);
2577 case 2 : /* unicode */
2578 if (afp_version < 30) {
2579 return( AFPERR_PARAM );
2581 memcpy(&ulen, ibuf, sizeof(ulen));
2584 LOG(log_debug, logtype_afpd, "afp_mapname: alive");
2588 len = (unsigned char) *ibuf++;
2590 case 5 : /* username -> UUID */
2591 case 6 : /* groupname -> UUID */
2592 if ((afp_version < 32) || !(obj->options.flags & OPTION_UUID ))
2593 return AFPERR_PARAM;
2594 memcpy(&ulen, ibuf, sizeof(ulen));
2599 return( AFPERR_PARAM );
2605 return AFPERR_PARAM;
2608 case 1 : /* unicode */
2610 if (NULL == ( pw = (struct passwd *)getpwnam( ibuf )) ) {
2611 return( AFPERR_NOITEM );
2615 memcpy( rbuf, &id, sizeof( id ));
2616 *rbuflen = sizeof( id );
2619 case 2 : /* unicode */
2621 LOG(log_debug, logtype_afpd, "afp_mapname: getgrnam for name: %s",ibuf);
2622 if (NULL == ( gr = (struct group *)getgrnam( ibuf ))) {
2623 return( AFPERR_NOITEM );
2626 LOG(log_debug, logtype_afpd, "afp_mapname: getgrnam for name: %s -> id: %d",ibuf, id);
2628 memcpy( rbuf, &id, sizeof( id ));
2629 *rbuflen = sizeof( id );
2631 case 5 : /* username -> UUID */
2632 LOG(log_debug, logtype_afpd, "afp_mapname: name: %s",ibuf);
2633 if (0 != getuuidfromname(ibuf, UUID_USER, (unsigned char *)rbuf))
2634 return AFPERR_NOITEM;
2635 *rbuflen = UUID_BINSIZE;
2637 case 6 : /* groupname -> UUID */
2638 LOG(log_debug, logtype_afpd, "afp_mapname: name: %s",ibuf);
2639 if (0 != getuuidfromname(ibuf, UUID_GROUP, (unsigned char *)rbuf))
2640 return AFPERR_NOITEM;
2641 *rbuflen = UUID_BINSIZE;
2648 /* ------------------------------------
2649 variable DID support
2651 int afp_closedir(AFPObj *obj _U_, char *ibuf _U_, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
2662 /* do nothing as dids are static for the life of the process. */
2666 memcpy(&vid, ibuf, sizeof( vid ));
2667 ibuf += sizeof( vid );
2668 if (( vol = getvolbyvid( vid )) == NULL ) {
2669 return( AFPERR_PARAM );
2672 memcpy( &did, ibuf, sizeof( did ));
2673 ibuf += sizeof( did );
2674 if (( dir = dirlookup( vol, did )) == NULL ) {
2675 return( AFPERR_PARAM );
2678 /* dir_remove -- deletedid */
2684 /* did creation gets done automatically
2685 * there's a pb again with case but move it to cname
2687 int afp_opendir(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
2690 struct dir *parentdir;
2698 memcpy(&vid, ibuf, sizeof(vid));
2699 ibuf += sizeof( vid );
2701 if (NULL == ( vol = getvolbyvid( vid )) ) {
2702 return( AFPERR_PARAM );
2705 memcpy(&did, ibuf, sizeof(did));
2706 ibuf += sizeof(did);
2708 if (NULL == ( parentdir = dirlookup( vol, did )) ) {
2712 if (NULL == ( path = cname( vol, parentdir, &ibuf )) ) {
2713 return get_afp_errno(AFPERR_PARAM);
2716 if ( *path->m_name != '\0' ) {
2717 return path_error(path, AFPERR_NOOBJ);
2720 if ( !path->st_valid && of_stat(path ) < 0 ) {
2721 return( AFPERR_NOOBJ );
2723 if ( path->st_errno ) {
2724 return( AFPERR_NOOBJ );
2727 memcpy(rbuf, &curdir->d_did, sizeof(curdir->d_did));
2728 *rbuflen = sizeof(curdir->d_did);