1 /*
2    BAREOS® - Backup Archiving REcovery Open Sourced
3 
4    Copyright (C) 2004-2008 Free Software Foundation Europe e.V.
5    Copyright (C) 2011-2012 Planets Communications B.V.
6    Copyright (C) 2013-2020 Bareos GmbH & Co. KG
7 
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12 
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    Affero General Public License for more details.
17 
18    You should have received a copy of the GNU Affero 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
21    02110-1301, USA.
22 */
23 /**
24  * @file
25  * Properties we use for getting and setting ACLs.
26  */
27 
28 #ifndef BAREOS_FINDLIB_ACL_H_
29 #define BAREOS_FINDLIB_ACL_H_
30 
31 /**
32  * Number of acl errors to report per job.
33  */
34 #define ACL_REPORT_ERR_MAX_PER_JOB 25
35 
36 /**
37  * Return codes from acl subroutines.
38  */
39 typedef enum
40 {
41   bacl_exit_fatal = -1,
42   bacl_exit_error = 0,
43   bacl_exit_ok = 1
44 } bacl_exit_code;
45 
46 /* For shorter ACL strings when possible, define BACL_WANT_SHORT_ACLS */
47 /* #define BACL_WANT_SHORT_ACLS */
48 
49 /* For numeric user/group ids when possible, define BACL_WANT_NUMERIC_IDS */
50 /* #define BACL_WANT_NUMERIC_IDS */
51 
52 /**
53  * We support the following types of ACLs
54  */
55 typedef enum
56 {
57   BACL_TYPE_NONE = 0,
58   BACL_TYPE_ACCESS = 1,
59   BACL_TYPE_DEFAULT = 2,
60   BACL_TYPE_DEFAULT_DIR = 3,
61   BACL_TYPE_EXTENDED = 4,
62   BACL_TYPE_NFS4 = 5
63 } bacl_type;
64 
65 /**
66  * This value is used as ostype when we encounter an invalid acl type.
67  * The way the code is build this should never happen.
68  */
69 #if !defined(ACL_TYPE_NONE)
70 #  define ACL_TYPE_NONE 0x0
71 #endif
72 
73 #if defined(HAVE_FREEBSD_OS) || defined(HAVE_DARWIN_OS) \
74     || defined(HAVE_HPUX_OS) || defined(HAVE_LINUX_OS)
75 #  define BACL_ENOTSUP EOPNOTSUPP
76 #elif defined(HAVE_IRIX_OS)
77 #  define BACL_ENOTSUP ENOSYS
78 #endif
79 
80 #define BACL_FLAG_SAVE_NATIVE 0x01
81 #define BACL_FLAG_SAVE_AFS 0x02
82 #define BACL_FLAG_RESTORE_NATIVE 0x04
83 #define BACL_FLAG_RESTORE_AFS 0x08
84 
85 struct acl_build_data_t {
86   uint32_t nr_errors;
87   uint32_t content_length;
88   POOLMEM* content;
89 };
90 
91 struct acl_parse_data_t {
92   uint32_t nr_errors;
93 };
94 
95 /**
96  * Internal tracking data.
97  */
98 struct AclData {
99   int filetype;
100   POOLMEM* last_fname;
101   uint32_t flags{}; /* See BACL_FLAG_* */
102   uint32_t current_dev{0};
103   bool first_dev{true};
104   union {
105     struct acl_build_data_t* build;
106     struct acl_parse_data_t* parse;
107   } u;
108 };
109 
110 bacl_exit_code SendAclStream(JobControlRecord* jcr,
111                              AclData* acl_data,
112                              int stream);
113 bacl_exit_code BuildAclStreams(JobControlRecord* jcr,
114                                AclData* acl_data,
115                                FindFilesPacket* ff_pkt);
116 bacl_exit_code parse_acl_streams(JobControlRecord* jcr,
117                                  AclData* acl_data,
118                                  int stream,
119                                  char* content,
120                                  uint32_t content_length);
121 
122 #endif
123