#!/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/lib/ksh93/aix/KLIB_AIX_get_user_info.sh 1.4 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2005,2011 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)68	1.4 src/43haes/lib/ksh93/aix/KLIB_AIX_get_user_info.sh, hacmp, 61haes_r714 11/28/11 15:22:29
#
#=head1 NAME
#
# KLIB_AIX_get_user_info - Get the user group, UID and GID properties
#                          of an AIX user
#
#=head1 SYNOPSIS
#
# typeset user_struct_var
# user_struct_var (
#	user=""
#	group=""
#	uid=0
#	gid=0
# )
# KLIB_AIX_get_user_info user_struct_var "mattg"
#
#=head1 DESCRIPTION
#
# Obtains the user group, UID and GID of the provided user name and populates
# the data structure passed in (by reference) as the first argument to
# this function
# 
#=head1 ARGUMENTS
#
#   1: [by ref] user data structure
#	2: [scalar] user name to obtain info on
#
#=head1 RETURN
#
#   0: success, structure was completely populated 
#   1: failed, unable to determine part or all of the user
#	   info given the user name provided to this function
#
#=head1 COPYRIGHT
#
#(C) COPYRIGHT International Business Machines Corp. 2005
#All Rights Reserved
#
#=cut
#
function KLIB_AIX_get_user_info
{
	. /usr/es/lib/ksh93/func_include

	typeset -n userinfo=$1
	typeset user=$2
	typeset group
	typeset uid
	typeset gid

	if [[ -z $user ]]; then
		return 1
	fi

	userinfo.user=$user
	uid=$(lsuser -a id $user 2>/dev/null)
	if [[ -z $uid ]]; then
		return 1
	fi
	group=$(KLIB_AIX_get_usergroup $user)
	if [[ -z $group ]]; then
		return 1
	fi
	gid=$(lsgroup -a id $group)
	if [[ -z $gid ]]; then
		return 1
	fi
	userinfo.uid=${uid/*=/}
	userinfo.gid=${gid/*=/}
	userinfo.group=$group
	userinfo.user=$user
	return 0
}
