/*
 * just a quick wrapper to run ircd
 *
 * Compile with:
 *
 * $ gcc -O2 -static -o run_irc run_irc.c
 * $ chmod 4555 run_irc
 *
 * (or use 4500 to only allow its owner to run it)
 *
 * This lets you easily run an ircd from any account on a machine.
 * This wrapper will simply setuid to the ircd account and run the ircd
 * binary.
 *
 * This file is based on a chroot wrapper by Vid 'Martin' Strpic'
 * <strpic@bofhlet.net>
 */

#define ROOTDIR "/var/ircd"
#define EXENAME "/var/ircd/ircd"
#define USER "ircd"

#include <pwd.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>

int main()
{
        struct passwd *pentry;

        pentry = getpwnam (USER);
        if (pentry == NULL) { perror ("no user"); exit (10); }

        if (chdir (ROOTDIR)) { perror ("chdir"); exit (1); }

        if (setregid (pentry->pw_gid, pentry->pw_gid)) { perror ("setregid"); exit (4); }
        if (setreuid (pentry->pw_uid, pentry->pw_uid)) { perror ("setreuid"); exit (5); }

        execl (EXENAME, EXENAME, NULL);

        perror ("exec"); exit (20);
}

