#include "volume.h"
#include "unix.h"
+#ifdef HAVE_NFSv4_ACLS
+extern int remove_acl(const char *name);
+#endif
+
struct perm {
uid_t uid;
gid_t gid;
{
char *adouble = vol->vfs->ad_path( name, ADFLAGS_DIR );
char ad_p[ MAXPATHLEN + 1];
- int dropbox = (vol->v_flags & AFPVOL_DROPBOX);
+ int dropbox = vol->v_flags;
strlcpy(ad_p,ad_dir(adouble), MAXPATHLEN + 1);
if (dir_rx_set(mode)) {
/* .AppleDouble */
- if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, dropbox) < 0 && !vol_noadouble(vol))
+ if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, dropbox) < 0)
return -1;
/* .AppleDouble/.Parent */
- if (stickydirmode(ad_p, DIRBITS | mode, dropbox) < 0 && !vol_noadouble(vol))
+ if (stickydirmode(ad_p, DIRBITS | mode, dropbox) < 0)
return -1;
}
return -1;
if (!dir_rx_set(mode)) {
- if (stickydirmode(ad_p, DIRBITS | mode, dropbox) < 0 && !vol_noadouble(vol))
+ if (stickydirmode(ad_p, DIRBITS | mode, dropbox) < 0)
return -1 ;
- if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, dropbox) < 0 && !vol_noadouble(vol))
+ if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, dropbox) < 0)
return -1;
}
return 0;
struct dir_mode param;
param.mode = mode;
- param.dropbox = (vol->v_flags & AFPVOL_DROPBOX);
+ param.dropbox = vol->v_flags;
strlcpy(ad_p,ad_dir(adouble), sizeof(ad_p));
if (dir_rx_set(mode)) {
/* .AppleDouble */
- if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, param.dropbox) < 0 && !vol_noadouble(vol))
+ if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, param.dropbox) < 0)
return -1;
}
return -1;
if (!dir_rx_set(mode)) {
- if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, param.dropbox) < 0 && !vol_noadouble(vol))
+ if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, param.dropbox) < 0 )
return -1;
}
return 0;
struct adouble ad;
if (stat(adsrc, &st)) /* source has no ressource fork, */
- return AFP_OK;
+ return 0;
/* We are here because :
* -there's no dest folder.
classic adouble format
*/
-static int validupath_adouble(const struct vol *vol, const char *name)
+static int netatalk_name(const char *name)
{
- return (vol->v_flags & AFPVOL_USEDOTS) ?
- strcasecmp(name,".AppleDB") &&
- strcasecmp(name,".AppleDouble") &&
- strcasecmp(name,".AppleDesktop") &&
- strcasecmp(name,".Parent")
- : name[0] != '.';
+ return strcasecmp(name,".AppleDB") &&
+ strcasecmp(name,".AppleDouble") &&
+ strcasecmp(name,".AppleDesktop");
}
+static int validupath_adouble(const struct vol *vol, const char *name)
+{
+ return (vol->v_flags & AFPVOL_USEDOTS) ?
+ netatalk_name(name) && strcasecmp(name,".Parent"): name[0] != '.';
+}
+
/* ----------------- */
static int RF_chown_adouble(const struct vol *vol, const char *path, uid_t uid, gid_t gid)
static int RF_setdirunixmode_adouble(const struct vol *vol, const char * name, mode_t mode, struct stat *st)
{
char *adouble = vol->vfs->ad_path( name, ADFLAGS_DIR );
- int dropbox = (vol->v_flags & AFPVOL_DROPBOX);
+ int dropbox = vol->v_flags;
if (dir_rx_set(mode)) {
- if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox) < 0 && !vol_noadouble(vol))
+ if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox) < 0 )
return -1;
}
return -1;
if (!dir_rx_set(mode)) {
- if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox) < 0 && !vol_noadouble(vol))
+ if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox) < 0 )
return -1 ;
}
return 0;
static int RF_setdirmode_adouble(const struct vol *vol, const char * name, mode_t mode, struct stat *st _U_)
{
- int dropbox = (vol->v_flags & AFPVOL_DROPBOX);
+ int dropbox = vol->v_flags;
mode_t hf_mode = ad_hf_mode(mode);
char *adouble = vol->vfs->ad_path( name, ADFLAGS_DIR );
char *adouble_p = ad_dir(adouble);
if (dir_rx_set(mode)) {
- if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox) < 0 && !vol_noadouble(vol))
+ if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox) < 0)
return -1;
}
return -1;
if (!dir_rx_set(mode)) {
- if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox) < 0 && !vol_noadouble(vol))
+ if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox) < 0)
return -1 ;
}
return 0;
struct adouble ad;
if (stat(adsrc, &st)) /* source has no ressource fork, */
- return AFP_OK;
+ return 0;
/* We are here because :
* -there's no dest folder.
return 0;
}
+#ifdef HAVE_NFSv4_ACLS
+static int RF_acl(const struct vol *vol, const char *path, int cmd, int count, ace_t *aces)
+{
+ static char buf[ MAXPATHLEN + 1];
+ struct stat st;
+
+ if ((stat(path, &st)) != 0)
+ return -1;
+ if (S_ISDIR(st.st_mode)) {
+ if ((snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path)) < 0)
+ return -1;
+ /* set acl on .AppleDouble dir first */
+ if ((acl(buf, cmd, count, aces)) != 0)
+ return -1;
+ /* now set ACL on ressource fork */
+ if ((acl(vol->vfs->ad_path(path, ADFLAGS_DIR), cmd, count, aces)) != 0)
+ return -1;
+ } else
+ /* set ACL on ressource fork */
+ if ((acl(vol->vfs->ad_path(path, ADFLAGS_HF), cmd, count, aces)) != 0)
+ return -1;
+
+ return 0;
+}
+
+static int RF_remove_acl(const struct vol *vol, const char *path, int dir)
+{
+ int ret;
+ static char buf[ MAXPATHLEN + 1];
+
+ if (dir) {
+ if ((snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path)) < 0)
+ return AFPERR_MISC;
+ /* remove ACL from .AppleDouble/.Parent first */
+ if ((ret = remove_acl(vol->vfs->ad_path(path, ADFLAGS_DIR))) != AFP_OK)
+ return ret;
+ /* now remove from .AppleDouble dir */
+ if ((ret = remove_acl(buf)) != AFP_OK)
+ return ret;
+ } else
+ /* remove ACL from ressource fork */
+ if ((ret = remove_acl(vol->vfs->ad_path(path, ADFLAGS_HF))) != AFP_OK)
+ return ret;
+
+ return AFP_OK;
+}
+#endif
+
struct vfs_ops netatalk_adouble = {
/* ad_path: */ ad_path,
/* validupath: */ validupath_adouble,
/* rf_setdirowner: */ RF_setdirowner_adouble,
/* rf_deletefile: */ RF_deletefile_adouble,
/* rf_renamefile: */ RF_renamefile_adouble,
+#ifdef HAVE_NFSv4_ACLS
+ /* rf_acl: */ RF_acl,
+ /* rf_remove_acl */ RF_remove_acl
+#endif
};
/* =======================================
osx adouble format
*/
-static int validupath_osx(const struct vol *vol _U_, const char *name)
+static int validupath_osx(const struct vol *vol, const char *name)
{
- return strncasecmp(name,".Apple", 6) && strncasecmp(name,"._", 2);
-}
+ return strncmp(name,"._", 2) && (
+ (vol->v_flags & AFPVOL_USEDOTS) ? netatalk_name(name): name[0] != '.');
+}
/* ---------------- */
int RF_renamedir_osx(const struct vol *vol, const char *oldpath, const char *newpath)
int RF_renamefile_osx(const struct vol *vol, const char *src, const char *dst)
{
char adsrc[ MAXPATHLEN + 1];
+ int err = 0;
strcpy( adsrc, vol->vfs->ad_path( src, 0 ));
- return unix_rename( adsrc, vol->vfs->ad_path( dst, 0 ));
+
+ if (unix_rename( adsrc, vol->vfs->ad_path( dst, 0 )) < 0) {
+ struct stat st;
+
+ err = errno;
+ if (errno == ENOENT && stat(adsrc, &st)) /* source has no ressource fork, */
+ return 0;
+ errno = err;
+ return -1;
+ }
+ return 0;
}
struct vfs_ops netatalk_adouble_osx = {