lib/courier-authlib/success.c
author "Tomas Zeman <tzeman@volny.cz>"
Sun, 20 Jan 2008 00:22:09 +0100
changeset 2 b3afb9f1e801
parent 0 6f7a81934006
permissions -rw-r--r--
Imported vmailmgr-0.97

/*
** Copyright 1998 - 1999 Double Precision, Inc.  See COPYING for
** distribution information.
*/

#include	"auth.h"

#include	<stdio.h>
#include	<errno.h>
#include	<stdlib.h>
#include	<string.h>

#if	HAVE_UNISTD_H
#include	<unistd.h>
#endif

static const char rcsid[]="$Id: success.c,v 1.2 2000/12/18 20:20:10 bruce Exp $";

void authsuccess(const char *homedir,
	const char *username,
	const uid_t	*uid,
	const gid_t	*gid,
	const char	*authaddr,
	const char	*authfullname)
{
static char	*authaddr_buf=0;
static char	*authfullname_buf=0;
char	*p;

	if (username)
	{
		if (gid)
			authchangegroup(*gid);
		authchangeusername(username, gid);
	}
	else
	{
		if (!uid || !gid)
		{
			write(2, "AUTHFAILURE\n", 12);
			authexit(1);
		}
		authchangeuidgid(*uid, *gid);
	}

	if (chdir(homedir))
	{
		perror("chdir");
		authexit(1);
	}

	if (!authaddr)	authaddr="";
	if (authaddr_buf)	free(authaddr_buf);
	authaddr_buf=malloc(sizeof("AUTHADDR=")+strlen(authaddr));
	if (!authaddr_buf)
	{
		perror("malloc");
		authexit(1);
	}
	strcat(strcpy(authaddr_buf, "AUTHADDR="), authaddr);

	if (!authfullname)	authfullname="";
	if (authfullname_buf)	free(authfullname_buf);
	authfullname_buf=malloc(sizeof("AUTHFULLNAME=")+strlen(authfullname));
	if (!authfullname_buf)
	{
		perror("malloc");
		authexit(1);
	}
	strcat(strcpy(authfullname_buf, "AUTHFULLNAME="), authfullname);

	/* Get rid of GECOS crud */

	p=authfullname_buf+strlen(authfullname_buf);
	while (*--p == ',')
		*p=0;
	putenv(authaddr_buf);
	putenv(authfullname_buf);
}

void authdummy()
{
}