summaryrefslogtreecommitdiff
path: root/src/users.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/users.c')
-rw-r--r--src/users.c63
1 files changed, 57 insertions, 6 deletions
diff --git a/src/users.c b/src/users.c
index 338834f..b0f767c 100644
--- a/src/users.c
+++ b/src/users.c
@@ -24,6 +24,10 @@
#include <shell.h>
#include <users.h>
+
+char user_name[USER_NAME_SIZE];
+char user_role[USER_ROLE_SIZE];
+
/* **************************************************************** */
/* */
/* SILA Users Commands */
@@ -39,9 +43,6 @@ static char args[PATH_MAX];
static const char *argv[PATH_MAX];
/* Options: */
-#define USER_NAME_SIZE 64
-#define USER_ROLE_SIZE 16
-
static int opt_help = 0;
static char opt_name[USER_NAME_SIZE];
static char opt_role[USER_ROLE_SIZE];
@@ -132,9 +133,12 @@ void get_args( int argc, char * const *argv )
}
}
+ /*
+ Assume that the last argument is a user name:
+ */
if( optind < argc )
{
- opt_help = 1;
+ strncpy( opt_name, (const char *)argv[optind++], sizeof( opt_name ) - 1 );
}
/* This is important for call getopt_long() several times! */
@@ -146,17 +150,64 @@ void get_args( int argc, char * const *argv )
Users management commands:
***************************************************************/
+static void passwd_usage( char *fname )
+{
+ fprintf( stdout, "\n" );
+ fprintf( stdout, "Usage: %s [username]\n", fname );
+ fprintf( stdout, "\n" );
+ fprintf( stdout, "Set or change user password.\n" );
+ fprintf( stdout, "\n" );
+ fprintf( stdout, "Options:\n" );
+ fprintf( stdout, " -h,--help Display this information.\n" );
+ fprintf( stdout, "\n" );
+ fprintf( stdout, "Parameter:\n" );
+ fprintf( stdout, " [username] User name (default: %s).\n", user_name );
+ fprintf( stdout, "\n" );
+}
+
+int com_passwd( char *arg )
+{
+ split_args( "passwd", arg );
+
+ get_args( argc, (char * const *)&argv[0] );
+
+ if( opt_help )
+ {
+ passwd_usage( "passwd" );
+ }
+ else
+ {
+ /* check args */
+ if( !opt_name[0] )
+ {
+ sprintf( syscom, "passwd %s", user_name );
+ }
+ else
+ {
+ if( !strncmp( user_role, ROLE_ADMIN, sizeof( ROLE_ADMIN ) ) )
+ sprintf( syscom, "passwd %s", opt_name );
+ else
+ sprintf( syscom, "echo \"Only users with role='%s' can change other user's password\"", ROLE_ADMIN );
+ }
+
+ return( system( syscom ) );
+ }
+
+ return( 0 );
+}
+
+
static void useradd_usage( char *fname )
{
fprintf( stdout, "\n" );
- fprintf( stdout, "Usage: %s [options]\n", fname );
+ fprintf( stdout, "Usage: %s [options] [user name]\n", fname );
fprintf( stdout, "\n" );
fprintf( stdout, "Delete user.\n" );
fprintf( stdout, "\n" );
fprintf( stdout, "Options:\n" );
fprintf( stdout, " -h,--help Display this information.\n" );
fprintf( stdout, " -n,--name User Name.\n" );
- fprintf( stdout, " -r,--role User Role (default: %s.\n", ROLE_USER );
+ fprintf( stdout, " -r,--role User Role (default: %s).\n", ROLE_USER );
fprintf( stdout, "\n" );
}