»
S
I
D
E
B
A
R
«
Limiting Users’ Mail Access in Qmail
Sep 17th, 2010 by Anand Shah

Some organizations grant different amounts of access to email to different users. In particular, some are allowed to send mail outside the organization and some can’t.

One approach that’s a little harder to set up but easier to administer is to use a single copy of qmail but to check the mail as users send it. If you use the old-fashioned fixup scheme to handle injected mail, you can check whether a user is allowed to send external mail in the fixup script. Modify ~alias/.qmail-fixup-default to something like this:

    | bouncesaying ‘Permission denied’ [ "@$HOST" != "@fixme" ]
    | ./checkrestrict
    | qmail-inject -f “$SENDER” — “$DEFAULT”
    checks whether the sender is in a list of authorized users.


Example:- checkrestrict script for .qmail-fixme

    #!/bin/sh
    # inherit $SENDER and $DEFAULT from the .qmail file

    case “$DEFAULT” in
    *@example.com) # our domain, always permitted
    exit 0 ;;
    *@*) # external address
    if egrep -q “^($SENDER)$” authorized-users
    then
    exit 0
    else
    bouncesaying “You cannot send external mail.”
    fi ;;
    *) # local mail, always permitted
    exit 0 ;;
    esac

This script needs to be ruggedized a little, because mail from user fred might have a sender of fred or fred@example.com depending on how his mail program is set up, and a local recipient address might be mary@EXAMPLE.COM in uppercase, but the checking remains quite simple.

Perl script to uninstall Modules Cleanly
Sep 14th, 2010 by Anand Shah

A script which would help deleting modules cleanly from your system.

    #!/usr/local/bin/perl -w

    use strict;
    use IO::Dir;
    use ExtUtils::Packlist;
    use ExtUtils::Installed;

    sub emptydir($) {
    my ($dir) = @_;
    my $dh = IO::Dir->new($dir) || return(0);
    my @count = $dh->read();
    $dh->close();
    return(@count == 2 ? 1 : 0);
    }

    # Find all the installed packages
    print(”Finding all installed modules…\n”);
    my $installed = ExtUtils::Installed->new();

    foreach my $module (grep(!/^Perl$/, $installed->modules())) {
    my $version = $installed->version($module) || “???”;
    print(”Found module $module Version $version\n”);
    print(”Do you want to delete $module? [n] “);
    my $r = <>;
    chomp($r);
    if ($r && $r =~ /^y/i) {
    # Remove all the files
    foreach my $file (sort($installed->files($module))) {
    print(”rm $file\n”);
    unlink($file);
    }
    my $pf = $installed->packlist($module)->packlist_file();
    print(”rm $pf\n”);
    unlink($pf);
    foreach my $dir (sort($installed->directory_tree($module))) {
    if (emptydir($dir)) {
    print(”rmdir $dir\n”);
    rmdir($dir);
    }
    }
    }
    }

Note: Please check the script before trying; it has always worked for me; exceptions cannot be denied.

»  Substance: WordPress   »  Style: Ahren Ahimsa