/*
 * DANG_BEGIN_MODULE
 *
 * This file holds the priv_on/priv_off code
 *
 * DANG_END_MODULE
 *
 * DANG_BEGIN_CHANGELOG
 *
 * $Date: $
 * $Source: $
 * $Revision: $
 * $State: $
 *
 * $Log: $
 *
 * DANG_END_CHANGELOG
 */

#include "dosemu.h"
#include "base/misc.h"

static uid_t euid;
static gid_t egid;
static inited = 0;

int priv_on(void)
{
  g_printf("PRIV: priv_on()\n");

  if (seteuid(euid) || setegid(egid)) {
    error("PRIV: Cannot enable privs!\n");
    return (0);
  }
  return (1);
}

int priv_off(void)
{
  g_printf("PRIV: priv_off()\n");

  if (!inited) {
    euid = geteuid();
    egid = getegid();
    inited = 1;
  }
  if (seteuid(getuid()) || setegid(getgid())) {
    error("PRIV: Cannot disable privs!\n");
    return (0);
  }
  return (1);
}

