Jeremy C. Reed wrote: > > Here is an untested patch (or at least an idea :) that should help those > > who don't use raised securelevel. This patch needs some debug output for > > both chflags introduced here. > > > > Index: src/findlib/create_file.c > > I see my patch is missing a closing brace. And also it fails to return > error if no file flags. If someone will use this code, I will finish it > up.
I'm trying right now with the following patch. It is a bit of redundant code (error handling, flag restoring), but I think it should work... --- src/findlib/create_file.c.orig Tue May 2 16:48:16 2006 +++ src/findlib/create_file.c Tue Dec 12 22:50:22 2006 @@ -304,9 +304,42 @@ Dmsg2(130, "Hard link %s => %s\n", attr->ofname, attr->olname); if (link(attr->olname, attr->ofname) != 0) { berrno be; - Jmsg3(jcr, M_ERROR, 0, _("Could not hard link %s -> %s: ERR=%s\n"), - attr->ofname, attr->olname, be.strerror()); - return CF_ERROR; +#ifdef HAVE_CHFLAGS + struct stat s; + + /* + * If using BSD user flags, maybe has a file flag + * preventing this. So attempt to disable, retry link, + * and reset flags. + * Note that BSD securelevel may prevent disabling flag. + */ + + if (stat(attr->ofname, &s) == 0 && s.st_flags != 0 && + chflags(attr->ofname, 0) == 0) { + if (link(attr->olname, attr->ofname) != 0) { + /* restore original file flags even when linking failed */ + if (chflags(attr->ofname, s.st_flags) < 0) { + Jmsg2(jcr, M_ERROR, 0, _("Could not restore file flags for file %s: ERR=%s\n"), + attr->olname, be.strerror()); + } +#endif /* HAVE_CHFLAGS */ + Jmsg3(jcr, M_ERROR, 0, _("Could not hard link %s -> %s: ERR=%s\n"), + attr->ofname, attr->olname, be.strerror()); + return CF_ERROR; +#ifdef HAVE_CHFLAGS + } + /* finally restore original file flags */ + if (chflags(attr->ofname, s.st_flags) < 0) { + Jmsg2(jcr, M_ERROR, 0, _("Could not restore file flags for file %s: ERR=%s\n"), + attr->olname, be.strerror()); + } + } else { + Jmsg3(jcr, M_ERROR, 0, _("Could not hard link %s -> %s: ERR=%s\n"), + attr->ofname, attr->olname, be.strerror()); + return CF_ERROR; + } +#endif /* HAVE_CHFLAGS */ + } return CF_CREATED; #endif -- Oliver Lehmann http://www.pofo.de/ http://wishlist.ans-netz.de/ ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Bacula-users mailing list Bacula-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bacula-users