Always declare $config global in case a script is included in a non-global scope
$config is expected to always be a global containing the parsed configuration, however in the sources that it is assigned a value in toplevel scope it is not explicitly declared as such. As a result, if one of these sources is included in function scope the assignment will only apply to a local $config in that scope, leaving the global $config untouched. This can result in the global $config being null or not current with the on disk configuration. The most obvious occurrence of this results in a thrown error with a backtrace leading to one of the array_*_path() functions in util.inc indicating the expected array parameter is null.
An example of how this historically happened was in guiconfig.inc, which includes csrf_error.php within the scope of the function pfSense_csrf_callback(), which then includes config.gui.inc, which assigns the return value of parse_config() to $config at toplevel scope, which in this particular stack is the function level scope of pfSense_csrf_callback(). When $config is declared global elsewhere, it does not bind to this local variable and is null.
To resolve this problem, every source that assigns a value to $config is changed in this commit to declare it global. For scripts that are not included in a scope, there is no obvious effect of this other than for $config to be promoted to the $GLOBALS array sooner rather than later, and ensures that if a script is included in the scope of a function that a scope level binding isn't made.
Always declare $config global in case a script is included in a non-global scope
$config is expected to always be a global containing the parsed configuration,
however in the sources that it is assigned a value in toplevel scope it is not
explicitly declared as such. As a result, if one of these sources is included in
function scope the assignment will only apply to a local $config in that scope,
leaving the global $config untouched. This can result in the global $config
being null or not current with the on disk configuration. The most obvious
occurrence of this results in a thrown error with a backtrace leading to one of
the array_*_path() functions in util.inc indicating the expected array parameter
is null.
An example of how this historically happened was in guiconfig.inc, which
includes csrf_error.php within the scope of the function
pfSense_csrf_callback(), which then includes config.gui.inc, which assigns the
return value of parse_config() to $config at toplevel scope, which in this
particular stack is the function level scope of pfSense_csrf_callback(). When
$config is declared global elsewhere, it does not bind to this local variable
and is null.
To resolve this problem, every source that assigns a value to $config is changed
in this commit to declare it global. For scripts that are not included in a
scope, there is no obvious effect of this other than for $config to be promoted
to the $GLOBALS array sooner rather than later, and ensures that if a script is
included in the scope of a function that a scope level binding isn't made.