1 /* 2 BAREOS® - Backup Archiving REcovery Open Sourced 3 4 Copyright (C) 2018-2021 Bareos GmbH & Co. KG 5 6 This program is Free Software; you can redistribute it and/or 7 modify it under the terms of version three of the GNU Affero General Public 8 License as published by the Free Software Foundation and included 9 in the file LICENSE. 10 11 This program is distributed in the hope that it will be useful, but 12 WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Affero General Public License for more details. 15 16 You should have received a copy of the GNU Affero General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19 02110-1301, USA. 20 */ 21 #ifndef BAREOS_LIB_BSYS_H_ 22 #define BAREOS_LIB_BSYS_H_ 23 24 char* bstrinlinecpy(char* dest, const char* src); 25 char* bstrncpy(char* dest, const char* src, int maxlen); 26 char* bstrncpy(char* dest, PoolMem& src, int maxlen); 27 char* bstrncat(char* dest, const char* src, int maxlen); 28 char* bstrncat(char* dest, PoolMem& src, int maxlen); 29 bool bstrcmp(const char* s1, const char* s2); 30 bool bstrncmp(const char* s1, const char* s2, int n); 31 bool Bstrcasecmp(const char* s1, const char* s2); 32 bool bstrncasecmp(const char* s1, const char* s2, int n); 33 int cstrlen(const char* str); 34 int Bsnprintf(char* str, int32_t size, const char* format, ...); 35 int Bvsnprintf(char* str, int32_t size, const char* format, va_list ap); 36 int PoolSprintf(char* pool_buf, const char* fmt, ...); 37 void CreatePidFile(char* dir, const char* progname, int port); 38 int DeletePidFile(char* dir, const char* progname, int port); 39 void drop(char* uid, char* gid, bool keep_readall_caps); 40 int Bmicrosleep(int32_t sec, int32_t usec); 41 char* bfgets(char* s, int size, FILE* fd); 42 char* bfgets(POOLMEM*& s, FILE* fd); 43 void MakeUniqueFilename(POOLMEM*& name, int Id, char* what); 44 void ReadStateFile(const char* dir, const char* progname, int port); 45 int b_strerror(int errnum, char* buf, size_t bufsiz); 46 char* escape_filename(const char* file_path); 47 int Zdeflate(char* in, int in_len, char* out, int& out_len); 48 int Zinflate(char* in, int in_len, char* out, int& out_len); 49 void stack_trace(); 50 int SaferUnlink(const char* pathname, const char* regex); 51 int SecureErase(JobControlRecord* jcr, const char* pathname); 52 void SetSecureEraseCmdline(const char* cmdline); 53 bool PathExists(const char* path); 54 bool PathExists(PoolMem& path); 55 bool PathIsDirectory(const char* path); 56 bool PathIsDirectory(PoolMem& path); 57 bool PathContainsDirectory(const char* path); 58 bool PathContainsDirectory(PoolMem& path); 59 bool PathIsAbsolute(const char* path); 60 bool PathIsAbsolute(PoolMem& path); 61 bool PathGetDirectory(PoolMem& directory, PoolMem& path); 62 bool PathAppend(char* path, const char* extra, unsigned int max_path); 63 bool PathAppend(PoolMem& path, const char* extra); 64 bool PathAppend(PoolMem& path, PoolMem& extra); 65 bool PathCreate(const char* path, mode_t mode = 0750); 66 bool PathCreate(PoolMem& path, mode_t mode = 0750); 67 68 struct StateFileHeader { 69 char id[14]; 70 int32_t version; 71 uint64_t last_jobs_addr; 72 uint64_t end_of_recent_job_results_list; 73 uint64_t reserved[19]; 74 }; 75 76 static_assert(offsetof(StateFileHeader, version) == 16, 77 "StateFileHeader.version offset"); 78 static_assert(offsetof(StateFileHeader, last_jobs_addr) == 20 79 || offsetof(StateFileHeader, last_jobs_addr) == 24, 80 "StageFileHeader.last_jobs_addr offset"); 81 static_assert(offsetof(StateFileHeader, end_of_recent_job_results_list) == 28 82 || offsetof(StateFileHeader, end_of_recent_job_results_list) 83 == 32, 84 "StateFileHeader.end_of_recent_job_results_list offset"); 85 static_assert(offsetof(StateFileHeader, reserved) == 36 86 || offsetof(StateFileHeader, reserved) == 40, 87 "StateFileHeader.reserved offset"); 88 #endif // BAREOS_LIB_BSYS_H_ 89