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