From 2e82d69712f86ec6ed0362c3719bb7c4371c6aae Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Fri, 31 Aug 2018 13:47:24 +0200 Subject: [PATCH] config: added global and static methods from res.cc to ConfigurationParser - methods now working on the respective object instead of one global object (that was at this point my_config) - left methods from BareosResource untouched --- core/src/console/console_conf.cc | 4 +- core/src/dird/dird_conf.cc | 32 +- core/src/filed/filed_conf.cc | 4 +- core/src/include/baconfig.h | 4 +- core/src/lib/parse_conf.h | 866 ++++--- core/src/lib/res.cc | 3143 ++++++++++++------------- core/src/qt-tray-monitor/tray_conf.cc | 466 ++-- core/src/stored/stored_conf.cc | 14 +- 8 files changed, 2309 insertions(+), 2224 deletions(-) diff --git a/core/src/console/console_conf.cc b/core/src/console/console_conf.cc index c8776ef83e9..4ccd2d709f1 100644 --- a/core/src/console/console_conf.cc +++ b/core/src/console/console_conf.cc @@ -141,7 +141,7 @@ void DumpResource(int type, CommonResourceHeader *reshdr, bool recurse = true; if (res == NULL) { - sendit(sock, _("Warning: no \"%s\" resource (%d) defined.\n"), res_to_str(type), type); + sendit(sock, _("Warning: no \"%s\" resource (%d) defined.\n"), my_config->res_to_str(type), type); return; } if (type < 0) { /* no recursion */ @@ -364,7 +364,7 @@ bool SaveResource(int type, ResourceItem *items, int pass) } } last->next = (CommonResourceHeader *)res; - Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type), res->res_dir.name()); + Dmsg2(90, "Inserting %s res: %s\n", my_config->res_to_str(type), res->res_dir.name()); } } return (error == 0); diff --git a/core/src/dird/dird_conf.cc b/core/src/dird/dird_conf.cc index 49d01feddde..f7a3e732a22 100644 --- a/core/src/dird/dird_conf.cc +++ b/core/src/dird/dird_conf.cc @@ -1313,7 +1313,7 @@ bool ValidateResource(int res_type, ResourceItem *items, BareosResource *res) if (!BitIsSet(i, res->hdr.item_present)) { Jmsg(NULL, M_ERROR, 0, _("\"%s\" directive in %s \"%s\" resource is required, but not found.\n"), - items[i].name, res_to_str(res_type), res->name()); + items[i].name, my_config->res_to_str(res_type), res->name()); return false; } } @@ -1322,7 +1322,7 @@ bool ValidateResource(int res_type, ResourceItem *items, BareosResource *res) * If this triggers, take a look at lib/parse_conf.h */ if (i >= MAX_RES_ITEMS) { - Emsg1(M_ERROR, 0, _("Too many items in %s resource\n"), res_to_str(res_type)); + Emsg1(M_ERROR, 0, _("Too many items in %s resource\n"), my_config->res_to_str(res_type)); return false; } } @@ -2763,7 +2763,7 @@ static void StoreDevice(LEX *lc, ResourceItem *item, int index, int pass) res->res_dev.hdr.name = bstrdup(lc->str); res_head[rindex] = (CommonResourceHeader *)res; /* store first entry */ Dmsg3(900, "Inserting first %s res: %s index=%d\n", - res_to_str(R_DEVICE), res->res_dir.name(), rindex); + my_config->res_to_str(R_DEVICE), res->res_dir.name(), rindex); } else { CommonResourceHeader *next; /* @@ -2781,7 +2781,7 @@ static void StoreDevice(LEX *lc, ResourceItem *item, int index, int pass) res->res_dev.hdr.name = bstrdup(lc->str); next->next = (CommonResourceHeader *)res; Dmsg4(900, "Inserting %s res: %s index=%d pass=%d\n", - res_to_str(R_DEVICE), res->res_dir.name(), rindex, pass); + my_config->res_to_str(R_DEVICE), res->res_dir.name(), rindex, pass); } } @@ -2789,7 +2789,7 @@ static void StoreDevice(LEX *lc, ResourceItem *item, int index, int pass) SetBit(index, res_all.hdr.item_present); ClearBit(index, res_all.hdr.inherit_content); } else { - StoreResource(CFG_TYPE_ALIST_RES, lc, item, index, pass); + my_config->StoreResource(CFG_TYPE_ALIST_RES, lc, item, index, pass); } } @@ -2999,10 +2999,10 @@ static void StoreAutopassword(LEX *lc, ResourceItem *item, int index, int pass) */ switch (item->code) { case 1: - StoreResource(CFG_TYPE_CLEARPASSWORD, lc, item, index, pass); + my_config->StoreResource(CFG_TYPE_CLEARPASSWORD, lc, item, index, pass); break; default: - StoreResource(CFG_TYPE_MD5PASSWORD, lc, item, index, pass); + my_config->StoreResource(CFG_TYPE_MD5PASSWORD, lc, item, index, pass); break; } break; @@ -3011,10 +3011,10 @@ static void StoreAutopassword(LEX *lc, ResourceItem *item, int index, int pass) case APT_NDMPV2: case APT_NDMPV3: case APT_NDMPV4: - StoreResource(CFG_TYPE_CLEARPASSWORD, lc, item, index, pass); + my_config->StoreResource(CFG_TYPE_CLEARPASSWORD, lc, item, index, pass); break; default: - StoreResource(CFG_TYPE_MD5PASSWORD, lc, item, index, pass); + my_config->StoreResource(CFG_TYPE_MD5PASSWORD, lc, item, index, pass); break; } break; @@ -3023,18 +3023,18 @@ static void StoreAutopassword(LEX *lc, ResourceItem *item, int index, int pass) case APT_NDMPV2: case APT_NDMPV3: case APT_NDMPV4: - StoreResource(CFG_TYPE_CLEARPASSWORD, lc, item, index, pass); + my_config->StoreResource(CFG_TYPE_CLEARPASSWORD, lc, item, index, pass); break; default: - StoreResource(CFG_TYPE_MD5PASSWORD, lc, item, index, pass); + my_config->StoreResource(CFG_TYPE_MD5PASSWORD, lc, item, index, pass); break; } break; case R_CATALOG: - StoreResource(CFG_TYPE_CLEARPASSWORD, lc, item, index, pass); + my_config->StoreResource(CFG_TYPE_CLEARPASSWORD, lc, item, index, pass); break; default: - StoreResource(CFG_TYPE_MD5PASSWORD, lc, item, index, pass); + my_config->StoreResource(CFG_TYPE_MD5PASSWORD, lc, item, index, pass); break; } } @@ -3854,7 +3854,7 @@ void DumpResource(int type, CommonResourceHeader *ures, UaContext *ua = (UaContext *)sock; if (!res) { - sendit(sock, _("No %s resource defined\n"), res_to_str(type)); + sendit(sock, _("No %s resource defined\n"), my_config->res_to_str(type)); return; } @@ -4434,7 +4434,7 @@ bool SaveResource(int type, ResourceItem *items, int pass) memcpy(res, &res_all, resources[rindex].size); if (!res_head[rindex]) { res_head[rindex] = (CommonResourceHeader *)res; /* store first entry */ - Dmsg3(900, "Inserting first %s res: %s index=%d\n", res_to_str(type), + Dmsg3(900, "Inserting first %s res: %s index=%d\n", my_config->res_to_str(type), res->res_dir.name(), rindex); } else { CommonResourceHeader *next, *last; @@ -4456,7 +4456,7 @@ bool SaveResource(int type, ResourceItem *items, int pass) } } last->next = (CommonResourceHeader *)res; - Dmsg4(900, _("Inserting %s res: %s index=%d pass=%d\n"), res_to_str(type), + Dmsg4(900, _("Inserting %s res: %s index=%d pass=%d\n"), my_config->res_to_str(type), res->res_dir.name(), rindex, pass); } return true; diff --git a/core/src/filed/filed_conf.cc b/core/src/filed/filed_conf.cc index d5b4abfda7e..1c91d4a0071 100644 --- a/core/src/filed/filed_conf.cc +++ b/core/src/filed/filed_conf.cc @@ -353,7 +353,7 @@ void DumpResource(int type, CommonResourceHeader *reshdr, int recurse = 1; if (res == NULL) { - sendit(sock, "No record for %d %s\n", type, res_to_str(type)); + sendit(sock, "No record for %d %s\n", type, my_config->res_to_str(type)); return; } @@ -688,7 +688,7 @@ bool SaveResource(int type, ResourceItem *items, int pass) } } last->next = (CommonResourceHeader *)res; - Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type), + Dmsg2(90, "Inserting %s res: %s\n", my_config->res_to_str(type), res->res_dir.name()); } } diff --git a/core/src/include/baconfig.h b/core/src/include/baconfig.h index 311ee1de9e9..576f875b6a4 100644 --- a/core/src/include/baconfig.h +++ b/core/src/include/baconfig.h @@ -331,8 +331,8 @@ do { int errstat; if ((errstat=RwlWriteunlock(&(x)))) \ strerror(errstat)); \ } while(0) -#define LockRes() b_LockRes(__FILE__, __LINE__) -#define UnlockRes() b_UnlockRes(__FILE__, __LINE__) +#define LockRes() my_config->b_LockRes(__FILE__, __LINE__) +#define UnlockRes() my_config->b_UnlockRes(__FILE__, __LINE__) #ifdef DEBUG_MEMSET #define memset(a, v, n) b_memset(__FILE__, __LINE__, a, v, n) diff --git a/core/src/lib/parse_conf.h b/core/src/lib/parse_conf.h index e4807481375..c5fc438a2c6 100644 --- a/core/src/lib/parse_conf.h +++ b/core/src/lib/parse_conf.h @@ -30,192 +30,257 @@ #include -struct ResourceItem; /* Declare forward referenced structure */ -class CommonResourceHeader; /* Declare forward referenced structure */ +struct ResourceItem; /* Declare forward referenced structure */ +class CommonResourceHeader; /* Declare forward referenced structure */ /* * Parser state */ -enum parse_state { - p_none, - p_resource +enum parse_state +{ + p_none, + p_resource }; /* * Password encodings. */ -enum password_encoding { - p_encoding_clear, - p_encoding_md5 +enum password_encoding +{ + p_encoding_clear, + p_encoding_md5 }; /* * Used for message destinations. */ struct s_mdestination { - int code; - const char *destination; - bool where; + int code; + const char *destination; + bool where; }; /* * Used for message types. */ struct s_mtypes { - const char *name; - uint32_t token; + const char *name; + uint32_t token; }; /* * Used for certain KeyWord tables */ struct s_kw { - const char *name; - uint32_t token; + const char *name; + uint32_t token; }; /* * Used to store passwords with their encoding. */ struct s_password { - enum password_encoding encoding; - char *value; + enum password_encoding encoding; + char *value; }; /** * Common TLS-Settings for both (Certificate and PSK). -*/ -#define TLS_COMMON_CONFIG(res) \ - { "TlsAuthenticate", CFG_TYPE_BOOL, ITEM(res.tls_cert.authenticate), 0, CFG_ITEM_DEFAULT, "false", NULL, \ - "Use TLS only to authenticate, not for encryption." }, \ - { "TlsEnable", CFG_TYPE_BOOL, ITEM(res.tls_cert.enable), 0, CFG_ITEM_DEFAULT, "false", NULL, \ - "Enable TLS support." }, \ - { "TlsRequire", CFG_TYPE_BOOL, ITEM(res.tls_cert.require), 0, CFG_ITEM_DEFAULT, "false", NULL, \ - "Without setting this to yes, Bareos can fall back to use unencrypted connections. " \ - "Enabling this implicitly sets \"TLS Enable = yes\"." }, \ - { "TlsCipherList", CFG_TYPE_STR, ITEM(res.tls_cert.cipherlist), 0, CFG_ITEM_PLATFORM_SPECIFIC, NULL, NULL, \ - "List of valid TLS Ciphers." }, \ - { "TlsDhFile", CFG_TYPE_STDSTRDIR, ITEM(res.tls_cert.dhfile), 0, 0, NULL, NULL, \ - "Path to PEM encoded Diffie-Hellman parameter file. " \ - "If this directive is specified, DH key exchange will be used for the ephemeral keying, " \ - "allowing for forward secrecy of communications." } - - /* - * TLS Settings for Certificate only - */ - #define TLS_CERT_CONFIG(res) \ - { "TlsVerifyPeer", CFG_TYPE_BOOL, ITEM(res.tls_cert.VerifyPeer), 0, CFG_ITEM_DEFAULT, "false", NULL, \ - "If disabled, all certificates signed by a known CA will be accepted. " \ - "If enabled, the CN of a certificate must the Address or in the \"TLS Allowed CN\" list." }, \ - { "TlsCaCertificateFile", CFG_TYPE_STDSTRDIR, ITEM(res.tls_cert.CaCertfile), 0, 0, NULL, NULL, \ - "Path of a PEM encoded TLS CA certificate(s) file." }, \ - { "TlsCaCertificateDir", CFG_TYPE_STDSTRDIR, ITEM(res.tls_cert.CaCertdir), 0, 0, NULL, NULL, \ - "Path of a TLS CA certificate directory." }, \ - { "TlsCertificateRevocationList", CFG_TYPE_STDSTRDIR, ITEM(res.tls_cert.crlfile), 0, 0, NULL, NULL, \ - "Path of a Certificate Revocation List file." }, \ - { "TlsCertificate", CFG_TYPE_STDSTRDIR, ITEM(res.tls_cert.certfile), 0, 0, NULL, NULL, \ - "Path of a PEM encoded TLS certificate." }, \ - { "TlsKey", CFG_TYPE_STDSTRDIR, ITEM(res.tls_cert.keyfile), 0, 0, NULL, NULL, \ - "Path of a PEM encoded private key. It must correspond to the specified \"TLS Certificate\"." }, \ - { "TlsAllowedCn", CFG_TYPE_ALIST_STR, ITEM(res.tls_cert.allowed_certificate_common_names_), 0, 0, NULL, NULL, \ - "\"Common Name\"s (CNs) of the allowed peer certificates." } - - /* - * TLS Settings for PSK only - */ - #define TLS_PSK_CONFIG(res) \ - { "TlsPskEnable", CFG_TYPE_BOOL, ITEM(res.tls_psk.enable), 0, CFG_ITEM_DEFAULT, "true", NULL, \ - "Enable TLS-PSK support." }, \ - { "TlsPskRequire", CFG_TYPE_BOOL, ITEM(res.tls_psk.require), 0, CFG_ITEM_DEFAULT, "false", NULL, \ - "Without setting this to yes, Bareos can fall back to use unencryption connections. " \ - "Enabling this implicitly sets \"TLS-PSK Enable = yes\"." } + */ +#define TLS_COMMON_CONFIG(res) \ + {"TlsAuthenticate", \ + CFG_TYPE_BOOL, \ + ITEM(res.tls_cert.authenticate), \ + 0, \ + CFG_ITEM_DEFAULT, \ + "false", \ + NULL, \ + "Use TLS only to authenticate, not for encryption."}, \ + {"TlsEnable", CFG_TYPE_BOOL, ITEM(res.tls_cert.enable), 0, CFG_ITEM_DEFAULT, \ + "false", NULL, "Enable TLS support."}, \ + {"TlsRequire", \ + CFG_TYPE_BOOL, \ + ITEM(res.tls_cert.require), \ + 0, \ + CFG_ITEM_DEFAULT, \ + "false", \ + NULL, \ + "Without setting this to yes, Bareos can fall back to use unencrypted connections. " \ + "Enabling this implicitly sets \"TLS Enable = yes\"."}, \ + {"TlsCipherList", \ + CFG_TYPE_STR, \ + ITEM(res.tls_cert.cipherlist), \ + 0, \ + CFG_ITEM_PLATFORM_SPECIFIC, \ + NULL, \ + NULL, \ + "List of valid TLS Ciphers."}, \ + { \ + "TlsDhFile", CFG_TYPE_STDSTRDIR, ITEM(res.tls_cert.dhfile), 0, 0, NULL, NULL, \ + "Path to PEM encoded Diffie-Hellman parameter file. " \ + "If this directive is specified, DH key exchange will be used for the ephemeral keying, " \ + "allowing for forward secrecy of communications." \ + } + +/* + * TLS Settings for Certificate only + */ +#define TLS_CERT_CONFIG(res) \ + {"TlsVerifyPeer", \ + CFG_TYPE_BOOL, \ + ITEM(res.tls_cert.VerifyPeer), \ + 0, \ + CFG_ITEM_DEFAULT, \ + "false", \ + NULL, \ + "If disabled, all certificates signed by a known CA will be accepted. " \ + "If enabled, the CN of a certificate must the Address or in the \"TLS Allowed CN\" list."}, \ + {"TlsCaCertificateFile", \ + CFG_TYPE_STDSTRDIR, \ + ITEM(res.tls_cert.CaCertfile), \ + 0, \ + 0, \ + NULL, \ + NULL, \ + "Path of a PEM encoded TLS CA certificate(s) file."}, \ + {"TlsCaCertificateDir", \ + CFG_TYPE_STDSTRDIR, \ + ITEM(res.tls_cert.CaCertdir), \ + 0, \ + 0, \ + NULL, \ + NULL, \ + "Path of a TLS CA certificate directory."}, \ + {"TlsCertificateRevocationList", \ + CFG_TYPE_STDSTRDIR, \ + ITEM(res.tls_cert.crlfile), \ + 0, \ + 0, \ + NULL, \ + NULL, \ + "Path of a Certificate Revocation List file."}, \ + {"TlsCertificate", \ + CFG_TYPE_STDSTRDIR, \ + ITEM(res.tls_cert.certfile), \ + 0, \ + 0, \ + NULL, \ + NULL, \ + "Path of a PEM encoded TLS certificate."}, \ + {"TlsKey", \ + CFG_TYPE_STDSTRDIR, \ + ITEM(res.tls_cert.keyfile), \ + 0, \ + 0, \ + NULL, \ + NULL, \ + "Path of a PEM encoded private key. It must correspond to the specified \"TLS Certificate\"."}, \ + { \ + "TlsAllowedCn", CFG_TYPE_ALIST_STR, ITEM(res.tls_cert.allowed_certificate_common_names_), 0, 0, NULL, \ + NULL, "\"Common Name\"s (CNs) of the allowed peer certificates." \ + } + +/* + * TLS Settings for PSK only + */ +#define TLS_PSK_CONFIG(res) \ + {"TlsPskEnable", CFG_TYPE_BOOL, ITEM(res.tls_psk.enable), 0, CFG_ITEM_DEFAULT, \ + "true", NULL, "Enable TLS-PSK support."}, \ + { \ + "TlsPskRequire", CFG_TYPE_BOOL, ITEM(res.tls_psk.require), 0, CFG_ITEM_DEFAULT, "false", NULL, \ + "Without setting this to yes, Bareos can fall back to use unencryption connections. " \ + "Enabling this implicitly sets \"TLS-PSK Enable = yes\"." \ + } /* * This is the structure that defines the record types (items) permitted within each * resource. It is used to define the configuration tables. */ struct ResourceItem { - const char *name; /* Resource name i.e. Director, ... */ - const int type; - union { - char **value; /* Where to store the item */ - std::string **strValue; - uint16_t *ui16value; - uint32_t *ui32value; - int16_t *i16value; - int32_t *i32value; - uint64_t *ui64value; - int64_t *i64value; - bool *boolvalue; - utime_t *utimevalue; - s_password *pwdvalue; - CommonResourceHeader **resvalue; - alist **alistvalue; - dlist **dlistvalue; - char *bitvalue; - }; - int32_t code; /* Item code/additional info */ - uint32_t flags; /* Flags: See CFG_ITEM_* */ - const char *default_value; /* Default value */ - /* - * version string in format: [start_version]-[end_version] - * start_version: directive has been introduced in this version - * end_version: directive is deprecated since this version - */ - const char *versions; - /* - * description of the directive, used for the documentation. - * Full sentence. - * Every new directive should have a description. - */ - const char *description; + const char *name; /* Resource name i.e. Director, ... */ + const int type; + union { + char **value; /* Where to store the item */ + std::string **strValue; + uint16_t *ui16value; + uint32_t *ui32value; + int16_t *i16value; + int32_t *i32value; + uint64_t *ui64value; + int64_t *i64value; + bool *boolvalue; + utime_t *utimevalue; + s_password *pwdvalue; + CommonResourceHeader **resvalue; + alist **alistvalue; + dlist **dlistvalue; + char *bitvalue; + }; + int32_t code; /* Item code/additional info */ + uint32_t flags; /* Flags: See CFG_ITEM_* */ + const char *default_value; /* Default value */ + /* + * version string in format: [start_version]-[end_version] + * start_version: directive has been introduced in this version + * end_version: directive is deprecated since this version + */ + const char *versions; + /* + * description of the directive, used for the documentation. + * Full sentence. + * Every new directive should have a description. + */ + const char *description; }; /* For storing name_addr items in res_items table */ -#define ITEM(x) {(char **)&res_all.x} +#define ITEM(x) \ + { \ + (char **)&res_all.x \ + } -#define MAX_RES_ITEMS 90 /* maximum resource items per CommonResourceHeader */ +#define MAX_RES_ITEMS 90 /* maximum resource items per CommonResourceHeader */ /* * This is the universal header that is at the beginning of every resource record. */ class CommonResourceHeader { -public: - CommonResourceHeader *next; /* Pointer to next resource of this type */ - char *name; /* Resource name */ - char *desc; /* Resource description */ - uint32_t rcode; /* Resource id or type */ - int32_t refcnt; /* Reference count for releasing */ - char item_present[MAX_RES_ITEMS]; /* Set if item is present in conf file */ - char inherit_content[MAX_RES_ITEMS]; /* Set if item has inherited content */ + public: + CommonResourceHeader *next; /* Pointer to next resource of this type */ + char *name; /* Resource name */ + char *desc; /* Resource description */ + uint32_t rcode; /* Resource id or type */ + int32_t refcnt; /* Reference count for releasing */ + char item_present[MAX_RES_ITEMS]; /* Set if item is present in conf file */ + char inherit_content[MAX_RES_ITEMS]; /* Set if item has inherited content */ }; /* * Master Resource configuration structure definition * This is the structure that defines the resources that are available to this daemon. */ - struct ResourceTable { - const char *name; /* Resource name */ - ResourceItem *items; /* List of resource keywords */ - uint32_t rcode; /* Code if needed */ - uint32_t size; /* Size of resource */ - - std::function initres; /* this shoud call the new replacement*/ - }; - - /* - * Common Resource definitions - */ +struct ResourceTable { + const char *name; /* Resource name */ + ResourceItem *items; /* List of resource keywords */ + uint32_t rcode; /* Code if needed */ + uint32_t size; /* Size of resource */ + + std::function initres; /* this shoud call the new replacement*/ +}; + +/* + * Common Resource definitions + */ #define MAX_RES_NAME_LENGTH MAX_NAME_LENGTH - 1 /* maximum resource name length */ /* * Config item flags. */ -#define CFG_ITEM_REQUIRED 0x1 /* Item required */ -#define CFG_ITEM_DEFAULT 0x2 /* Default supplied */ -#define CFG_ITEM_NO_EQUALS 0x4 /* Don't scan = after name */ -#define CFG_ITEM_DEPRECATED 0x8 /* Deprecated config option */ -#define CFG_ITEM_ALIAS 0x10 /* Item is an alias for another */ +#define CFG_ITEM_REQUIRED 0x1 /* Item required */ +#define CFG_ITEM_DEFAULT 0x2 /* Default supplied */ +#define CFG_ITEM_NO_EQUALS 0x4 /* Don't scan = after name */ +#define CFG_ITEM_DEPRECATED 0x8 /* Deprecated config option */ +#define CFG_ITEM_ALIAS 0x10 /* Item is an alias for another */ /* * CFG_ITEM_DEFAULT_PLATFORM_SPECIFIC: the value may differ between different @@ -223,262 +288,340 @@ class CommonResourceHeader { */ #define CFG_ITEM_PLATFORM_SPECIFIC 0x20 -enum { - /* - * Standard resource types. handlers in res.c - */ - CFG_TYPE_STR = 1, /* String */ - CFG_TYPE_DIR = 2, /* Directory */ - CFG_TYPE_MD5PASSWORD = 3, /* MD5 hashed Password */ - CFG_TYPE_CLEARPASSWORD = 4, /* Clear text Password */ - CFG_TYPE_AUTOPASSWORD = 5, /* Password stored in clear when needed otherwise hashed */ - CFG_TYPE_NAME = 6, /* Name */ - CFG_TYPE_STRNAME = 7, /* String Name */ - CFG_TYPE_RES = 8, /* Resource */ - CFG_TYPE_ALIST_RES = 9, /* List of resources */ - CFG_TYPE_ALIST_STR = 10, /* List of strings */ - CFG_TYPE_ALIST_DIR = 11, /* List of dirs */ - CFG_TYPE_INT16 = 12, /* 16 bits Integer */ - CFG_TYPE_PINT16 = 13, /* Positive 16 bits Integer (unsigned) */ - CFG_TYPE_INT32 = 14, /* 32 bits Integer */ - CFG_TYPE_PINT32 = 15, /* Positive 32 bits Integer (unsigned) */ - CFG_TYPE_MSGS = 16, /* Message resource */ - CFG_TYPE_INT64 = 17, /* 64 bits Integer */ - CFG_TYPE_BIT = 18, /* Bitfield */ - CFG_TYPE_BOOL = 19, /* Boolean */ - CFG_TYPE_TIME = 20, /* Time value */ - CFG_TYPE_SIZE64 = 21, /* 64 bits file size */ - CFG_TYPE_SIZE32 = 22, /* 32 bits file size */ - CFG_TYPE_SPEED = 23, /* Speed limit */ - CFG_TYPE_DEFS = 24, /* Definition */ - CFG_TYPE_LABEL = 25, /* Label */ - CFG_TYPE_ADDRESSES = 26, /* List of ip addresses */ - CFG_TYPE_ADDRESSES_ADDRESS = 27, /* Ip address */ - CFG_TYPE_ADDRESSES_PORT = 28, /* Ip port */ - CFG_TYPE_PLUGIN_NAMES = 29, /* Plugin Name(s) */ - CFG_TYPE_STDSTR = 30, /* String as std::string*/ - CFG_TYPE_STDSTRDIR = 31, /* Directory as std::string*/ - - /* - * Director resource types. handlers in dird_conf. - */ - CFG_TYPE_ACL = 50, /* User Access Control List */ - CFG_TYPE_AUDIT = 51, /* Auditing Command List */ - CFG_TYPE_AUTHPROTOCOLTYPE = 52, /* Authentication Protocol */ - CFG_TYPE_AUTHTYPE = 53, /* Authentication Type */ - CFG_TYPE_DEVICE = 54, /* Device resource */ - CFG_TYPE_JOBTYPE = 55, /* Type of Job */ - CFG_TYPE_PROTOCOLTYPE = 56, /* Protocol */ - CFG_TYPE_LEVEL = 57, /* Backup Level */ - CFG_TYPE_REPLACE = 58, /* Replace option */ - CFG_TYPE_SHRTRUNSCRIPT = 59, /* Short Runscript definition */ - CFG_TYPE_RUNSCRIPT = 60, /* Runscript */ - CFG_TYPE_RUNSCRIPT_CMD = 61, /* Runscript Command */ - CFG_TYPE_RUNSCRIPT_TARGET = 62, /* Runscript Target (Host) */ - CFG_TYPE_RUNSCRIPT_BOOL = 63, /* Runscript Boolean */ - CFG_TYPE_RUNSCRIPT_WHEN = 64, /* Runscript When expression */ - CFG_TYPE_MIGTYPE = 65, /* Migration Type */ - CFG_TYPE_INCEXC = 66, /* Include/Exclude item */ - CFG_TYPE_RUN = 67, /* Schedule Run Command */ - CFG_TYPE_ACTIONONPURGE = 68, /* Action to perform on Purge */ - CFG_TYPE_POOLTYPE = 69, /* Pool Type */ - - /* - * Director fileset options. handlers in dird_conf. - */ - CFG_TYPE_FNAME = 80, /* Filename */ - CFG_TYPE_PLUGINNAME = 81, /* Pluginname */ - CFG_TYPE_EXCLUDEDIR = 82, /* Exclude directory */ - CFG_TYPE_OPTIONS = 83, /* Options block */ - CFG_TYPE_OPTION = 84, /* Option of Options block */ - CFG_TYPE_REGEX = 85, /* Regular Expression */ - CFG_TYPE_BASE = 86, /* Basejob Expression */ - CFG_TYPE_WILD = 87, /* Wildcard Expression */ - CFG_TYPE_PLUGIN = 88, /* Plugin definition */ - CFG_TYPE_FSTYPE = 89, /* FileSytem match criterium (UNIX)*/ - CFG_TYPE_DRIVETYPE = 90, /* DriveType match criterium (Windows) */ - CFG_TYPE_META = 91, /* Meta tag */ - - /* - * Storage daemon resource types - */ - CFG_TYPE_DEVTYPE = 201, /* Device Type */ - CFG_TYPE_MAXBLOCKSIZE = 202, /* Maximum Blocksize */ - CFG_TYPE_IODIRECTION = 203, /* IO Direction */ - CFG_TYPE_CMPRSALGO = 204, /* Compression Algorithm */ - - /* - * File daemon resource types - */ - CFG_TYPE_CIPHER = 301 /* Encryption Cipher */ +enum +{ + /* + * Standard resource types. handlers in res.c + */ + CFG_TYPE_STR = 1, /* String */ + CFG_TYPE_DIR = 2, /* Directory */ + CFG_TYPE_MD5PASSWORD = 3, /* MD5 hashed Password */ + CFG_TYPE_CLEARPASSWORD = 4, /* Clear text Password */ + CFG_TYPE_AUTOPASSWORD = 5, /* Password stored in clear when needed otherwise hashed */ + CFG_TYPE_NAME = 6, /* Name */ + CFG_TYPE_STRNAME = 7, /* String Name */ + CFG_TYPE_RES = 8, /* Resource */ + CFG_TYPE_ALIST_RES = 9, /* List of resources */ + CFG_TYPE_ALIST_STR = 10, /* List of strings */ + CFG_TYPE_ALIST_DIR = 11, /* List of dirs */ + CFG_TYPE_INT16 = 12, /* 16 bits Integer */ + CFG_TYPE_PINT16 = 13, /* Positive 16 bits Integer (unsigned) */ + CFG_TYPE_INT32 = 14, /* 32 bits Integer */ + CFG_TYPE_PINT32 = 15, /* Positive 32 bits Integer (unsigned) */ + CFG_TYPE_MSGS = 16, /* Message resource */ + CFG_TYPE_INT64 = 17, /* 64 bits Integer */ + CFG_TYPE_BIT = 18, /* Bitfield */ + CFG_TYPE_BOOL = 19, /* Boolean */ + CFG_TYPE_TIME = 20, /* Time value */ + CFG_TYPE_SIZE64 = 21, /* 64 bits file size */ + CFG_TYPE_SIZE32 = 22, /* 32 bits file size */ + CFG_TYPE_SPEED = 23, /* Speed limit */ + CFG_TYPE_DEFS = 24, /* Definition */ + CFG_TYPE_LABEL = 25, /* Label */ + CFG_TYPE_ADDRESSES = 26, /* List of ip addresses */ + CFG_TYPE_ADDRESSES_ADDRESS = 27, /* Ip address */ + CFG_TYPE_ADDRESSES_PORT = 28, /* Ip port */ + CFG_TYPE_PLUGIN_NAMES = 29, /* Plugin Name(s) */ + CFG_TYPE_STDSTR = 30, /* String as std::string*/ + CFG_TYPE_STDSTRDIR = 31, /* Directory as std::string*/ + + /* + * Director resource types. handlers in dird_conf. + */ + CFG_TYPE_ACL = 50, /* User Access Control List */ + CFG_TYPE_AUDIT = 51, /* Auditing Command List */ + CFG_TYPE_AUTHPROTOCOLTYPE = 52, /* Authentication Protocol */ + CFG_TYPE_AUTHTYPE = 53, /* Authentication Type */ + CFG_TYPE_DEVICE = 54, /* Device resource */ + CFG_TYPE_JOBTYPE = 55, /* Type of Job */ + CFG_TYPE_PROTOCOLTYPE = 56, /* Protocol */ + CFG_TYPE_LEVEL = 57, /* Backup Level */ + CFG_TYPE_REPLACE = 58, /* Replace option */ + CFG_TYPE_SHRTRUNSCRIPT = 59, /* Short Runscript definition */ + CFG_TYPE_RUNSCRIPT = 60, /* Runscript */ + CFG_TYPE_RUNSCRIPT_CMD = 61, /* Runscript Command */ + CFG_TYPE_RUNSCRIPT_TARGET = 62, /* Runscript Target (Host) */ + CFG_TYPE_RUNSCRIPT_BOOL = 63, /* Runscript Boolean */ + CFG_TYPE_RUNSCRIPT_WHEN = 64, /* Runscript When expression */ + CFG_TYPE_MIGTYPE = 65, /* Migration Type */ + CFG_TYPE_INCEXC = 66, /* Include/Exclude item */ + CFG_TYPE_RUN = 67, /* Schedule Run Command */ + CFG_TYPE_ACTIONONPURGE = 68, /* Action to perform on Purge */ + CFG_TYPE_POOLTYPE = 69, /* Pool Type */ + + /* + * Director fileset options. handlers in dird_conf. + */ + CFG_TYPE_FNAME = 80, /* Filename */ + CFG_TYPE_PLUGINNAME = 81, /* Pluginname */ + CFG_TYPE_EXCLUDEDIR = 82, /* Exclude directory */ + CFG_TYPE_OPTIONS = 83, /* Options block */ + CFG_TYPE_OPTION = 84, /* Option of Options block */ + CFG_TYPE_REGEX = 85, /* Regular Expression */ + CFG_TYPE_BASE = 86, /* Basejob Expression */ + CFG_TYPE_WILD = 87, /* Wildcard Expression */ + CFG_TYPE_PLUGIN = 88, /* Plugin definition */ + CFG_TYPE_FSTYPE = 89, /* FileSytem match criterium (UNIX)*/ + CFG_TYPE_DRIVETYPE = 90, /* DriveType match criterium (Windows) */ + CFG_TYPE_META = 91, /* Meta tag */ + + /* + * Storage daemon resource types + */ + CFG_TYPE_DEVTYPE = 201, /* Device Type */ + CFG_TYPE_MAXBLOCKSIZE = 202, /* Maximum Blocksize */ + CFG_TYPE_IODIRECTION = 203, /* IO Direction */ + CFG_TYPE_CMPRSALGO = 204, /* Compression Algorithm */ + + /* + * File daemon resource types + */ + CFG_TYPE_CIPHER = 301 /* Encryption Cipher */ }; struct DatatypeName { - const int number; - const char *name; - const char *description; + const int number; + const char *name; + const char *description; }; - /* * Base Class for all Resource Classes */ class BareosResource { -public: - CommonResourceHeader hdr; - - /* Methods */ - inline char *name() const { return this->hdr.name; } - bool PrintConfig(PoolMem &buf, bool hide_sensitive_data = false, bool verbose = false); - /* - * validate can be defined by inherited classes, - * when special rules for this resource type must be checked. - */ - // virtual inline bool validate() { return true; }; + public: + CommonResourceHeader hdr; + + /* Methods */ + inline char *name() const { return this->hdr.name; } + bool PrintConfig(PoolMem &buf, bool hide_sensitive_data = false, bool verbose = false); + /* + * validate can be defined by inherited classes, + * when special rules for this resource type must be checked. + */ + // virtual inline bool validate() { return true; }; }; class TlsResource : public BareosResource { public: - s_password password; /* UA server password */ - TlsConfigCert tls_cert; /* TLS structure */ - TlsConfigPsk tls_psk; /* TLS-PSK structure */ + s_password password; /* UA server password */ + TlsConfigCert tls_cert; /* TLS structure */ + TlsConfigPsk tls_psk; /* TLS-PSK structure */ }; /* * Message Resource */ class MessagesResource : public BareosResource { - /* - * Members - */ -public: - char *mail_cmd; /* Mail command */ - char *operator_cmd; /* Operator command */ - char *timestamp_format; /* Timestamp format */ - DEST *dest_chain; /* chain of destinations */ - char SendMsg[NbytesForBits(M_MAX+1)]; /* Bit array of types */ - -private: - bool in_use_; /* Set when using to send a message */ - bool closing_; /* Set when closing message resource */ - -public: - /* - * Methods - */ - void ClearInUse() { lock(); in_use_=false; unlock(); } - void SetInUse() { WaitNotInUse(); in_use_=true; unlock(); } - void SetClosing() { closing_=true; } - bool GetClosing() { return closing_; } - void ClearClosing() { lock(); closing_=false; unlock(); } - bool IsClosing() { lock(); bool rtn=closing_; unlock(); return rtn; } - - void WaitNotInUse(); /* in message.c */ - void lock(); /* in message.c */ - void unlock(); /* in message.c */ - bool PrintConfig(PoolMem &buff, bool hide_sensitive_data = false, bool verbose = false); + /* + * Members + */ + public: + char *mail_cmd; /* Mail command */ + char *operator_cmd; /* Operator command */ + char *timestamp_format; /* Timestamp format */ + DEST *dest_chain; /* chain of destinations */ + char SendMsg[NbytesForBits(M_MAX + 1)]; /* Bit array of types */ + + private: + bool in_use_; /* Set when using to send a message */ + bool closing_; /* Set when closing message resource */ + + public: + /* + * Methods + */ + void ClearInUse() + { + lock(); + in_use_ = false; + unlock(); + } + void SetInUse() + { + WaitNotInUse(); + in_use_ = true; + unlock(); + } + void SetClosing() { closing_ = true; } + bool GetClosing() { return closing_; } + void ClearClosing() + { + lock(); + closing_ = false; + unlock(); + } + bool IsClosing() + { + lock(); + bool rtn = closing_; + unlock(); + return rtn; + } + + void WaitNotInUse(); /* in message.c */ + void lock(); /* in message.c */ + void unlock(); /* in message.c */ + bool PrintConfig(PoolMem &buff, bool hide_sensitive_data = false, bool verbose = false); }; -typedef void (INIT_RES_HANDLER)(ResourceItem *item, int pass); -typedef void (STORE_RES_HANDLER)(LEX *lc, ResourceItem *item, int index, int pass); -typedef void (PRINT_RES_HANDLER)(ResourceItem *items, int i, PoolMem &cfg_str, bool hide_sensitive_data, bool inherited); +typedef void(INIT_RES_HANDLER)(ResourceItem *item, int pass); +typedef void(STORE_RES_HANDLER)(LEX *lc, ResourceItem *item, int index, int pass); +typedef void( + PRINT_RES_HANDLER)(ResourceItem *items, int i, PoolMem &cfg_str, bool hide_sensitive_data, bool inherited); /* * New C++ configuration routines */ class DLL_IMP_EXP ConfigurationParser { -public: - /* - * Members - */ - std::string cf_; /* Config file parameter */ - LEX_ERROR_HANDLER *scan_error_; /* Error handler if non-null */ - LEX_WARNING_HANDLER *scan_warning_; /* Warning handler if non-null */ - INIT_RES_HANDLER *init_res_; /* Init resource handler for non default types if non-null */ - STORE_RES_HANDLER *store_res_; /* Store resource handler for non default types if non-null */ - PRINT_RES_HANDLER *print_res_; /* Print resource handler for non default types if non-null */ - - int32_t err_type_; /* The way to Terminate on failure */ - void *res_all_; /* Pointer to res_all buffer */ - int32_t res_all_size_; /* Length of buffer */ - bool omit_defaults_; /* Omit config variables with default values when dumping the config */ - - int32_t r_first_; /* First daemon resource type */ - int32_t r_last_; /* Last daemon resource type */ - ResourceTable *resources_; /* Pointer to table of permitted resources */ - CommonResourceHeader **res_head_; /* Pointer to defined resources */ - brwlock_t res_lock_; /* Resource lock */ - - /* - * Methods - */ - - ConfigurationParser(); - ConfigurationParser ( - const char *cf, - LEX_ERROR_HANDLER *ScanError, - LEX_WARNING_HANDLER *scan_warning, - INIT_RES_HANDLER *init_res, - STORE_RES_HANDLER *StoreRes, - PRINT_RES_HANDLER *print_res, - int32_t err_type, - void *vres_all, - int32_t res_all_size, - int32_t r_first, - int32_t r_last, - ResourceTable *resources, - CommonResourceHeader **res_head, - const char* config_default_filename, - const char* config_include_dir, - void (*DoneParseConfigCallback)(ConfigurationParser&) = nullptr); - - ~ConfigurationParser(); - - bool IsUsingConfigIncludeDir() const { return use_config_include_dir_; } - bool ParseConfig(); - bool ParseConfigFile(const char *cf, void *caller_ctx, LEX_ERROR_HANDLER *ScanError = NULL, - LEX_WARNING_HANDLER *scan_warning = NULL); - const std::string &get_base_config_path() const { return used_config_path_; } - void FreeResources(); - CommonResourceHeader **save_resources(); - CommonResourceHeader **new_res_head(); - void InitResource(int type, ResourceItem *items, int pass, std::function initres); - bool RemoveResource(int type, const char *name); - void DumpResources(void sendit(void *sock, const char *fmt, ...), - void *sock, bool hide_sensitive_data = false); - const char *get_resource_type_name(int code); - int GetResourceCode(const char *resource_type); - ResourceTable *get_resource_table(int resource_type); - ResourceTable *get_resource_table(const char *resource_type_name); - int GetResourceItemIndex(ResourceItem *res_table, const char *item); - ResourceItem *get_resource_item(ResourceItem *res_table, const char *item); - bool GetPathOfResource(PoolMem &path, const char *component, const char *resourcetype, - const char *name, bool set_wildcards = false); - bool GetPathOfNewResource(PoolMem &path, PoolMem &extramsg, const char *component, - const char *resourcetype, const char *name, - bool error_if_exits = false, bool create_directories = false); + public: + /* + * Members + */ + std::string cf_; /* Config file parameter */ + LEX_ERROR_HANDLER *scan_error_; /* Error handler if non-null */ + LEX_WARNING_HANDLER *scan_warning_; /* Warning handler if non-null */ + INIT_RES_HANDLER *init_res_; /* Init resource handler for non default types if non-null */ + STORE_RES_HANDLER *store_res_; /* Store resource handler for non default types if non-null */ + PRINT_RES_HANDLER *print_res_; /* Print resource handler for non default types if non-null */ + + int32_t err_type_; /* The way to Terminate on failure */ + void *res_all_; /* Pointer to res_all buffer */ + int32_t res_all_size_; /* Length of buffer */ + bool omit_defaults_; /* Omit config variables with default values when dumping the config */ + + int32_t r_first_; /* First daemon resource type */ + int32_t r_last_; /* Last daemon resource type */ + ResourceTable *resources_; /* Pointer to table of permitted resources */ + CommonResourceHeader **res_head_; /* Pointer to defined resources */ + brwlock_t res_lock_; /* Resource lock */ + + /* + * Methods + */ + + ConfigurationParser(); + ConfigurationParser(const char *cf, + LEX_ERROR_HANDLER *ScanError, + LEX_WARNING_HANDLER *scan_warning, + INIT_RES_HANDLER *init_res, + STORE_RES_HANDLER *StoreRes, + PRINT_RES_HANDLER *print_res, + int32_t err_type, + void *vres_all, + int32_t res_all_size, + int32_t r_first, + int32_t r_last, + ResourceTable *resources, + CommonResourceHeader **res_head, + const char *config_default_filename, + const char *config_include_dir, + void (*DoneParseConfigCallback)(ConfigurationParser &) = nullptr); + + ~ConfigurationParser(); + + bool IsUsingConfigIncludeDir() const { return use_config_include_dir_; } + bool ParseConfig(); + bool ParseConfigFile(const char *cf, + void *caller_ctx, + LEX_ERROR_HANDLER *ScanError = NULL, + LEX_WARNING_HANDLER *scan_warning = NULL); + const std::string &get_base_config_path() const { return used_config_path_; } + void FreeResources(); + CommonResourceHeader **save_resources(); + CommonResourceHeader **new_res_head(); + void InitResource(int type, ResourceItem *items, int pass, std::function initres); + bool RemoveResource(int type, const char *name); + void DumpResources(void sendit(void *sock, const char *fmt, ...), + void *sock, + bool hide_sensitive_data = false); + const char *get_resource_type_name(int code); + int GetResourceCode(const char *resource_type); + ResourceTable *get_resource_table(int resource_type); + ResourceTable *get_resource_table(const char *resource_type_name); + int GetResourceItemIndex(ResourceItem *res_table, const char *item); + ResourceItem *get_resource_item(ResourceItem *res_table, const char *item); + bool GetPathOfResource(PoolMem &path, + const char *component, + const char *resourcetype, + const char *name, + bool set_wildcards = false); + bool GetPathOfNewResource(PoolMem &path, + PoolMem &extramsg, + const char *component, + const char *resourcetype, + const char *name, + bool error_if_exits = false, + bool create_directories = false); CommonResourceHeader *GetNextRes(int rcode, CommonResourceHeader *res); CommonResourceHeader *GetResWithName(int rcode, const char *name, bool lock = true); - -private: - ConfigurationParser(const ConfigurationParser&) = delete; - ConfigurationParser operator=(const ConfigurationParser&) = delete; - -private: - std::string config_default_filename_; /* default config filename, that is used, if no filename is given */ - std::string config_dir_; /* base directory of configuration files */ - std::string config_include_dir_; /* rel. path to the config include directory - (bareos-dir.d, bareos-sd.d, bareos-fd.d, ...) */ - bool use_config_include_dir_; /* Use the config include directory */ - std::string config_include_naming_format_; /* Format string for file paths of resources */ - std::string used_config_path_; /* Config file that is used. */ - void (*ParseConfigReadyCallback_)(ConfigurationParser&); - - const char *get_default_configdir(); - bool GetConfigFile(PoolMem &full_path, const char *config_dir, const char *config_filename); - bool GetConfigIncludePath(PoolMem &full_path, const char *config_dir); - bool FindConfigPath(PoolMem &full_path); - int GetResourceTableIndex(int resource_type); + void b_LockRes(const char *file, int line); + void b_UnlockRes(const char *file, int line); + const char *res_to_str(int rcode) const; + bool StoreResource(int type, LEX *lc, ResourceItem *item, int index, int pass); + + private: + ConfigurationParser(const ConfigurationParser &) = delete; + ConfigurationParser operator=(const ConfigurationParser &) = delete; + + private: + enum unit_type + { + STORE_SIZE, + STORE_SPEED + }; + + std::string config_default_filename_; /* default config filename, that is used, if no filename is given */ + std::string config_dir_; /* base directory of configuration files */ + std::string config_include_dir_; /* rel. path to the config include directory + (bareos-dir.d, bareos-sd.d, bareos-fd.d, ...) */ + bool use_config_include_dir_; /* Use the config include directory */ + std::string config_include_naming_format_; /* Format string for file paths of resources */ + std::string used_config_path_; /* Config file that is used. */ + void (*ParseConfigReadyCallback_)(ConfigurationParser &); + + const char *get_default_configdir(); + bool GetConfigFile(PoolMem &full_path, const char *config_dir, const char *config_filename); + bool GetConfigIncludePath(PoolMem &full_path, const char *config_dir); + bool FindConfigPath(PoolMem &full_path); + int GetResourceTableIndex(int resource_type); + void StoreMsgs(LEX *lc, ResourceItem *item, int index, int pass); + void StoreName(LEX *lc, ResourceItem *item, int index, int pass); + void StoreStrname(LEX *lc, ResourceItem *item, int index, int pass); + void StoreStr(LEX *lc, ResourceItem *item, int index, int pass); + void StoreStdstr(LEX *lc, ResourceItem *item, int index, int pass); + void StoreDir(LEX *lc, ResourceItem *item, int index, int pass); + void StoreStdstrdir(LEX *lc, ResourceItem *item, int index, int pass); + void store_md5password(LEX *lc, ResourceItem *item, int index, int pass); + void StoreClearpassword(LEX *lc, ResourceItem *item, int index, int pass); + void StoreRes(LEX *lc, ResourceItem *item, int index, int pass); + void StoreAlistRes(LEX *lc, ResourceItem *item, int index, int pass); + void StoreAlistStr(LEX *lc, ResourceItem *item, int index, int pass); + void StoreAlistDir(LEX *lc, ResourceItem *item, int index, int pass); + void StorePluginNames(LEX *lc, ResourceItem *item, int index, int pass); + void StoreDefs(LEX *lc, ResourceItem *item, int index, int pass); + void store_int16(LEX *lc, ResourceItem *item, int index, int pass); + void store_int32(LEX *lc, ResourceItem *item, int index, int pass); + void store_pint16(LEX *lc, ResourceItem *item, int index, int pass); + void store_pint32(LEX *lc, ResourceItem *item, int index, int pass); + void store_int64(LEX *lc, ResourceItem *item, int index, int pass); + void store_int_unit(LEX *lc, ResourceItem *item, int index, int pass, bool size32, enum unit_type type); + void store_size32(LEX *lc, ResourceItem *item, int index, int pass); + void store_size64(LEX *lc, ResourceItem *item, int index, int pass); + void StoreSpeed(LEX *lc, ResourceItem *item, int index, int pass); + void StoreTime(LEX *lc, ResourceItem *item, int index, int pass); + void StoreBit(LEX *lc, ResourceItem *item, int index, int pass); + void StoreBool(LEX *lc, ResourceItem *item, int index, int pass); + void StoreLabel(LEX *lc, ResourceItem *item, int index, int pass); + void StoreAddresses(LEX *lc, ResourceItem *item, int index, int pass); + void StoreAddressesAddress(LEX *lc, ResourceItem *item, int index, int pass); + void StoreAddressesPort(LEX *lc, ResourceItem *item, int index, int pass); + void scan_types(LEX *lc, + MessagesResource *msg, + int dest_code, + char *where, + char *cmd, + char *timestamp_format); }; DLL_IMP_EXP void PrintMessage(void *sock, const char *fmt, ...); @@ -493,16 +636,19 @@ DLL_IMP_EXP const char *datatype_to_description(int type); /* * Resource routines */ -DLL_IMP_EXP void b_LockRes(const char *file, int line); -DLL_IMP_EXP void b_UnlockRes(const char *file, int line); -DLL_IMP_EXP void DumpResource(int type, CommonResourceHeader *res, void sendmsg(void *sock, const char *fmt, ...), - void *sock, bool hide_sensitive_data = false, bool verbose = false); -DLL_IMP_EXP void IndentConfigItem(PoolMem &cfg_str, int level, const char *config_item, bool inherited = false); +DLL_IMP_EXP void DumpResource(int type, + CommonResourceHeader *res, + void sendmsg(void *sock, const char *fmt, ...), + void *sock, + bool hide_sensitive_data = false, + bool verbose = false); +DLL_IMP_EXP void IndentConfigItem(PoolMem &cfg_str, + int level, + const char *config_item, + bool inherited = false); DLL_IMP_EXP void FreeResource(CommonResourceHeader *res, int type); DLL_IMP_EXP void InitResource(int type, ResourceItem *item); DLL_IMP_EXP bool SaveResource(int type, ResourceItem *item, int pass); -DLL_IMP_EXP bool StoreResource(int type, LEX *lc, ResourceItem *item, int index, int pass); -DLL_IMP_EXP const char *res_to_str(int rcode); #ifdef HAVE_JANSSON /* @@ -518,8 +664,8 @@ DLL_IMP_EXP json_t *json_items(ResourceItem items[]); */ #ifdef HAVE_TYPEOF #define foreach_res(var, type) \ - for((var)=NULL; ((var)=(typeof(var))my_config->GetNextRes((type), (CommonResourceHeader *)var));) + for ((var) = NULL; ((var) = (typeof(var))my_config->GetNextRes((type), (CommonResourceHeader *)var));) #else #define foreach_res(var, type) \ - for(var=NULL; (*((void **)&(var))=(void *)my_config->GetNextRes((type), (CommonResourceHeader *)var));) + for (var = NULL; (*((void **)&(var)) = (void *)my_config->GetNextRes((type), (CommonResourceHeader *)var));) #endif diff --git a/core/src/lib/res.cc b/core/src/lib/res.cc index e80afb3dcfc..c6ef9d03381 100644 --- a/core/src/lib/res.cc +++ b/core/src/lib/res.cc @@ -33,7 +33,7 @@ /* Forward referenced subroutines */ -extern ConfigurationParser *my_config; /* Our Global config */ +extern ConfigurationParser *my_config; /* Our Global config */ /* * Set default indention e.g. 2 spaces. @@ -44,51 +44,46 @@ extern ConfigurationParser *my_config; /* Our Global config */ * Define the Union of all the common resource structure definitions. */ union UnionOfResources { - MessagesResource res_msgs; - CommonResourceHeader hdr; + MessagesResource res_msgs; + CommonResourceHeader hdr; }; -static int res_locked = 0; /* resource chain lock count -- for debug */ +static int res_locked = 0; /* resource chain lock count -- for debug */ // #define TRACE_RES -void b_LockRes(const char *file, int line) +void ConfigurationParser::b_LockRes(const char *file, int line) { - int errstat; + int errstat; #ifdef TRACE_RES - char ed1[50]; + char ed1[50]; - Pmsg4(000, "LockRes locked=%d w_active=%d at %s:%d\n", - res_locked, my_config->res_lock_.w_active, file, line); + Pmsg4(000, "LockRes locked=%d w_active=%d at %s:%d\n", res_locked, res_lock_.w_active, file, line); - if (res_locked) { - Pmsg2(000, "LockRes writerid=%lu myid=%s\n", - my_config->res_lock_.writer_id, - edit_pthread(pthread_self(), ed1, sizeof(ed1))); - } + if (res_locked) { + Pmsg2(000, "LockRes writerid=%lu myid=%s\n", res_lock_.writer_id, + edit_pthread(pthread_self(), ed1, sizeof(ed1))); + } #endif - if ((errstat = RwlWritelock(&my_config->res_lock_)) != 0) { - Emsg3(M_ABORT, 0, _("RwlWritelock failure at %s:%d: ERR=%s\n"), - file, line, strerror(errstat)); - } + if ((errstat = RwlWritelock(&res_lock_)) != 0) { + Emsg3(M_ABORT, 0, _("RwlWritelock failure at %s:%d: ERR=%s\n"), file, line, strerror(errstat)); + } - res_locked++; + res_locked++; } -void b_UnlockRes(const char *file, int line) +void ConfigurationParser::b_UnlockRes(const char *file, int line) { - int errstat; + int errstat; - if ((errstat = RwlWriteunlock(&my_config->res_lock_)) != 0) { - Emsg3(M_ABORT, 0, _("RwlWriteunlock failure at %s:%d:. ERR=%s\n"), - file, line, strerror(errstat)); - } - res_locked--; + if ((errstat = RwlWriteunlock(&res_lock_)) != 0) { + Emsg3(M_ABORT, 0, _("RwlWriteunlock failure at %s:%d:. ERR=%s\n"), file, line, strerror(errstat)); + } + res_locked--; #ifdef TRACE_RES - Pmsg4(000, "UnLockRes locked=%d wactive=%d at %s:%d\n", - res_locked, my_config->res_lock_.w_active, file, line); + Pmsg4(000, "UnLockRes locked=%d wactive=%d at %s:%d\n", res_locked, res_lock_.w_active, file, line); #endif } @@ -97,26 +92,26 @@ void b_UnlockRes(const char *file, int line) */ CommonResourceHeader *ConfigurationParser::GetResWithName(int rcode, const char *name, bool lock) { - CommonResourceHeader *res; - int rindex = rcode - my_config->r_first_; + CommonResourceHeader *res; + int rindex = rcode - r_first_; - if (lock) { - LockRes(); - } + if (lock) { + LockRes(); + } - res = my_config->res_head_[rindex]; - while (res) { - if (bstrcmp(res->name, name)) { - break; - } - res = res->next; - } + res = res_head_[rindex]; + while (res) { + if (bstrcmp(res->name, name)) { + break; + } + res = res->next; + } - if (lock) { - UnlockRes(); - } + if (lock) { + UnlockRes(); + } - return res; + return res; } /* @@ -126,25 +121,25 @@ CommonResourceHeader *ConfigurationParser::GetResWithName(int rcode, const char */ CommonResourceHeader *ConfigurationParser::GetNextRes(int rcode, CommonResourceHeader *res) { - CommonResourceHeader *nres; - int rindex = rcode - r_first_; + CommonResourceHeader *nres; + int rindex = rcode - r_first_; - if (res == NULL) { - nres = res_head_[rindex]; - } else { - nres = res->next; - } + if (res == NULL) { + nres = res_head_[rindex]; + } else { + nres = res->next; + } - return nres; + return nres; } -const char *res_to_str(int rcode) +const char *ConfigurationParser::res_to_str(int rcode) const { - if (rcode < my_config->r_first_ || rcode > my_config->r_last_) { - return _("***UNKNOWN***"); - } else { - return my_config->resources_[rcode - my_config->r_first_].name; - } + if (rcode < r_first_ || rcode > r_last_) { + return _("***UNKNOWN***"); + } else { + return resources_[rcode - r_first_].name; + } } /* @@ -153,297 +148,287 @@ const char *res_to_str(int rcode) * (WARNING, ERROR, FATAL, INFO, ...) with an appropriate * destination (MAIL, FILE, OPERATOR, ...) */ -static void scan_types(LEX *lc, MessagesResource *msg, int dest_code, - char *where, char *cmd, char *timestamp_format) +void ConfigurationParser::scan_types(LEX *lc, + MessagesResource *msg, + int dest_code, + char *where, + char *cmd, + char *timestamp_format) { - int i; - bool found, is_not; - int msg_type = 0; - char *str; - - for (;;) { - LexGetToken(lc, BCT_NAME); /* expect at least one type */ - found = false; - if (lc->str[0] == '!') { - is_not = true; - str = &lc->str[1]; - } else { - is_not = false; - str = &lc->str[0]; - } - for (i = 0; msg_types[i].name; i++) { - if (Bstrcasecmp(str, msg_types[i].name)) { - msg_type = msg_types[i].token; - found = true; - break; - } - } - if (!found) { - scan_err1(lc, _("message type: %s not found"), str); - return; + int i; + bool found, is_not; + int msg_type = 0; + char *str; + + for (;;) { + LexGetToken(lc, BCT_NAME); /* expect at least one type */ + found = false; + if (lc->str[0] == '!') { + is_not = true; + str = &lc->str[1]; + } else { + is_not = false; + str = &lc->str[0]; + } + for (i = 0; msg_types[i].name; i++) { + if (Bstrcasecmp(str, msg_types[i].name)) { + msg_type = msg_types[i].token; + found = true; + break; } + } + if (!found) { + scan_err1(lc, _("message type: %s not found"), str); + return; + } - if (msg_type == M_MAX + 1) { /* all? */ - for (i = 1; i <= M_MAX; i++) { /* yes set all types */ - AddMsgDest(msg, dest_code, i, where, cmd, timestamp_format); - } - } else if (is_not) { - RemMsgDest(msg, dest_code, msg_type, where); - } else { - AddMsgDest(msg, dest_code, msg_type, where, cmd, timestamp_format); + if (msg_type == M_MAX + 1) { /* all? */ + for (i = 1; i <= M_MAX; i++) { /* yes set all types */ + AddMsgDest(msg, dest_code, i, where, cmd, timestamp_format); } - if (lc->ch != ',') { - break; - } - Dmsg0(900, "call LexGetToken() to eat comma\n"); - LexGetToken(lc, BCT_ALL); /* eat comma */ - } - Dmsg0(900, "Done scan_types()\n"); + } else if (is_not) { + RemMsgDest(msg, dest_code, msg_type, where); + } else { + AddMsgDest(msg, dest_code, msg_type, where, cmd, timestamp_format); + } + if (lc->ch != ',') { + break; + } + Dmsg0(900, "call LexGetToken() to eat comma\n"); + LexGetToken(lc, BCT_ALL); /* eat comma */ + } + Dmsg0(900, "Done scan_types()\n"); } /* * Store Messages Destination information */ -static void StoreMsgs(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::StoreMsgs(LEX *lc, ResourceItem *item, int index, int pass) { - int token; - char *cmd = NULL, - *tsf = NULL; - POOLMEM *dest; - int dest_len; - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; - - Dmsg2(900, "StoreMsgs pass=%d code=%d\n", pass, item->code); - - tsf = res_all->res_msgs.timestamp_format; - if (pass == 1) { - switch (item->code) { + int token; + char *cmd = NULL, *tsf = NULL; + POOLMEM *dest; + int dest_len; + UnionOfResources *res_all = reinterpret_cast(res_all_); + + Dmsg2(900, "StoreMsgs pass=%d code=%d\n", pass, item->code); + + tsf = res_all->res_msgs.timestamp_format; + if (pass == 1) { + switch (item->code) { case MD_STDOUT: case MD_STDERR: case MD_CONSOLE: case MD_CATALOG: - scan_types(lc, (MessagesResource *)(item->value), item->code, NULL, NULL, tsf); - break; - case MD_SYSLOG: { /* syslog */ - char *p; - int cnt = 0; - bool done = false; - - /* - * See if this is an old style syslog definition. - * We count the number of = signs in the current config line. - */ - p = lc->line; - while (!done && *p) { - switch (*p) { + scan_types(lc, (MessagesResource *)(item->value), item->code, NULL, NULL, tsf); + break; + case MD_SYSLOG: { /* syslog */ + char *p; + int cnt = 0; + bool done = false; + + /* + * See if this is an old style syslog definition. + * We count the number of = signs in the current config line. + */ + p = lc->line; + while (!done && *p) { + switch (*p) { case '=': - cnt++; - break; + cnt++; + break; case ',': case ';': - /* - * No need to continue scanning when we encounter a ',' or ';' - */ - done = true; - break; + /* + * No need to continue scanning when we encounter a ',' or ';' + */ + done = true; + break; default: - break; - } - p++; - } - - /* - * If there is more then one = its the new format e.g. - * syslog = facility = filter - */ - if (cnt > 1) { - dest = GetPoolMemory(PM_MESSAGE); - /* - * Pick up a single facility. - */ - token = LexGetToken(lc, BCT_NAME); /* Scan destination */ - PmStrcpy(dest, lc->str); - dest_len = lc->str_len; - token = LexGetToken(lc, BCT_SKIP_EOL); - - scan_types(lc, (MessagesResource *)(item->value), item->code, dest, NULL, NULL); - FreePoolMemory(dest); - Dmsg0(900, "done with dest codes\n"); - } else { - scan_types(lc, (MessagesResource *)(item->value), item->code, NULL, NULL, NULL); - } - break; + break; + } + p++; + } + + /* + * If there is more then one = its the new format e.g. + * syslog = facility = filter + */ + if (cnt > 1) { + dest = GetPoolMemory(PM_MESSAGE); + /* + * Pick up a single facility. + */ + token = LexGetToken(lc, BCT_NAME); /* Scan destination */ + PmStrcpy(dest, lc->str); + dest_len = lc->str_len; + token = LexGetToken(lc, BCT_SKIP_EOL); + + scan_types(lc, (MessagesResource *)(item->value), item->code, dest, NULL, NULL); + FreePoolMemory(dest); + Dmsg0(900, "done with dest codes\n"); + } else { + scan_types(lc, (MessagesResource *)(item->value), item->code, NULL, NULL, NULL); + } + break; } - case MD_OPERATOR: /* Send to operator */ - case MD_DIRECTOR: /* Send to Director */ - case MD_MAIL: /* Mail */ - case MD_MAIL_ON_ERROR: /* Mail if Job errors */ - case MD_MAIL_ON_SUCCESS: /* Mail if Job succeeds */ - if (item->code == MD_OPERATOR) { - cmd = res_all->res_msgs.operator_cmd; - } else { - cmd = res_all->res_msgs.mail_cmd; - } - dest = GetPoolMemory(PM_MESSAGE); - dest[0] = 0; - dest_len = 0; - - /* - * Pick up comma separated list of destinations. - */ - for (;;) { - token = LexGetToken(lc, BCT_NAME); /* Scan destination */ - dest = CheckPoolMemorySize(dest, dest_len + lc->str_len + 2); - if (dest[0] != 0) { - PmStrcat(dest, " "); /* Separate multiple destinations with space */ - dest_len++; - } - PmStrcat(dest, lc->str); - dest_len += lc->str_len; - Dmsg2(900, "StoreMsgs newdest=%s: dest=%s:\n", lc->str, NPRT(dest)); - token = LexGetToken(lc, BCT_SKIP_EOL); - if (token == BCT_COMMA) { - continue; /* Get another destination */ - } - if (token != BCT_EQUALS) { - scan_err1(lc, _("expected an =, got: %s"), lc->str); - return; - } - break; - } - Dmsg1(900, "mail_cmd=%s\n", NPRT(cmd)); - scan_types(lc, (MessagesResource *)(item->value), item->code, dest, cmd, tsf); - FreePoolMemory(dest); - Dmsg0(900, "done with dest codes\n"); - break; - case MD_FILE: /* File */ - case MD_APPEND: /* Append */ - dest = GetPoolMemory(PM_MESSAGE); - - /* - * Pick up a single destination. - */ - token = LexGetToken(lc, BCT_NAME); /* Scan destination */ - PmStrcpy(dest, lc->str); - dest_len = lc->str_len; - token = LexGetToken(lc, BCT_SKIP_EOL); - Dmsg1(900, "StoreMsgs dest=%s:\n", NPRT(dest)); - if (token != BCT_EQUALS) { + case MD_OPERATOR: /* Send to operator */ + case MD_DIRECTOR: /* Send to Director */ + case MD_MAIL: /* Mail */ + case MD_MAIL_ON_ERROR: /* Mail if Job errors */ + case MD_MAIL_ON_SUCCESS: /* Mail if Job succeeds */ + if (item->code == MD_OPERATOR) { + cmd = res_all->res_msgs.operator_cmd; + } else { + cmd = res_all->res_msgs.mail_cmd; + } + dest = GetPoolMemory(PM_MESSAGE); + dest[0] = 0; + dest_len = 0; + + /* + * Pick up comma separated list of destinations. + */ + for (;;) { + token = LexGetToken(lc, BCT_NAME); /* Scan destination */ + dest = CheckPoolMemorySize(dest, dest_len + lc->str_len + 2); + if (dest[0] != 0) { + PmStrcat(dest, " "); /* Separate multiple destinations with space */ + dest_len++; + } + PmStrcat(dest, lc->str); + dest_len += lc->str_len; + Dmsg2(900, "StoreMsgs newdest=%s: dest=%s:\n", lc->str, NPRT(dest)); + token = LexGetToken(lc, BCT_SKIP_EOL); + if (token == BCT_COMMA) { + continue; /* Get another destination */ + } + if (token != BCT_EQUALS) { scan_err1(lc, _("expected an =, got: %s"), lc->str); return; - } - scan_types(lc, (MessagesResource *)(item->value), item->code, dest, NULL, tsf); - FreePoolMemory(dest); - Dmsg0(900, "done with dest codes\n"); - break; + } + break; + } + Dmsg1(900, "mail_cmd=%s\n", NPRT(cmd)); + scan_types(lc, (MessagesResource *)(item->value), item->code, dest, cmd, tsf); + FreePoolMemory(dest); + Dmsg0(900, "done with dest codes\n"); + break; + case MD_FILE: /* File */ + case MD_APPEND: /* Append */ + dest = GetPoolMemory(PM_MESSAGE); + + /* + * Pick up a single destination. + */ + token = LexGetToken(lc, BCT_NAME); /* Scan destination */ + PmStrcpy(dest, lc->str); + dest_len = lc->str_len; + token = LexGetToken(lc, BCT_SKIP_EOL); + Dmsg1(900, "StoreMsgs dest=%s:\n", NPRT(dest)); + if (token != BCT_EQUALS) { + scan_err1(lc, _("expected an =, got: %s"), lc->str); + return; + } + scan_types(lc, (MessagesResource *)(item->value), item->code, dest, NULL, tsf); + FreePoolMemory(dest); + Dmsg0(900, "done with dest codes\n"); + break; default: - scan_err1(lc, _("Unknown item code: %d\n"), item->code); - return; - } - } - ScanToEol(lc); - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); - Dmsg0(900, "Done StoreMsgs\n"); + scan_err1(lc, _("Unknown item code: %d\n"), item->code); + return; + } + } + ScanToEol(lc); + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); + Dmsg0(900, "Done StoreMsgs\n"); } /* * This routine is ONLY for resource names * Store a name at specified address. */ -static void StoreName(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::StoreName(LEX *lc, ResourceItem *item, int index, int pass) { - POOLMEM *msg = GetPoolMemory(PM_EMSG); - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; - - LexGetToken(lc, BCT_NAME); - if (!IsNameValid(lc->str, msg)) { - scan_err1(lc, "%s\n", msg); - return; - } - FreePoolMemory(msg); - /* - * Store the name both in pass 1 and pass 2 - */ - if (*(item->value)) { - scan_err2(lc, _("Attempt to redefine name \"%s\" to \"%s\"."), - *(item->value), lc->str); - return; - } - *(item->value) = bstrdup(lc->str); - ScanToEol(lc); - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); + POOLMEM *msg = GetPoolMemory(PM_EMSG); + UnionOfResources *res_all = reinterpret_cast(res_all_); + + LexGetToken(lc, BCT_NAME); + if (!IsNameValid(lc->str, msg)) { + scan_err1(lc, "%s\n", msg); + return; + } + FreePoolMemory(msg); + /* + * Store the name both in pass 1 and pass 2 + */ + if (*(item->value)) { + scan_err2(lc, _("Attempt to redefine name \"%s\" to \"%s\"."), *(item->value), lc->str); + return; + } + *(item->value) = bstrdup(lc->str); + ScanToEol(lc); + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); } /* * Store a name string at specified address * A name string is limited to MAX_RES_NAME_LENGTH */ -static void StoreStrname(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::StoreStrname(LEX *lc, ResourceItem *item, int index, int pass) { - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; - - /* - * Store the name - */ - LexGetToken(lc, BCT_NAME); - if (pass == 1) { - /* - * If a default was set free it first. - */ - if (*(item->value)) { - free(*(item->value)); - } - *(item->value) = bstrdup(lc->str); - } - ScanToEol(lc); - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); + UnionOfResources *res_all = reinterpret_cast(res_all_); + + LexGetToken(lc, BCT_NAME); + if (pass == 1) { + if (*(item->value)) { /* free old item */ + free(*(item->value)); + } + *(item->value) = bstrdup(lc->str); + } + ScanToEol(lc); + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); } /* * Store a string at specified address */ -static void StoreStr(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::StoreStr(LEX *lc, ResourceItem *item, int index, int pass) { - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; - - LexGetToken(lc, BCT_STRING); - if (pass == 1) { - /* - * If a default was set free it first. - */ - if (*(item->value)) { - free(*(item->value)); - } - *(item->value) = bstrdup(lc->str); - } - ScanToEol(lc); - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); + UnionOfResources *res_all = reinterpret_cast(res_all_); + + LexGetToken(lc, BCT_STRING); + if (pass == 1) { + if (*(item->value)) { /* free old item */ + free(*(item->value)); + } + *(item->value) = bstrdup(lc->str); + } + ScanToEol(lc); + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); } /* * Store a string at specified address */ -static void StoreStdstr(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::StoreStdstr(LEX *lc, ResourceItem *item, int index, int pass) { - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; - - LexGetToken(lc, BCT_STRING); - if (pass == 1) { - /* - * If a default was set free it first. - */ - if (*(item->strValue)) { - free(*(item->strValue)); - } - *(item->strValue) = new std::string(lc->str); -} - ScanToEol(lc); - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); + UnionOfResources *res_all = reinterpret_cast(res_all_); + + LexGetToken(lc, BCT_STRING); + if (pass == 1) { + if (*(item->strValue)) { /* free old item */ + free(*(item->strValue)); + } + *(item->strValue) = new std::string(lc->str); + } + ScanToEol(lc); + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); } /* @@ -451,116 +436,110 @@ static void StoreStdstr(LEX *lc, ResourceItem *item, int index, int pass) * shell expansion except if the string begins with a vertical * bar (i.e. it will likely be passed to the shell later). */ -static void StoreDir(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::StoreDir(LEX *lc, ResourceItem *item, int index, int pass) { - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; - - LexGetToken(lc, BCT_STRING); - if (pass == 1) { - /* - * If a default was set free it first. - */ - if (*(item->value)) { - free(*(item->value)); - } - if (lc->str[0] != '|') { - DoShellExpansion(lc->str, SizeofPoolMemory(lc->str)); - } - *(item->value) = bstrdup(lc->str); - } - ScanToEol(lc); - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); + UnionOfResources *res_all = reinterpret_cast(res_all_); + + LexGetToken(lc, BCT_STRING); + if (pass == 1) { + if (*(item->value)) { /* free old item */ + free(*(item->value)); + } + if (lc->str[0] != '|') { + DoShellExpansion(lc->str, SizeofPoolMemory(lc->str)); + } + *(item->value) = bstrdup(lc->str); + } + ScanToEol(lc); + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); } -static void StoreStdstrdir(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::StoreStdstrdir(LEX *lc, ResourceItem *item, int index, int pass) { - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; - - LexGetToken(lc, BCT_STRING); - if (pass == 1) { - /* - * If a default was set free it first. - */ - if (*(item->strValue)) { - delete (*(item->value)); - } - if (lc->str[0] != '|') { - DoShellExpansion(lc->str, SizeofPoolMemory(lc->str)); - } - *(item->strValue) = new std::string(lc->str); - } - ScanToEol(lc); - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); + UnionOfResources *res_all = reinterpret_cast(res_all_); + + LexGetToken(lc, BCT_STRING); + if (pass == 1) { + if (*(item->strValue)) { /* free old item */ + delete (*(item->value)); + } + if (lc->str[0] != '|') { + DoShellExpansion(lc->str, SizeofPoolMemory(lc->str)); + } + *(item->strValue) = new std::string(lc->str); + } + ScanToEol(lc); + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); } /* * Store a password at specified address in MD5 coding */ -static void store_md5password(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::store_md5password(LEX *lc, ResourceItem *item, int index, int pass) { - s_password *pwd; - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; - - LexGetToken(lc, BCT_STRING); - if (pass == 1) { - pwd = item->pwdvalue; - - if (pwd->value) { - free(pwd->value); - } - - /* - * See if we are parsing an MD5 encoded password already. - */ - if (bstrncmp(lc->str, "[md5]", 5)) { - pwd->encoding = p_encoding_md5; - pwd->value = bstrdup(lc->str + 5); - } else { - unsigned int i, j; - MD5_CTX md5c; - unsigned char digest[CRYPTO_DIGEST_MD5_SIZE]; - char sig[100]; - - MD5_Init(&md5c); - MD5_Update(&md5c, (unsigned char *) (lc->str), lc->str_len); - MD5_Final(digest, &md5c); - for (i = j = 0; i < sizeof(digest); i++) { - sprintf(&sig[j], "%02x", digest[i]); - j += 2; - } - pwd->encoding = p_encoding_md5; - pwd->value = bstrdup(sig); + s_password *pwd; + UnionOfResources *res_all = reinterpret_cast(res_all_); + + LexGetToken(lc, BCT_STRING); + if (pass == 1) { /* free old item */ + pwd = item->pwdvalue; + + if (pwd->value) { + free(pwd->value); + } + + /* + * See if we are parsing an MD5 encoded password already. + */ + if (bstrncmp(lc->str, "[md5]", 5)) { + pwd->encoding = p_encoding_md5; + pwd->value = bstrdup(lc->str + 5); + } else { + unsigned int i, j; + MD5_CTX md5c; + unsigned char digest[CRYPTO_DIGEST_MD5_SIZE]; + char sig[100]; + + MD5_Init(&md5c); + MD5_Update(&md5c, (unsigned char *)(lc->str), lc->str_len); + MD5_Final(digest, &md5c); + for (i = j = 0; i < sizeof(digest); i++) { + sprintf(&sig[j], "%02x", digest[i]); + j += 2; } - } - ScanToEol(lc); - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); + pwd->encoding = p_encoding_md5; + pwd->value = bstrdup(sig); + } + } + ScanToEol(lc); + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); } /* * Store a password at specified address in MD5 coding */ -static void StoreClearpassword(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::StoreClearpassword(LEX *lc, ResourceItem *item, int index, int pass) { - s_password *pwd; - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; - - LexGetToken(lc, BCT_STRING); - if (pass == 1) { - pwd = item->pwdvalue; - - if (pwd->value) { - free(pwd->value); - } - - pwd->encoding = p_encoding_clear; - pwd->value = bstrdup(lc->str); - } - ScanToEol(lc); - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); + s_password *pwd; + UnionOfResources *res_all = reinterpret_cast(res_all_); + + LexGetToken(lc, BCT_STRING); + if (pass == 1) { + pwd = item->pwdvalue; + + if (pwd->value) { + free(pwd->value); + } + + pwd->encoding = p_encoding_clear; + pwd->value = bstrdup(lc->str); + } + ScanToEol(lc); + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); } /* @@ -568,29 +547,29 @@ static void StoreClearpassword(LEX *lc, ResourceItem *item, int index, int pass) * If we are in pass 2, do a lookup of the * resource. */ -static void StoreRes(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::StoreRes(LEX *lc, ResourceItem *item, int index, int pass) { - CommonResourceHeader *res; - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; - - LexGetToken(lc, BCT_NAME); - if (pass == 2) { - res = my_config->GetResWithName(item->code, lc->str); - if (res == NULL) { - scan_err3(lc, _("Could not find config resource \"%s\" referenced on line %d: %s"), - lc->str, lc->line_no, lc->line); - return; - } - if (*(item->resvalue)) { - scan_err3(lc, _("Attempt to redefine resource \"%s\" referenced on line %d: %s"), - item->name, lc->line_no, lc->line); - return; - } - *(item->resvalue) = res; - } - ScanToEol(lc); - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); + CommonResourceHeader *res; + UnionOfResources *res_all = reinterpret_cast(res_all_); + + LexGetToken(lc, BCT_NAME); + if (pass == 2) { + res = GetResWithName(item->code, lc->str); + if (res == NULL) { + scan_err3(lc, _("Could not find config resource \"%s\" referenced on line %d: %s"), lc->str, lc->line_no, + lc->line); + return; + } + if (*(item->resvalue)) { + scan_err3(lc, _("Attempt to redefine resource \"%s\" referenced on line %d: %s"), item->name, + lc->line_no, lc->line); + return; + } + *(item->resvalue) = res; + } + ScanToEol(lc); + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); } /* @@ -599,94 +578,94 @@ static void StoreRes(LEX *lc, ResourceItem *item, int index, int pass) * * If we are in pass 2, do a lookup of the resource. */ -static void StoreAlistRes(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::StoreAlistRes(LEX *lc, ResourceItem *item, int index, int pass) { - CommonResourceHeader *res; - int i = 0; - alist *list; - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; - int count = str_to_int32(item->default_value); - - if (pass == 2) { - if (count == 0) { /* always store in item->value */ - i = 0; - if (!item->alistvalue[i]) { - item->alistvalue[i] = New(alist(10, not_owned_by_alist)); - } - } else { - /* - * Find empty place to store this directive - */ - while ((item->value)[i] != NULL && i++ < count) { } - if (i >= count) { - scan_err4(lc, _("Too many %s directives. Max. is %d. line %d: %s\n"), - lc->str, count, lc->line_no, lc->line); - return; - } - item->alistvalue[i] = New(alist(10, not_owned_by_alist)); + CommonResourceHeader *res; + int i = 0; + alist *list; + UnionOfResources *res_all = reinterpret_cast(res_all_); + int count = str_to_int32(item->default_value); + + if (pass == 2) { + if (count == 0) { /* always store in item->value */ + i = 0; + if (!item->alistvalue[i]) { + item->alistvalue[i] = New(alist(10, not_owned_by_alist)); } - list = item->alistvalue[i]; - - for (;;) { - LexGetToken(lc, BCT_NAME); /* scan next item */ - res = my_config->GetResWithName(item->code, lc->str); - if (res == NULL) { - scan_err3(lc, _("Could not find config Resource \"%s\" referenced on line %d : %s\n"), - item->name, lc->line_no, lc->line); - return; - } - Dmsg5(900, "Append %p to alist %p size=%d i=%d %s\n", res, list, list->size(), i, item->name); - list->append(res); - if (lc->ch != ',') { /* if no other item follows */ - break; /* get out */ - } - LexGetToken(lc, BCT_ALL); /* eat comma */ + } else { + /* + * Find empty place to store this directive + */ + while ((item->value)[i] != NULL && i++ < count) { + } + if (i >= count) { + scan_err4(lc, _("Too many %s directives. Max. is %d. line %d: %s\n"), lc->str, count, lc->line_no, + lc->line); + return; + } + item->alistvalue[i] = New(alist(10, not_owned_by_alist)); + } + list = item->alistvalue[i]; + + for (;;) { + LexGetToken(lc, BCT_NAME); /* scan next item */ + res = GetResWithName(item->code, lc->str); + if (res == NULL) { + scan_err3(lc, _("Could not find config Resource \"%s\" referenced on line %d : %s\n"), item->name, + lc->line_no, lc->line); + return; } - } - ScanToEol(lc); - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); + Dmsg5(900, "Append %p to alist %p size=%d i=%d %s\n", res, list, list->size(), i, item->name); + list->append(res); + if (lc->ch != ',') { /* if no other item follows */ + break; /* get out */ + } + LexGetToken(lc, BCT_ALL); /* eat comma */ + } + } + ScanToEol(lc); + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); } /* * Store a string in an alist. */ -static void StoreAlistStr(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::StoreAlistStr(LEX *lc, ResourceItem *item, int index, int pass) { - alist *list; - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; - - if (pass == 2) { - if (!*(item->value)) { - *(item->alistvalue) = New(alist(10, owned_by_alist)); + alist *list; + UnionOfResources *res_all = reinterpret_cast(res_all_); + + if (pass == 2) { + if (!*(item->value)) { + *(item->alistvalue) = New(alist(10, owned_by_alist)); + } + list = *(item->alistvalue); + + LexGetToken(lc, BCT_STRING); /* scan next item */ + Dmsg4(900, "Append %s to alist %p size=%d %s\n", lc->str, list, list->size(), item->name); + + /* + * See if we need to drop the default value from the alist. + * + * We first check to see if the config item has the CFG_ITEM_DEFAULT + * flag set and currently has exactly one entry. + */ + if ((item->flags & CFG_ITEM_DEFAULT) && list->size() == 1) { + char *entry; + + entry = (char *)list->first(); + if (bstrcmp(entry, item->default_value)) { + list->destroy(); + list->init(10, owned_by_alist); } - list = *(item->alistvalue); + } - LexGetToken(lc, BCT_STRING); /* scan next item */ - Dmsg4(900, "Append %s to alist %p size=%d %s\n", - lc->str, list, list->size(), item->name); - - /* - * See if we need to drop the default value from the alist. - * - * We first check to see if the config item has the CFG_ITEM_DEFAULT - * flag set and currently has exactly one entry. - */ - if ((item->flags & CFG_ITEM_DEFAULT) && list->size() == 1) { - char *entry; - - entry = (char *)list->first(); - if (bstrcmp(entry, item->default_value)) { - list->destroy(); - list->init(10, owned_by_alist); - } - } - - list->append(bstrdup(lc->str)); - } - ScanToEol(lc); - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); + list->append(bstrdup(lc->str)); + } + ScanToEol(lc); + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); } /* @@ -695,83 +674,79 @@ static void StoreAlistStr(LEX *lc, ResourceItem *item, int index, int pass) * with a vertical bar (i.e. it will likely be passed to the * shell later). */ -static void StoreAlistDir(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::StoreAlistDir(LEX *lc, ResourceItem *item, int index, int pass) { - alist *list; - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; - - if (pass == 2) { - if (!*(item->alistvalue)) { - *(item->alistvalue) = New(alist(10, owned_by_alist)); - } - list = *(item->alistvalue); - - LexGetToken(lc, BCT_STRING); /* scan next item */ - Dmsg4(900, "Append %s to alist %p size=%d %s\n", - lc->str, list, list->size(), item->name); - - if (lc->str[0] != '|') { - DoShellExpansion(lc->str, SizeofPoolMemory(lc->str)); - } - - /* - * See if we need to drop the default value from the alist. - * - * We first check to see if the config item has the CFG_ITEM_DEFAULT - * flag set and currently has exactly one entry. - */ - if ((item->flags & CFG_ITEM_DEFAULT) && list->size() == 1) { - char *entry; - - entry = (char *)list->first(); - if (bstrcmp(entry, item->default_value)) { - list->destroy(); - list->init(10, owned_by_alist); - } + alist *list; + UnionOfResources *res_all = reinterpret_cast(res_all_); + + if (pass == 2) { + if (!*(item->alistvalue)) { + *(item->alistvalue) = New(alist(10, owned_by_alist)); + } + list = *(item->alistvalue); + + LexGetToken(lc, BCT_STRING); /* scan next item */ + Dmsg4(900, "Append %s to alist %p size=%d %s\n", lc->str, list, list->size(), item->name); + + if (lc->str[0] != '|') { + DoShellExpansion(lc->str, SizeofPoolMemory(lc->str)); + } + + /* + * See if we need to drop the default value from the alist. + * + * We first check to see if the config item has the CFG_ITEM_DEFAULT + * flag set and currently has exactly one entry. + */ + if ((item->flags & CFG_ITEM_DEFAULT) && list->size() == 1) { + char *entry; + + entry = (char *)list->first(); + if (bstrcmp(entry, item->default_value)) { + list->destroy(); + list->init(10, owned_by_alist); } + } - list->append(bstrdup(lc->str)); - } - ScanToEol(lc); - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); + list->append(bstrdup(lc->str)); + } + ScanToEol(lc); + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); } /* * Store a list of plugin names to load by the daemon on startup. */ -static void StorePluginNames(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::StorePluginNames(LEX *lc, ResourceItem *item, int index, int pass) { - alist *list; - char *p, *plugin_name, *plugin_names; - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; - - if (pass == 2) { - LexGetToken(lc, BCT_STRING); /* scan next item */ - - if (!*(item->alistvalue)) { - *(item->alistvalue) = New(alist(10, owned_by_alist)); + alist *list; + char *p, *plugin_name, *plugin_names; + UnionOfResources *res_all = reinterpret_cast(res_all_); + + if (pass == 2) { + LexGetToken(lc, BCT_STRING); /* scan next item */ + + if (!*(item->alistvalue)) { + *(item->alistvalue) = New(alist(10, owned_by_alist)); + } + list = *(item->alistvalue); + + plugin_names = bstrdup(lc->str); + plugin_name = plugin_names; + while (plugin_name) { + if ((p = strchr(plugin_name, ':'))) { /* split string at ':' */ + *p++ = '\0'; } - list = *(item->alistvalue); - - plugin_names = bstrdup(lc->str); - plugin_name = plugin_names; - while (plugin_name) { - /* - * Split the plugin_names string on ':' - */ - if ((p = strchr(plugin_name, ':'))) { - *p++ = '\0'; - } - - list->append(bstrdup(plugin_name)); - plugin_name = p; - } - free(plugin_names); - } - ScanToEol(lc); - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); + + list->append(bstrdup(plugin_name)); + plugin_name = p; + } + free(plugin_names); + } + ScanToEol(lc); + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); } /* @@ -783,311 +758,308 @@ static void StorePluginNames(LEX *lc, ResourceItem *item, int index, int pass) * Note, here item points to the main resource (e.g. Job, not * the jobdefs, which we look up). */ -static void StoreDefs(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::StoreDefs(LEX *lc, ResourceItem *item, int index, int pass) { - CommonResourceHeader *res; - - LexGetToken(lc, BCT_NAME); - if (pass == 2) { - Dmsg2(900, "Code=%d name=%s\n", item->code, lc->str); - res = my_config->GetResWithName(item->code, lc->str); - if (res == NULL) { - scan_err3(lc, _("Missing config Resource \"%s\" referenced on line %d : %s\n"), - lc->str, lc->line_no, lc->line); - return; - } - } - ScanToEol(lc); + CommonResourceHeader *res; + + LexGetToken(lc, BCT_NAME); + if (pass == 2) { + Dmsg2(900, "Code=%d name=%s\n", item->code, lc->str); + res = GetResWithName(item->code, lc->str); + if (res == NULL) { + scan_err3(lc, _("Missing config Resource \"%s\" referenced on line %d : %s\n"), lc->str, lc->line_no, + lc->line); + return; + } + } + ScanToEol(lc); } /* * Store an integer at specified address */ -static void store_int16(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::store_int16(LEX *lc, ResourceItem *item, int index, int pass) { - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; + UnionOfResources *res_all = reinterpret_cast(res_all_); - LexGetToken(lc, BCT_INT16); - *(item->i16value) = lc->u.int16_val; - ScanToEol(lc); - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); + LexGetToken(lc, BCT_INT16); + *(item->i16value) = lc->u.int16_val; + ScanToEol(lc); + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); } -static void store_int32(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::store_int32(LEX *lc, ResourceItem *item, int index, int pass) { - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; + UnionOfResources *res_all = reinterpret_cast(res_all_); - LexGetToken(lc, BCT_INT32); - *(item->i32value) = lc->u.int32_val; - ScanToEol(lc); - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); + LexGetToken(lc, BCT_INT32); + *(item->i32value) = lc->u.int32_val; + ScanToEol(lc); + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); } /* * Store a positive integer at specified address */ -static void store_pint16(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::store_pint16(LEX *lc, ResourceItem *item, int index, int pass) { - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; + UnionOfResources *res_all = reinterpret_cast(res_all_); - LexGetToken(lc, BCT_PINT16); - *(item->ui16value) = lc->u.pint16_val; - ScanToEol(lc); - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); + LexGetToken(lc, BCT_PINT16); + *(item->ui16value) = lc->u.pint16_val; + ScanToEol(lc); + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); } -static void store_pint32(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::store_pint32(LEX *lc, ResourceItem *item, int index, int pass) { - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; + UnionOfResources *res_all = reinterpret_cast(res_all_); - LexGetToken(lc, BCT_PINT32); - *(item->ui32value) = lc->u.pint32_val; - ScanToEol(lc); - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); + LexGetToken(lc, BCT_PINT32); + *(item->ui32value) = lc->u.pint32_val; + ScanToEol(lc); + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); } /* * Store an 64 bit integer at specified address */ -static void store_int64(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::store_int64(LEX *lc, ResourceItem *item, int index, int pass) { - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; + UnionOfResources *res_all = reinterpret_cast(res_all_); - LexGetToken(lc, BCT_INT64); - *(item->i64value) = lc->u.int64_val; - ScanToEol(lc); - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); + LexGetToken(lc, BCT_INT64); + *(item->i64value) = lc->u.int64_val; + ScanToEol(lc); + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); } -/* - * Unit types - */ -enum unit_type { - STORE_SIZE, - STORE_SPEED -}; - /* * Store a size in bytes */ -static void store_int_unit(LEX *lc, ResourceItem *item, int index, int pass, - bool size32, enum unit_type type) +void ConfigurationParser::store_int_unit(LEX *lc, + ResourceItem *item, + int index, + int pass, + bool size32, + enum unit_type type) { - int token; - uint64_t uvalue; - char bsize[500]; - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; - - Dmsg0(900, "Enter store_unit\n"); - token = LexGetToken(lc, BCT_SKIP_EOL); - errno = 0; - switch (token) { - case BCT_NUMBER: - case BCT_IDENTIFIER: - case BCT_UNQUOTED_STRING: - bstrncpy(bsize, lc->str, sizeof(bsize)); /* save first part */ + int token; + uint64_t uvalue; + char bsize[500]; + UnionOfResources *res_all = reinterpret_cast(res_all_); + + Dmsg0(900, "Enter store_unit\n"); + token = LexGetToken(lc, BCT_SKIP_EOL); + errno = 0; + switch (token) { + case BCT_NUMBER: + case BCT_IDENTIFIER: + case BCT_UNQUOTED_STRING: + bstrncpy(bsize, lc->str, sizeof(bsize)); /* save first part */ /* * If terminated by space, scan and get modifier */ while (lc->ch == ' ') { - token = LexGetToken(lc, BCT_ALL); - switch (token) { - case BCT_NUMBER: - case BCT_IDENTIFIER: - case BCT_UNQUOTED_STRING: + token = LexGetToken(lc, BCT_ALL); + switch (token) { + case BCT_NUMBER: + case BCT_IDENTIFIER: + case BCT_UNQUOTED_STRING: bstrncat(bsize, lc->str, sizeof(bsize)); break; - } + } } switch (type) { - case STORE_SIZE: - if (!size_to_uint64(bsize, &uvalue)) { + case STORE_SIZE: + if (!size_to_uint64(bsize, &uvalue)) { scan_err1(lc, _("expected a size number, got: %s"), lc->str); return; - } - break; - case STORE_SPEED: - if (!speed_to_uint64(bsize, &uvalue)) { + } + break; + case STORE_SPEED: + if (!speed_to_uint64(bsize, &uvalue)) { scan_err1(lc, _("expected a speed number, got: %s"), lc->str); return; - } - break; - default: - scan_err0(lc, _("unknown unit type encountered")); - return; + } + break; + default: + scan_err0(lc, _("unknown unit type encountered")); + return; } if (size32) { - *(item->ui32value) = (uint32_t)uvalue; + *(item->ui32value) = (uint32_t)uvalue; } else { - switch (type) { - case STORE_SIZE: + switch (type) { + case STORE_SIZE: *(item->i64value) = uvalue; break; - case STORE_SPEED: + case STORE_SPEED: *(item->ui64value) = uvalue; break; - } + } } break; - default: - scan_err2(lc, _("expected a %s, got: %s"), - (type == STORE_SIZE)?_("size"):_("speed"), lc->str); + default: + scan_err2(lc, _("expected a %s, got: %s"), (type == STORE_SIZE) ? _("size") : _("speed"), lc->str); return; - } - if (token != BCT_EOL) { - ScanToEol(lc); - } - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); - Dmsg0(900, "Leave store_unit\n"); + } + if (token != BCT_EOL) { + ScanToEol(lc); + } + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); + Dmsg0(900, "Leave store_unit\n"); } /* * Store a size in bytes */ -static void store_size32(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::store_size32(LEX *lc, ResourceItem *item, int index, int pass) { - store_int_unit(lc, item, index, pass, true /* 32 bit */, STORE_SIZE); + store_int_unit(lc, item, index, pass, true /* 32 bit */, STORE_SIZE); } /* * Store a size in bytes */ -static void store_size64(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::store_size64(LEX *lc, ResourceItem *item, int index, int pass) { - store_int_unit(lc, item, index, pass, false /* not 32 bit */, STORE_SIZE); + store_int_unit(lc, item, index, pass, false /* not 32 bit */, STORE_SIZE); } /* * Store a speed in bytes/s */ -static void StoreSpeed(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::StoreSpeed(LEX *lc, ResourceItem *item, int index, int pass) { - store_int_unit(lc, item, index, pass, false /* 64 bit */, STORE_SPEED); + store_int_unit(lc, item, index, pass, false /* 64 bit */, STORE_SPEED); } /* * Store a time period in seconds */ -static void StoreTime(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::StoreTime(LEX *lc, ResourceItem *item, int index, int pass) { - int token; - utime_t utime; - char period[500]; - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; - - token = LexGetToken(lc, BCT_SKIP_EOL); - errno = 0; - switch (token) { - case BCT_NUMBER: - case BCT_IDENTIFIER: - case BCT_UNQUOTED_STRING: - bstrncpy(period, lc->str, sizeof(period)); /* get first part */ + int token; + utime_t utime; + char period[500]; + UnionOfResources *res_all = reinterpret_cast(res_all_); + + token = LexGetToken(lc, BCT_SKIP_EOL); + errno = 0; + switch (token) { + case BCT_NUMBER: + case BCT_IDENTIFIER: + case BCT_UNQUOTED_STRING: + bstrncpy(period, lc->str, sizeof(period)); /* get first part */ /* * If terminated by space, scan and get modifier */ while (lc->ch == ' ') { - token = LexGetToken(lc, BCT_ALL); - switch (token) { - case BCT_NUMBER: - case BCT_IDENTIFIER: - case BCT_UNQUOTED_STRING: + token = LexGetToken(lc, BCT_ALL); + switch (token) { + case BCT_NUMBER: + case BCT_IDENTIFIER: + case BCT_UNQUOTED_STRING: bstrncat(period, lc->str, sizeof(period)); break; - } + } } if (!DurationToUtime(period, &utime)) { - scan_err1(lc, _("expected a time period, got: %s"), period); - return; + scan_err1(lc, _("expected a time period, got: %s"), period); + return; } *(item->utimevalue) = utime; break; - default: + default: scan_err1(lc, _("expected a time period, got: %s"), lc->str); return; - } - if (token != BCT_EOL) { - ScanToEol(lc); - } - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); + } + if (token != BCT_EOL) { + ScanToEol(lc); + } + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); } /* * Store a yes/no in a bit field */ -static void StoreBit(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::StoreBit(LEX *lc, ResourceItem *item, int index, int pass) { - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; - - LexGetToken(lc, BCT_NAME); - if (Bstrcasecmp(lc->str, "yes") || Bstrcasecmp(lc->str, "true")) { - SetBit(item->code, item->bitvalue); - } else if (Bstrcasecmp(lc->str, "no") || Bstrcasecmp(lc->str, "false")) { - ClearBit(item->code, item->bitvalue); - } else { - scan_err2(lc, _("Expect %s, got: %s"), "YES, NO, TRUE, or FALSE", lc->str); /* YES and NO must not be translated */ - return; - } - ScanToEol(lc); - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); + UnionOfResources *res_all = reinterpret_cast(res_all_); + + LexGetToken(lc, BCT_NAME); + if (Bstrcasecmp(lc->str, "yes") || Bstrcasecmp(lc->str, "true")) { + SetBit(item->code, item->bitvalue); + } else if (Bstrcasecmp(lc->str, "no") || Bstrcasecmp(lc->str, "false")) { + ClearBit(item->code, item->bitvalue); + } else { + scan_err2(lc, _("Expect %s, got: %s"), "YES, NO, TRUE, or FALSE", + lc->str); /* YES and NO must not be translated */ + return; + } + ScanToEol(lc); + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); } /* * Store a bool in a bit field */ -static void StoreBool(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::StoreBool(LEX *lc, ResourceItem *item, int index, int pass) { - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; - - LexGetToken(lc, BCT_NAME); - if (Bstrcasecmp(lc->str, "yes") || Bstrcasecmp(lc->str, "true")) { - *item->boolvalue = true; - } else if (Bstrcasecmp(lc->str, "no") || Bstrcasecmp(lc->str, "false")) { - *(item->boolvalue) = false; - } else { - scan_err2(lc, _("Expect %s, got: %s"), "YES, NO, TRUE, or FALSE", lc->str); /* YES and NO must not be translated */ - return; - } - ScanToEol(lc); - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); + UnionOfResources *res_all = reinterpret_cast(res_all_); + + LexGetToken(lc, BCT_NAME); + if (Bstrcasecmp(lc->str, "yes") || Bstrcasecmp(lc->str, "true")) { + *item->boolvalue = true; + } else if (Bstrcasecmp(lc->str, "no") || Bstrcasecmp(lc->str, "false")) { + *(item->boolvalue) = false; + } else { + scan_err2(lc, _("Expect %s, got: %s"), "YES, NO, TRUE, or FALSE", + lc->str); /* YES and NO must not be translated */ + return; + } + ScanToEol(lc); + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); } /* * Store Tape Label Type (BAREOS, ANSI, IBM) */ -static void StoreLabel(LEX *lc, ResourceItem *item, int index, int pass) +void ConfigurationParser::StoreLabel(LEX *lc, ResourceItem *item, int index, int pass) { - int i; - UnionOfResources *res_all = (UnionOfResources *)my_config->res_all_; - - LexGetToken(lc, BCT_NAME); - /* - * Store the label pass 2 so that type is defined - */ - for (i = 0; tapelabels[i].name; i++) { - if (Bstrcasecmp(lc->str, tapelabels[i].name)) { - *(item->ui32value) = tapelabels[i].token; - i = 0; - break; - } - } - if (i != 0) { - scan_err1(lc, _("Expected a Tape Label keyword, got: %s"), lc->str); - return; - } - ScanToEol(lc); - SetBit(index, res_all->hdr.item_present); - ClearBit(index, res_all->hdr.inherit_content); + int i; + UnionOfResources *res_all = reinterpret_cast(res_all_); + + LexGetToken(lc, BCT_NAME); + /* + * Store the label pass 2 so that type is defined + */ + for (i = 0; tapelabels[i].name; i++) { + if (Bstrcasecmp(lc->str, tapelabels[i].name)) { + *(item->ui32value) = tapelabels[i].token; + i = 0; + break; + } + } + if (i != 0) { + scan_err1(lc, _("Expected a Tape Label keyword, got: %s"), lc->str); + return; + } + ScanToEol(lc); + SetBit(index, res_all->hdr.item_present); + ClearBit(index, res_all->hdr.inherit_content); } /* @@ -1123,868 +1095,846 @@ static void StoreLabel(LEX *lc, ResourceItem *item, int index, int pass) * = { ipv4 { addr = doof.nowaytoheavenxyz.uhu; } } * = { ipv4 { port = 4711 } } */ -static void StoreAddresses(LEX * lc, ResourceItem * item, int index, int pass) +void ConfigurationParser::StoreAddresses(LEX *lc, ResourceItem *item, int index, int pass) { - int token; - int exist; - int family = 0; - char errmsg[1024]; - char port_str[128]; - char hostname_str[1024]; - enum { - EMPTYLINE = 0x0, - PORTLINE = 0x1, - ADDRLINE = 0x2 - } next_line = EMPTYLINE; - int port = str_to_int32(item->default_value); - - token = LexGetToken(lc, BCT_SKIP_EOL); - if (token != BCT_BOB) { - scan_err1(lc, _("Expected a block begin { , got: %s"), lc->str); - } - token = LexGetToken(lc, BCT_SKIP_EOL); - if (token == BCT_EOB) { - scan_err0(lc, _("Empty addr block is not allowed")); - } - do { - if (!(token == BCT_UNQUOTED_STRING || token == BCT_IDENTIFIER)) { - scan_err1(lc, _("Expected a string, got: %s"), lc->str); - } - if (Bstrcasecmp("ip", lc->str) || Bstrcasecmp("ipv4", lc->str)) { - family = AF_INET; + int token; + int exist; + int family = 0; + char errmsg[1024]; + char port_str[128]; + char hostname_str[1024]; + enum + { + EMPTYLINE = 0x0, + PORTLINE = 0x1, + ADDRLINE = 0x2 + } next_line = EMPTYLINE; + int port = str_to_int32(item->default_value); + + token = LexGetToken(lc, BCT_SKIP_EOL); + if (token != BCT_BOB) { + scan_err1(lc, _("Expected a block begin { , got: %s"), lc->str); + } + token = LexGetToken(lc, BCT_SKIP_EOL); + if (token == BCT_EOB) { + scan_err0(lc, _("Empty addr block is not allowed")); + } + do { + if (!(token == BCT_UNQUOTED_STRING || token == BCT_IDENTIFIER)) { + scan_err1(lc, _("Expected a string, got: %s"), lc->str); + } + if (Bstrcasecmp("ip", lc->str) || Bstrcasecmp("ipv4", lc->str)) { + family = AF_INET; #ifdef HAVE_IPV6 - } else if (Bstrcasecmp("ipv6", lc->str)) { - family = AF_INET6; - } else { - scan_err1(lc, _("Expected a string [ip|ipv4|ipv6], got: %s"), lc->str); - } + } else if (Bstrcasecmp("ipv6", lc->str)) { + family = AF_INET6; + } else { + scan_err1(lc, _("Expected a string [ip|ipv4|ipv6], got: %s"), lc->str); + } #else + } else { + scan_err1(lc, _("Expected a string [ip|ipv4], got: %s"), lc->str); + } +#endif + token = LexGetToken(lc, BCT_SKIP_EOL); + if (token != BCT_EQUALS) { + scan_err1(lc, _("Expected a equal =, got: %s"), lc->str); + } + token = LexGetToken(lc, BCT_SKIP_EOL); + if (token != BCT_BOB) { + scan_err1(lc, _("Expected a block begin { , got: %s"), lc->str); + } + token = LexGetToken(lc, BCT_SKIP_EOL); + exist = EMPTYLINE; + port_str[0] = hostname_str[0] = '\0'; + do { + if (token != BCT_IDENTIFIER) { + scan_err1(lc, _("Expected a identifier [addr|port], got: %s"), lc->str); + } + if (Bstrcasecmp("port", lc->str)) { + next_line = PORTLINE; + if (exist & PORTLINE) { + scan_err0(lc, _("Only one port per address block")); + } + exist |= PORTLINE; + } else if (Bstrcasecmp("addr", lc->str)) { + next_line = ADDRLINE; + if (exist & ADDRLINE) { + scan_err0(lc, _("Only one addr per address block")); + } + exist |= ADDRLINE; } else { - scan_err1(lc, _("Expected a string [ip|ipv4], got: %s"), lc->str); + scan_err1(lc, _("Expected a identifier [addr|port], got: %s"), lc->str); } -#endif token = LexGetToken(lc, BCT_SKIP_EOL); if (token != BCT_EQUALS) { - scan_err1(lc, _("Expected a equal =, got: %s"), lc->str); + scan_err1(lc, _("Expected a equal =, got: %s"), lc->str); } token = LexGetToken(lc, BCT_SKIP_EOL); - if (token != BCT_BOB) { - scan_err1(lc, _("Expected a block begin { , got: %s"), lc->str); + switch (next_line) { + case PORTLINE: + if (!(token == BCT_UNQUOTED_STRING || token == BCT_NUMBER || token == BCT_IDENTIFIER)) { + scan_err1(lc, _("Expected a number or a string, got: %s"), lc->str); + } + bstrncpy(port_str, lc->str, sizeof(port_str)); + break; + case ADDRLINE: + if (!(token == BCT_UNQUOTED_STRING || token == BCT_IDENTIFIER)) { + scan_err1(lc, _("Expected an IP number or a hostname, got: %s"), lc->str); + } + bstrncpy(hostname_str, lc->str, sizeof(hostname_str)); + break; + case EMPTYLINE: + scan_err0(lc, _("State machine mismatch")); + break; } token = LexGetToken(lc, BCT_SKIP_EOL); - exist = EMPTYLINE; - port_str[0] = hostname_str[0] = '\0'; - do { - if (token != BCT_IDENTIFIER) { - scan_err1(lc, _("Expected a identifier [addr|port], got: %s"), lc->str); - } - if (Bstrcasecmp("port", lc->str)) { - next_line = PORTLINE; - if (exist & PORTLINE) { - scan_err0(lc, _("Only one port per address block")); - } - exist |= PORTLINE; - } else if (Bstrcasecmp("addr", lc->str)) { - next_line = ADDRLINE; - if (exist & ADDRLINE) { - scan_err0(lc, _("Only one addr per address block")); - } - exist |= ADDRLINE; - } else { - scan_err1(lc, _("Expected a identifier [addr|port], got: %s"), lc->str); - } - token = LexGetToken(lc, BCT_SKIP_EOL); - if (token != BCT_EQUALS) { - scan_err1(lc, _("Expected a equal =, got: %s"), lc->str); - } - token = LexGetToken(lc, BCT_SKIP_EOL); - switch (next_line) { - case PORTLINE: - if (!(token == BCT_UNQUOTED_STRING || token == BCT_NUMBER || token == BCT_IDENTIFIER)) { - scan_err1(lc, _("Expected a number or a string, got: %s"), lc->str); - } - bstrncpy(port_str, lc->str, sizeof(port_str)); - break; - case ADDRLINE: - if (!(token == BCT_UNQUOTED_STRING || token == BCT_IDENTIFIER)) { - scan_err1(lc, _("Expected an IP number or a hostname, got: %s"), - lc->str); - } - bstrncpy(hostname_str, lc->str, sizeof(hostname_str)); - break; - case EMPTYLINE: - scan_err0(lc, _("State machine mismatch")); - break; - } - token = LexGetToken(lc, BCT_SKIP_EOL); - } while (token == BCT_IDENTIFIER); - if (token != BCT_EOB) { - scan_err1(lc, _("Expected a end of block }, got: %s"), lc->str); - } - if (pass == 1 && !AddAddress(item->dlistvalue, IPADDR::R_MULTIPLE, - htons(port), family, hostname_str, port_str, - errmsg, sizeof(errmsg))) { - scan_err3(lc, _("Can't add hostname(%s) and port(%s) to addrlist (%s)"), - hostname_str, port_str, errmsg); - } - token = ScanToNextNotEol(lc); - } while ((token == BCT_IDENTIFIER || token == BCT_UNQUOTED_STRING)); - if (token != BCT_EOB) { + } while (token == BCT_IDENTIFIER); + if (token != BCT_EOB) { scan_err1(lc, _("Expected a end of block }, got: %s"), lc->str); - } + } + if (pass == 1 && !AddAddress(item->dlistvalue, IPADDR::R_MULTIPLE, htons(port), family, hostname_str, + port_str, errmsg, sizeof(errmsg))) { + scan_err3(lc, _("Can't add hostname(%s) and port(%s) to addrlist (%s)"), hostname_str, port_str, errmsg); + } + token = ScanToNextNotEol(lc); + } while ((token == BCT_IDENTIFIER || token == BCT_UNQUOTED_STRING)); + if (token != BCT_EOB) { + scan_err1(lc, _("Expected a end of block }, got: %s"), lc->str); + } } -static void StoreAddressesAddress(LEX * lc, ResourceItem * item, int index, int pass) +void ConfigurationParser::StoreAddressesAddress(LEX *lc, ResourceItem *item, int index, int pass) { - int token; - char errmsg[1024]; - int port = str_to_int32(item->default_value); - - token = LexGetToken(lc, BCT_SKIP_EOL); - if (!(token == BCT_UNQUOTED_STRING || token == BCT_NUMBER || token == BCT_IDENTIFIER)) { - scan_err1(lc, _("Expected an IP number or a hostname, got: %s"), lc->str); - } - if (pass == 1 && !AddAddress(item->dlistvalue, IPADDR::R_SINGLE_ADDR, - htons(port), AF_INET, lc->str, 0, - errmsg, sizeof(errmsg))) { - scan_err2(lc, _("can't add port (%s) to (%s)"), lc->str, errmsg); - } + int token; + char errmsg[1024]; + int port = str_to_int32(item->default_value); + + token = LexGetToken(lc, BCT_SKIP_EOL); + if (!(token == BCT_UNQUOTED_STRING || token == BCT_NUMBER || token == BCT_IDENTIFIER)) { + scan_err1(lc, _("Expected an IP number or a hostname, got: %s"), lc->str); + } + if (pass == 1 && !AddAddress(item->dlistvalue, IPADDR::R_SINGLE_ADDR, htons(port), AF_INET, lc->str, 0, + errmsg, sizeof(errmsg))) { + scan_err2(lc, _("can't add port (%s) to (%s)"), lc->str, errmsg); + } } -static void StoreAddressesPort(LEX * lc, ResourceItem * item, int index, int pass) +void ConfigurationParser::StoreAddressesPort(LEX *lc, ResourceItem *item, int index, int pass) { - int token; - char errmsg[1024]; - int port = str_to_int32(item->default_value); - - token = LexGetToken(lc, BCT_SKIP_EOL); - if (!(token == BCT_UNQUOTED_STRING || token == BCT_NUMBER || token == BCT_IDENTIFIER)) { - scan_err1(lc, _("Expected a port number or string, got: %s"), lc->str); - } - if (pass == 1 && !AddAddress(item->dlistvalue, IPADDR::R_SINGLE_PORT, - htons(port), AF_INET, 0, lc->str, - errmsg, sizeof(errmsg))) { - scan_err2(lc, _("can't add port (%s) to (%s)"), lc->str, errmsg); - } + int token; + char errmsg[1024]; + int port = str_to_int32(item->default_value); + + token = LexGetToken(lc, BCT_SKIP_EOL); + if (!(token == BCT_UNQUOTED_STRING || token == BCT_NUMBER || token == BCT_IDENTIFIER)) { + scan_err1(lc, _("Expected a port number or string, got: %s"), lc->str); + } + if (pass == 1 && !AddAddress(item->dlistvalue, IPADDR::R_SINGLE_PORT, htons(port), AF_INET, 0, lc->str, + errmsg, sizeof(errmsg))) { + scan_err2(lc, _("can't add port (%s) to (%s)"), lc->str, errmsg); + } } /* * Generic store resource dispatcher. */ -bool StoreResource(int type, LEX *lc, ResourceItem *item, int index, int pass) +bool ConfigurationParser::StoreResource(int type, LEX *lc, ResourceItem *item, int index, int pass) { - switch (type) { - case CFG_TYPE_STR: + switch (type) { + case CFG_TYPE_STR: StoreStr(lc, item, index, pass); break; - case CFG_TYPE_DIR: + case CFG_TYPE_DIR: StoreDir(lc, item, index, pass); break; - case CFG_TYPE_STDSTR: + case CFG_TYPE_STDSTR: StoreStdstr(lc, item, index, pass); break; - case CFG_TYPE_STDSTRDIR: + case CFG_TYPE_STDSTRDIR: StoreStdstrdir(lc, item, index, pass); break; - case CFG_TYPE_MD5PASSWORD: + case CFG_TYPE_MD5PASSWORD: store_md5password(lc, item, index, pass); break; - case CFG_TYPE_CLEARPASSWORD: + case CFG_TYPE_CLEARPASSWORD: StoreClearpassword(lc, item, index, pass); break; - case CFG_TYPE_NAME: + case CFG_TYPE_NAME: StoreName(lc, item, index, pass); break; - case CFG_TYPE_STRNAME: + case CFG_TYPE_STRNAME: StoreStrname(lc, item, index, pass); break; - case CFG_TYPE_RES: + case CFG_TYPE_RES: StoreRes(lc, item, index, pass); break; - case CFG_TYPE_ALIST_RES: + case CFG_TYPE_ALIST_RES: StoreAlistRes(lc, item, index, pass); break; - case CFG_TYPE_ALIST_STR: + case CFG_TYPE_ALIST_STR: StoreAlistStr(lc, item, index, pass); break; - case CFG_TYPE_ALIST_DIR: + case CFG_TYPE_ALIST_DIR: StoreAlistDir(lc, item, index, pass); break; - case CFG_TYPE_INT16: + case CFG_TYPE_INT16: store_int16(lc, item, index, pass); break; - case CFG_TYPE_PINT16: + case CFG_TYPE_PINT16: store_pint16(lc, item, index, pass); break; - case CFG_TYPE_INT32: + case CFG_TYPE_INT32: store_int32(lc, item, index, pass); break; - case CFG_TYPE_PINT32: + case CFG_TYPE_PINT32: store_pint32(lc, item, index, pass); break; - case CFG_TYPE_MSGS: + case CFG_TYPE_MSGS: StoreMsgs(lc, item, index, pass); break; - case CFG_TYPE_INT64: + case CFG_TYPE_INT64: store_int64(lc, item, index, pass); break; - case CFG_TYPE_BIT: + case CFG_TYPE_BIT: StoreBit(lc, item, index, pass); break; - case CFG_TYPE_BOOL: + case CFG_TYPE_BOOL: StoreBool(lc, item, index, pass); break; - case CFG_TYPE_TIME: + case CFG_TYPE_TIME: StoreTime(lc, item, index, pass); break; - case CFG_TYPE_SIZE64: + case CFG_TYPE_SIZE64: store_size64(lc, item, index, pass); break; - case CFG_TYPE_SIZE32: + case CFG_TYPE_SIZE32: store_size32(lc, item, index, pass); break; - case CFG_TYPE_SPEED: + case CFG_TYPE_SPEED: StoreSpeed(lc, item, index, pass); break; - case CFG_TYPE_DEFS: + case CFG_TYPE_DEFS: StoreDefs(lc, item, index, pass); break; - case CFG_TYPE_LABEL: + case CFG_TYPE_LABEL: StoreLabel(lc, item, index, pass); break; - case CFG_TYPE_ADDRESSES: + case CFG_TYPE_ADDRESSES: StoreAddresses(lc, item, index, pass); break; - case CFG_TYPE_ADDRESSES_ADDRESS: + case CFG_TYPE_ADDRESSES_ADDRESS: StoreAddressesAddress(lc, item, index, pass); break; - case CFG_TYPE_ADDRESSES_PORT: + case CFG_TYPE_ADDRESSES_PORT: StoreAddressesPort(lc, item, index, pass); break; - case CFG_TYPE_PLUGIN_NAMES: + case CFG_TYPE_PLUGIN_NAMES: StorePluginNames(lc, item, index, pass); break; - default: + default: return false; - } + } - return true; + return true; } void IndentConfigItem(PoolMem &cfg_str, int level, const char *config_item, bool inherited) { - for (int i = 0; i < level; i++) { - PmStrcat(cfg_str, DEFAULT_INDENT_STRING); - } - if (inherited) { - PmStrcat(cfg_str, "#"); - PmStrcat(cfg_str, DEFAULT_INDENT_STRING); - } - PmStrcat(cfg_str, config_item); + for (int i = 0; i < level; i++) { + PmStrcat(cfg_str, DEFAULT_INDENT_STRING); + } + if (inherited) { + PmStrcat(cfg_str, "#"); + PmStrcat(cfg_str, DEFAULT_INDENT_STRING); + } + PmStrcat(cfg_str, config_item); } -static inline void PrintConfigSize(ResourceItem *item, PoolMem &cfg_str, bool inherited) +static void PrintConfigSize(ResourceItem *item, PoolMem &cfg_str, bool inherited) { - PoolMem temp; - PoolMem volspec; /* vol specification string*/ - int64_t bytes = *(item->ui64value); - int factor; - - /* - * convert default value string to numeric value - */ - static const char *modifier[] = { - "g", - "m", - "k", - "", - NULL - }; - const int64_t multiplier[] = { - 1073741824, /* gibi */ - 1048576, /* mebi */ - 1024, /* kibi */ - 1 /* byte */ - }; - - if (bytes == 0) { - PmStrcat(volspec, "0"); - } else { - for (int t=0; modifier[t]; t++) { - Dmsg2(200, " %s bytes: %lld\n", item->name, bytes); - factor = bytes / multiplier[t]; - bytes = bytes % multiplier[t]; - if (factor > 0) { - Mmsg(temp, "%d %s ", factor, modifier[t]); - PmStrcat(volspec, temp.c_str()); - Dmsg1(200, " volspec: %s\n", volspec.c_str()); - } - if (bytes == 0) { - break; - } + PoolMem temp; + PoolMem volspec; /* vol specification string*/ + int64_t bytes = *(item->ui64value); + int factor; + + /* + * convert default value string to numeric value + */ + static const char *modifier[] = {"g", "m", "k", "", NULL}; + const int64_t multiplier[] = { + 1073741824, /* gibi */ + 1048576, /* mebi */ + 1024, /* kibi */ + 1 /* byte */ + }; + + if (bytes == 0) { + PmStrcat(volspec, "0"); + } else { + for (int t = 0; modifier[t]; t++) { + Dmsg2(200, " %s bytes: %lld\n", item->name, bytes); + factor = bytes / multiplier[t]; + bytes = bytes % multiplier[t]; + if (factor > 0) { + Mmsg(temp, "%d %s ", factor, modifier[t]); + PmStrcat(volspec, temp.c_str()); + Dmsg1(200, " volspec: %s\n", volspec.c_str()); + } + if (bytes == 0) { + break; } - } + } + } - Mmsg(temp, "%s = %s\n", item->name, volspec.c_str()); - IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); + Mmsg(temp, "%s = %s\n", item->name, volspec.c_str()); + IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); } -static inline void PrintConfigTime(ResourceItem *item, PoolMem &cfg_str, bool inherited) +static void PrintConfigTime(ResourceItem *item, PoolMem &cfg_str, bool inherited) { - PoolMem temp; - PoolMem timespec; - utime_t secs = *(item->utimevalue); - int factor; - - /* - * Reverse time formatting: 1 Month, 1 Week, etc. - * - * convert default value string to numeric value - */ - static const char *modifier[] = { - "years", - "months", - "weeks", - "days", - "hours", - "minutes", - "seconds", - NULL - }; - static const int32_t multiplier[] = { - 60 * 60 * 24 * 365, - 60 * 60 * 24 * 30, - 60 * 60 * 24 * 7, - 60 * 60 * 24, - 60 * 60, - 60, - 1, - 0 - }; - - if (secs == 0) { - PmStrcat(timespec, "0"); - } else { - for (int t=0; modifier[t]; t++) { - factor = secs / multiplier[t]; - secs = secs % multiplier[t]; - if (factor > 0) { - Mmsg(temp, "%d %s ", factor, modifier[t]); - PmStrcat(timespec, temp.c_str()); - } - if (secs == 0) { - break; - } + PoolMem temp; + PoolMem timespec; + utime_t secs = *(item->utimevalue); + int factor; + + /* + * Reverse time formatting: 1 Month, 1 Week, etc. + * + * convert default value string to numeric value + */ + static const char *modifier[] = {"years", "months", "weeks", "days", "hours", "minutes", "seconds", NULL}; + static const int32_t multiplier[] = { + 60 * 60 * 24 * 365, 60 * 60 * 24 * 30, 60 * 60 * 24 * 7, 60 * 60 * 24, 60 * 60, 60, 1, 0}; + + if (secs == 0) { + PmStrcat(timespec, "0"); + } else { + for (int t = 0; modifier[t]; t++) { + factor = secs / multiplier[t]; + secs = secs % multiplier[t]; + if (factor > 0) { + Mmsg(temp, "%d %s ", factor, modifier[t]); + PmStrcat(timespec, temp.c_str()); + } + if (secs == 0) { + break; } - } + } + } - Mmsg(temp, "%s = %s\n", item->name, timespec.c_str()); - IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); + Mmsg(temp, "%s = %s\n", item->name, timespec.c_str()); + IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); } bool MessagesResource::PrintConfig(PoolMem &buff, bool hide_sensitive_data, bool verbose) { - PoolMem cfg_str; /* configuration as string */ - PoolMem temp; - MessagesResource *msgres; - DEST *d; - - msgres = this; - - PmStrcat(cfg_str, "Messages {\n"); - Mmsg(temp, " %s = \"%s\"\n", "Name", msgres->name()); - PmStrcat(cfg_str, temp.c_str()); - - if (msgres->mail_cmd) { - PoolMem esc; - - EscapeString(esc, msgres->mail_cmd, strlen(msgres->mail_cmd)); - Mmsg(temp, " MailCommand = \"%s\"\n", esc.c_str()); - PmStrcat(cfg_str, temp.c_str()); - } - - if (msgres->operator_cmd) { - PoolMem esc; - - EscapeString(esc, msgres->operator_cmd, strlen(msgres->operator_cmd)); - Mmsg(temp, " OperatorCommand = \"%s\"\n", esc.c_str()); - PmStrcat(cfg_str, temp.c_str()); - } - - if (msgres->timestamp_format) { - PoolMem esc; - - EscapeString(esc, msgres->timestamp_format, strlen(msgres->timestamp_format)); - Mmsg(temp, " TimestampFormat = \"%s\"\n", esc.c_str()); - PmStrcat(cfg_str, temp.c_str()); - } - - for (d = msgres->dest_chain; d; d = d->next) { - int nr_set = 0; - int nr_unset = 0; - PoolMem t; /* number of set types */ - PoolMem u; /* number of unset types */ - - for (int i = 0; msg_destinations[i].code; i++) { - if (msg_destinations[i].code == d->dest_code) { - if (msg_destinations[i].where) { - Mmsg(temp, " %s = %s = ", msg_destinations[i].destination, d->where); - } else { - Mmsg(temp, " %s = ", msg_destinations[i].destination); - } - PmStrcat(cfg_str, temp.c_str()); - break; - } + PoolMem cfg_str; /* configuration as string */ + PoolMem temp; + MessagesResource *msgres; + DEST *d; + + msgres = this; + + PmStrcat(cfg_str, "Messages {\n"); + Mmsg(temp, " %s = \"%s\"\n", "Name", msgres->name()); + PmStrcat(cfg_str, temp.c_str()); + + if (msgres->mail_cmd) { + PoolMem esc; + + EscapeString(esc, msgres->mail_cmd, strlen(msgres->mail_cmd)); + Mmsg(temp, " MailCommand = \"%s\"\n", esc.c_str()); + PmStrcat(cfg_str, temp.c_str()); + } + + if (msgres->operator_cmd) { + PoolMem esc; + + EscapeString(esc, msgres->operator_cmd, strlen(msgres->operator_cmd)); + Mmsg(temp, " OperatorCommand = \"%s\"\n", esc.c_str()); + PmStrcat(cfg_str, temp.c_str()); + } + + if (msgres->timestamp_format) { + PoolMem esc; + + EscapeString(esc, msgres->timestamp_format, strlen(msgres->timestamp_format)); + Mmsg(temp, " TimestampFormat = \"%s\"\n", esc.c_str()); + PmStrcat(cfg_str, temp.c_str()); + } + + for (d = msgres->dest_chain; d; d = d->next) { + int nr_set = 0; + int nr_unset = 0; + PoolMem t; /* number of set types */ + PoolMem u; /* number of unset types */ + + for (int i = 0; msg_destinations[i].code; i++) { + if (msg_destinations[i].code == d->dest_code) { + if (msg_destinations[i].where) { + Mmsg(temp, " %s = %s = ", msg_destinations[i].destination, d->where); + } else { + Mmsg(temp, " %s = ", msg_destinations[i].destination); + } + PmStrcat(cfg_str, temp.c_str()); + break; } - - for (int j = 0; j < M_MAX - 1; j++) { - if BitIsSet(msg_types[j].token, d->msg_types) { - nr_set ++; - Mmsg(temp, ",%s" , msg_types[j].name); - PmStrcat(t, temp.c_str()); - } else { - Mmsg(temp, ",!%s" , msg_types[j].name); - nr_unset++; - PmStrcat(u, temp.c_str()); - } + } + + for (int j = 0; j < M_MAX - 1; j++) { + if + BitIsSet(msg_types[j].token, d->msg_types) + { + nr_set++; + Mmsg(temp, ",%s", msg_types[j].name); + PmStrcat(t, temp.c_str()); + } + else { + Mmsg(temp, ",!%s", msg_types[j].name); + nr_unset++; + PmStrcat(u, temp.c_str()); } + } - if (nr_set > nr_unset) { /* if more is set than is unset */ - PmStrcat(cfg_str,"all"); /* all, but not ... */ - PmStrcat(cfg_str, u.c_str()); - } else { /* only print set types */ - PmStrcat(cfg_str, t.c_str() + 1); /* skip first comma */ - } - PmStrcat(cfg_str, "\n"); - } + if (nr_set > nr_unset) { /* if more is set than is unset */ + PmStrcat(cfg_str, "all"); /* all, but not ... */ + PmStrcat(cfg_str, u.c_str()); + } else { /* only print set types */ + PmStrcat(cfg_str, t.c_str() + 1); /* skip first comma */ + } + PmStrcat(cfg_str, "\n"); + } - PmStrcat (cfg_str, "}\n\n"); - PmStrcat (buff, cfg_str.c_str()); + PmStrcat(cfg_str, "}\n\n"); + PmStrcat(buff, cfg_str.c_str()); - return true; + return true; } -static inline bool HasDefaultValue(ResourceItem *item) +static bool HasDefaultValue(ResourceItem *item) { - bool is_default = false; + bool is_default = false; - if (item->flags & CFG_ITEM_DEFAULT) { - /* - * Check for default values. - */ - switch (item->type) { - case CFG_TYPE_STR: - case CFG_TYPE_DIR: - case CFG_TYPE_NAME: - case CFG_TYPE_STRNAME: - is_default = bstrcmp(*(item->value), item->default_value); - break; - case CFG_TYPE_STDSTR: - case CFG_TYPE_STDSTRDIR: - is_default = bstrcmp((*item->strValue)->c_str(), item->default_value); - break; - case CFG_TYPE_INT16: - is_default = (*(item->i16value) == (int16_t)str_to_int32(item->default_value)); - break; - case CFG_TYPE_PINT16: - is_default = (*(item->ui16value) == (uint16_t)str_to_int32(item->default_value)); - break; - case CFG_TYPE_INT32: - is_default = (*(item->i32value) == str_to_int32(item->default_value)); - break; - case CFG_TYPE_PINT32: - is_default = (*(item->ui32value) == (uint32_t)str_to_int32(item->default_value)); - break; - case CFG_TYPE_INT64: - is_default = (*(item->i64value) == str_to_int64(item->default_value)); - break; - case CFG_TYPE_SPEED: - is_default = (*(item->ui64value) == (uint64_t)str_to_int64(item->default_value)); - break; - case CFG_TYPE_SIZE64: - is_default = (*(item->ui64value) == (uint64_t)str_to_int64(item->default_value)); - break; - case CFG_TYPE_SIZE32: - is_default = (*(item->ui32value) != (uint32_t)str_to_int32(item->default_value)); - break; - case CFG_TYPE_TIME: - is_default = (*(item->ui64value) == (uint64_t)str_to_int64(item->default_value)); - break; - case CFG_TYPE_BOOL: { - bool default_value = Bstrcasecmp(item->default_value, "true") || - Bstrcasecmp(item->default_value, "yes"); - - is_default = (*item->boolvalue == default_value); - break; - } - default: - break; - } - } else { - switch (item->type) { - case CFG_TYPE_STR: - case CFG_TYPE_DIR: - case CFG_TYPE_NAME: - case CFG_TYPE_STRNAME: - is_default = (*(item->value) == NULL); - break; - case CFG_TYPE_STDSTR: - case CFG_TYPE_STDSTRDIR: - is_default = (*(item->strValue)) == nullptr || (*(item->strValue))->empty(); - break; - case CFG_TYPE_INT16: - is_default = (*(item->i16value) == 0); - break; - case CFG_TYPE_PINT16: - is_default = (*(item->ui16value) == 0); - break; - case CFG_TYPE_INT32: - is_default = (*(item->i32value) == 0); - break; - case CFG_TYPE_PINT32: - is_default = (*(item->ui32value) == 0); - break; - case CFG_TYPE_INT64: - is_default = (*(item->i64value) == 0); - break; - case CFG_TYPE_SPEED: - is_default = (*(item->ui64value) == 0); - break; - case CFG_TYPE_SIZE64: - is_default = (*(item->ui64value) == 0); - break; - case CFG_TYPE_SIZE32: - is_default = (*(item->ui32value) == 0); - break; - case CFG_TYPE_TIME: - is_default = (*(item->ui64value) == 0); - break; - case CFG_TYPE_BOOL: - is_default = (*item->boolvalue == false); - break; - default: - break; - } - } + if (item->flags & CFG_ITEM_DEFAULT) { + /* + * Check for default values. + */ + switch (item->type) { + case CFG_TYPE_STR: + case CFG_TYPE_DIR: + case CFG_TYPE_NAME: + case CFG_TYPE_STRNAME: + is_default = bstrcmp(*(item->value), item->default_value); + break; + case CFG_TYPE_STDSTR: + case CFG_TYPE_STDSTRDIR: + is_default = bstrcmp((*item->strValue)->c_str(), item->default_value); + break; + case CFG_TYPE_INT16: + is_default = (*(item->i16value) == (int16_t)str_to_int32(item->default_value)); + break; + case CFG_TYPE_PINT16: + is_default = (*(item->ui16value) == (uint16_t)str_to_int32(item->default_value)); + break; + case CFG_TYPE_INT32: + is_default = (*(item->i32value) == str_to_int32(item->default_value)); + break; + case CFG_TYPE_PINT32: + is_default = (*(item->ui32value) == (uint32_t)str_to_int32(item->default_value)); + break; + case CFG_TYPE_INT64: + is_default = (*(item->i64value) == str_to_int64(item->default_value)); + break; + case CFG_TYPE_SPEED: + is_default = (*(item->ui64value) == (uint64_t)str_to_int64(item->default_value)); + break; + case CFG_TYPE_SIZE64: + is_default = (*(item->ui64value) == (uint64_t)str_to_int64(item->default_value)); + break; + case CFG_TYPE_SIZE32: + is_default = (*(item->ui32value) != (uint32_t)str_to_int32(item->default_value)); + break; + case CFG_TYPE_TIME: + is_default = (*(item->ui64value) == (uint64_t)str_to_int64(item->default_value)); + break; + case CFG_TYPE_BOOL: { + bool default_value = + Bstrcasecmp(item->default_value, "true") || Bstrcasecmp(item->default_value, "yes"); + + is_default = (*item->boolvalue == default_value); + break; + } + default: + break; + } + } else { + switch (item->type) { + case CFG_TYPE_STR: + case CFG_TYPE_DIR: + case CFG_TYPE_NAME: + case CFG_TYPE_STRNAME: + is_default = (*(item->value) == NULL); + break; + case CFG_TYPE_STDSTR: + case CFG_TYPE_STDSTRDIR: + is_default = (*(item->strValue)) == nullptr || (*(item->strValue))->empty(); + break; + case CFG_TYPE_INT16: + is_default = (*(item->i16value) == 0); + break; + case CFG_TYPE_PINT16: + is_default = (*(item->ui16value) == 0); + break; + case CFG_TYPE_INT32: + is_default = (*(item->i32value) == 0); + break; + case CFG_TYPE_PINT32: + is_default = (*(item->ui32value) == 0); + break; + case CFG_TYPE_INT64: + is_default = (*(item->i64value) == 0); + break; + case CFG_TYPE_SPEED: + is_default = (*(item->ui64value) == 0); + break; + case CFG_TYPE_SIZE64: + is_default = (*(item->ui64value) == 0); + break; + case CFG_TYPE_SIZE32: + is_default = (*(item->ui32value) == 0); + break; + case CFG_TYPE_TIME: + is_default = (*(item->ui64value) == 0); + break; + case CFG_TYPE_BOOL: + is_default = (*item->boolvalue == false); + break; + default: + break; + } + } - return is_default; + return is_default; } bool BareosResource::PrintConfig(PoolMem &buff, bool hide_sensitive_data, bool verbose) { - PoolMem cfg_str; - PoolMem temp; - ResourceItem *items; - int i = 0; - int rindex; - bool inherited = false; - - /* - * If entry is not used, then there is nothing to print. - */ - if (this->hdr.rcode < (uint32_t)my_config->r_first_ || - this->hdr.refcnt <= 0) { - return true; - } - rindex = this->hdr.rcode - my_config->r_first_; - - /* - * Make sure the resource class has any items. - */ - if (!my_config->resources_[rindex].items) { - return true; - } - - memcpy(my_config->res_all_, this, my_config->resources_[rindex].size); - - PmStrcat(cfg_str, res_to_str(this->hdr.rcode)); - PmStrcat(cfg_str, " {\n"); - - items = my_config->resources_[rindex].items; - - for (i = 0; items[i].name; i++) { - bool print_item = false; - inherited = BitIsSet(i, this->hdr.inherit_content); - + PoolMem cfg_str; + PoolMem temp; + ResourceItem *items; + int i = 0; + int rindex; + bool inherited = false; + + /* + * If entry is not used, then there is nothing to print. + */ + if (this->hdr.rcode < (uint32_t)my_config->r_first_ || this->hdr.refcnt <= 0) { + return true; + } + rindex = this->hdr.rcode - my_config->r_first_; + + /* + * Make sure the resource class has any items. + */ + if (!my_config->resources_[rindex].items) { + return true; + } + + memcpy(my_config->res_all_, this, my_config->resources_[rindex].size); + + PmStrcat(cfg_str, my_config->res_to_str(this->hdr.rcode)); + PmStrcat(cfg_str, " {\n"); + + items = my_config->resources_[rindex].items; + + for (i = 0; items[i].name; i++) { + bool print_item = false; + inherited = BitIsSet(i, this->hdr.inherit_content); + + /* + * If this is an alias for another config keyword suppress it. + */ + if ((items[i].flags & CFG_ITEM_ALIAS)) { + continue; + } + + if ((!verbose) && inherited) { /* - * If this is an alias for another config keyword suppress it. + * If not in verbose mode, skip inherited directives. */ - if ((items[i].flags & CFG_ITEM_ALIAS)) { - continue; - } + continue; + } - if ((!verbose) && inherited) { - /* - * If not in verbose mode, skip inherited directives. - */ - continue; - } - - if ((items[i].flags & CFG_ITEM_REQUIRED) || !my_config->omit_defaults_) { - /* - * Always print required items or if my_config->omit_defaults_ is false - */ - print_item = true; - } + if ((items[i].flags & CFG_ITEM_REQUIRED) || !my_config->omit_defaults_) { + /* + * Always print required items or if my_config->omit_defaults_ is false + */ + print_item = true; + } - if (!HasDefaultValue(&items[i])) { - print_item = true; - } else { - if ((items[i].flags & CFG_ITEM_DEFAULT) && verbose) { - /* - * If value has a expliciet default value and verbose mode is on, - * display directive as inherited. - */ - print_item = true; - inherited = true; - } + if (!HasDefaultValue(&items[i])) { + print_item = true; + } else { + if ((items[i].flags & CFG_ITEM_DEFAULT) && verbose) { + /* + * If value has a expliciet default value and verbose mode is on, + * display directive as inherited. + */ + print_item = true; + inherited = true; } + } - switch (items[i].type) { + switch (items[i].type) { case CFG_TYPE_STR: case CFG_TYPE_DIR: case CFG_TYPE_NAME: case CFG_TYPE_STRNAME: - if (print_item && *(items[i].value) != NULL) { - Dmsg2(200, "%s = \"%s\"\n", items[i].name, *(items[i].value)); - Mmsg(temp, "%s = \"%s\"\n", items[i].name, *(items[i].value)); - IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); - } - break; + if (print_item && *(items[i].value) != NULL) { + Dmsg2(200, "%s = \"%s\"\n", items[i].name, *(items[i].value)); + Mmsg(temp, "%s = \"%s\"\n", items[i].name, *(items[i].value)); + IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); + } + break; case CFG_TYPE_STDSTR: case CFG_TYPE_STDSTRDIR: - if (print_item && *(items[i].value) != NULL) { - Dmsg2(200, "%s = \"%s\"\n", items[i].name, (*items[i].strValue)->c_str()); - Mmsg(temp, "%s = \"%s\"\n", items[i].name, (*items[i].strValue)->c_str()); - IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); - } - break; + if (print_item && *(items[i].value) != NULL) { + Dmsg2(200, "%s = \"%s\"\n", items[i].name, (*items[i].strValue)->c_str()); + Mmsg(temp, "%s = \"%s\"\n", items[i].name, (*items[i].strValue)->c_str()); + IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); + } + break; case CFG_TYPE_MD5PASSWORD: case CFG_TYPE_CLEARPASSWORD: case CFG_TYPE_AUTOPASSWORD: - if (print_item) { - s_password *password; - - password = items[i].pwdvalue; - if (password && password->value != NULL) { - if (hide_sensitive_data) { - Dmsg1(200, "%s = \"****************\"\n", items[i].name); - Mmsg(temp, "%s = \"****************\"\n", items[i].name); - } else { - switch (password->encoding) { - case p_encoding_clear: - Dmsg2(200, "%s = \"%s\"\n", items[i].name, password->value); - Mmsg(temp, "%s = \"%s\"\n", items[i].name, password->value); - break; - case p_encoding_md5: - Dmsg2(200, "%s = \"[md5]%s\"\n", items[i].name, password->value); - Mmsg(temp, "%s = \"[md5]%s\"\n", items[i].name, password->value); - break; - default: - break; - } - } - IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); + if (print_item) { + s_password *password; + + password = items[i].pwdvalue; + if (password && password->value != NULL) { + if (hide_sensitive_data) { + Dmsg1(200, "%s = \"****************\"\n", items[i].name); + Mmsg(temp, "%s = \"****************\"\n", items[i].name); + } else { + switch (password->encoding) { + case p_encoding_clear: + Dmsg2(200, "%s = \"%s\"\n", items[i].name, password->value); + Mmsg(temp, "%s = \"%s\"\n", items[i].name, password->value); + break; + case p_encoding_md5: + Dmsg2(200, "%s = \"[md5]%s\"\n", items[i].name, password->value); + Mmsg(temp, "%s = \"[md5]%s\"\n", items[i].name, password->value); + break; + default: + break; + } } - } - break; + IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); + } + } + break; case CFG_TYPE_LABEL: - for (int j = 0; tapelabels[j].name; j++) { - if (*(items[i].ui32value) == tapelabels[j].token) { - /* - * Supress printing default value. - */ - if (items[i].flags & CFG_ITEM_DEFAULT) { - if (Bstrcasecmp(items[i].default_value, tapelabels[j].name)) { - break; - } - } - - Mmsg(temp, "%s = \"%s\"\n", items[i].name, tapelabels[j].name); - IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); - break; + for (int j = 0; tapelabels[j].name; j++) { + if (*(items[i].ui32value) == tapelabels[j].token) { + /* + * Supress printing default value. + */ + if (items[i].flags & CFG_ITEM_DEFAULT) { + if (Bstrcasecmp(items[i].default_value, tapelabels[j].name)) { + break; + } } - } - break; - case CFG_TYPE_INT16: - if (print_item) { - Mmsg(temp, "%s = %hd\n", items[i].name, *(items[i].i16value)); + + Mmsg(temp, "%s = \"%s\"\n", items[i].name, tapelabels[j].name); IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); - } - break; + break; + } + } + break; + case CFG_TYPE_INT16: + if (print_item) { + Mmsg(temp, "%s = %hd\n", items[i].name, *(items[i].i16value)); + IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); + } + break; case CFG_TYPE_PINT16: - if (print_item) { - Mmsg(temp, "%s = %hu\n", items[i].name, *(items[i].ui16value)); - IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); - } - break; + if (print_item) { + Mmsg(temp, "%s = %hu\n", items[i].name, *(items[i].ui16value)); + IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); + } + break; case CFG_TYPE_INT32: - if (print_item) { - Mmsg(temp, "%s = %d\n", items[i].name, *(items[i].i32value)); - IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); - } - break; + if (print_item) { + Mmsg(temp, "%s = %d\n", items[i].name, *(items[i].i32value)); + IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); + } + break; case CFG_TYPE_PINT32: - if (print_item) { - Mmsg(temp, "%s = %u\n", items[i].name, *(items[i].ui32value)); - IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); - } - break; + if (print_item) { + Mmsg(temp, "%s = %u\n", items[i].name, *(items[i].ui32value)); + IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); + } + break; case CFG_TYPE_INT64: - if (print_item) { - Mmsg(temp, "%s = %d\n", items[i].name, *(items[i].i64value)); - IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); - } - break; + if (print_item) { + Mmsg(temp, "%s = %d\n", items[i].name, *(items[i].i64value)); + IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); + } + break; case CFG_TYPE_SPEED: - if (print_item) { - Mmsg(temp, "%s = %u\n", items[i].name, *(items[i].ui64value)); - IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); - } - break; + if (print_item) { + Mmsg(temp, "%s = %u\n", items[i].name, *(items[i].ui64value)); + IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); + } + break; case CFG_TYPE_SIZE64: case CFG_TYPE_SIZE32: - if (print_item) { - PrintConfigSize(&items[i], cfg_str, inherited); - } - break; + if (print_item) { + PrintConfigSize(&items[i], cfg_str, inherited); + } + break; case CFG_TYPE_TIME: - if (print_item) { - PrintConfigTime(&items[i], cfg_str, inherited); - } - break; + if (print_item) { + PrintConfigTime(&items[i], cfg_str, inherited); + } + break; case CFG_TYPE_BOOL: - if (print_item) { - if (*items[i].boolvalue) { - Mmsg(temp, "%s = %s\n", items[i].name, NT_("yes")); - } else { - Mmsg(temp, "%s = %s\n", items[i].name, NT_("no")); - } - IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); - } - break; + if (print_item) { + if (*items[i].boolvalue) { + Mmsg(temp, "%s = %s\n", items[i].name, NT_("yes")); + } else { + Mmsg(temp, "%s = %s\n", items[i].name, NT_("no")); + } + IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); + } + break; case CFG_TYPE_ALIST_STR: case CFG_TYPE_ALIST_DIR: case CFG_TYPE_PLUGIN_NAMES: { /* * One line for each member of the list */ - char *value; - alist *list; - list = *(items[i].alistvalue); - - if (list != NULL) { - foreach_alist(value, list) { - /* - * If this is the default value skip it. - */ - if (items[i].flags & CFG_ITEM_DEFAULT) { - if (bstrcmp(value, items[i].default_value)) { - continue; - } - } - Mmsg(temp, "%s = \"%s\"\n", items[i].name, value); - IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); + char *value; + alist *list; + list = *(items[i].alistvalue); + + if (list != NULL) { + foreach_alist(value, list) + { + /* + * If this is the default value skip it. + */ + if (items[i].flags & CFG_ITEM_DEFAULT) { + if (bstrcmp(value, items[i].default_value)) { + continue; + } } - } - break; + Mmsg(temp, "%s = \"%s\"\n", items[i].name, value); + IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); + } + } + break; } case CFG_TYPE_ALIST_RES: { - /* - * Each member of the list is comma-separated - */ - int cnt = 0; - CommonResourceHeader *res; - alist *list; - PoolMem res_names; - - list = *(items[i].alistvalue); - if (list != NULL) { - Mmsg(temp, "%s = ", items[i].name); - IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); - - PmStrcpy(res_names, ""); - foreach_alist(res, list) { - if (cnt) { - Mmsg(temp, ",\"%s\"", res->name); - } else { - Mmsg(temp, "\"%s\"", res->name); - } - PmStrcat(res_names, temp.c_str()); - cnt++; + /* + * Each member of the list is comma-separated + */ + int cnt = 0; + CommonResourceHeader *res; + alist *list; + PoolMem res_names; + + list = *(items[i].alistvalue); + if (list != NULL) { + Mmsg(temp, "%s = ", items[i].name); + IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); + + PmStrcpy(res_names, ""); + foreach_alist(res, list) + { + if (cnt) { + Mmsg(temp, ",\"%s\"", res->name); + } else { + Mmsg(temp, "\"%s\"", res->name); } - - PmStrcat(cfg_str, res_names.c_str()); - PmStrcat(cfg_str, "\n"); - } - break; + PmStrcat(res_names, temp.c_str()); + cnt++; + } + + PmStrcat(cfg_str, res_names.c_str()); + PmStrcat(cfg_str, "\n"); + } + break; } case CFG_TYPE_RES: { - CommonResourceHeader *res; - - res = *(items[i].resvalue); - if (res != NULL && res->name != NULL) { - Mmsg(temp, "%s = \"%s\"\n", items[i].name, res->name); - IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); - } - break; + CommonResourceHeader *res; + + res = *(items[i].resvalue); + if (res != NULL && res->name != NULL) { + Mmsg(temp, "%s = \"%s\"\n", items[i].name, res->name); + IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); + } + break; } case CFG_TYPE_BIT: - if (BitIsSet(items[i].code, items[i].bitvalue)) { - Mmsg(temp, "%s = %s\n", items[i].name, NT_("yes")); - } else { - Mmsg(temp, "%s = %s\n", items[i].name, NT_("no")); - } - IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); - break; + if (BitIsSet(items[i].code, items[i].bitvalue)) { + Mmsg(temp, "%s = %s\n", items[i].name, NT_("yes")); + } else { + Mmsg(temp, "%s = %s\n", items[i].name, NT_("no")); + } + IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); + break; case CFG_TYPE_MSGS: - /* - * We ignore these items as they are printed in a special way in MessagesResource::PrintConfig() - */ - break; + /* + * We ignore these items as they are printed in a special way in MessagesResource::PrintConfig() + */ + break; case CFG_TYPE_ADDRESSES: { - dlist *addrs = *items[i].dlistvalue; - IPADDR *adr; - - Mmsg(temp, "%s = {\n", items[i].name); - IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); - foreach_dlist(adr, addrs) { - char tmp[1024]; - - adr->BuildConfigString(tmp, sizeof(tmp)); - PmStrcat(cfg_str, tmp); - PmStrcat(cfg_str, "\n"); - } - - IndentConfigItem(cfg_str, 1, "}\n"); - break; + dlist *addrs = *items[i].dlistvalue; + IPADDR *adr; + + Mmsg(temp, "%s = {\n", items[i].name); + IndentConfigItem(cfg_str, 1, temp.c_str(), inherited); + foreach_dlist(adr, addrs) + { + char tmp[1024]; + + adr->BuildConfigString(tmp, sizeof(tmp)); + PmStrcat(cfg_str, tmp); + PmStrcat(cfg_str, "\n"); + } + + IndentConfigItem(cfg_str, 1, "}\n"); + break; } case CFG_TYPE_ADDRESSES_PORT: - /* - * Is stored in CFG_TYPE_ADDRESSES and printed there. - */ - break; + /* + * Is stored in CFG_TYPE_ADDRESSES and printed there. + */ + break; case CFG_TYPE_ADDRESSES_ADDRESS: - /* - * Is stored in CFG_TYPE_ADDRESSES and printed there. - */ - break; + /* + * Is stored in CFG_TYPE_ADDRESSES and printed there. + */ + break; default: - /* - * This is a non-generic type call back to the daemon to get things printed. - */ - if (my_config->print_res_) { - my_config->print_res_(items, i, cfg_str, hide_sensitive_data, inherited); - } - break; - } - } + /* + * This is a non-generic type call back to the daemon to get things printed. + */ + if (my_config->print_res_) { + my_config->print_res_(items, i, cfg_str, hide_sensitive_data, inherited); + } + break; + } + } - PmStrcat(cfg_str, "}\n\n"); - PmStrcat(buff, cfg_str.c_str()); + PmStrcat(cfg_str, "}\n\n"); + PmStrcat(buff, cfg_str.c_str()); - return true; + return true; } #ifdef HAVE_JANSSON @@ -2007,189 +1957,188 @@ bool BareosResource::PrintConfig(PoolMem &buff, bool hide_sensitive_data, bool v */ json_t *json_item(ResourceItem *item) { - json_t *json = json_object(); - - json_object_set_new(json, "datatype", json_string(datatype_to_str(item->type))); - json_object_set_new(json, "code", json_integer(item->code)); - - if (item->flags & CFG_ITEM_ALIAS) { - json_object_set_new(json, "alias", json_true()); - } - if (item->flags & CFG_ITEM_DEFAULT) { - /* FIXME? would it be better to convert it to the right type before returning? */ - json_object_set_new(json, "default_value", json_string(item->default_value)); - } - if (item->flags & CFG_ITEM_PLATFORM_SPECIFIC) { - json_object_set_new(json, "platform_specific", json_true()); - } - if (item->flags & CFG_ITEM_DEPRECATED) { - json_object_set_new(json, "deprecated", json_true()); - } - if (item->flags & CFG_ITEM_NO_EQUALS) { - json_object_set_new(json, "equals", json_false()); - } else { - json_object_set_new(json, "equals", json_true()); - } - if (item->flags & CFG_ITEM_REQUIRED) { - json_object_set_new(json, "required", json_true()); - } - if (item->versions) { - json_object_set_new(json, "versions", json_string(item->versions)); - } - if (item->description) { - json_object_set_new(json, "description", json_string(item->description)); - } - - return json; + json_t *json = json_object(); + + json_object_set_new(json, "datatype", json_string(datatype_to_str(item->type))); + json_object_set_new(json, "code", json_integer(item->code)); + + if (item->flags & CFG_ITEM_ALIAS) { + json_object_set_new(json, "alias", json_true()); + } + if (item->flags & CFG_ITEM_DEFAULT) { + /* FIXME? would it be better to convert it to the right type before returning? */ + json_object_set_new(json, "default_value", json_string(item->default_value)); + } + if (item->flags & CFG_ITEM_PLATFORM_SPECIFIC) { + json_object_set_new(json, "platform_specific", json_true()); + } + if (item->flags & CFG_ITEM_DEPRECATED) { + json_object_set_new(json, "deprecated", json_true()); + } + if (item->flags & CFG_ITEM_NO_EQUALS) { + json_object_set_new(json, "equals", json_false()); + } else { + json_object_set_new(json, "equals", json_true()); + } + if (item->flags & CFG_ITEM_REQUIRED) { + json_object_set_new(json, "required", json_true()); + } + if (item->versions) { + json_object_set_new(json, "versions", json_string(item->versions)); + } + if (item->description) { + json_object_set_new(json, "description", json_string(item->description)); + } + + return json; } json_t *json_item(s_kw *item) { - json_t *json = json_object(); + json_t *json = json_object(); - json_object_set_new(json, "token", json_integer(item->token)); + json_object_set_new(json, "token", json_integer(item->token)); - return json; + return json; } json_t *json_items(ResourceItem items[]) { - json_t *json = json_object(); + json_t *json = json_object(); - if (items) { - for (int i = 0; items[i].name; i++) { - json_object_set_new(json, items[i].name, json_item(&items[i])); - } - } + if (items) { + for (int i = 0; items[i].name; i++) { + json_object_set_new(json, items[i].name, json_item(&items[i])); + } + } - return json; + return json; } #endif static DatatypeName datatype_names[] = { - /* - * Standard resource types. handlers in res.c - */ - { CFG_TYPE_STR, "STRING", "String" }, - { CFG_TYPE_DIR, "DIRECTORY", "directory" }, - { CFG_TYPE_STDSTR, "STDSTRING", "String" }, - { CFG_TYPE_STDSTRDIR, "STDDIRECTORY", "directory" }, - { CFG_TYPE_MD5PASSWORD, "MD5PASSWORD", "Password in MD5 format" }, - { CFG_TYPE_CLEARPASSWORD, "CLEARPASSWORD", "Password as cleartext" }, - { CFG_TYPE_AUTOPASSWORD, "AUTOPASSWORD", "Password stored in clear when needed otherwise hashed" }, - { CFG_TYPE_NAME, "NAME", "Name" }, - { CFG_TYPE_STRNAME, "STRNAME", "String name" }, - { CFG_TYPE_RES, "CommonResourceHeader", "Resource" }, - { CFG_TYPE_ALIST_RES, "RESOURCE_LIST", "Resource list" }, - { CFG_TYPE_ALIST_STR, "STRING_LIST", "string list" }, - { CFG_TYPE_ALIST_DIR, "DIRECTORY_LIST", "directory list" }, - { CFG_TYPE_INT16, "INT16", "Integer 16 bits" }, - { CFG_TYPE_PINT16, "PINT16", "Positive 16 bits Integer (unsigned)" }, - { CFG_TYPE_INT32, "INT32", "Integer 32 bits" }, - { CFG_TYPE_PINT32, "PINT32", "Positive 32 bits Integer (unsigned)" }, - { CFG_TYPE_MSGS, "MESSAGES", "Message resource" }, - { CFG_TYPE_INT64, "INT64", "Integer 64 bits" }, - { CFG_TYPE_BIT, "BIT", "Bitfield" }, - { CFG_TYPE_BOOL, "BOOLEAN", "boolean" }, - { CFG_TYPE_TIME, "TIME", "time" }, - { CFG_TYPE_SIZE64, "SIZE64", "64 bits file size" }, - { CFG_TYPE_SIZE32, "SIZE32", "32 bits file size" }, - { CFG_TYPE_SPEED, "SPEED", "speed" }, - { CFG_TYPE_DEFS, "DEFS", "definition" }, - { CFG_TYPE_LABEL, "LABEL", "label" }, - { CFG_TYPE_ADDRESSES, "ADDRESSES", "ip addresses list" }, - { CFG_TYPE_ADDRESSES_ADDRESS, "ADDRESS", "ip address" }, - { CFG_TYPE_ADDRESSES_PORT, "PORT", "network port" }, - { CFG_TYPE_PLUGIN_NAMES, "PLUGIN_NAMES", "Plugin Name(s)" }, - - /* - * Director resource types. handlers in dird_conf. - */ - { CFG_TYPE_ACL, "ACL", "User Access Control List" }, - { CFG_TYPE_AUDIT, "AUDIT_COMMAND_LIST", "Auditing Command List" }, - { CFG_TYPE_AUTHPROTOCOLTYPE, "AUTH_PROTOCOL_TYPE", "Authentication Protocol" }, - { CFG_TYPE_AUTHTYPE, "AUTH_TYPE", "Authentication Type" }, - { CFG_TYPE_DEVICE, "Device", "Device resource" }, - { CFG_TYPE_JOBTYPE, "JOB_TYPE", "Type of Job" }, - { CFG_TYPE_PROTOCOLTYPE, "PROTOCOL_TYPE", "Protocol" }, - { CFG_TYPE_LEVEL, "BACKUP_LEVEL", "Backup Level" }, - { CFG_TYPE_REPLACE, "REPLACE_OPTION", "Replace option" }, - { CFG_TYPE_SHRTRUNSCRIPT, "RUNSCRIPT_SHORT", "Short Runscript definition" }, - { CFG_TYPE_RUNSCRIPT, "RunScript", "Runscript" }, - { CFG_TYPE_RUNSCRIPT_CMD, "RUNSCRIPT_COMMAND", "Runscript Command" }, - { CFG_TYPE_RUNSCRIPT_TARGET, "RUNSCRIPT_TARGET", "Runscript Target (Host)" }, - { CFG_TYPE_RUNSCRIPT_BOOL, "RUNSCRIPT_BOOLEAN", "Runscript Boolean" }, - { CFG_TYPE_RUNSCRIPT_WHEN, "RUNSCRIPT_WHEN", "Runscript When expression" }, - { CFG_TYPE_MIGTYPE, "MIGRATION_TYPE", "Migration Type" }, - { CFG_TYPE_INCEXC, "INCLUDE_EXCLUDE_ITEM", "Include/Exclude item" }, - { CFG_TYPE_RUN, "SCHEDULE_RUN_COMMAND", "Schedule Run Command" }, - { CFG_TYPE_ACTIONONPURGE, "ACTION_ON_PURGE", "Action to perform on Purge" }, - { CFG_TYPE_POOLTYPE, "POOLTYPE", "Pool Type" }, - - /* - * Director fileset options. handlers in dird_conf. - */ - { CFG_TYPE_FNAME, "FILENAME", "Filename" }, - { CFG_TYPE_PLUGINNAME, "PLUGIN_NAME", "Pluginname" }, - { CFG_TYPE_EXCLUDEDIR, "EXCLUDE_DIRECTORY", "Exclude directory" }, - { CFG_TYPE_OPTIONS, "OPTIONS", "Options block" }, - { CFG_TYPE_OPTION, "OPTION", "Option of Options block" }, - { CFG_TYPE_REGEX, "REGEX", "Regular Expression" }, - { CFG_TYPE_BASE, "BASEJOB", "Basejob Expression" }, - { CFG_TYPE_WILD, "WILDCARD", "Wildcard Expression" }, - { CFG_TYPE_PLUGIN, "PLUGIN", "Plugin definition" }, - { CFG_TYPE_FSTYPE, "FILESYSTEM_TYPE", "FileSystem match criterium (UNIX)" }, - { CFG_TYPE_DRIVETYPE, "DRIVE_TYPE", "DriveType match criterium (Windows)" }, - { CFG_TYPE_META, "META_TAG", "Meta tag" }, - - /* - * Storage daemon resource types - */ - { CFG_TYPE_DEVTYPE, "DEVICE_TYPE", "Device Type" }, - { CFG_TYPE_MAXBLOCKSIZE, "MAX_BLOCKSIZE", "Maximum Blocksize" }, - { CFG_TYPE_IODIRECTION, "IO_DIRECTION", "IO Direction" }, - { CFG_TYPE_CMPRSALGO, "COMPRESSION_ALGORITHM", "Compression Algorithm" }, - - /* - * File daemon resource types - */ - { CFG_TYPE_CIPHER, "ENCRYPTION_CIPHER", "Encryption Cipher" }, - - { 0, NULL, NULL } -}; + /* + * Standard resource types. handlers in res.c + */ + {CFG_TYPE_STR, "STRING", "String"}, + {CFG_TYPE_DIR, "DIRECTORY", "directory"}, + {CFG_TYPE_STDSTR, "STDSTRING", "String"}, + {CFG_TYPE_STDSTRDIR, "STDDIRECTORY", "directory"}, + {CFG_TYPE_MD5PASSWORD, "MD5PASSWORD", "Password in MD5 format"}, + {CFG_TYPE_CLEARPASSWORD, "CLEARPASSWORD", "Password as cleartext"}, + {CFG_TYPE_AUTOPASSWORD, "AUTOPASSWORD", "Password stored in clear when needed otherwise hashed"}, + {CFG_TYPE_NAME, "NAME", "Name"}, + {CFG_TYPE_STRNAME, "STRNAME", "String name"}, + {CFG_TYPE_RES, "CommonResourceHeader", "Resource"}, + {CFG_TYPE_ALIST_RES, "RESOURCE_LIST", "Resource list"}, + {CFG_TYPE_ALIST_STR, "STRING_LIST", "string list"}, + {CFG_TYPE_ALIST_DIR, "DIRECTORY_LIST", "directory list"}, + {CFG_TYPE_INT16, "INT16", "Integer 16 bits"}, + {CFG_TYPE_PINT16, "PINT16", "Positive 16 bits Integer (unsigned)"}, + {CFG_TYPE_INT32, "INT32", "Integer 32 bits"}, + {CFG_TYPE_PINT32, "PINT32", "Positive 32 bits Integer (unsigned)"}, + {CFG_TYPE_MSGS, "MESSAGES", "Message resource"}, + {CFG_TYPE_INT64, "INT64", "Integer 64 bits"}, + {CFG_TYPE_BIT, "BIT", "Bitfield"}, + {CFG_TYPE_BOOL, "BOOLEAN", "boolean"}, + {CFG_TYPE_TIME, "TIME", "time"}, + {CFG_TYPE_SIZE64, "SIZE64", "64 bits file size"}, + {CFG_TYPE_SIZE32, "SIZE32", "32 bits file size"}, + {CFG_TYPE_SPEED, "SPEED", "speed"}, + {CFG_TYPE_DEFS, "DEFS", "definition"}, + {CFG_TYPE_LABEL, "LABEL", "label"}, + {CFG_TYPE_ADDRESSES, "ADDRESSES", "ip addresses list"}, + {CFG_TYPE_ADDRESSES_ADDRESS, "ADDRESS", "ip address"}, + {CFG_TYPE_ADDRESSES_PORT, "PORT", "network port"}, + {CFG_TYPE_PLUGIN_NAMES, "PLUGIN_NAMES", "Plugin Name(s)"}, + + /* + * Director resource types. handlers in dird_conf. + */ + {CFG_TYPE_ACL, "ACL", "User Access Control List"}, + {CFG_TYPE_AUDIT, "AUDIT_COMMAND_LIST", "Auditing Command List"}, + {CFG_TYPE_AUTHPROTOCOLTYPE, "AUTH_PROTOCOL_TYPE", "Authentication Protocol"}, + {CFG_TYPE_AUTHTYPE, "AUTH_TYPE", "Authentication Type"}, + {CFG_TYPE_DEVICE, "Device", "Device resource"}, + {CFG_TYPE_JOBTYPE, "JOB_TYPE", "Type of Job"}, + {CFG_TYPE_PROTOCOLTYPE, "PROTOCOL_TYPE", "Protocol"}, + {CFG_TYPE_LEVEL, "BACKUP_LEVEL", "Backup Level"}, + {CFG_TYPE_REPLACE, "REPLACE_OPTION", "Replace option"}, + {CFG_TYPE_SHRTRUNSCRIPT, "RUNSCRIPT_SHORT", "Short Runscript definition"}, + {CFG_TYPE_RUNSCRIPT, "RunScript", "Runscript"}, + {CFG_TYPE_RUNSCRIPT_CMD, "RUNSCRIPT_COMMAND", "Runscript Command"}, + {CFG_TYPE_RUNSCRIPT_TARGET, "RUNSCRIPT_TARGET", "Runscript Target (Host)"}, + {CFG_TYPE_RUNSCRIPT_BOOL, "RUNSCRIPT_BOOLEAN", "Runscript Boolean"}, + {CFG_TYPE_RUNSCRIPT_WHEN, "RUNSCRIPT_WHEN", "Runscript When expression"}, + {CFG_TYPE_MIGTYPE, "MIGRATION_TYPE", "Migration Type"}, + {CFG_TYPE_INCEXC, "INCLUDE_EXCLUDE_ITEM", "Include/Exclude item"}, + {CFG_TYPE_RUN, "SCHEDULE_RUN_COMMAND", "Schedule Run Command"}, + {CFG_TYPE_ACTIONONPURGE, "ACTION_ON_PURGE", "Action to perform on Purge"}, + {CFG_TYPE_POOLTYPE, "POOLTYPE", "Pool Type"}, + + /* + * Director fileset options. handlers in dird_conf. + */ + {CFG_TYPE_FNAME, "FILENAME", "Filename"}, + {CFG_TYPE_PLUGINNAME, "PLUGIN_NAME", "Pluginname"}, + {CFG_TYPE_EXCLUDEDIR, "EXCLUDE_DIRECTORY", "Exclude directory"}, + {CFG_TYPE_OPTIONS, "OPTIONS", "Options block"}, + {CFG_TYPE_OPTION, "OPTION", "Option of Options block"}, + {CFG_TYPE_REGEX, "REGEX", "Regular Expression"}, + {CFG_TYPE_BASE, "BASEJOB", "Basejob Expression"}, + {CFG_TYPE_WILD, "WILDCARD", "Wildcard Expression"}, + {CFG_TYPE_PLUGIN, "PLUGIN", "Plugin definition"}, + {CFG_TYPE_FSTYPE, "FILESYSTEM_TYPE", "FileSystem match criterium (UNIX)"}, + {CFG_TYPE_DRIVETYPE, "DRIVE_TYPE", "DriveType match criterium (Windows)"}, + {CFG_TYPE_META, "META_TAG", "Meta tag"}, + + /* + * Storage daemon resource types + */ + {CFG_TYPE_DEVTYPE, "DEVICE_TYPE", "Device Type"}, + {CFG_TYPE_MAXBLOCKSIZE, "MAX_BLOCKSIZE", "Maximum Blocksize"}, + {CFG_TYPE_IODIRECTION, "IO_DIRECTION", "IO Direction"}, + {CFG_TYPE_CMPRSALGO, "COMPRESSION_ALGORITHM", "Compression Algorithm"}, + + /* + * File daemon resource types + */ + {CFG_TYPE_CIPHER, "ENCRYPTION_CIPHER", "Encryption Cipher"}, + + {0, NULL, NULL}}; DatatypeName *get_datatype(int number) { - int size = sizeof(datatype_names) / sizeof(datatype_names[0]); + int size = sizeof(datatype_names) / sizeof(datatype_names[0]); - if (number >= size) { - /* - * Last entry of array is a dummy entry - */ - number=size - 1; - } + if (number >= size) { + /* + * Last entry of array is a dummy entry + */ + number = size - 1; + } - return &(datatype_names[number]); + return &(datatype_names[number]); } const char *datatype_to_str(int type) { - for (int i = 0; datatype_names[i].name; i++) { - if (datatype_names[i].number == type) { - return datatype_names[i].name; - } - } + for (int i = 0; datatype_names[i].name; i++) { + if (datatype_names[i].number == type) { + return datatype_names[i].name; + } + } - return "unknown"; + return "unknown"; } const char *datatype_to_description(int type) { - for (int i = 0; datatype_names[i].name; i++) { - if (datatype_names[i].number == type) { - return datatype_names[i].description; - } - } + for (int i = 0; datatype_names[i].name; i++) { + if (datatype_names[i].number == type) { + return datatype_names[i].description; + } + } - return NULL; + return NULL; } diff --git a/core/src/qt-tray-monitor/tray_conf.cc b/core/src/qt-tray-monitor/tray_conf.cc index 4bf5b0a5c65..1893cc698fb 100644 --- a/core/src/qt-tray-monitor/tray_conf.cc +++ b/core/src/qt-tray-monitor/tray_conf.cc @@ -74,19 +74,22 @@ int32_t res_all_size = sizeof(res_all); * name handler value code flags default_value */ static ResourceItem mon_items[] = { - { "Name", CFG_TYPE_NAME, ITEM(res_monitor.hdr.name), 0, CFG_ITEM_REQUIRED, 0, NULL, NULL }, - { "Description", CFG_TYPE_STR, ITEM(res_monitor.hdr.desc), 0, 0, 0, NULL, NULL }, - { "RequireSsl", CFG_TYPE_BOOL, ITEM(res_monitor.require_ssl), 0, CFG_ITEM_DEFAULT, "false", NULL, NULL }, - { "Password", CFG_TYPE_MD5PASSWORD, ITEM(res_monitor.password), 0, CFG_ITEM_REQUIRED, NULL, NULL, NULL }, - { "RefreshInterval", CFG_TYPE_TIME, ITEM(res_monitor.RefreshInterval), 0, CFG_ITEM_DEFAULT, "60", NULL, NULL }, - { "FdConnectTimeout", CFG_TYPE_TIME, ITEM(res_monitor.FDConnectTimeout), 0, CFG_ITEM_DEFAULT, "10", NULL, NULL }, - { "SdConnectTimeout", CFG_TYPE_TIME, ITEM(res_monitor.SDConnectTimeout), 0, CFG_ITEM_DEFAULT, "10", NULL, NULL }, - { "DirConnectTimeout", CFG_TYPE_TIME, ITEM(res_monitor.DIRConnectTimeout), 0, CFG_ITEM_DEFAULT, "10", NULL, NULL }, - TLS_COMMON_CONFIG(res_monitor), - TLS_CERT_CONFIG(res_monitor), - TLS_PSK_CONFIG(res_monitor), - { NULL, 0, { 0 }, 0, 0, NULL, NULL, NULL } -}; + {"Name", CFG_TYPE_NAME, ITEM(res_monitor.hdr.name), 0, CFG_ITEM_REQUIRED, 0, NULL, NULL}, + {"Description", CFG_TYPE_STR, ITEM(res_monitor.hdr.desc), 0, 0, 0, NULL, NULL}, + {"RequireSsl", CFG_TYPE_BOOL, ITEM(res_monitor.require_ssl), 0, CFG_ITEM_DEFAULT, "false", NULL, NULL}, + {"Password", CFG_TYPE_MD5PASSWORD, ITEM(res_monitor.password), 0, CFG_ITEM_REQUIRED, NULL, NULL, NULL}, + {"RefreshInterval", CFG_TYPE_TIME, ITEM(res_monitor.RefreshInterval), 0, CFG_ITEM_DEFAULT, "60", NULL, + NULL}, + {"FdConnectTimeout", CFG_TYPE_TIME, ITEM(res_monitor.FDConnectTimeout), 0, CFG_ITEM_DEFAULT, "10", NULL, + NULL}, + {"SdConnectTimeout", CFG_TYPE_TIME, ITEM(res_monitor.SDConnectTimeout), 0, CFG_ITEM_DEFAULT, "10", NULL, + NULL}, + {"DirConnectTimeout", CFG_TYPE_TIME, ITEM(res_monitor.DIRConnectTimeout), 0, CFG_ITEM_DEFAULT, "10", NULL, + NULL}, + TLS_COMMON_CONFIG(res_monitor), + TLS_CERT_CONFIG(res_monitor), + TLS_PSK_CONFIG(res_monitor), + {NULL, 0, {0}, 0, 0, NULL, NULL, NULL}}; /* * Director's that we can contact @@ -94,16 +97,15 @@ static ResourceItem mon_items[] = { * name handler value code flags default_value */ static ResourceItem dir_items[] = { - { "Name", CFG_TYPE_NAME, ITEM(res_dir.hdr.name), 0, CFG_ITEM_REQUIRED, NULL, NULL, NULL }, - { "Description", CFG_TYPE_STR, ITEM(res_dir.hdr.desc), 0, 0, NULL, NULL, NULL }, - { "DirPort", CFG_TYPE_PINT32, ITEM(res_dir.DIRport), 0, CFG_ITEM_DEFAULT, DIR_DEFAULT_PORT, NULL, NULL }, - { "Address", CFG_TYPE_STR, ITEM(res_dir.address), 0, CFG_ITEM_REQUIRED, NULL, NULL, NULL }, - { "EnableSsl", CFG_TYPE_BOOL, ITEM(res_dir.enable_ssl), 0, CFG_ITEM_DEFAULT, "false", NULL, NULL }, - TLS_COMMON_CONFIG(res_dir), - TLS_CERT_CONFIG(res_dir), - TLS_PSK_CONFIG(res_dir), - { NULL, 0, { 0 }, 0, 0, NULL, NULL, NULL } -}; + {"Name", CFG_TYPE_NAME, ITEM(res_dir.hdr.name), 0, CFG_ITEM_REQUIRED, NULL, NULL, NULL}, + {"Description", CFG_TYPE_STR, ITEM(res_dir.hdr.desc), 0, 0, NULL, NULL, NULL}, + {"DirPort", CFG_TYPE_PINT32, ITEM(res_dir.DIRport), 0, CFG_ITEM_DEFAULT, DIR_DEFAULT_PORT, NULL, NULL}, + {"Address", CFG_TYPE_STR, ITEM(res_dir.address), 0, CFG_ITEM_REQUIRED, NULL, NULL, NULL}, + {"EnableSsl", CFG_TYPE_BOOL, ITEM(res_dir.enable_ssl), 0, CFG_ITEM_DEFAULT, "false", NULL, NULL}, + TLS_COMMON_CONFIG(res_dir), + TLS_CERT_CONFIG(res_dir), + TLS_PSK_CONFIG(res_dir), + {NULL, 0, {0}, 0, 0, NULL, NULL, NULL}}; /* * Client or File daemon resource @@ -111,17 +113,16 @@ static ResourceItem dir_items[] = { * name handler value code flags default_value */ static ResourceItem cli_items[] = { - { "Name", CFG_TYPE_NAME, ITEM(res_client.hdr.name), 0, CFG_ITEM_REQUIRED, NULL, NULL, NULL }, - { "Description", CFG_TYPE_STR, ITEM(res_client.hdr.desc), 0, 0, NULL, NULL, NULL }, - { "Address", CFG_TYPE_STR, ITEM(res_client.address), 0, CFG_ITEM_REQUIRED, NULL, NULL, NULL }, - { "FdPort", CFG_TYPE_PINT32, ITEM(res_client.FDport), 0, CFG_ITEM_DEFAULT, FD_DEFAULT_PORT, NULL, NULL }, - { "Password", CFG_TYPE_MD5PASSWORD, ITEM(res_client.password), 0, CFG_ITEM_REQUIRED, NULL, NULL, NULL }, - { "EnableSsl", CFG_TYPE_BOOL, ITEM(res_client.enable_ssl), 0, CFG_ITEM_DEFAULT, "false", NULL, NULL }, - TLS_COMMON_CONFIG(res_client), - TLS_CERT_CONFIG(res_client), - TLS_PSK_CONFIG(res_client), - { NULL, 0, { 0 }, 0, 0, NULL, NULL, NULL } -}; + {"Name", CFG_TYPE_NAME, ITEM(res_client.hdr.name), 0, CFG_ITEM_REQUIRED, NULL, NULL, NULL}, + {"Description", CFG_TYPE_STR, ITEM(res_client.hdr.desc), 0, 0, NULL, NULL, NULL}, + {"Address", CFG_TYPE_STR, ITEM(res_client.address), 0, CFG_ITEM_REQUIRED, NULL, NULL, NULL}, + {"FdPort", CFG_TYPE_PINT32, ITEM(res_client.FDport), 0, CFG_ITEM_DEFAULT, FD_DEFAULT_PORT, NULL, NULL}, + {"Password", CFG_TYPE_MD5PASSWORD, ITEM(res_client.password), 0, CFG_ITEM_REQUIRED, NULL, NULL, NULL}, + {"EnableSsl", CFG_TYPE_BOOL, ITEM(res_client.enable_ssl), 0, CFG_ITEM_DEFAULT, "false", NULL, NULL}, + TLS_COMMON_CONFIG(res_client), + TLS_CERT_CONFIG(res_client), + TLS_PSK_CONFIG(res_client), + {NULL, 0, {0}, 0, 0, NULL, NULL, NULL}}; /* * Storage daemon resource @@ -129,19 +130,18 @@ static ResourceItem cli_items[] = { * name handler value code flags default_value */ static ResourceItem store_items[] = { - { "Name", CFG_TYPE_NAME, ITEM(res_store.hdr.name), 0, CFG_ITEM_REQUIRED, NULL, NULL, NULL }, - { "Description", CFG_TYPE_STR, ITEM(res_store.hdr.desc), 0, 0, NULL, NULL, NULL }, - { "SdPort", CFG_TYPE_PINT32, ITEM(res_store.SDport), 0, CFG_ITEM_DEFAULT, SD_DEFAULT_PORT, NULL, NULL }, - { "Address", CFG_TYPE_STR, ITEM(res_store.address), 0, CFG_ITEM_REQUIRED, NULL, NULL, NULL }, - { "SdAddress", CFG_TYPE_STR, ITEM(res_store.address), 0, 0, NULL, NULL, NULL }, - { "Password", CFG_TYPE_MD5PASSWORD, ITEM(res_store.password), 0, CFG_ITEM_REQUIRED, NULL, NULL, NULL }, - { "SdPassword", CFG_TYPE_MD5PASSWORD, ITEM(res_store.password), 0, 0, NULL, NULL, NULL }, - { "EnableSsl", CFG_TYPE_BOOL, ITEM(res_store.enable_ssl), 0, CFG_ITEM_DEFAULT, "false", NULL, NULL }, - TLS_COMMON_CONFIG(res_store), - TLS_CERT_CONFIG(res_store), - TLS_PSK_CONFIG(res_store), - { NULL, 0, { 0 }, 0, 0, NULL, NULL, NULL } -}; + {"Name", CFG_TYPE_NAME, ITEM(res_store.hdr.name), 0, CFG_ITEM_REQUIRED, NULL, NULL, NULL}, + {"Description", CFG_TYPE_STR, ITEM(res_store.hdr.desc), 0, 0, NULL, NULL, NULL}, + {"SdPort", CFG_TYPE_PINT32, ITEM(res_store.SDport), 0, CFG_ITEM_DEFAULT, SD_DEFAULT_PORT, NULL, NULL}, + {"Address", CFG_TYPE_STR, ITEM(res_store.address), 0, CFG_ITEM_REQUIRED, NULL, NULL, NULL}, + {"SdAddress", CFG_TYPE_STR, ITEM(res_store.address), 0, 0, NULL, NULL, NULL}, + {"Password", CFG_TYPE_MD5PASSWORD, ITEM(res_store.password), 0, CFG_ITEM_REQUIRED, NULL, NULL, NULL}, + {"SdPassword", CFG_TYPE_MD5PASSWORD, ITEM(res_store.password), 0, 0, NULL, NULL, NULL}, + {"EnableSsl", CFG_TYPE_BOOL, ITEM(res_store.enable_ssl), 0, CFG_ITEM_DEFAULT, "false", NULL, NULL}, + TLS_COMMON_CONFIG(res_store), + TLS_CERT_CONFIG(res_store), + TLS_PSK_CONFIG(res_store), + {NULL, 0, {0}, 0, 0, NULL, NULL, NULL}}; /* * Font resource @@ -149,11 +149,10 @@ static ResourceItem store_items[] = { * name handler value code flags default_value */ static ResourceItem con_font_items[] = { - { "Name", CFG_TYPE_NAME, ITEM(con_font.hdr.name), 0, CFG_ITEM_REQUIRED, NULL, NULL, NULL }, - { "Description", CFG_TYPE_STR, ITEM(con_font.hdr.desc), 0, 0, NULL, NULL, NULL }, - { "Font", CFG_TYPE_STR, ITEM(con_font.fontface), 0, 0, NULL, NULL, NULL }, - { NULL, 0, { 0 }, 0, 0, NULL, NULL, NULL } -}; + {"Name", CFG_TYPE_NAME, ITEM(con_font.hdr.name), 0, CFG_ITEM_REQUIRED, NULL, NULL, NULL}, + {"Description", CFG_TYPE_STR, ITEM(con_font.hdr.desc), 0, 0, NULL, NULL, NULL}, + {"Font", CFG_TYPE_STR, ITEM(con_font.fontface), 0, 0, NULL, NULL, NULL}, + {NULL, 0, {0}, 0, 0, NULL, NULL, NULL}}; /* * This is the master resource definition. @@ -165,44 +164,51 @@ static ResourceItem con_font_items[] = { * name items rcode res_head */ static ResourceTable resources[] = { - { "Monitor", mon_items, R_MONITOR, sizeof(MonitorResource), [] (void *res){ return new((MonitorResource *) res) MonitorResource(); } }, - { "Director", dir_items, R_DIRECTOR, sizeof(DirectorResource), [] (void *res){ return new((DirectorResource *) res) DirectorResource(); } }, - { "Client", cli_items, R_CLIENT, sizeof(ClientResource), [] (void *res){ return new((ClientResource *) res) ClientResource(); } }, - { "Storage", store_items, R_STORAGE, sizeof(StorageResource), [] (void *res){ return new((StorageResource *) res) StorageResource(); } }, - { "ConsoleFont", con_font_items, R_CONSOLE_FONT, sizeof(ConsoleFontResource) }, - { NULL, NULL, 0, 0 } -}; + {"Monitor", mon_items, R_MONITOR, sizeof(MonitorResource), + [](void *res) { return new ((MonitorResource *)res) MonitorResource(); }}, + {"Director", dir_items, R_DIRECTOR, sizeof(DirectorResource), + [](void *res) { return new ((DirectorResource *)res) DirectorResource(); }}, + {"Client", cli_items, R_CLIENT, sizeof(ClientResource), + [](void *res) { return new ((ClientResource *)res) ClientResource(); }}, + {"Storage", store_items, R_STORAGE, sizeof(StorageResource), + [](void *res) { return new ((StorageResource *)res) StorageResource(); }}, + {"ConsoleFont", con_font_items, R_CONSOLE_FONT, sizeof(ConsoleFontResource)}, + {NULL, NULL, 0, 0}}; /* * Dump contents of resource */ -void DumpResource(int type, CommonResourceHeader *reshdr, void sendit(void *sock, const char *fmt, ...), - void *sock, bool hide_sensitive_data, bool verbose) +void DumpResource(int type, + CommonResourceHeader *reshdr, + void sendit(void *sock, const char *fmt, ...), + void *sock, + bool hide_sensitive_data, + bool verbose) { - PoolMem buf; - UnionOfResources *res = (UnionOfResources *)reshdr; - BareosResource *resclass; - bool recurse = true; - - if (res == NULL) { - sendit(sock, _("Warning: no \"%s\" resource (%d) defined.\n"), res_to_str(type), type); - return; - } - if (type < 0) { /* no recursion */ - type = - type; - recurse = false; - } - switch (type) { - default: - resclass = (BareosResource *)reshdr; - resclass->PrintConfig(buf); - break; - } - sendit(sock, "%s", buf.c_str()); - - if (recurse && res->res_monitor.hdr.next) { - DumpResource(type, res->res_monitor.hdr.next, sendit, sock, hide_sensitive_data, verbose); - } + PoolMem buf; + UnionOfResources *res = reinterpret_cast(reshdr); + BareosResource *resclass; + bool recurse = true; + + if (res == NULL) { + sendit(sock, _("Warning: no \"%s\" resource (%d) defined.\n"), my_config->res_to_str(type), type); + return; + } + if (type < 0) { /* no recursion */ + type = -type; + recurse = false; + } + switch (type) { + default: + resclass = (BareosResource *)reshdr; + resclass->PrintConfig(buf); + break; + } + sendit(sock, "%s", buf.c_str()); + + if (recurse && res->res_monitor.hdr.next) { + DumpResource(type, res->res_monitor.hdr.next, sendit, sock, hide_sensitive_data, verbose); + } } /* @@ -214,65 +220,64 @@ void DumpResource(int type, CommonResourceHeader *reshdr, void sendit(void *sock */ void FreeResource(CommonResourceHeader *sres, int type) { - CommonResourceHeader *nres; /* next resource if linked */ - UnionOfResources *res = (UnionOfResources *)sres; - - if (res == NULL) - return; - - /* - * Common stuff -- free the resource name and description - */ - nres = (CommonResourceHeader *)res->res_monitor.hdr.next; - if (res->res_monitor.hdr.name) { - free(res->res_monitor.hdr.name); - } - if (res->res_monitor.hdr.desc) { - free(res->res_monitor.hdr.desc); - } - - switch (type) { - case R_MONITOR: + CommonResourceHeader *nres; /* next resource if linked */ + UnionOfResources *res = reinterpret_cast(sres); + + if (res == NULL) return; + + /* + * Common stuff -- free the resource name and description + */ + nres = (CommonResourceHeader *)res->res_monitor.hdr.next; + if (res->res_monitor.hdr.name) { + free(res->res_monitor.hdr.name); + } + if (res->res_monitor.hdr.desc) { + free(res->res_monitor.hdr.desc); + } + + switch (type) { + case R_MONITOR: break; - case R_DIRECTOR: + case R_DIRECTOR: if (res->res_dir.address) { - free(res->res_dir.address); + free(res->res_dir.address); } break; - case R_CLIENT: + case R_CLIENT: if (res->res_client.address) { - free(res->res_client.address); + free(res->res_client.address); } if (res->res_client.password.value) { - free(res->res_client.password.value); + free(res->res_client.password.value); } break; - case R_STORAGE: + case R_STORAGE: if (res->res_store.address) { - free(res->res_store.address); + free(res->res_store.address); } if (res->res_store.password.value) { - free(res->res_store.password.value); + free(res->res_store.password.value); } break; - case R_CONSOLE_FONT: + case R_CONSOLE_FONT: if (res->con_font.fontface) { - free(res->con_font.fontface); + free(res->con_font.fontface); } break; - default: + default: printf(_("Unknown resource type %d in FreeResource.\n"), type); - } - - /* - * Common stuff again -- free the resource, recurse to next one - */ - if (res) { - free(res); - } - if (nres) { - FreeResource(nres, type); - } + } + + /* + * Common stuff again -- free the resource, recurse to next one + */ + if (res) { + free(res); + } + if (nres) { + FreeResource(nres, type); + } } /* @@ -283,35 +288,35 @@ void FreeResource(CommonResourceHeader *sres, int type) */ bool SaveResource(int type, ResourceItem *items, int pass) { - UnionOfResources *res; - int rindex = type - R_FIRST; - int i; - int error = 0; - - /* - * Ensure that all required items are present - */ - for (i = 0; items[i].name; i++) { - if (items[i].flags & CFG_ITEM_REQUIRED) { - if (!BitIsSet(i, res_all.res_monitor.hdr.item_present)) { - Emsg2(M_ERROR_TERM, 0, _("%s item is required in %s resource, but not found.\n"), - items[i].name, resources[rindex].name); - } - } - /* If this triggers, take a look at lib/parse_conf.h */ - if (i >= MAX_RES_ITEMS) { - Emsg1(M_ERROR_TERM, 0, _("Too many items in %s resource\n"), resources[rindex].name); + UnionOfResources *res; + int rindex = type - R_FIRST; + int i; + int error = 0; + + /* + * Ensure that all required items are present + */ + for (i = 0; items[i].name; i++) { + if (items[i].flags & CFG_ITEM_REQUIRED) { + if (!BitIsSet(i, res_all.res_monitor.hdr.item_present)) { + Emsg2(M_ERROR_TERM, 0, _("%s item is required in %s resource, but not found.\n"), items[i].name, + resources[rindex].name); } - } - - /* - * During pass 2 in each "store" routine, we looked up pointers - * to all the resources referrenced in the current resource, now we - * must copy their addresses from the static record to the allocated - * record. - */ - if (pass == 2) { - switch (type) { + } + /* If this triggers, take a look at lib/parse_conf.h */ + if (i >= MAX_RES_ITEMS) { + Emsg1(M_ERROR_TERM, 0, _("Too many items in %s resource\n"), resources[rindex].name); + } + } + + /* + * During pass 2 in each "store" routine, we looked up pointers + * to all the resources referrenced in the current resource, now we + * must copy their addresses from the static record to the allocated + * record. + */ + if (pass == 2) { + switch (type) { /* * Resources not containing a resource */ @@ -320,76 +325,61 @@ bool SaveResource(int type, ResourceItem *items, int pass) case R_STORAGE: case R_DIRECTOR: case R_CONSOLE_FONT: - break; + break; default: - Emsg1(M_ERROR, 0, _("Unknown resource type %d in SaveResource.\n"), type); - error = 1; - break; - } + Emsg1(M_ERROR, 0, _("Unknown resource type %d in SaveResource.\n"), type); + error = 1; + break; + } + /* + * Note, the resource name was already saved during pass 1, + * so here, we can just release it. + */ + if (res_all.res_monitor.hdr.name) { + free(res_all.res_monitor.hdr.name); + res_all.res_monitor.hdr.name = NULL; + } + if (res_all.res_monitor.hdr.desc) { + free(res_all.res_monitor.hdr.desc); + res_all.res_monitor.hdr.desc = NULL; + } + return (error == 0); + } + + /* + * Common + */ + if (!error) { + res = (UnionOfResources *)malloc(resources[rindex].size); + memcpy(res, &res_all, resources[rindex].size); + if (!res_head[rindex]) { + res_head[rindex] = (CommonResourceHeader *)res; /* store first entry */ + Dmsg3(900, "Inserting first %s res: %s index=%d\n", my_config->res_to_str(type), res->res_monitor.name(), rindex); + } else { + CommonResourceHeader *next, *last; /* - * Note, the resource name was already saved during pass 1, - * so here, we can just release it. + * Add new res to end of chain */ - if (res_all.res_monitor.hdr.name) { - free(res_all.res_monitor.hdr.name); - res_all.res_monitor.hdr.name = NULL; - } - if (res_all.res_monitor.hdr.desc) { - free(res_all.res_monitor.hdr.desc); - res_all.res_monitor.hdr.desc = NULL; - } - return (error == 0); - } - - /* - * Common - */ - if (!error) { - res = (UnionOfResources *)malloc(resources[rindex].size); - memcpy(res, &res_all, resources[rindex].size); - if (!res_head[rindex]) { - res_head[rindex] = (CommonResourceHeader *)res; /* store first entry */ - Dmsg3(900, "Inserting first %s res: %s index=%d\n", - res_to_str(type), res->res_monitor.name(), rindex); - } else { - CommonResourceHeader *next, *last; - /* - * Add new res to end of chain - */ - for (last = next = res_head[rindex]; next; next=next->next) { - last = next; - if (strcmp(next->name, res->res_monitor.name()) == 0) { - Emsg2(M_ERROR_TERM, 0, - _("Attempt to define second %s resource named \"%s\" is not permitted.\n"), - resources[rindex].name, res->res_monitor.name()); - } - } - last->next = (CommonResourceHeader *)res; - Dmsg4(900, "Inserting %s res: %s index=%d pass=%d\n", - res_to_str(type), res->res_monitor.name(), rindex, pass); + for (last = next = res_head[rindex]; next; next = next->next) { + last = next; + if (strcmp(next->name, res->res_monitor.name()) == 0) { + Emsg2(M_ERROR_TERM, 0, _("Attempt to define second %s resource named \"%s\" is not permitted.\n"), + resources[rindex].name, res->res_monitor.name()); + } } - } - return (error == 0); + last->next = (CommonResourceHeader *)res; + Dmsg4(900, "Inserting %s res: %s index=%d pass=%d\n", my_config->res_to_str(type), res->res_monitor.name(), rindex, + pass); + } + } + return (error == 0); } ConfigurationParser *InitTmonConfig(const char *configfile, int exit_code) { - return new ConfigurationParser( - configfile, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - exit_code, - (void *)&res_all, - res_all_size, - R_FIRST, - R_LAST, - resources, - res_head, - default_config_filename.c_str(), - "tray-monitor.d"); + return new ConfigurationParser(configfile, nullptr, nullptr, nullptr, nullptr, nullptr, exit_code, + (void *)&res_all, res_all_size, R_FIRST, R_LAST, resources, res_head, + default_config_filename.c_str(), "tray-monitor.d"); } /* @@ -398,37 +388,37 @@ ConfigurationParser *InitTmonConfig(const char *configfile, int exit_code) #ifdef HAVE_JANSSON bool PrintConfigSchemaJson(PoolMem &buffer) { - ResourceTable *resources = my_config->resources_; + ResourceTable *resources = my_config->resources_; - InitializeJson(); + InitializeJson(); - json_t *json = json_object(); - json_object_set_new(json, "format-version", json_integer(2)); - json_object_set_new(json, "component", json_string("bareos-tray-monitor")); - json_object_set_new(json, "version", json_string(VERSION)); + json_t *json = json_object(); + json_object_set_new(json, "format-version", json_integer(2)); + json_object_set_new(json, "component", json_string("bareos-tray-monitor")); + json_object_set_new(json, "version", json_string(VERSION)); - /* - * Resources - */ - json_t *resource = json_object(); - json_object_set(json, "resource", resource); - json_t *bareos_tray_monitor = json_object(); - json_object_set(resource, "bareos-tray-monitor", bareos_tray_monitor); + /* + * Resources + */ + json_t *resource = json_object(); + json_object_set(json, "resource", resource); + json_t *bareos_tray_monitor = json_object(); + json_object_set(resource, "bareos-tray-monitor", bareos_tray_monitor); - for (int r = 0; resources[r].name; r++) { - ResourceTable resource = my_config->resources_[r]; - json_object_set(bareos_tray_monitor, resource.name, json_items(resource.items)); - } + for (int r = 0; resources[r].name; r++) { + ResourceTable resource = my_config->resources_[r]; + json_object_set(bareos_tray_monitor, resource.name, json_items(resource.items)); + } - PmStrcat(buffer, json_dumps(json, JSON_INDENT(2))); - json_decref(json); + PmStrcat(buffer, json_dumps(json, JSON_INDENT(2))); + json_decref(json); - return true; + return true; } #else bool PrintConfigSchemaJson(PoolMem &buffer) { - PmStrcat(buffer, "{ \"success\": false, \"message\": \"not available\" }"); - return false; + PmStrcat(buffer, "{ \"success\": false, \"message\": \"not available\" }"); + return false; } #endif diff --git a/core/src/stored/stored_conf.cc b/core/src/stored/stored_conf.cc index a589b58e8b2..0f0a5a93b28 100644 --- a/core/src/stored/stored_conf.cc +++ b/core/src/stored/stored_conf.cc @@ -342,18 +342,18 @@ static void StoreAutopassword(LEX *lc, ResourceItem *item, int index, int pass) */ switch (item->code) { case 1: - StoreResource(CFG_TYPE_CLEARPASSWORD, lc, item, index, pass); + my_config->StoreResource(CFG_TYPE_CLEARPASSWORD, lc, item, index, pass); break; default: - StoreResource(CFG_TYPE_MD5PASSWORD, lc, item, index, pass); + my_config->StoreResource(CFG_TYPE_MD5PASSWORD, lc, item, index, pass); break; } break; case R_NDMP: - StoreResource(CFG_TYPE_CLEARPASSWORD, lc, item, index, pass); + my_config->StoreResource(CFG_TYPE_CLEARPASSWORD, lc, item, index, pass); break; default: - StoreResource(CFG_TYPE_MD5PASSWORD, lc, item, index, pass); + my_config->StoreResource(CFG_TYPE_MD5PASSWORD, lc, item, index, pass); break; } } @@ -388,7 +388,7 @@ static void StoreDevtype(LEX *lc, ResourceItem *item, int index, int pass) */ static void StoreMaxblocksize(LEX *lc, ResourceItem *item, int index, int pass) { - StoreResource(CFG_TYPE_SIZE32, lc, item, index, pass); + my_config->StoreResource(CFG_TYPE_SIZE32, lc, item, index, pass); if (*(uint32_t *)(item->value) > MAX_BLOCK_LENGTH) { scan_err2(lc, _("Maximum Block Size configured value %u is greater than allowed maximum: %u"), *(uint32_t *)(item->value), MAX_BLOCK_LENGTH); @@ -619,7 +619,7 @@ void DumpResource(int type, CommonResourceHeader *reshdr, int recurse = 1; if (res == NULL) { - sendit(sock, _("Warning: no \"%s\" resource (%d) defined.\n"), res_to_str(type), type); + sendit(sock, _("Warning: no \"%s\" resource (%d) defined.\n"), my_config->res_to_str(type), type); return; } @@ -778,7 +778,7 @@ bool SaveResource(int type, ResourceItem *items, int pass) } } last->next = (CommonResourceHeader *)res; - Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type), res->res_dir.name()); + Dmsg2(90, "Inserting %s res: %s\n", my_config->res_to_str(type), res->res_dir.name()); } } return (error == 0);