+ return stream_status;
+}
+
+static bacl_exit_code solaris_parse_acl_streams(JCR *jcr, int stream)
+{
+ acl_t *aclp;
+ int acl_enabled, error;
+ berrno be;
+
+ switch (stream) {
+ case STREAM_UNIX_ACCESS_ACL:
+ case STREAM_ACL_SOLARIS_ACLENT:
+ case STREAM_ACL_SOLARIS_ACE:
+ /**
+ * First make sure the filesystem supports acls.
+ */
+ acl_enabled = pathconf(jcr->last_fname, _PC_ACL_ENABLED);
+ switch (acl_enabled) {
+ case 0:
+ Mmsg1(jcr->errmsg, _("Trying to restore acl on file \"%s\" on filesystem without acl support\n"),
+ jcr->last_fname);
+ return bacl_exit_error;
+ case -1:
+ switch (errno) {
+ case ENOENT:
+ return bacl_exit_ok;
+ default:
+ Mmsg2(jcr->errmsg, _("pathconf error on file \"%s\": ERR=%s\n"),
+ jcr->last_fname, be.bstrerror());
+ Dmsg3(100, "pathconf error acl=%s file=%s ERR=%s\n",
+ jcr->acl_data->content, jcr->last_fname, be.bstrerror());
+ return bacl_exit_error;
+ }
+ default:
+ /**
+ * On a filesystem with ACL support make sure this particilar ACL type can be restored.
+ */
+ switch (stream) {
+ case STREAM_ACL_SOLARIS_ACLENT:
+ /**
+ * An aclent can be restored on filesystems with _ACL_ACLENT_ENABLED or _ACL_ACE_ENABLED support.
+ */
+ if ((acl_enabled & (_ACL_ACLENT_ENABLED | _ACL_ACE_ENABLED)) == 0) {
+ Mmsg1(jcr->errmsg, _("Trying to restore acl on file \"%s\" on filesystem without aclent acl support\n"),
+ jcr->last_fname);
+ return bacl_exit_error;
+ }
+ break;
+ case STREAM_ACL_SOLARIS_ACE:
+ /**
+ * An ace can only be restored on a filesystem with _ACL_ACE_ENABLED support.
+ */
+ if ((acl_enabled & _ACL_ACE_ENABLED) == 0) {
+ Mmsg1(jcr->errmsg, _("Trying to restore acl on file \"%s\" on filesystem without ace acl support\n"),
+ jcr->last_fname);
+ return bacl_exit_error;
+ }
+ break;
+ default:
+ /**
+ * Stream id which doesn't describe the type of acl which is encoded.
+ */
+ break;
+ }
+ break;
+ }
+
+ if ((error = acl_fromtext(jcr->acl_data->content, &aclp)) != 0) {
+ Mmsg2(jcr->errmsg, _("acl_fromtext error on file \"%s\": ERR=%s\n"),
+ jcr->last_fname, acl_strerror(error));
+ Dmsg3(100, "acl_fromtext error acl=%s file=%s ERR=%s\n",
+ jcr->acl_data->content, jcr->last_fname, acl_strerror(error));
+ return bacl_exit_error;
+ }
+
+ /**
+ * Validate that the conversion gave us the correct acl type.
+ */
+ switch (stream) {
+ case STREAM_ACL_SOLARIS_ACLENT:
+ if (acl_type(aclp) != ACLENT_T) {
+ Mmsg1(jcr->errmsg, _("wrong encoding of acl type in acl stream on file \"%s\"\n"),
+ jcr->last_fname);
+ return bacl_exit_error;
+ }
+ break;
+ case STREAM_ACL_SOLARIS_ACE:
+ if (acl_type(aclp) != ACE_T) {
+ Mmsg1(jcr->errmsg, _("wrong encoding of acl type in acl stream on file \"%s\"\n"),
+ jcr->last_fname);
+ return bacl_exit_error;
+ }
+ break;
+ default:
+ /**
+ * Stream id which doesn't describe the type of acl which is encoded.
+ */
+ break;
+ }
+
+ /**
+ * Restore the ACLs, but don't complain about links which really should
+ * not have attributes, and the file it is linked to may not yet be restored.
+ * This is only true for the old acl streams as in the new implementation we
+ * don't save acls of symlinks (which cannot have acls anyhow)
+ */
+ if ((error = acl_set(jcr->last_fname, aclp)) == -1 && jcr->last_type != FT_LNK) {
+ switch (errno) {
+ case ENOENT:
+ acl_free(aclp);
+ return bacl_exit_ok;
+ default:
+ Mmsg2(jcr->errmsg, _("acl_set error on file \"%s\": ERR=%s\n"),
+ jcr->last_fname, acl_strerror(error));
+ Dmsg3(100, "acl_set error acl=%s file=%s ERR=%s\n",
+ jcr->acl_data->content, jcr->last_fname, acl_strerror(error));
+ acl_free(aclp);
+ return bacl_exit_error;
+ }
+ }
+
+ acl_free(aclp);
+ return bacl_exit_ok;
+ default:
+ return bacl_exit_error;
+ } /* end switch (stream) */
+}
+
+#else /* HAVE_EXTENDED_ACL */
+
+/**
+ * Define the supported ACL streams for this OS
+ */
+static int os_access_acl_streams[2] = { STREAM_ACL_SOLARIS_ACLENT };
+static int os_default_acl_streams[1] = { -1 };
+
+/**
+ * See if an acl is a trivial one (e.g. just the stat bits encoded as acl.)
+ * There is no need to store those acls as we already store the stat bits too.
+ */
+static bool acl_is_trivial(int count, aclent_t *entries)
+{
+ int n;
+ aclent_t *ace;
+
+ for (n = 0; n < count; n++) {
+ ace = &entries[n];
+
+ if (!(ace->a_type == USER_OBJ ||
+ ace->a_type == GROUP_OBJ ||
+ ace->a_type == OTHER_OBJ ||
+ ace->a_type == CLASS_OBJ))
+ return false;
+ }
+ return true;
+}
+
+/**
+ * OS specific functions for handling different types of acl streams.
+ */
+static bacl_exit_code solaris_build_acl_streams(JCR *jcr, FF_PKT *ff_pkt)
+{
+ int n;
+ aclent_t *acls;
+ char *acl_text;
+ berrno be;
+
+ n = acl(jcr->last_fname, GETACLCNT, 0, NULL);
+ if (n < MIN_ACL_ENTRIES)
+ return bacl_exit_error;
+
+ acls = (aclent_t *)malloc(n * sizeof(aclent_t));