/*
 * Copyright (c) 1992-2004 by Wayne C. Gramlich.
 * All rights reserved.
 */

/*
 * This file implements an interface to operating system services.
 */

#ifndef LIBC_EXPORTS_H
#include "libc_exports.h"
#endif

#ifndef STHEADERS_H
#include "stheaders.h"
#endif

#ifndef STDLIB_H
#include "stdlib.h"
#endif

#ifndef STR_EXPORTS_H
#include "str_exports.h"
#endif

#ifndef UNIX_ASSERT_H
#include "unix_assert.h"
#endif

#ifndef UNIX_DIRENT_H
#include "unix_dirent.h"
#endif

#ifndef UNIX_STDIO_H
#include "unix_stdio.h"
#endif

#ifdef LINUX
#ifndef UNIX_PWD_H
#include "unix_pwd.h"
#endif
#endif /* LINUX */

#ifndef UNIX_SYS_STAT_H
#include "unix_sys_stat.h"
#endif

#ifndef UNIX_TIME_H
#include "unix_time.h"
#endif

#ifdef LINUX
#ifndef UNIX_SYS_WAIT_H
#include "unix_sys_wait.h"
#endif
#endif /* LINUX */

#ifndef UNIX_UNISTD_H
#include "unix_unistd.h"
#endif

#ifndef VECTOR_EXPORTS_H
#include "vector_exports.h"
#endif

#ifdef LINUX
typedef struct passwd *Password, Password_struct;
#endif /* LINUX */
#ifdef WINDOWS
typedef int *Password, Password_struct;
#endif /* WINDOWS */
typedef void *In_stream;
typedef void *Out_stream;
typedef void *String;

#ifdef LINUX
static Password_struct password_struct = {
	(Str)0,		/* pw_name */
	(Str)0,		/* pw_passwd */
	0,		/* pw_uid */
	0,		/* pw_gid */
	(Str)0,		/* pw_gecos */
	(Str)0,		/* pw_dir */
	(Str)0		/* pw_shell */
};
#endif /* LINUX */
#ifdef WINDOWS
static Password_struct password_struct = 0;
#endif /* WINDOWS */
Password password___initial = &password_struct;

extern In_stream	in_stream__standard;
extern Out_stream	out_stream__standard;
extern Out_stream	out_stream__error;
extern String		string__unix_create(Str);
extern Str		string__unix_string(String);

static object___object password_initial_object = {
	"",				/* Package name */
	"user",				/* Type name */
	"??",				/* Object name */
	(type___reference *)0,		/*XXX: Fix me */
	(int *)0,			/* Size of character object */
	0,				/* Static needs count */
	(need___entry *)0, 		/*XXX: Fix me Static needs */
	0,				/* Parameter needs count */
	(need___entry *)0, 		/* Parameter needs */
	(void **)&password___initial,	/* Object pointer */
	(instantiation___object *)0	/* Instantiation list */
};
static object___object *object_list[1] = {
	&password_initial_object,
};

void
user__external__initialize(void)
{
	extern module___object user__module__object;

	user__module__object.object_count = 1;
	user__module__object.objects = object_list;
}

void
password__external__initialize(void)
{
	int x = 0;
}

/*
 * password__address_get(password)
 *	This routine will return the address associated with "password".
 */
unsigned
password__address_get(
	Password	password)
{
	return (unsigned)password;
}

/*
 * password__home_directory_get(password)
 *	This routine will return the home directory associated with
 *	"password".
 */
String
password__home_directory_get(
	Password	password)
{
#ifdef LINUX
	assert(password != (Password)0);
	return string__unix_create(password->pw_dir);
#endif /* LINUX */
#ifdef WINDOWS
	assert(0);
#endif /* WINDOWS */
}

/*
 * password__full_name_get(password)
 *	This routine will return the full name associated with
 *	"password".
 */
String
password__full_name_get(
	Password	password)
{
#ifdef LINUX
	assert(password != (Password)0);
	return string__unix_create(password->pw_gecos);
#endif /* LINUX */
#ifdef WINDOWS
	assert(0);
#endif /* WINDOWS */
}

/*
 * password__group_number_get(password)
 *	This routine will return the group number associated with "password".
 */
unsigned
password__group_number_get(
	Password	password)
{
#ifdef LINUX
	return password->pw_gid;
#endif /* LINUX */
#ifdef WINDOWS
	assert(0);
#endif /* WINDOWS */
}

/*
 * password__login_name_lookup(login_name)
 *	This routine will return the "password" associated with "login_name".
 */
Password
password__login_name_lookup(
	String		login_name)
{
#ifdef LINUX
	Str name = string__unix_string(login_name);
	Password password = getpwnam(name);
	return password;
#endif /* LINUX */
#ifdef WINDOWS
	assert(0);
#endif /* WINDOWS */
}

/*
 * password__login_name_get(password)
 *	This routine will return the login name associated with "password".
 */
String
password__login_name_get(
	Password	password)
{
#ifdef LINUX
	assert(password != (Password)0);
	return string__unix_create(password->pw_name);
#endif /* LINUX */
#ifdef WINDOWS
	assert(0);
#endif /* WINDOWS */
}

/*
 * password__password_get(password)
 *	This routine will return the password associated with "password".
 */
String
password__password_get(
	Password	password)
{
#ifdef LINUX
	assert(password != (Password)0);
	return string__unix_create(password->pw_passwd);
#endif /* LINUX */
#ifdef WINDOWS
	assert(0);
#endif /* WINDOWS */
}

/*
 * password__shell_get(password)
 *	This routine will return the login name associated with "password".
 */
String
password__shell_get(
	Password	password)
{
#ifdef LINUX
	assert(password != (Password)0);
	return string__unix_create(password->pw_shell);
#endif /* LINUX */
#ifdef WINDOWS
	assert(0);
#endif /* WINDOWS */
}

/*
 * password__user_number_get(password)
 *	This routine will return the user number associated with "password".
 */
unsigned
password__user_number_get(
	Password	password)
{
#ifdef LINUX
	return password->pw_uid;
#endif /* LINUX */
#ifdef WINDOWS
	assert(0);
#endif /* WINDOWS */
}


/*
 * password__user_number_lookup(login_name)
 *	This routine will return the "password" associated with "user_number".
 */
Password
password__user_number_lookup(
	unsigned	user_number)
{
#ifdef LINUX
	return getpwuid(user_number);
#endif /* LINUX */
#ifdef WINDOWS
	assert(0);
#endif /* WINDOWS */
}



