[BACK]Return to unix_auth.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tcfs

File: [local] / src / usr.bin / tcfs / Attic / unix_auth.c (download)

Revision 1.4, Tue Jun 20 08:01:21 2000 UTC (23 years, 11 months ago) by fgsch
Branch: MAIN
CVS Tags: OPENBSD_3_2_BASE, OPENBSD_3_2, OPENBSD_3_1_BASE, OPENBSD_3_1, OPENBSD_3_0_BASE, OPENBSD_3_0, OPENBSD_2_9_BASE, OPENBSD_2_9, OPENBSD_2_8_BASE, OPENBSD_2_8
Changes since 1.3: +2 -0 lines

weird. missing OpenBSD tags.

/*	$OpenBSD: unix_auth.c,v 1.4 2000/06/20 08:01:21 fgsch Exp $	*/

/*
 *	Transparent Cryptographic File System (TCFS) for NetBSD 
 *	Author and mantainer: 	Luigi Catuogno [luicat@tcfs.unisa.it]
 *	
 *	references:		http://tcfs.dia.unisa.it
 *				tcfs-bsd@tcfs.unisa.it
 */

/*
 *	Base utility set v0.1
 */

#include <sys/param.h>
#include <limits.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <miscfs/tcfs/tcfs.h>
#include "tcfslib.h"
#include "tcfserrors.h"

int
unix_auth(char **user, char **password, int flag)
{
	char *luser, *passwd;
	struct passwd *passentry;

	luser = (char *)calloc(LOGIN_NAME_MAX, sizeof(char));
	passwd = (char *)calloc(_PASSWORD_LEN, sizeof(char));

	if (!luser || !passwd)
		tcfs_error(ER_MEM, NULL);

	if (flag) {
		passentry = getpwuid(getuid());
		strlcpy(luser, passentry->pw_name, LOGIN_NAME_MAX);
	} else {
		printf("Enter user: ");
		fgets(luser, LOGIN_NAME_MAX, stdin);
		luser[strlen(luser)-1] = '\0';
		passentry = getpwnam(luser);
	}

	passwd = getpass("Password:");
	
	if (passentry == NULL) {
		bzero(passwd, strlen(passwd));
		return (0);
	}

	if (strcmp(crypt(passwd, passentry->pw_passwd), passentry->pw_passwd))
		return (0);

	*user = luser;
	*password = passwd;

	return (1);
}