#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>

/*
 *
 * Compile via "cc -o qmail-scanner-queue qmail-scanner-queue.c"
 * and install as /var/qmail/bin/qmail-scanner-queue.
 * chown root:qmail /var/qmail/bin/qmail-scanner-queue 
 * chmod 4711 /var/qmail/bin/qmail-scanner-queue
 *
 * Then change the first line of /var/qmail/bin/qmail-scanner-queue.pl
 * to "#!/usr/bin/perl -T "
 * and "chown qmailq.qmail /var/qmail/bin/qmail-scanner-queue.pl"
 * and "chmod 0755 /var/qmail/bin/qmail-scanner-queue.pl"
 *
 * IMPORTANT! 
 * Remmember to change the env var QMAILQUEUE to "/var/qmail/bin/qmail-scanner-queue"
 *
 * QMAILQUEUE="/var/qmail/bin/qmail-scanner-queue" export QMAILQUEUE
 *
 */

#define REAL_PATH "/var/qmail/bin/qmail-scanner-queue.pl"

struct stat file_stat;

main(ac, av)
  char **av;
{
  stat(REAL_PATH,&file_stat);

  if (setgid(file_stat.st_gid) < 0) {
    fprintf(stderr,"Can't change group for %s with %d (%s)\n",REAL_PATH,file_stat.st_gid,strerror(errno));
    exit(0);
  }
  if (setuid(file_stat.st_uid) < 0) {
    fprintf(stderr,"Can't change user for %s with %d (%s)\n",REAL_PATH,file_stat.st_uid,strerror(errno));  
    exit(0);
  }
  execv(REAL_PATH, av);
}


