#
# @(#)83	1.3  src/examples/svc/timop_svc/timop_svc_setup.dcecp, examples.src, os2dce21.dss, 960602a.1 3/17/96 15:51:16
#
# COMPONENT_NAME:  examples.src
#
# FILE NAME: timop_svc_setup.dcecp
#
# FUNCTIONS: Setup dcecp script for the timop_svc application.
#
# USAGE: dcecp timop_svc_setup.dcecp <cdsentry-1> [<cdsentry-2> ... <cdsentry-n>]
#				-p <cell_admin passwd>
#
# ORIGINS: 72/27
#
# (C) COPYRIGHT International Business Machines Corp. 1995
#  All Rights Reserved
#  Licensed Materials - Property of IBM
#
#  US Government Users Restricted Rights - Use, duplication or
#  disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#
# @OSF_COPYRIGHT@
# COPYRIGHT NOTICE
# Copyright (c) 1990, 1991, 1992, 1993, 1994 Open Software Foundation, Inc.
# ALL RIGHTS RESERVED (DCE).  See the file named COPYRIGHT.DCE in the
# src directory for the full copyright text.
#

proc run_cmd {cmd} {

   set sts  [catch {uplevel $cmd} answer]

   if {$sts == 0} {
       return 0
   } else {
	puts "$answer"
	return 1
   }
}

# Check argument count and print the usage if necessary.

   if { $argc < 3 } {
      error "Usage: dcecp timop_svc_setup.dcecp <cdsentry-1> <cdsentry-2> ... <cdsentry-n> -p <cell_admin passwd>"
   }

# Find where the -p parameter is
   set where [string first -p $argv]

# Find out how long the whole string is
   set long [string length $argv]

# Length of Password, minus 2, because password starts 2 spaces after -, and index starts at 0
   set what [expr ($long - $where - 3)]

# Get password
   set first [expr ($where + 3)]
   set pwd [string range $argv $first $long]

# Get entry(ies)
   set last [expr ($where - 1)]
   set entry [string range $argv 0 $last]

# Steps:
#	- Login as cell_admin
#	- Add server principal tsserver
#	- Add client principal tsclient
#	- Create server principal account
#	- Create client principal account
#	- Create keytab file
#	- Create CDS entries

   puts "Logging in..."
   run_cmd {login cell_admin -password $pwd}

   puts "Adding principals."
   puts "principal create {tsserver tsclient} "
   run_cmd {principal create {tsserver tsclient}}

   puts "Adding principals to groups."
   puts "group add none -member tsserver"
   run_cmd  {group add none -member tsserver}
   puts "group add none -member tsclient"
   run_cmd  {group add none -member tsclient}

   puts "Adding principals to organizations."
   puts "organization add none -member tsserver"
   run_cmd {organization add none -member tsserver}
   puts "organization add none -member tsclient"
   run_cmd {organization add none -member tsclient}

   puts "Creating accounts."
   puts "account create tsserver -group none -organization none -password qwerty -mypwd $pwd"
   run_cmd {account create tsserver -group none -organization none -password qwerty -mypwd $pwd}

   puts "account create tsclient -group none -organization none -password xyzzy -mypwd $pwd"
   run_cmd {account create tsclient -group none -organization none -password xyzzy -mypwd $pwd}

   puts "Adding CDS entries."
   puts "rpcentry create $entry"
   run_cmd {rpcentry create "$entry"}
   puts "acl modify $entry -entry -add user:tsserver:rwdtc"
   run_cmd {acl modify "$entry" -entry -add user:tsserver:rwdtc}

   puts "Logging out."
   run_cmd {logout}

# Need to be "self" in dce for keytab operations.
# Create the keytab file using dcecp if the cell's protection level is
# DES encryption or CDMF. If not, comment-out the following keytab create line:
# run_cmd {keytab create timeop -storage {/tmp/tskeyfile} -data{tsserver plain
# 1 qwerty}}. Use rgy_edit to add the keytab entry: ktadd -p tsserver -pw
# qwerty -f /tmp/tskeyfile.

   puts "Creating keytab table."
   puts "keytab create timeop -storage {/tmp/tskeyfile} -data {tsserver plain 1 qwerty}"
   run_cmd {keytab create timeop -storage {/tmp/tskeyfile} -data {tsserver plain 1 qwerty}}

