~ubuntu-branches/ubuntu/karmic/system-tools-backends/karmic-proposed

« back to all changes in this revision

Viewing changes to Users/Users.pm

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2009-10-08 11:42:26 UTC
  • mfrom: (1.1.28 upstream) (1.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20091008114226-zp9fxn7h4ky0qai0
Tags: 2.8.2-1
* New upstream release.
  - debian/patches/01_debian_4.0.patch,
  - debian/patches/04_correct_perl_command.patch:
    + Removed, fixed upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
236
236
  'mandrake-9.0'    => $rh_logindefs_defaults,
237
237
  'pld-1.0'         => $rh_logindefs_defaults,
238
238
  'fedora-1'        => $rh_logindefs_defaults,
239
 
  'debian-3.0'      => $rh_logindefs_defaults,
 
239
  'debian'          => $rh_logindefs_defaults,
240
240
  'vine-3.0'        => $rh_logindefs_defaults,
241
241
  'gentoo'              => $gentoo_logindefs_defaults,
242
242
  'archlinux'       => $gentoo_logindefs_defaults,
439
439
sub del_user
440
440
{
441
441
        my ($user) = @_;
442
 
  my ($command);
 
442
  my (@command);
443
443
        
444
444
  if ($Utils::Backend::tool{"system"} eq "FreeBSD")
445
445
  {
446
 
    $command = "$cmd_pw userdel -n \'" . $$user[$LOGIN] . "\' ";
 
446
    @command = ($cmd_pw, "userdel", "-n", $$user[$LOGIN]);
447
447
  }
448
448
  else
449
449
  {
450
450
    if ($cmd_deluser)
451
451
    {
452
 
      $command = "$cmd_deluser '". $$user[$LOGIN] . "'";
 
452
      @command = ($cmd_deluser, $$user[$LOGIN]);
453
453
    }
454
454
    else
455
455
    {
456
 
      $command = "$cmd_userdel \'" . $$user[$LOGIN] . "\'";
 
456
      @command = ($cmd_userdel, $$user[$LOGIN]);
457
457
    }
458
458
  }
459
459
 
460
 
  &Utils::File::run ($command);
 
460
  &Utils::File::run (@command);
461
461
}
462
462
 
463
463
sub change_user_chfn
464
464
{
465
465
  my ($login, $old_comment, $comment) = @_;
466
466
  my ($fname, $office, $office_phone, $home_phone);
467
 
  my ($command, $str);
 
467
  my (@command, $str);
468
468
 
469
469
  return if !$login;
470
470
 
474
474
 
475
475
  if ($Utils::Backend::tool{"system"} eq "FreeBSD")
476
476
  {
477
 
    $command = "$cmd_pw usermod -n " . $login . " -c \'" . $str . "\'";
 
477
    @command = ($cmd_pw, "usermod", "-n", $login,
 
478
                                    "-c", $str);
478
479
  }
479
480
  else
480
481
  {
481
 
    $command = "$cmd_usermod -c \'" . $str . "\' " . $login;
 
482
    @command = ($cmd_usermod, "-c", $str, $login);
482
483
  }
483
484
 
484
 
  &Utils::File::run ($command);
 
485
  &Utils::File::run (@command);
485
486
}
486
487
 
487
488
# modifies /etc/shadow directly, not good practice,
515
516
sub set_passwd
516
517
{
517
518
  my ($login, $password) = @_;
518
 
  my ($pwdpipe, $command);
 
519
  my ($pwdpipe);
519
520
 
520
521
  if ($Utils::Backend::tool{"system"} eq "FreeBSD")
521
522
  {
522
 
 
 
523
    my ($command);
523
524
    $command = "$cmd_pw usermod -H 0";
524
525
    $pwdpipe = &Utils::File::run_pipe_write ($command);
525
526
    print $pwdpipe $password;
531
532
  }
532
533
  else
533
534
  {
534
 
    $command = "$cmd_usermod " .
535
 
        " -p '" . $password . "' " . $login;
 
535
    my (@command);
 
536
    @command = ($cmd_usermod, "-p", $password, $login);
536
537
 
537
 
    &Utils::File::run ($command);
 
538
    &Utils::File::run (@command);
538
539
  }
539
540
}
540
541
 
552
553
 
553
554
    # FreeBSD doesn't create the home directory
554
555
    $home = $$user[$HOME];
555
 
    &Utils::File::run ("$tool_mkdir -p $home");
 
556
    &Utils::File::run ($tool_mkdir, "-p", $home);
556
557
 
557
558
    $command = "$cmd_pw useradd " .
558
559
        " -n \'" . $$user[$LOGIN] . "\'" .
562
563
        " -s \'" . $$user[$SHELL] . "\'" .
563
564
        " -H 0"; # pw(8) reads password from STDIN
564
565
 
 
566
#    @command = ($cmd_pw, "useradd", "-n", $$user[$LOGIN],
 
567
#                                    "-u", $$user[$UID],
 
568
#                                    "-d", $$user[$HOME],
 
569
#                                    "-g", $$user[$GID],
 
570
#                                    "-s", $$user[$SHELL],
 
571
#                                    "-H", "0"); # pw(8) reads password from STDIN
 
572
 
565
573
    $pwdpipe = &Utils::File::run_pipe_write ($command);
566
574
    print $pwdpipe $$user[$PASSWD];
567
575
    &Utils::File::close_file ($pwdpipe);
570
578
  {
571
579
    $home_parents = $$user[$HOME];
572
580
    $home_parents =~ s/\/+[^\/]+\/*$//;
573
 
    &Utils::File::run ("$tool_mkdir -p $home_parents");
574
 
 
575
 
    $command = "$cmd_useradd" .
576
 
        " -d \'" . $$user[$HOME]  . "\'" .
577
 
        " -g \'" . $$user[$GID]   . "\'" .
578
 
        " -s \'" . $$user[$SHELL] . "\'" .
579
 
        " -u \'" . $$user[$UID]   . "\'" .
580
 
        " \'"    . $$user[$LOGIN] . "\'";
581
 
 
582
 
    &Utils::File::run ($command);
 
581
    &Utils::File::run ($tool_mkdir, "-p", $home_parents);
 
582
 
 
583
    @command = ($cmd_useradd, "-d", $$user[$HOME],
 
584
                              "-g", $$user[$GID],
 
585
                              "-s", $$user[$SHELL],
 
586
                              "-u", $$user[$UID],
 
587
                                    $$user[$LOGIN]);
 
588
 
 
589
    &Utils::File::run (@command);
583
590
    &modify_shadow_password ($$user[$LOGIN], $$user[$PASSWD]);
584
591
  }
585
592
  else
586
593
  {
587
594
    $home_parents = $$user[$HOME];
588
595
    $home_parents =~ s/\/+[^\/]+\/*$//;
589
 
    &Utils::File::run ("$tool_mkdir -p $home_parents");
 
596
    &Utils::File::run ($tool_mkdir, "-p", $home_parents);
590
597
 
591
598
    if ($cmd_adduser &&
592
599
        $Utils::Backend::tool{"platform"} !~ /^slackware/ &&
596
603
    {
597
604
      # use adduser if available and valid (slackware one is b0rk)
598
605
      # set empty gecos fields and password, they will be filled out later
599
 
      $command = "$cmd_adduser --gecos '' --disabled-password" .
600
 
          " --home \'"  . $$user[$HOME]   . "\'" .
601
 
          " --gid \'"   . $$user[$GID]    . "\'" .
602
 
          " --shell \'" . $$user[$SHELL]  . "\'" .
603
 
          " --uid \'"   . $$user[$UID]    . "\'" .
604
 
          " \'"         . $$user[$LOGIN]  . "\'";
 
606
      @command = ($cmd_adduser, "--gecos", "",
 
607
                                "--disabled-password",
 
608
                                "--home", $$user[$HOME],
 
609
                                "--gid", $$user[$GID],
 
610
                                "--shell", $$user[$SHELL],
 
611
                                "--uid", $$user[$UID],
 
612
                                         $$user[$LOGIN]);
605
613
 
606
 
      &Utils::File::run ($command);
 
614
      &Utils::File::run (@command);
607
615
 
608
616
      # password can't be set in non-interactive
609
617
      # mode with adduser, call usermod instead
610
 
      $command = "$cmd_usermod " .
611
 
          " -p '" . $$user[$PASSWD] . "' " . $$user[$LOGIN];
 
618
      @command = ($cmd_usermod, "-p", $$user[$PASSWD], $$user[$LOGIN]);
612
619
 
613
 
      &Utils::File::run ($command);
 
620
      &Utils::File::run (@command);
614
621
    }
615
622
    else
616
623
    {
617
624
      # fallback to useradd
618
 
      $command = "$cmd_useradd -m" .
619
 
          " -d \'" . $$user[$HOME]   . "\'" .
620
 
          " -g \'" . $$user[$GID]    . "\'" .
621
 
          " -p \'" . $$user[$PASSWD] . "\'" .
622
 
          " -s \'" . $$user[$SHELL]  . "\'" .
623
 
          " -u \'" . $$user[$UID]    . "\'" .
624
 
          " \'"    . $$user[$LOGIN]  . "\'";
 
625
      @command = ($cmd_useradd, "-m",
 
626
                                "-d", $$user[$HOME],
 
627
                                "-g", $$user[$GID],
 
628
                                "-p", $$user[$PASSWD],
 
629
                                "-s", $$user[$SHELL],
 
630
                                "-u", $$user[$UID],
 
631
                                      $$user[$LOGIN]);
625
632
 
626
 
      &Utils::File::run ($command);
 
633
      &Utils::File::run (@command);
627
634
    }
628
635
  }
629
636
 
652
659
  }
653
660
  elsif ($Utils::Backend::tool{"system"} eq "SunOS")
654
661
  {
655
 
    $command = "$cmd_usermod" .
656
 
        " -d \'" . $$new_user[$HOME]   . "\'" .
657
 
        " -g \'" . $$new_user[$GID]    . "\'" .
658
 
        " -l \'" . $$new_user[$LOGIN]  . "\'" .
659
 
        " -s \'" . $$new_user[$SHELL]  . "\'" .
660
 
        " -u \'" . $$new_user[$UID]    . "\'" .
661
 
        " \'" . $$old_user[$LOGIN] . "\'";
 
662
    @command = ($cmd_usermod, "-d", $$new_user[$HOME],
 
663
                              "-g", $$new_user[$GID],
 
664
                              "-l", $$new_user[$LOGIN],
 
665
                              "-s", $$new_user[$SHELL],
 
666
                              "-u", $$new_user[$UID],
 
667
                                    $$old_user[$LOGIN]);
662
668
 
663
 
    &Utils::File::run ($command);
 
669
    &Utils::File::run (@command);
664
670
    &modify_shadow_password ($$new_user[$LOGIN], $$new_user[$PASSWD]);
665
671
  }
666
672
  else
667
673
  {
668
 
    $command = "$cmd_usermod" .
669
 
        " -d \'" . $$new_user[$HOME]   . "\'" .
670
 
        " -g \'" . $$new_user[$GID]    . "\'" .
671
 
        " -l \'" . $$new_user[$LOGIN]  . "\'" .
672
 
        " -p \'" . $$new_user[$PASSWD] . "\'" .
673
 
        " -s \'" . $$new_user[$SHELL]  . "\'" .
674
 
        " -u \'" . $$new_user[$UID]    . "\'" .
675
 
        " \'" . $$old_user[$LOGIN] . "\'";
 
674
    @command = ($cmd_usermod, "-d", $$new_user[$HOME],
 
675
                              "-g", $$new_user[$GID],
 
676
                              "-l", $$new_user[$LOGIN],
 
677
                              "-s", $$new_user[$SHELL],
 
678
                              "-u", $$new_user[$UID],
 
679
                                    $$old_user[$LOGIN]);
676
680
 
677
681
    &Utils::File::run ($command);
678
682
  }