Handle hostnames with upper-case letters
[webmin.git] / useradmin / openserver-lib.pl
1 # openserver-lib.pl
2 # Functions for SCO openserver password file format
3
4 # passfiles_type()
5 # Returns 0 for old-style passwords (/etc/passwd only), 1 for FreeBSD-style
6 # (/etc/master.passwd), 2 for SysV (/etc/passwd & /etc/shadow), 3 for
7 # /etc/passwd with update via useradd, 4 for AIX (/etc/passwd &
8 # /etc/security/passwd), and 5 for SCO (/etc/passwd and short /etc/shadow)
9 sub passfiles_type
10 {
11 return 5;
12 }
13
14 # groupfiles_type()
15 # Returns 0 for normal group file (/etc/group only) and 2 for shadowed
16 # (/etc/group and /etc/gshadow)
17 sub groupfiles_type
18 {
19 return 0;
20 }
21
22 # open_last_command(handle, user)
23 sub open_last_command
24 {
25 local ($fh, $user) = @_;
26 open($fh, "last $user |");
27 }
28
29 # read_last_line(handle)
30 # Parses a line of output from last into an array of
31 #  user, tty, host, login, logout, period
32 sub read_last_line
33 {
34 local $fh = $_[0];
35 while(1) {
36         chop($line = <$fh>);
37         if (!$line) { return (); }
38         if ($line =~ /system boot/) { next; }
39         if ($line =~ /^(\S+)\s+(\S+)\s+(\S+)?\s+(\S+\s+\S+\s+\d+\s+\d+:\d+)\s+\-\s+(\d+:\d+)\s+\((\d+:\d+)\)/) {
40                 return ($1, $2, $3, $4, $5, $6);
41                 }
42         elsif ($line =~ /^(\S+)\s+(\S+)\s+(\S+)?\s+(\S+\s+\S+\s+\d+\s+\d+:\d+)\s+still/) {
43                 return ($1, $2, $3, $4);
44                 }
45         }
46 }
47
48 1;
49