Error 534 & onlinefiles
Posted in 1998
While looking for an answer to why I'm getting an error 534,
"Can't create explain file", I saw that it was possibly caused by
informix file permissions (& maybe the permission of the oninit
file in particular), and that all the files and their permissions
are listed in the 'onlinefiles' file. So I wrote this utility to check
all the files in 'onlinefiles', and it may be of use to someone
else, and I'll accept any criticisms (& complements) of it.
I'm not the DBA, so I don't know for sure if fixing the permissions
actually fixes the original problem, 'cause he hasn't got round
to fixing the permissions.
Cheers,
Douglas Wilson
doug> cat onfileschk
#!/usr/bin/perl -w
# Reads an Informix 'onlinefiles'-type file from stdin
# And validates info actual owners, groups, and permissions against
what
# the 'onlinefiles' file says the files should be
#
# Input: stdin (or filename on cmd line)
# Outputs to stdout
# Usage: onfileschk <filename>
use strict;
use integer;
# Create arrays for user and group names
my %unames;
open(PASSWD, "</etc/passwd") or die "Can't open passwd file:$!\\n";
while (<PASSWD>) {
my ($uname, $dummy, $uid, $gid, $dummy) = split(/:/,$_,5);
$unames{$uid}=$uname;
}
close PASSWD;
my %gnames;
open(GROUP, "</etc/group") or die "Can't open group file:$!\\n";
while (<GROUP>) {
my ($gname, $dummy, $gid, $dummy) = split(/:/,$_,4);
$gnames{$gid}=$gname;
}
close GROUP;
# Base directory to validate files in
my $path=$ENV{"INFORMIXDIR"};
open(ONFILE, "<$path/etc/onlinefiles") or die "Can't open onlinefiles:
$!\\n";
LOOP:
while (<ONFILE>) {
# Just process lines that start with lowercase alpha, number, or '.'
next unless /^[a-z0-9.]/;
my ($file, $p_owner, $p_group, $p_perms, $action1, $action2) = split;
# Check if file was renamed (not just copied)
if ($action1 eq "RENAME") {
if (not -f "$path/$action2") {
print "Rename $file to $action2\\n";
next LOOP;
}
if (-f "$path/$file") {
print "File $file renamed but original still exists\\n";
}
$file = $action2;
}
# Check if file was removed
if ($action1 eq "REMOVE") {
print "File not removed: $path/$file\\n" if -f "$path/$file";
next LOOP;
}
print("Can't find file $path/$file\\n"),next
unless my ($dummy,$dummy,$mode,$dummy,$uid,$gid) =
stat("$path/$file");
if ($unames{$uid} ne $p_owner) {
print "Wrong owner for $file: is $unames{$uid} should be
$p_owner\\n";
}
if ($gnames{$gid} ne $p_group) {
print "Wrong group for $file: is $gnames{$gid} should be
$p_group\\n";
}
$mode &= 07777;
if ($mode ne oct($p_perms)) {
$mode = sprintf("%o",$mode);
print "Wrong permissions for $file: is $mode should be $p_perms\\n";
}
}
close ONFILE;