v4.0.1-rc7 - reimplement some functions

This commit is contained in:
2024-12-05 17:41:44 -05:00
parent 4883c6ee08
commit 7d495ec7b6
6 changed files with 350 additions and 44 deletions

View File

@@ -22,16 +22,25 @@
* init_config
* DESCRIPTION: Init_config initializes the libconfig library, so it can read the required runtime files
* PARAMETERS:
* None.
* None. (void)
* RETURN VAUES:
* 0 on success, 1 on failure
* 0 on success, EXIT_FAILURE on failure
* CAVEATS:
* None.
* EXAMPLE:
* init_config();
* // It is best practice to check for ALL non-zero return values, rather than specific ones,
* // as init_config() returns EXIT_FAILURE
*
* if (init_config() != 0) {
* errlog("Failed to initialize libconfig");
* return(EXIT_FAILURE); // fatal error requiring termination of program execution
* }
* else {
* successlog("Initialized libconfig"); // output automatically if LG_VERBOSE = 1
* }
*/
int init_config();
int init_config(void);
/**************************************************************************************************************/
@@ -39,16 +48,19 @@ int init_config();
* die_config
* DESCRPTION: Die_config destroys the loaded libconfig library.
* PARAMETERS:
* None.
* None. (void)
* RETURN VALUES:
* 0 on success, 1 on failure
* EXIT_SUCCESS on success
* CAVEATS:
* None.
* EXAMPLE:
* // die_config() is unlikely to fail unless you tried to destroy an invalid object,
* // so checking for non-zero return values is unnecessary
*
* die_config();
*/
int die_config();
int die_config(void);
/**************************************************************************************************************/
@@ -56,7 +68,7 @@ int die_config();
* load_all_from_config
* DESCRIPTION: Initialize all settings from glacier.cfg.
* PARAMETERS:
* None.
* None. (void)
* RETURN VALUES:
* 0 on success, 1 on file does not exist, 2 on library error
* CAVEATS:

View File

@@ -72,4 +72,85 @@ void add_child(struct node *parent, struct node *child);
void print_tree(struct node *root, int level);
/**************************************************************************************************************/
/*
* init_queue
*
* DESCRIPTION: Init_queue initializes a queue data structue.
* PARAMETERS:
* queue *q -> The name of the queue to initialize
* RETURN VALUES:
* None.
* CAVEATS:
* None.
* EXAMPLE:
* init_queue("operation_queue");
*/
void init_queue(queue *q);
/**************************************************************************************************************/
/*
* queue_is_empty
*
* DESCRIPTION: Queue_is_empty checks if queue *q is empty
* PARAMETERS:
* queue *q -> The queue to check
* RETURN VALUES:
* true on empty, false on not empty
* CAVEATS:
* None.
* EXAMPLE:
* if (queue_is_empty(q)) {
* printf("Queue is empty\n");
* return;
* }
*/
bool queue_is_empty(queue *q);
/**************************************************************************************************************/
/*
* queue_is_full
*
* DESCRIPTION: Queue_is_full checks if queue *q is full
* PARAMETERS:
* queue *q -> The queue to check
* RETURN VALUES:
* true on full, false on not full
* CAVEATS:
* None.
* EXAMPLE:
* if (queue_is_full(q)) {
* printf("Queue is full\n");
* return;
* }
*/
bool queue_is_full(queue *q);
/**************************************************************************************************************/
/*
* enqueue
*
* DESCRIPTION: Enqueue enqueues an element at the back of the queue
* PARAMETERS:
* queue *q -> The queue to enqueue to
* int value ->
* RETURN VALUES:
* true on full, false on not full
* CAVEATS:
* None.
* EXAMPLE:
* if (queue_is_full(q)) {
* printf("Queue is full\n");
* return;
* }
*/
#endif

View File

@@ -23,31 +23,47 @@
*
* DESCRIPTION: runtime_exists checks if all necessary runtime files exist.
* PARAMETERS:
* None.
* None. (void)
* RETURN VALUES:
* None.
* 0 on one or more runtime files missing, 1 on all runtime files exist
* CAVEATS:
* None.
* EXAMPLE:
* runtime_exists();
* if (runtime_exists() == 0) {
* errlog("One or more runtime files missing");
* return 1;
* }
* else {
* successlog("All runtime files present");
* return 0;
* }
*/
void runtime_exists();
int runtime_exists(void);
/*
* is_process_root
*
* DESCRIPTION: is_process_root checks if the process is running with root privileges.
* PARAMETERS:
* None.
* None. (void)
* RETURN VALUES:
* 0 on root, 1 on non-root
* 0 on process is not running as root, 1 on process is running as root
* CAVEATS:
* None.
* EXAMPLE:
* is_process_root();
* // Assuming block is running within main(), no values will be returned.
* // If you wish to exit the program if it is not running as root, it would
* // be appropriate to add return values to this block
*
* if (is_process_root() == 0) {
* errlog("Process is not running as root");
* }
* else {
* successlog("Process is running as root");
* }
*/
int is_process_root();
int is_process_root(void);
#endif

View File

@@ -0,0 +1,38 @@
/*
* glacier_runtime.h - Runtime function declarations for libglacier
*
* This file is part of Glacier.
*
* Glacier is free software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* Glacier is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Glacier. If
* not, see <https://www.gnu.org/licenses/>.
*/
#ifndef GLACIERSECURITY_H_
#define GLACIERSECURITY_H_
/*
* compare_file_hash
*
* DESCRIPTION: compare_file_hash compares the SHA256 hashes of a file and its original hash
* PARAMETERS:
* char ORIG_HASH[] -> The file containing the expected hash result
* char FILE[] -> The file to compare against ORIG_HASH[]
* RETURN VALUES:
* 0 on hashes match, 1 on hashes do not match, -1 on library error
* CAVEATS:
* None.
* EXAMPLE:
* compare_file_hash("pkg.sha256sum", "pkg.tar.xz");
*/
int compare_file_hash(char ORIG_HASH[], char FILE[]);
#endif