Electroneum
config_file.h File Reference

Go to the source code of this file.

Classes

struct  config_strlist_head
 
struct  config_file
 
struct  config_stub
 
struct  config_auth
 
struct  config_view
 
struct  config_strlist
 
struct  config_str2list
 
struct  config_str3list
 
struct  config_strbytelist
 
struct  config_parser_state
 

Functions

struct config_fileconfig_create (void)
 
struct config_fileconfig_create_forlib (void)
 
int config_read (struct config_file *config, const char *filename, const char *chroot)
 
void config_delete (struct config_file *config)
 
void config_apply (struct config_file *config)
 
void config_lookup_uid (struct config_file *config)
 
int config_set_option (struct config_file *config, const char *option, const char *value)
 
int config_get_option (struct config_file *cfg, const char *opt, void(*func)(char *, void *), void *arg)
 
int config_get_option_list (struct config_file *cfg, const char *opt, struct config_strlist **list)
 
int config_get_option_collate (struct config_file *cfg, const char *opt, char **str)
 
void config_print_func (char *line, void *arg)
 
void config_collate_func (char *line, void *arg)
 
char * config_collate_cat (struct config_strlist *list)
 
int cfg_strlist_append (struct config_strlist_head *list, char *item)
 
struct config_strlistcfg_strlist_find (struct config_strlist *head, const char *item)
 
int cfg_strlist_insert (struct config_strlist **head, char *item)
 
int cfg_region_strlist_insert (struct regional *region, struct config_strlist **head, char *item)
 
int cfg_str2list_insert (struct config_str2list **head, char *item, char *i2)
 
int cfg_str3list_insert (struct config_str3list **head, char *item, char *i2, char *i3)
 
int cfg_strbytelist_insert (struct config_strbytelist **head, char *item, uint8_t *i2, size_t i2len)
 
struct config_stubcfg_stub_find (struct config_stub ***pp, const char *nm)
 
void config_delstrlist (struct config_strlist *list)
 
void config_deldblstrlist (struct config_str2list *list)
 
void config_deltrplstrlist (struct config_str3list *list)
 
void config_del_strbytelist (struct config_strbytelist *list)
 
void config_delstub (struct config_stub *p)
 
void config_delstubs (struct config_stub *list)
 
void config_delauth (struct config_auth *p)
 
void config_delauths (struct config_auth *list)
 
void config_delview (struct config_view *p)
 
void config_delviews (struct config_view *list)
 
int options_remote_is_address (struct config_file *cfg)
 
time_t cfg_convert_timeval (const char *str)
 
int cfg_count_numbers (const char *str)
 
int cfg_parse_memsize (const char *str, size_t *res)
 
int config_add_tag (struct config_file *cfg, const char *tag)
 
int find_tag_id (struct config_file *cfg, const char *tag)
 
uint8_tconfig_parse_taglist (struct config_file *cfg, char *str, size_t *listlen)
 
char * config_taglist2str (struct config_file *cfg, uint8_t *taglist, size_t len)
 
int taglist_intersect (uint8_t *list1, size_t list1len, uint8_t *list2, size_t list2len)
 
int cfg_parse_local_zone (struct config_file *cfg, const char *val)
 
int cfg_mark_ports (const char *str, int allow, int *avail, int num)
 
int cfg_condense_ports (struct config_file *cfg, int **avail)
 
int cfg_scan_ports (int *avail, int num)
 
char * fname_after_chroot (const char *fname, struct config_file *cfg, int use_chdir)
 
char * cfg_ptr_reverse (char *str)
 
void errinf (struct module_qstate *qstate, const char *str)
 
void errinf_origin (struct module_qstate *qstate, struct sock_list *origin)
 
void errinf_rrset (struct module_qstate *qstate, struct ub_packed_rrset_key *rr)
 
void errinf_dname (struct module_qstate *qstate, const char *str, uint8_t *dname)
 
char * errinf_to_str (struct module_qstate *qstate)
 
void init_cfg_parse (void)
 
int ub_c_parse (void)
 
int ub_c_lex (void)
 
int ub_c_wrap (void)
 
void ub_c_error (const char *msg)
 
void ub_c_error_msg (const char *fmt,...) ATTR_FORMAT(printf
 

Variables

uid_t cfg_uid
 
gid_t cfg_gid
 
int autr_permit_small_holddown
 
struct config_parser_statecfg_parser
 
FILE * ub_c_in
 
FILE * ub_c_out
 
void int fake_dsa
 
void int fake_sha1
 

Detailed Description

This file contains functions for the config file.

Definition in file config_file.h.

Function Documentation

◆ cfg_condense_ports()

int cfg_condense_ports ( struct config_file cfg,
int **  avail 
)

Get a condensed list of ports returned. allocated.

Parameters
cfgconfig file.
availthe available ports array is returned here.
Returns
: number of ports in array or 0 on error.

◆ cfg_convert_timeval()

time_t cfg_convert_timeval ( const char *  str)

Convert 14digit to time value

Parameters
strstring of 14 digits
Returns
time value or 0 for error.

◆ cfg_count_numbers()

int cfg_count_numbers ( const char *  str)

Count number of values in the string. format ::= (sp num)+ sp num ::= [-](0-9)+ sp ::= (space|tab)*

Parameters
strstring
Returns
: 0 on parse error, or empty string, else number of integer values in the string.

◆ cfg_mark_ports()

int cfg_mark_ports ( const char *  str,
int  allow,
int *  avail,
int  num 
)

Mark "number" or "low-high" as available or not in ports array.

Parameters
strstring in input
allowgive true if this range is permitted.
availthe array from cfg.
numsize of the array (65536).
Returns
: true if parsed correctly, or 0 on a parse error (and an error is logged).

◆ cfg_parse_local_zone()

int cfg_parse_local_zone ( struct config_file cfg,
const char *  val 
)

Parse local-zone directive into two strings and register it in the config.

Parameters
cfgto put it in.
valargument strings to local-zone, "example.com nodefault".
Returns
: false on failure

◆ cfg_parse_memsize()

int cfg_parse_memsize ( const char *  str,
size_t *  res 
)

Convert a 'nice' memory or file size into a bytecount From '100k' to 102400. and so on. Understands kKmMgG. k=1024, m=1024*1024, g=1024*1024*1024.

Parameters
strstring
resresult is stored here, size in bytes.
Returns
: true if parsed correctly, or 0 on a parse error (and an error is logged).

◆ cfg_ptr_reverse()

char* cfg_ptr_reverse ( char *  str)

Convert a ptr shorthand into a full reverse-notation PTR record.

Parameters
strinput string, "IP name"
Returns
: malloced string "reversed-ip-name PTR name"

◆ cfg_region_strlist_insert()

int cfg_region_strlist_insert ( struct regional region,
struct config_strlist **  head,
char *  item 
)

insert with region for allocation.

◆ cfg_scan_ports()

int cfg_scan_ports ( int *  avail,
int  num 
)

Scan ports available

Parameters
availthe array from cfg.
numsize of the array (65536).
Returns
the number of ports available for use.

◆ cfg_str2list_insert()

int cfg_str2list_insert ( struct config_str2list **  head,
char *  item,
char *  i2 
)

Insert string into str2list.

Parameters
headpointer to str2list head variable.
itemnew item. malloced by caller. If NULL the insertion fails.
i22nd string, malloced by caller. If NULL the insertion fails.
Returns
: true on success.

◆ cfg_str3list_insert()

int cfg_str3list_insert ( struct config_str3list **  head,
char *  item,
char *  i2,
char *  i3 
)

Insert string into str3list.

Parameters
headpointer to str3list head variable.
itemnew item. malloced by caller. If NULL the insertion fails.
i22nd string, malloced by caller. If NULL the insertion fails.
i33rd string, malloced by caller. If NULL the insertion fails.
Returns
: true on success.

◆ cfg_strbytelist_insert()

int cfg_strbytelist_insert ( struct config_strbytelist **  head,
char *  item,
uint8_t i2,
size_t  i2len 
)

Insert string into strbytelist.

Parameters
headpointer to strbytelist head variable.
itemnew item. malloced by caller. If NULL the insertion fails.
i22nd string, malloced by caller. If NULL the insertion fails.
i2lenlength of the i2 bytestring.
Returns
: true on success.

◆ cfg_strlist_append()

int cfg_strlist_append ( struct config_strlist_head list,
char *  item 
)

Append text at end of list.

Parameters
listlist head. zeroed at start.
itemnew item. malloced by caller. if NULL the insertion fails.
Returns
true on success.

◆ cfg_strlist_find()

struct config_strlist* cfg_strlist_find ( struct config_strlist head,
const char *  item 
)

Find string in strlist.

Parameters
headpointer to strlist head variable.
itemthe item to search for.
Returns
: the element in the list when found, NULL otherwise.

◆ cfg_strlist_insert()

int cfg_strlist_insert ( struct config_strlist **  head,
char *  item 
)

Insert string into strlist.

Parameters
headpointer to strlist head variable.
itemnew item. malloced by caller. If NULL the insertion fails.
Returns
: true on success.

◆ cfg_stub_find()

struct config_stub* cfg_stub_find ( struct config_stub ***  pp,
const char *  nm 
)

Find stub in config list, also returns prevptr (for deletion).

Parameters
ppcall routine with pointer to a pointer to the start of the list, if the stub is found, on exit, the value contains a pointer to the next pointer that points to the found element (or to the list start pointer if it is the first element).
nmname of stub to find.
Returns
: pointer to config_stub if found, or NULL if not found.

◆ config_add_tag()

int config_add_tag ( struct config_file cfg,
const char *  tag 
)

Add a tag name to the config. It is added at the end with a new ID value.

Parameters
cfgthe config structure.
tagstring (which is copied) with the name.
Returns
: false on alloc failure.

◆ config_apply()

void config_apply ( struct config_file config)

Apply config to global constants; this routine is called in single thread.

Parameters
configto apply. Side effect: global constants change.

◆ config_collate_cat()

char* config_collate_cat ( struct config_strlist list)

take a strlist_head list and return a malloc string. separated with newline.

Parameters
liststrlist first to collate. zeroes return "".
Returns
NULL on malloc failure. Or if malloc failure happened in strlist.

◆ config_collate_func()

void config_collate_func ( char *  line,
void *  arg 
)

function to collate the text strings into a strlist_head.

Parameters
linetext to append.
argpass a strlist_head structure. zeroed on start.

◆ config_create()

struct config_file* config_create ( void  )

Create config file structure. Filled with default values.

Returns
: the new structure or NULL on memory error.

◆ config_create_forlib()

struct config_file* config_create_forlib ( void  )

Create config file structure for library use. Filled with default values.

Returns
: the new structure or NULL on memory error.

◆ config_del_strbytelist()

void config_del_strbytelist ( struct config_strbytelist list)

delete stringbytelist

◆ config_delauth()

void config_delauth ( struct config_auth p)

Delete an auth item

Parameters
pauth item

◆ config_delauths()

void config_delauths ( struct config_auth list)

Delete items in config auth list.

Parameters
listlist.

◆ config_deldblstrlist()

void config_deldblstrlist ( struct config_str2list list)

Delete items in config double string list.

Parameters
listlist.

◆ config_delete()

void config_delete ( struct config_file config)

Destroy the config file structure.

Parameters
configto delete.

◆ config_delstrlist()

void config_delstrlist ( struct config_strlist list)

Delete items in config string list.

Parameters
listlist.

◆ config_delstub()

void config_delstub ( struct config_stub p)

Delete a stub item

Parameters
pstub item

◆ config_delstubs()

void config_delstubs ( struct config_stub list)

Delete items in config stub list.

Parameters
listlist.

◆ config_deltrplstrlist()

void config_deltrplstrlist ( struct config_str3list list)

Delete items in config triple string list.

Parameters
listlist.

◆ config_delview()

void config_delview ( struct config_view p)

Delete a view item

Parameters
pview item

◆ config_delviews()

void config_delviews ( struct config_view list)

Delete items in config view list.

Parameters
listlist.

◆ config_get_option()

int config_get_option ( struct config_file cfg,
const char *  opt,
void(*)(char *, void *)  func,
void *  arg 
)

Call print routine for the given option.

Parameters
cfgconfig.
optoption name without trailing :. This is different from config_set_option.
funcprint func, called as (str, arg) for every data element.
arguser argument for print func.
Returns
false if the option name is not supported (syntax error).

◆ config_get_option_collate()

int config_get_option_collate ( struct config_file cfg,
const char *  opt,
char **  str 
)

Get an option and collate results into string

Parameters
cfgconfig file
optoption name.
strstring. malloced, caller must free it.
Returns
0=OK, 1=syntax error, 2=malloc failed.

◆ config_get_option_list()

int config_get_option_list ( struct config_file cfg,
const char *  opt,
struct config_strlist **  list 
)

Get an option and return strlist

Parameters
cfgconfig file
optoption name.
listlist is returned here. malloced, caller must free it.
Returns
0=OK, 1=syntax error, 2=malloc failed.

◆ config_lookup_uid()

void config_lookup_uid ( struct config_file config)

Find username, sets cfg_uid and cfg_gid.

Parameters
configthe config structure.

◆ config_parse_taglist()

uint8_t* config_parse_taglist ( struct config_file cfg,
char *  str,
size_t *  listlen 
)

parse taglist from string into bytestring with bitlist.

Parameters
cfgthe config structure (with tagnames)
strthe string to parse. Parse puts 0 bytes in string.
listlenreturns length of in bytes.
Returns
malloced bytes with a bitlist of the tags. or NULL on parse error or malloc failure.

◆ config_print_func()

void config_print_func ( char *  line,
void *  arg 
)

function to print to a file, use as func with config_get_option.

Parameters
linetext to print.
appended.
argpass a FILE*, like stdout.

◆ config_read()

int config_read ( struct config_file config,
const char *  filename,
const char *  chroot 
)

Read the config file from the specified filename.

Parameters
configwhere options are stored into, must be freshly created.
filenamename of configfile. If NULL nothing is done.
chrootif not NULL, the chroot dir currently in use (for include).
Returns
: false on error. In that case errno is set, ENOENT means file not found.

◆ config_set_option()

int config_set_option ( struct config_file config,
const char *  option,
const char *  value 
)

Set the given keyword to the given value.

Parameters
configwhere to store config
optionoption name, including the ':' character.
valuevalue, this string is copied if needed, or parsed. The caller owns the value string.
Returns
0 on error (malloc or syntax error).

◆ config_taglist2str()

char* config_taglist2str ( struct config_file cfg,
uint8_t taglist,
size_t  len 
)

convert tag bitlist to a malloced string with tag names. For debug output.

Parameters
cfgthe config structure (with tagnames)
taglistthe tag bitlist.
lenlength of the tag bitlist.
Returns
malloced string or NULL.

◆ errinf()

void errinf ( struct module_qstate qstate,
const char *  str 
)

Append text to the error info for validation.

Parameters
qstatequery state.
strcopied into query region and appended. Failures to allocate are logged.

◆ errinf_dname()

void errinf_dname ( struct module_qstate qstate,
const char *  str,
uint8_t dname 
)

Append text to error info: str dname

Parameters
qstatequery state.
strexplanation string
dnamethe dname.

◆ errinf_origin()

void errinf_origin ( struct module_qstate qstate,
struct sock_list origin 
)

Append text to error info: from 1.2.3.4

Parameters
qstatequery state.
originsock list with origin of trouble. Every element added. If NULL: nothing is added. if 0len element: 'from cache' is added.

◆ errinf_rrset()

void errinf_rrset ( struct module_qstate qstate,
struct ub_packed_rrset_key rr 
)

Append text to error info: for RRset name type class

Parameters
qstatequery state.
rrrrset_key.

◆ errinf_to_str()

char* errinf_to_str ( struct module_qstate qstate)

Create error info in string

Parameters
qstatequery state.
Returns
string or NULL on malloc failure (already logged). This string is malloced and has to be freed by caller.

◆ find_tag_id()

int find_tag_id ( struct config_file cfg,
const char *  tag 
)

Find tag ID in the tag list.

Parameters
cfgthe config structure.
tagstring with tag name to search for.
Returns
: 0..(num_tags-1) with tag ID, or -1 if tagname is not found.

◆ fname_after_chroot()

char* fname_after_chroot ( const char *  fname,
struct config_file cfg,
int  use_chdir 
)

Convert a filename to full pathname in original filesys

Parameters
fnamethe path name to convert. Must not be null or empty.
cfgconfig struct for chroot and chdir (if set).
use_chdirif false, only chroot is applied.
Returns
pointer to malloced buffer which is: [chroot][chdir]fname or NULL on malloc failure.

◆ init_cfg_parse()

void init_cfg_parse ( void  )

init lex state

◆ options_remote_is_address()

int options_remote_is_address ( struct config_file cfg)

check if config for remote control turns on IP-address interface with certificates or a named pipe without certificates.

◆ taglist_intersect()

int taglist_intersect ( uint8_t list1,
size_t  list1len,
uint8_t list2,
size_t  list2len 
)

see if two taglists intersect (have tags in common).

Parameters
list1first tag bitlist.
list1lenlength in bytes of first list.
list2second tag bitlist.
list2lenlength in bytes of second list.
Returns
true if there are tags in common, 0 if not.

◆ ub_c_error()

void ub_c_error ( const char *  msg)

parsing helpers: print error with file and line numbers

◆ ub_c_error_msg()

void ub_c_error_msg ( const char *  fmt,
  ... 
)

parsing helpers: print error with file and line numbers

◆ ub_c_lex()

int ub_c_lex ( void  )

the lexer function

◆ ub_c_parse()

int ub_c_parse ( void  )

the yacc lex generated parse function

◆ ub_c_wrap()

int ub_c_wrap ( void  )

wrap function

Variable Documentation

◆ autr_permit_small_holddown

int autr_permit_small_holddown

debug and enable small timeouts

◆ cfg_gid

gid_t cfg_gid

from cfg username, after daemonize setup performed

◆ cfg_parser

struct config_parser_state* cfg_parser

global config parser object used during config parsing

◆ cfg_uid

uid_t cfg_uid

from cfg username, after daemonize setup performed

◆ fake_dsa

void int fake_dsa

debug option for unit tests.

◆ fake_sha1

void int fake_sha1

◆ ub_c_in

FILE* ub_c_in

lex in file

◆ ub_c_out

FILE* ub_c_out

lex out file