#
# Checks for 666 permissions on /etc/aliases.pag and /etc/aliases.dir
# since newaliases makes them that way.
#

$failed = 0;
if ($os{'version'} eq '4.0.5') {
  $file = '/usr/lib/aliases.{pag,dir}';
  @files = ('/usr/lib/aliases.pag', '/usr/lib/aliases.dir');
  $base = '/usr/lib';
  }
else {
  $file = '/etc/aliases.{pag,dir}';
  @files = ('/etc/aliases.pag', '/etc/aliases.dir');
  $base = '/etc';
  }
&pcheck($file);
foreach $file (@files) {
  if (-e $file) {
    $mode = substr(sprintf("%o", (stat($file))[2]), 3, 3);
    if ($mode ne '644') {
      &report("DANGER: $file vulnerability\n",
              "    When newaliases makes it's database files from\n",
              "    the $base/aliases file, it makes them\n",
              "    with the wrong permissions ($mode instead of 644).\n",
              "  To fix, do a\n",
              "      `chmod go-w $base/aliases.pag`\n",
              "      `chmod go-w $base/aliases.dir`\n",
              "    after running newaliases\n\n");
      $failed = 1;
      }
    }
  }


if ($failed) { &failed; exit 0; }
else { 
  &report("INFO: possible $file vulnerability\n",
          "    When newaliases makes it's database files from\n",
          "    the /etc/aliases file, it may make them with the wrong\n",
          "    permissions.  To fix, do a `chmod go-w $file`\n",
          "    after running newaliases.  It's not a hole now, but\n",
          "    when newaliases is run, it may become one.\n\n");
  &info;
  }

exit 0;
