From 9e56edb095db7b2b241747ae2fa84085445ee298 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 13 Dec 2004 14:58:39 +0000 Subject: [PATCH] Integrate Tim Oberfoell patch to ACLs to handle both the standard and default ACLs. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1761 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/baconfig.h | 6 ++- bacula/src/filed/backup.c | 92 +++++++++++++++++++++++--------- bacula/src/filed/restore.c | 35 +++++++++--- bacula/src/stored/authenticate.c | 2 +- 4 files changed, 101 insertions(+), 34 deletions(-) diff --git a/bacula/src/baconfig.h b/bacula/src/baconfig.h index 90033c84c6..a29c923807 100644 --- a/bacula/src/baconfig.h +++ b/bacula/src/baconfig.h @@ -135,7 +135,11 @@ #define STREAM_WIN32_GZIP_DATA 12 /* Gzipped Win32 BackupRead data */ #define STREAM_MACOS_FORK_DATA 13 /* Mac resource fork */ #define STREAM_HFSPLUS_ATTRIBUTES 14 /* Mac OS extra attributes */ -#define STREAM_UNIX_ATTRIBUTES_ACL 15 /* ACL attributes on UNIX */ +/*** FIXME ***/ +#define STREAM_UNIX_ATTRIBUTES_ACCESS_ACL 15 /* Standard ACL attributes on UNIX */ +#define STREAM_UNIX_ATTRIBUTES_DEFAULT_ACL 16 /* Default ACL attributes on UNIX */ +/*** FIXME ***/ + /* * File type (Bacula defined). diff --git a/bacula/src/filed/backup.c b/bacula/src/filed/backup.c index 8ede73770b..2ade1050b1 100644 --- a/bacula/src/filed/backup.c +++ b/bacula/src/filed/backup.c @@ -384,28 +384,32 @@ static int save_file(FF_PKT *ff_pkt, void *vjcr) #endif #ifdef HAVE_ACL + /*** FIXME ***/ /* ACL stream */ if (ff_pkt->flags & FO_ACL) { - POOLMEM *msgsave; - char *acl_text; + char *acl_text = NULL; + char *aclDef_text = NULL; + /* Read ACLs for files, dirs and links */ if (ff_pkt->type == FT_DIREND) { - /* Directory: Try for default ACL*/ - acl_t myAcl = acl_get_file(ff_pkt->fname, ACL_TYPE_DEFAULT); - if (!myAcl) { - Dmsg1(200, "No default ACL defined for directory: %s!\n", ff_pkt->fname); - /* If there is no default ACL get standard ACL */ - myAcl = acl_get_file(ff_pkt->fname, ACL_TYPE_ACCESS); - if (!myAcl) { - Jmsg1(jcr, M_WARNING, 0, "Error while trying to get ACL of directory: %s!\n", ff_pkt->fname); - } - } - acl_text = acl_to_any_text(myAcl, NULL, ',', TEXT_ABBREVIATE); - /* Free memory */ - acl_free(myAcl); + /* Directory: Check for default ACL*/ + acl_t myDefAcl = acl_get_file(ff_pkt->fname, ACL_TYPE_DEFAULT); + /* Check for Access ACL */ + acl_t myAccAcl = acl_get_file(ff_pkt->fname, ACL_TYPE_ACCESS); + if (!myDefAcl || !myAccAcl) { + Jmsg1(jcr, M_WARNING, 0, "Error while trying to get ACL of directory: %s!\n", ff_pkt->fname); + } + if(myDefAcl){ + aclDef_text = acl_to_any_text(myDefAcl, NULL, ',', TEXT_ABBREVIATE); + acl_free(myDefAcl); + } + if(myAccAcl){ + acl_text = acl_to_any_text(myAccAcl, NULL, ',', TEXT_ABBREVIATE); + acl_free(myAccAcl); + } } else { /* Files or links */ - acl_t myAcl = acl_get_file(ff_pkt->fname, ACL_TYPE_ACCESS); + acl_t myAcl = acl_get_file(ff_pkt->fname, ACL_TYPE_ACCESS); if (!myAcl) { Jmsg1(jcr, M_WARNING, 0, "Error while trying to get ACL of file: %s!\n", ff_pkt->fname); acl_free(myAcl); @@ -413,23 +417,23 @@ static int save_file(FF_PKT *ff_pkt, void *vjcr) acl_text = acl_to_any_text(myAcl, NULL, ',', TEXT_ABBREVIATE); acl_free(myAcl); } - + + POOLMEM *msgsave; + /* If there is an ACL, send it to the Storage daemon */ - if (acl_text) { + if (acl_text != NULL) { sd = jcr->store_bsock; pm_strcpy(&jcr->last_fname, ff_pkt->fname); - - /* - * Send ACL header - * - */ - if (!bnet_fsend(sd, "%ld %d 0", jcr->JobFiles, STREAM_UNIX_ATTRIBUTES_ACL)) { + + + // Send ACL header + if (!bnet_fsend(sd, "%ld %d 0", jcr->JobFiles, STREAM_UNIX_ATTRIBUTES_ACCESS_ACL)) { berrno be; Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"), bnet_strerror(sd)); return 0; } - + /* Send the buffer to the storage deamon */ msgsave = sd->msg; sd->msg = acl_text; @@ -452,7 +456,43 @@ static int save_file(FF_PKT *ff_pkt, void *vjcr) } } } - } + /* If there is an Default ACL, send it to the Storage daemon */ + if (aclDef_text != NULL) { + sd = jcr->store_bsock; + pm_strcpy(&jcr->last_fname, ff_pkt->fname); + + + // Send ACL header + if (!bnet_fsend(sd, "%ld %d 0", jcr->JobFiles, STREAM_UNIX_ATTRIBUTES_DEFAULT_ACL)) { + berrno be; + Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"), + bnet_strerror(sd)); + return 0; + } + + // Send the buffer to the storage deamon + msgsave = sd->msg; + sd->msg = aclDef_text; + sd->msglen = strlen(aclDef_text) + 1; + if (!bnet_send(sd)) { + berrno be; + sd->msg = msgsave; + sd->msglen = 0; + Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"), + bnet_strerror(sd)); + } else { + jcr->JobBytes += sd->msglen; + sd->msg = msgsave; + if (!bnet_sig(sd, BNET_EOD)) { + berrno be; + Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"), + bnet_strerror(sd)); + } else { + Dmsg1(200, "ACL of file: %s successfully backed up!\n", ff_pkt->fname); + } + } + } + } #endif /* Terminate any signature and send it to Storage daemon and the Director */ diff --git a/bacula/src/filed/restore.c b/bacula/src/filed/restore.c index f89537c085..d02a1647a1 100644 --- a/bacula/src/filed/restore.c +++ b/bacula/src/filed/restore.c @@ -442,10 +442,10 @@ void do_restore(JCR *jcr) #else non_support_finfo++; #endif - - case STREAM_UNIX_ATTRIBUTES_ACL: +/*** FIXME ***/ +case STREAM_UNIX_ATTRIBUTES_ACCESS_ACL: #ifdef HAVE_ACL - /* Recover ACL from stream and check it */ + /* Recover Acess ACL from stream and check it */ acl = acl_from_text(sd->msg); if (acl_valid(acl) != 0) { Jmsg1(jcr, M_WARNING, 0, "Failure in the ACL of %s! FD is not able to restore it!\n", jcr->last_fname); @@ -455,8 +455,7 @@ void do_restore(JCR *jcr) /* Try to restore ACL */ if (attr->type == FT_DIREND) { /* Directory */ - if (acl_set_file(jcr->last_fname, ACL_TYPE_DEFAULT, acl) != 0 && - acl_set_file(jcr->last_fname, ACL_TYPE_ACCESS, acl) != 0) { + if (acl_set_file(jcr->last_fname, ACL_TYPE_ACCESS, acl) != 0) { Jmsg1(jcr, M_WARNING, 0, "Error! Can't restore ACL of directory: %s! Maybe system does not support ACLs!\n", jcr->last_fname); } /* File or Link */ @@ -469,7 +468,31 @@ void do_restore(JCR *jcr) #else non_support_acl++; break; /* unconfigured, ignore */ -#endif +#endif + case STREAM_UNIX_ATTRIBUTES_DEFAULT_ACL: +#ifdef HAVE_ACL + /* Recover Default ACL from stream and check it */ + acl = acl_from_text(sd->msg); + if (acl_valid(acl) != 0) { + Jmsg1(jcr, M_WARNING, 0, "Failure in the Default ACL of %s! FD is not able to restore it!\n", jcr->last_fname); + acl_free(acl); + } + + /* Try to restore ACL */ + if (attr->type == FT_DIREND) { + /* Directory */ + if (acl_set_file(jcr->last_fname, ACL_TYPE_DEFAULT, acl) != 0) { + Jmsg1(jcr, M_WARNING, 0, "Error! Can't restore Default ACL of directory: %s! Maybe system does not support ACLs!\n", jcr->last_fname); + } + } + acl_free(acl); + Dmsg1(200, "Default ACL of file: %s successfully restored!", jcr->last_fname); + break; +#else + non_support_acl++; + break; /* unconfigured, ignore */ +#endif +/*** FIXME ***/ case STREAM_MD5_SIGNATURE: case STREAM_SHA1_SIGNATURE: diff --git a/bacula/src/stored/authenticate.c b/bacula/src/stored/authenticate.c index b053dcb93f..2216a6ba30 100644 --- a/bacula/src/stored/authenticate.c +++ b/bacula/src/stored/authenticate.c @@ -70,7 +70,7 @@ static int authenticate(int rcode, BSOCK *bs, JCR* jcr) director = NULL; unbash_spaces(dirname); LockRes(); - while ((director=(DIRRES *)GetNextRes(rcode, (RES *)director))) { + foreach_res(director, rcode) { if (strcmp(director->hdr.name, dirname) == 0) break; } -- 2.39.5