📄 mactime.base
字号:
print "Timezone: $ENV{TZ}\n"; } print "passwd File: $PASSWD" if ($PASSWD ne ""); if ($GROUP ne "") { print "\t" if ($PASSWD ne ""); print "group File: $GROUP"; } print "\n" if (($PASSWD ne "") || ($GROUP ne "")); print "\n";}## Print the time line#sub print_tl { my $prev_day = ""; # has the format of 'day day_week mon year' my $prev_hour = ""; # has just the hour and is used for hourly index my $prev_cnt = 0; my $old_date_string = ""; my $delim = ":"; if ($COMMA != 0) { print "Date,Size,Type,Mode,UID,GID,Meta,File Name\n"; $delim = ","; } for my $key (sort { $a cmp $b } keys %time2macstr) { my $time; my $inode; my $file; if ($key =~ /^(\d+),([\d-]+),(.*)$/) { $time = $1; $inode = $2; $file = $3; } else { next; } my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($time); # the month here is 0-11, not 1-12, like what we want $mon++; print"\t($sec,$min,$hour,MDay: $mday,M: $mon,$year,$wday,$yday,$isdst) = ($time)\n" if $debug; # # cosmetic change to make it look like unix dates # $mon = "0$mon" if $mon < 10; $mday = "0$mday" if $mday < 10; $hour = "0$hour" if $hour < 10; $min = "0$min" if $min < 10; $sec = "0$sec" if $sec < 10; my $yeart = $year + 1900; # How do we print the date? # my $date_string; if ($year_first) { if ($month_num) { $date_string = "$yeart $mon $mday $digit_to_day{$wday} $hour:$min:$sec"; } else { $date_string ="$yeart $digit_to_month{$mon} $mday $digit_to_day{$wday} $hour:$min:$sec"; } } else { if ($month_num) { $date_string = "$digit_to_day{$wday} $mon $mday $yeart $hour:$min:$sec"; } else { $date_string ="$digit_to_day{$wday} $digit_to_month{$mon} $mday $yeart $hour:$min:$sec"; } } # # However, we only print the date if it's different from the one # above. We need to fill the empty space with blanks, though. # if ($old_date_string eq $date_string) { $date_string = " "; $prev_cnt++ if ($INDEX ne ""); } else { $old_date_string = $date_string; # Indexing code if ($INDEX ne "") { # First time it is run if ($prev_day eq "") { $prev_day = "$mday $wday $mon $yeart"; $prev_hour = $hour; $prev_cnt = 0; } # A new day, so print the results elsif ($prev_day ne "$mday $wday $mon $yeart") { my @prev_vals = split(/ /, $prev_day); my $date_str; if ($month_num) { $date_str = "$digit_to_day{$prev_vals[1]} " . "$prev_vals[2] " . "$prev_vals[0] ${prev_vals[3]}"; } else { $date_str = "$digit_to_day{$prev_vals[1]} " . "$digit_to_month{$prev_vals[2]} " . "$prev_vals[0] ${prev_vals[3]}"; } $date_str .= " $prev_hour:00:00" if ($INDEX_TYPE == $INDEX_HOUR); print INDEX "${date_str}${delim} $prev_cnt\n"; # Reset $prev_cnt = 0; $prev_day = "$mday $wday $mon $yeart"; $prev_hour = $hour; } # Same day, but new hour elsif (($INDEX_TYPE == $INDEX_HOUR) && ($prev_hour != $hour)) { my @prev_vals = split(/ /, $prev_day); if ($month_num) { print INDEX "$digit_to_day{$prev_vals[1]} " . "$prev_vals[2] " . "$prev_vals[0] ${prev_vals[3]} " . "$prev_hour:00:00${delim} $prev_cnt\n"; } else { print INDEX "$digit_to_day{$prev_vals[1]} " . "$digit_to_month{$prev_vals[2]} " . "$prev_vals[0] ${prev_vals[3]} " . "$prev_hour:00:00${delim} $prev_cnt\n"; } # Reset $prev_cnt = 0; $prev_hour = $hour; } $prev_cnt++; } } # # Muck around with the [mac]times string to make it pretty. # my $mactime_tmp = $time2macstr{$key}; my $mactime = ""; if ($mactime_tmp =~ /m/) { $mactime = "m"; } else { $mactime = "."; } if ($mactime_tmp =~ /a/) { $mactime .= "a"; } else { $mactime .= "."; } if ($mactime_tmp =~ /c/) { $mactime .= "c"; } else { $mactime .= "."; } if ($mactime_tmp =~ /b/) { $mactime .= "b"; } else { $mactime .= "."; } my ($ls, $uids, $groups, $size) = split(/:/, $file2other{$file}); print "FILE: $file MODES: $ls U: $uids G: $groups S: $size\n" if $debug; if ($COMMA == 0) { printf("%24s %8s %3s %s %-8s %-8s %-8s %s\n", $date_string, $size, $mactime, $ls, $uids, $groups, $inode, $file); } else { printf("%s,%s,%s,%s,%s,%s,%s,%s\n", $old_date_string, $size, $mactime, $ls, $uids, $groups, $inode, $file); } } # Finish the index page for the last entry if (($INDEX ne "") && ($prev_cnt > 0)) { my @prev_vals = split(/ /, $prev_day); my $date_str; if ($month_num) { $date_str = "$digit_to_day{$prev_vals[1]} " . "$prev_vals[2] " . "$prev_vals[0] ${prev_vals[3]}"; } else { $date_str = "$digit_to_day{$prev_vals[1]} " . "$digit_to_month{$prev_vals[2]} " . "$prev_vals[0] ${prev_vals[3]}"; } $date_str .= " $prev_hour:00:00" if ($INDEX_TYPE == $INDEX_HOUR); print INDEX "${date_str}${delim} $prev_cnt\n"; close INDEX; }}## Routines for reading and caching user and group information. These# are used in multiple programs... it caches the info once, then hopefully# won't be used again.## Steve Romig, May 1991.## Provides a bunch of routines and a bunch of arrays. Routines# (and their usage):## load_passwd_info($use_getent, $file_name)## loads user information into the %uname* and %uid* arrays# (see below).## If $use_getent is non-zero:# get the info via repeated 'getpwent' calls. This can be# *slow* on some hosts, especially if they are running as a# YP (NIS) client.# If $use_getent is 0:# if $file_name is "", then get the info from reading the# results of "ypcat passwd" and from /etc/passwd. Otherwise,# read the named file. The file should be in passwd(5)# format.## load_group_info($use_gentent, $file_name)## is similar to load_passwd_info.## Information is stored in several convenient associative arrays:## %uid2names Assoc array, indexed by uid, value is list of# user names with that uid, in form "name name# name...".## %gid2members Assoc array, indexed by gid, value is list of# group members in form "name name name..."## %gname2gid Assoc array, indexed by group name, value is# matching gid.## %gid2names Assoc array, indexed by gid, value is the# list of group names with that gid in form# "name name name...".## You can also use routines named the same as the arrays - pass the index# as the arg, get back the value. If you use this, get{gr|pw}{uid|gid|nam}# will be used to lookup entries that aren't found in the cache.## To be done:# probably ought to add routines to deal with full names.# maybe there ought to be some anal-retentive checking of password# and group entries.# probably ought to cache get{pw|gr}{nam|uid|gid} lookups also.# probably ought to avoid overwriting existing entries (eg, duplicate# names in password file would collide in the tables that are# indexed by name).## Disclaimer:# If you use YP and you use netgroup entries such as# +@servers::::::# +:*:::::/usr/local/utils/messages# then loading the password file in with &load_passwd_info(0) will get# you mostly correct YP stuff *except* that it won't do the password and# shell substitutions as you'd expect. You might want to use# &load_passwd_info(1) instead to use getpwent calls to do the lookups,# which would be more correct.### minor changes to make it fit with the TCT program, 9/25/99, - dan# A whole lot removed to clean it up for TSK - July 2008 - Brian#package main;my $passwd_loaded = 0; # flags to use to avoid reloading everythingmy $group_loaded = 0; # unnecessarily...## Update user information for the user named $name. We cache the password,# uid, login group, home directory and shell.#sub add_pw_info { my ($name, $tmp, $uid) = @_; if ((defined $name) && ($name ne "")) { if ((defined $uid) && ($uid ne "")) { if (defined($uid2names{$uid})) { $uid2names{$uid} .= " $name"; } else { $uid2names{$uid} = $name; } } }}## Update group information for the group named $name. We cache the gid# and the list of group members.#sub add_gr_info { my ($name, $tmp, $gid) = @_; if ((defined $name) && ($name ne "")) { if ((defined $gid) && ($gid ne "")) { if (defined($gid2names{$gid})) { $gid2names{$gid} .= " $name"; } else { $gid2names{$gid} = $name; } } }}sub load_passwd_info { my ($file_name) = @_; my (@pw_info); if ($passwd_loaded) { return; } $passwd_loaded = 1; open(FILE, $file_name) || die "can't open $file_name"; while (<FILE>) { chop; if ($_ !~ /^\+/) { &add_pw_info(split(/:/)); } } close(FILE);}sub load_group_info { my ($file_name) = @_; my (@gr_info); if ($group_loaded) { return; } $group_loaded = 1; open(FILE, $file_name) || die "can't open $file_name"; while (<FILE>) { chop; if ($_ !~ /^\+/) { &add_gr_info(split(/:/)); } } close(FILE);}## Split a time machine record.#sub tm_split { my ($line) = @_; my (@fields); for (@fields = split(/\|/, $line)) { s/%([A-F0-9][A-F0-9])/pack("C", hex($1))/egis; } return @fields;}1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -