TinyMUSH 3.3
TinyMUSH Server
|
Configuration functions and defaults. More...
#include "config.h"
#include "constants.h"
#include "typedefs.h"
#include "macros.h"
#include "externs.h"
#include "prototypes.h"
#include <stdbool.h>
#include <ctype.h>
#include <fcntl.h>
#include <string.h>
#include <dlfcn.h>
#include <arpa/inet.h>
#include <sys/param.h>
#include <libgen.h>
#include <unistd.h>
Functions | |
void | cf_init (void) |
Initialize mushconf to default values. More... | |
void | cf_log (dbref player, const char *primary, const char *secondary, char *cmd, const char *format,...) |
Log a configuration error. More... | |
CF_Result | cf_status_from_succfail (dbref player, char *cmd, int success, int failure) |
Return command status from succ and fail info. More... | |
CF_Result | cf_const (int *vp __attribute__((unused)), char *str __attribute__((unused)), long extra __attribute__((unused)), dbref player, char *cmd) |
Read-only integer or boolean parameter. More... | |
CF_Result | cf_int (int *vp, char *str, long extra, dbref player, char *cmd) |
Set integer parameter. More... | |
CF_Result | cf_int_factor (int *vp, char *str, long extra, dbref player, char *cmd) |
Set integer parameter that will be used as a factor (ie. cannot be set to 0) More... | |
CF_Result | cf_dbref (int *vp, char *str, long extra, dbref player, char *cmd) |
Set dbref parameter. More... | |
CF_Result | cf_module (int *vp __attribute__((unused)), char *modname, long extra __attribute__((unused)), dbref player __attribute__((unused)), char *cmd __attribute__((unused))) |
Open a loadable module. Modules are initialized later in the startup. More... | |
CF_Result | cf_bool (int *vp, char *str, long extra __attribute__((unused)), dbref player __attribute__((unused)), char *cmd __attribute__((unused))) |
Set boolean parameter. More... | |
CF_Result | cf_option (int *vp, char *str, long extra, dbref player, char *cmd) |
Select one option from many choices. More... | |
CF_Result | cf_string (int *vp, char *str, long extra, dbref player, char *cmd) |
Set string parameter. More... | |
CF_Result | cf_alias (int *vp, char *str, long extra, dbref player, char *cmd) |
define a generic hash table alias. More... | |
CF_Result | cf_infotext (int *vp __attribute__((unused)), char *str, long extra __attribute__((unused)), dbref player __attribute__((unused)), char *cmd __attribute__((unused))) |
Add an arbitrary field to INFO output. More... | |
CF_Result | cf_divert_log (int *vp, char *str, long extra, dbref player, char *cmd) |
Redirect a log type. More... | |
CF_Result | cf_modify_bits (int *vp, char *str, long extra, dbref player, char *cmd) |
set or clear bits in a flag word from a namelist. More... | |
bool | modify_xfuncs (char *fn_name, int(*fn_ptr)(dbref), EXTFUNCS **xfuncs, bool negate) |
Helper function to change xfuncs. More... | |
CF_Result | parse_ext_access (int *perms, EXTFUNCS **xperms, char *str, NAMETAB *ntab, dbref player, char *cmd) |
Parse an extended access list with module callouts. More... | |
CF_Result | cf_set_flags (int *vp, char *str, long extra __attribute__((unused)), dbref player, char *cmd) |
Clear flag word and then set from a flags htab. More... | |
CF_Result | cf_badname (int *vp __attribute__((unused)), char *str, long extra, dbref player __attribute__((unused)), char *cmd __attribute__((unused))) |
Disallow use of player name/alias. More... | |
in_addr_t | sane_inet_addr (char *str) |
Replacement for inet_addr() More... | |
CF_Result | cf_site (long **vp, char *str, long extra, dbref player, char *cmd) |
Update site information. More... | |
CF_Result | helper_cf_cf_access (CONF *tp, dbref player, int *vp, char *ap, char *cmd, long extra) |
Set write or read access on config directives kludge. More... | |
CF_Result | cf_cf_access (int *vp, char *str, long extra, dbref player, char *cmd) |
Set configuration parameter access. More... | |
CF_Result | add_helpfile (dbref player, char *confcmd, char *str, bool is_raw) |
Add a help/news-style file. Only valid during startup. More... | |
CF_Result | cf_helpfile (int *vp __attribute__((unused)), char *str, long extra __attribute__((unused)), dbref player, char *cmd) |
Add an helpfile. More... | |
CF_Result | cf_raw_helpfile (int *vp __attribute__((unused)), char *str, long extra __attribute__((unused)), dbref player, char *cmd) |
Add a raw helpfile. More... | |
CF_Result | cf_include (int *vp __attribute__((unused)), char *str, long extra __attribute__((unused)), dbref player, char *cmd) |
Read another config file. Only valid during startup. More... | |
CF_Result | helper_cf_set (char *cp, char *ap, dbref player, CONF *tp) |
Set config parameter. More... | |
CF_Result | cf_set (char *cp, char *ap, dbref player) |
Set a config directive. More... | |
void | do_admin (dbref player, dbref cause __attribute__((unused)), int extra __attribute__((unused)), char *kw, char *value) |
Command handler to set config params at runtime. More... | |
CF_Result | cf_read (char *fn) |
Read in config parameters from named file. More... | |
void | list_cf_access (dbref player) |
List write or read access to config directives. More... | |
void | list_cf_read_access (dbref player) |
List read access to config directives. More... | |
void | cf_verify (void) |
Walk all configuration tables and validate any dbref values. More... | |
void | helper_cf_display (dbref player, char *buff, char **bufc, CONF *tp) |
Helper function for cf_display. More... | |
void | cf_display (dbref player, char *param_name, char *buff, char **bufc) |
Given a config parameter by name, return its value in some sane fashion. More... | |
void | list_options (dbref player) |
List options to player. More... | |
void * | dlopen_format (const char *filename,...) |
Wrapper around lt_dlopen that can format filename. More... | |
void * | dlsym_format (void *place, const char *symbol,...) |
Wrapper for lt_dlsym that format symbol string. More... | |
Variables | |
CONFDATA | mushconf |
STATEDATA | mushstate |
int(* | cf_interpreter )(int *, char *, long, dbref, char *) |
Configuration functions and defaults.
CF_Result add_helpfile | ( | dbref | player, |
char * | confcmd, | ||
char * | str, | ||
bool | is_raw | ||
) |
Add a help/news-style file. Only valid during startup.
player | Dbref of player |
confcmd | Command |
str | Filename |
is_raw | Raw textfile? |
Make a new string so we won't SEGV if given a constant string
Check if file exists in given and standard path
Rebuild Index
We may need to grow the helpfiles table, or create it.
Add or replace the path to the file.
Initialize the associated hashtable.
CF_Result cf_alias | ( | int * | vp, |
char * | str, | ||
long | extra, | ||
dbref | player, | ||
char * | cmd | ||
) |
define a generic hash table alias.
vp | |
str | |
extra | |
player | |
cmd |
hashadd won't copy it, so we do that here
CF_Result cf_badname | ( | int *vp | __attribute__(unused), |
char * | str, | ||
long | extra, | ||
dbref player | __attribute__(unused), | ||
char *cmd | __attribute__(unused) | ||
) |
Disallow use of player name/alias.
vp | Variable buffer |
str | String Buffer |
extra | Name Table |
player | DBref of player |
cmd | Command |
CF_Result cf_bool | ( | int * | vp, |
char * | str, | ||
long extra | __attribute__(unused), | ||
dbref player | __attribute__(unused), | ||
char *cmd | __attribute__(unused) | ||
) |
Set boolean parameter.
vp | Boolean value |
str | String buffer |
extra | Not used |
player | DBref of the player |
cmd | Command |
CF_Result cf_cf_access | ( | int * | vp, |
char * | str, | ||
long | extra, | ||
dbref | player, | ||
char * | cmd | ||
) |
Set configuration parameter access.
vp | Variable buffer |
str | String Buffer |
extra | Name Table |
player | DBref of player |
cmd | Command |
CF_Result cf_const | ( | int *vp | __attribute__(unused), |
char *str | __attribute__(unused), | ||
long extra | __attribute__(unused), | ||
dbref | player, | ||
char * | cmd | ||
) |
Read-only integer or boolean parameter.
vp | Not used |
str | Not used |
extra | Not used |
player | Dbref of the player |
cmd | Command |
Fail on any attempt to change the value
CF_Result cf_dbref | ( | int * | vp, |
char * | str, | ||
long | extra, | ||
dbref | player, | ||
char * | cmd | ||
) |
Set dbref parameter.
vp | Numeric value |
str | String buffer |
extra | Maximum limit |
player | DBref of the player |
cmd | Command |
No consistency check on initialization.
Otherwise we have to validate this. If 'extra' is non-zero, the dbref is allowed to be NOTHING.
void cf_display | ( | dbref | player, |
char * | param_name, | ||
char * | buff, | ||
char ** | bufc | ||
) |
Given a config parameter by name, return its value in some sane fashion.
player | DBref of player |
param_name | Parameter name |
buff | Output buffer |
bufc | Output buffer tracker |
CF_Result cf_divert_log | ( | int * | vp, |
char * | str, | ||
long | extra, | ||
dbref | player, | ||
char * | cmd | ||
) |
Redirect a log type.
vp | Variable buffer |
str | String Buffer |
extra | Name Table |
player | DBref of player |
cmd | Command |
Two args, two args only
Find the log.
This should never happen!
We shouldn't have a file open already.
Check to make sure that we don't have this filename open already.
We don't have this filename yet. Open the logfile.
Indicate that this is being diverted.
CF_Result cf_helpfile | ( | int *vp | __attribute__(unused), |
char * | str, | ||
long extra | __attribute__(unused), | ||
dbref | player, | ||
char * | cmd | ||
) |
Add an helpfile.
player | Dbref of player |
confcmd | Command |
str | Filename |
is_raw | Raw textfile? |
CF_Result cf_include | ( | int *vp | __attribute__(unused), |
char * | str, | ||
long extra | __attribute__(unused), | ||
dbref | player, | ||
char * | cmd | ||
) |
Read another config file. Only valid during startup.
vp | Variable buffer |
str | String buffer |
extra | Extra data |
player | DBref of player |
cmd | Command |
**cfiletab; // Array of config files cfiletab_size; // Size of the table storing config pointers
Not a comment line. Strip off the NL and any characters following it. Then, split the line into the command and argument portions (separated by a space). Also, trim off the trailing comment, if any (delimited by #)
strip
strip spaces
skip over command
trim command
skip spaces
find comment
zap comment, but only if it's not sitting between whitespace and a digit, which traps a case like 'master_room #2'
zap trailing spaces
CF_Result cf_infotext | ( | int *vp | __attribute__(unused), |
char * | str, | ||
long extra | __attribute__(unused), | ||
dbref player | __attribute__(unused), | ||
char *cmd | __attribute__(unused) | ||
) |
Add an arbitrary field to INFO output.
vp | Variable buffer |
str | String Buffer |
extra | Not used |
player | DBref of player |
cmd | Command |
Empty loop
Otherwise we're setting. Replace if we had a previous value.
No previous value. Add a node.
void cf_init | ( | void | ) |
Initialize mushconf to default values.
We can make theses NULL because we are going to define default values later if they are still NULL.
< ??? Running SC on a non-SC DB may cause problems
CF_Result cf_int | ( | int * | vp, |
char * | str, | ||
long | extra, | ||
dbref | player, | ||
char * | cmd | ||
) |
Set integer parameter.
vp | Numeric value |
str | String buffer |
extra | Maximum limit |
player | DBref of the player |
cmd | Command |
Copy the numeric value to the parameter
CF_Result cf_int_factor | ( | int * | vp, |
char * | str, | ||
long | extra, | ||
dbref | player, | ||
char * | cmd | ||
) |
Set integer parameter that will be used as a factor (ie. cannot be set to 0)
vp | Numeric value |
str | String buffer |
extra | Maximum limit |
player | DBref of the player |
cmd | Command |
void cf_log | ( | dbref | player, |
const char * | primary, | ||
const char * | secondary, | ||
char * | cmd, | ||
const char * | format, | ||
... | |||
) |
Log a configuration error.
player | DBref of player |
primary | Primary error type |
secondary | Secondary error type |
cmd | Command |
format | Format string |
... | Variable parameter for format |
CF_Result cf_modify_bits | ( | int * | vp, |
char * | str, | ||
long | extra, | ||
dbref | player, | ||
char * | cmd | ||
) |
set or clear bits in a flag word from a namelist.
vp | Variable buffer |
str | String Buffer |
extra | Name Table |
player | DBref of player |
cmd | Command |
Walk through the tokens
Check for negation
Set or clear the appropriate bit
Get the next token
CF_Result cf_module | ( | int *vp | __attribute__(unused), |
char * | modname, | ||
long extra | __attribute__(unused), | ||
dbref player | __attribute__(unused), | ||
char *cmd | __attribute__(unused) | ||
) |
Open a loadable module. Modules are initialized later in the startup.
vp | |
modname | |
extra | |
player | |
cmd |
Look up our symbols now, and cache the pointers. They're not going to change from here on out.
CF_Result cf_option | ( | int * | vp, |
char * | str, | ||
long | extra, | ||
dbref | player, | ||
char * | cmd | ||
) |
Select one option from many choices.
vp | Index of the option |
str | String buffer |
extra | Name Table |
player | DBref of the player |
cmd | Command |
CF_Result cf_raw_helpfile | ( | int *vp | __attribute__(unused), |
char * | str, | ||
long extra | __attribute__(unused), | ||
dbref | player, | ||
char * | cmd | ||
) |
Add a raw helpfile.
player | Dbref of player |
confcmd | Command |
str | Filename |
is_raw | Raw textfile? |
CF_Result cf_read | ( | char * | fn | ) |
Read in config parameters from named file.
fn | Filename |
CF_Result cf_set | ( | char * | cp, |
char * | ap, | ||
dbref | player | ||
) |
Set a config directive.
cp | |
ap | |
player |
Search the config parameter table for the command. If we find it, call the handler to parse the argument. Make sure that if we're standalone, the paramaters we need to load module flatfiles are loaded
Config directive not found. Complain about it.
CF_Result cf_set_flags | ( | int * | vp, |
char * | str, | ||
long extra | __attribute__(unused), | ||
dbref | player, | ||
char * | cmd | ||
) |
Clear flag word and then set from a flags htab.
vp | Variable buffer |
str | String Buffer |
extra | Name Table |
player | DBref of player |
cmd | Command |
Walk through the tokens
Set the appropriate bit
Get the next token
CF_Result cf_site | ( | long ** | vp, |
char * | str, | ||
long | extra, | ||
dbref | player, | ||
char * | cmd | ||
) |
Update site information.
vp | Variable buffer |
str | String Buffer |
extra | Name Table |
player | DBref of player |
cmd | Command |
Standard IP range and netmask notation.
RFC 1517, 1518, 1519, 1520: CIDR IP prefix notation
can't shift by 32
Parse the access entry and allocate space for it
Initialize the site entry
Link in the entry. Link it at the start if not initializing, at the end if initializing. This is so that entries in the config file are processed as you would think they would be, while entries made while running are processed first.
CF_Result cf_status_from_succfail | ( | dbref | player, |
char * | cmd, | ||
int | success, | ||
int | failure | ||
) |
Return command status from succ and fail info.
player | DBref of player |
cmd | Command |
success | Dit it success? |
failure | Did it fail? |
If any successes, return SUCCESS(0) if no failures or PARTIAL_SUCCESS(1) if any failures.
No successes. If no failures indicate nothing done. Always return FAILURE(-1)
CF_Result cf_string | ( | int * | vp, |
char * | str, | ||
long | extra, | ||
dbref | player, | ||
char * | cmd | ||
) |
Set string parameter.
vp | Variable type |
str | String buffer |
extra | Maximum string length |
player | DBref of player |
cmd | Command |
Make a copy of the string if it is not too big
void cf_verify | ( | void | ) |
Walk all configuration tables and validate any dbref values.
void * dlopen_format | ( | const char * | filename, |
... | |||
) |
Wrapper around lt_dlopen that can format filename.
filename | filename to load (or construct if a format string is given) |
... | arguments for the format string |
void * dlsym_format | ( | void * | place, |
const char * | symbol, | ||
... | |||
) |
Wrapper for lt_dlsym that format symbol string.
place | Module handler |
symbol | Symbol to load (or construct if a format string is given) |
... | arguments for the format string |
void do_admin | ( | dbref | player, |
dbref cause | __attribute__(unused), | ||
int extra | __attribute__(unused), | ||
char * | kw, | ||
char * | value | ||
) |
Command handler to set config params at runtime.
player | DBref of player |
cause | DBref of cause |
extra | Extra data |
kw | Keyword |
value | Value |
CF_Result helper_cf_cf_access | ( | CONF * | tp, |
dbref | player, | ||
int * | vp, | ||
char * | ap, | ||
char * | cmd, | ||
long | extra | ||
) |
Set write or read access on config directives kludge.
this cf handler uses vp as an extra extra field since the first extra field is taken up with the access nametab.
tp | Config Parameter |
player | DBrief of player |
vp | Extra field |
ap | String buffer |
cmd | Command |
extra | Extra field |
Cannot modify parameters set STATIC
void helper_cf_display | ( | dbref | player, |
char * | buff, | ||
char ** | bufc, | ||
CONF * | tp | ||
) |
Helper function for cf_display.
player | DBref of player |
buff | Output buffer |
bufc | Output buffer tracker |
tp | Config parameter |
Set config parameter.
cp | |
ap | |
player | |
tp |
void list_cf_access | ( | dbref | player | ) |
List write or read access to config directives.
player | DBref of player |
void list_cf_read_access | ( | dbref | player | ) |
List read access to config directives.
player | DBref of player |
void list_options | ( | dbref | player | ) |
List options to player.
player | DBref of player |
bool modify_xfuncs | ( | char * | fn_name, |
int(*)(dbref) | fn_ptr, | ||
EXTFUNCS ** | xfuncs, | ||
bool | negate | ||
) |
Helper function to change xfuncs.
fn_name | Function name |
fn_ptr | Function pointer |
xfuncs | External functions |
negate | true: remove, false add: |
If we're negating, just remove it from the list of functions.
Have we encountered this function before?
If not, we need to allocate it.
Add it to the ones we know about.
Do we have an existing list of functions? If not, this is easy.
See if we have an empty slot to insert into.
Guess not. Tack it onto the end.
CF_Result parse_ext_access | ( | int * | perms, |
EXTFUNCS ** | xperms, | ||
char * | str, | ||
NAMETAB * | ntab, | ||
dbref | player, | ||
char * | cmd | ||
) |
Parse an extended access list with module callouts.
perms | Permissions |
xperms | Extendes permissions |
str | String buffer |
ntab | Name Table |
player | DBref of player |
cmd | Command |
Walk through the tokens
Check for negation
Set or clear the appropriate bit
Is this a module callout?
Split it apart, see if we have anything.
Get the next token
in_addr_t sane_inet_addr | ( | char * | str | ) |
Replacement for inet_addr()
inet_addr() does not necessarily do reasonable checking for sane syntax. On certain operating systems, if passed less than four octets, it will cause a segmentation violation. This is unfriendly. We take steps here to deal with it.
str | IP Address |