/*
 *  This file is part of ixnet.library for the Amiga.
 *  Copyright (C) 1996 Jeff Shepherd
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  $Id:$
 *
 *  $Log: $
 *
 */

#define _KERNEL
#include "ixnet.h"
#include "kprintf.h"
#include <grp.h>
#include <unistd.h>
#include <stdarg.h>

int getgroups(int gidsetlen, int *gidset)
{
    int err = -1;
    struct ixnet *p = (struct ixnet *)u.u_ixnet;

    switch (p->u_networkprotocol) {
	case IX_NETWORK_AMITCP:
	    err = UG_getgroups(gidsetlen,gidset);

	    if (err == -1) {
		errno = ug_GetErr();
	    }
	break;

	case IX_NETWORK_AS225:
	    err = SOCK_getgroups(gidsetlen,gidset);
	break;
    }
    return err;
}

gid_t
getgid(void)
{
    register struct ixnet *p = (struct ixnet *)u.u_ixnet;
    register int network_protocol = p->u_networkprotocol;
    gid_t retval;

    switch(network_protocol) {
	case IX_NETWORK_AMITCP:
	    retval = UG_getgid();
	break;

	default: /* case IX_NETWORK_AS225: */
	    retval = SOCK_getgid();
	break;
    }
    return retval;
}

gid_t
getegid(void)
{
    register struct ixnet *p = (struct ixnet *)u.u_ixnet;
    register int network_protocol = p->u_networkprotocol;

    switch(network_protocol) {
	case IX_NETWORK_AMITCP:
	    return UG_getegid();

	default: /* case IX_NETWORK_AS225: */
	    return SOCK_getgid();
    }
}

int setregid(int rgid, int egid)
{
  struct ixnet *p = (struct ixnet *)u.u_ixnet;

  if (p->u_networkprotocol == IX_NETWORK_AMITCP)
    return UG_setregid(rgid, egid);
  return 0;
}

int setgid(gid_t gid)
{
  struct ixnet *p = (struct ixnet *)u.u_ixnet;

  if (p->u_networkprotocol == IX_NETWORK_AMITCP)
    return UG_setgid(gid);
  return 0;
}

int setegid(gid_t gid)
{
  return setregid(getgid(),gid);
}
