Author Topic: How to set uidNumber  (Read 646 times)

andreas-h

  • Zen Apprentice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
How to set uidNumber
« on: December 08, 2015, 06:05:29 pm »
How can I explicitly set the uidNumber of a new user?  The web interface doesn't allow this.  So I searched around and found a Perl script, which I modified a bit:

Code: [Select]
#!/usr/bin/perl
use strict;
use warnings;

use EBox;
use EBox::Global;

EBox::init();

my $global = EBox::Global->getInstance(1);
my $users = $global->modInstance('samba');

$users->_loadSchemas();

foreach my $user (@{$users->users()}) {
    my $username = $user->name();
    my $uidNumber = $user->uidNumber();
    print "$username :: $uidNumber\n";
    if ($username eq 'myusername') {
        $uidNumber = '1111';
    };
    if ($uidNumber != $user->uidNumber()) {
        $user->set('uidNumber', $uidNumber);
        $user->save();
        print "$username UID changed to $uidNumber\n";
    };
}

my $prov = new EBox::Samba::Provision();
$prov->mapAccounts();

Now, first I create a user 'myusername' in the web interface.  If then I run the script once, I see the output

Code: [Select]
Administrator :: 2500
Guest :: 2501
myusername :: 2502
myusername UID changed to 1111

However, how can I verify this actually worked?  Because when I run the script again, the output looks like this:

Code: [Select]
Administrator :: 2500
Guest :: 2501

And this seems like the $users->users() list doesn't include myusername any more ...