summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2009-09-04 00:48:52 +0200
committerDavid Sommerseth <dazo@users.sourceforge.net>2009-09-04 00:48:52 +0200
commitda402ffcbe7e9a616bab83739b7294ce9f5e79c4 (patch)
tree8e85cd3f72a1cfa5b1600461b687917423eb2c9d
parent2dcc5b5da4291e0cb4fb9fce6134dc836e92c344 (diff)
downloadeurephia-da402ffcbe7e9a616bab83739b7294ce9f5e79c4.tar.gz
eurephia-da402ffcbe7e9a616bab83739b7294ce9f5e79c4.tar.xz
eurephia-da402ffcbe7e9a616bab83739b7294ce9f5e79c4.zip
Added doxygen comments for the main eurephiadm parts
-rw-r--r--eurephiadm/argparser.c43
-rw-r--r--eurephiadm/argparser.h33
-rw-r--r--eurephiadm/client_config.c39
-rw-r--r--eurephiadm/client_config.h9
-rw-r--r--eurephiadm/client_context.c26
-rw-r--r--eurephiadm/client_context.h9
-rw-r--r--eurephiadm/client_session.c52
-rw-r--r--eurephiadm/client_session.h9
-rw-r--r--eurephiadm/commands.h46
-rw-r--r--eurephiadm/eurephiadm.c104
-rw-r--r--eurephiadm/field_print.h22
-rw-r--r--eurephiadm/get_console_input.c23
-rw-r--r--eurephiadm/get_console_input.h9
-rw-r--r--eurephiadm/parse_certificate_files.c31
-rw-r--r--eurephiadm/parse_certificate_files.h26
-rw-r--r--eurephiadm/xsltparser.c22
-rw-r--r--eurephiadm/xsltparser.h8
17 files changed, 473 insertions, 38 deletions
diff --git a/eurephiadm/argparser.c b/eurephiadm/argparser.c
index 5f0be4e..33dc7ec 100644
--- a/eurephiadm/argparser.c
+++ b/eurephiadm/argparser.c
@@ -19,6 +19,15 @@
*
*/
+/**
+ * @file argparser.c
+ * @author David Sommerseth <dazo@users.sourceforge.net>
+ * @date 2008-12-04
+ *
+ * @brief A simple argument parser, inspired by getopt.
+ *
+ */
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -26,8 +35,21 @@
#define ARGPARSER_C
#include "argparser.h"
-char *optargs[MAX_ARGUMENTS];
+char *optargs[MAX_ARGUMENTS]; /**< If an argument takes parameters, they will be put into this array */
+
+/**
+ * Internal argument parser. Normally called via the eurephia_getopt(...) macro. Parses an
+ * argument and prepares the char **optargs array with parameters to the arguments.
+ *
+ * @param module string (const char *) containing a descriptive module name, used in error situations.
+ * @param curarg pointer to the argument index counter which gets updated during parsing.
+ * @param argc Input argument counter
+ * @param argv Input argument array (char **)
+ * @param argopts e_options struct array containing valid argument
+ *
+ * @return returns the short arg value on success, or -1 on failure.
+ */
int _eurephia_getopt(const char *module, int *curarg, int argc, char **argv, e_options *argopts) {
int i = 0;
char *arg = argv[*curarg];
@@ -58,11 +80,20 @@ int _eurephia_getopt(const char *module, int *curarg, int argc, char **argv, e_o
}
-// This function will take (argc,argv) and copy pointers over to (**outargv), starting from
-// the index given in stidx (start index). The outargv array must have been allocated first
-// by calloc(sizeof(char *), elmnts). The outsize must not exceed the number of elements you
-// have allocated space for. The function returns number of elements copied (the new argc, kind of)
-//
+/**
+ * This function will take (argc,argv) and copy pointers over to (**outargv), starting from
+ * the index given in stidx (start index). The outargv array must have been allocated first
+ * by calloc(sizeof(char *), elmnts). The outsize must not exceed the number of elements you
+ * have allocated space for. The function returns number of elements copied (the new argc, kind of)
+ *
+ * @param stidx start index of where to start the copy
+ * @param inargc input argument counter (size of the input array)
+ * @param inargv input argument array (char **)
+ * @param outargv pointer to an array of where to put the values being copied.
+ * @param outsize Size of the output array.
+ *
+ * @return Returns number of argument copied over to the output array.
+ */
size_t eurephia_arraycp(int stidx, int inargc, char **inargv, char **outargv, size_t outsize) {
int i, outargc;
diff --git a/eurephiadm/argparser.h b/eurephiadm/argparser.h
index ceef749..76c8d0b 100644
--- a/eurephiadm/argparser.h
+++ b/eurephiadm/argparser.h
@@ -19,6 +19,15 @@
*
*/
+/**
+ * @file argparser.h
+ * @author David Sommerseth <dazo@users.sourceforge.net>
+ * @date 2008-12-04
+ *
+ * @brief A simple argument parser, inspired by getopt.
+ *
+ */
+
#ifndef EUREPHIA__ARGPARSE_H
#define EUREPHIA__ARGPARSE_H
@@ -28,17 +37,29 @@
# endif
#endif
-#define MAX_ARGUMENTS 64
+#define MAX_ARGUMENTS 64 /**< Defines the maximum arguments the parsers handles */
typedef struct {
- char *longarg;
- char *shortarg;
- int param;
-} e_options;
+ char *longarg; /**< char* containing the valid long argument */
+ char *shortarg; /**< char* containing the short argument */
+ int param; /**< int containing the number of parameters this argument takes */
+} e_options; /**< The long and short arguments must contain the leading '-' character(s) */
-extern char *optargs[MAX_ARGUMENTS];
+extern char *optargs[MAX_ARGUMENTS]; /**< Contains the parameters of an argument, if param > 0 */
int _eurephia_getopt(const char *module, int *curarg, int argc, char **argv, e_options *argopts);
+/**
+ * Parses an argument and prepares the char **optargs array with parameters to the arguments.
+ * Macro for the internal _eurephia_getopt(), which automatically sets the const char *module
+ * parameter.
+ *
+ * @param ca pointer to the argument index counter which gets updated during parsing.
+ * @param ac Input argument counter
+ * @param av Input argument array (char **)
+ * @param opts e_options struct array containing valid argument
+ *
+ * @return returns the short arg value on success, or -1 on failure.
+ */
#define eurephia_getopt(ca, ac, av, opts) _eurephia_getopt(MODULE, ca, ac, av, opts)
size_t eurephia_arraycp(int stidx, int inargc, char **inargv, char **outargv, size_t outsize);
diff --git a/eurephiadm/client_config.c b/eurephiadm/client_config.c
index bbbe420..011de7c 100644
--- a/eurephiadm/client_config.c
+++ b/eurephiadm/client_config.c
@@ -19,6 +19,15 @@
*
*/
+/**
+ * @file client_config.c
+ * @author David Sommerseth <dazo@users.sourceforge.net>
+ * @date 2008-12-01
+ *
+ * @brief Config file parser
+ *
+ */
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -28,7 +37,15 @@
#include <eurephia_nullsafe.h>
#include <eurephia_values.h>
-
+/**
+ * Retrieve a the full path of a file name. Will try to look for the file in different places, like
+ * if EUREPHIA_DIR is set, it will look here or else in ${HOME}/.eurephia.
+ *
+ * @param env const char * to an environment variable to look for the given filename
+ * @param file File name which we are looking for
+ *
+ * @return Returns a full path to the file name, or NULL on error.
+ */
char *get_config_filename(const char *env, const char *file) {
struct stat chk;
static char fname[1026];
@@ -81,6 +98,17 @@ char *get_config_filename(const char *env, const char *file) {
return NULL;
}
+
+/**
+ * Parse one single configuration line into a eurephiaVALUES key/value pair. It will also ignore
+ * comment lines, and also remove the comments on the line of the configuration line so that only
+ * the key/value information is extracted.
+ *
+ * @param line Input configuration line
+ *
+ * @return eurephiaVALUES pointer containing the parsed result. On error or if no valid config
+ * line was found, NULL is returned.
+ */
eurephiaVALUES *parse_config_line(const char *line) {
char *cp = NULL, *key = NULL, *val = NULL, *ptr = NULL;;
eurephiaVALUES *ret = NULL;
@@ -136,6 +164,15 @@ eurephiaVALUES *parse_config_line(const char *line) {
}
+/**
+ * Parses a complete config file and puts it into an eurephiaVALUES key/value stack
+ *
+ * @param env Environment table, used for locating the config file
+ * @param cfgname File name of the configuration file.
+ *
+ * @return Returns a pointer to an eurephiaVALUES stack containing the configuration on success,
+ * otherwise NULL.
+ */
eurephiaVALUES *ReadConfig(const char *env, const char *cfgname) {
char *fname = NULL;
FILE *fp = NULL;
diff --git a/eurephiadm/client_config.h b/eurephiadm/client_config.h
index abffe48..8d31684 100644
--- a/eurephiadm/client_config.h
+++ b/eurephiadm/client_config.h
@@ -19,6 +19,15 @@
*
*/
+/**
+ * @file client_config.h
+ * @author David Sommerseth <dazo@users.sourceforge.net>
+ * @date 2008-12-01
+ *
+ * @brief Config file parser
+ *
+ */
+
#ifndef EUREPHIA_CLIENT_CONFIG_H
#define EUREPHIA_CLIENT_CONFIG_H
diff --git a/eurephiadm/client_context.c b/eurephiadm/client_context.c
index ebf4371..040e9d6 100644
--- a/eurephiadm/client_context.c
+++ b/eurephiadm/client_context.c
@@ -19,6 +19,15 @@
*
*/
+/**
+ * @file client_context.c
+ * @author David Sommerseth <dazo@users.sourceforge.net>
+ * @date 2008-12-01
+ *
+ * @brief Functions for working with eurephiaCTX outside the openvpn plug-in
+ *
+ */
+
#include <stdio.h>
#include <string.h>
#include <assert.h>
@@ -30,6 +39,16 @@
#include <eurephiadb.h>
+/**
+ * Initialises a new eurephiaCTX. This function also initialises the database driver, which must
+ * be configured in the configuration.
+ *
+ * @param log FILE pointer where to put log data
+ * @param loglevel Set the log level (verbosity)
+ * @param cfg eurephiaVALUES pointer to the configuration
+ *
+ * @return Returns a pointer to a eurephiaCTX, otherwise NULL.
+ */
eurephiaCTX *eurephiaCTX_init(FILE *log, const int loglevel, eurephiaVALUES *cfg) {
eurephiaCTX *ctx = NULL;
char *dbdriver = NULL, *logfile = NULL;
@@ -86,6 +105,13 @@ eurephiaCTX *eurephiaCTX_init(FILE *log, const int loglevel, eurephiaVALUES *cfg
return ctx;
}
+
+/**
+ * Takes care of tearing down a eurephiaCTX in a proper way. It will disconnect from the
+ * database and unload the database driver if needed.
+ *
+ * @param ctx eurephiaCTX to take down.
+ */
void eurephiaCTX_destroy(eurephiaCTX *ctx) {
if( ctx == NULL ) {
return;
diff --git a/eurephiadm/client_context.h b/eurephiadm/client_context.h
index ea804e5..56e85ed 100644
--- a/eurephiadm/client_context.h
+++ b/eurephiadm/client_context.h
@@ -19,6 +19,15 @@
*
*/
+/**
+ * @file client_context.h
+ * @author David Sommerseth <dazo@users.sourceforge.net>
+ * @date 2008-12-01
+ *
+ * @brief Functions for working with eurephiaCTX outside the openvpn plug-in
+ *
+ */
+
#ifndef EUREPHIA_CLIENT_CONTEXT
#define EUREPHIA_CLIENT_CONTEXT
diff --git a/eurephiadm/client_session.c b/eurephiadm/client_session.c
index dd86cb8..90a99a6 100644
--- a/eurephiadm/client_session.c
+++ b/eurephiadm/client_session.c
@@ -19,6 +19,15 @@
*
*/
+/**
+ * @file client_session.c
+ * @author David Sommerseth <dazo@users.sourceforge.net>
+ * @date 2008-12-01
+ *
+ * @brief Functions for working on eurephiaSESSIONs outside the openvpn plug-in
+ *
+ */
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -37,7 +46,13 @@
#include "client_config.h"
-
+/**
+ * Get a file name to a session file. This file can be found in either EUREPHIADM_SESSION
+ * environment variable, in the users ~/.eurephia or the directory defined by the EUREPHIA_DIR
+ * environment variable.
+ *
+ * @return Returns a full path to the session file on success, otherwise NULL.
+ */
char *get_session_file() {
char *fname = NULL;
@@ -51,6 +66,14 @@ char *get_session_file() {
return fname;
}
+
+/**
+ * Reads the session key and does a quick validation of it.
+ *
+ * @param ctx eurephiaCTX
+ *
+ * @return Returns a string (char *) containing the session key on success, otherwise NULL.
+ */
char *read_session_file(eurephiaCTX *ctx) {
char *sesskey = NULL, *fname = NULL;
FILE *sfp = NULL;
@@ -74,6 +97,14 @@ char *read_session_file(eurephiaCTX *ctx) {
return sesskey;
}
+/**
+ * Writes a session key to disk, to keep session logged in over a longer time.
+ *
+ * @param ctx eurephiaCTX
+ * @param sess eurephiaSESSION with session info for the current logged in user.
+ *
+ * @return Returns 1 on success, otherwise 0.
+ */
int write_session_file(eurephiaCTX *ctx, eurephiaSESSION *sess) {
struct stat fchk;
char *fname = NULL;
@@ -98,6 +129,12 @@ int write_session_file(eurephiaCTX *ctx, eurephiaSESSION *sess) {
return 1;
}
+
+/**
+ * Removes the session file, used when logging out or the user is automatically logged out.
+ *
+ * @param ctx eurephiaCTX
+ */
void remove_session_file(eurephiaCTX *ctx) {
const char *fname = NULL;
@@ -109,6 +146,15 @@ void remove_session_file(eurephiaCTX *ctx) {
};
}
+/**
+ * Create a eurephiaSESSION. If session key is given, it will try to load that session back.
+ * If no session key is given, it will create a brand new user session.
+ *
+ * @param ctx eurephiaCTX
+ * @param sesskey session key, used for loading existing sessions back.
+ *
+ * @return Returns a eurephiaSESSION pointer to a session, either new or old. On failure, NULL is returned.
+ */
eurephiaSESSION *create_session(eurephiaCTX *ctx, const char *sesskey) {
eurephiaSESSION *new_sess = NULL;
int loop, uniqchk;
@@ -167,8 +213,8 @@ eurephiaSESSION *create_session(eurephiaCTX *ctx, const char *sesskey) {
if( uniqchk == 0 ) {
eurephia_log(ctx, LOG_FATAL, 0,
- "Did not manage to create a unique session key after %i attemtps. Aborting.",
- loop-1);
+ "Did not manage to create a unique session key after %i attempts."
+ " Aborting.", loop-1);
free_nullsafe(new_sess->sessionkey);
free_nullsafe(new_sess);
return NULL;
diff --git a/eurephiadm/client_session.h b/eurephiadm/client_session.h
index 8eaf32a..1ca5309 100644
--- a/eurephiadm/client_session.h
+++ b/eurephiadm/client_session.h
@@ -19,6 +19,15 @@
*
*/
+/**
+ * @file client_session.h
+ * @author David Sommerseth <dazo@users.sourceforge.net>
+ * @date 2008-12-01
+ *
+ * @brief Functions for working on eurephiaSESSIONs outside the openvpn plug-in
+ *
+ */
+
#ifndef EUREPHIA_CLIENT_SESSION_H
#define EUREPHIA_CLIENT_SESSION_H
diff --git a/eurephiadm/commands.h b/eurephiadm/commands.h
index cd3498b..48cea25 100644
--- a/eurephiadm/commands.h
+++ b/eurephiadm/commands.h
@@ -21,21 +21,43 @@
*
*/
+/**
+ * @file commands.h
+ * @author David Sommerseth <dazo@users.sourceforge.net>
+ * @date 2008-12-01
+ *
+ * @brief All eurephiadm commands must be declared here. It defines the overview over
+ * valid commands and the function pointers for the command itself plus its help
+ * function.
+ *
+ */
+
#ifndef EUREPHIADM_COMMANDS_H_
# define EUREPHIADM_COMMANDS_H_
-/* struct used for definition of commands, help info and function pointers to the command */
+/**
+ * struct used for definition of commands, help info and function pointers to the command
+ */
typedef struct {
- char *command;
- int need_session;
- char *accesslvl;
- char *arghint;
- char *helpinfo;
- void (*helpfunc)(void);
+ char *command; /**< Command name, which is used by the end user */
+ int need_session; /**< Set this flag to 1, if the user must log in to use this command */
+ char *accesslvl; /**< String containing the access level the user need to use this command */
+ char *arghint; /**< Simple help hints string, used in the main help screen mainly */
+ char *helpinfo; /**< Simple one-line help string describing the command */
+ void (*helpfunc)(void); /**< Function pointer to the help function. Takes no arguments */
+ /**
+ * Commands main entry function. This function will be called when a valid function is found
+ *
+ * @param eurephiaCTX* The current eurephiaCTX will be received here.
+ * @param eurephiaSESSION* The current eurephiaSESSION for the logged in user.
+ * @param argc argument counter of all following arguments.
+ * @param argv argument vector, char * array of all arguments. arg[0] is the command itself.
+ * @return The function must return 0 on success, and a value > 0 on errors.
+ */
int (*function)(eurephiaCTX *, eurephiaSESSION *, eurephiaVALUES *, int argc, char **argv);
} eurephiadm_functions;
-/* eurephiadm commands, found in eurephiadm.c */
+/**< eurephiadm commands, found in eurephiadm.c */
void help_Help();
int cmd_Help(eurephiaCTX *, eurephiaSESSION *, eurephiaVALUES *cfg, int argc, char **argv);
int cmd_Logout(eurephiaCTX *, eurephiaSESSION *, eurephiaVALUES *cfg, int argc, char **argv);
@@ -70,10 +92,12 @@ int cmd_AdminAccess(eurephiaCTX *, eurephiaSESSION *, eurephiaVALUES *cfg, int a
void help_EditConfig();
int cmd_EditConfig(eurephiaCTX *, eurephiaSESSION *, eurephiaVALUES *cfg, int argc, char **argv);
-/* Declaration of all commands */
+/**
+ * Declaration of all valid commands
+ * {command, need_session, acclvl, arghints,
+ * helpinfo, helpdescr, function}
+ */
static const eurephiadm_functions cmdline_functions[] = {
- // {command, need_session, acclvl, arghints,
- // helpinfo, helpdescr, function}
{"help", 0, NULL, "[<command>]",
"This help screen", help_Help, cmd_Help},
diff --git a/eurephiadm/eurephiadm.c b/eurephiadm/eurephiadm.c
index d07c46f..aceae91 100644
--- a/eurephiadm/eurephiadm.c
+++ b/eurephiadm/eurephiadm.c
@@ -19,6 +19,16 @@
*
*/
+/**
+ * @file eurephiadm.c
+ * @author David Sommerseth <dazo@users.sourceforge.net>
+ * @date 2008-11-28
+ *
+ * @brief Main part of the eurephiadm command line administration utility for eurephia
+ *
+ */
+
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -41,22 +51,47 @@
#include "get_console_input.h"
#include "commands.h"
+
+/**
+ * Prints version and copyright info to stdout
+ *
+ * @param fprg Full path to binary
+ *
+ * @return Returns the basename part of the binary file name
+ */
char *print_version(char *fprg) {
char *prg = basename(fprg);
fprintf(stdout, "%s (v%s) - eurephia administration utility\n"
- "Copyright (C) 2008 David Sommerseth <dazo@users.sourceforge.net>\n",
+ "Copyright (C) 2008, 2009 David Sommerseth <dazo@users.sourceforge.net>\n",
prg, EUREPHIAVERSION);
return prg;
}
+/**
+ * Wrapper function to be used by the command API in eurephiadm
+ *
+ */
void help_Help() {
char *argv[] = { MODULE, NULL };
cmd_Help(NULL, NULL, NULL, 1, argv);
}
+
+/**
+ * Displays a generic help screen, if no arguments where given, or else the
+ * the help screen for the eurephiadm command if it was found.
+ *
+ * @param ctx eurephiaCTX
+ * @param sess eurephiaSESSION of the current logged in user
+ * @param cfg eurephiaVALUES struct of the current configuration
+ * @param argc argument count for the eurephiadm command
+ * @param argv argument table for the eurephiadm command
+ *
+ * @return returns 0 on success, otherwise 1.
+ */
int cmd_Help(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) {
eurephiadm_functions *func = NULL;
int i;
@@ -105,13 +140,38 @@ int cmd_Help(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int a
return 0;
}
+
+/**
+ * eurephiadm logout command. Logs out the current active session.
+ *
+ * @param ctx eurephiaCTX
+ * @param sess eurephiaSESSION of the current logged in user
+ * @param cfg eurephiaVALUES struct of the current configuration
+ * @param argc argument count for the logout command
+ * @param argv argument table for the logout command
+ *
+ * @return returns 0 on success, otherwise 1.
+ */
int cmd_Logout(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) {
int rc = 0;
rc = eDBadminLogout(ctx, argv[0]);
- fprintf(stdout, "%s\n", (rc == 1 ? "Logged out succesfully" : "Logout failed."));
+ fprintf(stdout, "%s\n", (rc == 1 ? "Logged out successfully" : "Logout failed."));
return (rc == 0);
}
+
+/**
+ * eurephiadm show-config command. Dumps configuration to stdout. If the user is logged in, the
+ * configuration saved in the database is also dumped.
+ *
+ * @param ctx eurephiaCTX
+ * @param sess eurephiaSESSION of the current logged in user
+ * @param cfg eurephiaVALUES struct of the current configuration
+ * @param argc argument count for the show-config command
+ * @param argv argument table for the show-config command
+ *
+ * @return returns 0 on success, otherwise 1.
+ */
int cmd_ShowCfg(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) {
void dump_values(eurephiaVALUES *vls) {
eurephiaVALUES *ptr = NULL;
@@ -138,6 +198,14 @@ int cmd_ShowCfg(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, in
}
+/**
+ * Establish a connection to the database and register the database connection in the eurephiaCTX
+ *
+ * @param ctx eurephiaCTX
+ * @param argstr argument string for the database connection
+ *
+ * @return Returns 1 on success, otherwise 0.
+ */
int eurephia_ConnectDB(eurephiaCTX *ctx, const char *argstr) {
char *delims = " ";
char *cp = NULL;
@@ -169,6 +237,17 @@ int eurephia_ConnectDB(eurephiaCTX *ctx, const char *argstr) {
return 1;
}
+
+/**
+ * Log in a user. The function will ask for user name and password and authenticate the user against
+ * the eurephia database and make sure the user is granted access to the requested access level.
+ *
+ * @param ctx eurephiaCTX
+ * @param cfg eurephiaVALUES with configuration settings
+ * @param req_access String (const char *) containing the requested access level.
+ *
+ * @return Returns a eurephiaSESSION pointer to the authenticated user session on success, otherwise NULL.
+ */
eurephiaSESSION *do_login(eurephiaCTX *ctx, eurephiaVALUES *cfg, const char *req_access) {
eurephiaSESSION *session = NULL;
char username[33], password[33], *tmp = NULL;
@@ -211,6 +290,15 @@ eurephiaSESSION *do_login(eurephiaCTX *ctx, eurephiaVALUES *cfg, const char *req
return session;
}
+
+/**
+ * Converts a argument table (char **) into a space separated string (char *)
+ *
+ * @param argc argument counter
+ * @param argv argument array
+ *
+ * @return String (char *) of all arguments, separated by space.
+ */
char *args2string(int argc, char **argv) {
char *res = NULL;
int len = 0, i = 0;
@@ -230,6 +318,14 @@ char *args2string(int argc, char **argv) {
}
+/**
+ * eurephiadm main function
+ *
+ * @param argc argument counter
+ * @param argv argument table
+ *
+ * @return returns 0 on success, otherwise a value > 0
+ */
int main(int argc, char **argv) {
FILE *logfile = NULL;
int loglevel = 0;
@@ -297,7 +393,7 @@ int main(int argc, char **argv) {
}
}
- // Find the command requested and save a pointer to that command's C function
+ // Find the command requested and save a pointer to that commands C function
for( i = 0; cmdline_functions[i].command != NULL; i++ ) {
call_fnc = (eurephiadm_functions *)&cmdline_functions[i];
@@ -330,7 +426,7 @@ int main(int argc, char **argv) {
//
// Load database driver, setup a context and create or reuse an open session
- // and then call the command's function
+ // and then call the commando's function
//
// Create a eurephia context and load database driver
diff --git a/eurephiadm/field_print.h b/eurephiadm/field_print.h
index 09743f0..f52ba86 100644
--- a/eurephiadm/field_print.h
+++ b/eurephiadm/field_print.h
@@ -19,15 +19,37 @@
*
*/
+/**
+ * @file field_print.h
+ * @author David Sommerseth <dazo@users.sourceforge.net>
+ * @date 2008-12-20
+ *
+ * @brief Simple functions for printing labels and values on screen.
+ *
+ */
+
#include <stdio.h>
#ifndef FIELD_PRINT_H
#define FIELD_PRINT_H
+/**
+ * Prints an integer value
+ *
+ * @param label Label of the field to be printed
+ * @param val int value to be printed
+ */
inline static void field_print_int(char *label, int val) {
printf("%25.25s: %i\n", label, val);
}
+
+/**
+ * Prints a string value
+ *
+ * @param label Label of the field to be printed
+ * @param val String (char *) value to be printed
+ */
inline static void field_print_str(char *label, char *val) {
printf("%25.25s: %s\n", label, (val == NULL ? "-" : val));
}
diff --git a/eurephiadm/get_console_input.c b/eurephiadm/get_console_input.c
index c64cefd..8914d7b 100644
--- a/eurephiadm/get_console_input.c
+++ b/eurephiadm/get_console_input.c
@@ -19,10 +19,31 @@
*
*/
+/**
+ * @file get_console_input.c
+ * @author David Sommerseth <dazo@users.sourceforge.net>
+ * @date 2008-11-29
+ *
+ * @brief Simple function to retrieve user input from the console
+ *
+ */
+
#include <stdio.h>
#include <termios.h>
#include <string.h>
+
+/**
+ * Prints a prompt to the screen and waits for user input via the tty.
+ *
+ * @param buf char* to the buffer where the user input is to be stored.
+ * @param len size of the input buffer
+ * @param prompt String printed before the user is asked for input
+ * @param hidden If set to 1, the user input will not be echoed to the tty,
+ * which is useful for passwords.
+ *
+ * @return Returns the number of bytes received from the user. On error -1 is returned
+ */
int get_console_input(char *buf, size_t len, const char *prompt, int hidden) {
struct termios term_orig, term_noecho;
char *ptr;
@@ -66,5 +87,3 @@ int get_console_input(char *buf, size_t len, const char *prompt, int hidden) {
return (buf != NULL ? strlen(buf) : -1);
}
-
-
diff --git a/eurephiadm/get_console_input.h b/eurephiadm/get_console_input.h
index 12120ab..827aea6 100644
--- a/eurephiadm/get_console_input.h
+++ b/eurephiadm/get_console_input.h
@@ -19,6 +19,15 @@
*
*/
+/**
+ * @file get_console_input.h
+ * @author David Sommerseth <dazo@users.sourceforge.net>
+ * @date 2008-11-29
+ *
+ * @brief Simple function to retrieve user input from the console
+ *
+ */
+
#ifndef _GETPASSWORD_H
#define _GETPASSWORD_H
diff --git a/eurephiadm/parse_certificate_files.c b/eurephiadm/parse_certificate_files.c
index de8f9d4..1a5d3e1 100644
--- a/eurephiadm/parse_certificate_files.c
+++ b/eurephiadm/parse_certificate_files.c
@@ -1,4 +1,4 @@
-/* parse_certificate_files.c -- Parses PEM or PKCS12 formated cert. files
+/* parse_certificate_files.c -- Parses PEM or PKCS12 formatted cert. files
*
* GPLv2 only - Copyright (C) 2008, 2009
* David Sommerseth <dazo@users.sourceforge.net>
@@ -19,6 +19,16 @@
*
*/
+/**
+ * @file parse_certificate_files.c
+ * @author David Sommerseth <dazo@users.sourceforge.net>
+ * @date 2008-12-21
+ *
+ * @brief Parses PEM/DER or PKCS#12 certificate files to retrieve information
+ * needed by eurephia. This feature requires OpenSSL to be available.
+ *
+ */
+
#ifdef HAVE_OPENSSL
#include <stdio.h>
#include <string.h>
@@ -37,6 +47,15 @@
#include "parse_certificate_files.h"
+/**
+ * Extracts a specific X.509 field from an X509 struct pointer.
+ *
+ * @param module String containing a module name, only used in error situations
+ * @param cert Pointer to an X509 struct with the certificate information
+ * @param fieldname X.509 field name to extract
+ *
+ * @return Returns a string (char *) to the field value if found, otherwise NULL.
+ */
char *ExtractCertInfo(const char *module, X509 *cert, const char *fieldname) {
unsigned char *buf = (unsigned char *)1; // Needs to be 1 to avoid OpenSSL 0.9.6b bug
char resbuf[2050];
@@ -86,6 +105,16 @@ char *ExtractCertInfo(const char *module, X509 *cert, const char *fieldname) {
}
+/**
+ * Internal function, usually called via the Cert_ParseFile(...) macro. Parses a certificate
+ * file of a given format.
+ *
+ * @param cfile File name of the input file
+ * @param cformat Certificate format of the file
+ *
+ * @return Returns a certinfo struct pointer with the parsed result on success, otherwise NULL.
+ */
+
certinfo *_Cert_ParseFile(const char *module, const char *certfile, int certfile_format) {
BIO *bio_err = NULL;
PKCS12 *p12 = NULL;
diff --git a/eurephiadm/parse_certificate_files.h b/eurephiadm/parse_certificate_files.h
index 8ae7802..ab0b64e 100644
--- a/eurephiadm/parse_certificate_files.h
+++ b/eurephiadm/parse_certificate_files.h
@@ -1,4 +1,4 @@
-/* parse_certificate_files.c -- Parses PEM or PKCS12 formated cert. files
+/* parse_certificate_files.c -- Parses PEM or PKCS12 formatted cert. files
*
* GPLv2 only - Copyright (C) 2008
* David Sommerseth <dazo@users.sourceforge.net>
@@ -19,21 +19,39 @@
*
*/
+/**
+ * @file parse_certificate_files.h
+ * @author David Sommerseth <dazo@users.sourceforge.net>
+ * @date 2008-12-21
+ *
+ * @brief Parses PEM/DER or PKCS#12 certificate files to retrieve information
+ * needed by eurephia. This feature requires OpenSSL to be available.
+ *
+ */
+
#ifndef PARSE_CERTIFICATE_FILES_H_
# define PARSE_CERTIFICATE_FILES_H_
#include <certinfo.h>
#ifdef HAVE_OPENSSL
-#define CERTFILE_PEM 0x01
-#define CERTFILE_PKCS12 0x02
+#define CERTFILE_PEM 0x01 /**< Input certificate is in PEM/DER format */
+#define CERTFILE_PKCS12 0x02 /**< Input certificate is in PKCS#12 format */
#ifndef _PARSE_CERTFICIATE_FILES_C
+/**
+ * Macro to _Cert_ParseFile(...). Parses a certificate file of a given format.
+ *
+ * @param cfile File name of the input file
+ * @param cformat Certificate format of the file
+ *
+ * @return Returns a certinfo struct pointer with the parsed result on success, otherwise NULL.
+ */
#define Cert_ParseFile(cfile,cformat) _Cert_ParseFile(MODULE, cfile, cformat)
certinfo *_Cert_ParseFile(const char *module, const char *certfile, int certfile_format);
-#endif /* !_PARSE_CERTFICIATE_FILES_C */
+#endif /* !_PARSE_CERTIFICATE_FILES_C */
#endif /* HAVE OPENSSL */
#endif /* !PARSE_CERTIFICATE_FILES_H_ */
diff --git a/eurephiadm/xsltparser.c b/eurephiadm/xsltparser.c
index 663417d..03c5ccb 100644
--- a/eurephiadm/xsltparser.c
+++ b/eurephiadm/xsltparser.c
@@ -19,6 +19,15 @@
*
*/
+/**
+ * @file xsltparser.c
+ * @author David Sommerseth <dazo@users.sourceforge.net>
+ * @date 2009-03-29
+ *
+ * @brief Generic XSLT parser for eurephiadm
+ *
+ */
+
#include <stdio.h>
#ifdef HAVE_LIBXML2
@@ -34,6 +43,19 @@
#include <eurephia_values.h>
+
+/**
+ * Parses an XML document and a given XSLT file and returns the result as text to a FILE pointer.
+ *
+ * @param dst FILE pointer where the result will be returned
+ * @param cfg eurephiaVALUES with the eurephiadm configuration. Used for locating the correct
+ * path to the XSLT templates
+ * @param xmldoc xmlDoc pointer to the input XML document.
+ * @param xsltfname File name of the XSLT template to use for the parsing.
+ * @param xsltparams Parameters to the XSLT template.
+ *
+ * @return Returns 1 on success, otherwise 0.
+ */
int xslt_print_xmldoc(FILE *dst, eurephiaVALUES *cfg, xmlDoc *xmldoc,
const char *xsltfname, const char **xsltparams)
{
diff --git a/eurephiadm/xsltparser.h b/eurephiadm/xsltparser.h
index dffa8d1..392f6c4 100644
--- a/eurephiadm/xsltparser.h
+++ b/eurephiadm/xsltparser.h
@@ -19,6 +19,14 @@
*
*/
+/**
+ * @file xsltparser.h
+ * @author David Sommerseth <dazo@users.sourceforge.net>
+ * @date 2009-03-29
+ *
+ * @brief Generic XSLT parser for eurephiadm
+ *
+ */
#ifndef XSLTPARSER_H_
# define XSLTPARSER_H_