/* Several tricks for IBM AIX for Zmailer
   by Matti Aarnio <mea@utu.fi> <mea@nic.funet.fi>

   Mostly these are pulled in from various sources :)

   On your AIX machine, see:

      /usr/lpp/bos/bsdport(.tr)

   file for the information about how to do the porting of
   BSD-oriented software into AIX systems.
   (A PostScript rendered version is on Zmailers  doc/aix-bsdport.ps)

*/
#ifdef	AIX

#include <sys/types.h>
#include <sys/param.h>
#include <sys/id.h>
#include <sys/priv.h>


int
aixsetreuid(ruid,euid)
uid_t ruid, euid;
{
	/* Pulled in from WUARCHIVE's FTPD source.. */

	/* AIX 3 lossage.  Don't ask.  It's undocumented.  */
	priv_t priv;

	priv.pv_priv[0] = 0;
	priv.pv_priv[1] = 0;
	setgroups(NULL, NULL);
	if (setpriv(PRIV_SET|PRIV_INHERITED|PRIV_EFFECTIVE|PRIV_BEQUEATH,
		    &priv, sizeof(priv_t)) < 0 ||
	    setuidx(ID_REAL|ID_EFFECTIVE, ruid) < 0 ||
	    seteuid(euid) < 0) {
	  return -1;
	}
#ifdef UID_DEBUG
	lreply(230, "ruid=%d, euid=%d, suid=%d, luid=%d", getuidx(ID_REAL),
	       getuidx(ID_EFFECTIVE), getuidx(ID_SAVED), getuidx(ID_LOGIN));
	lreply(230, "rgid=%d, egid=%d, sgid=%d, lgid=%d", getgidx(ID_REAL),
	       getgidx(ID_EFFECTIVE), getgidx(ID_SAVED), getgidx(ID_LOGIN));
#endif
}

#else
static int dummy = 0; /* To please some compilers we have a non-void file..*/
#endif
