-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeluser
executable file
·65 lines (48 loc) · 1.3 KB
/
deluser
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/perl
#
# deluser - utility to delete users
#
# Copyright (c) Timo Kokkonen <[email protected]> 2000-2003.
#
require 5;
use Getopt::Long;
use Sauron::DB;
use Sauron::Util;
use Sauron::BackEnd;
use Sauron::Sauron;
load_config();
##############################################
my($id,$res,$i,$t,@q);
GetOptions("user=s","help|h");
if ($opt_help) {
print "syntax: $0 [--help] [--user=<username>]\n";
print "\n" if ($opt_help);
exit(0);
}
db_connect();
unless ($opt_user) {
print "Enter user to be deleted: ";
chomp($opt_user = <STDIN>);
$i=1;
}
fatal("Invalid username '$opt_user'!") unless ($opt_user =~ /^\S+$/);
fatal("Cannot find user '$opt_user' from users table!")
if (get_user($opt_user,\%user) < 0);
$id=$user{id};
if ($i) { # ask confirmation only in interactive session...
print "\t Username: $opt_user (id=$id)\n",
"\t Longname: $user{name}\n",
"\tsuperuser: " . ($user{superuser} eq 't' ? 'Yes' : 'No') ."\n",
"\t email; $user{email}\n",
"\t comment: $user{comment}\n";
print "Delete this user [y/n]?";
chomp ($t=<STDIN>);
unless ($t eq 'y' || $t eq 'Y') {
print "User not deleted!\n";
exit(1);
}
}
fatal("Cannot delete user from users table!") if (delete_user($id) < 0);
print "User $opt_user deleted succesfully.\n";
exit(0);
# eof