[pve-devel] r4843 - pve-access-control/trunk

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Jun 25 13:24:26 CEST 2010


Author: dietmar
Date: 2010-06-25 11:24:26 +0000 (Fri, 25 Jun 2010)
New Revision: 4843

Modified:
   pve-access-control/trunk/AccessControl.pm
   pve-access-control/trunk/ChangeLog
   pve-access-control/trunk/pveum
Log:
* AccessControl.pm (modify_user): include patch from Seth



Modified: pve-access-control/trunk/AccessControl.pm
===================================================================
--- pve-access-control/trunk/AccessControl.pm	2010-06-25 10:22:35 UTC (rev 4842)
+++ pve-access-control/trunk/AccessControl.pm	2010-06-25 11:24:26 UTC (rev 4843)
@@ -459,6 +459,81 @@
     save_user_config ($usercfg);
 }
 
+sub modify_user {
+
+    my ($username, $opts) = @_;
+    
+    ($username, undef, undef) = verify_username ($username);
+    
+    die "modify failed: username '$username' contains invalid characters\n" if !$username;
+    
+    my $usercfg = load_user_config();
+
+    die "user '$username' does not exist\n" if !$usercfg->{users}->{$username};
+
+    enable_user ($username,$usercfg) if $opts->{unlock} &&
+	!$usercfg->{users}->{$username}->{enabled};
+    disable_user ($username,$usercfg) if $opts->{lock} &&
+	$usercfg->{users}->{$username}->{enabled};
+    change_password ($username,$usercfg) if $opts->{password};
+    name_user ($username,$usercfg) if $opts->{name};
+    comment_user ($username,$usercfg) if $opts->{comment};
+
+    save_user_config ($usercfg);
+
+}
+
+sub delete_user {
+    
+    my ($username) = @_;
+
+    ($username, undef, undef) = verify_username ($username);
+
+    my $usercfg = load_user_config();
+
+    delete ($usercfg->{users}->{$username})
+        if $usercfg->{users}->{$username};
+
+    #fixme: Remove user from ACLs and groups
+
+    save_user_config ($usercfg);
+
+}   
+
+sub disable_user {
+
+    my ($username,$usercfg) = @_;
+
+    $usercfg->{users}->{$username} = { enabled => 0 };
+
+}
+
+sub enable_user {
+
+    my ($username,$usercfg) = @_;
+
+    $usercfg->{users}->{$username} = { enabled => 1 };
+
+}
+
+sub change_password {
+
+    warn "change password not implemented\n";
+
+}
+
+sub name_user {
+
+    warn "change name not implemented\n";
+
+}
+
+sub comment_user {
+
+    warn "change comment not implemented\n";
+
+}
+
 my $valid_privs = {
     'VM.Create' => 1,
     'VM.Remove' => 1,

Modified: pve-access-control/trunk/ChangeLog
===================================================================
--- pve-access-control/trunk/ChangeLog	2010-06-25 10:22:35 UTC (rev 4842)
+++ pve-access-control/trunk/ChangeLog	2010-06-25 11:24:26 UTC (rev 4843)
@@ -1,3 +1,7 @@
+2010-06-25  Proxmox Support Team  <support at proxmox.com>
+
+	* AccessControl.pm (modify_user): include patch from Seth
+
 2010-06-24  Proxmox Support Team  <support at proxmox.com>
 
 	* test/perm-test1.pl (check_permission): a first regression test

Modified: pve-access-control/trunk/pveum
===================================================================
--- pve-access-control/trunk/pveum	2010-06-25 10:22:35 UTC (rev 4842)
+++ pve-access-control/trunk/pveum	2010-06-25 11:24:26 UTC (rev 4843)
@@ -5,7 +5,6 @@
 use PVE::AccessControl;
 use File::Path qw(make_path remove_tree);
 use Term::ReadLine;
-
 use Data::Dumper; # fixme: remove
 use Time::HiRes qw( usleep ualarm gettimeofday tv_interval ); # fixme: remove
 
@@ -66,7 +65,7 @@
 
     exit (0);
 
-} elsif ($cmd eq 'adduser') {
+} elsif ($cmd eq 'useradd') {
 
     my $username = shift;
 
@@ -78,6 +77,37 @@
 
     exit(0);
 
+} elsif ($cmd eq 'usermod') {
+
+    my $opts = {};
+
+    if (!GetOptions ($opts, 'unlock', 'lock', 'password', 'name=s', 'comment=s')) {
+        exit (-1);
+    }
+
+    die "wrong number of arguments\n" if scalar (@ARGV) != 1;
+
+    die "conflicting options unlock/lock\n" if $opts->{unlock} &&
+        $opts->{lock};
+
+    my $username = shift;
+
+    PVE::AccessControl::modify_user($username, $opts);
+
+    exit(0);
+
+} elsif ($cmd eq 'userdel') {
+
+    my $username = shift;
+
+    die "no username specified\n" if !$username;
+
+    #fixme: Verify deletion?
+
+    PVE::AccessControl::delete_user($username);
+
+    exit(0);
+
 } else {
 
     print_usage("unknown command '$cmd'");




More information about the pve-devel mailing list