Macros | |
#define | PRINT_ERROR(s) { print_error(MAIN_ERR_PREFIX s); } |
Prepend module prefix and print error message. | |
#define | MAIN_ERR_PREFIX "MAIN: " |
Message prefix for MAIN module. | |
#define | SECURE_CL_PERM (posix_mode_t) (POSIX_S_IRUSR | POSIX_S_IWUSR) |
Permissions for Cancel-Lock secret file. | |
#define | SECURE_CL_SECSIZE (size_t) 64 |
Size of secret (64 octets is sufficient for the SHA2 family) | |
#define | MAIN_ERR_PREFIX "MAIN: " |
Message prefix for security related functions. | |
#define | MAIN_ERR_PREFIX "MAIN: " |
Message prefix for MAIN module. | |
#define | MAIN_ERR_PREFIX "MAIN: " |
Message prefix for MAIN module. | |
Functions | |
int | ts_lock_ui (void) |
Lock UI thread. More... | |
int | ts_unlock_ui (void) |
Unlock UI thread. More... | |
void | print_error (const char *msg) |
Print error message. More... | |
int | main (int argc, char **argv) |
Program entry point. More... | |
void | secure_clear_memory (char *p, size_t len) |
Remove string from memory. More... | |
void | secure_clear_string (char *p) |
Remove string from memory. More... | |
void | secure_cl_secret (const char *pathname) |
Generate file with new secret if CL secret file is missing. More... | |
int | sighandler_install (void) |
Install signal handlers. More... | |
int | sighandler_exec_prepare (void) |
Prepare for exec() More... | |
int | sighandler_check_abort (void) |
Check abort flag. More... | |
void | ts_environ_init (void) |
Copy environment variables. More... | |
void | ts_environ_exit (void) |
Destroy copy of environment variables. More... | |
int | ts_getenv (const char *name, const char **buf) |
Thread safe replacement for getenv() More... | |
Variables | |
const char | BDATE [] |
int | main_debug = 0 |
Enable additional debug output if nonzero. | |
const char * | main_confprefix = NULL |
Configuration directory path from command line option or NULL otherwise. | |
The POSIX getenv()
function is not required to be thread safe. Therefore we must provide our own. It was considered to clone the getenv_r() function from BSD, but this function has no buffer management and is inconvenient to use. The function ts_getenv()
dynamically allocate or resize the thread local buffer internally.
ts_getenv()
. ts_environ_init()
and ts_environ_exit()
must be called to create and destroy this copy of the enviroment. int main | ( | int | argc, |
char ** | argv | ||
) |
Program entry point.
[in] | argc | Number of command line arguments |
[in] | argv | Array containing command line argument strings |
Parse command line and control startup and shutdown
EXIT_SUCCESS
on successEXIT_FAILURE
on error Definition at line 315 of file main.cxx.
References log_delete_logfile(), sighandler_install(), and ts_environ_init().
void print_error | ( | const char * | msg | ) |
Print error message.
Exported as C style function
[in] | msg | String (Unicode error message) |
This function executes as NOP if msg is NULL . Otherwise msg must be a NUL-terminated string.
The Unicode encoding of msg is checked and is allowed to be invalid.
void secure_cl_secret | ( | const char * | pathname | ) |
Generate file with new secret if CL secret file is missing.
[in] | pathname | Pathname string of CL secret file |
If pathname is NULL
no operation is excecuted.
Definition at line 138 of file secure.c.
References fu_check_file(), fu_close_file(), fu_open_file(), fu_unlink_file(), fu_write_to_filedesc(), MAIN_ERR_PREFIX, PRINT_ERROR, SECURE_CL_PERM, SECURE_CL_SECSIZE, and secure_clear_memory().
Referenced by core_get_cancel_key().
void secure_clear_memory | ( | char * | p, |
size_t | len | ||
) |
Remove string from memory.
[in] | p | Pointer to memory block |
[in] | len | Number of bytes to clear |
This function overwrites len bytes starting at location p with undefined data.
Definition at line 72 of file secure.c.
Referenced by core_get_cancel_key(), secure_cl_secret(), and secure_clear_string().
void secure_clear_string | ( | char * | p | ) |
Remove string from memory.
[in] | p | Pointer to string |
NUL
terminated string.The complete string is overwritten and then NUL
is written to the first byte. The function therefore returns with p pointing to an empty string.
Definition at line 116 of file secure.c.
References secure_clear_memory().
Referenced by conf_string_replace().
int sighandler_check_abort | ( | void | ) |
Check abort flag.
Definition at line 155 of file sighandler.c.
int sighandler_exec_prepare | ( | void | ) |
Prepare for exec()
Restore default state for ignored signals.
Definition at line 119 of file sighandler.c.
References PRINT_ERROR.
Referenced by ext_editor(), ext_inews(), and ext_pp_filter().
int sighandler_install | ( | void | ) |
Install signal handlers.
Ignored signals: SIGHUP, SIGPIPE
Signals that trigger save exit: SIGTERM, SIGQUIT, SIGINT
Definition at line 66 of file sighandler.c.
Referenced by main().
void ts_environ_exit | ( | void | ) |
Destroy copy of environment variables.
Call this function once after last use of ts_getenv()
.
Definition at line 107 of file ts_functions.c.
void ts_environ_init | ( | void | ) |
Copy environment variables.
Must be called once before ts_getenv()
is used and before additional threads are created.
Definition at line 58 of file ts_functions.c.
Referenced by main().
int ts_getenv | ( | const char * | name, |
const char ** | buf | ||
) |
Thread safe replacement for getenv()
[in] | name | Name of the requested environment variable |
[in,out] | buf | Pointer to pointer to buffer for result |
Dereferenced buf must be either NULL
or an existing dynamically allocated buffer that can be resized with realloc()
if required.
The buffer pointed to by buf is created or resized so that it can hold the result and the value of the environment variable name is copied to it.
The caller is responsible to free the memory allocated for the buffer on success.
Definition at line 136 of file ts_functions.c.
Referenced by core_get_homedir(), core_get_signature(), and xdg_get_confdir().
int ts_lock_ui | ( | void | ) |
Lock UI thread.
Exported as C style function
Definition at line 217 of file main.cxx.
References core_check_thread_ui(), and ui_lock().
int ts_unlock_ui | ( | void | ) |
Unlock UI thread.
Exported as C style function
Definition at line 244 of file main.cxx.
References core_check_thread_ui(), and ui_unlock().