~ubuntu-branches/ubuntu/lucid/adduser/lucid

« back to all changes in this revision

Viewing changes to deluser

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2008-05-02 11:06:06 UTC
  • Revision ID: james.westby@ubuntu.com-20080502110606-likj7wivz3fs4u7l
Tags: 3.107ubuntu1
* Merge from debian unstable, remaining changes:
  - Allow uppercase letters in the names of system users.
    This is done by having a separate NAME_REGEX_SYSTEM configuration
    setting which applies when --system is specified.
* Modify Maintainer value to match the DebianMaintainerField
  specification.

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
my %config = ();
74
74
my $configfile;
75
75
my @defaults;
 
76
my $force;
 
77
 
76
78
 
77
79
unless ( GetOptions ("quiet|q" => sub {$verbose = 0; },
78
80
            "debug" => sub {$verbose = 2; },
85
87
            "remove-home" => \$pconfig{"remove_home"},
86
88
            "remove-all-files" => \$pconfig{"remove_all_files"},
87
89
            "backup" => \$pconfig{"backup"},
88
 
            "backup-to=s" => \$pconfig{"backup_to"}
 
90
            "backup-to=s" => \$pconfig{"backup_to"},
 
91
            "force" => \$force
89
92
       ) ) {
90
93
    &usage;
91
94
    exit 1;
200
203
    
201
204
    my($dummy1,$dummy2,$uid);
202
205
 
203
 
    # Check if there is more than one account with the same uid
 
206
 
204
207
 
205
208
 
206
209
 
223
226
    unless(exist_user($user)) {
224
227
        fail (2,gtx("The user `%s' does not exist.\n"),$user);
225
228
    }
 
229
    
 
230
    # Warn in any case if you want to remove the root account 
 
231
    if ((defined($pw_uid)) && ($pw_uid == 0) && (!defined($force)))  {
 
232
        printf (gtx("WARNING: You are just about to delete the root account (uid 0)\n"));
 
233
        printf (gtx("Usually this is never required as it may render the whole system unusable\n"));
 
234
        printf (gtx("If you really want this, call deluser with parameter --force\n"));
 
235
        printf (gtx("Stopping now without having performed any action\n"));
 
236
        exit 9;
 
237
    }
226
238
 
227
239
 
228
240
    if($config{"remove_home"} || $config{"remove_all_files"}) {
292
304
      }
293
305
 
294
306
      if($config{"backup"}) {
295
 
          s_printf (gtx("Backing up files to be removed to %s ...\n"),$config{"backup_to"});
296
 
          my $filesfile = new File::Temp(TEMPLATE=>"deluser.XXXXX", DIR=>"/tmp");
297
 
          my $filesfilename = $filesfile->filename;
298
 
          my $backup_name = $config{"backup_to"} . "/$user.tar";
299
 
          print "backup_name = $backup_name";
300
 
          print $filesfile join("\n",@files);
301
 
          $filesfile->close();
 
307
         s_printf (gtx("Backing up files to be removed to %s ...\n"),$config{"backup_to"});
 
308
         my $filesfile = new File::Temp(TEMPLATE=>"deluser.XXXXX", DIR=>"/tmp");
 
309
         my $filesfilename = $filesfile->filename;
 
310
         my $backup_name = $config{"backup_to"} . "/$user.tar";
 
311
         print "backup_name = $backup_name";
 
312
         print $filesfile join("\n",@files);
 
313
         $filesfile->close();
302
314
         my $tar = &which('tar');
303
 
          &systemcall($tar, "-cf", $backup_name, "--files-from", $filesfilename);
304
 
          chmod 0600, $backup_name;
305
 
         my $rootid = 0;
306
 
          chown $rootid, $rootid, $backup_name;
307
 
          unlink($filesfilename);
308
315
         my $bzip2 = &which('bzip2', 1);
309
316
         my $gzip = &which('gzip', 1);
310
 
          if($bzip2) {
311
 
              systemcall($bzip2, $backup_name);
312
 
          } elsif($gzip) {
313
 
              systemcall($gzip, "--best", $backup_name);
314
 
          }
 
317
         my $options = '';
 
318
         if($bzip2) {
 
319
             $backup_name = "$backup_name.bz2";
 
320
             $options = "--bzip2";
 
321
         } elsif($gzip) {
 
322
             $backup_name = "$backup_name.gz";
 
323
             $options = "--gzip";
 
324
         }
 
325
         &systemcall($tar, "-cf", $options, $backup_name, "--files-from", $filesfilename);
 
326
         chmod 0600, $backup_name;
 
327
         my $rootid = 0;
 
328
         chown $rootid, $rootid, $backup_name;
 
329
         unlink($filesfilename);
315
330
      }
316
331
 
317
332
      if(@files || @dirs) {
333
348
    s_printf (gtx("Removing user `%s' ...\n"),$user);
334
349
    my @members = get_group_members($maingroup);
335
350
    if (@members == 0) {
336
 
        s_printf (gtx("Warning: Removing group `%s', since no other user is part of it.\n"), $maingroup);    
 
351
        s_printf (gtx("Warning: group `%s' has no more members.\n"), $maingroup);    
337
352
    }
338
353
    my $userdel = &which('userdel');
339
354
    &systemcall($userdel, $user);