english
version "1.0"
identify "xyz"

#: Copyright (c) 1996 by Wayne C. Gramlich.
#, All rights reserved.
#,
#, Permission to use, copy, modify, distribute, and sell this software
#, for any purpose is hereby granted without fee provided that the above
#, copyright notice and this permission are retained.  The author makes
#, no representations about the suitability of this software for any purpose.
#, It is provided "as is" without express or implied warranty.

module user

#: The user module provides access to per user information.

import
    address
    format
    in_stream
    logical
    out_stream
    string
    system
    unsigned

define user 			#: The user record.
    record
	home_directory string	#: Home directory for user
	group_number unsigned	#: Group number (gid)
	full_name string	#: Full user name
	login_name string	#: The user's login name
	password string		#: Encrypted password string	
	shell string		#: User's login shell
	user_number unsigned	#: User number (uid)
    generate allocate, erase, print

define password
    external


#: {user} procedures:

procedure create@user
    takes
	password password
    returns user

    #: This procedure will take a {password} object and return a corresponging
    #, {user} object that has all of its fields filled in.

    user :@= allocate@user()
    user.home_directory := home_directory_get@(password)
    user.group_number := password.group_number
    user.full_name := full_name_get@(password)
    user.login_name := login_name_get@(password)
    user.password := password_get@(password)
    user.shell := shell_get@(password)
    user.user_number := password.user_number
    return user


procedure login_name_lookup@user
    takes
	login_name string
    returns user

    #: This procedure will return a {user} object that corresponds to
    #, {login_name}.  ??@{user} is returned if there is no login name
    #, that matches {login_name}.
    
    password :@= login_name_lookup@password(login_name)
    if password == ??
	return ??
    user :@= create@user(password)
    return user


procedure user_number_lookup@user
    takes
	user_number unsigned
    returns user

    #: This procedure will fill in the contents of {user} with
    #, the values associated with the {user_number} user.
    #, ??@{user} is returned if there is no login name
    #, that matches {login_name}.
    
    password :@= user_number_lookup@password(user_number)
    if password == ??
	return ??
    user :@= create@user(password)
    return user


#: {password} procedures:
#, In general, these procedures are not safe.

procedure address_get@password
    takes
	password password
    returns address
    external password__address_get

    #: This procedure will return the address of {password}.


procedure home_directory_get@password
    takes
	password password
    returns string
    external password__home_directory_get

    #: This procedure will return the {home_directory} from {password}.


procedure identical@password
    takes
	password1 password
	password2 password
    returns logical

    #: This procedure will return {true} if {password1} is identical to
    #, {password2}.

    return password1.address = password2.address


procedure group_number_get@password
    takes
	password password
    returns unsigned
    external password__group_number_get

    #: This procedure will return the {group_number} from {password}.


procedure full_name_get@password
    takes
	password password
    returns string
    external password__full_name_get

    #: This procedure will return the {full_name} from {password}.


procedure login_name_get@password
    takes
	password password
    returns string
    external password__login_name_get

    #: This procedure will return the {login_name} from {password}.


procedure login_name_lookup@password
    takes
	login_name string
    returns password
    external password__login_name_lookup

    #: This procedure will return the {user} assocaiated with {login_name}.


procedure password_get@password
    takes
	password password
    returns string
    external password__password_get

    #: This procedure will return the encrypted {password} from {password}.


procedure print@password
    takes
	password password
	out_stream out_stream
    returns_nothing

    #: This procedure will print out the contents of {password} to
    #, {out_stream}.

    format@format1[address](out_stream, '{Password: %X%\n\}', password.address)


procedure shell_get@password
    takes
	password password
    returns string
    external password__shell_get

    #: This procedure will return the {shell} from {password}.


procedure user_number_get@password
    takes
	password password
    returns unsigned
    external password__user_number_get

    #: This procedure will return the {user_number} from {password}.


procedure user_number_lookup@password
    takes
	user_number unsigned
    returns password
    external password__user_number_lookup

    #: This procedure will return the {password} from assocaitied with
    #, {user_number}.











