]> git.sur5r.net Git - bacula/bacula/commitdiff
Integrate Tim Oberfoell <oberfoell@web.de> patch to ACLs
authorKern Sibbald <kern@sibbald.com>
Mon, 13 Dec 2004 14:58:39 +0000 (14:58 +0000)
committerKern Sibbald <kern@sibbald.com>
Mon, 13 Dec 2004 14:58:39 +0000 (14:58 +0000)
  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
bacula/src/filed/backup.c
bacula/src/filed/restore.c
bacula/src/stored/authenticate.c

index 90033c84c690ddc3e7e21e85d49f979bd07cd91f..a29c9238078b03d0244c5c453b956405144bc10e 100644 (file)
 #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).           
index 8ede73770b86a2b280874847ff75c4f6bd7c17b5..2ade1050b1a467cd6deb79c4b90551b75222bc4d 100644 (file)
@@ -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 */
index f89537c08550f4c35b810830651cd18d85b92286..d02a1647a1eda470e9cadf11642433fe14f4341d 100644 (file)
@@ -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:
index b053dcb93f2a89f22fcf33b591b760b93252ad59..2216a6ba30256a34b3f4dae9155829209634ac31 100644 (file)
@@ -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;
    }