LCOV - code coverage report
Current view: top level - src - conf.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 346 427 81.0 %
Date: 2022-05-01 01:22:11 Functions: 32 39 82.1 %

          Line data    Source code
       1             : #include "burp.h"
       2             : #include "strlist.h"
       3             : #include "conf.h"
       4             : #include "log.h"
       5             : #include "alloc.h"
       6             : #include "cntr.h"
       7             : #include "prepend.h"
       8             : #include "server/dpth.h"
       9             : 
      10             : #include <assert.h>
      11             : 
      12         118 : enum burp_mode str_to_burp_mode(const char *str)
      13             : {
      14         118 :         if(!strcmp(str, "server"))
      15             :                 return BURP_MODE_SERVER;
      16          50 :         else if(!strcmp(str, "client"))
      17             :                 return BURP_MODE_CLIENT;
      18           0 :         logp("Unknown mode setting: %s\n", str);
      19           0 :         return BURP_MODE_UNSET;
      20             : }
      21             : 
      22             : static const char *burp_mode_to_str(enum burp_mode bm)
      23             : {
      24           0 :         switch(bm)
      25             :         {
      26             :                 case BURP_MODE_UNSET: return "unset";
      27             :                 case BURP_MODE_SERVER: return "server";
      28             :                 case BURP_MODE_CLIENT: return "client";
      29             :                 default: return "unknown";
      30             :         }
      31             : }
      32             : 
      33           1 : enum recovery_method str_to_recovery_method(const char *str)
      34             : {
      35           1 :         if(!strcmp(str, "delete"))
      36             :                 return RECOVERY_METHOD_DELETE;
      37           1 :         else if(!strcmp(str, "resume"))
      38             :                 return RECOVERY_METHOD_RESUME;
      39           0 :         logp("Unknown working_dir_recovery_method setting: %s\n", str);
      40           0 :         return RECOVERY_METHOD_UNSET;
      41             : }
      42             : 
      43           0 : const char *recovery_method_to_str(enum recovery_method r)
      44             : {
      45           0 :         switch(r)
      46             :         {
      47             :                 case RECOVERY_METHOD_DELETE: return "delete";
      48           0 :                 case RECOVERY_METHOD_RESUME: return "resume";
      49           0 :                 default: return "unknown";
      50             :         }
      51             : }
      52             : 
      53           1 : const char *rshash_to_str(enum rshash r)
      54             : {
      55           1 :         switch(r)
      56             :         {
      57             :                 case RSHASH_UNSET: return "unset";
      58           0 :                 case RSHASH_MD4: return "md4";
      59           0 :                 case RSHASH_BLAKE2: return "blake2";
      60           0 :                 default: return "unknown";
      61             :         }
      62             : }
      63             : 
      64        6747 : struct strlist *get_strlist(struct conf *conf)
      65             : {
      66        6747 :         assert(conf->conf_type==CT_STRLIST);
      67        6747 :         return conf->data.sl;
      68             : }
      69             : 
      70        4293 : char *get_string(struct conf *conf)
      71             : {
      72        4293 :         assert(conf->conf_type==CT_STRING);
      73        4293 :         return conf->data.s;
      74             : }
      75             : 
      76        3723 : int get_int(struct conf *conf)
      77             : {
      78        3723 :         assert(conf->conf_type==CT_UINT);
      79        3723 :         return conf->data.i;
      80             : }
      81             : 
      82         464 : uint64_t get_uint64_t(struct conf *conf)
      83             : {
      84         464 :         assert(conf->conf_type==CT_SSIZE_T);
      85         464 :         return conf->data.uint64;
      86             : }
      87             : 
      88           1 : float get_float(struct conf *conf)
      89             : {
      90           1 :         assert(conf->conf_type==CT_FLOAT);
      91           1 :         return conf->data.f;
      92             : }
      93             : 
      94           1 : mode_t get_mode_t(struct conf *conf)
      95             : {
      96           1 :         assert(conf->conf_type==CT_MODE_T);
      97           1 :         return conf->data.mode;
      98             : }
      99             : 
     100         281 : enum burp_mode get_e_burp_mode(struct conf *conf)
     101             : {
     102         281 :         assert(conf->conf_type==CT_E_BURP_MODE);
     103         281 :         return conf->data.burp_mode;
     104             : }
     105             : 
     106         125 : enum recovery_method get_e_recovery_method(struct conf *conf)
     107             : {
     108         125 :         assert(conf->conf_type==CT_E_RECOVERY_METHOD);
     109         125 :         return conf->data.recovery_method;
     110             : }
     111             : 
     112          77 : enum rshash get_e_rshash(struct conf *conf)
     113             : {
     114          77 :         assert(conf->conf_type==CT_E_RSHASH);
     115          77 :         return conf->data.rshash;
     116             : }
     117             : 
     118        1192 : struct cntr *get_cntr(struct conf **confs)
     119             : {
     120        1192 :         return confs[OPT_CNTR]->data.cntr;
     121             : }
     122             : 
     123       23378 : int set_string(struct conf *conf, const char *s)
     124             : {
     125       23378 :         assert(conf->conf_type==CT_STRING);
     126       23378 :         if(conf->data.s) free_w(&(conf->data.s));
     127       23378 :         if(s && !(conf->data.s=strdup_w(s, __func__)))
     128             :                 return -1;
     129             :         return 0;
     130             : }
     131             : 
     132        3063 : int set_int(struct conf *conf, unsigned int i)
     133             : {
     134        3063 :         assert(conf->conf_type==CT_UINT);
     135       27705 :         conf->data.i=i;
     136        3063 :         return 0;
     137             : }
     138             : 
     139       14648 : int set_strlist(struct conf *conf, struct strlist *s)
     140             : {
     141       14648 :         assert(conf->conf_type==CT_STRLIST);
     142       14648 :         if(conf->data.sl) strlists_free(&conf->data.sl);
     143       14648 :         conf->data.sl=s;
     144       14648 :         return 0;
     145             : }
     146             : 
     147           0 : int set_float(struct conf *conf, float f)
     148             : {
     149           0 :         assert(conf->conf_type==CT_FLOAT);
     150         333 :         conf->data.f=f;
     151           0 :         return 0;
     152             : }
     153             : 
     154         118 : int set_e_burp_mode(struct conf *conf, enum burp_mode bm)
     155             : {
     156         118 :         assert(conf->conf_type==CT_E_BURP_MODE);
     157         451 :         conf->data.burp_mode=bm;
     158         118 :         return 0;
     159             : }
     160             : 
     161          73 : int set_e_recovery_method(struct conf *conf, enum recovery_method r)
     162             : {
     163          73 :         assert(conf->conf_type==CT_E_RECOVERY_METHOD);
     164         406 :         conf->data.recovery_method=r;
     165          73 :         return 0;
     166             : }
     167             : 
     168          85 : int set_e_rshash(struct conf *conf, enum rshash r)
     169             : {
     170          85 :         assert(conf->conf_type==CT_E_RSHASH);
     171         418 :         conf->data.rshash=r;
     172          85 :         return 0;
     173             : }
     174             : 
     175           0 : int set_mode_t(struct conf *conf, mode_t m)
     176             : {
     177           0 :         assert(conf->conf_type==CT_MODE_T);
     178         333 :         conf->data.mode=m;
     179           0 :         return 0;
     180             : }
     181             : 
     182         363 : int set_uint64_t(struct conf *conf, uint64_t s)
     183             : {
     184         363 :         assert(conf->conf_type==CT_SSIZE_T);
     185        2694 :         conf->data.uint64=s;
     186         363 :         return 0;
     187             : }
     188             : 
     189          34 : int set_cntr(struct conf *conf, struct cntr *cntr)
     190             : {
     191          34 :         assert(conf->conf_type==CT_CNTR);
     192         367 :         conf->data.cntr=cntr;
     193          34 :         return 0;
     194             : }
     195             : 
     196         642 : int add_to_strlist(struct conf *conf, const char *value, int include)
     197             : {
     198         642 :         assert(conf->conf_type==CT_STRLIST);
     199         642 :         if(conf->flags & CONF_FLAG_STRLIST_SORTED)
     200         152 :                 return strlist_add_sorted(&(conf->data.sl), value, include);
     201             :         else
     202         490 :                 return strlist_add(&(conf->data.sl), value, include);
     203             : }
     204             : 
     205          50 : int add_to_strlist_sorted_uniq(struct conf *conf, const char *value, int flag)
     206             : {
     207          50 :         return strlist_add_sorted_uniq(&(conf->data.sl), value, flag);
     208             : }
     209             : 
     210       59104 : void conf_free_content(struct conf *c)
     211             : {
     212       59104 :         if(!c) return;
     213       56812 :         switch(c->conf_type)
     214             :         {
     215             :                 case CT_STRING:
     216       18273 :                         free_w(&c->data.s);
     217       18273 :                         break;
     218             :                 case CT_STRLIST:
     219       12922 :                         strlists_free(&c->data.sl);
     220       12922 :                         break;
     221             :                 case CT_CNTR:
     222         293 :                         cntr_free(&c->data.cntr);
     223         293 :                         break;
     224             :                 case CT_FLOAT:
     225             :                 case CT_E_BURP_MODE:
     226             :                 case CT_E_RECOVERY_METHOD:
     227             :                 case CT_E_RSHASH:
     228             :                 case CT_UINT:
     229             :                 case CT_MODE_T:
     230             :                 case CT_SSIZE_T:
     231       25324 :                         memset(&c->data, 0, sizeof(c->data));
     232       25324 :                         break;
     233             :         }
     234             : }
     235             : 
     236          12 : void confs_memcpy(struct conf **dst, struct conf **src)
     237             : {
     238          12 :         int i=0;
     239        2304 :         for(i=0; i<OPT_MAX; i++)
     240             :         {
     241        2292 :                 free_v((void **)&(dst[i]));
     242        2292 :                 dst[i]=src[i];
     243             :         }
     244          12 : }
     245             : 
     246          12 : void confs_null(struct conf **confs)
     247             : {
     248          12 :         int i=0;
     249          12 :         if(!confs) return;
     250        2292 :         for(i=0; i<OPT_MAX; i++) confs[i]=NULL;
     251             : }
     252             : 
     253         307 : void confs_free_content(struct conf **confs)
     254             : {
     255         307 :         int i=0;
     256         307 :         if(!confs) return;
     257       58637 :         for(i=0; i<OPT_MAX; i++) conf_free_content(confs[i]);
     258             : }
     259             : 
     260             : /* Free only stuff related to includes/excludes.
     261             :    This is so that the server can override them all on the client. */
     262           9 : void free_incexcs(struct conf **confs)
     263             : {
     264           9 :         int i=0;
     265           9 :         if(!confs) return;
     266        1719 :         for(i=0; i<OPT_MAX; i++)
     267        1719 :                 if(confs[i]->flags & CONF_FLAG_INCEXC)
     268         288 :                         conf_free_content(confs[i]);
     269             : }
     270             : 
     271             : static void sc(struct conf *conf, uint8_t flags,
     272             :         enum conf_type conf_type, const char *field)
     273             : {
     274       63603 :         conf->conf_type=conf_type;
     275       63603 :         conf->field=field;
     276       63603 :         conf->flags=flags;
     277       60939 :         memset(&conf->data, 0, sizeof(conf->data));
     278             : }
     279             : 
     280             : static int sc_str(struct conf *conf, const char *def,
     281             :         uint8_t flags, const char *field)
     282             : {
     283       40626 :         sc(conf, flags, CT_STRING, field);
     284       20313 :         return set_string(conf, def);
     285             : }
     286             : 
     287             : static int sc_int(struct conf *conf, unsigned int def,
     288             :         uint8_t flags, const char *field)
     289             : {
     290       49284 :         sc(conf, flags, CT_UINT, field);
     291       24642 :         return set_int(conf, def);
     292             : }
     293             : 
     294             : static int sc_lst(struct conf *conf, struct strlist *def,
     295             :         uint8_t flags, const char *field)
     296             : {
     297       28638 :         sc(conf, flags, CT_STRLIST, field);
     298       14319 :         return set_strlist(conf, def);
     299             : }
     300             : 
     301             : static int sc_flt(struct conf *conf, float def,
     302             :         uint8_t flags, const char *field)
     303             : {
     304         666 :         sc(conf, flags, CT_FLOAT, field);
     305         333 :         return set_float(conf, def);
     306             : }
     307             : 
     308             : static int sc_ebm(struct conf *conf, enum burp_mode def,
     309             :         uint8_t flags, const char *field)
     310             : {
     311         666 :         sc(conf, flags, CT_E_BURP_MODE, field);
     312         333 :         return set_e_burp_mode(conf, def);
     313             : }
     314             : 
     315             : static int sc_rec(struct conf *conf, enum recovery_method def,
     316             :         uint8_t flags, const char *field)
     317             : {
     318         666 :         sc(conf, flags, CT_E_RECOVERY_METHOD, field);
     319         333 :         return set_e_recovery_method(conf, def);
     320             : }
     321             : 
     322             : static int sc_rsh(struct conf *conf, enum rshash def,
     323             :         uint8_t flags, const char *field)
     324             : {
     325         666 :         sc(conf, flags, CT_E_RSHASH, field);
     326         333 :         return set_e_rshash(conf, def);
     327             : }
     328             : 
     329             : static int sc_mod(struct conf *conf, mode_t def,
     330             :         uint8_t flags, const char *field)
     331             : {
     332         666 :         sc(conf, flags, CT_MODE_T, field);
     333         333 :         return set_mode_t(conf, def);
     334             : }
     335             : 
     336             : static int sc_u64(struct conf *conf, uint64_t def,
     337             :         uint8_t flags, const char *field)
     338             : {
     339        4662 :         sc(conf, flags, CT_SSIZE_T, field);
     340        2331 :         return set_uint64_t(conf, def);
     341             : }
     342             : 
     343             : static int sc_cntr(struct conf *conf, struct cntr *def,
     344             :         uint8_t flags, const char *field)
     345             : {
     346         666 :         sc(conf, flags, CT_CNTR, field);
     347         333 :         return set_cntr(conf, def);
     348             : }
     349             : 
     350       63603 : static int reset_conf(struct conf **c, enum conf_opt o)
     351             : {
     352             :         // Do this with a switch statement, so that we get compiler warnings
     353             :         // if anything is missed.
     354       63603 :         switch(o)
     355             :         {
     356             :         case OPT_BURP_MODE:
     357         666 :           return sc_ebm(c[o], BURP_MODE_UNSET, 0, "mode");
     358             :         case OPT_LOCKFILE:
     359         666 :           return sc_str(c[o], 0, 0, "lockfile");
     360             :         case OPT_PIDFILE:
     361         666 :           return sc_str(c[o], 0, 0, "pidfile");
     362             :         case OPT_SSL_CERT_CA:
     363         666 :           return sc_str(c[o], 0, 0, "ssl_cert_ca");
     364             :         case OPT_SSL_CERT:
     365         666 :           return sc_str(c[o], 0, 0, "ssl_cert");
     366             :         case OPT_SSL_KEY:
     367         666 :           return sc_str(c[o], 0, 0, "ssl_key");
     368             :         case OPT_SSL_KEY_PASSWORD:
     369             :           // FIX THIS: synonym: ssl_cert_password
     370         666 :           return sc_str(c[o], 0, 0, "ssl_key_password");
     371             :         case OPT_SSL_PEER_CN:
     372         666 :           return sc_str(c[o], 0, 0, "ssl_peer_cn");
     373             :         case OPT_SSL_CIPHERS:
     374         666 :           return sc_str(c[o], 0, 0, "ssl_ciphers");
     375             :         case OPT_SSL_COMPRESSION:
     376         666 :           return sc_int(c[o], 5, 0, "ssl_compression");
     377             :         case OPT_SSL_VERIFY_PEER_EARLY:
     378         666 :           return sc_int(c[o], 0, 0, "ssl_verify_peer_early");
     379             :         case OPT_RATELIMIT:
     380         666 :           return sc_flt(c[o], 0, 0, "ratelimit");
     381             :         case OPT_NETWORK_TIMEOUT:
     382         666 :           return sc_int(c[o], 60*60*2, 0, "network_timeout");
     383             :         case OPT_CLIENT_IS_WINDOWS:
     384         666 :           return sc_int(c[o], 0, 0, "client_is_windows");
     385             :         case OPT_PEER_VERSION:
     386         666 :           return sc_str(c[o], 0, 0, "peer_version");
     387             :         case OPT_PORT:
     388         666 :           return sc_lst(c[o], 0, 0, "port");
     389             :         case OPT_STATUS_PORT:
     390         666 :           return sc_lst(c[o], 0, 0, "status_port");
     391             :         case OPT_LISTEN:
     392         666 :           return sc_lst(c[o], 0, 0, "listen");
     393             :         case OPT_LISTEN_STATUS:
     394         666 :           return sc_lst(c[o], 0, 0, "listen_status");
     395             :         case OPT_NETWORK_ALLOW:
     396         666 :           return sc_lst(c[o], 0,
     397             :                 CONF_FLAG_CC_OVERRIDE|CONF_FLAG_STRLIST_REPLACE, "network_allow");
     398             :         case OPT_NETWORK_ALLOW_STATUS:
     399         666 :           return sc_lst(c[o], 0,
     400             :                 CONF_FLAG_CC_OVERRIDE|CONF_FLAG_STRLIST_REPLACE, "network_allow_status");
     401             :         case OPT_PORT_BACKUP:
     402         666 :           return sc_int(c[o], 0, 0, "port_backup");
     403             :         case OPT_PORT_RESTORE:
     404         666 :           return sc_int(c[o], 0, 0, "port_restore");
     405             :         case OPT_PORT_VERIFY:
     406         666 :           return sc_int(c[o], 0, 0, "port_verify");
     407             :         case OPT_PORT_LIST:
     408         666 :           return sc_int(c[o], 0, 0, "port_list");
     409             :         case OPT_PORT_DELETE:
     410         666 :           return sc_int(c[o], 0, 0, "port_delete");
     411             :         case OPT_SSL_DHFILE:
     412         666 :           return sc_str(c[o], 0, 0, "ssl_dhfile");
     413             :         case OPT_MAX_CHILDREN:
     414         666 :           return sc_lst(c[o], 0, 0, "max_children");
     415             :         case OPT_MAX_STATUS_CHILDREN:
     416         666 :           return sc_lst(c[o], 0, 0, "max_status_children");
     417             :         case OPT_MAX_PARALLEL_BACKUPS:
     418         666 :           return sc_int(c[o], 0, CONF_FLAG_CC_OVERRIDE, "max_parallel_backups");
     419             :         case OPT_CLIENT_LOCKDIR:
     420         666 :           return sc_str(c[o], 0, CONF_FLAG_CC_OVERRIDE, "client_lockdir");
     421             :         case OPT_UMASK:
     422         666 :           return sc_mod(c[o], 0022, 0, "umask");
     423             :         case OPT_MAX_HARDLINKS:
     424         666 :           return sc_int(c[o], 10000, 0, "max_hardlinks");
     425             :         case OPT_MAX_STORAGE_SUBDIRS:
     426         666 :           return sc_int(c[o], MAX_STORAGE_SUBDIRS, 0, "max_storage_subdirs");
     427             :         case OPT_DAEMON:
     428         666 :           return sc_int(c[o], 1, 0, "daemon");
     429             :         case OPT_CA_CONF:
     430         666 :           return sc_str(c[o], 0, 0, "ca_conf");
     431             :         case OPT_CA_NAME:
     432         666 :           return sc_str(c[o], 0, 0, "ca_name");
     433             :         case OPT_CA_SERVER_NAME:
     434         666 :           return sc_str(c[o], 0, 0, "ca_server_name");
     435             :         case OPT_CA_BURP_CA:
     436         666 :           return sc_str(c[o], 0, 0, "ca_" PACKAGE_TARNAME "_ca");
     437             :         case OPT_CA_CRL:
     438         666 :           return sc_str(c[o], 0, 0, "ca_crl");
     439             :         case OPT_CA_CRL_CHECK:
     440         666 :           return sc_int(c[o], 0, 0, "ca_crl_check");
     441             :         case OPT_RBLK_MEMORY_MAX:
     442         666 :           return sc_u64(c[o], 256*1024*1024, // 256 Mb.
     443             :                 CONF_FLAG_CC_OVERRIDE, "rblk_memory_max");
     444             :         case OPT_SPARSE_SIZE_MAX:
     445         666 :           return sc_u64(c[o], 256*1024*1024, // 256 Mb.
     446             :                 CONF_FLAG_CC_OVERRIDE, "sparse_size_max");
     447             :         case OPT_MONITOR_LOGFILE:
     448         666 :           return sc_str(c[o], 0, 0, "monitor_logfile");
     449             :         case OPT_MONITOR_EXE:
     450         666 :           return sc_str(c[o], 0, 0, "monitor_exe");
     451             :         case OPT_BACKUP_FAILOVERS_LEFT:
     452         666 :           return sc_int(c[o], 0, 0, "");
     453             :         case OPT_CNAME:
     454         666 :           return sc_str(c[o], 0, 0, "cname");
     455             :         case OPT_CNAME_LOWERCASE:
     456         666 :           return sc_int(c[o], 0, 0, "cname_lowercase");
     457             :         case OPT_CNAME_FQDN:
     458         666 :           return sc_int(c[o], 1, 0, "cname_fqdn");
     459             :         case OPT_PASSWORD:
     460         666 :           return sc_str(c[o], 0, 0, "password");
     461             :         case OPT_PASSWD:
     462         666 :           return sc_str(c[o], 0, 0, "passwd");
     463             :         case OPT_SERVER:
     464         666 :           return sc_str(c[o], 0, 0, "server");
     465             :         case OPT_SERVER_FAILOVER:
     466         666 :           return sc_lst(c[o], 0, 0, "server_failover");
     467             :         case OPT_FAILOVER_ON_BACKUP_ERROR:
     468         666 :           return sc_int(c[o], 0, 0, "failover_on_backup_error");
     469             :         case OPT_ENCRYPTION_PASSWORD:
     470         666 :           return sc_str(c[o], 0, 0, "encryption_password");
     471             :         case OPT_AUTOUPGRADE_OS:
     472         666 :           return sc_str(c[o], 0, 0, "autoupgrade_os");
     473             :         case OPT_AUTOUPGRADE_DIR:
     474         666 :           return sc_str(c[o], 0, 0, "autoupgrade_dir");
     475             :         case OPT_CA_CSR_DIR:
     476         666 :           return sc_str(c[o], 0, 0, "ca_csr_dir");
     477             :         case OPT_RANDOMISE:
     478         666 :           return sc_int(c[o], 0, 0, "randomise");
     479             :         case OPT_RESTORE_LIST:
     480         666 :           return sc_str(c[o], 0, 0, "restore_list");
     481             :         case OPT_ENABLED:
     482         666 :           return sc_int(c[o], 1, CONF_FLAG_CC_OVERRIDE, "enabled");
     483             :         case OPT_SERVER_CAN_OVERRIDE_INCLUDES:
     484         666 :           return sc_int(c[o], 1, 0, "server_can_override_includes");
     485             :         case OPT_BACKUP:
     486         666 :           return sc_str(c[o], 0, CONF_FLAG_INCEXC_RESTORE, "backup");
     487             :         case OPT_BACKUP2:
     488         666 :           return sc_str(c[o], 0, 0, "backup2");
     489             :         case OPT_RESTOREPREFIX:
     490         666 :           return sc_str(c[o], 0, CONF_FLAG_INCEXC_RESTORE, "restoreprefix");
     491             :         case OPT_STRIP_FROM_PATH:
     492         666 :           return sc_str(c[o], 0, CONF_FLAG_INCEXC_RESTORE, "stripfrompath");
     493             :         case OPT_BROWSEFILE:
     494         666 :           return sc_str(c[o], 0, 0, "browsefile");
     495             :         case OPT_BROWSEDIR:
     496         666 :           return sc_str(c[o], 0, 0, "browsedir");
     497             :         case OPT_GLOB_AFTER_SCRIPT_PRE:
     498         666 :           return sc_int(c[o], 1, 0, "glob_after_script_pre");
     499             :         case OPT_B_SCRIPT_PRE:
     500         666 :           return sc_str(c[o], 0, 0, "backup_script_pre");
     501             :         case OPT_B_SCRIPT_PRE_ARG:
     502         666 :           return sc_lst(c[o], 0, 0, "backup_script_pre_arg");
     503             :         case OPT_B_SCRIPT_POST:
     504         666 :           return sc_str(c[o], 0, 0, "backup_script_post");
     505             :         case OPT_B_SCRIPT_POST_ARG:
     506         666 :           return sc_lst(c[o], 0, 0, "backup_script_post_arg");
     507             :         case OPT_B_SCRIPT_POST_RUN_ON_FAIL:
     508         666 :           return sc_int(c[o], 0, 0, "backup_script_post_run_on_fail");
     509             :         case OPT_B_SCRIPT_RESERVED_ARGS:
     510         666 :           return sc_int(c[o], 1, 0, "backup_script_reserved_args");
     511             :         case OPT_R_SCRIPT_PRE:
     512         666 :           return sc_str(c[o], 0, 0, "restore_script_pre");
     513             :         case OPT_R_SCRIPT_PRE_ARG:
     514         666 :           return sc_lst(c[o], 0, 0, "restore_script_pre_arg");
     515             :         case OPT_R_SCRIPT_POST:
     516         666 :           return sc_str(c[o], 0, 0, "restore_script_post");
     517             :         case OPT_R_SCRIPT_POST_ARG:
     518         666 :           return sc_lst(c[o], 0, 0, "restore_script_post_arg");
     519             :         case OPT_R_SCRIPT_POST_RUN_ON_FAIL:
     520         666 :           return sc_int(c[o], 0, 0, "restore_script_post_run_on_fail");
     521             :         case OPT_B_SCRIPT:
     522         666 :           return sc_str(c[o], 0, 0, "backup_script");
     523             :         case OPT_B_SCRIPT_ARG:
     524         666 :           return sc_lst(c[o], 0, 0, "backup_script_arg");
     525             :         case OPT_R_SCRIPT:
     526         666 :           return sc_str(c[o], 0, 0, "restore_script");
     527             :         case OPT_R_SCRIPT_ARG:
     528         666 :           return sc_lst(c[o], 0, 0, "restore_script_arg");
     529             :         case OPT_R_SCRIPT_RESERVED_ARGS:
     530         666 :           return sc_int(c[o], 1, 0, "restore_script_reserved_args");
     531             :         case OPT_SEND_CLIENT_CNTR:
     532         666 :           return sc_int(c[o], 0, 0, "send_client_cntr");
     533             :         case OPT_SUPER_CLIENT:
     534         666 :           return sc_str(c[o], 0, 0, "");
     535             :         case OPT_RESTORE_PATH:
     536         666 :           return sc_str(c[o], 0, 0, "restore_path");
     537             :         case OPT_ORIG_CLIENT:
     538         666 :           return sc_str(c[o], 0, CONF_FLAG_INCEXC_RESTORE, "orig_client");
     539             :         case OPT_CONNECT_CLIENT:
     540         666 :           return sc_str(c[o], 0, 0, "");
     541             :         case OPT_CNTR:
     542         666 :           return sc_cntr(c[o], 0, 0, "");
     543             :         case OPT_VSS_RESTORE:
     544         666 :           return sc_int(c[o], VSS_RESTORE_ON, 0, "");
     545             :         case OPT_READALL:
     546         666 :           return sc_int(c[o], 0, CONF_FLAG_CC_OVERRIDE, "readall");
     547             :         case OPT_BREAKPOINT:
     548         666 :           return sc_int(c[o], 0,
     549             :                 CONF_FLAG_CC_OVERRIDE, "breakpoint");
     550             :         case OPT_CONFFILE:
     551         666 :           return sc_str(c[o], 0,
     552             :                 CONF_FLAG_CC_OVERRIDE, "conffile");
     553             :         case OPT_SYSLOG:
     554         666 :           return sc_int(c[o], 0,
     555             :                 CONF_FLAG_CC_OVERRIDE, "syslog");
     556             :         case OPT_STDOUT:
     557         666 :           return sc_int(c[o], 1,
     558             :                 CONF_FLAG_CC_OVERRIDE, "stdout");
     559             :         case OPT_PROGRESS_COUNTER:
     560         666 :           return sc_int(c[o], 0,
     561             :                 CONF_FLAG_CC_OVERRIDE, "progress_counter");
     562             :         case OPT_USER:
     563         666 :           return sc_str(c[o], 0,
     564             :                 CONF_FLAG_CC_OVERRIDE, "user");
     565             :         case OPT_GROUP:
     566         666 :           return sc_str(c[o], 0,
     567             :                 CONF_FLAG_CC_OVERRIDE, "group");
     568             :         case OPT_DIRECTORY:
     569         666 :           return sc_str(c[o], 0,
     570             :                 CONF_FLAG_CC_OVERRIDE, "directory");
     571             :         case OPT_TIMESTAMP_FORMAT:
     572         666 :           return sc_str(c[o], 0,
     573             :                 CONF_FLAG_CC_OVERRIDE, "timestamp_format");
     574             :         case OPT_CLIENTCONFDIR:
     575         666 :           return sc_str(c[o], 0,
     576             :                 CONF_FLAG_CC_OVERRIDE, "clientconfdir");
     577             :         case OPT_FORK:
     578         666 :           return sc_int(c[o], 1, 0, "fork");
     579             :         case OPT_DIRECTORY_TREE:
     580         666 :           return sc_int(c[o], 1,
     581             :                 CONF_FLAG_CC_OVERRIDE, "directory_tree");
     582             :         case OPT_PASSWORD_CHECK:
     583         666 :           return sc_int(c[o], 1,
     584             :                 CONF_FLAG_CC_OVERRIDE, "password_check");
     585             :         case OPT_MANUAL_DELETE:
     586         666 :           return sc_str(c[o], 0,
     587             :                 CONF_FLAG_CC_OVERRIDE, "manual_delete");
     588             :         case OPT_MONITOR_BROWSE_CACHE:
     589         666 :           return sc_int(c[o], 0,
     590             :                 CONF_FLAG_CC_OVERRIDE, "monitor_browse_cache");
     591             :         case OPT_S_SCRIPT_PRE:
     592         666 :           return sc_str(c[o], 0,
     593             :                 CONF_FLAG_CC_OVERRIDE, "server_script_pre");
     594             :         case OPT_S_SCRIPT_PRE_ARG:
     595         666 :           return sc_lst(c[o], 0,
     596             :                 CONF_FLAG_CC_OVERRIDE|CONF_FLAG_STRLIST_REPLACE, "server_script_pre_arg");
     597             :         case OPT_S_SCRIPT_PRE_NOTIFY:
     598         666 :           return sc_int(c[o], 0,
     599             :                 CONF_FLAG_CC_OVERRIDE, "server_script_pre_notify");
     600             :         case OPT_S_SCRIPT_POST:
     601         666 :           return sc_str(c[o], 0,
     602             :                 CONF_FLAG_CC_OVERRIDE, "server_script_post");
     603             :         case OPT_S_SCRIPT_POST_ARG:
     604         666 :           return sc_lst(c[o], 0,
     605             :                 CONF_FLAG_CC_OVERRIDE|CONF_FLAG_STRLIST_REPLACE, "server_script_post_arg");
     606             :         case OPT_S_SCRIPT_POST_RUN_ON_FAIL:
     607         666 :           return sc_int(c[o], 0,
     608             :                 CONF_FLAG_CC_OVERRIDE, "server_script_post_run_on_fail");
     609             :         case OPT_S_SCRIPT_POST_NOTIFY:
     610         666 :           return sc_int(c[o], 0,
     611             :                 CONF_FLAG_CC_OVERRIDE, "server_script_post_notify");
     612             :         case OPT_S_SCRIPT:
     613         666 :           return sc_str(c[o], 0,
     614             :                 CONF_FLAG_CC_OVERRIDE, "server_script");
     615             :         case OPT_S_SCRIPT_ARG:
     616         666 :           return sc_lst(c[o], 0,
     617             :                 CONF_FLAG_CC_OVERRIDE|CONF_FLAG_STRLIST_REPLACE, "server_script_arg");
     618             :         case OPT_S_SCRIPT_NOTIFY:
     619         666 :           return sc_int(c[o], 0,
     620             :                 CONF_FLAG_CC_OVERRIDE, "server_script_notify");
     621             :         case OPT_HARDLINKED_ARCHIVE:
     622         666 :           return sc_int(c[o], 0,
     623             :                 CONF_FLAG_CC_OVERRIDE, "hardlinked_archive");
     624             :         case OPT_KEEP:
     625         666 :           return sc_lst(c[o], 0,
     626             :                 CONF_FLAG_CC_OVERRIDE|CONF_FLAG_STRLIST_REPLACE, "keep");
     627             :         case OPT_LIBRSYNC:
     628         666 :           return sc_int(c[o], 1,
     629             :                 CONF_FLAG_CC_OVERRIDE, "librsync");
     630             :         case OPT_LIBRSYNC_MAX_SIZE:
     631         666 :           return sc_u64(c[o], 0,
     632             :                 CONF_FLAG_CC_OVERRIDE, "librsync_max_size");
     633             :         case OPT_COMPRESSION:
     634         666 :           return sc_int(c[o], 9,
     635             :                 CONF_FLAG_CC_OVERRIDE, "compression");
     636             :         case OPT_VERSION_WARN:
     637         666 :           return sc_int(c[o], 1,
     638             :                 CONF_FLAG_CC_OVERRIDE, "version_warn");
     639             :         case OPT_PATH_LENGTH_WARN:
     640         666 :           return sc_int(c[o], 1,
     641             :                 CONF_FLAG_CC_OVERRIDE, "path_length_warn");
     642             :         case OPT_HARD_QUOTA:
     643         666 :           return sc_u64(c[o], 0,
     644             :                 CONF_FLAG_CC_OVERRIDE, "hard_quota");
     645             :         case OPT_SOFT_QUOTA:
     646         666 :           return sc_u64(c[o], 0,
     647             :                 CONF_FLAG_CC_OVERRIDE, "soft_quota");
     648             :         case OPT_TIMER_SCRIPT:
     649         666 :           return sc_str(c[o], 0,
     650             :                 CONF_FLAG_CC_OVERRIDE, "timer_script");
     651             :         case OPT_TIMER_ARG:
     652         666 :           return sc_lst(c[o], 0,
     653             :                 CONF_FLAG_CC_OVERRIDE|CONF_FLAG_STRLIST_REPLACE, "timer_arg");
     654             :         case OPT_TIMER_REPEAT_INTERVAL:
     655         666 :           return sc_int(c[o], 0,
     656             :                 CONF_FLAG_CC_OVERRIDE, "timer_repeat_interval");
     657             :         case OPT_LABEL:
     658         666 :           return sc_lst(c[o], 0,
     659             :                 CONF_FLAG_CC_OVERRIDE|CONF_FLAG_STRLIST_REPLACE, "label");
     660             :         case OPT_N_SUCCESS_SCRIPT:
     661         666 :           return sc_str(c[o], 0,
     662             :                 CONF_FLAG_CC_OVERRIDE, "notify_success_script");
     663             :         case OPT_N_SUCCESS_ARG:
     664         666 :           return sc_lst(c[o], 0,
     665             :                 CONF_FLAG_CC_OVERRIDE|CONF_FLAG_STRLIST_REPLACE, "notify_success_arg");
     666             :         case OPT_N_SUCCESS_WARNINGS_ONLY:
     667         666 :           return sc_int(c[o], 0,
     668             :                 CONF_FLAG_CC_OVERRIDE, "notify_success_warnings_only");
     669             :         case OPT_N_SUCCESS_CHANGES_ONLY:
     670         666 :           return sc_int(c[o], 0,
     671             :                 CONF_FLAG_CC_OVERRIDE, "notify_success_changes_only");
     672             :         case OPT_N_FAILURE_SCRIPT:
     673         666 :           return sc_str(c[o], 0,
     674             :                 CONF_FLAG_CC_OVERRIDE, "notify_failure_script");
     675             :         case OPT_N_FAILURE_ARG:
     676         666 :           return sc_lst(c[o], 0,
     677             :                 CONF_FLAG_CC_OVERRIDE|CONF_FLAG_STRLIST_REPLACE, "notify_failure_arg");
     678             :         case OPT_N_FAILURE_BACKUP_FAILOVERS_LEFT:
     679         666 :           return sc_int(c[o], 1,
     680             :                 CONF_FLAG_CC_OVERRIDE, "notify_failure_on_backup_with_failovers_left");
     681             :         case OPT_N_FAILURE_BACKUP_WORKING_DELETION:
     682         666 :           return sc_int(c[o], 0,
     683             :                 CONF_FLAG_CC_OVERRIDE, "notify_failure_on_backup_working_dir_deletion");
     684             :         case OPT_RESTORE_CLIENTS:
     685         666 :           return sc_lst(c[o], 0,
     686             :                 CONF_FLAG_CC_OVERRIDE|CONF_FLAG_STRLIST_SORTED, "restore_client");
     687             :         case OPT_SUPER_CLIENTS:
     688         666 :           return sc_lst(c[o], 0,
     689             :                 CONF_FLAG_CC_OVERRIDE|CONF_FLAG_STRLIST_SORTED, "super_client");
     690             :         case OPT_DEDUP_GROUP:
     691         666 :           return sc_str(c[o], 0,
     692             :                 CONF_FLAG_CC_OVERRIDE, "dedup_group");
     693             :         case OPT_CLIENT_CAN_DELETE:
     694         666 :           return sc_int(c[o], 1,
     695             :                 CONF_FLAG_CC_OVERRIDE, "client_can_delete");
     696             :         case OPT_CLIENT_CAN_DIFF:
     697         666 :           return sc_int(c[o], 1,
     698             :                 CONF_FLAG_CC_OVERRIDE, "client_can_diff");
     699             :         case OPT_CLIENT_CAN_FORCE_BACKUP:
     700         666 :           return sc_int(c[o], 1,
     701             :                 CONF_FLAG_CC_OVERRIDE, "client_can_force_backup");
     702             :         case OPT_CLIENT_CAN_LIST:
     703         666 :           return sc_int(c[o], 1,
     704             :                 CONF_FLAG_CC_OVERRIDE, "client_can_list");
     705             :         case OPT_CLIENT_CAN_MONITOR:
     706         666 :           return sc_int(c[o], 1,
     707             :                 CONF_FLAG_CC_OVERRIDE, "client_can_monitor");
     708             :         case OPT_CLIENT_CAN_RESTORE:
     709         666 :           return sc_int(c[o], 1,
     710             :                 CONF_FLAG_CC_OVERRIDE, "client_can_restore");
     711             :         case OPT_CLIENT_CAN_VERIFY:
     712         666 :           return sc_int(c[o], 1,
     713             :                 CONF_FLAG_CC_OVERRIDE, "client_can_verify");
     714             :         case OPT_SERVER_CAN_RESTORE:
     715         666 :           return sc_int(c[o], 1,
     716             :                 CONF_FLAG_CC_OVERRIDE, "server_can_restore");
     717             :         case OPT_WORKING_DIR_RECOVERY_METHOD:
     718         666 :           return sc_rec(c[o], RECOVERY_METHOD_DELETE,
     719             :                 CONF_FLAG_CC_OVERRIDE, "working_dir_recovery_method");
     720             :         case OPT_MAX_RESUME_ATTEMPTS:
     721         666 :           return sc_int(c[o], 0,
     722             :                 CONF_FLAG_CC_OVERRIDE, "max_resume_attempts");
     723             :         case OPT_FAIL_ON_WARNING:
     724         666 :           return sc_int(c[o], 0,
     725             :                 CONF_FLAG_CC_OVERRIDE, "fail_on_warning");
     726             :         case OPT_RSHASH:
     727         666 :           return sc_rsh(c[o], RSHASH_UNSET,
     728             :                 CONF_FLAG_CC_OVERRIDE, "");
     729             :         case OPT_MESSAGE:
     730         666 :           return sc_int(c[o], 0,
     731             :                 CONF_FLAG_CC_OVERRIDE, "");
     732             :         case OPT_INCEXCDIR:
     733             :           // This is a combination of OPT_INCLUDE and OPT_EXCLUDE, so
     734             :           // no field name set for now.
     735         666 :           return sc_lst(c[o], 0, CONF_FLAG_STRLIST_SORTED, "incexcdir");
     736             :         case OPT_STARTDIR:
     737             :           // This is a combination of OPT_INCLUDE and OPT_EXCLUDE, so
     738             :           // no field name set for now.
     739             :           // Deliberately not using CONF_FLAG_STRLIST_SORTED because of the
     740             :           // way finalise_start_dirs() works.
     741         666 :           return sc_lst(c[o], 0, 0, "startdir");
     742             :         case OPT_INCLUDE:
     743             :           // Combines with OPT_EXCLUDE to make OPT_INCEXCDIR and OPT_STARTDIR.
     744         666 :           return sc_lst(c[o], 0,
     745             :                 CONF_FLAG_INCEXC|CONF_FLAG_INCEXC_RESTORE|CONF_FLAG_STRLIST_SORTED, "include");
     746             :         case OPT_EXCLUDE:
     747             :           // Combines with OPT_INCLUDE to make OPT_INCEXCDIR and OPT_STARTDIR.
     748         666 :           return sc_lst(c[o], 0,
     749             :                 CONF_FLAG_INCEXC|CONF_FLAG_INCEXC_RESTORE|CONF_FLAG_STRLIST_SORTED, "exclude");
     750             :         case OPT_FSCHGDIR:
     751         666 :           return sc_lst(c[o], 0,
     752             :                 CONF_FLAG_INCEXC|CONF_FLAG_STRLIST_SORTED, "cross_filesystem");
     753             :         case OPT_NOBACKUP:
     754         666 :           return sc_lst(c[o], 0,
     755             :                 CONF_FLAG_INCEXC|CONF_FLAG_STRLIST_SORTED, "nobackup");
     756             :         case OPT_INCEXT:
     757         666 :           return sc_lst(c[o], 0,
     758             :                 CONF_FLAG_INCEXC|CONF_FLAG_STRLIST_SORTED, "include_ext");
     759             :         case OPT_EXCEXT:
     760         666 :           return sc_lst(c[o], 0,
     761             :                 CONF_FLAG_INCEXC|CONF_FLAG_STRLIST_SORTED, "exclude_ext");
     762             :         case OPT_INCREG:
     763         666 :           return sc_lst(c[o], 0,
     764             :                 CONF_FLAG_INCEXC|CONF_FLAG_STRLIST_SORTED, "include_regex");
     765             :         case OPT_EXCREG:
     766         666 :           return sc_lst(c[o], 0,
     767             :                 CONF_FLAG_INCEXC|CONF_FLAG_STRLIST_SORTED, "exclude_regex");
     768             :         case OPT_INCLOGIC:
     769         666 :           return sc_lst(c[o], 0,
     770             :                 CONF_FLAG_INCEXC|CONF_FLAG_STRLIST_SORTED, "include_logic");
     771             :          case OPT_EXCLOGIC:
     772         666 :           return sc_lst(c[o], 0,
     773             :                 CONF_FLAG_INCEXC|CONF_FLAG_STRLIST_SORTED, "exclude_logic");
     774             :         case OPT_EXCFS:
     775         666 :           return sc_lst(c[o], 0,
     776             :                 CONF_FLAG_INCEXC|CONF_FLAG_STRLIST_SORTED, "exclude_fs");
     777             :         case OPT_INCFS:
     778         666 :           return sc_lst(c[o], 0,
     779             :                 CONF_FLAG_INCEXC|CONF_FLAG_STRLIST_SORTED, "include_fs");
     780             :         case OPT_EXCOM:
     781         666 :           return sc_lst(c[o], 0,
     782             :                 CONF_FLAG_INCEXC|CONF_FLAG_STRLIST_SORTED, "exclude_comp");
     783             :         case OPT_INCGLOB:
     784         666 :           return sc_lst(c[o], 0,
     785             :                 CONF_FLAG_INCEXC|CONF_FLAG_STRLIST_SORTED, "include_glob");
     786             :         case OPT_SEED_SRC:
     787         666 :           return sc_str(c[o], 0, 0, "seed_src");
     788             :         case OPT_SEED_DST:
     789         666 :           return sc_str(c[o], 0, 0, "seed_dst");
     790             :         case OPT_CROSS_ALL_FILESYSTEMS:
     791         666 :           return sc_int(c[o], 0, CONF_FLAG_INCEXC, "cross_all_filesystems");
     792             :         case OPT_READ_ALL_FIFOS:
     793         666 :           return sc_int(c[o], 0, CONF_FLAG_INCEXC, "read_all_fifos");
     794             :         case OPT_FIFOS:
     795         666 :           return sc_lst(c[o], 0, CONF_FLAG_INCEXC, "read_fifo");
     796             :         case OPT_READ_ALL_BLOCKDEVS:
     797         666 :           return sc_int(c[o], 0, CONF_FLAG_INCEXC, "read_all_blockdevs");
     798             :         case OPT_BLOCKDEVS:
     799         666 :           return sc_lst(c[o], 0, CONF_FLAG_INCEXC, "read_blockdev");
     800             :         case OPT_MIN_FILE_SIZE:
     801         666 :           return sc_u64(c[o], 0, CONF_FLAG_INCEXC, "min_file_size");
     802             :         case OPT_MAX_FILE_SIZE:
     803         666 :           return sc_u64(c[o], 0, CONF_FLAG_INCEXC, "max_file_size");
     804             :         case OPT_SPLIT_VSS:
     805         666 :           return sc_int(c[o], 0, CONF_FLAG_INCEXC, "split_vss");
     806             :         case OPT_STRIP_VSS:
     807         666 :           return sc_int(c[o], 0, CONF_FLAG_INCEXC, "strip_vss");
     808             :         case OPT_VSS_DRIVES:
     809         666 :           return sc_str(c[o], 0, CONF_FLAG_INCEXC, "vss_drives");
     810             :         case OPT_ACL:
     811         666 :           return sc_int(c[o], 1, CONF_FLAG_INCEXC, "acl");
     812             :         case OPT_XATTR:
     813         666 :           return sc_int(c[o], 1, CONF_FLAG_INCEXC, "xattr");
     814             :         case OPT_ATIME:
     815         666 :           return sc_int(c[o], 0, CONF_FLAG_INCEXC, "atime");
     816             :         case OPT_SCAN_PROBLEM_RAISES_ERROR:
     817         666 :           return sc_int(c[o], 0, CONF_FLAG_INCEXC, "scan_problem_raises_error");
     818             :         case OPT_OVERWRITE:
     819         666 :           return sc_int(c[o], 0,
     820             :                 CONF_FLAG_INCEXC|CONF_FLAG_INCEXC_RESTORE, "overwrite");
     821             :         case OPT_STRIP:
     822         666 :           return sc_int(c[o], 0,
     823             :                 CONF_FLAG_INCEXC|CONF_FLAG_INCEXC_RESTORE, "strip");
     824             :         case OPT_REGEX:
     825         666 :           return sc_str(c[o], 0,
     826             :                 CONF_FLAG_INCEXC|CONF_FLAG_INCEXC_RESTORE, "regex");
     827             :         case OPT_REGEX_CASE_INSENSITIVE:
     828         666 :           return sc_int(c[o], 0,
     829             :                 CONF_FLAG_INCEXC|CONF_FLAG_INCEXC_RESTORE, "regex_case_insensitive");
     830             :         case OPT_MAX:
     831             :           return 0;
     832             :         // No default, so we get compiler warnings if something was missed.
     833             :         }
     834           0 :         return -1;
     835             : }
     836             : 
     837           0 : static int set_conf(struct conf *c, const char *value)
     838             : {
     839           0 :         switch(c->conf_type)
     840             :         {
     841             :                 case CT_STRING:
     842           0 :                         if(set_string(c, value)) return 1;
     843             :                         break;
     844             :                 case CT_FLOAT:
     845           0 :                         if(set_float(c, atof(value))) return 1;
     846             :                         break;
     847             :                 case CT_E_BURP_MODE:
     848             :                 {
     849             :                         enum burp_mode bm;
     850           0 :                         bm=str_to_burp_mode(value);
     851           0 :                         if(bm==BURP_MODE_UNSET
     852           0 :                           || set_e_burp_mode(c, bm))
     853             :                                 return 1;
     854             :                         break;
     855             :                 }
     856             :                 case CT_E_RECOVERY_METHOD:
     857             :                 {
     858             :                         enum recovery_method rm;
     859           0 :                         rm=str_to_recovery_method(value);
     860           0 :                         if(rm==RECOVERY_METHOD_UNSET
     861           0 :                           || set_e_recovery_method(c, rm))
     862             :                                 return 1;
     863             :                         break;
     864             :                 }
     865             :         // FIX THIS
     866             :                 case CT_E_RSHASH:
     867             :                 case CT_UINT:
     868             :                 case CT_MODE_T:
     869             :                 case CT_SSIZE_T:
     870             :                 case CT_STRLIST:
     871             :                 case CT_CNTR:
     872             :                         break;
     873             :         }
     874             :         return 0;
     875             : }
     876             : 
     877           0 : int conf_set(struct conf **confs, const char *field, const char *value)
     878             : {
     879           0 :         int i=0;
     880           0 :         int r=0;
     881           0 :         for(i=0; i<OPT_MAX; i++)
     882             :         {
     883           0 :                 if(strcmp(confs[i]->field, field)) continue;
     884           0 :                 r+=set_conf(confs[i], value);
     885             :         }
     886           0 :         return r;
     887             : }
     888             : 
     889           0 : static char *conf_data_to_str(struct conf *conf)
     890             : {
     891           0 :         size_t l=256;
     892           0 :         char *ret=NULL;
     893           0 :         if(!conf->field || !*conf->field)
     894             :                 return NULL;
     895           0 :         if(!(ret=(char *)calloc_w(1, l, __func__))) return ret;
     896           0 :         *ret='\0';
     897           0 :         switch(conf->conf_type)
     898             :         {
     899             :                 case CT_STRING:
     900           0 :                         snprintf(ret, l, "%32s: %s\n", conf->field,
     901           0 :                                 get_string(conf)?get_string(conf):"");
     902           0 :                         break;
     903             :                 case CT_FLOAT:
     904           0 :                         snprintf(ret, l, "%32s: %g\n", conf->field,
     905           0 :                                 get_float(conf));
     906           0 :                         break;
     907             :                 case CT_E_BURP_MODE:
     908           0 :                         snprintf(ret, l, "%32s: %s\n", conf->field,
     909             :                                 burp_mode_to_str(get_e_burp_mode(conf)));
     910           0 :                         break;
     911             :                 case CT_E_RECOVERY_METHOD:
     912           0 :                         snprintf(ret, l, "%32s: %s\n", conf->field,
     913             :                                 recovery_method_to_str(
     914             :                                         get_e_recovery_method(conf)));
     915           0 :                         break;
     916             :                 case CT_E_RSHASH:
     917           0 :                         snprintf(ret, l, "%32s: %s\n", conf->field,
     918             :                                 rshash_to_str(get_e_rshash(conf)));
     919           0 :                         break;
     920             :                 case CT_UINT:
     921           0 :                         snprintf(ret, l, "%32s: %u\n", conf->field,
     922             :                                 get_int(conf));
     923           0 :                         break;
     924             :                 case CT_STRLIST:
     925             :                 {
     926           0 :                         int count=0;
     927           0 :                         char piece[256]="";
     928             :                         struct strlist *s;
     929           0 :                         for(s=get_strlist(conf); s; s=s->next)
     930             :                         {
     931           0 :                                 snprintf(piece, sizeof(piece),
     932             :                                         "%32s: %s\n", conf->field, s->path);
     933           0 :                                 if(astrcat(&ret, piece, __func__))
     934           0 :                                         return ret;
     935           0 :                                 count++;
     936             :                         }
     937           0 :                         if(!count)
     938           0 :                         snprintf(ret, l, "%32s:\n", conf->field);
     939           0 :                         break;
     940             :                 }
     941             :                 case CT_MODE_T:
     942           0 :                         snprintf(ret, l, "%32s: %o\n", conf->field,
     943             :                                 get_mode_t(conf));
     944           0 :                         break;
     945             :                 case CT_SSIZE_T:
     946           0 :                         snprintf(ret, l, "%32s: %" PRIu64 "\n", conf->field,
     947             :                                 get_uint64_t(conf));
     948           0 :                         break;
     949             :                 case CT_CNTR:
     950             :                         break;
     951             :         }
     952           0 :         return ret;
     953             : 
     954             : }
     955             : 
     956         279 : struct conf **confs_alloc(void)
     957             : {
     958         279 :         int i=0;
     959         279 :         struct conf **confs=NULL;
     960         279 :         if(!(confs=(struct conf **)
     961             :                 calloc_w(OPT_MAX, sizeof(struct conf *), __func__)))
     962             :                         return NULL;
     963       53289 :         for(i=0; i<OPT_MAX; i++)
     964             :         {
     965             :                 struct conf *c;
     966       53289 :                 if(!(c=(struct conf *)
     967             :                         calloc_w(1, sizeof(struct conf), __func__)))
     968             :                                 return NULL;
     969       53289 :                 confs[i]=c;
     970             :         }
     971             :         return confs;
     972             : };
     973             : 
     974         310 : void confs_free(struct conf ***confs)
     975             : {
     976         310 :         int i=0;
     977         310 :         if(!confs || !*confs) return;
     978         279 :         confs_free_content(*confs);
     979       53568 :         for(i=0; i<OPT_MAX; i++)
     980       53289 :                 free_v((void **)&((*confs)[i]));
     981         279 :         free_v((void **)confs);
     982         279 :         *confs=NULL;
     983             : }
     984             : 
     985         333 : int confs_init(struct conf **confs)
     986             : {
     987         333 :         int i=0;
     988       63936 :         for(i=0; i<OPT_MAX; i++)
     989       63603 :                 if(reset_conf(confs, (enum conf_opt)i))
     990             :                         return -1;
     991             :         return 0;
     992             : }
     993             : 
     994           0 : int confs_dump(struct conf **confs, int flags)
     995             : {
     996           0 :         int i=0;
     997           0 :         char *str=NULL;
     998           0 :         for(i=0; i<OPT_MAX; i++)
     999             :         {
    1000           0 :                 if(flags && !(flags & confs[i]->flags)) continue;
    1001             :         //      if(!*(confs[i]->field)) continue;
    1002           0 :                 str=conf_data_to_str(confs[i]);
    1003           0 :                 if(str && *str) printf("%s", str);
    1004           0 :                 free_w(&str);
    1005             :         }
    1006           0 :         return 0;
    1007             : }

Generated by: LCOV version 1.13