diff options
Diffstat (limited to 'eurephiadm/commands/users.c')
-rw-r--r-- | eurephiadm/commands/users.c | 120 |
1 files changed, 109 insertions, 11 deletions
diff --git a/eurephiadm/commands/users.c b/eurephiadm/commands/users.c index 4450b37..9210094 100644 --- a/eurephiadm/commands/users.c +++ b/eurephiadm/commands/users.c @@ -19,6 +19,15 @@ * */ +/** + * @file users.c + * @author David Sommerseth <dazo@users.sourceforge.net> + * @date 2008-12-01 + * + * @brief eurephiadm users command. User account management command. + * + */ + #include <stdio.h> #include <string.h> #include <sys/stat.h> @@ -30,7 +39,7 @@ #include <libxml/xpath.h> #endif -#define MODULE "eurephia::Users" +#define MODULE "eurephia::Users" /**< Need to define the active module before including argparser.h */ #include <eurephia_nullsafe.h> #include <eurephia_context.h> #include <eurephia_log.h> @@ -48,13 +57,22 @@ #include "../parse_certificate_files.h" #include "../xsltparser.h" -// Reuse code which is in certificats.c +// Reuse code which is in certificates.c #define SHOWCERTS_FIREWALL 0x001 #define SHOWCERTS_DIGEST 0x002 +/** + * Forward declaration of a function already found in certificates.c + */ int register_certificate(eurephiaCTX *ctx, int depth, const char *digest, const char *cname, const char *org, const char *email); + +/** + * Help screens for the users command + * + * @param page which help screen to display + */ void display_users_help(int page) { printf("\n%s -- Administer user accounts\n\n", MODULE); @@ -75,7 +93,7 @@ void display_users_help(int page) { "Optional arguments are:\n\n" " -l | --lastlog Show users lastlog entries\n" " -L | --lastlog-details Show a more verbose lastlog\n" - " -a | --attempts Show users failed attempts and blaclisting\n" + " -a | --attempts Show users failed attempts and blacklisting\n" " -b | --blacklist Alias for --attempts\n" "\n"); break; @@ -137,6 +155,18 @@ void display_users_help(int page) { } } + +/** + * Help screen wrapper for the users help function. + * + * @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 help_Users2(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) { e_options helpargs[] = { {"--list", "-l", 0}, @@ -154,11 +184,25 @@ int help_Users2(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, in return 0; } +/** + * Help screen wrapper. Used by cmd_Help() + */ void help_Users() { display_users_help(0); } +/** + * users list mode. Lists all registered users. + * + * @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 list_users(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) { xmlDoc *userlist = NULL; int i = 0; @@ -198,6 +242,15 @@ int list_users(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int return 0; } +/** + * Simple function to convert account flags from an XML document to a string of flags, + * separated by space + * + * @param xpathCTX XPath context of the XML document being parsed. + * @param xpath XPath expression of the flag nodes. + * + * @return Returns a string of flags on success, otherwise NULL is returned. + */ char *xmlFlags2str(xmlXPathContext *xpathCTX, const char *xpath) { xmlXPathObject *flagsObj = NULL; int i = 0; @@ -225,7 +278,17 @@ char *xmlFlags2str(xmlXPathContext *xpathCTX, const char *xpath) { } -// Show account information for a particular user +/** + * users show mode. Show account information for a particular user + * + * @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 show_user(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) { int i, crit_set = 0, lastlog_verb = 0; long int show_info = USERINFO_user | USERINFO_certs; @@ -297,7 +360,7 @@ int show_user(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int } } - // Check if we have the needed search criterias + // Check if we have the needed search criteria if( crit_set == 0 ) { fprintf(stderr, "%s: Missing required parameter. You must provide either user id or user name\n", @@ -308,7 +371,7 @@ int show_user(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int if( crit_set > 1 ) { fprintf(stderr, - "%s: You cannot have several search criterias (-i | -u)\n", MODULE); + "%s: You cannot have several search criteria (-i | -u)\n", MODULE); xmlFreeDoc(srch_xml); return 1; } @@ -364,7 +427,19 @@ int show_user(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int } -// This function handles activation, deactivation and deletion of an account + + +/** + * This function handles activation, deactivation and deletion of an account + * + * @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 account_activation(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) { xmlDoc *user_xml = NULL, *update_xml = NULL, *srch_xml = NULL, *tmp_xml = NULL; xmlNode *user_n = NULL, *update_n = NULL, *srch_root = NULL, *tmp_n = NULL; @@ -437,7 +512,7 @@ int account_activation(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES * } } - // Check if we have the needed search criterias + // Check if we have the needed search criteria if( crit_set == 0 ) { fprintf(stderr, "%s: Missing required parameter. You must provide either user id or user name\n", @@ -448,7 +523,7 @@ int account_activation(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES * if( crit_set > 1 ) { fprintf(stderr, - "%s: You cannot have several search criterias (-i | -u)\n", MODULE); + "%s: You cannot have several search criteria (-i | -u)\n", MODULE); xmlFreeDoc(srch_xml); return 1; } @@ -503,7 +578,7 @@ int account_activation(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES * case 'd': // Deactivate a user account if( (activated != NULL) && (deactivated != NULL) ) { - printf("User account is already deactived\n"); + printf("User account is already deactivated\n"); goto exit; } else if( (activated != NULL) ) { // Set deactivated to now() @@ -580,7 +655,7 @@ int account_activation(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES * tmp_xml = eDBadminUserCertsLink(ctx, update_xml); if( tmp_xml == NULL ) { - fprintf(stderr, "%s: Failed to deregister user <-> certificate link\n", MODULE); + fprintf(stderr, "%s: Failed to remove the user-certs link\n", MODULE); } tmp_n = eurephiaXML_getRoot(ctx, tmp_xml, NULL, 1); @@ -604,6 +679,18 @@ int account_activation(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES * return (rc != 1); } + +/** + * users add mode. Creates a new user account. + * + * @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 add_user(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) { xmlDoc *user_xml = NULL; xmlNode *node = NULL, *node2 = NULL; @@ -862,6 +949,17 @@ int add_user(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int a } +/** + * Main function for the users command. + * + * @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_Users(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) { char **mode_argv; int i, mode_argc = 0, rc = 0; |