2 # Functions for freebsd format last output
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)
13 # Returns 0 for normal group file (/etc/group only) and 2 for shadowed
14 # (/etc/group and /etc/gshadow)
20 # open_last_command(handle, user)
23 local ($fh, $user) = @_;
24 open($fh, "last $user |");
27 # read_last_line(handle)
28 # Parses a line of output from last into an array of
29 # user, tty, host, login, logout, period
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);
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);
48 # Returns 1 if pam is set up to use MD5 encryption
52 &open_readfile(CONF, "/etc/login.conf");
56 $md5 = 1 if (/passwd_format\s*=\s*md5/);
59 &open_readfile(CONF, "/etc/auth.conf");
63 $md5 = 1 if (/crypt_default\s*=\s*md5/);