Hi,

I've written a little bit of perl to examine our users/assign file 
and check for errors/inconsistencies. It might be of use to others. 
It's attached.

Regards,

james
-- 
James Raftery (JBR54)  -  Programmer Hostmaster  -  IE TLD Hostmaster
   IE Domain Registry  -  www.domainregistry.ie  -  (+353 1) 706 2375
  "Managing 4000 customer domains with BIND has been a lot like
   herding cats." - Mike Batchelor, on [EMAIL PROTECTED]
#!/usr/bin/perl -w

# assign-lint. Reports obvious problems in assignments in a
# users/assign file as used by qmail-lspawn and created by
# qmail-newu.
#
# 6th July 2000, James Raftery <[EMAIL PROTECTED]>,
# IE Domain Registry, University College Dublin Computing Services.
#
# Usage:    assign-lint file
#           file is a path to a users/assign file.
#
# Example:  assign-lint /var/qmail/users/assign
#
# Comments, suggestions, improvements, bug-reports, patches, etc are
# welcomed.
# History:
# 6th July 2000: First release.

while (<>) {
        chomp;

        if (/^\.$/) {
                warn "Syntax error: Dot appears more than once.\n" if $dot;
                $dot = 1;
                next;
        }

        unless (/^(.)(\S*):(\S+):(\d+):(\d+):(\S+):(\S*):(\S*):$/) {
                warn "Syntax error, line $.: $_\n";
                next;
        }

        $assign_char = $1;
        $address = $2;
        $user = $3;
        $uid = $4;
        $gid = $5;
        $homedir = $6;
        $dash = ($7 ? $7 : "");
        $ext = ($8 ? $8 : "");

        if ($dot && !$warned_about_the_dot) {
                warn "Syntax error: Assignments found after the dot.\n";
                $warned_about_the_dot = 1;
        }


        if ($assign_char eq "=") {
                $assign_type = "simple";
        } elsif ($assign_char eq "+") {
                $assign_type = "wildcard";
        } else {
                warn "Bad assignment type in assignment '$address': $assign_char is 
invalid.\n";
        }


        @pwd_ent = getpwnam($user);

        if (@pwd_ent) {

                if ($uid != $pwd_ent[2]) {
                        warn "Bad uid in $assign_type assignment '$address' for user 
$user: $uid should be ", $pwd_ent[2], ".\n";
                }

                if ($gid != $pwd_ent[3]) {
                        warn "Bad gid in $assign_type assignment '$address' for user 
$user: $gid should be ", $pwd_ent[3], ".\n";
                }

                if (!-e $homedir) {
                        warn "Bad directory in $assign_type assignment '$address' for 
user $user: $homedir does not exist.\n";

                } elsif (!-d _) {
                        warn "Bad directory in $assign_type assignment '$address' for 
user $user: $homedir is not a directory.\n";

                } else {
                        @dir_stat = stat(_);
                        warn "Bad directory in $assign_type assignment '$address' for 
user $user: $homedir is not owned by $user.\n" if ($uid != $dir_stat[4]);

                        if (($assign_type eq "simple") && $dash && $ext) {
                                $qmail_file = "${homedir}/.qmail${dash}${ext}";
                                warn "Bad .qmail file in $assign_type assignment 
'$address' for user $user: $qmail_file not valid.\n" if (!-f $qmail_file);
                        }

                }

        } else {
                warn "Bad user in $assign_type assignment '$address': user $user does 
not exist.\n";
        }

}

exit;

Reply via email to