From: <tak...@us...> - 2011-03-29 12:01:12
|
Revision: 5239 http://gfarm.svn.sourceforge.net/gfarm/?rev=5239&view=rev Author: takuya-i Date: 2011-03-29 12:01:01 +0000 (Tue, 29 Mar 2011) Log Message: ----------- * add gfarm2fs_fix_acl system. * This fixes the ACL xattr problem on gfarm2fs-1.2.2 or older. * gfarm2fs_fix_acl command : do chmod() and remove useless xattrs * gfarm2fs -o fix_acl option : for gfarm2fs_fix_acl command * gfarm2fs_fix_acl.sh script : mount, execute and unmount automatically Modified Paths: -------------- gfarm2fs/trunk/Makefile.am gfarm2fs/trunk/Makefile.in gfarm2fs/trunk/acl.c gfarm2fs/trunk/acl.h gfarm2fs/trunk/gfarm2fs.c gfarm2fs/trunk/gfarm2fs.h Added Paths: ----------- gfarm2fs/trunk/gfarm2fs_fix_acl.c gfarm2fs/trunk/gfarm2fs_fix_acl.sh Modified: gfarm2fs/trunk/Makefile.am =================================================================== --- gfarm2fs/trunk/Makefile.am 2011-03-29 08:04:55 UTC (rev 5238) +++ gfarm2fs/trunk/Makefile.am 2011-03-29 12:01:01 UTC (rev 5239) @@ -1,7 +1,9 @@ -bin_PROGRAMS = gfarm2fs +bin_PROGRAMS = gfarm2fs gfarm2fs_fix_acl gfarm2fs_SOURCES = gfarm2fs.c acl.c id.c replicate.c open_file.c \ gfarm2fs.h acl.h id.h replicate.h open_file.h gfarm2fs_msg_enums.h \ hash.h +gfarm2fs_fix_acl_SOURCES = gfarm2fs_fix_acl.c acl.h gfarm2fs.h +dist_bin_SCRIPTS = gfarm2fs_fix_acl.sh man_MANS = gfarm2fs.1 EXTRA_DIST = RELNOTES LICENSE gfarm2fs.spec $(man_MANS) $(private_srcs) AM_CFLAGS = -Wall Modified: gfarm2fs/trunk/Makefile.in =================================================================== --- gfarm2fs/trunk/Makefile.in 2011-03-29 08:04:55 UTC (rev 5238) +++ gfarm2fs/trunk/Makefile.in 2011-03-29 12:01:01 UTC (rev 5239) @@ -15,6 +15,7 @@ @SET_MAKE@ + VPATH = @srcdir@ pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ @@ -34,12 +35,12 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -bin_PROGRAMS = gfarm2fs$(EXEEXT) +bin_PROGRAMS = gfarm2fs$(EXEEXT) gfarm2fs_fix_acl$(EXEEXT) subdir = . -DIST_COMMON = $(am__configure_deps) $(srcdir)/Makefile.am \ - $(srcdir)/Makefile.in $(srcdir)/config.h.in \ - $(top_srcdir)/configure INSTALL config.guess config.sub \ - depcomp install-sh ltmain.sh missing +DIST_COMMON = $(am__configure_deps) $(dist_bin_SCRIPTS) \ + $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ + $(srcdir)/config.h.in $(top_srcdir)/configure INSTALL \ + config.guess config.sub depcomp install-sh ltmain.sh missing ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ @@ -53,27 +54,16 @@ CONFIG_HEADER = config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = -am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)" +am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(bindir)" \ + "$(DESTDIR)$(man1dir)" PROGRAMS = $(bin_PROGRAMS) am_gfarm2fs_OBJECTS = gfarm2fs.$(OBJEXT) acl.$(OBJEXT) id.$(OBJEXT) \ replicate.$(OBJEXT) open_file.$(OBJEXT) gfarm2fs_OBJECTS = $(am_gfarm2fs_OBJECTS) gfarm2fs_LDADD = $(LDADD) -DEFAULT_INCLUDES = -I.@am__isrc@ -depcomp = $(SHELL) $(top_srcdir)/depcomp -am__depfiles_maybe = depfiles -am__mv = mv -f -COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ - $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ - --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ - $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -CCLD = $(CC) -LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ - --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ - $(LDFLAGS) -o $@ -SOURCES = $(gfarm2fs_SOURCES) -DIST_SOURCES = $(gfarm2fs_SOURCES) +am_gfarm2fs_fix_acl_OBJECTS = gfarm2fs_fix_acl.$(OBJEXT) +gfarm2fs_fix_acl_OBJECTS = $(am_gfarm2fs_fix_acl_OBJECTS) +gfarm2fs_fix_acl_LDADD = $(LDADD) am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ @@ -95,6 +85,22 @@ am__base_list = \ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +SCRIPTS = $(dist_bin_SCRIPTS) +DEFAULT_INCLUDES = -I.@am__isrc@ +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(gfarm2fs_SOURCES) $(gfarm2fs_fix_acl_SOURCES) +DIST_SOURCES = $(gfarm2fs_SOURCES) $(gfarm2fs_fix_acl_SOURCES) man1dir = $(mandir)/man1 NROFF = nroff MANS = $(man_MANS) @@ -229,6 +235,8 @@ gfarm2fs.h acl.h id.h replicate.h open_file.h gfarm2fs_msg_enums.h \ hash.h +gfarm2fs_fix_acl_SOURCES = gfarm2fs_fix_acl.c acl.h gfarm2fs.h +dist_bin_SCRIPTS = gfarm2fs_fix_acl.sh man_MANS = gfarm2fs.1 EXTRA_DIST = RELNOTES LICENSE gfarm2fs.spec $(man_MANS) $(private_srcs) AM_CFLAGS = -Wall @@ -336,7 +344,44 @@ gfarm2fs$(EXEEXT): $(gfarm2fs_OBJECTS) $(gfarm2fs_DEPENDENCIES) @rm -f gfarm2fs$(EXEEXT) $(LINK) $(gfarm2fs_OBJECTS) $(gfarm2fs_LDADD) $(LIBS) +gfarm2fs_fix_acl$(EXEEXT): $(gfarm2fs_fix_acl_OBJECTS) $(gfarm2fs_fix_acl_DEPENDENCIES) + @rm -f gfarm2fs_fix_acl$(EXEEXT) + $(LINK) $(gfarm2fs_fix_acl_OBJECTS) $(gfarm2fs_fix_acl_LDADD) $(LIBS) +install-dist_binSCRIPTS: $(dist_bin_SCRIPTS) + @$(NORMAL_INSTALL) + test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)" + @list='$(dist_bin_SCRIPTS)'; test -n "$(bindir)" || list=; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + if test -f "$$d$$p"; then echo "$$d$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n' \ + -e 'h;s|.*|.|' \ + -e 'p;x;s,.*/,,;$(transform)' | sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1; } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) { files[d] = files[d] " " $$1; \ + if (++n[d] == $(am__install_max)) { \ + print "f", d, files[d]; n[d] = 0; files[d] = "" } } \ + else { print "f", d "/" $$4, $$1 } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_SCRIPT) $$files '$(DESTDIR)$(bindir)$$dir'"; \ + $(INSTALL_SCRIPT) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ + } \ + ; done +uninstall-dist_binSCRIPTS: + @$(NORMAL_UNINSTALL) + @list='$(dist_bin_SCRIPTS)'; test -n "$(bindir)" || exit 0; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 's,.*/,,;$(transform)'`; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(bindir)" && rm -f $$files + mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -345,6 +390,7 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/acl.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gfarm2fs.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gfarm2fs_fix_acl.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/id.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/open_file.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/replicate.Po@am__quote@ @@ -631,9 +677,9 @@ exit 1; } >&2 check-am: all-am check: check-am -all-am: Makefile $(PROGRAMS) $(MANS) config.h +all-am: Makefile $(PROGRAMS) $(SCRIPTS) $(MANS) config.h installdirs: - for dir in "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)"; do \ + for dir in "$(DESTDIR)$(bindir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-am @@ -690,7 +736,7 @@ install-dvi-am: -install-exec-am: install-binPROGRAMS +install-exec-am: install-binPROGRAMS install-dist_binSCRIPTS install-html: install-html-am @@ -732,7 +778,8 @@ ps-am: -uninstall-am: uninstall-binPROGRAMS uninstall-man +uninstall-am: uninstall-binPROGRAMS uninstall-dist_binSCRIPTS \ + uninstall-man uninstall-man: uninstall-man1 @@ -746,14 +793,15 @@ distclean-local distclean-tags distcleancheck distdir \ distuninstallcheck dvi dvi-am html html-am info info-am \ install install-am install-binPROGRAMS install-data \ - install-data-am install-dvi install-dvi-am install-exec \ - install-exec-am install-html install-html-am install-info \ - install-info-am install-man install-man1 install-pdf \ - install-pdf-am install-ps install-ps-am install-strip \ - installcheck installcheck-am installdirs maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-compile \ - mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ - tags uninstall uninstall-am uninstall-binPROGRAMS \ + install-data-am install-dist_binSCRIPTS install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-man1 install-pdf install-pdf-am install-ps \ + install-ps-am install-strip installcheck installcheck-am \ + installdirs maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am tags uninstall \ + uninstall-am uninstall-binPROGRAMS uninstall-dist_binSCRIPTS \ uninstall-man uninstall-man1 Modified: gfarm2fs/trunk/acl.c =================================================================== --- gfarm2fs/trunk/acl.c 2011-03-29 08:04:55 UTC (rev 5238) +++ gfarm2fs/trunk/acl.c 2011-03-29 12:01:01 UTC (rev 5239) @@ -16,16 +16,9 @@ #include "id.h" #include "acl.h" -static const char ACL_EA_ACCESS[] = "system.posix_acl_access"; -static const char ACL_EA_DEFAULT[] = "system.posix_acl_default"; - #ifdef ENABLE_GFARM_ACL /* with HAVE_SYS_ACL_H */ #include <sys/acl.h> -#define ACL_EA_VERSION (0x0002) /* Linux ACL Version */ - -static int enable_acl; - #define ADD_BUF(src, size) \ do { \ if (nowlen + size > bufsize) { \ @@ -44,9 +37,9 @@ /* to get ACL */ static gfarm_error_t -gfarm2fs_gfarm_acl_to_posix_acl_xattr(const char *url, const gfarm_acl_t acl, - void **posix_xattr_value_p, - size_t *sizep) +gfarm2fs_gfarm_acl_to_posix_acl_xattr( + const char *url, const gfarm_acl_t acl, + void **posix_xattr_value_p, size_t *sizep) { gfarm_error_t e; void *buf; @@ -144,9 +137,9 @@ /* to set ACL */ static gfarm_error_t -gfarm2fs_gfarm_acl_from_posix_acl_xattr(const char *url, - const void *posix_xattr_value, - size_t size, gfarm_acl_t *acl_p) +gfarm2fs_gfarm_acl_from_posix_acl_xattr( + const char *url, const void *posix_xattr_value, + size_t size, gfarm_acl_t *acl_p) { gfarm_error_t e; gfarm_acl_t acl; @@ -185,6 +178,7 @@ tag2 = gfarm_ltoh_16(tag); /* posix_acl_tag to gfarm_acl_tag */ gfs_acl_set_tag_type(ent, tag2); + gfs_acl_get_permset(ent, &pset); /* posix_acl_perm to gfarm_acl_perm */ gfs_acl_add_perm(pset, gfarm_ltoh_16(perm)); @@ -224,24 +218,15 @@ return (e); } -gfarm_error_t -gfarm2fs_acl_setxattr(const char *path, const char *name, - const void *value, size_t size, int flags) +/* ------------------------------- */ + +static gfarm_error_t +__acl_setxattr(const char *path, gfarm_acl_type_t type, + const void *value, size_t size) { gfarm_error_t e; gfarm_acl_t acl; - gfarm_acl_type_t type; - if (strcmp(name, ACL_EA_ACCESS) == 0) - type = GFARM_ACL_TYPE_ACCESS; - else if (strcmp(name, ACL_EA_DEFAULT) == 0) - type = GFARM_ACL_TYPE_DEFAULT; - else - return (gfs_lsetxattr(path, name, value, size, flags)); - - if (enable_acl == 0) - return (GFARM_ERR_OPERATION_NOT_SUPPORTED); /* EOPNOTSUPP */ - e = gfarm2fs_gfarm_acl_from_posix_acl_xattr(path, value, size, &acl); if (e != GFARM_ERR_NO_ERROR) { gflog_debug(GFARM_MSG_UNFIXED, @@ -260,26 +245,15 @@ return (e); } -gfarm_error_t -gfarm2fs_acl_getxattr(const char *path, const char *name, - void *value, size_t *sizep) +static gfarm_error_t +__acl_getxattr(const char *path, gfarm_acl_type_t type, + void *value, size_t *sizep) { gfarm_error_t e; gfarm_acl_t acl; size_t size; void *posix; - gfarm_acl_type_t type; - if (strcmp(name, ACL_EA_ACCESS) == 0) - type = GFARM_ACL_TYPE_ACCESS; - else if (strcmp(name, ACL_EA_DEFAULT) == 0) - type = GFARM_ACL_TYPE_DEFAULT; - else - return (gfs_lgetxattr_cached(path, name, value, sizep)); - - if (enable_acl == 0) - return (GFARM_ERR_NO_SUCH_OBJECT); - e = gfs_acl_get_file_cached(path, type, &acl); if (e != GFARM_ERR_NO_ERROR) return (e); @@ -313,41 +287,111 @@ return (e); } -gfarm_error_t -gfarm2fs_acl_removexattr(const char *path, const char *name) +/* ------------------------------- */ + +static gfarm_error_t +normal_acl_setxattr(const char *path, const char *name, + const void *value, size_t size, int flags) { - const char *type; + if (strcmp(name, ACL_EA_ACCESS) == 0) + return (__acl_setxattr(path, GFARM_ACL_TYPE_ACCESS, + value, size)); + else if (strcmp(name, ACL_EA_DEFAULT) == 0) + return (__acl_setxattr(path, GFARM_ACL_TYPE_DEFAULT, + value, size)); + else + return (gfs_lsetxattr(path, name, value, size, flags)); +} +static gfarm_error_t +normal_acl_getxattr(const char *path, const char *name, + void *value, size_t *sizep) +{ if (strcmp(name, ACL_EA_ACCESS) == 0) - type = GFARM_ACL_EA_ACCESS; + return (__acl_getxattr(path, GFARM_ACL_TYPE_ACCESS, + value, sizep)); else if (strcmp(name, ACL_EA_DEFAULT) == 0) - type = GFARM_ACL_EA_DEFAULT; + return (__acl_getxattr(path, GFARM_ACL_TYPE_DEFAULT, + value, sizep)); else + return (gfs_lgetxattr_cached(path, name, value, sizep)); +} + +static gfarm_error_t +normal_acl_removexattr(const char *path, const char *name) +{ + if (strcmp(name, ACL_EA_ACCESS) == 0) + return (gfs_lremovexattr(path, GFARM_ACL_EA_ACCESS)); + else if (strcmp(name, ACL_EA_DEFAULT) == 0) + return (gfs_lremovexattr(path, GFARM_ACL_EA_DEFAULT)); + else return (gfs_lremovexattr(path, name)); +} - if (enable_acl == 0) +/* ------------------------------- */ + +/* for gfarm2fs_fix_acl command */ + +gfarm_error_t +fix_acl_setxattr(const char *path, const char *name, + const void *value, size_t size, int flags) +{ + if (strcmp(name, FIX_ACL_ACCESS) == 0 || + strcmp(name, FIX_ACL_DEFAULT) == 0) return (GFARM_ERR_OPERATION_NOT_SUPPORTED); /* EOPNOTSUPP */ - - return (gfs_lremovexattr(path, type)); + else if (strcmp(name, ACL_EA_ACCESS) == 0) + return (__acl_setxattr(path, GFARM_ACL_TYPE_ACCESS, + value, size)); + else if (strcmp(name, ACL_EA_DEFAULT) == 0) + return (__acl_setxattr(path, GFARM_ACL_TYPE_DEFAULT, + value, size)); + else + return (gfs_lsetxattr(path, name, value, size, flags)); } -void -gfarm2fs_acl_init(struct gfarm2fs_param *params) +gfarm_error_t +fix_acl_getxattr(const char *path, const char *name, + void *value, size_t *sizep) { - enable_acl = !params->disable_acl; - - if (enable_acl) { - gfarm_xattr_caching_pattern_add(GFARM_ACL_EA_ACCESS); - gfarm_xattr_caching_pattern_add(GFARM_ACL_EA_DEFAULT); - } + if (strcmp(name, FIX_ACL_ACCESS) == 0) + return (gfs_lgetxattr_cached(path, ACL_EA_ACCESS, + value, sizep)); + else if (strcmp(name, FIX_ACL_DEFAULT) == 0) + return (gfs_lgetxattr_cached(path, ACL_EA_DEFAULT, + value, sizep)); + else if (strcmp(name, ACL_EA_ACCESS) == 0) + return (__acl_getxattr(path, GFARM_ACL_TYPE_ACCESS, + value, sizep)); + else if (strcmp(name, ACL_EA_DEFAULT) == 0) + return (__acl_getxattr(path, GFARM_ACL_TYPE_DEFAULT, + value, sizep)); + else + return (gfs_lgetxattr_cached(path, name, value, sizep)); } -#else /* ENABLE_GFARM_ACL */ -/* ----- disable ACL ----------------------------------------------- */ gfarm_error_t -gfarm2fs_acl_setxattr(const char *path, const char *name, - const void *value, size_t size, int flags) +fix_acl_removexattr(const char *path, const char *name) { + if (strcmp(name, FIX_ACL_ACCESS) == 0) + return (gfs_lremovexattr(path, ACL_EA_ACCESS)); + else if (strcmp(name, FIX_ACL_DEFAULT) == 0) + return (gfs_lremovexattr(path, ACL_EA_DEFAULT)); + else if (strcmp(name, ACL_EA_ACCESS) == 0) + return (gfs_lremovexattr(path, GFARM_ACL_EA_ACCESS)); + else if (strcmp(name, ACL_EA_DEFAULT) == 0) + return (gfs_lremovexattr(path, GFARM_ACL_EA_DEFAULT)); + else + return (gfs_lremovexattr(path, name)); +} + +#endif /* ENABLE_GFARM_ACL */ + +/* ------------------------------- */ + +static gfarm_error_t +disable_acl_setxattr(const char *path, const char *name, + const void *value, size_t size, int flags) +{ if (strcmp(name, ACL_EA_ACCESS) == 0 || strcmp(name, ACL_EA_DEFAULT) == 0) return (GFARM_ERR_OPERATION_NOT_SUPPORTED); /* EOPNOTSUPP */ @@ -355,9 +399,9 @@ return (gfs_lsetxattr(path, name, value, size, flags)); } -gfarm_error_t -gfarm2fs_acl_getxattr(const char *path, const char *name, - void *value, size_t *sizep) +static gfarm_error_t +disable_acl_getxattr(const char *path, const char *name, + void *value, size_t *sizep) { if (strcmp(name, ACL_EA_ACCESS) == 0 || strcmp(name, ACL_EA_DEFAULT) == 0) @@ -366,16 +410,77 @@ return (gfs_lgetxattr_cached(path, name, value, sizep)); } +static gfarm_error_t +disable_acl_removexattr(const char *path, const char *name) +{ + return (gfs_lremovexattr(path, name)); +} + +/* ------------------------------- */ + +struct gfarm2fs_acl_sw { + gfarm_error_t (*set)(const char *path, const char *name, + const void *value, size_t size, int flags); + gfarm_error_t (*get)(const char *path, const char *name, + void *value, size_t *sizep); + gfarm_error_t (*remove)(const char *path, const char *name); + +}; + +#ifdef ENABLE_GFARM_ACL +static struct gfarm2fs_acl_sw sw_normal = { + normal_acl_setxattr, + normal_acl_getxattr, + normal_acl_removexattr, +}; + +static struct gfarm2fs_acl_sw sw_fix_xattr = { + fix_acl_setxattr, + fix_acl_getxattr, + fix_acl_removexattr, +}; +#endif /* ENABLE_GFARM_ACL */ + +static struct gfarm2fs_acl_sw sw_disable = { + disable_acl_setxattr, + disable_acl_getxattr, + disable_acl_removexattr, +}; + +static struct gfarm2fs_acl_sw *funcs = &sw_disable; + gfarm_error_t +gfarm2fs_acl_setxattr(const char *path, const char *name, + const void *value, size_t size, int flags) +{ + return ((*funcs->set)(path, name, value, size, flags)); +} + +gfarm_error_t +gfarm2fs_acl_getxattr(const char *path, const char *name, + void *value, size_t *sizep) +{ + return ((*funcs->get)(path, name, value, sizep)); +} + +gfarm_error_t gfarm2fs_acl_removexattr(const char *path, const char *name) { - return (gfs_lremovexattr(path, name)); + return ((*funcs->remove)(path, name)); } void gfarm2fs_acl_init(struct gfarm2fs_param *params) { - /* do nothing */ +#ifdef ENABLE_GFARM_ACL + if (params->disable_acl) + funcs = &sw_disable; + else if (params->fix_acl) + funcs = &sw_fix_xattr; + else { + funcs = &sw_normal; + gfarm_xattr_caching_pattern_add(GFARM_ACL_EA_ACCESS); + gfarm_xattr_caching_pattern_add(GFARM_ACL_EA_DEFAULT); + } +#endif } - -#endif /* ENABLE_GFARM_ACL */ Modified: gfarm2fs/trunk/acl.h =================================================================== --- gfarm2fs/trunk/acl.h 2011-03-29 08:04:55 UTC (rev 5238) +++ gfarm2fs/trunk/acl.h 2011-03-29 12:01:01 UTC (rev 5239) @@ -15,3 +15,11 @@ gfarm_error_t gfarm2fs_acl_getxattr(const char *, const char *, void *, size_t *); gfarm_error_t gfarm2fs_acl_removexattr(const char *, const char *); + +static const char ACL_EA_ACCESS[] = "system.posix_acl_access"; +static const char ACL_EA_DEFAULT[] = "system.posix_acl_default"; + +#define ACL_EA_VERSION (0x0002) /* Linux ACL Version */ + +static const char FIX_ACL_ACCESS[] = "gfarm2fs.fix_acl_access"; +static const char FIX_ACL_DEFAULT[] = "gfarm2fs.fix_acl_default"; Modified: gfarm2fs/trunk/gfarm2fs.c =================================================================== --- gfarm2fs/trunk/gfarm2fs.c 2011-03-29 08:04:55 UTC (rev 5238) +++ gfarm2fs/trunk/gfarm2fs.c 2011-03-29 12:01:01 UTC (rev 5239) @@ -1622,6 +1622,7 @@ KEY_D, KEY_VERSION, KEY_HELP, + KEY_FIX_ACL, KEY_DISABLE_ACL, KEY_ENABLE_CACHED_ID, }; @@ -1644,6 +1645,7 @@ FUSE_OPT_KEY("--version", KEY_VERSION), FUSE_OPT_KEY("-h", KEY_HELP), FUSE_OPT_KEY("--help", KEY_HELP), + FUSE_OPT_KEY("fix_acl", KEY_FIX_ACL), FUSE_OPT_KEY("disable_acl", KEY_DISABLE_ACL), /* for debug */ FUSE_OPT_KEY("enable_cached_id", KEY_ENABLE_CACHED_ID), /* for debug */ GFARM2FS_OPT("auto_uid_min=%d", auto_uid_min, KEY_GFARM2FS_OPT), @@ -1722,6 +1724,15 @@ case KEY_D: paramsp->debug = 1; return (1); /* through */ + case KEY_FIX_ACL: + paramsp->fix_acl = 1; + return (0); + case KEY_DISABLE_ACL: + paramsp->disable_acl = 1; + return (0); + case KEY_ENABLE_CACHED_ID: + paramsp->enable_cached_id = 1; + return (0); case KEY_VERSION: fprintf(stderr, "GFARM2FS version %s\n", VERSION); #if FUSE_VERSION >= 25 @@ -1734,8 +1745,6 @@ fuse_opt_add_arg(outargs, "-ho"); gfarm2fs_fuse_main(outargs, NULL); exit(1); - case KEY_DISABLE_ACL: - paramsp->disable_acl = 1; default: return (0); } @@ -1762,6 +1771,7 @@ .ncopy = 0, .disable_acl = 0, /* for debug */ .enable_cached_id = 0, /* for debug */ + .fix_acl = 0, .auto_uid_min = 70000, .auto_uid_max = 79999, .auto_gid_min = 70000, Modified: gfarm2fs/trunk/gfarm2fs.h =================================================================== --- gfarm2fs/trunk/gfarm2fs.h 2011-03-29 08:04:55 UTC (rev 5238) +++ gfarm2fs/trunk/gfarm2fs.h 2011-03-29 12:01:01 UTC (rev 5239) @@ -12,6 +12,7 @@ char *loglevel; int ncopy; int copy_limit; + int fix_acl; int disable_acl; int enable_cached_id; int auto_uid_min; Added: gfarm2fs/trunk/gfarm2fs_fix_acl.c =================================================================== --- gfarm2fs/trunk/gfarm2fs_fix_acl.c (rev 0) +++ gfarm2fs/trunk/gfarm2fs_fix_acl.c 2011-03-29 12:01:01 UTC (rev 5239) @@ -0,0 +1,259 @@ +/* + * $Id$ + */ + +#include "config.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <unistd.h> +#include <libgen.h> +#include <sys/types.h> +#include <sys/stat.h> + +#undef PACKAGE_NAME +#undef PACKAGE_STRING +#undef PACKAGE_TARNAME +#undef PACKAGE_VERSION +#include <gfarm/gfarm.h> + +#if defined(HAVE_SYS_ACL_H) && defined(HAVE_SYS_XATTR_H) +#define ENABLE_ACL +#endif + +#ifdef ENABLE_ACL +#include <attr/xattr.h> +#include <sys/acl.h> + +#include "gfarm2fs.h" +#include "acl.h" + +static char *progname = "gfarm2fs_fix_acl"; + +static gfarm_error_t +mode_from_posix_acl_xattr(const char *path, const void *posix_xattr_value, + size_t size, mode_t *modep) +{ + gfarm_error_t e; + const void *p = posix_xattr_value; + const void *endp = p + size; + gfarm_uint32_t version, id; + gfarm_uint16_t tag, perm; + mode_t mode = 0; + + memcpy(&version, p, sizeof(version)); + p += sizeof(version); + if (p > endp) + return (GFARM_ERR_INVALID_ARGUMENT); + if (gfarm_ltoh_32(version) != ACL_EA_VERSION) + return (GFARM_ERR_INVALID_ARGUMENT); + e = GFARM_ERR_NO_ERROR; + while (p < endp) { + memcpy(&tag, p, sizeof(tag)); + p += sizeof(tag); + memcpy(&perm, p, sizeof(perm)); + p += sizeof(perm); + memcpy(&id, p, sizeof(id)); + p += sizeof(id); + + tag = gfarm_ltoh_16(tag); + perm = gfarm_ltoh_16(perm); + + switch (tag) { + case ACL_USER_OBJ: + mode |= perm << 6; + break; + case ACL_GROUP_OBJ: + mode |= perm << 3; + break; + case ACL_OTHER: + mode |= perm; + break; + case ACL_USER: + case ACL_GROUP: + case ACL_MASK: + /* do nothing */ + break; + default: + e = GFARM_ERR_INVALID_ARGUMENT; + break; + } + } + *modep = mode; + + return (e); +} + +static int +check_acl_access(const char *path, struct stat *stbufp, + int do_chmod, int do_remove) +{ + gfarm_error_t e; + ssize_t size, size2; + void *value; + mode_t mode; + int res; + + size = lgetxattr(path, FIX_ACL_ACCESS, NULL, 0); + if (size == -1) { + if (errno == ENODATA || errno == ENOATTR) + return (0); /* ignore */ + fprintf(stderr, "%s: lgetxattr(): %s\n", + path, strerror(errno)); + return (-1); + } + + if (!S_ISLNK(stbufp->st_mode)) { + GFARM_MALLOC_ARRAY(value, size); + if (value == NULL) { + fprintf(stderr, "%s: error: no memory\n", path); + return (-1); + } + size2 = lgetxattr(path, FIX_ACL_ACCESS, value, size); + if (size2 == -1) { + fprintf(stderr, "%s: lgetxattr(): %s\n", + path, strerror(errno)); + free(value); + return (-1); + } else if (size != size2) { + fprintf(stderr, + "%s: lgetxattr(): unexpected size\n", path); + free(value); + return (-1); + } + e = mode_from_posix_acl_xattr(path, value, size, &mode); + if (e != GFARM_ERR_NO_ERROR) { + fprintf(stderr, + "%s: mode_from_posix_acl_xattr(): %s\n", + path, gfarm_error_string(e)); + free(value); + return (-1); + } + free(value); + mode = (stbufp->st_mode & 07000) | mode; + printf("%s (%o): %s\n", ACL_EA_ACCESS, mode, path); + if (do_chmod) { + res = chmod(path ,mode); + if (res == -1) { + fprintf(stderr, "%s: chmod(): %s\n", + path, strerror(errno)); + return (-1); + } + printf("change mode: %o -> %o\n", + stbufp->st_mode & 07777, mode); + } + } else + printf("%s (symlink): %s\n", ACL_EA_ACCESS, path); + + if (do_remove) { + res = lremovexattr(path, FIX_ACL_ACCESS); + if (res == -1) { + fprintf(stderr, "%s: lremovexattr(): %s\n", + path, strerror(errno)); + return (-1); + } + } + + return (0); +} + +static int +check_acl_default(const char *path, struct stat *stbufp, int do_remove) +{ + ssize_t size; + int res; + + size = lgetxattr(path, FIX_ACL_DEFAULT, NULL, 0); + if (size == -1) { + if (errno == ENODATA || errno == ENOATTR) + return (0); /* ignore */ + fprintf(stderr, "%s: lgetxattr(): %s\n", + path, strerror(errno)); + return (-1); + } + printf("%s: %s\n", ACL_EA_DEFAULT, path); + if (do_remove) { + res = lremovexattr(path, FIX_ACL_DEFAULT); + if (res == -1) { + fprintf(stderr, "%s: lremovexattr(): %s\n", + path, strerror(errno)); + return (-1); + } + } + + return (0); +} + +static void +usage(FILE *out) +{ + fprintf(out, +"Fix the ACL extended attribute (xattr) problem on gfarm2fs-1.2.2 or older.\n" +"The wrong xattr exists if 'cp -p' or 'mv' have been used on gfarm2fs.\n" +"Usage: %s [-cr] filename\n" +" default: Print paths which have wrong xattrs. (do nothing)\n" +" -c: Do chmod() using system.posix_acl_access xattr.\n" +" -r: Remove useless system.posix_acl_{access,default} xattrs.\n" +" (Not remove gfarm.acl_{access,default} xattrs.)\n" +"Example: find . -exec %s -cr {} \\;\n", + progname, progname); +} + +int +main(int argc, char **argv) +{ + struct stat stbuf; + int i, c, res; + int do_chmod = 0, do_remove = 0, error = 0; + + if (argc > 0) + progname = basename(argv[0]); + while ((c = getopt(argc, argv, "crh?")) != -1) { + switch (c) { + case 'c': + do_chmod = 1; + break; + case 'r': + do_remove = 1; + break; + case 'h': + case '?': + usage(stdout); + return (0); + default: + usage(stderr); + return (1); + } + } + argc -= optind; + argv += optind; + if (argc <= 0) { + usage(stderr); + return (1); + } + + for (i = 0; i < argc; i++) { + char *path = argv[i]; + + res = lstat(path, &stbuf); + if (res == -1) { + fprintf(stderr, "%s: lstat(): %s\n", + path, strerror(errno)); + error++; + continue; + } + res = check_acl_access(path, &stbuf, do_chmod, do_remove); + if (res == 0) + res = check_acl_default(path, &stbuf, do_remove); + if (res == -1) + error++; + } + + return (error); +} + +#else +int main() { return (1); } +#endif Property changes on: gfarm2fs/trunk/gfarm2fs_fix_acl.c ___________________________________________________________________ Added: svn:keywords + Id Added: gfarm2fs/trunk/gfarm2fs_fix_acl.sh =================================================================== --- gfarm2fs/trunk/gfarm2fs_fix_acl.sh (rev 0) +++ gfarm2fs/trunk/gfarm2fs_fix_acl.sh 2011-03-29 12:01:01 UTC (rev 5239) @@ -0,0 +1,39 @@ +#!/bin/sh + +# +# $Id$ +# + +gfgroup_exist() { + group=$1 + user=$2 + + gfgroup -l $group | egrep " ${user} | ${user}\$" > /dev/null + return $? +} + +WHOAMI=`gfwhoami` +if gfgroup_exist gfarmroot $WHOAMI ; then + : +else + echo You\(${WHOAMI}\) do not belong to gfarmroot. 1>&2 + exit 1 +fi + +TMP=`mktemp -d` +if [ $? -ne 0 ]; then + echo cannot create a temporary directory. 1>&2 + exit 1 +fi + +gfarm2fs $TMP -o fix_acl +wait + +find $TMP -exec gfarm2fs_fix_acl -cr {} \; +retv=$? + +sleep 10 +fusermount -u $TMP +rmdir $TMP + +exit $retv Property changes on: gfarm2fs/trunk/gfarm2fs_fix_acl.sh ___________________________________________________________________ Added: svn:executable + * Added: svn:keywords + Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |