1 /* 2 BAREOS® - Backup Archiving REcovery Open Sourced 3 4 Copyright (C) 2001-2011 Free Software Foundation Europe e.V. 5 Copyright (C) 2011-2016 Planets Communications B.V. 6 Copyright (C) 2013-2016 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 * Kern Sibbald, August MMI 25 */ 26 /** 27 * @file 28 * Includes specific to the Director User Agent Server 29 */ 30 31 #ifndef BAREOS_DIRD_UA_H_ 32 #define BAREOS_DIRD_UA_H_ 1 33 34 #include "include/bareos.h" 35 #include "lib/bsock.h" 36 #include "lib/output_formatter.h" 37 38 class JobControlRecord; 39 class BareosDb; 40 class guid_list; 41 typedef struct s_tree_root TREE_ROOT; 42 typedef struct s_tree_node TREE_NODE; 43 44 namespace directordaemon { 45 46 class CatalogResource; 47 class ConsoleResource; 48 class PoolResource; 49 class StorageResource; 50 class ClientResource; 51 class JobResource; 52 class FilesetResource; 53 class ScheduleResource; 54 struct RestoreBootstrapRecord; 55 struct ua_cmdstruct; 56 class UnifiedStorageResource; 57 struct UserAcl; 58 59 class UaContext { 60 public: 61 BareosSocket* UA_sock; 62 BareosSocket* sd; 63 JobControlRecord* jcr; 64 BareosDb* db; 65 BareosDb* shared_db; /**< Shared database connection used by multiple ua's */ 66 BareosDb* private_db; /**< Private database connection only used by this ua */ 67 CatalogResource* catalog; 68 UserAcl* user_acl; /**< acl from console or user resource */ 69 POOLMEM* cmd; /**< Return command/name buffer */ 70 POOLMEM* args; /**< Command line arguments */ 71 POOLMEM* errmsg; /**< Store error message */ 72 guid_list* guid; /**< User and Group Name mapping cache */ 73 char* argk[MAX_CMD_ARGS]; /**< Argument keywords */ 74 char* argv[MAX_CMD_ARGS]; /**< Argument values */ 75 int argc; /**< Number of arguments */ 76 char** prompt; /**< List of prompts */ 77 int max_prompts; /**< Max size of list */ 78 int num_prompts; /**< Current number in list */ 79 int api; /**< For programs want an API */ 80 bool auto_display_messages; /**< If set, display messages */ 81 bool user_notified_msg_pending; /**< Set when user notified */ 82 bool automount; /**< If set, mount after label */ 83 bool quit; /**< If set, quit */ 84 bool verbose; /**< Set for normal UA verbosity */ 85 bool batch; /**< Set for non-interactive mode */ 86 bool gui; /**< Set if talking to GUI program */ 87 bool runscript; /**< Set if we are in runscript */ 88 uint32_t pint32_val; /**< Positive integer */ 89 int32_t int32_val; /**< Positive/negative */ 90 int64_t int64_val; /**< Big int */ 91 OutputFormatter* send; /**< object instance to handle output */ 92 93 private: 94 ua_cmdstruct* cmddef; /**< Definition of the currently executed command */ 95 96 bool AclAccessOk(int acl, 97 const char* item, 98 int len, 99 bool audit_event = false); 100 int RcodeToAcltype(int rcode); 101 void LogAuditEventAclFailure(int acl, const char* item); 102 void LogAuditEventAclSuccess(int acl, const char* item); SetCommandDefinition(ua_cmdstruct * cmdstruct)103 void SetCommandDefinition(ua_cmdstruct* cmdstruct) { cmddef = cmdstruct; } 104 105 public: 106 UaContext(); signal(int sig)107 void signal(int sig) { UA_sock->signal(sig); } 108 bool execute(ua_cmdstruct* cmd); 109 110 /* 111 * ACL check method. 112 */ 113 bool AclAccessOk(int rcode, const char* item, bool audit_event = false); 114 bool AclNoRestrictions(int acl); AclHasRestrictions(int acl)115 bool AclHasRestrictions(int acl) { return !AclNoRestrictions(acl); } 116 117 /* 118 * Resource retrieval methods including check on ACL. 119 */ 120 bool IsResAllowed(BareosResource* res); 121 BareosResource* GetResWithName(int rcode, 122 const char* name, 123 bool audit_event = false, 124 bool lock = true); 125 PoolResource* GetPoolResWithName(const char* name, 126 bool audit_event = true, 127 bool lock = true); 128 StorageResource* GetStoreResWithName(const char* name, 129 bool audit_event = true, 130 bool lock = true); 131 StorageResource* GetStoreResWithId(DBId_t id, 132 bool audit_event = true, 133 bool lock = true); 134 ClientResource* GetClientResWithName(const char* name, 135 bool audit_event = true, 136 bool lock = true); 137 JobResource* GetJobResWithName(const char* name, 138 bool audit_event = true, 139 bool lock = true); 140 FilesetResource* GetFileSetResWithName(const char* name, 141 bool audit_event = true, 142 bool lock = true); 143 CatalogResource* GetCatalogResWithName(const char* name, 144 bool audit_event = true, 145 bool lock = true); 146 ScheduleResource* GetScheduleResWithName(const char* name, 147 bool audit_event = true, 148 bool lock = true); 149 150 /* 151 * Audit event methods. 152 */ 153 bool AuditEventWanted(bool audit_event_enabled); 154 void LogAuditEventCmdline(); 155 156 /* 157 * The below are in ua_output.c 158 */ 159 void SendRawMsg(const char* msg); 160 void SendMsg(const char* fmt, ...); 161 void ErrorMsg(const char* fmt, ...); 162 void WarningMsg(const char* fmt, ...); 163 void InfoMsg(const char* fmt, ...); 164 void SendCmdUsage(const char* fmt, ...); 165 }; 166 167 /* 168 * Context for InsertTreeHandler() 169 */ 170 struct TreeContext { 171 TREE_ROOT* root = nullptr; /**< Root */ 172 TREE_NODE* node = nullptr; /**< Current node */ 173 TREE_NODE* avail_node = nullptr; /**< Unused node last insert */ 174 int cnt = 0; /**< Count for user feedback */ 175 bool all = false; /**< If set mark all as default */ 176 UaContext* ua = nullptr; 177 uint32_t FileEstimate = 0; /**< Estimate of number of files */ 178 uint32_t FileCount = 0; /**< Current count of files */ 179 uint32_t LastCount = 0; /**< Last count of files */ 180 uint32_t DeltaCount = 0; /**< Trigger for printing */ 181 182 TreeContext() = default; 183 ~TreeContext() = default; 184 }; 185 186 struct NameList { 187 char** name = nullptr; /**< List of names */ 188 int num_ids = 0; /**< Ids stored */ 189 int max_ids = 0; /**< Size of array */ 190 int num_del = 0; /**< Number deleted */ 191 int tot_ids = 0; /**< Total to process */ 192 193 NameList() = default; 194 ~NameList() = default; 195 }; 196 197 /* 198 * Context for restore job. 199 */ 200 struct RestoreContext { 201 utime_t JobTDate = {0}; 202 uint32_t TotalFiles = 0; 203 JobId_t JobId = 0; 204 char* backup_format = nullptr; 205 char* ClientName = nullptr; /**< Backup client */ 206 char* RestoreClientName = nullptr; /**< Restore client */ 207 char last_jobid[20]{0}; 208 POOLMEM* JobIds = nullptr; /**< User entered string of JobIds */ 209 POOLMEM* BaseJobIds = nullptr; /**< Base jobids */ 210 StorageResource* store = nullptr; 211 JobResource* restore_job = nullptr; 212 PoolResource* pool = nullptr; 213 int restore_jobs = 0; 214 uint32_t selected_files = 0; 215 char* comment = nullptr; 216 char* where = nullptr; 217 char* RegexWhere = nullptr; 218 char* replace = nullptr; 219 char* plugin_options = nullptr; 220 std::unique_ptr<RestoreBootstrapRecord> bsr; 221 POOLMEM* fname = nullptr; /**< Filename only */ 222 POOLMEM* path = nullptr; /**< Path only */ 223 POOLMEM* query = nullptr; 224 int fnl = 0; /**< Filename length */ 225 int pnl = 0; /**< Path length */ 226 bool found = false; 227 bool all = false; /**< Mark all as default */ 228 NameList name_list; 229 230 RestoreContext() = default; 231 ~RestoreContext() = default; 232 }; 233 234 /* 235 * Context for run job. 236 */ 237 class RunContext { 238 public: 239 char* backup_format = nullptr; 240 char* bootstrap = nullptr; 241 char* catalog_name = nullptr; 242 char* client_name = nullptr; 243 char* comment = nullptr; 244 char* fileset_name = nullptr; 245 char* jid = nullptr; 246 char* job_name = nullptr; 247 char* level_name = nullptr; 248 char* next_pool_name = nullptr; 249 char* plugin_options = nullptr; 250 char* pool_name = nullptr; 251 char* previous_job_name = nullptr; 252 char* regexwhere = nullptr; 253 char* restore_client_name = nullptr; 254 char* since = nullptr; 255 char* StoreName = nullptr; 256 char* verify_job_name = nullptr; 257 char* when = nullptr; 258 char* where = nullptr; 259 const char* replace = nullptr; 260 const char* verify_list = nullptr; 261 JobResource* job = nullptr; 262 JobResource* verify_job = nullptr; 263 JobResource* previous_job = nullptr; 264 UnifiedStorageResource* store = nullptr; 265 ClientResource* client = nullptr; 266 FilesetResource* fileset = nullptr; 267 PoolResource* pool = nullptr; 268 PoolResource* next_pool = nullptr; 269 CatalogResource* catalog = nullptr; 270 int Priority = 0; 271 int files = 0; 272 bool level_override = false; 273 bool pool_override = false; 274 bool spool_data = false; 275 bool accurate = false; 276 bool ignoreduplicatecheck = false; 277 bool cloned = false; 278 bool mod = false; 279 bool spool_data_set = false; 280 bool nextpool_set = false; 281 bool accurate_set = false; 282 bool ignoreduplicatecheck_set = false; 283 284 RunContext(); 285 ~RunContext(); 286 }; 287 288 } /* namespace directordaemon */ 289 #endif /* BAREOS_DIRD_UA_H_ */ 290