2 Bacula® - The Network Backup Solution
4 Copyright (C) 2004-2008 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version two of the GNU General Public
10 License as published by the Free Software Foundation and included
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of Kern Sibbald.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
29 * Functions to handle ACLs for bacula.
31 * We handle two different types of ACLs: access and default ACLS.
32 * On most systems that support default ACLs they only apply to directories.
34 * On some systems (eg. linux and FreeBSD) we must obtain the two ACLs
35 * independently, while others (eg. Solaris) provide both in one call.
37 * The Filed saves ACLs in their native format and uses different streams
38 * for all different platforms. Currently we only allow ACLs to be restored
39 * which were saved in the native format of the platform they are extracted
40 * on. Later on we might add conversion functions for mapping from one
41 * platform to an other or allow restores of systems that use the same
44 * Its also interesting to see what the exact format of acl text is on
45 * certain platforms and if they use they same encoding we might allow
46 * different platform streams to be decoded on an other similar platform.
47 * As we implement the decoding/restoring process as a big switch based
48 * on the stream number being passed in extending the switching code is
51 * Original written by Preben 'Peppe' Guldberg, December MMIV
52 * Major rewrite by Marco van Wieringen, November MMVIII
61 * List of supported OSs.
62 * Not sure if all the HAVE_XYZ_OS are correct for autoconf.
63 * The ones that says man page, are coded according to man pages only.
65 #if !defined(HAVE_ACL) /* ACL support is required, of course */ \
66 || !( defined(HAVE_AIX_OS) /* man page -- may need flags */ \
67 || defined(HAVE_DARWIN_OS) /* tested -- compile without flags */ \
68 || defined(HAVE_FREEBSD_OS) /* tested -- compile without flags */ \
69 || defined(HAVE_HPUX_OS) /* man page -- may need flags */ \
70 || defined(HAVE_IRIX_OS) /* man page -- compile without flags */ \
71 || defined(HAVE_LINUX_OS) /* tested -- compile with -lacl */ \
72 || defined(HAVE_OSF1_OS) /* man page -- may need -lpacl */ \
73 || defined(HAVE_SUN_OS) /* tested -- compile with -lsec */ \
77 * Entry points when compiled without support for ACLs or on an unsupported platform.
79 bool build_acl_streams(JCR *jcr, FF_PKT *ff_pkt)
81 Jmsg(jcr, M_FATAL, 0, _("ACL support not configured for your machine.\n"));
85 bool parse_acl_stream(JCR *jcr, int stream)
87 Jmsg(jcr, M_FATAL, 0, _("ACL support not configured for your machine.\n"));
94 * Send an ACL stream to the SD.
96 static bool send_acl_stream(JCR *jcr, int stream, int len)
98 BSOCK *sd = jcr->store_bsock;
100 #ifdef FD_NO_SEND_TEST
107 if (!sd->fsend("%ld %d 0", jcr->JobFiles, stream)) {
108 Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
115 * Send the buffer to the storage deamon
117 Dmsg1(400, "Backing up ACL <%s>\n", jcr->acl_data);
119 sd->msg = jcr->acl_data;
120 sd->msglen = len + 1;
124 Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
130 jcr->JobBytes += sd->msglen;
132 if (!sd->signal(BNET_EOD)) {
133 Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
139 Dmsg1(200, "ACL of file: %s successfully backed up!\n", jcr->last_fname);
144 #if defined(HAVE_AIX_OS)
146 #include <sys/access.h>
148 static bool aix_build_acl_streams(JCR *jcr, FF_PKT *ff_pkt)
153 if ((acl_text = acl_get(jcr->last_fname)) != NULL) {
154 len = pm_strcpy(jcr->acl_data, acl_text);
155 actuallyfree(acl_text);
157 return send_acl_stream(jcr, STREAM_ACL_AIX_TEXT, len);
163 static bool aix_parse_acl_stream(JCR *jcr, int stream)
165 if (acl_put(jcr->last_fname, jcr->acl_data, 0) != 0) {
172 #elif defined(HAVE_DARWIN_OS) \
173 || defined(HAVE_FREEBSD_OS) \
174 || defined(HAVE_IRIX_OS) \
175 || defined(HAVE_OSF1_OS) \
176 || defined(HAVE_LINUX_OS)
178 #include <sys/types.h>
180 #ifdef HAVE_SYS_ACL_H
183 #error "configure failed to detect availability of sys/acl.h"
186 /* On IRIX we can get shortened ACLs */
187 #if defined(HAVE_IRIX_OS) && defined(BACL_WANT_SHORT_ACLS)
188 #define acl_to_text(acl,len) acl_to_short_text((acl), (len))
191 /* In Linux we can get numeric and/or shorted ACLs */
192 #if defined(HAVE_LINUX_OS)
193 #if defined(BACL_WANT_SHORT_ACLS) && defined(BACL_WANT_NUMERIC_IDS)
194 #define BACL_ALTERNATE_TEXT (TEXT_ABBREVIATE|TEXT_NUMERIC_IDS)
195 #elif defined(BACL_WANT_SHORT_ACLS)
196 #define BACL_ALTERNATE_TEXT TEXT_ABBREVIATE
197 #elif defined(BACL_WANT_NUMERIC_IDS)
198 #define BACL_ALTERNATE_TEXT TEXT_NUMERIC_IDS
200 #ifdef BACL_ALTERNATE_TEXT
201 #include <acl/libacl.h>
202 #define acl_to_text(acl,len) (acl_to_any_text((acl), NULL, ',', BACL_ALTERNATE_TEXT))
207 * Some generic functions used by multiple OSes.
209 static acl_type_t bac_to_os_acltype(bacl_type acltype)
214 case BACL_TYPE_ACCESS:
215 ostype = ACL_TYPE_ACCESS;
217 case BACL_TYPE_DEFAULT:
218 ostype = ACL_TYPE_DEFAULT;
221 #ifdef ACL_TYPE_DEFAULT_DIR
222 case BACL_TYPE_DEFAULT_DIR:
224 * OSF1 has an additional acl type named ACL_TYPE_DEFAULT_DIR.
226 ostype = ACL_TYPE_DEFAULT_DIR;
229 #ifdef ACL_TYPE_EXTENDED
230 case BACL_TYPE_EXTENDED:
232 * MacOSX has an additional acl type named ACL_TYPE_EXTENDED.
234 ostype = ACL_TYPE_EXTENDED;
239 * This should never happen, as the per os version function only tries acl
240 * types supported on a certain platform.
242 ostype = (acl_type_t)ACL_TYPE_NONE;
249 #if !defined(HAVE_DARWIN_OS)
251 * See if an acl is a trivial one (e.g. just the stat bits encoded as acl.)
252 * There is no need to store those acls as we already store the stat bits too.
254 static bool acl_is_trivial(acl_t acl)
257 * acl is trivial if it has only the following entries:
264 #if defined(HAVE_FREEBSD_OS) || defined(HAVE_LINUX_OS)
267 entry_available = acl_get_entry(acl, ACL_FIRST_ENTRY, &ace);
268 while (entry_available == 1) {
270 * Get the tag type of this acl entry.
271 * If we fail to get the tagtype we call the acl non-trivial.
273 if (acl_get_tag_type(ace, &tag) < 0)
277 * Anything other the ACL_USER_OBJ, ACL_GROUP_OBJ or ACL_OTHER breaks the spell.
279 if (tag != ACL_USER_OBJ &&
280 tag != ACL_GROUP_OBJ &&
284 entry_available = acl_get_entry(acl, ACL_NEXT_ENTRY, &ace);
288 #elif defined(HAVE_IRIX_OS)
291 for (n = 0; n < acl->acl_cnt; n++) {
292 ace = &acl->acl_entry[n];
296 * Anything other the ACL_USER_OBJ, ACL_GROUP_OBJ or ACL_OTHER breaks the spell.
298 if (tag != ACL_USER_OBJ &&
299 tag != ACL_GROUP_OBJ &&
305 #elif defined(HAVE_OSF1_OS)
308 ace = acl->acl_first;
309 count = acl->acl_num;
312 tag = ace->entry->acl_type;
315 * Anything other the ACL_USER_OBJ, ACL_GROUP_OBJ or ACL_OTHER breaks the spell.
317 if (tag != ACL_USER_OBJ &&
318 tag != ACL_GROUP_OBJ &&
323 * On Tru64, perm can also contain non-standard bits such as
324 * PERM_INSERT, PERM_DELETE, PERM_MODIFY, PERM_LOOKUP, ...
326 if ((ace->entry->acl_perm & ~(ACL_READ | ACL_WRITE | ACL_EXECUTE)))
339 * Generic wrapper around acl_get_file call.
341 static int generic_get_acl_from_os(JCR *jcr, bacl_type acltype)
348 ostype = bac_to_os_acltype(acltype);
349 acl = acl_get_file(jcr->last_fname, ostype);
351 #if defined(HAVE_IRIX_OS)
353 * From observation, IRIX's acl_get_file() seems to return a
354 * non-NULL acl with a count field of -1 when a file has no ACL
355 * defined, while IRIX's acl_to_text() returns NULL when presented
358 * Checking the count in the acl structure before calling
359 * acl_to_text() lets us avoid error messages about files
360 * with no ACLs, without modifying the flow of the code used for
361 * other operating systems, and it saves making some calls
362 * to acl_to_text() besides.
364 if (acl->acl_cnt <= 0) {
365 pm_strcpy(jcr->acl_data, "");
371 #if !defined(HAVE_DARWIN_OS)
373 * Make sure this is not just a trivial ACL.
375 if (acltype == BACL_TYPE_ACCESS && acl_is_trivial(acl)) {
377 * The ACLs simply reflect the (already known) standard permissions
378 * So we don't send an ACL stream to the SD.
380 pm_strcpy(jcr->acl_data, "");
386 if ((acl_text = acl_to_text(acl, NULL)) != NULL) {
387 len = pm_strcpy(jcr->acl_data, acl_text);
395 Jmsg2(jcr, M_ERROR, 0, _("acl_to_text error on file \"%s\": ERR=%s\n"),
396 jcr->last_fname, be.bstrerror());
397 Dmsg2(100, "acl_to_text error file=%s ERR=%s\n",
398 jcr->last_fname, be.bstrerror());
400 pm_strcpy(jcr->acl_data, "");
407 * Handle errors gracefully.
410 #if defined(BACL_ENOTSUP)
413 * Not supported, just pretend there is nothing to see
415 pm_strcpy(jcr->acl_data, "");
420 Jmsg2(jcr, M_ERROR, 0, _("acl_get_file error on file \"%s\": ERR=%s\n"),
421 jcr->last_fname, be.bstrerror());
422 Dmsg2(100, "acl_get_file error file=%s ERR=%s\n",
423 jcr->last_fname, be.bstrerror());
425 pm_strcpy(jcr->acl_data, "");
431 * Generic wrapper around acl_set_file call.
433 static bool generic_set_acl_on_os(JCR *jcr, bacl_type acltype)
439 * If we get empty default ACLs, clear ACLs now
441 ostype = bac_to_os_acltype(acltype);
442 if (ostype == ACL_TYPE_DEFAULT && strlen(jcr->acl_data) == 0) {
443 if (acl_delete_def_file(jcr->last_fname) == 0) {
447 Jmsg2(jcr, M_ERROR, 0, _("acl_delete_def_file error on file \"%s\": ERR=%s\n"),
448 jcr->last_fname, be.bstrerror());
453 acl = acl_from_text(jcr->acl_data);
456 Jmsg2(jcr, M_ERROR, 0, _("acl_from_text error on file \"%s\": ERR=%s\n"),
457 jcr->last_fname, be.bstrerror());
458 Dmsg3(100, "acl_from_text error acl=%s file=%s ERR=%s\n",
459 jcr->acl_data, jcr->last_fname, be.bstrerror());
465 * FreeBSD always fails acl_valid() - at least on valid input...
466 * As it does the right thing, given valid input, just ignore acl_valid().
468 #ifndef HAVE_FREEBSD_OS
469 if (acl_valid(acl) != 0) {
471 Jmsg2(jcr, M_ERROR, 0, _("ac_valid error on file \"%s\": ERR=%s\n"),
472 jcr->last_fname, be.bstrerror());
473 Dmsg3(100, "acl_valid error acl=%s file=%s ERR=%s\n",
474 jcr->acl_data, jcr->last_fname, be.bstrerror());
482 * Restore the ACLs, but don't complain about links which really should
483 * not have attributes, and the file it is linked to may not yet be restored.
484 * This is only true for the old acl streams as in the new implementation we
485 * don't save acls of symlinks (which cannot have acls anyhow)
487 if (acl_set_file(jcr->last_fname, ostype, acl) != 0 && jcr->last_type != FT_LNK) {
489 Jmsg2(jcr, M_ERROR, 0, _("acl_set_file error on file \"%s\": ERR=%s\n"),
490 jcr->last_fname, be.bstrerror());
491 Dmsg3(100, "acl_set_file error acl=%s file=%s ERR=%s\n",
492 jcr->acl_data, jcr->last_fname, be.bstrerror());
503 * OS specific functions for handling different types of acl streams.
505 #if defined(HAVE_DARWIN_OS)
506 static bool darwin_build_acl_streams(JCR *jcr, FF_PKT *ff_pkt)
510 #if defined(ACL_TYPE_EXTENDED)
512 * On MacOS X, acl_get_file (name, ACL_TYPE_ACCESS)
513 * and acl_get_file (name, ACL_TYPE_DEFAULT)
514 * always return NULL / EINVAL. There is no point in making
515 * these two useless calls. The real ACL is retrieved through
516 * acl_get_file (name, ACL_TYPE_EXTENDED).
518 * Read access ACLs for files, dirs and links
520 if ((len = generic_get_acl_from_os(jcr, BACL_TYPE_EXTENDED)) < 0)
524 * Read access ACLs for files, dirs and links
526 if ((len = generic_get_acl_from_os(jcr, BACL_TYPE_ACCESS)) < 0)
530 if (!send_acl_stream(jcr, STREAM_ACL_DARWIN_ACCESS_ACL, len))
538 static bool darwin_parse_acl_stream(JCR *jcr, int stream)
541 case STREAM_UNIX_ACCESS_ACL:
542 case STREAM_ACL_DARWIN_ACCESS_ACL:
543 return generic_set_acl_on_os(jcr, BACL_TYPE_ACCESS);
548 #elif defined(HAVE_FREEBSD_OS)
549 static bool freebsd_build_acl_streams(JCR *jcr, FF_PKT *ff_pkt)
554 * Read access ACLs for files, dirs and links
556 if ((len = generic_get_acl_from_os(jcr, BACL_TYPE_ACCESS)) < 0)
560 if (!send_acl_stream(jcr, STREAM_ACL_FREEBSD_ACCESS_ACL, len))
565 * Directories can have default ACLs too
567 if (ff_pkt->type == FT_DIREND) {
568 if ((len = generic_get_acl_from_os(jcr, BACL_TYPE_DEFAULT)) < 0)
572 if (!send_acl_stream(jcr, STREAM_ACL_FREEBSD_DEFAULT_ACL, len))
580 static bool freebsd_parse_acl_stream(JCR *jcr, int stream)
583 case STREAM_UNIX_ACCESS_ACL:
584 case STREAM_ACL_FREEBSD_ACCESS_ACL:
585 return generic_set_acl_on_os(jcr, BACL_TYPE_ACCESS);
586 case STREAM_UNIX_DEFAULT_ACL:
587 case STREAM_ACL_FREEBSD_DEFAULT_ACL:
588 return generic_set_acl_on_os(jcr, BACL_TYPE_DEFAULT);
593 #elif defined(HAVE_IRIX_OS)
594 static bool irix_build_acl_streams(JCR *jcr, FF_PKT *ff_pkt)
599 * Read access ACLs for files, dirs and links
601 if ((len = generic_get_acl_from_os(jcr, BACL_TYPE_ACCESS)) < 0)
605 if (!send_acl_stream(jcr, STREAM_ACL_IRIX_ACCESS_ACL, len))
610 * Directories can have default ACLs too
612 if (ff_pkt->type == FT_DIREND) {
613 if ((len = generic_get_acl_from_os(jcr, BACL_TYPE_DEFAULT)) < 0)
617 if (!send_acl_stream(jcr, STREAM_ACL_IRIX_DEFAULT_ACL, len))
625 static bool irix_parse_acl_stream(JCR *jcr, int stream)
628 case STREAM_UNIX_ACCESS_ACL:
629 case STREAM_ACL_IRIX_ACCESS_ACL:
630 return generic_set_acl_on_os(jcr, BACL_TYPE_ACCESS);
631 case STREAM_UNIX_DEFAULT_ACL:
632 case STREAM_ACL_IRIX_DEFAULT_ACL:
633 return generic_set_acl_on_os(jcr, BACL_TYPE_DEFAULT);
638 #elif defined(HAVE_LINUX_OS)
639 static bool linux_build_acl_streams(JCR *jcr, FF_PKT *ff_pkt)
644 * Read access ACLs for files, dirs and links
646 if ((len = generic_get_acl_from_os(jcr, BACL_TYPE_ACCESS)) < 0)
650 if (!send_acl_stream(jcr, STREAM_ACL_LINUX_ACCESS_ACL, len))
655 * Directories can have default ACLs too
657 if (ff_pkt->type == FT_DIREND) {
658 if ((len = generic_get_acl_from_os(jcr, BACL_TYPE_DEFAULT)) < 0)
662 if (!send_acl_stream(jcr, STREAM_ACL_LINUX_DEFAULT_ACL, len))
670 static bool linux_parse_acl_stream(JCR *jcr, int stream)
673 case STREAM_UNIX_ACCESS_ACL:
674 case STREAM_ACL_LINUX_ACCESS_ACL:
675 return generic_set_acl_on_os(jcr, BACL_TYPE_ACCESS);
676 case STREAM_UNIX_DEFAULT_ACL:
677 case STREAM_ACL_LINUX_DEFAULT_ACL:
678 return generic_set_acl_on_os(jcr, BACL_TYPE_DEFAULT);
683 #elif defined(HAVE_OSF1_OS)
684 static bool tru64_build_acl_streams(JCR *jcr, FF_PKT *ff_pkt)
689 * Read access ACLs for files, dirs and links
691 if ((len = generic_get_acl_from_os(jcr, BACL_TYPE_ACCESS)) < 0)
695 if (!send_acl_stream(jcr, STREAM_ACL_TRU64_ACCESS_ACL, len))
700 * Directories can have default ACLs too
702 if (ff_pkt->type == FT_DIREND) {
703 if ((len = generic_get_acl_from_os(jcr, BACL_TYPE_DEFAULT)) < 0)
707 if (!send_acl_stream(jcr, STREAM_ACL_TRU64_DEFAULT_ACL, len))
712 * Tru64 has next to BACL_TYPE_DEFAULT also BACL_TYPE_DEFAULT_DIR acls.
713 * This is an inherited acl for all subdirs.
714 * See http://www.helsinki.fi/atk/unix/dec_manuals/DOC_40D/AQ0R2DTE/DOCU_018.HTM
715 * Section 21.5 Default ACLs
717 if ((len = generic_get_acl_from_os(jcr, BACL_TYPE_DEFAULT_DIR)) < 0)
721 if (!send_acl_stream(jcr, STREAM_ACL_TRU64_DEFAULT_DIR_ACL, len))
729 static bool tru64_parse_acl_stream(JCR *jcr, int stream)
732 case STREAM_UNIX_ACCESS_ACL:
733 case STREAM_ACL_TRU64_ACCESS_ACL:
734 return generic_set_acl_on_os(jcr, BACL_TYPE_ACCESS);
735 case STREAM_UNIX_DEFAULT_ACL:
736 case STREAM_ACL_TRU64_DEFAULT_ACL:
737 return generic_set_acl_on_os(jcr, BACL_TYPE_DEFAULT);
738 case STREAM_ACL_TRU64_DEFAULT_DIR_ACL:
739 return generic_set_acl_on_os(jcr, BACL_TYPE_DEFAULT_DIR);
743 #elif defined(HAVE_HPUX_OS)
744 #ifdef HAVE_SYS_ACL_H
747 #error "configure failed to detect availability of sys/acl.h"
753 * See if an acl is a trivial one (e.g. just the stat bits encoded as acl.)
754 * There is no need to store those acls as we already store the stat bits too.
756 static bool acl_is_trivial(int count, struct acl_entry *entries, struct stat sb)
761 for (n = 0; n < count; n++) {
765 * See if this acl just is the stat mode in acl form.
767 if (!((ace.uid == sb.st_uid && ace.gid == ACL_NSGROUP) ||
768 (ace.uid == ACL_NSUSER && ace.gid == sb.st_gid) ||
769 (ace.uid == ACL_NSUSER && ace.gid == ACL_NSGROUP)))
777 * OS specific functions for handling different types of acl streams.
779 static bool hpux_build_acl_streams(JCR *jcr, FF_PKT *ff_pkt)
782 struct acl_entry acls[NACLENTRIES];
785 if ((n = getacl(jcr->last_fname, 0, acls)) < 0) {
787 #if defined(BACL_ENOTSUP)
790 * Not supported, just pretend there is nothing to see
792 pm_strcpy(jcr->acl_data, "");
797 Jmsg2(jcr, M_ERROR, 0, _("getacl error on file \"%s\": ERR=%s\n"),
798 jcr->last_fname, be.bstrerror());
799 Dmsg2(100, "getacl error file=%s ERR=%s\n",
800 jcr->last_fname, be.bstrerror());
802 pm_strcpy(jcr->acl_data, "");
808 pm_strcpy(jcr->acl_data, "");
812 if ((n = getacl(jcr->last_fname, n, acls)) > 0) {
813 if (acl_is_trivial(n, acls, ff_pkt->statp)) {
815 * The ACLs simply reflect the (already known) standard permissions
816 * So we don't send an ACL stream to the SD.
818 pm_strcpy(jcr->acl_data, "");
822 if ((acl_text = acltostr(n, acls, FORM_SHORT)) != NULL) {
823 len = pm_strcpy(jcr->acl_data, acl_text);
824 actuallyfree(acl_text);
826 return send_acl_stream(jcr, STREAM_ACL_HPUX_ACL_ENTRY, len);
830 Jmsg2(jcr, M_ERROR, 0, _("acltostr error on file \"%s\": ERR=%s\n"),
831 jcr->last_fname, be.bstrerror());
832 Dmsg3(100, "acltostr error acl=%s file=%s ERR=%s\n",
833 jcr->acl_data, jcr->last_fname, be.bstrerror());
841 static bool hpux_parse_acl_stream(JCR *jcr, int stream)
844 struct acl_entry acls[NACLENTRIES];
846 n = strtoacl(jcr->acl_data, 0, NACLENTRIES, acls, ACL_FILEOWNER, ACL_FILEGROUP);
849 Jmsg2(jcr, M_ERROR, 0, _("strtoacl error on file \"%s\": ERR=%s\n"),
850 jcr->last_fname, be.bstrerror());
851 Dmsg3(100, "strtoacl error acl=%s file=%s ERR=%s\n",
852 jcr->acl_data, jcr->last_fname, be.bstrerror());
856 if (strtoacl(jcr->acl_data, n, NACLENTRIES, acls, ACL_FILEOWNER, ACL_FILEGROUP) != n) {
858 Jmsg2(jcr, M_ERROR, 0, _("strtoacl error on file \"%s\": ERR=%s\n"),
859 jcr->last_fname, be.bstrerror());
860 Dmsg3(100, "strtoacl error acl=%s file=%s ERR=%s\n",
861 jcr->acl_data, jcr->last_fname, be.bstrerror());
866 * Restore the ACLs, but don't complain about links which really should
867 * not have attributes, and the file it is linked to may not yet be restored.
868 * This is only true for the old acl streams as in the new implementation we
869 * don't save acls of symlinks (which cannot have acls anyhow)
871 if (setacl(jcr->last_fname, n, acls) != 0 && jcr->last_type != FT_LNK) {
873 Jmsg2(jcr, M_ERROR, 0, _("setacl error on file \"%s\": ERR=%s\n"),
874 jcr->last_fname, be.bstrerror());
875 Dmsg3(100, "setacl error acl=%s file=%s ERR=%s\n",
876 jcr->acl_data, jcr->last_fname, be.bstrerror());
884 #elif defined(HAVE_SUN_OS)
885 #ifdef HAVE_SYS_ACL_H
888 #error "configure failed to detect availability of sys/acl.h"
891 #if defined(HAVE_EXTENDED_ACL)
893 * We define some internals of the Solaris acl libs here as those
894 * are not exposed yet. Probably because they want us to see the
895 * acls as opague data. But as we need to support different platforms
896 * and versions of Solaris we need to expose some data to be able
897 * to determine the type of acl used to stuff it into the correct
898 * data stream. I know this is far from portable, but maybe the
899 * propper interface is exposed later on and we can get ride of
900 * this kludge. Newer versions of Solaris include sys/acl_impl.h
901 * which has implementation details of acls, if thats included we
902 * don't have to define it ourself.
904 #if !defined(_SYS_ACL_IMPL_H)
905 typedef enum acl_type {
912 * Two external references to functions in the libsec library function not in current include files.
915 int acl_type(acl_t *);
916 char *acl_strerror(int);
920 * As the new libsec interface with acl_totext and acl_fromtext also handles
921 * the old format from acltotext we can use the new functions even
922 * for acls retrieved and stored in the database with older fd versions. If the
923 * new interface is not defined (Solaris 9 and older we fall back to the old code)
925 static bool solaris_build_acl_streams(JCR *jcr, FF_PKT *ff_pkt)
930 bool stream_status = false;
933 * Get ACL info: don't bother allocating space if there is only a trivial ACL.
935 if (acl_get(jcr->last_fname, ACL_NO_TRIVIAL, &aclp) != 0) {
937 #if defined(BACL_ENOTSUP)
940 * Not supported, just pretend there is nothing to see
942 pm_strcpy(jcr->acl_data, "");
946 Jmsg2(jcr, M_ERROR, 0, _("acl_get error on file \"%s\": ERR=%s\n"),
947 jcr->last_fname, acl_strerror(errno));
948 Dmsg2(100, "acl_get error file=%s ERR=%s\n",
949 jcr->last_fname, acl_strerror(errno));
957 * The ACLs simply reflect the (already known) standard permissions
958 * So we don't send an ACL stream to the SD.
960 pm_strcpy(jcr->acl_data, "");
964 #if defined(ACL_SID_FMT)
966 * New format flag added in newer Solaris versions.
968 flags = ACL_APPEND_ID | ACL_COMPACT_FMT | ACL_SID_FMT;
970 flags = ACL_APPEND_ID | ACL_COMPACT_FMT;
971 #endif /* ACL_SID_FMT */
973 if ((acl_text = acl_totext(aclp, flags)) != NULL) {
974 len = pm_strcpy(jcr->acl_data, acl_text);
975 actuallyfree(acl_text);
977 switch (acl_type(aclp)) {
979 stream_status = send_acl_stream(jcr, STREAM_ACL_SOLARIS_ACLENT, len);
982 stream_status = send_acl_stream(jcr, STREAM_ACL_SOLARIS_ACE, len);
991 return stream_status;
994 static bool solaris_parse_acl_stream(JCR *jcr, int stream)
1000 case STREAM_UNIX_ACCESS_ACL:
1001 case STREAM_ACL_SOLARIS_ACLENT:
1002 case STREAM_ACL_SOLARIS_ACE:
1003 if ((error = acl_fromtext(jcr->acl_data, &aclp)) != 0) {
1004 Jmsg2(jcr, M_ERROR, 0, _("acl_fromtext error on file \"%s\": ERR=%s\n"),
1005 jcr->last_fname, acl_strerror(error));
1006 Dmsg3(100, "acl_fromtext error acl=%s file=%s ERR=%s\n",
1007 jcr->acl_data, jcr->last_fname, acl_strerror(error));
1012 * Validate that the conversion gave us the correct acl type.
1015 case STREAM_ACL_SOLARIS_ACLENT:
1016 if (acl_type(aclp) != ACLENT_T) {
1017 Jmsg1(jcr, M_ERROR, 0, _("wrong encoding of acl type in acl stream on file \"%s\"\n"),
1021 case STREAM_ACL_SOLARIS_ACE:
1022 if (acl_type(aclp) != ACE_T) {
1023 Jmsg1(jcr, M_ERROR, 0, _("wrong encoding of acl type in acl stream on file \"%s\"\n"),
1029 * Stream id which doesn't describe the type of acl which is encoded.
1035 * Restore the ACLs, but don't complain about links which really should
1036 * not have attributes, and the file it is linked to may not yet be restored.
1037 * This is only true for the old acl streams as in the new implementation we
1038 * don't save acls of symlinks (which cannot have acls anyhow)
1040 if ((error = acl_set(jcr->last_fname, aclp)) == -1 && jcr->last_type != FT_LNK) {
1041 Jmsg2(jcr, M_ERROR, 0, _("acl_set error on file \"%s\": ERR=%s\n"),
1042 jcr->last_fname, acl_strerror(error));
1043 Dmsg3(100, "acl_set error acl=%s file=%s ERR=%s\n",
1044 jcr->acl_data, jcr->last_fname, acl_strerror(error));
1054 } /* end switch (stream) */
1057 #else /* HAVE_EXTENDED_ACL */
1060 * See if an acl is a trivial one (e.g. just the stat bits encoded as acl.)
1061 * There is no need to store those acls as we already store the stat bits too.
1063 static bool acl_is_trivial(int count, aclent_t *entries)
1068 for (n = 0; n < count; n++) {
1071 if (!(ace->a_type == USER_OBJ ||
1072 ace->a_type == GROUP_OBJ ||
1073 ace->a_type == OTHER_OBJ ||
1074 ace->a_type == CLASS_OBJ))
1082 * OS specific functions for handling different types of acl streams.
1084 static bool solaris_build_acl_streams(JCR *jcr, FF_PKT *ff_pkt);
1090 n = acl(jcr->last_fname, GETACLCNT, 0, NULL);
1091 if (n < MIN_ACL_ENTRIES) {
1094 acls = (aclent_t *)malloc(n * sizeof(aclent_t));
1095 if (acl(jcr->last_fname, GETACL, n, acls) == n) {
1096 if (acl_is_trivial(n, acls)) {
1098 * The ACLs simply reflect the (already known) standard permissions
1099 * So we don't send an ACL stream to the SD.
1102 pm_strcpy(jcr->acl_data, "");
1106 if ((acl_text = acltotext(acls, n)) != NULL) {
1107 len = pm_strcpy(jcr->acl_data, acl_text);
1108 actuallyfree(acl_text);
1111 return send_acl_stream(jcr, STREAM_ACL_SOLARIS_ACLENT, len);
1115 Jmsg2(jcr, M_ERROR, 0, _("acltotext error on file \"%s\": ERR=%s\n"),
1116 jcr->last_fname, be.bstrerror());
1117 Dmsg3(100, "acltotext error acl=%s file=%s ERR=%s\n",
1118 jcr->acl_data, jcr->last_fname, be.bstrerror());
1125 static bool solaris_parse_acl_stream(JCR *jcr, int stream)
1130 acls = aclfromtext(jcr->acl_data, &n);
1133 Jmsg2(jcr, M_ERROR, 0, _("aclfromtext error on file \"%s\": ERR=%s\n"),
1134 jcr->last_fname, be.bstrerror());
1135 Dmsg3(100, "aclfromtext error acl=%s file=%s ERR=%s\n",
1136 jcr->acl_data, jcr->last_fname, be.bstrerror());
1142 * Restore the ACLs, but don't complain about links which really should
1143 * not have attributes, and the file it is linked to may not yet be restored.
1145 if (acl(jcr->last_fname, SETACL, n, acls) == -1 && jcr->last_type != FT_LNK) {
1147 Jmsg2(jcr, M_ERROR, 0, _("acl(SETACL) error on file \"%s\": ERR=%s\n"),
1148 jcr->last_fname, be.bstrerror());
1149 Dmsg3(100, "acl(SETACL) error acl=%s file=%s ERR=%s\n",
1150 jcr->acl_data, jcr->last_fname, be.bstrerror());
1160 #endif /* HAVE_EXTENDED_ACL */
1161 #endif /* HAVE_SUN_OS */
1164 * Entry points when compiled with support for ACLs on a supported platform.
1168 * Read and send an ACL for the last encountered file.
1170 bool build_acl_streams(JCR *jcr, FF_PKT *ff_pkt)
1173 * Call the appropriate function, the ifdefs make sure the proper code is compiled.
1175 #if defined(HAVE_AIX_OS)
1176 return aix_build_acl_streams(jcr, ff_pkt);
1177 #elif defined(HAVE_DARWIN_OS)
1178 return darwin_build_acl_streams(jcr, ff_pkt);
1179 #elif defined(HAVE_FREEBSD_OS)
1180 return freebsd_build_acl_streams(jcr, ff_pkt);
1181 #elif defined(HAVE_HPUX_OS)
1182 return hpux_build_acl_streams(jcr, ff_pkt);
1183 #elif defined(HAVE_IRIX_OS)
1184 return irix_build_acl_streams(jcr, ff_pkt);
1185 #elif defined(HAVE_LINUX_OS)
1186 return linux_build_acl_streams(jcr, ff_pkt);
1187 #elif defined(HAVE_OSF1_OS)
1188 return tru64_build_acl_streams(jcr, ff_pkt);
1189 #elif defined(HAVE_SUN_OS)
1190 return solaris_build_acl_streams(jcr, ff_pkt);
1194 bool parse_acl_stream(JCR *jcr, int stream)
1197 * Based on the stream being passed in dispatch to the right function
1198 * for parsing and restoring a specific acl. The platform determines
1199 * which streams are recognized and parsed and which are handled by
1200 * the default case and ignored. The old STREAM_UNIX_ACCESS_ACL and
1201 * STREAM_UNIX_DEFAULT_ACL is handled as a legacy stream by each function.
1202 * As only one of the platform defines is true per compile we never end
1203 * up with duplicate switch values.
1206 #if defined(HAVE_AIX_OS)
1207 case STREAM_UNIX_ACCESS_ACL:
1208 case STREAM_UNIX_DEFAULT_ACL:
1209 case STREAM_ACL_AIX_TEXT:
1210 return aix_parse_acl_stream(jcr, stream);
1211 #elif defined(HAVE_DARWIN_OS)
1212 case STREAM_UNIX_ACCESS_ACL:
1213 case STREAM_ACL_DARWIN_ACCESS_ACL:
1214 return darwin_parse_acl_stream(jcr, stream);
1215 #elif defined(HAVE_FREEBSD_OS)
1216 case STREAM_UNIX_ACCESS_ACL:
1217 case STREAM_UNIX_DEFAULT_ACL:
1218 case STREAM_ACL_FREEBSD_DEFAULT_ACL:
1219 case STREAM_ACL_FREEBSD_ACCESS_ACL:
1220 return freebsd_parse_acl_stream(jcr, stream);
1221 #elif defined(HAVE_HPUX_OS)
1222 case STREAM_UNIX_ACCESS_ACL:
1223 case STREAM_ACL_HPUX_ACL_ENTRY:
1224 return hpux_parse_acl_stream(jcr, stream);
1225 #elif defined(HAVE_IRIX_OS)
1226 case STREAM_UNIX_ACCESS_ACL:
1227 case STREAM_UNIX_DEFAULT_ACL:
1228 case STREAM_ACL_IRIX_DEFAULT_ACL:
1229 case STREAM_ACL_IRIX_ACCESS_ACL:
1230 return irix_parse_acl_stream(jcr, stream);
1231 #elif defined(HAVE_LINUX_OS)
1232 case STREAM_UNIX_ACCESS_ACL:
1233 case STREAM_UNIX_DEFAULT_ACL:
1234 case STREAM_ACL_LINUX_DEFAULT_ACL:
1235 case STREAM_ACL_LINUX_ACCESS_ACL:
1236 return linux_parse_acl_stream(jcr, stream);
1237 #elif defined(HAVE_OSF1_OS)
1238 case STREAM_UNIX_ACCESS_ACL:
1239 case STREAM_UNIX_DEFAULT_ACL:
1240 case STREAM_ACL_TRU64_DEFAULT_ACL:
1241 case STREAM_ACL_TRU64_ACCESS_ACL:
1242 case STREAM_ACL_TRU64_DEFAULT_DIR_ACL:
1243 return tru64_parse_acl_stream(jcr, stream);
1244 #elif defined(HAVE_SUN_OS)
1245 case STREAM_UNIX_ACCESS_ACL:
1246 case STREAM_ACL_SOLARIS_ACLENT:
1247 #if defined(HAVE_EXTENDED_ACL)
1248 case STREAM_ACL_SOLARIS_ACE:
1250 return solaris_parse_acl_stream(jcr, stream);
1254 * Issue a warning and discard the message. But pretend the restore was ok.
1256 Qmsg2(jcr, M_WARNING, 0,
1257 _("Can't restore ACLs of %s - incompatible acl stream encountered - %d\n"),
1258 jcr->last_fname, stream);
1260 } /* end switch (stream) */