/* setug.c */

/* Copyright 2000 by Eberhard Mattes <em-gw@windhager.de>
   Donated to the public domain.  No warranty.

   2000-04-29 Initial version */

#include <stdlib.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>
#include <errno.h>
#include "firewall.h"
#include "libemfw.h"

extern int libemfw_uid;
extern int libemfw_gid;

void set_userid_groupid (void)
{
  if (libemfw_gid != -1 && setgid (libemfw_gid) != 0)
    {
      syslog (LLEV, "fwtksyserr: cannot setgid %d: %s", libemfw_gid, strerror(errno));
      exit (1);
    }
  if (libemfw_uid != -1 && setuid (libemfw_uid) != 0)
    {
      syslog (LLEV, "fwtksyserr: cannot setuid %d: %s", libemfw_uid, strerror(errno));
      exit (1);
    }
}
