From 25b5d2196afe740269c3347d49e6f59c40071429 Mon Sep 17 00:00:00 2001 From: franklahm Date: Tue, 5 Jan 2010 12:06:33 +0000 Subject: [PATCH] Substitute ADFLAGS_NOADOUBLE with ADVOL_NOADOUBLE, which gets automatically stuffed into struct adouble via ad_init. This eleminates the need to call vol_no_adouble(vol) every time in ad_open in order to pass ADFLAGS_NOADOUBLE with adflags, instead inside ad_open the func checks ad->ad_options. Remove forced adouble file creation from ad_metadata, this broke the clean ad_* API semantics of only creating files with O_CREATE. Instead do it explicitly in enumerate where the original force adouble patch grew from. --- etc/afpd/catsearch.c | 2 +- etc/afpd/desktop.c | 6 +++--- etc/afpd/directory.c | 8 ++++---- etc/afpd/extattrs.c | 7 ++++--- etc/afpd/file.c | 8 ++++---- etc/afpd/filedir.c | 4 ++-- etc/afpd/volume.c | 9 +++++---- include/atalk/adouble.h | 11 ++++++----- include/atalk/volume.h | 6 ++---- libatalk/adouble/ad_open.c | 18 ++++++------------ 10 files changed, 37 insertions(+), 42 deletions(-) diff --git a/etc/afpd/catsearch.c b/etc/afpd/catsearch.c index 28fe3411..59b0227b 100644 --- a/etc/afpd/catsearch.c +++ b/etc/afpd/catsearch.c @@ -215,7 +215,7 @@ static struct adouble *adl_lkup(struct vol *vol, struct path *path, struct adoub adp = &ad; } - if ( ad_metadata( path->u_name, vol_noadouble(vol) | ((isdir)?ADFLAGS_DIR:0), adp) < 0 ) { + if ( ad_metadata( path->u_name, ((isdir) ? ADFLAGS_DIR : 0), adp) < 0 ) { adp = NULL; /* FIXME without resource fork adl_lkup will be call again */ } diff --git a/etc/afpd/desktop.c b/etc/afpd/desktop.c index a679cf7d..fc2e306b 100644 --- a/etc/afpd/desktop.c +++ b/etc/afpd/desktop.c @@ -1,5 +1,5 @@ /* - * $Id: desktop.c,v 1.47 2009-11-27 12:37:24 didg Exp $ + * $Id: desktop.c,v 1.48 2010-01-05 12:06:33 franklahm Exp $ * * See COPYRIGHT. * @@ -693,7 +693,7 @@ static int ad_addcomment(struct vol *vol, struct path *path, char *ibuf) } else adp = of->of_ad; - if (ad_open_metadata( upath , vol_noadouble(vol) | ( (isadir) ? ADFLAGS_DIR :0),O_CREAT, adp) < 0 ) { + if (ad_open_metadata( upath , ( (isadir) ? ADFLAGS_DIR : 0), O_CREAT, adp) < 0 ) { return( AFPERR_ACCESS ); } @@ -766,7 +766,7 @@ static int ad_getcomment(struct vol *vol, struct path *path, char *rbuf, size_t } else adp = of->of_ad; - if ( ad_metadata( upath,vol_noadouble(vol) | ((isadir) ? ADFLAGS_DIR : 0), adp) < 0 ) { + if ( ad_metadata( upath, ((isadir) ? ADFLAGS_DIR : 0), adp) < 0 ) { return( AFPERR_NOITEM ); } diff --git a/etc/afpd/directory.c b/etc/afpd/directory.c index d6845297..3bc836c7 100644 --- a/etc/afpd/directory.c +++ b/etc/afpd/directory.c @@ -1,5 +1,5 @@ /* - * $Id: directory.c,v 1.121 2009-11-27 12:37:24 didg Exp $ + * $Id: directory.c,v 1.122 2010-01-05 12:06:33 franklahm Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -1645,7 +1645,7 @@ int getdirparams(const struct vol *vol, (1 << DIRPBIT_FINFO)))) { ad_init(&ad, vol->v_adouble, vol->v_ad_options); - if ( !ad_metadata( upath, vol_noadouble(vol) | ADFLAGS_DIR, &ad) ) { + if ( !ad_metadata( upath, ADFLAGS_DIR, &ad) ) { isad = 1; } } @@ -2079,7 +2079,7 @@ int setdirparams(struct vol *vol, } ad_init(&ad, vol->v_adouble, vol->v_ad_options); - if (ad_open_metadata( upath, vol_noadouble(vol)|ADFLAGS_DIR, O_CREAT, &ad) < 0) { + if (ad_open_metadata( upath, ADFLAGS_DIR, O_CREAT, &ad) < 0) { /* * Check to see what we're trying to set. If it's anything * but ACCESS, UID, or GID, give an error. If it's any of those @@ -2577,7 +2577,7 @@ int deletecurdir(struct vol *vol) ad_init(&ad, vol->v_adouble, vol->v_ad_options); /* we never want to create a resource fork here, we are going to delete it */ - if ( ad_metadata( ".", ADFLAGS_NOADOUBLE | ADFLAGS_DIR, &ad) == 0 ) { + if ( ad_metadata( ".", ADFLAGS_DIR, &ad) == 0 ) { ad_getattr(&ad, &ashort); ad_close( &ad, ADFLAGS_HF ); diff --git a/etc/afpd/extattrs.c b/etc/afpd/extattrs.c index 13e27a03..649cc6a3 100644 --- a/etc/afpd/extattrs.c +++ b/etc/afpd/extattrs.c @@ -1,5 +1,5 @@ /* - $Id: extattrs.c,v 1.28 2009-11-27 12:37:24 didg Exp $ + $Id: extattrs.c,v 1.29 2010-01-05 12:06:33 franklahm Exp $ Copyright (c) 2009 Frank Lahm This program is free software; you can redistribute it and/or modify @@ -140,7 +140,8 @@ int afp_listextattr(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, } adp = of_ad(vol, s_path, &ad); - uname = s_path->u_name; /* + uname = s_path->u_name; + /* We have to check the FinderInfo for the file, because if they aren't all 0 we must return the synthetic attribute "com.apple.FinderInfo". Note: the client will never (never seen in traces) request that attribute @@ -150,7 +151,7 @@ int afp_listextattr(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, if (S_ISDIR(st->st_mode)) adflags = ADFLAGS_DIR; - if ( ad_metadata( uname, vol_noadouble(vol) | adflags, adp) < 0 ) { + if ( ad_metadata( uname, adflags, adp) < 0 ) { switch (errno) { case ENOENT: adp = NULL; diff --git a/etc/afpd/file.c b/etc/afpd/file.c index a5a2c1cc..905c7820 100644 --- a/etc/afpd/file.c +++ b/etc/afpd/file.c @@ -1,5 +1,5 @@ /* - * $Id: file.c,v 1.126 2009-11-30 15:27:48 didg Exp $ + * $Id: file.c,v 1.127 2010-01-05 12:06:33 franklahm Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -527,7 +527,7 @@ int getfilparams(struct vol *vol, adp = of_ad(vol, path, &ad); upath = path->u_name; - if ( ad_metadata( upath, vol_noadouble(vol) | flags, adp) < 0 ) { + if ( ad_metadata( upath, flags, adp) < 0 ) { switch (errno) { case EACCES: LOG(log_error, logtype_afpd, "getfilparams(%s): %s: check resource fork permission?", @@ -619,7 +619,7 @@ int afp_createfile(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, openf = O_RDWR|O_CREAT|O_EXCL; } - if ( ad_open( upath, vol_noadouble(vol)|ADFLAGS_DF|ADFLAGS_HF|ADFLAGS_NOHF|ADFLAGS_CREATE, + if ( ad_open( upath, ADFLAGS_DF|ADFLAGS_HF|ADFLAGS_NOHF|ADFLAGS_CREATE, openf, 0666, adp) < 0 ) { switch ( errno ) { case EROFS: @@ -1498,7 +1498,7 @@ int deletefile(const struct vol *vol, char *file, int checkAttrib) * moreover sometimes deletefile is called with a no existent file and * ad_open would create a 0 byte resource fork */ - if ( ad_metadata( file , ADFLAGS_NOADOUBLE | ADFLAGS_OPENFORKS, &ad) == 0 ) { + if ( ad_metadata( file, ADFLAGS_OPENFORKS, &ad) == 0 ) { ad_close( &ad, adflags ); if ((err = check_attrib(&ad))) { return err; diff --git a/etc/afpd/filedir.c b/etc/afpd/filedir.c index 5db262df..2f82fca4 100644 --- a/etc/afpd/filedir.c +++ b/etc/afpd/filedir.c @@ -1,5 +1,5 @@ /* - * $Id: filedir.c,v 1.65 2009-11-27 12:37:24 didg Exp $ + * $Id: filedir.c,v 1.66 2010-01-05 12:06:33 franklahm Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -360,7 +360,7 @@ static int moveandrename(const struct vol *vol, struct dir *sdir, char *oldname, * we are in the dest folder so we need to use p for ad_open */ - if (!ad_metadata(p, vol_noadouble(vol) | adflags, adp)) { + if (!ad_metadata(p, adflags, adp)) { u_int16_t bshort; ad_getattr(adp, &bshort); diff --git a/etc/afpd/volume.c b/etc/afpd/volume.c index 7f86f04d..75a8678a 100644 --- a/etc/afpd/volume.c +++ b/etc/afpd/volume.c @@ -1,5 +1,5 @@ /* - * $Id: volume.c,v 1.112 2009-12-18 19:18:40 franklahm Exp $ + * $Id: volume.c,v 1.113 2010-01-05 12:06:33 franklahm Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -696,6 +696,8 @@ static int creatvol(AFPObj *obj, struct passwd *pwd, volume->v_ad_options |= ADVOL_UNIXPRIV; if ((volume->v_flags & AFPVOL_INV_DOTS)) volume->v_ad_options |= ADVOL_INVDOTS; + if ((volume->v_flags & AFPVOL_NOADOUBLE)) + volume->v_ad_options |= ADVOL_NOADOUBLE; if (options[VOLOPT_PASSWORD].c_value) volume->v_password = strdup(options[VOLOPT_PASSWORD].c_value); @@ -1408,7 +1410,7 @@ static int getvolparams( u_int16_t bitmap, struct vol *vol, struct stat *st, cha * .Parent file here if it doesn't exist. */ ad_init(&ad, vol->v_adouble, vol->v_ad_options); - if ( ad_open_metadata( vol->v_path, vol_noadouble(vol) | ADFLAGS_DIR, O_CREAT, &ad) < 0 ) { + if ( ad_open_metadata( vol->v_path, ADFLAGS_DIR, O_CREAT, &ad) < 0 ) { isad = 0; vol->v_ctime = AD_DATE_FROM_UNIX(st->st_mtime); @@ -2450,8 +2452,7 @@ static int create_special_folder (const struct vol *vol, const struct _special_f if ( !ret && folder->hide) { /* Hide it */ ad_init(&ad, vol->v_adouble, vol->v_ad_options); - if (ad_open( p, vol_noadouble(vol) | ADFLAGS_HF|ADFLAGS_DIR, - O_RDWR|O_CREAT, 0666, &ad) < 0) { + if (ad_open( p, ADFLAGS_HF|ADFLAGS_DIR, O_RDWR|O_CREAT, 0666, &ad) < 0) { free (p); free(q); return (-1); diff --git a/include/atalk/adouble.h b/include/atalk/adouble.h index 0c420d04..8ead1c4d 100644 --- a/include/atalk/adouble.h +++ b/include/atalk/adouble.h @@ -1,5 +1,5 @@ /* - * $Id: adouble.h,v 1.51 2010-01-04 13:49:48 franklahm Exp $ + * $Id: adouble.h,v 1.52 2010-01-05 12:06:34 franklahm Exp $ * Copyright (c) 1990,1991 Regents of The University of Michigan. * All Rights Reserved. * @@ -300,7 +300,9 @@ struct adouble_fops { #define ADFLAGS_DF (1<<0) #define ADFLAGS_HF (1<<1) #define ADFLAGS_DIR (1<<2) +/* #define ADFLAGS_NOADOUBLE (1<<3) +*/ #define ADFLAGS_V1COMPAT (1<<4) #define ADFLAGS_NOHF (1<<5) /* not an error if no ressource fork */ #define ADFLAGS_RDONLY (1<<6) /* don't try readwrite */ @@ -312,10 +314,9 @@ struct adouble_fops { /* adouble v2 cnid cache */ #define ADVOL_NODEV (1 << 0) #define ADVOL_CACHE (1 << 1) -/* adouble unix priv */ -#define ADVOL_UNIXPRIV (1 << 2) -/* dot files (.DS_Store) are invisible) */ -#define ADVOL_INVDOTS (1 << 3) +#define ADVOL_UNIXPRIV (1 << 2) /* adouble unix priv */ +#define ADVOL_INVDOTS (1 << 3) /* dot files (.DS_Store) are invisible) */ +#define ADVOL_NOADOUBLE (1 << 4) /* lock flags */ #define ADLOCK_CLR (0) diff --git a/include/atalk/volume.h b/include/atalk/volume.h index bbc9fe48..0a4f1c88 100644 --- a/include/atalk/volume.h +++ b/include/atalk/volume.h @@ -1,5 +1,5 @@ /* - * $Id: volume.h,v 1.10 2010-01-05 10:37:29 franklahm Exp $ + * $Id: volume.h,v 1.11 2010-01-05 12:06:34 franklahm Exp $ * * Copyright (c) 1990,1994 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -195,15 +195,13 @@ int wincheck(const struct vol *vol, const char *path); #define VOLPBIT_XBTOTAL 10 #define VOLPBIT_BSIZE 11 /* block size */ - -#define vol_noadouble(vol) (((vol)->v_flags & AFPVOL_NOADOUBLE) ? \ - ADFLAGS_NOADOUBLE : 0) #ifdef AFP3x #define utf8_encoding() (afp_version >= 30) #else #define utf8_encoding() (0) #endif +#define vol_noadouble(vol) (((vol)->v_flags & AFPVOL_NOADOUBLE) ? 1 : 0) #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_inv_dots(vol) (((vol)->v_flags & AFPVOL_INV_DOTS) ? 1 : 0) diff --git a/libatalk/adouble/ad_open.c b/libatalk/adouble/ad_open.c index 5b3f93c4..d8ebc8cc 100644 --- a/libatalk/adouble/ad_open.c +++ b/libatalk/adouble/ad_open.c @@ -1,5 +1,5 @@ /* - * $Id: ad_open.c,v 1.61 2010-01-04 13:49:48 franklahm Exp $ + * $Id: ad_open.c,v 1.62 2010-01-05 12:06:34 franklahm Exp $ * * Copyright (c) 1999 Adrian Sun (asun@u.washington.edu) * Copyright (c) 1990,1991 Regents of The University of Michigan. @@ -1246,7 +1246,8 @@ void ad_init(struct adouble *ad, int flags, int options) * @returns 0 on success * * @note It's not possible to open the header file O_RDONLY -- the read - * will fail and return an error. this refcounts things now. + * will fail and return an error. this refcounts things now.\n + * metadata(ressource)-fork only gets created with O_CREAT. */ int ad_open( const char *path, int adflags, int oflags, int mode, struct adouble *ad) { @@ -1371,7 +1372,7 @@ int ad_open( const char *path, int adflags, int oflags, int mode, struct adouble admode = mode; } admode = ad_hf_mode(admode); - if ( errno == ENOENT && !(adflags & ADFLAGS_NOADOUBLE) && ad->ad_flags != AD_VERSION2_OSX) { + if ( errno == ENOENT && !(ad->ad_options & ADVOL_NOADOUBLE) && ad->ad_flags != AD_VERSION2_OSX) { if (ad->ad_ops->ad_mkrf( ad_p) < 0) { return ad_error(ad, adflags); } @@ -1505,22 +1506,15 @@ sfm: } /* ----------------------------------- - * return only metadata but try very hard + * return only metadata but try very hard ie at first try as user, then try as root */ int ad_metadata(const char *name, int flags, struct adouble *adp) { uid_t uid; int ret, err; int dir = flags & ADFLAGS_DIR; - int adouble = 0; - if (!(flags & ADFLAGS_NOADOUBLE)) { - adouble = O_CREAT; - } - - /* Open with O_CREAT, thus enumarating a dir will create missing adouble files, see: */ - /* http://marc.info/?l=netatalk-devel&m=124039156832408&w=2 */ - if ((ret = ad_open(name, ADFLAGS_HF | dir, O_RDWR | adouble, 0666, adp)) < 0 && errno == EACCES) { + if ((ret = ad_open(name, ADFLAGS_HF | dir, O_RDWR, 0666, adp)) < 0 && errno == EACCES) { uid = geteuid(); if (seteuid(0)) { LOG(log_error, logtype_default, "ad_metadata(%s): seteuid failed %s", name, strerror(errno)); -- 2.39.2