Handle hostnames with upper-case letters
[webmin.git] / useradmin / freebsd-lib.pl
1 # freebsd-lib.pl
2 # Functions for freebsd format last output
3
4 # passfiles_type()
5 # Returns 0 for old-style passwords (/etc/passwd only), 1 for FreeBSD-style
6 # (/etc/master.passwd) and 2 for SysV (/etc/passwd & /etc/shadow)
7 sub passfiles_type
8 {
9 return 1;
10 }
11
12 # groupfiles_type()
13 # Returns 0 for normal group file (/etc/group only) and 2 for shadowed
14 # (/etc/group and /etc/gshadow)
15 sub groupfiles_type
16 {
17 return 0;
18 }
19
20 # open_last_command(handle, user)
21 sub open_last_command
22 {
23 local ($fh, $user) = @_;
24 open($fh, "last $user |");
25 }
26
27 # read_last_line(handle)
28 # Parses a line of output from last into an array of
29 #  user, tty, host, login, logout, period
30 sub read_last_line
31 {
32 $fh = $_[0];
33 while(1) {
34         chop($line = <$fh>);
35         if (!$line) { return (); }
36         if ($line =~ /^(reboot|shutdown)/) { next; }
37         if ($line =~ /^(\S+)\s+(\S+)\s+(\S+)?\s+(\S+\s+\S+\s+\d+\s+\d+:\d+)\s+\-\s+(\S+)\s+\((\d+:\d+)\)/) {
38                 return ($1, $2, $3, $4, $5 eq "shutdown" ? "Shutdown" :
39                                         $5 eq "crash" ? "Crash" : $5, $6);
40                 }
41         elsif ($line =~ /^(\S+)\s+(\S+)\s+(\S+)?\s+(\S+\s+\S+\s+\d+\s+\d+:\d+)\s+still/) {
42                 return ($1, $2, $3, $4);
43                 }
44         }
45 }
46
47 # use_md5()
48 # Returns 1 if pam is set up to use MD5 encryption
49 sub use_md5
50 {
51 local $md5 = 0;
52 &open_readfile(CONF, "/etc/login.conf");
53 while(<CONF>) {
54         s/\r|\n//g;
55         s/#.*$//;
56         $md5 = 1 if (/passwd_format\s*=\s*md5/);
57         }
58 close(CONF);
59 &open_readfile(CONF, "/etc/auth.conf");
60 while(<CONF>) {
61         s/\r|\n//g;
62         s/#.*$//;
63         $md5 = 1 if (/crypt_default\s*=\s*md5/);
64         }
65 close(CONF);
66 return $md5;
67 }
68
69 1;
70