#!/bin/ksh -p
#
# ident "@(#)xdm-add-dpy.sh	1.5 04/04/13"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
#
# Script to add an X server to the xdm Xservers file and set it up via the
# Xconfig file to service 
#
# The database of available display numbers is taken as 
# Xservers. If a display is mentioned as
#
#	sysname:num OR :num
#
# at the beginning of a line or the beginning of a comment, it is considered
# unavailable for use.
#
# E.g. a line '# :3 RESERVED' will prevent display 3 from being assigned
#

#
# Note that for XDM Xconfig is not required - the xdm-config file is
# used by XDM instead, and although there is a resource called
# DisplayManager.exportList described on the man page I've been unable
# to get this to work to export env variables into the session
# environment.  Therefore we will create an Xconfig file, whose sole
# purpose in life is to contain the env necessary for the session, and
# we'll read it when necessary to establish the environment.  Today
# that is only done in 0010.SUNWut.xdmEnv, run out of xinitrc, to
# create the env for the session environment.  This means we have no
# env established during the greeter context, but that's not necessary
# at this time.  Should we need it in future, we can read in the env
# in Xsetup or a PAM module.
#

unset LD_LIBRARY_PATH

BASE=/etc/opt/SUNWut/basedir
SUNWUT=$BASE
SUNWUTLIB=$SUNWUT/lib

INET_SERVICES=/etc/services 

#
# Set default values
#
INFODIR=/var/opt/SUNWut
ETCDIR=/etc/opt/SUNWut
TMPDIR=/tmp/SUNWut

MINDISP=2		# minimum display number XXX
MAXDISP=1000		# maximum display number XXX -> must match OWconfig
#
# Add a session
#

dir=$1		# location of config files and lock
token=$2	# token name
type=$3		# session type
mvdisplay=$4	# mv display command line

xserv=$dir/Xservers	# xdm's Xservers file
xconf=$dir/Xconfig	# SRSS's Xconfig file
xconfiglock=$dir/config.lock    # X-Windows config lock file

xcdesc="DisplayManager.*_%d.exportList: SUN_SUNRAY_TOKEN=$token CORONA_TOKEN=$token"
if [ "$type" = normal ]
then
	xsdesc=":%d SunRay local /opt/SUNWut/lib/utxsun :%d"
else
	xsdesc="# :%d RESERVED"
fi

#
# Allow everyone to read Xsessions and Xconfig file
#
umask 0022

dpy=$($SUNWUTLIB/utdtutil -l $xconfiglock -s "$xsdesc" -c "$xcdesc" \
	-i "$INET_SERVICES" -F $MINDISP -L $MAXDISP \
	-R "$mvdisplay" $xserv $xconf)
print $dpy
