Skip to content

Commit

Permalink
Dump bareos-dir configuration options
Browse files Browse the repository at this point in the history
Add command line option -x to let bareos-dir dump his configuration
options in JSON format.

This output will get used to autogenerated documentation for Bareos.

Issues #190: Bareos director should be able to provide information
             about possible configuration options
  • Loading branch information
joergsteffens authored and Marco van Wieringen committed Feb 17, 2015
1 parent 439d459 commit 769affd
Show file tree
Hide file tree
Showing 6 changed files with 327 additions and 74 deletions.
15 changes: 14 additions & 1 deletion src/dird/dird.c
Expand Up @@ -132,6 +132,7 @@ PROG_COPYRIGHT
" -t test - read configuration and exit\n"
" -u userid\n"
" -v verbose user messages\n"
" -x print configuration file schema in JSON format and exit\n"
" -? print this message.\n"
"\n"), 2000, VERSION, BDATE);

Expand All @@ -155,6 +156,7 @@ int main (int argc, char *argv[])
cat_op mode;
bool no_signals = false;
bool test_config = false;
bool export_config_schema = false;
char *uid = NULL;
char *gid = NULL;

Expand All @@ -171,7 +173,7 @@ int main (int argc, char *argv[])

console_command = run_console_command;

while ((ch = getopt(argc, argv, "c:d:fg:mr:stu:v?")) != -1) {
while ((ch = getopt(argc, argv, "c:d:fg:mr:stu:vx?")) != -1) {
switch (ch) {
case 'c': /* specify config file */
if (configfile != NULL) {
Expand Down Expand Up @@ -229,6 +231,10 @@ int main (int argc, char *argv[])
verbose++;
break;

case 'x': /* export configuration file schema (json) and exit */
export_config_schema = true;
break;

case '?':
default:
usage();
Expand Down Expand Up @@ -278,6 +284,13 @@ int main (int argc, char *argv[])
goto bail_out;
}

if (export_config_schema) {
POOL_MEM buffer;
print_config_schema_json(buffer);
printf( "%s\n", buffer.c_str() );
goto bail_out;
}

if (!test_config) { /* we don't need to do this block in test mode */
if (background) {
daemon_start();
Expand Down
38 changes: 0 additions & 38 deletions src/dird/dird_conf.h
Expand Up @@ -28,44 +28,6 @@

/* NOTE: #includes at the end of this file */

/*
* Program specific config types (start at 50)
*/
enum {
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_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 */
};

/*
* Resource codes -- they must be sequential for indexing
*/
Expand Down
7 changes: 0 additions & 7 deletions src/filed/filed_conf.h
Expand Up @@ -26,13 +26,6 @@
* Kern Sibbald, Sep MM
*/

/*
* Program specific config types (start at 50)
*/
enum {
CFG_TYPE_CIPHER = 50 /* Encryption Cipher */
};

/*
* Resource codes -- they must be sequential for indexing
*/
Expand Down
93 changes: 82 additions & 11 deletions src/lib/parse_conf.h
Expand Up @@ -106,9 +106,8 @@ struct RES_ITEM {

#define MAX_RES_ITEMS 80 /* maximum resource items per RES */

/* This is the universal header that is
* at the beginning of every resource
* record.
/*
* This is the universal header that is at the beginning of every resource record.
*/
class RES {
public:
Expand All @@ -122,8 +121,7 @@ class RES {

/*
* Master Resource configuration structure definition
* This is the structure that defines the
* resources that are available to this daemon.
* This is the structure that defines the resources that are available to this daemon.
*/
struct RES_TABLE {
const char *name; /* resource name */
Expand All @@ -132,8 +130,9 @@ struct RES_TABLE {
uint32_t size; /* Size of resource */
};

/* Common Resource definitions */

/*
* Common Resource definitions
*/
#define MAX_RES_NAME_LENGTH MAX_NAME_LENGTH - 1 /* maximum resource name length */

/*
Expand All @@ -145,10 +144,10 @@ struct RES_TABLE {
#define CFG_ITEM_DEPRECATED 0x8 /* Deprecated config option */
#define CFG_ITEM_ALIAS 0x10 /* Item is an alias for an other */

/*
* Standard global types with handlers defined in res.c
*/
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 */
Expand All @@ -175,7 +174,65 @@ enum {
CFG_TYPE_ADDRESSES = 24, /* List of ip addresses */
CFG_TYPE_ADDRESSES_ADDRESS = 25, /* Ip address */
CFG_TYPE_ADDRESSES_PORT = 26, /* Ip port */
CFG_TYPE_PLUGIN_NAMES = 27 /* Plugin Name(s) */
CFG_TYPE_PLUGIN_NAMES = 27, /* Plugin Name(s) */

/*
* 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 */

/*
* 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 DATATYPE_NAME {
const int number;
const char *name;
const char *description;
};

/*
Expand Down Expand Up @@ -291,6 +348,20 @@ void init_resource(int type, RES_ITEM *item);
void save_resource(int type, RES_ITEM *item, int pass);
bool store_resource(int type, LEX *lc, RES_ITEM *item, int index, int pass);
const char *res_to_str(int rcode);
static const char *datatype_to_str(int type);

bool print_config_schema_json(POOL_MEM &buff);
bool print_res_item_schema_json(POOL_MEM &buff, int level, RES_ITEM *item );

/* JSON output helper functions */
void add_json_object_start(POOL_MEM &cfg_str, int level, const char *string);
void add_json_object_end(POOL_MEM &cfg_str, int level, const char *string);
void add_json_pair_plain(POOL_MEM &cfg_str, int level, const char *string, const char *value);
void add_json_pair(POOL_MEM &cfg_str, int level, const char *string, const char *value);
void add_json_pair(POOL_MEM &cfg_str, int level, const char *string, int value);




/* Loop through each resource of type, returning in var */
#ifdef HAVE_TYPEOF
Expand Down

0 comments on commit 769affd

Please sign in to comment.