ServDoc_0230sendmail

Code Index:



NAME

ServDoc_sendmail - describe the sendmail daemon


VERSION

$Id: ServDoc_0230sendmail,v 1.7 2004/02/22 21:27:22 uherbst Exp $


SYNOPSIS

ServDoc_sendmail [-h|help] [-v|version] [--debug SENDM,intensity]


DESCRIPTION

ServDoc_sendmail describe the sendmail daemon (if installed).

We don't check, if sendmail is running, because many servers have just a local installed sendmail that isn't running as daemon.


OPTIONS

-h|help
This help.

-v|version
Version

--debug SENDM,intensity
Turn on Debugging for that module.

The debug feature for that module is named ``SENDM''.


AUTHORS

Ulrich Herbst <Ulrich.Herbst@gmx.de>


#!/usr/bin/perl -w

#----------------------------------------------------------------------

# standard perl modules
use strict;                       # print error about unknown variables ...
use English;                      # long internal variable names;
use FindBin;                      # In which directory is ServDoc itself ?
                                  # There has to be the module and the lib dir!
use lib $FindBin::Bin. "/lib";    # Here are the ServDoc-perl-modules
use File::Basename;
use vars qw($options);

# our own perl modules
use ServDoc;

######################################################################
#
# Output relevant Variables
#
# Should we delete comments from sendmail.cf in the output ?
#my $delcomments='^#.*$';       # delete comments
my $delcomments='';            # preserve comments
#
# Should we delete blank lines from sendmail.cf in the output ?
my $delblanklines=0;           # 1: delete blank linkes
#                              # 0: don't delete blank lines
######################################################################

#----------------------------------------------------------------------

$options->{Version} = '$Id: ServDoc_0230sendmail,v 1.7 2004/02/22 21:27:22 uherbst Exp $';

# We need the cmdline to call the modules with the same debug options.
$options->{cmdline} = join " ", @ARGV;

sub debug { ServDoc_debug( "SENDM", $options, shift, shift ); }

$options = &process_cmdline($options);

my $h='Net%%+Services%%+Sendmail%%+';
%{$options->{lang}->{en}}=
  (
   version         => $h . "Version, Compile Parameters",
   version_short   => i18n_std('cmd','sendmail -bp -d0.1'),
   version_long    => '',

   config          => $h . 'Configuration',
   config_long     => '',

   alias           => $h . 'EMail Aliases',
   alias_long      => "Where go your local email users to ?",

   relay           => $h . 'Relaying',
   relay_long      => 'Which servers are allowed for relaying ?',

   local           => $h . 'Local Mailhost Names',
   local_long      => 'For which host/domainnames does sendmail '.
   'receive mails ?',

   mtab            => $h . 'Mail Routing',
   mtab_long       => 'Where is mail for a specific receiving domain '.
   'sent ?',

   virt            => $h . 'Virtual Mailhost Configuration',
   virt_long       => "",

   generic         => $h . 'From: Header Configuration',
   generic_long    => '',
  );

$h='Netzwerk%%+Dienste%%+Sendmail%%+';
%{$options->{lang}->{de}}=
  (
   version         => $h . "Version, einkompilierte Parameter",
   version_short   => i18n_std('cmd','sendmail -bp -d0.1'),
   version_long    => '',

   config          => $h . 'Konfiguration',
   config_long     => '',

   alias           => $h . 'EMail Aliases',
   alias_long      => "Wo gehen Mails an lokale Benutzer hin ?",

   relay           => $h . 'Relaying',
   relay_long      => 'Von welchen Servern werden Emails '.
   'weitergeleitet (relayed)?',

   local           => $h . 'Namen des eigenen Mailservers',
   local_long      => 'F&uuml;r welche Rechner-/Domainnamen '.
   'empf&auml;ngt dieser Server Emails ?',

   mtab            => $h . 'Mail Routing',
   mtab_long       => 'Wohin wird welche Mail geschickt ?',

   virt            => $h . 'Virtual Mailhost Konfiguration',
   virt_long       => "",

   generic         => $h . 'From: Header Konfiguration',
   generic_long    => '',
  );
debug( 9, i18n_std('running',$0));

#----------------------------------------------------------------------

# Main

# Here is your useful code.

my $file;

# check if we have really sendmail installed. (and not postfix,
# qmail,...)

# Is it sufficient to check for /etc/sendmail.cf ?
if ( !( -e "/etc/sendmail.cf" or -e "/etc/mail/sendmail.cf" )) { exit 0; }

# Maybe it's sufficent to check, if /usr/sbin/sendmail is a binary or
# a link to binary called "sendmail" (and not exim...)

if (-l "/usr/sbin/sendmail") {
  my $smlink=readlink("/usr/sbin/sendmail");
  if (basename($smlink) !~ m/sendmail/) {
    exit 0;
  }
}

# Version
my $dummy="*";
$dummy="0" if ($OSNAME =~ /aix/);
report_i18n('cmd','version','sendmail -bp -d0.1',UID=>$dummy);

# Port:
# FIXME

# sendmail.cf is always (?) on /etc/sendmail.cf
# We need sendmail.cf for later configurations...
my $sendmailpath= "/etc/sendmail.cf";
my $sendmailcf = readfile ($sendmailpath);

if (! $sendmailcf) {$sendmailpath="/etc/mail/sendmail.cf";
		    $sendmailcf = readfile($sendmailpath);}

report_string(i18n_mesg('config'),
              i18n_std('file',$sendmailpath),
              i18n_mesg('config_long'),
	      $sendmailcf,
	      delcomment    => $delcomments,
	      delblanklines => $delblanklines,
	     );

# The matching xxx.m4 ?
# Oh, I think that isn't so easy....
# FIXME :-)

# /etc/aliases
# O AliasFile= is a "new" Configuration (ok since Sendmail 8.x => 1996?)
# Does anyone know the old configuration ?
# FIXME
if ($file = get_sendmailcf_entry("O AliasFile=")) {
  report_file(i18n_mesg('alias'),
              i18n_std('file',$file),
              i18n_mesg('alias_long'),
              $file);
}

# relay-domains/access,... if exists
if ($file = get_sendmailcf_entry("Kaccess hash -o")) {
  $file =~ s/(.*).db/$1/;
  report_file(i18n_mesg('relay'),
              i18n_std('file',$file),
              i18n_mesg('relay_long'),
              $file);
}

# sendmail.cw, local-host-names
if ($file = get_sendmailcf_entry("Fw")) {
  report_file(i18n_mesg('local'),
              i18n_std('file',$file),
              i18n_mesg('local_long'),
              $file);
}

# mailertable
if ($file = get_sendmailcf_entry("Kmailertable hash -o")) {
  $file =~ s/(.*).db/$1/;
  report_file(i18n_mesg('mtab'),
              i18n_std('file',$file),
              i18n_mesg('mtab_long'),
              $file);
}

# virtusertable
if ($file = get_sendmailcf_entry("Kvirtuser hash -o")) {
  $file =~ s/(.*).db/$1/;
  report_file(i18n_mesg('virt'),
              i18n_std('file',$file),
              i18n_mesg('virt_long'),
              $file);
}

# generics
if ($file = get_sendmailcf_entry("Kgenerics hash -o")) {
  $file =~ s/(.*).db/$1/;
  report_file(i18n_mesg('generic'),
              i18n_std('file',$file),
              i18n_mesg('generic_long'),
              $file);
}

#----------------------------------------------------------------------
sub get_sendmailcf_entry {
  # argument: string what is in that line before the value
  my $arg = shift;
  my @lines=grep /$arg/,
            grep !/^#/,
            split /\n/,$sendmailcf;
  if ($#lines > -1) {
    # we return just the first value!
    my $rval = $lines[0];
    $rval =~ s{.*$arg\s*(.*?)\s*}{$1};
    return $rval;
  }
  return 0;
}
exit 0;