The Windows ATS Install has been updated to not perform the configuration step as part of the MSI install process.
This commit is contained in:
parent
05fd9550b5
commit
dee103c988
@ -29,5 +29,5 @@ rem #
|
||||
rem ########################################################################
|
||||
|
||||
rem # Perform the operation requested
|
||||
ATS_JAVA_HOME\bin\java -jar ATS_INSTALL_DIRats\lib\CasaAuthPolicyEditor.jar %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
ATS_JAVA_HOME\bin\java -jar ATS_INSTALL_DIR\bin\CasaAuthPolicyEditor.jar %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
|
||||
|
@ -29,5 +29,5 @@ rem #
|
||||
rem ########################################################################
|
||||
|
||||
rem # Perform the operation requested
|
||||
ATS_JAVA_HOME\bin\java -jar ATS_INSTALL_DIRats\lib\CasaAuthTokenSettingsEditor.jar %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
ATS_JAVA_HOME\bin\java -jar ATS_INSTALL_DIR\bin\CasaAuthTokenSettingsEditor.jar %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
|
||||
|
@ -29,5 +29,5 @@ rem #
|
||||
rem ########################################################################
|
||||
|
||||
rem # Peform the operation requested
|
||||
ATS_JAVA_HOME\bin\java -jar ATS_INSTALL_DIRats\lib\CasaIdenTokenSettingsEditor.jar %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
ATS_JAVA_HOME\bin\java -jar ATS_INSTALL_DIR\bin\CasaIdenTokenSettingsEditor.jar %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
|
||||
|
@ -29,5 +29,5 @@ rem #
|
||||
rem ########################################################################
|
||||
|
||||
rem # Perform the operation requested
|
||||
ATS_JAVA_HOME\bin\java -jar ATS_INSTALL_DIRats\lib\CasaSvcSettingsEditor.jar %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
ATS_JAVA_HOME\bin\java -jar ATS_INSTALL_DIR\bin\CasaSvcSettingsEditor.jar %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
|
||||
|
10
CASA-auth-token/server-java/Svc/templates/windows/jaas.conf
Normal file
10
CASA-auth-token/server-java/Svc/templates/windows/jaas.conf
Normal file
@ -0,0 +1,10 @@
|
||||
other {
|
||||
com.sun.security.auth.module.Krb5LoginModule required
|
||||
useTicketCache=true
|
||||
ticketCache="ATS_INSTALL_DIR\\catalinabase\\temp\\ticket.cache"
|
||||
useKeyTab=true
|
||||
principal="host/HOSTNAME"
|
||||
doNotPrompt=true
|
||||
storeKey=true
|
||||
debug=true;
|
||||
};
|
@ -18,7 +18,7 @@ log4j.rootLogger=warn, DefaultAppender
|
||||
# DefaultAppender configuration.
|
||||
#
|
||||
log4j.appender.DefaultAppender=org.apache.log4j.RollingFileAppender
|
||||
log4j.appender.DefaultAppender.File=ATS_INSTALL_DIRats\\catalinabase\\logs\\ats.log
|
||||
log4j.appender.DefaultAppender.File=ATS_INSTALL_DIR\\catalinabase\\logs\\ats.log
|
||||
log4j.appender.DefaultAppender.MaxFileSize=300KB
|
||||
log4j.appender.DefaultAppender.MaxBackupIndex=2
|
||||
log4j.appender.DefaultAppender.layout=org.apache.log4j.PatternLayout
|
||||
@ -34,7 +34,7 @@ log4j.additivity.ATS_Trace=false
|
||||
# TraceAppender configuration.
|
||||
#
|
||||
log4j.appender.TraceAppender=org.apache.log4j.RollingFileAppender
|
||||
log4j.appender.TraceAppender.File=ATS_INSTALL_DIRats\\catalinabase\\logs\\ats.trace
|
||||
log4j.appender.TraceAppender.File=ATS_INSTALL_DIR\\catalinabase\\logs\\ats.trace
|
||||
log4j.appender.TraceAppender.MaxFileSize=300KB
|
||||
log4j.appender.TraceAppender.MaxBackupIndex=2
|
||||
log4j.appender.TraceAppender.layout=org.apache.log4j.PatternLayout
|
||||
|
@ -90,7 +90,7 @@
|
||||
enableLookups="false" disableUploadTimeout="true"
|
||||
acceptCount="100" debug="0" scheme="https" secure="true"
|
||||
clientAuth="false" sslProtocol="TLS"
|
||||
keystoreFile="ATS_INSTALL_DIRats\etc\keys\server\jks-store"
|
||||
keystoreFile="ATS_INSTALL_DIR\etc\keys\server\jks-store"
|
||||
keystorePass="secret" algorithm="SunX509" />
|
||||
|
||||
|
||||
|
@ -2,4 +2,4 @@ com.novell.casa.authtoksvc.crypto.keystore.type=jks
|
||||
com.novell.casa.authtoksvc.crypto.keystore.password=secret
|
||||
com.novell.casa.authtoksvc.crypto.keystore.alias=signingKey
|
||||
com.novell.casa.authtoksvc.crypto.alias.password=secret
|
||||
com.novell.casa.authtoksvc.crypto.file=ATS_INSTALL_DIRats\etc\keys\server\jks-store
|
||||
com.novell.casa.authtoksvc.crypto.file=ATS_INSTALL_DIR//etc//keys//server//jks-store
|
||||
|
@ -267,15 +267,9 @@ package/linux/Makefile
|
||||
package/linux/CASA_auth_token_svc.spec
|
||||
package/linux/CASA_auth_token_svc_4zen.spec
|
||||
package/windows/Makefile
|
||||
package/windows/ClientKeystoreSetup/Makefile
|
||||
package/windows/CommandLauncher/Makefile
|
||||
package/windows/DeleteFile/Makefile
|
||||
package/windows/InitConfigFile/Makefile
|
||||
package/windows/MungeCryptoPropertiesFilePath/Makefile
|
||||
package/windows/ServerKeystoreSetup/Makefile
|
||||
package/windows/SetupAsWindowsService/Makefile
|
||||
package/windows/ShutdownWindowsService/Makefile
|
||||
package/windows/UpdateWarFile/Makefile
|
||||
package/windows/AtsConfigurator/Makefile
|
||||
package/windows/AtsConfigurator/src/Makefile
|
||||
package/windows/AtsConfigurator/manifest/Makefile
|
||||
package/windows/server-java_msi/Makefile
|
||||
Svc/Makefile
|
||||
Svc/external/Makefile
|
||||
|
@ -0,0 +1,86 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Copyright (C) 2004 Novell, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# Author: Juan Carlos Luciani <jluciani@novell.com>
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
SUBDIRS = src manifest
|
||||
|
||||
DIST_SUBDIRS = src manifest
|
||||
|
||||
EXTRA_DIST =
|
||||
|
||||
ROOT = ../../..
|
||||
LIB = lib
|
||||
|
||||
LIBDIR = $(ROOT)/$(LIB)
|
||||
MANIFEST_DIR = manifest
|
||||
MANIFEST_FILE_NAME = AtsConfigurator.txt
|
||||
|
||||
JAVAC= javac
|
||||
|
||||
MODULE_NAME = AtsConfigurator
|
||||
MODULE_EXT = jar
|
||||
|
||||
JAVAFILES = src/AtsConfigurator.java \
|
||||
src/Configure.java \
|
||||
src/Unconfigure.java
|
||||
|
||||
BUILDDIR = build
|
||||
|
||||
CLASSES = $(addprefix $(BUILDDIR)/, $(JAVAFILES:%.java=%.class))
|
||||
|
||||
LIBS =
|
||||
CLASSPATH =
|
||||
|
||||
CUR_DIR := $(shell pwd)
|
||||
|
||||
all: $(BUILDDIR)/$(MODULE_NAME).$(MODULE_EXT)
|
||||
|
||||
$(BUILDDIR)/%.class: %.java
|
||||
@echo [======== Compiling $@ ========]
|
||||
$(JAVAC) -g -sourcepath src -classpath "$(CLASSPATH)" -d $(BUILDDIR)/classes $<
|
||||
|
||||
$(BUILDDIR)/$(MODULE_NAME).$(MODULE_EXT): $(BUILDDIR) $(CLASSES)
|
||||
@echo [======== Jarring $@ ========]
|
||||
jar cvmf $(MANIFEST_DIR)/$(MANIFEST_FILE_NAME) $(BUILDDIR)/$(MODULE_NAME).$(MODULE_EXT) -C $(BUILDDIR)/classes .
|
||||
cp $(BUILDDIR)/$(MODULE_NAME).$(MODULE_EXT) $(LIBDIR)/java/
|
||||
|
||||
$(BUILDDIR):
|
||||
[ -d $(BUILDDIR) ] || mkdir -p $(BUILDDIR)
|
||||
[ -d $(BUILDDIR)/classes ] || mkdir -p $(BUILDDIR)/classes
|
||||
[ -d $(LIBDIR) ] || mkdir -p $(LIBDIR)
|
||||
[ -d $(LIBDIR)/java ] || mkdir -p $(LIBDIR)/java
|
||||
|
||||
install-exec-local:
|
||||
|
||||
uninstall-local:
|
||||
|
||||
#installcheck-local: install
|
||||
|
||||
clean-local:
|
||||
if [ -d $(BUILDDIR) ]; then rm -rf $(BUILDDIR); fi
|
||||
if [ -f $(LIBDIR)/java/$(MODULE_NAME).$(MODULE_EXT) ]; then rm -f $(LIBDIR)/java/$(MODULE_NAME).$(MODULE_EXT); fi
|
||||
|
||||
distclean-local:
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -f Makefile.in
|
||||
rm -f Makefile
|
||||
|
@ -0,0 +1,2 @@
|
||||
Main-Class: AtsConfigurator
|
||||
|
@ -0,0 +1,35 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Copyright (C) 2006 Novell, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# Author: Juan Carlos Luciani <jluciani@novell.com>
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
DIST_SUBDIRS =
|
||||
|
||||
EXTRA_DIST = AtsConfigurator.txt
|
||||
|
||||
.PHONY: package package-clean package-install package-uninstall
|
||||
package package-clean package-install package-uninstall:
|
||||
$(MAKE) -C $(TARGET_OS) $@
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -f Makefile.in
|
||||
|
@ -0,0 +1,575 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright (C) 2006 Novell, Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, Novell, Inc.
|
||||
*
|
||||
* To contact Novell about this file by physical or electronic mail,
|
||||
* you may find current contact information at www.novell.com.
|
||||
*
|
||||
* Author: Juan Carlos Luciani <jluciani@novell.com>
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
import java.util.Properties;
|
||||
import java.util.Enumeration;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class for configuring and unconfiguring an ATS under windows.
|
||||
*
|
||||
*/
|
||||
public final class AtsConfigurator
|
||||
{
|
||||
private static final String usage =
|
||||
"usage: AtsConfigurator -op -file propertiesFilePath [-logfolder logFolderPath]\n\n" +
|
||||
" where:\n" +
|
||||
" -op - Corresponds to one of the following operations:\n" +
|
||||
" -c - Configure the ATS installation.\n" +
|
||||
" -u - Unconfigure the ATS installation.\n" +
|
||||
" -file - Path to the properties file\n" +
|
||||
" -logfolder - Path to the log folder\n" +
|
||||
" The following properties must be present in the file:\n" +
|
||||
" ATS_INSTALL_DIR - The location of the ATS Install Directory.\n" +
|
||||
" COMPUTERNAME - The computer name.\n" +
|
||||
" ATS_JAVA_HOME - Java home.\n" +
|
||||
" TOMCAT_HOME - Tomcat install base directory.\n" +
|
||||
" HOSTNAME - Name of the host.\n" +
|
||||
" TOMCAT5 - Location of the tomcat5 executable.\n";
|
||||
|
||||
// Error codes
|
||||
final static int ERROR_NO_ERROR = 0;
|
||||
final static int ERROR_EXEC_FAILED = -1;
|
||||
final static int ERROR_INVALID_ARGUMENT = -2;
|
||||
final static int ERROR_MISSING_INSTALL_DIR = -4;
|
||||
final static int ERROR_INSTALL_DIR_NOT_A_DIR = -5;
|
||||
final static int ERROR_MISSING_PROPERTIES_FILE = -7;
|
||||
final static int ERROR_UNABLE_TO_READ_PROPERTIES = -8;
|
||||
final static int ERROR_REQUIRED_PROPERTY_MISSING = -11;
|
||||
final static int ERROR_EXEC_INTERRUPTED = -12;
|
||||
final static int ERROR_IO_EXCEPTION = -13;
|
||||
final static int ERROR_EXCEPTION = -14;
|
||||
final static int ERROR_UNABLE_TO_OPEN_TEMPLATE = -15;
|
||||
final static int ERROR_FILEWRITER_CREATE_FAILED = -16;
|
||||
final static int ERROR_OUTPUT_COPY_FAILED = -17;
|
||||
final static int ERROR_JAR_COPY_FAILED = -18;
|
||||
final static int ERROR_ADD_FILE_TO_JAR_FAILED = -19;
|
||||
final static int ERROR_WAR_TEMPLATE_FILE_MISSING = -20;
|
||||
final static int ERROR_NEW_JAR_CANNOT_BE_REPLACED = -21;
|
||||
final static int ERROR_CREATE_WAR_FOS_FAILED = -22;
|
||||
final static int ERROR_OPEN_JAR_TEMPLATE_FAILED = -23;
|
||||
final static int ERROR_JOS_FLUSH_FAILED = -24;
|
||||
final static int ERROR_JOS_CLOSE_FAILED = -25;
|
||||
final static int ERROR_FOS_CLOSE_FAILED = -26;
|
||||
final static int ERROR_JFTEMPLATE_CLOSE_FAILED = -27;
|
||||
|
||||
// Required properties
|
||||
final static String INSTALL_DIR_PROPERTY = "ATS_INSTALL_DIR";
|
||||
final static String COMPUTERNAME_PROPERTY = "COMPUTERNAME";
|
||||
final static String TOMCAT_HOME_PROPERTY = "TOMCAT_HOME";
|
||||
final static String JAVA_HOME_PROPERTY = "ATS_JAVA_HOME";
|
||||
final static String HOSTNAME_PROPERTY = "HOSTNAME";
|
||||
|
||||
final static String[] m_requiredProperties = {
|
||||
INSTALL_DIR_PROPERTY,
|
||||
COMPUTERNAME_PROPERTY,
|
||||
TOMCAT_HOME_PROPERTY,
|
||||
JAVA_HOME_PROPERTY,
|
||||
HOSTNAME_PROPERTY};
|
||||
|
||||
// Other constants
|
||||
final static String LOG_FILE_NAME = "AtsConfigurator.log";
|
||||
|
||||
// Configured properties
|
||||
static Properties m_properties = null;
|
||||
|
||||
// InstallLog variables
|
||||
static String m_logFolderPath = "\\temp";
|
||||
static File m_logFile = null;
|
||||
static FileWriter m_logFileWriter = null;
|
||||
|
||||
/**
|
||||
* Invoke external command.
|
||||
*
|
||||
* @param commandArray Array of command parameters.
|
||||
* @return Return code.
|
||||
*/
|
||||
static int invokeExternalCommand(String[] commandArray)
|
||||
{
|
||||
int rc;
|
||||
|
||||
log("AtsConfigurator.invokeExternalCommand()- Start");
|
||||
|
||||
try
|
||||
{
|
||||
Process p = Runtime.getRuntime().exec(commandArray);
|
||||
try
|
||||
{
|
||||
int r = p.waitFor();
|
||||
if (r == 0)
|
||||
{
|
||||
rc = ERROR_NO_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
log("Command " + commandArray[0] + " returned status: " + r);
|
||||
rc = ERROR_EXEC_FAILED;
|
||||
}
|
||||
}
|
||||
catch (InterruptedException ie)
|
||||
{
|
||||
rc = ERROR_EXEC_INTERRUPTED;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
rc = AtsConfigurator.ERROR_EXEC_FAILED;
|
||||
}
|
||||
|
||||
log("AtsConfigurator.invokeExternalCommand()- End, rc= ", rc);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to fill in missing properties from system properties.
|
||||
*/
|
||||
static void tryToFillInMissingProperties()
|
||||
{
|
||||
log("AtsConfigurator.tryToFillInMissingProperties()- Start");
|
||||
|
||||
for (int i = 0; i < m_requiredProperties.length; i++)
|
||||
{
|
||||
String propertyKey = m_requiredProperties[i];
|
||||
if (!m_properties.containsKey(propertyKey))
|
||||
{
|
||||
AtsConfigurator.log("Trying to fill in property: " + propertyKey);
|
||||
|
||||
String propertyValue = System.getProperty(propertyKey);
|
||||
if (propertyValue != null)
|
||||
{
|
||||
log(" Filling in property using system property value: " + propertyValue);
|
||||
m_properties.put(propertyKey, propertyValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
log(" Unable to fill in property " + propertyKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log("AtsConfigurator.tryToFillInMissingProperties()- End");
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the properties required have been specified.
|
||||
*
|
||||
* @return Return code.
|
||||
*/
|
||||
static int verifyRequiredPropertiesSpecified()
|
||||
{
|
||||
int rc = ERROR_NO_ERROR;
|
||||
|
||||
log("AtsConfigurator.verifyRequiredPropertiesSpecified()- Start");
|
||||
|
||||
for (int i = 0; i < m_requiredProperties.length; i++)
|
||||
{
|
||||
if (!m_properties.containsKey(m_requiredProperties[i]))
|
||||
{
|
||||
log("Required property " + m_requiredProperties[i] + " missing");
|
||||
rc = ERROR_REQUIRED_PROPERTY_MISSING;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
log("AtsConfigurator.verifyRequiredPropertiesSpecified()- End, rc= ", rc);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process properties.
|
||||
*
|
||||
* @return Return code.
|
||||
*/
|
||||
static int processProperties(String configFilePath)
|
||||
{
|
||||
int rc = ERROR_NO_ERROR;
|
||||
|
||||
log("AtsConfigurator.processProperties()- Start");
|
||||
|
||||
// Obtain configuration properties from config file
|
||||
InputStream in = null;
|
||||
try
|
||||
{
|
||||
File fileProperties = new File(configFilePath);
|
||||
|
||||
// Make sure the properties file can be found
|
||||
if (!fileProperties.exists())
|
||||
{
|
||||
rc = ERROR_MISSING_PROPERTIES_FILE;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Read the properties from the file
|
||||
in = new FileInputStream(fileProperties);
|
||||
m_properties = new Properties();
|
||||
m_properties.load(in);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
rc = ERROR_UNABLE_TO_READ_PROPERTIES;
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (in != null)
|
||||
in.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
// Continue if no errors detected
|
||||
if (rc == ERROR_NO_ERROR)
|
||||
{
|
||||
tryToFillInMissingProperties();
|
||||
|
||||
// Log the properties obtained
|
||||
Enumeration e = m_properties.propertyNames();
|
||||
while (e.hasMoreElements())
|
||||
{
|
||||
String key = (String) e.nextElement();
|
||||
String value = (String) m_properties.get(key);
|
||||
AtsConfigurator.log("Property " + key + " = " + value);
|
||||
}
|
||||
|
||||
// Validate that we have the required properties
|
||||
if (ERROR_NO_ERROR == (rc = verifyRequiredPropertiesSpecified()))
|
||||
{
|
||||
// Verify that the install directory specified exists
|
||||
File fileInstallDir = new File((String) m_properties.get(INSTALL_DIR_PROPERTY));
|
||||
|
||||
// Make sure the install dir can be found
|
||||
if (!fileInstallDir.exists())
|
||||
{
|
||||
rc = ERROR_MISSING_INSTALL_DIR;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Make sure the install dir is a directory
|
||||
if (!fileInstallDir.isDirectory())
|
||||
{
|
||||
rc = ERROR_INSTALL_DIR_NOT_A_DIR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log("AtsConfigurator.processProperties()- End, rc= ", rc);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log error code.
|
||||
*
|
||||
* @param err Error code.
|
||||
*/
|
||||
static void log(int err)
|
||||
{
|
||||
log(null, err);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log string with error code.
|
||||
*
|
||||
* @param s Log string.
|
||||
* @param err Error code.
|
||||
*/
|
||||
static void log(String s, int err)
|
||||
{
|
||||
String rcMessage;
|
||||
|
||||
switch (err)
|
||||
{
|
||||
case ERROR_NO_ERROR:
|
||||
rcMessage = "No error";
|
||||
break;
|
||||
case ERROR_EXEC_FAILED:
|
||||
rcMessage = "Execute command failed";
|
||||
break;
|
||||
case ERROR_MISSING_INSTALL_DIR:
|
||||
rcMessage = "Missing install dir";
|
||||
break;
|
||||
case ERROR_INSTALL_DIR_NOT_A_DIR:
|
||||
rcMessage = "Install dir is not a dir";
|
||||
break;
|
||||
case ERROR_MISSING_PROPERTIES_FILE:
|
||||
rcMessage = "Property file not found";
|
||||
break;
|
||||
case ERROR_UNABLE_TO_READ_PROPERTIES:
|
||||
rcMessage = "Unable to read property file";
|
||||
break;
|
||||
case ERROR_REQUIRED_PROPERTY_MISSING:
|
||||
rcMessage = "Required property is missing";
|
||||
break;
|
||||
case ERROR_EXEC_INTERRUPTED:
|
||||
rcMessage = "Execution interrupted";
|
||||
break;
|
||||
case ERROR_UNABLE_TO_OPEN_TEMPLATE:
|
||||
rcMessage = "Unable to open template file";
|
||||
break;
|
||||
case ERROR_FILEWRITER_CREATE_FAILED:
|
||||
rcMessage = "FileWriter create failed";
|
||||
break;
|
||||
case ERROR_OUTPUT_COPY_FAILED:
|
||||
rcMessage = "Output copy failed";
|
||||
break;
|
||||
case ERROR_IO_EXCEPTION:
|
||||
rcMessage = "IO Exception";
|
||||
break;
|
||||
case ERROR_JAR_COPY_FAILED:
|
||||
rcMessage = "Failed to copy Jar";
|
||||
break;
|
||||
case ERROR_ADD_FILE_TO_JAR_FAILED:
|
||||
rcMessage = "Failed to add file to Jar";
|
||||
break;
|
||||
case ERROR_WAR_TEMPLATE_FILE_MISSING:
|
||||
rcMessage = "Template War file missing";
|
||||
break;
|
||||
case ERROR_NEW_JAR_CANNOT_BE_REPLACED:
|
||||
rcMessage = "Cannot create new Jar";
|
||||
break;
|
||||
case ERROR_CREATE_WAR_FOS_FAILED:
|
||||
rcMessage = "Failed to create War File Output Stream";
|
||||
break;
|
||||
case ERROR_OPEN_JAR_TEMPLATE_FAILED:
|
||||
rcMessage = "Failed to open Template War file";
|
||||
break;
|
||||
case ERROR_JOS_FLUSH_FAILED:
|
||||
rcMessage = "Jar Output Stream Flush failed";
|
||||
break;
|
||||
case ERROR_JOS_CLOSE_FAILED:
|
||||
rcMessage = "Jar Output Stream Close failed";
|
||||
break;
|
||||
case ERROR_FOS_CLOSE_FAILED:
|
||||
rcMessage = "File Output Stream Close failed";
|
||||
break;
|
||||
case ERROR_JFTEMPLATE_CLOSE_FAILED:
|
||||
rcMessage = "War Template Input Stream Close failed";
|
||||
break;
|
||||
case ERROR_EXCEPTION:
|
||||
rcMessage = "Exception";
|
||||
break;
|
||||
default:
|
||||
rcMessage = "Unknown error";
|
||||
break;
|
||||
}
|
||||
|
||||
if (s != null)
|
||||
log(s + rcMessage);
|
||||
else
|
||||
log(rcMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log string.
|
||||
*
|
||||
* @param s Log string.
|
||||
*/
|
||||
static void log(String s)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (m_logFileWriter != null)
|
||||
m_logFileWriter.write(s + "\r\n");
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applications Entry Point.
|
||||
*
|
||||
* @param args Arguments.
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
String op = null;
|
||||
boolean opPerformed = false;
|
||||
boolean argumentsError = false;
|
||||
String filePath = null;
|
||||
int rc = ERROR_NO_ERROR;
|
||||
|
||||
try
|
||||
{
|
||||
// Process the command line arguments
|
||||
for (int i = 0; i < args.length; i++)
|
||||
{
|
||||
// Proceed based on the command
|
||||
if (args[i].equalsIgnoreCase("-file"))
|
||||
{
|
||||
// The next argument should contain the filepath
|
||||
if (args.length > (i + 1))
|
||||
{
|
||||
filePath = args[i + 1];
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
argumentsError = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (args[i].equalsIgnoreCase("-logfolder"))
|
||||
{
|
||||
// The next argument should contain the path to the log folder
|
||||
if (args.length > (i + 1))
|
||||
{
|
||||
// Overwrite the default
|
||||
m_logFolderPath = args[i + 1];
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
argumentsError = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (args[i].equalsIgnoreCase("-c"))
|
||||
{
|
||||
// List operation requested
|
||||
if (op == null)
|
||||
{
|
||||
op = "configure";
|
||||
}
|
||||
else
|
||||
{
|
||||
argumentsError = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (args[i].equalsIgnoreCase("-u"))
|
||||
{
|
||||
// List operation requested
|
||||
if (op == null)
|
||||
{
|
||||
op = "unconfigure";
|
||||
}
|
||||
else
|
||||
{
|
||||
argumentsError = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get ready to log
|
||||
File logFolder = new File(m_logFolderPath);
|
||||
if (!logFolder.exists())
|
||||
{
|
||||
// Create the log folder
|
||||
logFolder.mkdirs();
|
||||
m_logFile = new File(logFolder.getAbsolutePath() + "\\" + LOG_FILE_NAME);
|
||||
m_logFileWriter = new FileWriter(m_logFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logFolder.isDirectory())
|
||||
{
|
||||
m_logFile = new File(logFolder.getAbsolutePath() + "\\" + LOG_FILE_NAME);
|
||||
m_logFileWriter = new FileWriter(m_logFile);
|
||||
}
|
||||
}
|
||||
|
||||
// Proceed based on the specified parameters
|
||||
if (argumentsError == false)
|
||||
{
|
||||
// Verify that the necessary input parameters where specified
|
||||
if (filePath != null && op != null)
|
||||
{
|
||||
// Process the property file
|
||||
if (ERROR_NO_ERROR == (rc = processProperties(filePath)))
|
||||
{
|
||||
// Proceed based on the operation requested
|
||||
if (op.compareTo("configure") == 0)
|
||||
{
|
||||
Configure c = new Configure(m_properties);
|
||||
rc = c.m_rc;
|
||||
}
|
||||
else if (op.compareTo("unconfigure") == 0)
|
||||
{
|
||||
Unconfigure u = new Unconfigure(m_properties);
|
||||
rc = u.m_rc;
|
||||
}
|
||||
else
|
||||
{
|
||||
log("Unsupported operation: " + op);
|
||||
argumentsError = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
argumentsError = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
argumentsError = true;
|
||||
log("Not all required parameters specified");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
rc = ERROR_EXCEPTION;
|
||||
log("Exception" + e.getMessage());
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Close the log file writer if necessary
|
||||
if (m_logFileWriter != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_logFileWriter.flush();
|
||||
m_logFileWriter.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Display the usage string if we encountered an error with the
|
||||
// command line arguments.
|
||||
if (argumentsError)
|
||||
{
|
||||
System.out.print(usage);
|
||||
rc = ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
// Set the exit code
|
||||
System.exit(rc);
|
||||
}
|
||||
}
|
@ -0,0 +1,795 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright (C) 2006 Novell, Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, Novell, Inc.
|
||||
*
|
||||
* To contact Novell about this file by physical or electronic mail,
|
||||
* you may find current contact information at www.novell.com.
|
||||
*
|
||||
* Authors: Juan Carlos Luciani <jluciani@novell.com>
|
||||
* Greg Richardson <grichardson@novell.com>
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
/**
|
||||
* Configure Class.
|
||||
* <p>
|
||||
* This class readies the Authentication Token Service after it has been
|
||||
* installed.
|
||||
*/
|
||||
public class Configure
|
||||
{
|
||||
// Other constants
|
||||
final static String SERVER_KEY_STORE_RELATIVE_PATH = "\\etc\\keys\\server\\jks-store";
|
||||
final static String CLIENT_KEY_STORE_RELATIVE_PATH = "\\etc\\keys\\client\\jks-store";
|
||||
final static String SIGNING_CERT_RELATIVE_PATH = "\\etc\\keys\\casaatsdSigningCert";
|
||||
|
||||
// Configured properties
|
||||
Properties m_properties;
|
||||
|
||||
// Completion code
|
||||
int m_rc;
|
||||
|
||||
// Template replace strings
|
||||
String[] m_rgsSearchFor;
|
||||
String[] m_rgsReplaceWith;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param properties Configuration properties.
|
||||
*/
|
||||
Configure(Properties properties)
|
||||
{
|
||||
m_rc = AtsConfigurator.ERROR_NO_ERROR;
|
||||
|
||||
AtsConfigurator.log("Configure()- Start");
|
||||
|
||||
try
|
||||
{
|
||||
// Save the properties
|
||||
m_properties = properties;
|
||||
|
||||
// Process the properties
|
||||
if (AtsConfigurator.ERROR_NO_ERROR == (m_rc = processProperties()))
|
||||
{
|
||||
// Create the server keystore
|
||||
if (AtsConfigurator.ERROR_NO_ERROR == (m_rc = createServerKeystore()))
|
||||
{
|
||||
// Create the client keystore
|
||||
if (AtsConfigurator.ERROR_NO_ERROR == (m_rc = createClientKeystore()))
|
||||
{
|
||||
// Setup the relocatable files
|
||||
if (AtsConfigurator.ERROR_NO_ERROR == (m_rc = setupRelocatableFiles()))
|
||||
{
|
||||
// Setup the War file
|
||||
if (AtsConfigurator.ERROR_NO_ERROR == (m_rc = createWarFileFromTemplate()))
|
||||
{
|
||||
// Create the ATS Service
|
||||
m_rc = createATSService();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_rc = AtsConfigurator.ERROR_EXCEPTION;
|
||||
AtsConfigurator.log("Exception" + e.getMessage());
|
||||
}
|
||||
|
||||
AtsConfigurator.log("Configure()- End, rc= ", m_rc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process properties.
|
||||
*
|
||||
* @return Return code.
|
||||
*/
|
||||
int processProperties()
|
||||
{
|
||||
int rc = AtsConfigurator.ERROR_NO_ERROR;
|
||||
|
||||
AtsConfigurator.log("Configure.processProperties()- Start");
|
||||
|
||||
// Setup replace template key/values arrays
|
||||
int i = 0;
|
||||
Enumeration e = m_properties.propertyNames();
|
||||
|
||||
m_rgsSearchFor = new String[m_properties.size()];
|
||||
m_rgsReplaceWith = new String[m_properties.size()];
|
||||
|
||||
while (e.hasMoreElements())
|
||||
{
|
||||
String key = (String) e.nextElement();
|
||||
String value = (String) m_properties.get(key);
|
||||
m_rgsSearchFor[i] = key;
|
||||
m_rgsReplaceWith[i] = value;
|
||||
i++;
|
||||
}
|
||||
|
||||
AtsConfigurator.log("Configure.processProperties()- End, rc= ", rc);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the keystore already exists
|
||||
*
|
||||
* @param keyStoreRelPath Relative path to the keystore
|
||||
* @return true if the keystore exists otherwise false.
|
||||
*/
|
||||
boolean keyStoreAlreadyExists(String keyStoreRelPath)
|
||||
{
|
||||
boolean retValue = false;
|
||||
|
||||
AtsConfigurator.log("Configure.keyStoreAlreadyExists()- Start, relPath = " + keyStoreRelPath);
|
||||
|
||||
File fileKeystore = new File(((String) m_properties.get(AtsConfigurator.INSTALL_DIR_PROPERTY)) + keyStoreRelPath);
|
||||
File fileParent = fileKeystore.getParentFile();
|
||||
String[] rgChildren = fileParent.list();
|
||||
if (null != rgChildren)
|
||||
{
|
||||
for (int i = 0; i < rgChildren.length; i++)
|
||||
{
|
||||
AtsConfigurator.log("child " + i + " = " + rgChildren[i]);
|
||||
if ("jks-store".equals(rgChildren[i]))
|
||||
{
|
||||
retValue = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AtsConfigurator.log("Configure.keyStoreAlreadyExists()- End, retValue = " + retValue );
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the server keystore.
|
||||
*
|
||||
* @return Return code.
|
||||
*/
|
||||
int createServerKeystore()
|
||||
{
|
||||
int rc = AtsConfigurator.ERROR_NO_ERROR;
|
||||
|
||||
AtsConfigurator.log("Configure.createServerKeystore()- Start");
|
||||
|
||||
// Proceed only if the server keystore has not been created
|
||||
if (!keyStoreAlreadyExists(SERVER_KEY_STORE_RELATIVE_PATH))
|
||||
{
|
||||
String keytoolPath = m_properties.get(AtsConfigurator.JAVA_HOME_PROPERTY) + "\\bin\\keytool";
|
||||
String installDir = (String) m_properties.get(AtsConfigurator.INSTALL_DIR_PROPERTY);
|
||||
|
||||
// Allocate and setup commandArray to create signing key
|
||||
String[] commandArray = new String[14];
|
||||
commandArray[0] = keytoolPath;
|
||||
commandArray[1] = "-genkey";
|
||||
commandArray[2] = "-alias"; commandArray[3] = "signingKey";
|
||||
commandArray[4] = "-keypass"; commandArray[5] = "secret";
|
||||
commandArray[6] = "-keystore"; commandArray[7] = installDir + SERVER_KEY_STORE_RELATIVE_PATH;
|
||||
commandArray[8] = "-storepass"; commandArray[9] = "secret";
|
||||
commandArray[10] = "-dname"; commandArray[11] = "cn=casaatsd@" + (String) m_properties.get("COMPUTERNAME");
|
||||
commandArray[12] = "-validity"; commandArray[13] = "3600";
|
||||
|
||||
// Create the signing key
|
||||
if (AtsConfigurator.ERROR_NO_ERROR == (rc =AtsConfigurator.invokeExternalCommand(commandArray)))
|
||||
{
|
||||
// Allocate and setup commandArray to export the signing certificate
|
||||
commandArray = new String[12];
|
||||
commandArray[0] = keytoolPath;
|
||||
commandArray[1] = "-export";
|
||||
commandArray[2] = "-alias"; commandArray[3] = "signingKey";
|
||||
commandArray[4] = "-keypass"; commandArray[5] = "secret";
|
||||
commandArray[6] = "-keystore"; commandArray[7] = installDir + SERVER_KEY_STORE_RELATIVE_PATH;
|
||||
commandArray[8] = "-storepass"; commandArray[9] = "secret";
|
||||
commandArray[10] = "-file"; commandArray[11] = installDir + SIGNING_CERT_RELATIVE_PATH;
|
||||
|
||||
// Export self-signed certificate for the signing key
|
||||
if (AtsConfigurator.ERROR_NO_ERROR == (rc = AtsConfigurator.invokeExternalCommand(commandArray)))
|
||||
{
|
||||
// Allocate and setup commandArray to create key for Tomcat to do SSL communications
|
||||
commandArray = new String[14];
|
||||
commandArray[0] = keytoolPath;
|
||||
commandArray[1] = "-genkey";
|
||||
commandArray[2] = "-alias"; commandArray[3] = "tomcat";
|
||||
commandArray[4] = "-keypass"; commandArray[5] = "secret";
|
||||
commandArray[6] = "-keystore"; commandArray[7] = installDir + SERVER_KEY_STORE_RELATIVE_PATH;
|
||||
commandArray[8] = "-storepass"; commandArray[9] = "secret";
|
||||
commandArray[10] = "-dname"; commandArray[11] = "cn=" + (String) m_properties.get("COMPUTERNAME");
|
||||
commandArray[12] = "-keyalg"; commandArray[13] = "RSA";
|
||||
|
||||
// Create a key for Tomcat to do SSL communications
|
||||
rc = AtsConfigurator.invokeExternalCommand(commandArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AtsConfigurator.log("Configure.createServerKeystore()- End, rc= ", rc);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the client keystore.
|
||||
*
|
||||
* @return Return code.
|
||||
*/
|
||||
int createClientKeystore()
|
||||
{
|
||||
int rc = AtsConfigurator.ERROR_NO_ERROR;
|
||||
|
||||
AtsConfigurator.log("Configure.createClientKeystore()- Start");
|
||||
|
||||
// Proceed only if the client keystore has not been created
|
||||
if (!keyStoreAlreadyExists(CLIENT_KEY_STORE_RELATIVE_PATH))
|
||||
{
|
||||
String keytoolPath = m_properties.get(AtsConfigurator.JAVA_HOME_PROPERTY) + "\\bin\\keytool";
|
||||
String installDir = (String) m_properties.get(AtsConfigurator.INSTALL_DIR_PROPERTY);
|
||||
|
||||
// Allocate and setup commandArray to export the signing certificate
|
||||
String[] commandArray = new String[13];
|
||||
commandArray[0] = keytoolPath;
|
||||
commandArray[1] = "-import";
|
||||
commandArray[2] = "-noprompt";
|
||||
commandArray[3] = "-alias"; commandArray[4] = "signingCert";
|
||||
commandArray[5] = "-keypass"; commandArray[6] = "secret";
|
||||
commandArray[7] = "-keystore"; commandArray[8] = installDir + CLIENT_KEY_STORE_RELATIVE_PATH;
|
||||
commandArray[9] = "-storepass"; commandArray[10] = "secret";
|
||||
commandArray[11] = "-file"; commandArray[12] = installDir + SIGNING_CERT_RELATIVE_PATH;
|
||||
|
||||
// Import the servers certificate in the client keystore
|
||||
rc = AtsConfigurator.invokeExternalCommand(commandArray);
|
||||
}
|
||||
|
||||
AtsConfigurator.log("Configure.createClientKeystore()- End, rc= ", rc);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create file from template.
|
||||
*
|
||||
* @param fileTemplate Template file.
|
||||
* @param fileOutput Output file path.
|
||||
* @param escapePathCharsInReplaceString Escape Windows Path Chars in Replace String before using.
|
||||
* @param useUnixPathCharsInReplaceString Replace Windows Path Chars with "//" in Replace String before using.
|
||||
* @return Return code.
|
||||
*/
|
||||
int createFileFromTemplate(File fileTemplate, File fileOutput, boolean escapePathCharsInReplaceString, boolean useUnixPathCharsInReplaceString)
|
||||
{
|
||||
int rc = AtsConfigurator.ERROR_NO_ERROR;
|
||||
LineNumberReader lnr = null;
|
||||
FileWriter fwOutput = null;
|
||||
|
||||
AtsConfigurator.log("Configure.createFileFromTemplate()- Start, template = " + fileTemplate);
|
||||
|
||||
try
|
||||
{
|
||||
// Open the files
|
||||
lnr = new LineNumberReader(new FileReader(fileTemplate));
|
||||
try
|
||||
{
|
||||
fwOutput = new FileWriter(fileOutput);
|
||||
try
|
||||
{
|
||||
// For each line of text in the template file...
|
||||
String sLineTemplate;
|
||||
while (null != (sLineTemplate = lnr.readLine()))
|
||||
{
|
||||
String sLineOutput = sLineTemplate;
|
||||
|
||||
// For each term to be replaced...
|
||||
for (int i = 0; i < m_rgsSearchFor.length; i++)
|
||||
{
|
||||
// Replace all instances of the term on the line
|
||||
int iSearchFor;
|
||||
while (-1 != (iSearchFor = sLineOutput.indexOf(m_rgsSearchFor[i])))
|
||||
{
|
||||
// Check if we must escape path characters in replace string
|
||||
String replaceString;
|
||||
if (useUnixPathCharsInReplaceString)
|
||||
{
|
||||
replaceString = m_rgsReplaceWith[i].replace("\\", "//");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (escapePathCharsInReplaceString)
|
||||
replaceString = m_rgsReplaceWith[i].replace("\\", "\\\\");
|
||||
else
|
||||
replaceString = m_rgsReplaceWith[i];
|
||||
}
|
||||
|
||||
AtsConfigurator.log("replacing " + m_rgsSearchFor[i] + " at position " + iSearchFor + " with " + replaceString);
|
||||
sLineOutput = sLineOutput.substring(0, iSearchFor) + replaceString +
|
||||
sLineOutput.substring(iSearchFor + m_rgsSearchFor[i].length());
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
fwOutput.write(sLineOutput + "\r\n");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
rc = AtsConfigurator.ERROR_EXCEPTION;
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up
|
||||
fwOutput.flush();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
rc = AtsConfigurator.ERROR_OUTPUT_COPY_FAILED;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
rc = AtsConfigurator.ERROR_FILEWRITER_CREATE_FAILED;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
rc = AtsConfigurator.ERROR_UNABLE_TO_OPEN_TEMPLATE;
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (lnr != null)
|
||||
lnr.close();
|
||||
|
||||
if (fwOutput != null)
|
||||
fwOutput.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
AtsConfigurator.log("Configure.createFileFromTemplate()- End, rc= ", rc);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup all of the needed relocatable files.
|
||||
*
|
||||
* @return Return code.
|
||||
*/
|
||||
int setupRelocatableFiles()
|
||||
{
|
||||
int rc;
|
||||
|
||||
AtsConfigurator.log("Configure.setupRelocatableFiles()- Start");
|
||||
|
||||
String installDir = (String) m_properties.get(AtsConfigurator.INSTALL_DIR_PROPERTY);
|
||||
if (AtsConfigurator.ERROR_NO_ERROR == (rc = createFileFromTemplate(new File(installDir + "\\etc\\svc\\templates\\server-sun.xml"),
|
||||
new File(installDir + "\\catalinabase\\conf\\server.xml"),
|
||||
false, false)))
|
||||
if (AtsConfigurator.ERROR_NO_ERROR == (rc = createFileFromTemplate(new File(installDir + "\\etc\\svc\\templates\\startup.bat"),
|
||||
new File(installDir + "\\bin\\startup.bat"),
|
||||
false, false)))
|
||||
if (AtsConfigurator.ERROR_NO_ERROR == (rc = createFileFromTemplate(new File(installDir + "\\etc\\svc\\templates\\shutdown.bat"),
|
||||
new File(installDir + "\\bin\\shutdown.bat"),
|
||||
false, false)))
|
||||
if (AtsConfigurator.ERROR_NO_ERROR == (rc = createFileFromTemplate(new File(installDir + "\\etc\\svc\\templates\\CasaAuthPolicyEditor.bat"),
|
||||
new File(installDir + "\\bin\\CasaAuthPolicyEditor.bat"),
|
||||
false, false)))
|
||||
if (AtsConfigurator.ERROR_NO_ERROR == (rc = createFileFromTemplate(new File(installDir + "\\etc\\svc\\templates\\CasaAuthTokenSettingsEditor.bat"),
|
||||
new File(installDir + "\\bin\\CasaAuthTokenSettingsEditor.bat"),
|
||||
false, false)))
|
||||
if (AtsConfigurator.ERROR_NO_ERROR == (rc = createFileFromTemplate(new File(installDir + "\\etc\\svc\\templates\\CasaIdenTokenSettingsEditor.bat"),
|
||||
new File(installDir + "\\bin\\CasaIdenTokenSettingsEditor.bat"),
|
||||
false, false)))
|
||||
if (AtsConfigurator.ERROR_NO_ERROR == (rc = createFileFromTemplate(new File(installDir + "\\etc\\svc\\templates\\CasaSvcSettingsEditor.bat"),
|
||||
new File(installDir + "\\bin\\CasaSvcSettingsEditor.bat"),
|
||||
false, false)))
|
||||
if (AtsConfigurator.ERROR_NO_ERROR == (rc = createFileFromTemplate(new File(installDir + "\\etc\\svc\\templates\\svc.settings"),
|
||||
new File(installDir + "\\etc\\svc\\svc.settings"),
|
||||
false, false)))
|
||||
if (AtsConfigurator.ERROR_NO_ERROR == (rc = createFileFromTemplate(new File(installDir + "\\etc\\svc\\templates\\jaas.conf"),
|
||||
new File(installDir + "\\etc\\svc\\jaas.conf"),
|
||||
false, false)))
|
||||
if (AtsConfigurator.ERROR_NO_ERROR == (rc = createFileFromTemplate(new File(installDir + "\\etc\\svc\\templates\\casa_crypto.properties"),
|
||||
new File(installDir + "\\etc\\svc\\casa_crypto.properties"),
|
||||
false, true)))
|
||||
rc = createFileFromTemplate(new File(installDir + "\\etc\\svc\\templates\\log4j.properties"),
|
||||
new File(installDir + "\\etc\\svc\\log4j.properties"),
|
||||
true, false);
|
||||
|
||||
AtsConfigurator.log("Configure.setupRelocatableFiles()- End, rc= ", rc);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move files from Jar to Jar.
|
||||
*
|
||||
* @param josDst Destination Jar Output stream.
|
||||
* @param jfSrc Source Jar.
|
||||
* @return Return code.
|
||||
*/
|
||||
int moveFilesFromJarToJar(ZipOutputStream josDst, ZipFile jfSrc)
|
||||
{
|
||||
int rc = AtsConfigurator.ERROR_NO_ERROR;
|
||||
|
||||
AtsConfigurator.log("Configure.moveFilesFromJarToJar()- Start");
|
||||
|
||||
try
|
||||
{
|
||||
Enumeration entries = jfSrc.entries();
|
||||
while (entries.hasMoreElements())
|
||||
{
|
||||
ZipEntry jeLoop = (ZipEntry)entries.nextElement();
|
||||
|
||||
// Skip WEB-INF/classes/cypto.properties
|
||||
if (jeLoop.getName().equalsIgnoreCase("WEB-INF/classes/casa_crypto.properties"))
|
||||
{
|
||||
AtsConfigurator.log("skipping: " + "WEB-INF/classes/casa_crypto.properties");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Move the rest of the files over
|
||||
else
|
||||
{
|
||||
AtsConfigurator.log("Transferring jar file: " + jeLoop.getName());
|
||||
|
||||
// Create the input stream
|
||||
InputStream isLoop = jfSrc.getInputStream(jeLoop);
|
||||
|
||||
// Set up the output stream
|
||||
ZipEntry zeIndex = new ZipEntry(jeLoop.getName());
|
||||
josDst.putNextEntry( zeIndex);
|
||||
|
||||
// Transfer the file contents
|
||||
int bRead;
|
||||
byte [] b = new byte[4096];
|
||||
while (-1 != (bRead = isLoop.read(b)))
|
||||
{
|
||||
josDst.write(b, 0, bRead);
|
||||
}
|
||||
|
||||
// all done
|
||||
josDst.closeEntry();
|
||||
isLoop.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
rc = AtsConfigurator.ERROR_JAR_COPY_FAILED;
|
||||
}
|
||||
|
||||
AtsConfigurator.log("Configure.moveFilesFromJarToJar()- End, rc= ", rc);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add file to Jar.
|
||||
*
|
||||
* @param sFilename Path to file.
|
||||
* @param sName Zip entry name.
|
||||
* @param josJarNew Jar output stream.
|
||||
* @return Return code.
|
||||
*/
|
||||
int addFileToJar(String sFilename, String sName, ZipOutputStream josJarNew)
|
||||
{
|
||||
int rc = AtsConfigurator.ERROR_NO_ERROR;
|
||||
|
||||
AtsConfigurator.log("Configure.addFileToJar()- Start");
|
||||
|
||||
try
|
||||
{
|
||||
// Create the input stream
|
||||
FileInputStream fis = new FileInputStream(sFilename);
|
||||
|
||||
// Set up the output stream
|
||||
ZipEntry je = new ZipEntry(sName);
|
||||
josJarNew.putNextEntry(je);
|
||||
|
||||
// Tansfer the contents of the file
|
||||
int bRead;
|
||||
byte [] b = new byte[4096];
|
||||
while (-1 != (bRead = fis.read(b)))
|
||||
{
|
||||
josJarNew.write(b, 0, bRead);
|
||||
}
|
||||
|
||||
// All done
|
||||
fis.close();
|
||||
josJarNew.closeEntry();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
AtsConfigurator.log(e.toString());
|
||||
rc = AtsConfigurator.ERROR_ADD_FILE_TO_JAR_FAILED;
|
||||
}
|
||||
|
||||
AtsConfigurator.log("Configure.addFileToJar()- End, rc= ", rc);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create War file from template.
|
||||
*
|
||||
* @return Return code.
|
||||
*/
|
||||
int createWarFileFromTemplate()
|
||||
{
|
||||
String sWarTemplate = ((String) m_properties.get(AtsConfigurator.INSTALL_DIR_PROPERTY)) + "\\etc\\svc\\templates\\CasaAuthTokenSvc.war";
|
||||
String sWarNew = ((String) m_properties.get(AtsConfigurator.INSTALL_DIR_PROPERTY)) + "\\catalinabase\\webapps\\CasaAuthTokenSvc.war";
|
||||
File fileWarTemplate = new File(sWarTemplate);
|
||||
File fileWarNew = new File(sWarNew);
|
||||
FileOutputStream fosWarNew = null;
|
||||
ZipOutputStream josWarNew = null;
|
||||
ZipFile jfTemplate = null;
|
||||
int rc = AtsConfigurator.ERROR_NO_ERROR;
|
||||
|
||||
AtsConfigurator.log("Configure.createWarFileFromTemplate()- Start");
|
||||
|
||||
// Ensure that the war template exists
|
||||
AtsConfigurator.log("looking for war template: " + sWarTemplate);
|
||||
if (!fileWarTemplate.exists())
|
||||
{
|
||||
rc = AtsConfigurator.ERROR_WAR_TEMPLATE_FILE_MISSING;
|
||||
}
|
||||
|
||||
if (rc == AtsConfigurator.ERROR_NO_ERROR)
|
||||
{
|
||||
// Ensure that the new jar name does not exist
|
||||
if (fileWarNew.exists())
|
||||
{
|
||||
AtsConfigurator.log("war file already exists: " + sWarNew);
|
||||
if (!fileWarNew.delete())
|
||||
{
|
||||
AtsConfigurator.log("could not delete war file: " + sWarNew);
|
||||
rc = AtsConfigurator.ERROR_NEW_JAR_CANNOT_BE_REPLACED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rc == AtsConfigurator.ERROR_NO_ERROR)
|
||||
{
|
||||
// Create/open the new jar
|
||||
try
|
||||
{
|
||||
AtsConfigurator.log("create new war file output stream: " + sWarNew);
|
||||
fosWarNew = new FileOutputStream(fileWarNew);
|
||||
josWarNew = new ZipOutputStream(fosWarNew);
|
||||
}
|
||||
catch (IOException ioe0)
|
||||
{
|
||||
AtsConfigurator.log(ioe0.toString());
|
||||
rc = AtsConfigurator.ERROR_CREATE_WAR_FOS_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
if (rc == AtsConfigurator.ERROR_NO_ERROR)
|
||||
{
|
||||
// Open the old jar
|
||||
try
|
||||
{
|
||||
jfTemplate = new ZipFile(sWarTemplate);
|
||||
}
|
||||
catch (IOException ioe1)
|
||||
{
|
||||
rc = AtsConfigurator.ERROR_OPEN_JAR_TEMPLATE_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
if (rc == AtsConfigurator.ERROR_NO_ERROR)
|
||||
{
|
||||
// Transfer the files
|
||||
rc = moveFilesFromJarToJar(josWarNew, jfTemplate);
|
||||
}
|
||||
|
||||
// Add the files
|
||||
if (rc == AtsConfigurator.ERROR_NO_ERROR)
|
||||
{
|
||||
int i;
|
||||
String [] rgsFilesToAdd = new String[1];
|
||||
rgsFilesToAdd[0] = ((String) m_properties.get(AtsConfigurator.INSTALL_DIR_PROPERTY)) + "\\etc\\svc\\casa_crypto.properties";
|
||||
String [] rgsNames = new String[1];
|
||||
rgsNames[0] = "WEB-INF/classes/casa_crypto.properties";
|
||||
for (i = 0; i < rgsFilesToAdd.length; i++)
|
||||
{
|
||||
AtsConfigurator.log("Adding file: " + rgsFilesToAdd[i] + " with name " + rgsNames[i]);
|
||||
rc = addFileToJar(rgsFilesToAdd[i], rgsNames[i], josWarNew);
|
||||
}
|
||||
}
|
||||
|
||||
// Close up
|
||||
if (null != josWarNew)
|
||||
{
|
||||
try
|
||||
{
|
||||
josWarNew.flush();
|
||||
}
|
||||
catch (IOException ioe2)
|
||||
{
|
||||
rc = AtsConfigurator.ERROR_JOS_FLUSH_FAILED;
|
||||
}
|
||||
try
|
||||
{
|
||||
josWarNew.close();
|
||||
}
|
||||
catch (IOException ioe3)
|
||||
{
|
||||
rc = AtsConfigurator.ERROR_JOS_CLOSE_FAILED;
|
||||
}
|
||||
try
|
||||
{
|
||||
fosWarNew.close();
|
||||
}
|
||||
catch (IOException ioe4)
|
||||
{
|
||||
rc = AtsConfigurator.ERROR_FOS_CLOSE_FAILED;
|
||||
}
|
||||
}
|
||||
if (null != jfTemplate)
|
||||
{
|
||||
try
|
||||
{
|
||||
jfTemplate.close();
|
||||
}
|
||||
catch (IOException ioe5)
|
||||
{
|
||||
rc = AtsConfigurator.ERROR_JFTEMPLATE_CLOSE_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
AtsConfigurator.log("Configure.createWarFileFromTemplate()- End, rc= ", rc);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create ATS Service.
|
||||
*
|
||||
* @return Return code.
|
||||
*/
|
||||
int createATSService()
|
||||
{
|
||||
int rc = AtsConfigurator.ERROR_NO_ERROR;
|
||||
|
||||
AtsConfigurator.log("Configure.createATSService()- Start");
|
||||
|
||||
String installDir = (String) m_properties.get(AtsConfigurator.INSTALL_DIR_PROPERTY);
|
||||
String sDirCatalinaBase = installDir + "/catalinabase";
|
||||
String sDirCatalinaHome = (String) m_properties.get(AtsConfigurator.TOMCAT_HOME_PROPERTY);
|
||||
String sExe = ((String) m_properties.get(AtsConfigurator.TOMCAT_HOME_PROPERTY)) + "\\bin\\tomcat5.exe";
|
||||
String sFileJaasConf = installDir + "\\etc\\svc\\jaas.conf";
|
||||
String sDirConfig = installDir + "/etc/svc";
|
||||
String sDirJavaHome = (String) m_properties.get(AtsConfigurator.JAVA_HOME_PROPERTY);
|
||||
String sLogPrefix = "casa-auth-token-svc";
|
||||
String sDirLogs = sDirCatalinaBase + "/logs";
|
||||
|
||||
/*
|
||||
* Note that in the following code we do not bother to check the return of the invokeExternalCommand
|
||||
* call. This is because I have found that some versions of tomcat5.exe do not always return success
|
||||
* even though they should.
|
||||
*/
|
||||
String[] commandArray = {
|
||||
sExe, "//IS//CasaAuthTokenService", "--StartClass", "org.apache.catalina.startup.Bootstrap", "--StopClass", "org.apache.catalina.startup.Bootstrap", "--StartParams", "start", "--StopParams", "stop", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
|
||||
};
|
||||
AtsConfigurator.invokeExternalCommand(commandArray);
|
||||
|
||||
String[] commandArray1 = {
|
||||
sExe, "//US//CasaAuthTokenService", "--Startup", "auto", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
|
||||
};
|
||||
AtsConfigurator.invokeExternalCommand(commandArray1);
|
||||
|
||||
String[] commandArray2 = {
|
||||
sExe, "//US//CasaAuthTokenService", "--JvmOptions", "\"-Dcatalina.base=" + sDirCatalinaBase + "\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
|
||||
};
|
||||
AtsConfigurator.invokeExternalCommand(commandArray2);
|
||||
|
||||
String[] commandArray3 = {
|
||||
sExe, "//US//CasaAuthTokenService", "++JvmOptions", "\"-Dcatalina.home=" + sDirCatalinaHome + "\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
|
||||
};
|
||||
AtsConfigurator.invokeExternalCommand(commandArray3);
|
||||
|
||||
String[] commandArray4 = {
|
||||
sExe, "//US//CasaAuthTokenService", "++JvmOptions", "\"-Djava.endorsed.dirs=" + sDirCatalinaHome + "/common/endorsed\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
|
||||
};
|
||||
AtsConfigurator.invokeExternalCommand(commandArray4);
|
||||
|
||||
String[] commandArray5 = {
|
||||
sExe, "//US//CasaAuthTokenService", "++JvmOptions", "\"-Djava.security.auth.login.config=" + sFileJaasConf + "\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
|
||||
};
|
||||
AtsConfigurator.invokeExternalCommand(commandArray5);
|
||||
|
||||
String[] commandArray6 = {
|
||||
sExe, "//US//CasaAuthTokenService", "++JvmOptions", "\"-Dcom.novell.casa.authtoksvc.config=" + sDirConfig + "\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
|
||||
};
|
||||
AtsConfigurator.invokeExternalCommand(commandArray6);
|
||||
|
||||
String[] commandArray7 = {
|
||||
sExe, "//US//CasaAuthTokenService", "++JvmOptions", "\"-Dlog4j.configuration=file:" + installDir + "/etc/log4j.properties" + "\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
|
||||
};
|
||||
AtsConfigurator.invokeExternalCommand(commandArray7);
|
||||
|
||||
String[] commandArray8 = {
|
||||
sExe, "//US//CasaAuthTokenService", "++JvmOptions", "\"-Djava.io.tmpdir=" + sDirCatalinaBase+ "/temp\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
|
||||
};
|
||||
AtsConfigurator.invokeExternalCommand(commandArray8);
|
||||
|
||||
String[] commandArray9 = {
|
||||
sExe, "//US//CasaAuthTokenService", "--StartMode", "jvm", "--StopMode", "jvm", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
|
||||
};
|
||||
AtsConfigurator.invokeExternalCommand(commandArray9);
|
||||
|
||||
String[] commandArray10 = {
|
||||
sExe, "//US//CasaAuthTokenService", "--JvmMs", "128", "--JvmMx", "512", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
|
||||
};
|
||||
AtsConfigurator.invokeExternalCommand(commandArray10);
|
||||
|
||||
String[] commandArray11 = {
|
||||
sExe, "//US//CasaAuthTokenService", "--Classpath", "\"" + sDirCatalinaHome + "/bin/bootstrap.jar\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
|
||||
};
|
||||
AtsConfigurator.invokeExternalCommand(commandArray11);
|
||||
|
||||
String[] commandArray12 = {
|
||||
sExe, "//US//CasaAuthTokenService", "--Jvm", "\"" + sDirJavaHome + "/jre/bin/server/jvm.dll\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
|
||||
};
|
||||
AtsConfigurator.invokeExternalCommand(commandArray12);
|
||||
|
||||
String[] commandArray13 = {
|
||||
sExe, "//US//CasaAuthTokenService", "--LogPath", "\"" + sDirLogs + "\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
|
||||
};
|
||||
AtsConfigurator.invokeExternalCommand(commandArray13);
|
||||
|
||||
String[] commandArray14 = {
|
||||
sExe, "//US//CasaAuthTokenService", "--LogPrefix", "\"" + sLogPrefix + "_service.log\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
|
||||
};
|
||||
AtsConfigurator.invokeExternalCommand(commandArray14);
|
||||
|
||||
String[] commandArray15 = {
|
||||
sExe, "//US//CasaAuthTokenService", "--StdOutput", "\"" + sDirLogs + File.separator + sLogPrefix + "_stdout.log\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
|
||||
};
|
||||
AtsConfigurator.invokeExternalCommand(commandArray15);
|
||||
|
||||
String[] commandArray16 = {
|
||||
sExe, "//US//CasaAuthTokenService", "--StdError", "\"" + sDirLogs + File.separator + sLogPrefix + "_stderr.log\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
|
||||
};
|
||||
AtsConfigurator.invokeExternalCommand(commandArray16);
|
||||
|
||||
String[] commandArray17 = {
|
||||
sExe, "//US//CasaAuthTokenService", "--DisplayName", "CasaAuthTokenSvc", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
|
||||
};
|
||||
AtsConfigurator.invokeExternalCommand(commandArray17);
|
||||
|
||||
String[] commandArray18 = {
|
||||
sExe, "//US//CasaAuthTokenService", "--Description", "\"Casa Authentication Token Service\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
|
||||
};
|
||||
AtsConfigurator.invokeExternalCommand(commandArray18);
|
||||
|
||||
AtsConfigurator.log("Configure.createATSService()- End, rc= ", rc);
|
||||
|
||||
return rc;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Copyright (C) 2006 Novell, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# Author: Juan Carlos Luciani <jluciani@novell.com>
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
DIST_SUBDIRS =
|
||||
|
||||
JAVAFILES = AtsConfigurator.java \
|
||||
Configure.java \
|
||||
Unconfigure.java
|
||||
|
||||
|
||||
EXTRA_DIST = $(JAVAFILES)
|
||||
|
||||
.PHONY: package package-clean package-install package-uninstall
|
||||
package package-clean package-install package-uninstall:
|
||||
$(MAKE) -C $(TARGET_OS) $@
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -f Makefile.in
|
||||
|
@ -0,0 +1,101 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright (C) 2006 Novell, Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, Novell, Inc.
|
||||
*
|
||||
* To contact Novell about this file by physical or electronic mail,
|
||||
* you may find current contact information at www.novell.com.
|
||||
*
|
||||
* Authors: Juan Carlos Luciani <jluciani@novell.com>
|
||||
* Greg Richardson <grichardson@novell.com>
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
import java.util.Properties;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Unconfigure Class.
|
||||
* <p>
|
||||
* This class readies the Authentication Token Service to be un-installed.
|
||||
*/
|
||||
public class Unconfigure
|
||||
{
|
||||
// Configured properties
|
||||
Properties m_properties;
|
||||
|
||||
// Completion code
|
||||
int m_rc;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param properties Configuration properties.
|
||||
*/
|
||||
Unconfigure(Properties properties)
|
||||
{
|
||||
m_rc = AtsConfigurator.ERROR_NO_ERROR;
|
||||
|
||||
AtsConfigurator.log("Unconfigure()- Start");
|
||||
|
||||
try
|
||||
{
|
||||
// Save the properties
|
||||
m_properties = properties;
|
||||
|
||||
// delete the ATS service
|
||||
m_rc = deleteATSService();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_rc = AtsConfigurator.ERROR_EXCEPTION;
|
||||
AtsConfigurator.log("Exception" + e.getMessage());
|
||||
}
|
||||
|
||||
AtsConfigurator.log("Unconfigure()- End, rc= ", m_rc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete ATS Service.
|
||||
*
|
||||
* @return Return code.
|
||||
*/
|
||||
int deleteATSService()
|
||||
{
|
||||
int rc = AtsConfigurator.ERROR_NO_ERROR;
|
||||
String sExe = ((String) m_properties.get(AtsConfigurator.TOMCAT_HOME_PROPERTY)) + "\\bin\\tomcat5.exe";
|
||||
|
||||
AtsConfigurator.log("Unconfigure.deleteATSService()- Start");
|
||||
|
||||
/*
|
||||
* Note that in the following code we do not bother to check the return of the invokeExternalCommand
|
||||
* call. This is because I have found that some versions of tomcat5.exe do not always return success
|
||||
* even though they should.
|
||||
*/
|
||||
String[] commandArray = {
|
||||
sExe, "//SS//CasaAuthTokenService", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcUninstall.log"
|
||||
};
|
||||
AtsConfigurator.invokeExternalCommand(commandArray);
|
||||
|
||||
String[] commandArray1 = {
|
||||
sExe, "//DS//CasaAuthTokenService", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcUninstall.log"
|
||||
};
|
||||
AtsConfigurator.invokeExternalCommand(commandArray1);
|
||||
|
||||
AtsConfigurator.log("Unconfigure().deleteATSService- End, rc= ", rc);
|
||||
|
||||
return rc;
|
||||
}
|
||||
}
|
@ -1,408 +0,0 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright (C) 2006 Novell, Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, Novell, Inc.
|
||||
*
|
||||
* To contact Novell about this file by physical or electronic mail,
|
||||
* you may find current contact information at www.novell.com.
|
||||
*
|
||||
* Author: Greg Richardson <grichardson@novell.com>
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class ClientKeystoreSetup
|
||||
{
|
||||
final static int ERROR_NO_ERROR = 0;
|
||||
final static int ERROR_EXEC_FAILED = -1;
|
||||
final static int ERROR_INVALID_NUMBER_OF_PARAMS = -2;
|
||||
final static int ERROR_BAD_INSTALL_DIR_PARAM = -3;
|
||||
final static int ERROR_MISSING_INSTALL_DIR = -4;
|
||||
final static int ERROR_INSTALL_DIR_NOT_A_DIR = -5;
|
||||
final static int ERROR_BAD_PROPERTY_FILE_PARAM = -6;
|
||||
final static int ERROR_MISSING_PROPERTIES_FILE = -7;
|
||||
final static int ERROR_UNABLE_TO_READ_PROPERTIES = -8;
|
||||
final static int ERROR_UNKNOWN_PARAM = -9;
|
||||
final static int ERROR_MISSING_INSTALL_DIR_PARAM = -10;
|
||||
final static int ERROR_REQUIRED_VALUE_MISSING = -11;
|
||||
final static int ERROR_EXEC_INTERRUPTED = -12;
|
||||
final static int ERROR_IO_EXCEPTION = -13;
|
||||
final static int ERROR_EXCEPTION = -14;
|
||||
|
||||
final static String INSTALL_DIR = "installdir=";
|
||||
final static String PROPERTY_FILE = "propertyfile=";
|
||||
|
||||
String sInstallDir;
|
||||
Properties properties;
|
||||
int rc;
|
||||
|
||||
// debug stuff
|
||||
//File file;
|
||||
//FileWriter fw;
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
ClientKeystoreSetup p = new ClientKeystoreSetup(args);
|
||||
System.exit(p.rc);
|
||||
}
|
||||
|
||||
ClientKeystoreSetup(String[] args)
|
||||
{
|
||||
rc = ERROR_NO_ERROR;
|
||||
|
||||
try
|
||||
{
|
||||
// DEBUG STUFF
|
||||
//file = new File("c:\\test4.log");
|
||||
//fw = new FileWriter(file);
|
||||
|
||||
log("Here we go again: " + args.length);
|
||||
for (int i = 0; i < args.length; i++)
|
||||
{
|
||||
log("Arg " + i + " = " + args[i] + "\r\n");
|
||||
}
|
||||
// DEBUG STUFF
|
||||
|
||||
// Process the input params
|
||||
if (ERROR_NO_ERROR == (rc = processArgs(args)))
|
||||
{
|
||||
// Make sure we got everything we need
|
||||
if (ERROR_NO_ERROR == (rc = findRequiredValues()))
|
||||
{
|
||||
// Make sure the client keystore has been created
|
||||
rc = createClientKeystore();
|
||||
}
|
||||
}
|
||||
|
||||
// DEBUG STUFF
|
||||
log(rc);
|
||||
//fw.flush();
|
||||
//fw.close();
|
||||
// DEBUG STUFF
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
rc = ERROR_EXCEPTION;
|
||||
}
|
||||
}
|
||||
|
||||
int processArgs(String[] argsOld)
|
||||
{
|
||||
String sProperties;
|
||||
File fileInstallDir = null;
|
||||
File fileProperties = null;
|
||||
FileInputStream fisProperties = null;
|
||||
int iOld;
|
||||
int i;
|
||||
String args[] = new String[argsOld.length];
|
||||
int iNew;
|
||||
|
||||
log("Original arg count " + argsOld.length);
|
||||
for (i = 0; i < argsOld.length; i++)
|
||||
{
|
||||
log("Arg " + i + " = " + argsOld[i] + "\r\n");
|
||||
}
|
||||
|
||||
// Validate the number of parameters
|
||||
if (argsOld.length < 2)
|
||||
{
|
||||
return ERROR_INVALID_NUMBER_OF_PARAMS;
|
||||
}
|
||||
|
||||
iNew = -1;
|
||||
for (iOld = 0; iOld < argsOld.length; iOld++)
|
||||
{
|
||||
if (0 <= argsOld[iOld].indexOf("="))
|
||||
{
|
||||
iNew++;
|
||||
args[iNew] = argsOld[iOld];
|
||||
for (i = iOld + 1; i < argsOld.length && (-1 == argsOld[i].indexOf("=")); i++)
|
||||
{
|
||||
args[iNew] += " " + argsOld[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log("New arg count " + args.length);
|
||||
for (i = 0; i < args.length; i++)
|
||||
{
|
||||
log("Arg " + i + " = " + args[i] + "\r\n");
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i <= iNew; i++)
|
||||
{
|
||||
// is this the install dir param?
|
||||
if (args[i].startsWith(INSTALL_DIR))
|
||||
{
|
||||
// Make sure it is more the the param tag
|
||||
if (args[i].length() <= INSTALL_DIR.length())
|
||||
{
|
||||
return ERROR_BAD_INSTALL_DIR_PARAM;
|
||||
}
|
||||
|
||||
sInstallDir = args[i].substring(INSTALL_DIR.length()).trim();
|
||||
fileInstallDir = new File(sInstallDir);
|
||||
|
||||
// Make sure the install dir can be found
|
||||
if (!fileInstallDir.exists())
|
||||
{
|
||||
return ERROR_MISSING_INSTALL_DIR;
|
||||
}
|
||||
|
||||
// Make sure the install dir is a directory
|
||||
if (!fileInstallDir.isDirectory())
|
||||
{
|
||||
return ERROR_INSTALL_DIR_NOT_A_DIR;
|
||||
}
|
||||
}
|
||||
|
||||
// is this the properties file param?
|
||||
else if (args[i].startsWith(PROPERTY_FILE))
|
||||
{
|
||||
// Make sure it is more the the param tag
|
||||
if (args[i].length() <= PROPERTY_FILE.length())
|
||||
{
|
||||
return ERROR_BAD_PROPERTY_FILE_PARAM;
|
||||
}
|
||||
|
||||
sProperties = args[i].substring(PROPERTY_FILE.length()).trim();
|
||||
fileProperties = new File(sProperties);
|
||||
|
||||
// Make sure the properties file can be found
|
||||
if (!fileProperties.exists())
|
||||
{
|
||||
return ERROR_MISSING_PROPERTIES_FILE;
|
||||
}
|
||||
|
||||
// Read the properties
|
||||
try
|
||||
{
|
||||
fisProperties = new FileInputStream(fileProperties);
|
||||
properties = new Properties();
|
||||
properties.load(fisProperties);
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
return ERROR_UNABLE_TO_READ_PROPERTIES;
|
||||
}
|
||||
}
|
||||
|
||||
// Unknown parameter
|
||||
else
|
||||
{
|
||||
log(ERROR_UNKNOWN_PARAM, args[i]);
|
||||
return ERROR_UNKNOWN_PARAM;
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we got an install dir
|
||||
if (null == fileInstallDir)
|
||||
{
|
||||
return ERROR_MISSING_INSTALL_DIR_PARAM;
|
||||
}
|
||||
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
int findRequiredValues()
|
||||
{
|
||||
String[] rgsRequired = {
|
||||
"ATS_JAVA_HOME"};
|
||||
int i;
|
||||
String sValue;
|
||||
|
||||
for (i = 0; i < rgsRequired.length; i++)
|
||||
{
|
||||
log("look for required value: " + rgsRequired[i]);
|
||||
|
||||
if (!properties.containsKey(rgsRequired[i]))
|
||||
{
|
||||
log("look for required value in envirement: " + rgsRequired[i]);
|
||||
if (null == (sValue = System.getProperty(rgsRequired[i])))
|
||||
{
|
||||
log("unable to find required value in envirement: " + rgsRequired[i]);
|
||||
return ERROR_REQUIRED_VALUE_MISSING;
|
||||
}
|
||||
log("found required value in envirement: " + rgsRequired[i] + " = " + sValue);
|
||||
properties.put(rgsRequired[i], sValue);
|
||||
}
|
||||
log("found required value: " + rgsRequired[i] + " = " + properties.get(rgsRequired[i]));
|
||||
}
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
int createClientKeystore()
|
||||
{
|
||||
int rc;
|
||||
String sKeytool = properties.get("ATS_JAVA_HOME") + "\\bin\\keytool.exe";
|
||||
|
||||
log("keytool = " + sKeytool);
|
||||
|
||||
// Do not do anything if the server keystore has already been created
|
||||
if (keyStoreAlreadyExists())
|
||||
{
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
// Import the servers certificate in the client keystore
|
||||
rc = invokeCommand(sKeytool + " -import -noprompt -keystore " +
|
||||
sInstallDir + "ats\\etc\\keys\\client\\jks-store -alias signingCert -storepass secret -keypass secret -file " +
|
||||
sInstallDir + "ats\\etc\\keys\\casaatsdSigningCert");
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
boolean keyStoreAlreadyExists()
|
||||
{
|
||||
File fileKeystore = new File(sInstallDir + "ats\\etc\\keys\\client\\jks-store");
|
||||
|
||||
// Why is this always returning true? exists() also always returns true.
|
||||
// log("keystore (" + sInstallDir + "ats\\etc\\keys\\client\\jks-store" + ") already exists = " + (file.isFile()));
|
||||
// return (file.isFile());
|
||||
|
||||
File fileParent = fileKeystore.getParentFile();
|
||||
String[] rgChildren = fileParent.list();
|
||||
if (null != rgChildren)
|
||||
{
|
||||
for (int i = 0; i < rgChildren.length; i++)
|
||||
{
|
||||
log("child " + i + " = " + rgChildren[i]);
|
||||
if ("jks-store".equals(rgChildren[i]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int invokeCommand(String sCommand)
|
||||
{
|
||||
Process p;
|
||||
int rc;
|
||||
|
||||
log("invoke command: " + sCommand);
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
|
||||
try
|
||||
{
|
||||
p = runtime.exec(sCommand);
|
||||
try
|
||||
{
|
||||
rc = p.waitFor();
|
||||
log("invoke command return code: " + rc);
|
||||
}
|
||||
catch (InterruptedException ie)
|
||||
{
|
||||
log(ERROR_EXEC_INTERRUPTED, sCommand);
|
||||
return ERROR_EXEC_INTERRUPTED;
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
log("Ioexception");
|
||||
return ERROR_EXEC_FAILED;
|
||||
}
|
||||
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
void log(int err)
|
||||
{
|
||||
log(err, null);
|
||||
}
|
||||
|
||||
void log(int err, String s)
|
||||
{
|
||||
String sMessage = "";
|
||||
|
||||
switch (err)
|
||||
{
|
||||
case ERROR_NO_ERROR:
|
||||
sMessage = "No error";
|
||||
break;
|
||||
case ERROR_EXEC_FAILED:
|
||||
sMessage = "Execute command failed ";
|
||||
break;
|
||||
case ERROR_INVALID_NUMBER_OF_PARAMS:
|
||||
sMessage = "Invalid number of params";
|
||||
break;
|
||||
case ERROR_BAD_INSTALL_DIR_PARAM:
|
||||
sMessage = "Install dir parameter is bad";
|
||||
break;
|
||||
case ERROR_MISSING_INSTALL_DIR:
|
||||
sMessage = "Missing install dir";
|
||||
break;
|
||||
case ERROR_INSTALL_DIR_NOT_A_DIR:
|
||||
sMessage = "Install dir is not a dir";
|
||||
break;
|
||||
case ERROR_BAD_PROPERTY_FILE_PARAM:
|
||||
sMessage = "Invalid porperty file parameter";
|
||||
break;
|
||||
case ERROR_MISSING_PROPERTIES_FILE:
|
||||
sMessage = "Property file not found";
|
||||
break;
|
||||
case ERROR_UNABLE_TO_READ_PROPERTIES:
|
||||
sMessage = "Unable to read property file";
|
||||
break;
|
||||
case ERROR_UNKNOWN_PARAM:
|
||||
sMessage = "Unknown parameter: ";
|
||||
break;
|
||||
case ERROR_MISSING_INSTALL_DIR_PARAM:
|
||||
sMessage = "Install dir parameter is missing";
|
||||
break;
|
||||
case ERROR_REQUIRED_VALUE_MISSING:
|
||||
sMessage = "Required value is missing ";
|
||||
break;
|
||||
case ERROR_EXEC_INTERRUPTED:
|
||||
sMessage = "Execution iinterrupted: ";
|
||||
break;
|
||||
case ERROR_IO_EXCEPTION:
|
||||
sMessage = "IOException ";
|
||||
break;
|
||||
case ERROR_EXCEPTION:
|
||||
sMessage = "Exception ";
|
||||
break;
|
||||
default:
|
||||
sMessage = "Unknown error";
|
||||
break;
|
||||
}
|
||||
|
||||
if (null != s)
|
||||
{
|
||||
sMessage = sMessage + s;
|
||||
}
|
||||
log(sMessage);
|
||||
}
|
||||
|
||||
void log(String s)
|
||||
{
|
||||
/*
|
||||
try
|
||||
{
|
||||
fw.write(this.getClass().getName() + ": " + s + "\r\n");
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Copyright (C) 2004 Novell, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# Author: Greg Richardson <grichardson@novell.com>
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
DIST_SUBDIRS =
|
||||
|
||||
EXTRA_DIST = ClientKeystoreSetup.java
|
||||
|
||||
if DEBUG
|
||||
TARGET_CFG = Debug
|
||||
DEBUG = -g
|
||||
else
|
||||
TARGET_CFG = Release
|
||||
DEBUG = -g:none
|
||||
endif
|
||||
|
||||
PACKAGE = ClientKeystoreSetup
|
||||
TARGET_FILE = $(PACKAGE).class
|
||||
LOG_FILE = $(PACKAGE).log
|
||||
JAVAFILES = ClientKeystoreSetup.java
|
||||
CLASSES = $(addprefix $(BUILDDIR)/, $(JAVAFILES:%.java=%.class))
|
||||
BUILDDIR = bin/$(TARGET_CFG)
|
||||
|
||||
.PHONY: package package-clean package-install package-uninstall
|
||||
|
||||
all: $(BUILDDIR) $(CLASSES)
|
||||
|
||||
$(BUILDDIR)/%.class: %.java
|
||||
@rm -f $(LOG_FILE) $@
|
||||
@echo [======== Compiling $@ ========]
|
||||
@javac $(DEBUG) -d $(BUILDDIR) $< 2> $(LOG_FILE)
|
||||
@echo $$CMD; \
|
||||
if eval $$CMD; then \
|
||||
ls -l $(BUILDDIR)/$(TARGET_FILE); \
|
||||
cp $(BUILDDIR)/$(TARGET_FILE) bin; \
|
||||
else \
|
||||
grep -a "ERROR:" $(LOG_FILE); \
|
||||
fi
|
||||
|
||||
$(BUILDDIR):
|
||||
[ -d $(BUILDDIR) ] || mkdir -p $(BUILDDIR)
|
||||
|
||||
|
||||
package-clean clean-local:
|
||||
rm -rf bin/Release/* bin/Release bin/Debug/* bin/Debug bin/* bin *.log
|
||||
|
||||
clean:
|
||||
rm -rf bin/Release/* bin/Release bin/Debug/* bin/Debug bin/* bin *.log
|
||||
|
||||
distclean-local: package-clean
|
||||
rm -f Makefile
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -f Makefile.in
|
||||
|
||||
|
||||
|
@ -1,526 +0,0 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright (C) 2006 Novell, Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, Novell, Inc.
|
||||
*
|
||||
* To contact Novell about this file by physical or electronic mail,
|
||||
* you may find current contact information at www.novell.com.
|
||||
*
|
||||
* Author: Greg Richardson <grichardson@novell.com>
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
// CommandLauncher.cpp : Defines the entry point for the application.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "CommandLauncher.h"
|
||||
#include "string.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <conio.h>
|
||||
#include <process.h>
|
||||
#include <errno.h>
|
||||
|
||||
WCHAR ** G_rgArgs; // Command line arguments
|
||||
int G_cArg; // Count of command line arguments
|
||||
//FILE * G_pf;
|
||||
|
||||
// Forward declarations of functions included in this code module:
|
||||
int processArguments(LPTSTR lpCmdLine);
|
||||
void freeArgs();
|
||||
int countArgs(LPTSTR lpCmdLine);
|
||||
int addArg(int iArg, LPTSTR lpString, int cChar);
|
||||
void log(LPTSTR szMessage);
|
||||
_TCHAR * errorMessage(int err);
|
||||
int executeCommand( int cArg, _TCHAR* rgArg[]);
|
||||
|
||||
|
||||
#define ERROR_NO_ERROR 0
|
||||
#define ERROR_MEMORY_ALLOCATION_FAILED -1
|
||||
#define ERROR_INVALID_NUMBER_OF_PARAMETERS -2
|
||||
#define ERROR_EXEC_E2BIG -3
|
||||
#define ERROR_EXEC_EACCES -4
|
||||
#define ERROR_EXEC_EINVAL -5
|
||||
#define ERROR_EXEC_EMFILE -6
|
||||
#define ERROR_EXEC_ENOENT -7
|
||||
#define ERROR_EXEC_ENOEXEC -8
|
||||
#define ERROR_EXEC_ENOMEM -9
|
||||
#define ERROR_EXEC_UNKNOWN -10
|
||||
#define ERROR_STRCPY_FAILED -11
|
||||
#define ERROR_JAVA_EXE_ARG_MISSING -12
|
||||
#define ERROR_JAVA_CLASSPATH_OPTION_ARG_MISSING -13
|
||||
#define ERROR_JAVA_CLASSPATH_ARG_MISSING -14
|
||||
#define ERROR_BAD_COMMAND_LINE -15
|
||||
|
||||
|
||||
|
||||
int APIENTRY _tWinMain(HINSTANCE hInstance,
|
||||
HINSTANCE hPrevInstance,
|
||||
LPTSTR lpCmdLine,
|
||||
int nCmdShow)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(hInstance);
|
||||
UNREFERENCED_PARAMETER(hPrevInstance);
|
||||
UNREFERENCED_PARAMETER(lpCmdLine);
|
||||
UNREFERENCED_PARAMETER(nCmdShow);
|
||||
|
||||
int rc;
|
||||
|
||||
//_wfopen_s(&G_pf, L"C:\\CommandLauncher.log", L"a+");
|
||||
|
||||
// Process the command line
|
||||
if (ERROR_NO_ERROR != (rc = processArguments(lpCmdLine)))
|
||||
{
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = executeCommand(G_cArg, G_rgArgs);
|
||||
|
||||
log(errorMessage(rc));
|
||||
|
||||
//fwprintf(G_pf, L"CommandLauncher: return = %d\n", rc);
|
||||
|
||||
//fclose(G_pf);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
// <java exe path> -cp <classpath> class k1=v1 k2=k2
|
||||
int processArguments(LPTSTR lpCmdLine)
|
||||
{
|
||||
int iArg;
|
||||
int iChar;
|
||||
int iAssignment;
|
||||
int iClassStart;
|
||||
int iClassEnd;
|
||||
int iClassPathStart;
|
||||
int iClassPathEnd;
|
||||
int rc;
|
||||
bool fClasspathOptionFound = false;
|
||||
int iKeyStart;
|
||||
int iValueEnd;
|
||||
|
||||
//fwprintf( G_pf, L"current command line = %s\n", lpCmdLine);
|
||||
|
||||
|
||||
// Validate the command line
|
||||
if (NULL == lpCmdLine || (WCHAR)0 == *lpCmdLine)
|
||||
{
|
||||
return ERROR_BAD_COMMAND_LINE;
|
||||
}
|
||||
|
||||
// Count the arguments on the command line. TThe name of this executable
|
||||
// is not included in the count.
|
||||
G_cArg = countArgs(lpCmdLine);
|
||||
|
||||
// Make sure we got enough to exec something. There must be at least the
|
||||
// path to jave.exe, the classpath option, the classpath and a class.
|
||||
if (G_cArg < 4)
|
||||
{
|
||||
return ERROR_INVALID_NUMBER_OF_PARAMETERS;
|
||||
}
|
||||
|
||||
// Allocate an array of wide string for the arguments, add 1 for a NULL at
|
||||
// the end of the array
|
||||
G_rgArgs = (WCHAR**)malloc((G_cArg + 1) * sizeof(WCHAR *));
|
||||
if (NULL == G_rgArgs)
|
||||
{
|
||||
return ERROR_MEMORY_ALLOCATION_FAILED;
|
||||
}
|
||||
|
||||
// Null out the array
|
||||
memset(G_rgArgs, 0, (G_cArg + 1) * sizeof(WCHAR *));
|
||||
|
||||
// Find the java.exe argument
|
||||
iChar = 0;
|
||||
for (iChar = 0; 0 != lpCmdLine[iChar + 4]; iChar++)
|
||||
{
|
||||
if (0 == _wcsnicmp(lpCmdLine + iChar, L".exe", 4))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (0 == lpCmdLine[iChar + 4])
|
||||
{
|
||||
rc = ERROR_JAVA_EXE_ARG_MISSING;
|
||||
goto ErrorOut;
|
||||
}
|
||||
|
||||
// Add the java.exe argument
|
||||
if (ERROR_NO_ERROR != (rc = addArg(0, lpCmdLine, iChar + 4)))
|
||||
{
|
||||
goto ErrorOut;
|
||||
}
|
||||
|
||||
// Move past the java.exe argument
|
||||
iChar += 4;
|
||||
|
||||
// Move past any spaces
|
||||
for (;L' ' == lpCmdLine[iChar]; iChar++)
|
||||
{
|
||||
// Intentionally left blank
|
||||
}
|
||||
|
||||
// Find the classpath argument
|
||||
for (; 0 != lpCmdLine[iChar + 3]; iChar++)
|
||||
{
|
||||
if (0 == _wcsnicmp(lpCmdLine + iChar, L"-cp", 3))
|
||||
{
|
||||
fClasspathOptionFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!fClasspathOptionFound)
|
||||
{
|
||||
rc = ERROR_JAVA_CLASSPATH_OPTION_ARG_MISSING;
|
||||
goto ErrorOut;
|
||||
}
|
||||
if (0 == lpCmdLine[iChar + 3])
|
||||
{
|
||||
rc = ERROR_JAVA_CLASSPATH_ARG_MISSING;
|
||||
goto ErrorOut;
|
||||
}
|
||||
|
||||
// Add the classpath option argument
|
||||
if (ERROR_NO_ERROR != (rc = addArg(1, L"-cp", iChar + 3)))
|
||||
{
|
||||
goto ErrorOut;
|
||||
}
|
||||
|
||||
// Move past the classpath option argument
|
||||
iChar += 3;
|
||||
|
||||
// Move past any spaces
|
||||
for (;L' ' == lpCmdLine[iChar]; iChar++)
|
||||
{
|
||||
// Intentionally left blank
|
||||
}
|
||||
|
||||
// The classpath is next. It can have spaces in it so we need to work
|
||||
// backards from the first key/value pair, or the end of the line if
|
||||
// there are no key/value pairs.
|
||||
iClassPathStart = iChar;
|
||||
|
||||
// Find the location of the next '='
|
||||
for (; 0 != lpCmdLine[iChar] && L'=' != lpCmdLine[iChar]; iChar++)
|
||||
{
|
||||
// Intentially left blank
|
||||
}
|
||||
|
||||
// If there was a key/value pair - move to the start of the key
|
||||
if (L'=' == lpCmdLine[iChar])
|
||||
{
|
||||
iAssignment = iChar;
|
||||
|
||||
// Move back to the previous space. This should put us at the
|
||||
// beginning of the first key/value pair. Assume that all args
|
||||
// are property key/value pairs and property keys have no spaces.
|
||||
for (; L' ' != lpCmdLine[iChar] && iChar >= 0; iChar--)
|
||||
{
|
||||
// Intentially left blank
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
iAssignment = 0;
|
||||
iChar--;
|
||||
}
|
||||
|
||||
// Move past any spaces (moving toward the start of the line)
|
||||
for (;L' ' == lpCmdLine[iChar]; iChar--)
|
||||
{
|
||||
// Intentionally left blank
|
||||
}
|
||||
|
||||
// This should put us at the end of the class to be executed
|
||||
iClassEnd = iChar;
|
||||
|
||||
// Move to the previous space (moving toward the start of the line)
|
||||
for (;L' ' != lpCmdLine[iChar]; iChar--)
|
||||
{
|
||||
// Intentionally left blank
|
||||
}
|
||||
|
||||
iClassStart = iChar + 1;
|
||||
|
||||
// Add the class argument
|
||||
if (ERROR_NO_ERROR != (rc = addArg(3, lpCmdLine + iClassStart, iClassEnd - iClassStart + 1)))
|
||||
{
|
||||
goto ErrorOut;
|
||||
}
|
||||
|
||||
// Move past any spaces (moving toward the start of the line)
|
||||
for (;L' ' == lpCmdLine[iChar]; iChar--)
|
||||
{
|
||||
// Intentionally left blank
|
||||
}
|
||||
|
||||
// This should put us at the end of the classpath
|
||||
iClassPathEnd = iChar;
|
||||
|
||||
// Add the class path argument
|
||||
if (ERROR_NO_ERROR != (rc = addArg(2, lpCmdLine + iClassPathStart, iClassPathEnd - iClassPathStart + 1)))
|
||||
{
|
||||
goto ErrorOut;
|
||||
}
|
||||
|
||||
// Are the any key/value pairs?
|
||||
if (0 != iAssignment)
|
||||
{
|
||||
iArg = 4;
|
||||
while (0 != lpCmdLine[iAssignment])
|
||||
{
|
||||
iKeyStart = iAssignment;
|
||||
|
||||
// Move back to the previous space. This should put us at the
|
||||
// beginning of the current next key/value pair. Assume that all args
|
||||
// are property key/value pairs and property keys have no spaces.
|
||||
for (; L' ' != lpCmdLine[iKeyStart] && iKeyStart > 0; iKeyStart--)
|
||||
{
|
||||
// Intentially left blank
|
||||
}
|
||||
if (L' ' == lpCmdLine[iKeyStart])
|
||||
{
|
||||
iKeyStart++;
|
||||
}
|
||||
|
||||
// Find the location of the next '='
|
||||
iValueEnd = iAssignment + 1;
|
||||
for (; 0 != lpCmdLine[iValueEnd] && L'=' != lpCmdLine[iValueEnd]; iValueEnd++)
|
||||
{
|
||||
// Intentially left blank
|
||||
}
|
||||
|
||||
// If there was a property...
|
||||
if (L'=' == lpCmdLine[iValueEnd])
|
||||
{
|
||||
iAssignment = iValueEnd;
|
||||
|
||||
// Move back to the previous space. This should put us at the
|
||||
// beginning of the next key/value pair. Assume that all args
|
||||
// are property key/value pairs and property keys have no spaces.
|
||||
for (; L' ' != lpCmdLine[iValueEnd] && iValueEnd >= 0; iValueEnd--)
|
||||
{
|
||||
// Intentially left blank
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
// We have reached the end of the command line - back off from the
|
||||
// null terminator.
|
||||
iAssignment = iValueEnd;
|
||||
iValueEnd--;
|
||||
}
|
||||
|
||||
// Move thorugh any spaces
|
||||
for (; L' ' == lpCmdLine[iValueEnd] && iValueEnd >= 0; iValueEnd--)
|
||||
{
|
||||
// Intentially left blank
|
||||
}
|
||||
|
||||
// Add the key/value pair
|
||||
if (ERROR_NO_ERROR != (rc = addArg(iArg, lpCmdLine + iKeyStart, iValueEnd - iKeyStart + 1)))
|
||||
{
|
||||
goto ErrorOut;
|
||||
}
|
||||
|
||||
// Go on to the next arg
|
||||
iArg++;
|
||||
}
|
||||
}
|
||||
|
||||
return ERROR_NO_ERROR;
|
||||
|
||||
ErrorOut:
|
||||
|
||||
freeArgs();
|
||||
log(errorMessage(rc));
|
||||
return rc;
|
||||
}
|
||||
|
||||
void freeArgs()
|
||||
{
|
||||
int iArg;
|
||||
if (NULL != G_rgArgs)
|
||||
{
|
||||
for (iArg = 0; iArg < G_cArg; iArg++)
|
||||
{
|
||||
if (NULL != G_rgArgs[iArg])
|
||||
{
|
||||
free(G_rgArgs[iArg]);
|
||||
G_rgArgs[iArg] = NULL;
|
||||
}
|
||||
}
|
||||
free(G_rgArgs);
|
||||
G_rgArgs = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int countArgs(LPTSTR lpCmdLine)
|
||||
{
|
||||
int cArgument;
|
||||
|
||||
// Check if the exe to execute is the only argument. Assume that all additional
|
||||
// arguments have an '=' in them.
|
||||
for (cArgument = 4; *lpCmdLine != (WCHAR)0; lpCmdLine++)
|
||||
{
|
||||
if (*lpCmdLine == L'=')
|
||||
{
|
||||
cArgument++;
|
||||
}
|
||||
}
|
||||
return cArgument;
|
||||
}
|
||||
|
||||
int addArg(int iArg, LPTSTR lpString, int cChar)
|
||||
{
|
||||
int cb = (cChar + 3) * sizeof(WCHAR); // count of bytes
|
||||
|
||||
// Allocate space for the new arg
|
||||
G_rgArgs[iArg] = (WCHAR *)malloc(cb);
|
||||
if (NULL == G_rgArgs[iArg])
|
||||
{
|
||||
return ERROR_MEMORY_ALLOCATION_FAILED;
|
||||
}
|
||||
|
||||
// Null out the argument
|
||||
memset(G_rgArgs[iArg], 0, cb);
|
||||
|
||||
// Add a starting quote
|
||||
// G_rgArgs[iArg][0] = L'\"';
|
||||
|
||||
// Copy the arg
|
||||
if (0 != wcsncpy_s(G_rgArgs[iArg], cChar + 1, lpString, cChar))
|
||||
{
|
||||
return ERROR_STRCPY_FAILED;
|
||||
}
|
||||
|
||||
// Add a terminating quote
|
||||
// G_rgArgs[iArg][cb-1] = L'\"';
|
||||
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
void log(LPTSTR szMessage)
|
||||
{
|
||||
/*
|
||||
LPTSTR szT = L"";
|
||||
if (NULL == szMessage)
|
||||
szMessage = szT;
|
||||
fwprintf(G_pf, L"JavaLauncher: %s\n", szMessage);
|
||||
*/
|
||||
}
|
||||
|
||||
_TCHAR * errorMessage(int err)
|
||||
{
|
||||
switch (err)
|
||||
{
|
||||
case ERROR_NO_ERROR:
|
||||
return L"No error\n";
|
||||
case ERROR_MEMORY_ALLOCATION_FAILED:
|
||||
return L"Memory allocation failed\n";
|
||||
case ERROR_INVALID_NUMBER_OF_PARAMETERS:
|
||||
return L"Invalid number of parameters\n";
|
||||
case ERROR_EXEC_E2BIG:
|
||||
return L"_exec: The space required for the arguments and environment settings exceeds 32 KB.\n";
|
||||
case ERROR_EXEC_EACCES:
|
||||
return L"_exec: The specified file has a locking or sharing violation.\n";
|
||||
case ERROR_EXEC_EINVAL:
|
||||
return L"_exec: Invalid parameter.\n";
|
||||
case ERROR_EXEC_EMFILE:
|
||||
return L"_exec: Too many files open (the specified file must be opened to determine whether it is executable).\n";
|
||||
case ERROR_EXEC_ENOENT:
|
||||
return L"_exec: The file or path not found.\n";
|
||||
case ERROR_EXEC_ENOEXEC:
|
||||
return L"_exec: The specified file is not executable or has an invalid executable-file format.\n";
|
||||
case ERROR_EXEC_ENOMEM:
|
||||
return L"_exec: Not enough memory is available to execute the new process; the available memory has been corrupted; or an invalid block exists, indicating that the calling process was not allocated properly.\n";
|
||||
case ERROR_EXEC_UNKNOWN:
|
||||
return L"Unknown _exec error.\n";
|
||||
case ERROR_STRCPY_FAILED:
|
||||
return L"String copy failed.\n";
|
||||
case ERROR_JAVA_CLASSPATH_OPTION_ARG_MISSING:
|
||||
return L"Classpath option \"-cp\" missing\n";
|
||||
case ERROR_JAVA_CLASSPATH_ARG_MISSING:
|
||||
return L"Classpath argument missing\n";
|
||||
case ERROR_BAD_COMMAND_LINE:
|
||||
return L"Bad command line\n";
|
||||
default:
|
||||
return L"Unknown error.\n";
|
||||
}
|
||||
}
|
||||
|
||||
int executeCommand( int cArg, _TCHAR* rgArg[] )
|
||||
{
|
||||
int i; // Looping variable
|
||||
int rc = ERROR_NO_ERROR; // Return code
|
||||
|
||||
//fwprintf( G_pf, L"Arg count = %d\n", cArg);
|
||||
//for (i = 0; i < cArg; i++)
|
||||
//{
|
||||
// fwprintf(G_pf, L"rgArg[%d] (%s)\n", i, rgArg[i]);
|
||||
//}
|
||||
|
||||
// exec the command
|
||||
// if (-1 == _wexecv( rgArg[0], rgArg))
|
||||
if (-1 == _wspawnv(_P_WAIT, rgArg[0], rgArg))
|
||||
{
|
||||
switch (errno)
|
||||
{
|
||||
case E2BIG: // The space required for the arguments and environment settings exceeds 32 KB.
|
||||
rc = ERROR_EXEC_E2BIG;
|
||||
break;
|
||||
|
||||
case EACCES: // The specified file has a locking or sharing violation.
|
||||
rc = ERROR_EXEC_EACCES;
|
||||
break;
|
||||
|
||||
case EINVAL: // Invalid parameter.
|
||||
rc = ERROR_EXEC_EINVAL;
|
||||
break;
|
||||
|
||||
case EMFILE: // Too many files open (the specified file must be opened to determine whether it is executable).
|
||||
rc = ERROR_EXEC_EMFILE;
|
||||
break;
|
||||
|
||||
case ENOENT: // The file or path not found.
|
||||
rc = ERROR_EXEC_ENOENT;
|
||||
break;
|
||||
|
||||
case ENOEXEC: // The specified file is not executable or has an invalid executable-file format.
|
||||
rc = ERROR_EXEC_ENOEXEC;
|
||||
break;
|
||||
|
||||
case ENOMEM: // Not enough memory is available to execute the new process; the available memory has been
|
||||
// corrupted; or an invalid block exists, indicating that the calling process was not allocated
|
||||
// properly.
|
||||
rc = ERROR_EXEC_ENOMEM;
|
||||
break;
|
||||
|
||||
default:
|
||||
rc = ERROR_EXEC_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//fwprintf(G_pf, L"ExecuteCommand returning %d\n", rc);
|
||||
return rc;
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "resource.h"
|
@ -1,229 +0,0 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="CommandLauncher"
|
||||
ProjectGUID="{B52EF84A-D745-4637-9F59-DBD6E21C179C}"
|
||||
RootNamespace="CommandLauncher"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="bin"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="2"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="bin"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="2"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="2"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\CommandLauncher.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\CommandLauncher.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resource.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
@ -1,69 +0,0 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Copyright (C) 2004 Novell, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# Author: Greg Richardson <grichardson@novell.com>
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
DIST_SUBDIRS =
|
||||
|
||||
EXTRA_DIST = CommandLauncher.vcproj CommandLauncher.cpp CommandLauncher.h Resource.h stdafx.h stdafx.cpp
|
||||
|
||||
if DEBUG
|
||||
TARGET_CFG = Debug
|
||||
else
|
||||
TARGET_CFG = Release
|
||||
endif
|
||||
|
||||
PACKAGE = CommandLauncher
|
||||
TARGET_FILE = $(PACKAGE).exe
|
||||
LOG_FILE = $(PACKAGE).log
|
||||
|
||||
.PHONY: package package-clean package-install package-uninstall devenv
|
||||
|
||||
package: $(TARGET_FILE)
|
||||
|
||||
devenv:
|
||||
@if ! test -x "$(VSINSTALLDIR)/Common7/IDE/devenv.exe"; then echo "Error: Microsoft Visual Studio .NET is currently required to build MSI and MSM packages"; exit 1; fi
|
||||
|
||||
$(TARGET_FILE): devenv
|
||||
@rm -f $(LOG_FILE) $@
|
||||
@CMD='"$(VSINSTALLDIR)/Common7/IDE/devenv.exe" ../server-java_msi/server-java_msi.sln /build $(TARGET_CFG) /project $(PACKAGE) /out $(LOG_FILE)'; \
|
||||
echo $$CMD; \
|
||||
if eval $$CMD; then \
|
||||
ls -l bin/$(TARGET_FILE); \
|
||||
else \
|
||||
grep -a "ERROR:" $(LOG_FILE); \
|
||||
fi
|
||||
|
||||
package-clean clean-local:
|
||||
rm -rf Release/* Release Debug/* Debug*/Release */Debug *.log *.suo
|
||||
|
||||
clean:
|
||||
rm -rf Release/* Release Debug/* Debug */Release */Debug *.log *.suo bin/* bin
|
||||
|
||||
distclean-local: package-clean
|
||||
rm -f Makefile
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -f Makefile.in
|
||||
|
||||
|
||||
|
Binary file not shown.
@ -1,8 +0,0 @@
|
||||
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
|
||||
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
|
||||
<dependency>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity type='win32' name='Microsoft.VC80.CRT' version='8.0.50608.0' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
</assembly>
|
Binary file not shown.
@ -1 +0,0 @@
|
||||
Manifest resource last updated at 13:12:58.17 on Wed 01/31/2007
|
Binary file not shown.
@ -1,31 +0,0 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by CommandLauncher.rc
|
||||
//
|
||||
|
||||
#define IDS_APP_TITLE 103
|
||||
|
||||
#define IDR_MAINFRAME 128
|
||||
#define IDD_COMMANDLAUNCHER_DIALOG 102
|
||||
#define IDD_ABOUTBOX 103
|
||||
#define IDM_ABOUT 104
|
||||
#define IDM_EXIT 105
|
||||
#define IDI_COMMANDLAUNCHER 107
|
||||
#define IDI_SMALL 108
|
||||
#define IDC_COMMANDLAUNCHER 109
|
||||
#define IDC_MYICON 2
|
||||
#ifndef IDC_STATIC
|
||||
#define IDC_STATIC -1
|
||||
#endif
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
#define _APS_NO_MFC 130
|
||||
#define _APS_NEXT_RESOURCE_VALUE 129
|
||||
#define _APS_NEXT_COMMAND_VALUE 32771
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 110
|
||||
#endif
|
||||
#endif
|
Binary file not shown.
@ -1,8 +0,0 @@
|
||||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// CommandLauncher.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: reference any additional headers you need in STDAFX.H
|
||||
// and not in this file
|
@ -1,37 +0,0 @@
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
// Modify the following defines if you have to target a platform prior to the ones specified below.
|
||||
// Refer to MSDN for the latest info on corresponding values for different platforms.
|
||||
#ifndef WINVER // Allow use of features specific to Windows XP or later.
|
||||
#define WINVER 0x0501 // Change this to the appropriate value to target other versions of Windows.
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
|
||||
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
|
||||
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32_IE // Allow use of features specific to IE 6.0 or later.
|
||||
#define _WIN32_IE 0x0600 // Change this to the appropriate value to target other versions of IE.
|
||||
#endif
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
// Windows Header Files:
|
||||
#include <windows.h>
|
||||
|
||||
// C RunTime Header Files
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <memory.h>
|
||||
#include <tchar.h>
|
||||
|
||||
|
||||
// TODO: reference additional headers your program requires here
|
@ -1,385 +0,0 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright (C) 2006 Novell, Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, Novell, Inc.
|
||||
*
|
||||
* To contact Novell about this file by physical or electronic mail,
|
||||
* you may find current contact information at www.novell.com.
|
||||
*
|
||||
* Author: Greg Richardson <grichardson@novell.com>
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Summary description for DeleteFile
|
||||
*/
|
||||
public class DeleteFile
|
||||
{
|
||||
final static int ERROR_NO_ERROR = 0;
|
||||
final static int ERROR_INVALID_NUMBER_OF_PARAMS = -1;
|
||||
final static int ERROR_BAD_FILE_PARAM = -2;
|
||||
final static int ERROR_IO_EXCEPTION = -3;
|
||||
final static int ERROR_FILE_PARAM_REPEATED = -4;
|
||||
final static int ERROR_FILTER_PARAM_REPEATED = -5;
|
||||
final static int ERROR_UNKNOWN_PARAMETER = -6;
|
||||
final static int ERROR_MISSING_FILE_PARAM = -7;
|
||||
final static int ERROR_FILTER_ON_NON_DIRECTORY = -8;
|
||||
final static int ERROR_BAD_PROPERTY_FILE_PARAM = -9;;
|
||||
final static int ERROR_EXCEPTION = -10;
|
||||
|
||||
final static String FILE_KEY = "file=";
|
||||
final static String FILTER_KEY = "filter=";
|
||||
|
||||
//RandomAccessFile raf;
|
||||
int rc;
|
||||
String sFile;
|
||||
String sFilter;
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
DeleteFile p = new DeleteFile(args);
|
||||
System.exit(p.rc);
|
||||
}
|
||||
|
||||
DeleteFile(String[] args)
|
||||
{
|
||||
rc = ERROR_NO_ERROR;
|
||||
sFile = null;
|
||||
sFilter = null;
|
||||
|
||||
try
|
||||
{
|
||||
//raf = new RandomAccessFile(new File("c:\\test8.log"), "rw");
|
||||
//raf.seek(raf.length());
|
||||
|
||||
// Process the arguments
|
||||
if (ERROR_NO_ERROR == (rc = processArgs(args)))
|
||||
{
|
||||
rc = doDelete();
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
rc = ERROR_EXCEPTION;
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
log(rc);
|
||||
//raf.close();
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int processArgs(String[] argsOld)
|
||||
{
|
||||
String sProperties;
|
||||
File fileInstallDir = null;
|
||||
int iEquals;
|
||||
String sKey;
|
||||
String sValue;
|
||||
int iOld;
|
||||
int i;
|
||||
String args[] = new String[argsOld.length];
|
||||
int iNew;
|
||||
|
||||
log("Original arg count " + argsOld.length);
|
||||
for (i = 0; i < argsOld.length; i++)
|
||||
{
|
||||
log("Arg " + i + " = " + argsOld[i] + "\r\n");
|
||||
}
|
||||
|
||||
// Validate the number of parameters
|
||||
if (args.length < 1)
|
||||
{
|
||||
return ERROR_INVALID_NUMBER_OF_PARAMS;
|
||||
}
|
||||
|
||||
iNew = -1;
|
||||
for (iOld = 0; iOld < argsOld.length; iOld++)
|
||||
{
|
||||
if (0 <= argsOld[iOld].indexOf("="))
|
||||
{
|
||||
iNew++;
|
||||
args[iNew] = argsOld[iOld];
|
||||
for (i = iOld + 1; i < argsOld.length && (-1 == argsOld[i].indexOf("=")); i++)
|
||||
{
|
||||
args[iNew] += " " + argsOld[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log("New arg count " + args.length);
|
||||
for (i = 0; i < args.length; i++)
|
||||
{
|
||||
if (null == args[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
log("arg[" + i + "] = " +args[i]);
|
||||
|
||||
// is this the file to delete param?
|
||||
if (args[i].startsWith(FILE_KEY))
|
||||
{
|
||||
// Have we already processed a file paramter?
|
||||
if (null != sFile)
|
||||
{
|
||||
return ERROR_FILE_PARAM_REPEATED;
|
||||
}
|
||||
|
||||
// Make sure it is more the param tag
|
||||
if (args[i].length() <= FILE_KEY.length())
|
||||
{
|
||||
return ERROR_BAD_FILE_PARAM;
|
||||
}
|
||||
|
||||
sFile = args[i].substring(FILE_KEY.length()).trim();
|
||||
}
|
||||
|
||||
// is this the filter param?
|
||||
else if (args[i].startsWith(FILTER_KEY))
|
||||
{
|
||||
// Have we already processed a filter paramter?
|
||||
if (null != sFilter)
|
||||
{
|
||||
return ERROR_FILTER_PARAM_REPEATED;
|
||||
}
|
||||
|
||||
// Make sure it is more than the param tag
|
||||
if (args[i].length() <= FILTER_KEY.length())
|
||||
{
|
||||
return ERROR_BAD_PROPERTY_FILE_PARAM;
|
||||
}
|
||||
|
||||
sFilter = args[i].substring(FILTER_KEY.length()).trim();
|
||||
}
|
||||
|
||||
// Handle additional parameters
|
||||
else
|
||||
{
|
||||
return ERROR_UNKNOWN_PARAMETER;
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we got a file
|
||||
if (null == sFile)
|
||||
{
|
||||
return ERROR_MISSING_FILE_PARAM;
|
||||
}
|
||||
|
||||
// Note: the filter parameter is optional, if present the file is assumed to be a directory
|
||||
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
int doDelete()
|
||||
{
|
||||
File file = new File(sFile);
|
||||
|
||||
log("Attempt to delete: " + sFile);
|
||||
|
||||
// If the file is already gone - we are happy.
|
||||
if (!file.exists())
|
||||
{
|
||||
log("File did not exist: " + sFile);
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
// If a filter was passed in but the file is not a directory...
|
||||
if (null != sFilter)
|
||||
{
|
||||
log("there is a filter: + sFilter");
|
||||
|
||||
// The file is not a directory - we wont try to apply the filter
|
||||
if (!file.isDirectory())
|
||||
{
|
||||
log("file is not a directory");
|
||||
return ERROR_FILTER_ON_NON_DIRECTORY;
|
||||
}
|
||||
|
||||
// The file is a directory
|
||||
else
|
||||
{
|
||||
log("file is a directory");
|
||||
// Delete the children that match the template
|
||||
deleteFiles(file);
|
||||
|
||||
// Attempt to delete the directory
|
||||
deleteDirectory(file);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (!file.isDirectory())
|
||||
{
|
||||
log("Delete file: " + sFile);
|
||||
file.delete();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
deleteDirectory(file);
|
||||
}
|
||||
}
|
||||
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
void deleteFiles(File file)
|
||||
{
|
||||
File fileDelete;
|
||||
int i;
|
||||
|
||||
log("attempting to delete file");
|
||||
|
||||
// Get the children of this directory
|
||||
File[] rgFile = file.listFiles(
|
||||
new FileFilter()
|
||||
{
|
||||
public boolean accept(File f)
|
||||
{
|
||||
if (null == sFilter) return true;
|
||||
log("file " + f.getName() + " matches filter " + sFilter + " : " + (-1 != f.getName().indexOf(sFilter))) ;
|
||||
return (-1 != f.getName().indexOf(sFilter));
|
||||
}
|
||||
});
|
||||
|
||||
log(file.getAbsolutePath() + " has " + rgFile.length + " children that match the filter: " + sFilter);
|
||||
|
||||
// Attempt to delete each child file
|
||||
for (i = 0; i < rgFile.length; i++)
|
||||
{
|
||||
if (rgFile[i].isDirectory())
|
||||
{
|
||||
deleteDirectory(rgFile[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
log("Delete file: " + rgFile[i].getAbsolutePath());
|
||||
rgFile[i].delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void deleteDirectory(File file)
|
||||
{
|
||||
File fileDelete;
|
||||
int i;
|
||||
|
||||
log("Delete directory: " + file.getAbsolutePath());
|
||||
|
||||
// Get the children of this directory
|
||||
File[] rgFile = file.listFiles();
|
||||
|
||||
log(file.getAbsolutePath() + " has " + rgFile.length + " children");
|
||||
|
||||
// Delete empty child directories
|
||||
for (i = 0; i < rgFile.length; i++)
|
||||
{
|
||||
if (rgFile[i].isDirectory())
|
||||
{
|
||||
deleteDirectory(rgFile[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete this directory if it is empty
|
||||
rgFile = file.listFiles();
|
||||
if (rgFile.length == 0)
|
||||
{
|
||||
log("Delete file: " + file.getAbsolutePath());
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void log(int err)
|
||||
{
|
||||
log(err, null);
|
||||
}
|
||||
|
||||
void log(int err, String s)
|
||||
{
|
||||
String sMessage = "";
|
||||
|
||||
switch (err)
|
||||
{
|
||||
case ERROR_NO_ERROR:
|
||||
sMessage = "No error";
|
||||
break;
|
||||
case ERROR_INVALID_NUMBER_OF_PARAMS:
|
||||
sMessage = "Invalid number of parameters: 1 expected";
|
||||
break;
|
||||
case ERROR_BAD_FILE_PARAM:
|
||||
sMessage = "Bad file parameter";
|
||||
break;
|
||||
case ERROR_FILE_PARAM_REPEATED:
|
||||
sMessage = "File parameter repeated";
|
||||
break;
|
||||
case ERROR_FILTER_PARAM_REPEATED:
|
||||
sMessage = "Filter parameter repeated";
|
||||
break;
|
||||
case ERROR_UNKNOWN_PARAMETER:
|
||||
sMessage = "Unknown parameter: ";
|
||||
break;
|
||||
case ERROR_MISSING_FILE_PARAM:
|
||||
sMessage = "Missing file parameter";
|
||||
break;
|
||||
case ERROR_FILTER_ON_NON_DIRECTORY:
|
||||
sMessage = "Filter parameter of non-directory file";
|
||||
break;
|
||||
case ERROR_BAD_PROPERTY_FILE_PARAM:
|
||||
sMessage = "Bad property file parameter";
|
||||
break;
|
||||
case ERROR_IO_EXCEPTION:
|
||||
sMessage = "IOException ";
|
||||
break;
|
||||
case ERROR_EXCEPTION:
|
||||
sMessage = "Exception ";
|
||||
break;
|
||||
default:
|
||||
sMessage = "Unknown error: " + err;
|
||||
break;
|
||||
}
|
||||
|
||||
if (null != s)
|
||||
{
|
||||
sMessage = sMessage + s;
|
||||
}
|
||||
log(sMessage);
|
||||
}
|
||||
|
||||
void log(String s)
|
||||
{
|
||||
/*
|
||||
try
|
||||
{
|
||||
raf.writeUTF(this.getClass().getName() + ": " + s + "\r\n");
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Copyright (C) 2004 Novell, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# Author: Greg Richardson <grichardson@novell.com>
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
DIST_SUBDIRS =
|
||||
|
||||
EXTRA_DIST = DeleteFile.java
|
||||
|
||||
if DEBUG
|
||||
TARGET_CFG = Debug
|
||||
DEBUG = -g
|
||||
else
|
||||
TARGET_CFG = Release
|
||||
DEBUG = -g:none
|
||||
endif
|
||||
|
||||
PACKAGE = DeleteFile
|
||||
TARGET_FILE = $(PACKAGE).class
|
||||
LOG_FILE = $(PACKAGE).log
|
||||
JAVAFILES = DeleteFile.java
|
||||
CLASSES = $(addprefix $(BUILDDIR)/, $(JAVAFILES:%.java=%.class))
|
||||
BUILDDIR = bin/$(TARGET_CFG)
|
||||
|
||||
.PHONY: package package-clean package-install package-uninstall
|
||||
|
||||
all: $(BUILDDIR) $(CLASSES)
|
||||
|
||||
$(BUILDDIR)/%.class: %.java
|
||||
@rm -f $(LOG_FILE) $@
|
||||
@echo [======== Compiling $@ ========]
|
||||
@javac $(DEBUG) -d $(BUILDDIR) $< 2> $(LOG_FILE)
|
||||
@echo $$CMD; \
|
||||
if eval $$CMD; then \
|
||||
ls -l $(BUILDDIR)/$(TARGET_FILE); \
|
||||
cp $(BUILDDIR)/*.class bin; \
|
||||
else \
|
||||
grep -a "ERROR:" $(LOG_FILE); \
|
||||
fi
|
||||
|
||||
$(BUILDDIR):
|
||||
[ -d $(BUILDDIR) ] || mkdir -p $(BUILDDIR)
|
||||
|
||||
|
||||
package-clean clean-local:
|
||||
rm -rf bin/Release/* bin/Release bin/Debug/* bin/Debug bin/* bin *.log
|
||||
|
||||
clean:
|
||||
rm -rf bin/Release/* bin/Release bin/Debug/* bin/Debug bin/* bin *.log
|
||||
|
||||
distclean-local: package-clean
|
||||
rm -f Makefile
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -f Makefile.in
|
||||
|
||||
|
||||
|
@ -1,547 +0,0 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright (C) 2006 Novell, Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, Novell, Inc.
|
||||
*
|
||||
* To contact Novell about this file by physical or electronic mail,
|
||||
* you may find current contact information at www.novell.com.
|
||||
*
|
||||
* Author: Greg Richardson <grichardson@novell.com>
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Summary description for Program
|
||||
*/
|
||||
public class InitConfigFile
|
||||
{
|
||||
final static int ERROR_NO_ERROR = 0;
|
||||
final static int ERROR_INVALID_NUMBER_OF_PARAMS = -1;
|
||||
final static int ERROR_MISSING_TEMPLATE = -3;
|
||||
final static int ERROR_MISSING_TEMPLATE_FILE = -8;
|
||||
final static int ERROR_OUTPUT_PROPERTY_MISSING = -9;
|
||||
final static int ERROR_OUTPUT_COPY_FAILED = -12;
|
||||
final static int ERROR_IO_EXCEPTION = -13;
|
||||
final static int ERROR_MISSING_PROPERTIES = -15;
|
||||
final static int ERROR_UNABLE_TO_READ_PROPERTIES = -16;
|
||||
final static int ERROR_PROPERTIES_FILE_IS_EMPTY = -17;
|
||||
final static int ERROR_MISSING_INSTALL_DIR = -18;
|
||||
final static int ERROR_INSTALL_DIR_NOT_A_DIR = -19;
|
||||
final static int ERROR_BAD_INSTALL_DIR_PARAM = -20;
|
||||
final static int ERROR_BAD_PROPERTY_FILE_PARAM = -21;
|
||||
final static int ERROR_MISSING_PROPERTIES_FILE = -22;
|
||||
final static int ERROR_MISSING_INSTALL_DIR_PARAM = -23;
|
||||
final static int ERROR_MISSING_PROPERTY_FILE_PARAM = -24;
|
||||
final static int ERROR_BAD_TEMPLATE_FILE_PARAM = -25;
|
||||
final static int ERROR_BAD_OUTPUT_FILE_PARAM = -26;
|
||||
final static int ERROR_MISSING_TEMPLATE_FILE_PARAM = -27;
|
||||
final static int ERROR_MISSING_OUTPUT_FILE_PARAM = -28;
|
||||
final static int ERROR_BAD_PROPERTY_PARAM = -29;
|
||||
final static int ERROR_UNABLE_TO_OPEN_TEMPLATE = -30;
|
||||
final static int ERROR_FILEWRITER_CREATE_FAILED = -31;
|
||||
final static int ERROR_BAD_ESCAPE_PATH_CHARS_PARAM = -32;
|
||||
final static int ERROR_EXCEPTION = -33;
|
||||
|
||||
final static String TEMPLATE_FILE_PARAM = "template=";
|
||||
final static String OUTPUT_FILE_PARAM = "output=";
|
||||
final static String INSTALL_DIR_PARAM = "ATS_INSTALL_DIR=";
|
||||
final static String INSTALL_DIR_PROPERTY = "ATS_INSTALL_DIR";
|
||||
final static String PROPERTY_FILE_PARAM = "propertyfile=";
|
||||
final static String ESCAPE_PATH_CHARS = "escape_path_chars=";
|
||||
|
||||
Properties properties;
|
||||
File fileProperties;
|
||||
FileInputStream fisProperties;
|
||||
File fileTemplate;
|
||||
File fileOutput;
|
||||
//File file;
|
||||
//FileWriter fw;
|
||||
//RandomAccessFile raf;
|
||||
String[] rgsSearchFor;
|
||||
String[] rgsReplaceWith;
|
||||
String sInstallDir;
|
||||
String sTemplate;
|
||||
String sOutput;
|
||||
int rc;
|
||||
boolean escapePathCharsInReplaceString = false;
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
InitConfigFile p = new InitConfigFile(args);
|
||||
System.exit(p.rc);
|
||||
}
|
||||
|
||||
InitConfigFile(String[] args)
|
||||
{
|
||||
rc = ERROR_NO_ERROR;
|
||||
|
||||
properties = new Properties();
|
||||
fileProperties = null;
|
||||
fisProperties = null;
|
||||
fileTemplate = null;
|
||||
fileOutput = null;
|
||||
|
||||
try
|
||||
{
|
||||
//file = new File("c:\\test.log");
|
||||
//fw = new FileWriter(file);
|
||||
|
||||
//raf = new RandomAccessFile(file, "rw");
|
||||
//raf.seek(raf.length());
|
||||
|
||||
// Process the arguments
|
||||
if (ERROR_NO_ERROR == (rc = processArgs(args)))
|
||||
{
|
||||
// Process the properties
|
||||
if (ERROR_NO_ERROR == (rc = processProperties()))
|
||||
{
|
||||
rc = createOutputFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
rc = ERROR_EXCEPTION;
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
log(rc, " " + sOutput + "\n\n\n");
|
||||
//raf.close();
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int processArgs(String[] argsOld)
|
||||
{
|
||||
String sProperties;
|
||||
File fileInstallDir = null;
|
||||
int iEquals;
|
||||
String sKey;
|
||||
String sValue;
|
||||
int iOld;
|
||||
int i;
|
||||
String args[] = new String[argsOld.length];
|
||||
int iNew;
|
||||
|
||||
log("Original arg count " + argsOld.length);
|
||||
for (i = 0; i < argsOld.length; i++)
|
||||
{
|
||||
log("Arg " + i + " = " + argsOld[i] + "\r\n");
|
||||
}
|
||||
|
||||
// Validate the number of parameters
|
||||
if (argsOld.length < 2)
|
||||
{
|
||||
return ERROR_INVALID_NUMBER_OF_PARAMS;
|
||||
}
|
||||
|
||||
iNew = -1;
|
||||
for (iOld = 0; iOld < argsOld.length; iOld++)
|
||||
{
|
||||
if (0 <= argsOld[iOld].indexOf("="))
|
||||
{
|
||||
iNew++;
|
||||
args[iNew] = argsOld[iOld];
|
||||
for (i = iOld + 1; i < argsOld.length && (-1 == argsOld[i].indexOf("=")); i++)
|
||||
{
|
||||
args[iNew] += " " + argsOld[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log("New arg count " + args.length);
|
||||
for (i = 0; i < args.length; i++)
|
||||
{
|
||||
if (null == args[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
log("arg[" + i + "] = " +args[i]);
|
||||
|
||||
// is this the install dir param?
|
||||
if (args[i].startsWith(INSTALL_DIR_PARAM))
|
||||
{
|
||||
// Make sure it is more the the param tag
|
||||
if (args[i].length() <= INSTALL_DIR_PARAM.length())
|
||||
{
|
||||
return ERROR_BAD_INSTALL_DIR_PARAM;
|
||||
}
|
||||
|
||||
sInstallDir = args[i].substring(INSTALL_DIR_PARAM.length()).trim();
|
||||
fileInstallDir = new File(sInstallDir);
|
||||
|
||||
// Make sure the install dir can be found
|
||||
if (!fileInstallDir.exists())
|
||||
{
|
||||
return ERROR_MISSING_INSTALL_DIR;
|
||||
}
|
||||
|
||||
// Make sure the install dir is a directory
|
||||
if (!fileInstallDir.isDirectory())
|
||||
{
|
||||
return ERROR_INSTALL_DIR_NOT_A_DIR;
|
||||
}
|
||||
|
||||
log("Adding property (key = " + INSTALL_DIR_PROPERTY + " - value = " + sInstallDir);
|
||||
properties.setProperty(INSTALL_DIR_PROPERTY, sInstallDir);
|
||||
}
|
||||
|
||||
// is this the properties file param?
|
||||
else if (args[i].startsWith(PROPERTY_FILE_PARAM))
|
||||
{
|
||||
// Make sure it is more than the param tag
|
||||
if (args[i].length() <= PROPERTY_FILE_PARAM.length())
|
||||
{
|
||||
return ERROR_BAD_PROPERTY_FILE_PARAM;
|
||||
}
|
||||
|
||||
sProperties = args[i].substring(PROPERTY_FILE_PARAM.length()).trim();
|
||||
fileProperties = new File(sProperties);
|
||||
|
||||
// Make sure the properties file can be found
|
||||
if (!fileProperties.exists())
|
||||
{
|
||||
return ERROR_MISSING_PROPERTIES_FILE;
|
||||
}
|
||||
|
||||
// Read the properties
|
||||
try
|
||||
{
|
||||
fisProperties = new FileInputStream(fileProperties);
|
||||
properties.load(fisProperties);
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
return ERROR_UNABLE_TO_READ_PROPERTIES;
|
||||
}
|
||||
}
|
||||
|
||||
else if (args[i].startsWith(TEMPLATE_FILE_PARAM))
|
||||
{
|
||||
// Make sure it is more than the param tag
|
||||
if (args[i].length() <= TEMPLATE_FILE_PARAM.length())
|
||||
{
|
||||
return ERROR_BAD_TEMPLATE_FILE_PARAM;
|
||||
}
|
||||
|
||||
sTemplate = args[i].substring(TEMPLATE_FILE_PARAM.length()).trim();
|
||||
fileTemplate = new File(sTemplate);
|
||||
|
||||
// Make sure the template file can be found
|
||||
if (!fileTemplate.exists())
|
||||
{
|
||||
log(ERROR_MISSING_TEMPLATE_FILE, sTemplate);
|
||||
return ERROR_MISSING_TEMPLATE_FILE;
|
||||
}
|
||||
}
|
||||
|
||||
else if (args[i].startsWith(OUTPUT_FILE_PARAM))
|
||||
{
|
||||
// Make sure it is more than the param tag
|
||||
if (args[i].length() <= OUTPUT_FILE_PARAM.length())
|
||||
{
|
||||
return ERROR_BAD_OUTPUT_FILE_PARAM;
|
||||
}
|
||||
|
||||
sOutput = args[i].substring(OUTPUT_FILE_PARAM.length()).trim();
|
||||
fileOutput = new File(sOutput);
|
||||
}
|
||||
|
||||
else if (args[i].startsWith(ESCAPE_PATH_CHARS))
|
||||
{
|
||||
// Make sure it is more than the param tag
|
||||
if (args[i].length() <= ESCAPE_PATH_CHARS.length())
|
||||
{
|
||||
return ERROR_BAD_ESCAPE_PATH_CHARS_PARAM;
|
||||
}
|
||||
|
||||
String value = args[i].substring(ESCAPE_PATH_CHARS.length()).trim();
|
||||
if (value.equalsIgnoreCase("true"))
|
||||
{
|
||||
escapePathCharsInReplaceString = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle additional parameters
|
||||
else
|
||||
{
|
||||
if (-1 == (iEquals = args[i].indexOf("=")) ||
|
||||
0 == iEquals ||
|
||||
args[i].length() == iEquals)
|
||||
{
|
||||
return ERROR_BAD_PROPERTY_PARAM;
|
||||
}
|
||||
sKey = args[i].substring(0, iEquals);
|
||||
sValue = args[i].substring(iEquals + 1);
|
||||
log("Adding property (key = " + sKey + " - value = " + sValue);
|
||||
properties.setProperty(sKey, sValue);
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we got an install dir
|
||||
if (null == fileInstallDir)
|
||||
{
|
||||
return ERROR_MISSING_INSTALL_DIR_PARAM;
|
||||
}
|
||||
|
||||
// Make sure we got a template file
|
||||
if (null == fileTemplate)
|
||||
{
|
||||
return ERROR_MISSING_TEMPLATE_FILE_PARAM;
|
||||
}
|
||||
|
||||
// Make sure we got an output file
|
||||
if (null == fileOutput)
|
||||
{
|
||||
return ERROR_MISSING_OUTPUT_FILE_PARAM;
|
||||
}
|
||||
|
||||
// Note: the properties file parameter is optional
|
||||
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
int processProperties()
|
||||
{
|
||||
try
|
||||
{
|
||||
Enumeration e;
|
||||
String sKey;
|
||||
String sValue;
|
||||
int i = 0;
|
||||
|
||||
e = properties.propertyNames();
|
||||
|
||||
rgsSearchFor = new String[properties.size()];
|
||||
rgsReplaceWith = new String[properties.size()];
|
||||
|
||||
log("property count = " + properties.size());
|
||||
while (e.hasMoreElements())
|
||||
{
|
||||
sKey = (String)e.nextElement();
|
||||
sValue = (String)properties.get(sKey);
|
||||
|
||||
log("Property key = " + sKey + " Value = " + sValue);
|
||||
|
||||
rgsSearchFor[i] = sKey;
|
||||
if (escapePathCharsInReplaceString)
|
||||
{
|
||||
rgsReplaceWith[i] = sValue.replace("\\", "\\\\");
|
||||
}
|
||||
else
|
||||
{
|
||||
rgsReplaceWith[i] = sValue;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
catch (Exception ex1)
|
||||
{
|
||||
return -111;
|
||||
}
|
||||
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
int createOutputFile()
|
||||
{
|
||||
LineNumberReader lnr = null;
|
||||
FileWriter fwOutput = null;
|
||||
String sLineTemplate;
|
||||
String sLineOutput;
|
||||
int iSearchFor;
|
||||
int i;
|
||||
|
||||
try
|
||||
{
|
||||
// Open the files
|
||||
lnr = new LineNumberReader(new FileReader(fileTemplate));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return ERROR_UNABLE_TO_OPEN_TEMPLATE;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
fwOutput = new FileWriter(fileOutput);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return ERROR_FILEWRITER_CREATE_FAILED;
|
||||
}
|
||||
try
|
||||
{
|
||||
// For each line of text in the template file...
|
||||
while (null != (sLineTemplate = lnr.readLine()))
|
||||
{
|
||||
sLineOutput = sLineTemplate;
|
||||
log("<-- " + sLineOutput);
|
||||
|
||||
// For each term to be replaced...
|
||||
for (i = 0; i < rgsSearchFor.length; i++)
|
||||
{
|
||||
log("searching for " + rgsSearchFor[i]);
|
||||
// Replace all instances of the term on the line
|
||||
while (-1 != (iSearchFor = sLineOutput.indexOf(rgsSearchFor[i])))
|
||||
{
|
||||
log("replacing " + rgsSearchFor[i] + " at position " + iSearchFor + " with " + rgsReplaceWith[i]);
|
||||
sLineOutput = sLineOutput.substring(0, iSearchFor) + rgsReplaceWith[i] +
|
||||
sLineOutput.substring(iSearchFor + rgsSearchFor[i].length());
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
fwOutput.write(sLineOutput + "\r\n");
|
||||
log("--> " + sLineOutput);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return -42;
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up
|
||||
fwOutput.flush();
|
||||
fwOutput.close();
|
||||
lnr.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return ERROR_OUTPUT_COPY_FAILED;
|
||||
}
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
void log(int err)
|
||||
{
|
||||
log(err, null);
|
||||
}
|
||||
|
||||
void log(int err, String s)
|
||||
{
|
||||
String sMessage = "";
|
||||
|
||||
switch (err)
|
||||
{
|
||||
case ERROR_NO_ERROR:
|
||||
sMessage = "No error";
|
||||
break;
|
||||
case ERROR_INVALID_NUMBER_OF_PARAMS:
|
||||
sMessage = "Invalid number of parameters: 4 expected";
|
||||
break;
|
||||
case ERROR_MISSING_TEMPLATE:
|
||||
sMessage = "Template file not found";
|
||||
break;
|
||||
case ERROR_OUTPUT_PROPERTY_MISSING:
|
||||
sMessage = "Output file parameter missing";
|
||||
break;
|
||||
case ERROR_OUTPUT_COPY_FAILED:
|
||||
sMessage = "Unable to create output file";
|
||||
break;
|
||||
case ERROR_IO_EXCEPTION:
|
||||
sMessage = "IOException";
|
||||
break;
|
||||
case ERROR_MISSING_PROPERTIES:
|
||||
sMessage = "Properties file not found";
|
||||
break;
|
||||
case ERROR_MISSING_TEMPLATE_FILE:
|
||||
sMessage = "Missing template file";
|
||||
break;
|
||||
case ERROR_PROPERTIES_FILE_IS_EMPTY:
|
||||
sMessage = "Properties file is empty";
|
||||
break;
|
||||
case ERROR_MISSING_INSTALL_DIR:
|
||||
sMessage = "Missing install dir";
|
||||
break;
|
||||
case ERROR_INSTALL_DIR_NOT_A_DIR:
|
||||
sMessage = "Install directory is not a directory";
|
||||
break;
|
||||
case ERROR_BAD_INSTALL_DIR_PARAM:
|
||||
sMessage = "Bad install directory parameter";
|
||||
break;
|
||||
case ERROR_BAD_PROPERTY_FILE_PARAM:
|
||||
sMessage = "Bad property file parameter";
|
||||
break;
|
||||
case ERROR_MISSING_PROPERTIES_FILE:
|
||||
sMessage = "Missing properties file";
|
||||
break;
|
||||
case ERROR_MISSING_INSTALL_DIR_PARAM:
|
||||
sMessage = "Missing install directory parameter";
|
||||
break;
|
||||
case ERROR_MISSING_PROPERTY_FILE_PARAM:
|
||||
sMessage = "Missing property file parameter";
|
||||
break;
|
||||
case ERROR_BAD_TEMPLATE_FILE_PARAM:
|
||||
sMessage = "Bad template file parameter";
|
||||
break;
|
||||
case ERROR_BAD_OUTPUT_FILE_PARAM:
|
||||
sMessage = "Bad output file parameter";
|
||||
break;
|
||||
case ERROR_MISSING_TEMPLATE_FILE_PARAM:
|
||||
sMessage = "Missing template file parameter";
|
||||
break;
|
||||
case ERROR_MISSING_OUTPUT_FILE_PARAM:
|
||||
sMessage = "Missing output file parameter";
|
||||
break;
|
||||
case ERROR_BAD_PROPERTY_PARAM:
|
||||
sMessage = "Bad property parameter";
|
||||
break;
|
||||
case ERROR_UNABLE_TO_READ_PROPERTIES:
|
||||
sMessage = "Unable to read properties file";
|
||||
break;
|
||||
case ERROR_UNABLE_TO_OPEN_TEMPLATE:
|
||||
sMessage = "Unable to open template";
|
||||
break;
|
||||
case ERROR_FILEWRITER_CREATE_FAILED:
|
||||
sMessage = "FileWriter create failed";
|
||||
break;
|
||||
case ERROR_EXCEPTION:
|
||||
sMessage = "Exception ";
|
||||
break;
|
||||
default:
|
||||
sMessage = "Unknown error: " + err;
|
||||
break;
|
||||
}
|
||||
|
||||
if (null != s)
|
||||
{
|
||||
sMessage = sMessage + s;
|
||||
}
|
||||
log(sMessage);
|
||||
}
|
||||
|
||||
void log(String s)
|
||||
{
|
||||
/*
|
||||
try
|
||||
{
|
||||
raf.writeUTF(this.getClass().getName() + ": " + s + "\r\n");
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Copyright (C) 2004 Novell, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# Author: Greg Richardson <grichardson@novell.com>
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
DIST_SUBDIRS =
|
||||
|
||||
EXTRA_DIST = InitConfigFile.java
|
||||
|
||||
if DEBUG
|
||||
TARGET_CFG = Debug
|
||||
DEBUG = -g
|
||||
else
|
||||
TARGET_CFG = Release
|
||||
DEBUG = -g:none
|
||||
endif
|
||||
|
||||
PACKAGE = InitConfigFile
|
||||
TARGET_FILE = $(PACKAGE).class
|
||||
LOG_FILE = $(PACKAGE).log
|
||||
JAVAFILES = InitConfigFile.java
|
||||
CLASSES = $(addprefix $(BUILDDIR)/, $(JAVAFILES:%.java=%.class))
|
||||
BUILDDIR = bin/$(TARGET_CFG)
|
||||
|
||||
.PHONY: package package-clean package-install package-uninstall
|
||||
|
||||
all: $(BUILDDIR) $(CLASSES)
|
||||
|
||||
$(BUILDDIR)/%.class: %.java
|
||||
@rm -f $(LOG_FILE) $@
|
||||
@echo [======== Compiling $@ ========]
|
||||
@javac $(DEBUG) -d $(BUILDDIR) $< 2> $(LOG_FILE)
|
||||
@echo $$CMD; \
|
||||
if eval $$CMD; then \
|
||||
ls -l $(BUILDDIR)/$(TARGET_FILE); \
|
||||
cp $(BUILDDIR)/$(TARGET_FILE) bin; \
|
||||
else \
|
||||
grep -a "ERROR:" $(LOG_FILE); \
|
||||
fi
|
||||
|
||||
$(BUILDDIR):
|
||||
[ -d $(BUILDDIR) ] || mkdir -p $(BUILDDIR)
|
||||
|
||||
|
||||
package-clean clean-local:
|
||||
rm -rf bin/Release/* bin/Release bin/Debug/* bin/Debug bin/* bin *.log
|
||||
|
||||
clean:
|
||||
rm -rf bin/Release/* bin/Release bin/Debug/* bin/Debug bin/* bin *.log
|
||||
|
||||
distclean-local: package-clean
|
||||
rm -f Makefile
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -f Makefile.in
|
||||
|
||||
|
||||
|
@ -20,22 +20,15 @@
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
SUBDIRS = ClientKeystoreSetup DeleteFile InitConfigFile MungeCryptoPropertiesFilePath ServerKeystoreSetup SetupAsWindowsService ShutdownWindowsService UpdateWarFile server-java_msi
|
||||
SUBDIRS = AtsConfigurator server-java_msi
|
||||
|
||||
DIST_SUBDIRS = ClientKeystoreSetup DeleteFile CommandLauncher InitConfigFile MungeCryptoPropertiesFilePath ServerKeystoreSetup SetupAsWindowsService ShutdownWindowsService UpdateWarFile server-java_msi
|
||||
DIST_SUBDIRS = AtsConfigurator server-java_msi
|
||||
|
||||
EXTRA_DIST =
|
||||
|
||||
.PHONY: package package-clean package-install package-uninstall
|
||||
package package-clean package-install package-uninstall:
|
||||
$(MAKE) -C ClientKeystoreSetup $@
|
||||
$(MAKE) -C DeleteFile $@
|
||||
$(MAKE) -C InitConfigFile $@
|
||||
$(MAKE) -C MungeCryptoPropertiesFilePath $@
|
||||
$(MAKE) -C ServerKeystoreSetup $@
|
||||
$(MAKE) -C SetupAsWindowsService $@
|
||||
$(MAKE) -C ShutdownWindowsService $@
|
||||
$(MAKE) -C UpdateWarFile $@
|
||||
$(MAKE) -C AtsConfigurator $@
|
||||
$(MAKE) -C server-java_msi $@
|
||||
|
||||
clean-local:
|
||||
|
@ -1,77 +0,0 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Copyright (C) 2004 Novell, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# Author: Greg Richardson <grichardson@novell.com>
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
DIST_SUBDIRS =
|
||||
|
||||
EXTRA_DIST = MungeCryptoPropertiesFilePath.java
|
||||
|
||||
if DEBUG
|
||||
TARGET_CFG = Debug
|
||||
DEBUG = -g
|
||||
else
|
||||
TARGET_CFG = Release
|
||||
DEBUG = -g:none
|
||||
endif
|
||||
|
||||
PACKAGE = MungeCryptoPropertiesFilePath
|
||||
TARGET_FILE = $(PACKAGE).class
|
||||
LOG_FILE = $(PACKAGE).log
|
||||
JAVAFILES = MungeCryptoPropertiesFilePath.java
|
||||
CLASSES = $(addprefix $(BUILDDIR)/, $(JAVAFILES:%.java=%.class))
|
||||
BUILDDIR = bin/$(TARGET_CFG)
|
||||
|
||||
.PHONY: package package-clean package-install package-uninstall
|
||||
|
||||
all: $(BUILDDIR) $(CLASSES)
|
||||
|
||||
$(BUILDDIR)/%.class: %.java
|
||||
@rm -f $(LOG_FILE) $@
|
||||
@echo [======== Compiling $@ ========]
|
||||
@javac $(DEBUG) -d $(BUILDDIR) $< 2> $(LOG_FILE)
|
||||
@echo $$CMD; \
|
||||
if eval $$CMD; then \
|
||||
ls -l $(BUILDDIR)/$(TARGET_FILE); \
|
||||
cp $(BUILDDIR)/$(TARGET_FILE) bin; \
|
||||
else \
|
||||
grep -a "ERROR:" $(LOG_FILE); \
|
||||
fi
|
||||
|
||||
$(BUILDDIR):
|
||||
[ -d $(BUILDDIR) ] || mkdir -p $(BUILDDIR)
|
||||
|
||||
|
||||
package-clean clean-local:
|
||||
rm -rf bin/Release/* bin/Release bin/Debug/* bin/Debug bin/* bin *.log
|
||||
|
||||
clean:
|
||||
rm -rf bin/Release/* bin/Release bin/Debug/* bin/Debug bin/* bin *.log
|
||||
|
||||
distclean-local: package-clean
|
||||
rm -f Makefile
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -f Makefile.in
|
||||
|
||||
|
||||
|
@ -1,335 +0,0 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright (C) 2006 Novell, Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, Novell, Inc.
|
||||
*
|
||||
* To contact Novell about this file by physical or electronic mail,
|
||||
* you may find current contact information at www.novell.com.
|
||||
*
|
||||
* Author: Greg Richardson
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Summary description for Program
|
||||
*/
|
||||
public class MungeCryptoPropertiesFilePath
|
||||
{
|
||||
final static int ERROR_NO_ERROR = 0;
|
||||
final static int ERROR_INVALID_NUMBER_OF_PARAMS = -1;
|
||||
final static int ERROR_MISSING_INPUT_FILE = -2;
|
||||
final static int ERROR_OUTPUT_COPY_FAILED = -3;
|
||||
final static int ERROR_IO_EXCEPTION = -4;
|
||||
final static int ERROR_BAD_INPUT_FILE_PARAM = -5;
|
||||
final static int ERROR_BAD_OUTPUT_FILE_PARAM = -6;
|
||||
final static int ERROR_MISSING_INPUT_FILE_PARAM = -7;
|
||||
final static int ERROR_MISSING_OUTPUT_FILE_PARAM = -8;
|
||||
final static int ERROR_CANNOT_READ_FILE = -9;
|
||||
final static int ERROR_CANNOT_CREATE_FILE = -10;
|
||||
final static int ERROR_EXCEPTION = -11;
|
||||
|
||||
final static String INPUT_FILE_PARAM = "input=";
|
||||
final static String OUTPUT_FILE_PARAM = "output=";
|
||||
final static String FILE_KEY = "com.novell.casa.authtoksvc.crypto.file=";
|
||||
|
||||
File fileInput;
|
||||
File fileOutput;
|
||||
//File file;
|
||||
//FileWriter fw;
|
||||
String sInput;
|
||||
String sOutput;
|
||||
int rc;
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
MungeCryptoPropertiesFilePath p = new MungeCryptoPropertiesFilePath(args);
|
||||
System.exit(p.rc);
|
||||
}
|
||||
|
||||
MungeCryptoPropertiesFilePath(String[] args)
|
||||
{
|
||||
rc = ERROR_NO_ERROR;
|
||||
|
||||
fileInput = null;
|
||||
fileOutput = null;
|
||||
|
||||
try
|
||||
{
|
||||
//file = new File("c:\\test5.log");
|
||||
//fw = new FileWriter(file);
|
||||
|
||||
log("Here we go: " + args.length);
|
||||
for (int i = 0; i < args.length; i++)
|
||||
{
|
||||
log("Arg " + i + " = " + args[i]);
|
||||
}
|
||||
|
||||
// Process the arguments
|
||||
if (ERROR_NO_ERROR == (rc = processArgs(args)))
|
||||
{
|
||||
// Process the file
|
||||
rc = createOutputFile();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
rc = ERROR_EXCEPTION;
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
log(rc);
|
||||
//fw.flush();
|
||||
//fw.close();
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int processArgs(String[] argsOld)
|
||||
{
|
||||
int iOld;
|
||||
int i;
|
||||
String args[] = new String[argsOld.length];
|
||||
int iNew;
|
||||
|
||||
log("Original arg count " + argsOld.length);
|
||||
for (i = 0; i < argsOld.length; i++)
|
||||
{
|
||||
log("Arg " + i + " = " + argsOld[i] + "\r\n");
|
||||
}
|
||||
|
||||
// Validate the number of parameters
|
||||
if (argsOld.length < 2)
|
||||
{
|
||||
return ERROR_INVALID_NUMBER_OF_PARAMS;
|
||||
}
|
||||
|
||||
iNew = -1;
|
||||
for (iOld = 0; iOld < argsOld.length; iOld++)
|
||||
{
|
||||
if (0 <= argsOld[iOld].indexOf("="))
|
||||
{
|
||||
iNew++;
|
||||
args[iNew] = argsOld[iOld];
|
||||
for (i = iOld + 1; i < argsOld.length && (-1 == argsOld[i].indexOf("=")); i++)
|
||||
{
|
||||
args[iNew] += " " + argsOld[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log("New arg count " + args.length);
|
||||
for (i = 0; i < args.length; i++)
|
||||
{
|
||||
log("Arg " + i + " = " + args[i] + "\r\n");
|
||||
}
|
||||
|
||||
for (i = 0; i <= iNew; i++)
|
||||
{
|
||||
log("arg[" + i + "] = " +args[i]);
|
||||
|
||||
if (args[i].startsWith(INPUT_FILE_PARAM))
|
||||
{
|
||||
// Make sure it is more than the param tag
|
||||
if (args[i].length() <= INPUT_FILE_PARAM.length())
|
||||
{
|
||||
return ERROR_BAD_INPUT_FILE_PARAM;
|
||||
}
|
||||
|
||||
sInput = args[i].substring(INPUT_FILE_PARAM.length()).trim();
|
||||
fileInput = new File(sInput);
|
||||
|
||||
// Make sure the input file can be found
|
||||
if (!fileInput.exists())
|
||||
{
|
||||
log(ERROR_MISSING_INPUT_FILE, sInput);
|
||||
return ERROR_MISSING_INPUT_FILE;
|
||||
}
|
||||
}
|
||||
|
||||
else if (args[i].startsWith(OUTPUT_FILE_PARAM))
|
||||
{
|
||||
// Make sure it is more than the param tag
|
||||
if (args[i].length() <= OUTPUT_FILE_PARAM.length())
|
||||
{
|
||||
return ERROR_BAD_OUTPUT_FILE_PARAM;
|
||||
}
|
||||
|
||||
sOutput = args[i].substring(OUTPUT_FILE_PARAM.length()).trim();
|
||||
fileOutput = new File(sOutput);
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we got an input file
|
||||
if (null == fileInput)
|
||||
{
|
||||
return ERROR_MISSING_INPUT_FILE_PARAM;
|
||||
}
|
||||
|
||||
// Make sure we got an output file
|
||||
if (null == fileOutput)
|
||||
{
|
||||
return ERROR_MISSING_OUTPUT_FILE_PARAM;
|
||||
}
|
||||
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
int createOutputFile()
|
||||
{
|
||||
LineNumberReader lnr = null;
|
||||
FileWriter fwOutput = null;
|
||||
String sLineTemplate;
|
||||
String sLineOutput;
|
||||
int iSearchFor;
|
||||
|
||||
try
|
||||
{
|
||||
// Open the file
|
||||
lnr = new LineNumberReader(new FileReader(fileInput));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return ERROR_CANNOT_READ_FILE;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
fwOutput = new FileWriter(fileOutput);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return ERROR_CANNOT_CREATE_FILE;
|
||||
}
|
||||
try
|
||||
{
|
||||
// For each line of text in the template file...
|
||||
while (null != (sLineTemplate = lnr.readLine()))
|
||||
{
|
||||
sLineOutput = sLineTemplate;
|
||||
log("<-- " + sLineOutput);
|
||||
|
||||
if (sLineOutput.trim().startsWith(FILE_KEY))
|
||||
{
|
||||
// Replace all instances of the line separator on the line
|
||||
while (-1 != (iSearchFor = sLineOutput.indexOf("\\")))
|
||||
{
|
||||
log("replacing \\ at position " + iSearchFor + " with //");
|
||||
sLineOutput = sLineOutput.substring(0, iSearchFor) + "//" +
|
||||
sLineOutput.substring(iSearchFor + 1);
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
fwOutput.write(sLineOutput + "\r\n");
|
||||
log("--> " + sLineOutput);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return -42;
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up
|
||||
fwOutput.flush();
|
||||
fwOutput.close();
|
||||
lnr.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return ERROR_OUTPUT_COPY_FAILED;
|
||||
}
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
void log(int err)
|
||||
{
|
||||
log(err, null);
|
||||
}
|
||||
|
||||
void log(int err, String s)
|
||||
{
|
||||
String sMessage = "";
|
||||
|
||||
switch (err)
|
||||
{
|
||||
case ERROR_NO_ERROR:
|
||||
sMessage = "No error";
|
||||
break;
|
||||
case ERROR_INVALID_NUMBER_OF_PARAMS:
|
||||
sMessage = "Invalid number of parameters: 2 expected";
|
||||
break;
|
||||
case ERROR_MISSING_INPUT_FILE:
|
||||
sMessage = "Missing input file";
|
||||
break;
|
||||
case ERROR_OUTPUT_COPY_FAILED:
|
||||
sMessage = "Unable to create output file";
|
||||
break;
|
||||
case ERROR_IO_EXCEPTION:
|
||||
sMessage = "IOException";
|
||||
break;
|
||||
case ERROR_BAD_INPUT_FILE_PARAM:
|
||||
sMessage = "Invalid input file parameter";
|
||||
break;
|
||||
case ERROR_BAD_OUTPUT_FILE_PARAM:
|
||||
sMessage = "Invalid output file parameter";
|
||||
break;
|
||||
case ERROR_MISSING_INPUT_FILE_PARAM:
|
||||
sMessage = "Missing input file parameter";
|
||||
break;
|
||||
case ERROR_MISSING_OUTPUT_FILE_PARAM:
|
||||
sMessage = "Missing output file parameter";
|
||||
break;
|
||||
case ERROR_CANNOT_READ_FILE:
|
||||
sMessage = "Cannot read file";
|
||||
break;
|
||||
case ERROR_CANNOT_CREATE_FILE:
|
||||
sMessage = "Cannot create file";
|
||||
break;
|
||||
case ERROR_EXCEPTION:
|
||||
sMessage = "Exception";
|
||||
break;
|
||||
default:
|
||||
sMessage = "Unknown error: " + err;
|
||||
break;
|
||||
}
|
||||
|
||||
if (null != s)
|
||||
{
|
||||
sMessage = sMessage + s;
|
||||
}
|
||||
log(sMessage);
|
||||
}
|
||||
|
||||
void log(String s)
|
||||
{
|
||||
/*
|
||||
try
|
||||
{
|
||||
fw.write(this.getClass().getName() + ": " + s + "\r\n");
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Copyright (C) 2004 Novell, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# Author: Greg Richardson <grichardson@novell.com>
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
DIST_SUBDIRS =
|
||||
|
||||
EXTRA_DIST = ServerKeystoreSetup.java
|
||||
|
||||
if DEBUG
|
||||
TARGET_CFG = Debug
|
||||
DEBUG = -g
|
||||
else
|
||||
TARGET_CFG = Release
|
||||
DEBUG = -g:none
|
||||
endif
|
||||
|
||||
PACKAGE = ServerKeystoreSetup
|
||||
TARGET_FILE = $(PACKAGE).class
|
||||
LOG_FILE = $(PACKAGE).log
|
||||
JAVAFILES = ServerKeystoreSetup.java
|
||||
CLASSES = $(addprefix $(BUILDDIR)/, $(JAVAFILES:%.java=%.class))
|
||||
BUILDDIR = bin/$(TARGET_CFG)
|
||||
|
||||
.PHONY: package package-clean package-install package-uninstall
|
||||
|
||||
all: $(BUILDDIR) $(CLASSES)
|
||||
|
||||
$(BUILDDIR)/%.class: %.java
|
||||
@rm -f $(LOG_FILE) $@
|
||||
@echo [======== Compiling $@ ========]
|
||||
@javac $(DEBUG) -d $(BUILDDIR) $< 2> $(LOG_FILE)
|
||||
@echo $$CMD; \
|
||||
if eval $$CMD; then \
|
||||
ls -l $(BUILDDIR)/$(TARGET_FILE); \
|
||||
cp $(BUILDDIR)/$(TARGET_FILE) bin; \
|
||||
else \
|
||||
grep -a "ERROR:" $(LOG_FILE); \
|
||||
fi
|
||||
|
||||
$(BUILDDIR):
|
||||
[ -d $(BUILDDIR) ] || mkdir -p $(BUILDDIR)
|
||||
|
||||
|
||||
package-clean clean-local:
|
||||
rm -rf bin/Release/* bin/Release bin/Debug/* bin/Debug bin/* bin *.log
|
||||
|
||||
clean:
|
||||
rm -rf bin/Release/* bin/Release bin/Debug/* bin/Debug bin/* bin *.log
|
||||
|
||||
distclean-local: package-clean
|
||||
rm -f Makefile
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -f Makefile.in
|
||||
|
||||
|
||||
|
@ -1,36 +0,0 @@
|
||||
import System.Reflection.*;
|
||||
import System.Runtime.CompilerServices.*;
|
||||
import System.Runtime.InteropServices.*;
|
||||
|
||||
//
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
//
|
||||
|
||||
/** @assembly AssemblyTitle("ServerKeystoreSetup") */
|
||||
/** @assembly AssemblyDescription("") */
|
||||
/** @assembly AssemblyCompany("Novell") */
|
||||
/** @assembly AssemblyProduct("ServerKeystoreSetup") */
|
||||
/** @assembly AssemblyCopyright("Copyright © Novell 2006") */
|
||||
/** @assembly AssemblyTrademark("") */
|
||||
/** @assembly AssemblyCulture("") */
|
||||
|
||||
|
||||
// The ComVisible attribute controls accessibility of an individual type
|
||||
// or member, or of all types within this assembly, from COM. To access
|
||||
// a type or member in this assembly from COM, set the ComVisible attribute
|
||||
// on that type or member to true.
|
||||
/** @assembly ComVisible(false) */
|
||||
|
||||
|
||||
//
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
|
||||
/** @assembly AssemblyVersion("1.0.0.0") */
|
@ -1,414 +0,0 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright (C) 2006 Novell, Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, Novell, Inc.
|
||||
*
|
||||
* To contact Novell about this file by physical or electronic mail,
|
||||
* you may find current contact information at www.novell.com.
|
||||
*
|
||||
* Author: Greg Richardson <grichardson@novell.com>
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class ServerKeystoreSetup
|
||||
{
|
||||
final static int ERROR_NO_ERROR = 0;
|
||||
final static int ERROR_EXEC_FAILED = -1;
|
||||
final static int ERROR_INVALID_NUMBER_OF_PARAMS = -2;
|
||||
final static int ERROR_BAD_INSTALL_DIR_PARAM = -3;
|
||||
final static int ERROR_MISSING_INSTALL_DIR = -4;
|
||||
final static int ERROR_INSTALL_DIR_NOT_A_DIR = -5;
|
||||
final static int ERROR_BAD_PROPERTY_FILE_PARAM = -6;
|
||||
final static int ERROR_MISSING_PROPERTIES_FILE = -7;
|
||||
final static int ERROR_UNABLE_TO_READ_PROPERTIES = -8;
|
||||
final static int ERROR_UNKNOWN_PARAM = -9;
|
||||
final static int ERROR_MISSING_INSTALL_DIR_PARAM = -10;
|
||||
final static int ERROR_REQUIRED_VALUE_MISSING = -11;
|
||||
final static int ERROR_EXEC_INTERRUPTED = -12;
|
||||
final static int ERROR_IO_EXCEPTION = -13;
|
||||
final static int ERROR_EXCEPTION = -14;
|
||||
|
||||
final static String INSTALL_DIR = "installdir=";
|
||||
final static String PROPERTY_FILE = "propertyfile=";
|
||||
|
||||
String sInstallDir;
|
||||
Properties properties;
|
||||
int rc;
|
||||
|
||||
// debug stuff
|
||||
//File file;
|
||||
//FileWriter fw;
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
ServerKeystoreSetup p = new ServerKeystoreSetup(args);
|
||||
System.exit(p.rc);
|
||||
}
|
||||
|
||||
ServerKeystoreSetup(String[] args)
|
||||
{
|
||||
rc = ERROR_NO_ERROR;
|
||||
try
|
||||
{
|
||||
// DEBUG STUFF
|
||||
//file = new File("c:\\test2.log");
|
||||
//fw = new FileWriter(file);
|
||||
|
||||
// Process the input params
|
||||
if (ERROR_NO_ERROR == (rc = processArgs(args)))
|
||||
{
|
||||
// Make sure we got everything we need
|
||||
if (ERROR_NO_ERROR == (rc = findRequiredValues()))
|
||||
{
|
||||
// Make sure the server keystore has been created
|
||||
rc = createServerKeystore();
|
||||
}
|
||||
}
|
||||
|
||||
// DEBUG STUFF
|
||||
log(rc);
|
||||
//fw.flush();
|
||||
//fw.close();
|
||||
// DEBUG STUFF
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
rc = ERROR_EXCEPTION;
|
||||
}
|
||||
}
|
||||
|
||||
int processArgs(String[] argsOld)
|
||||
{
|
||||
String sProperties;
|
||||
File fileInstallDir = null;
|
||||
File fileProperties = null;
|
||||
FileInputStream fisProperties = null;
|
||||
int iOld;
|
||||
int i;
|
||||
String args[] = new String[argsOld.length];
|
||||
int iNew;
|
||||
|
||||
log("Original arg count " + argsOld.length);
|
||||
for (i = 0; i < argsOld.length; i++)
|
||||
{
|
||||
log("Arg " + i + " = " + argsOld[i] + "\r\n");
|
||||
}
|
||||
|
||||
// Validate the number of parameters
|
||||
if (args.length < 2)
|
||||
{
|
||||
return ERROR_INVALID_NUMBER_OF_PARAMS;
|
||||
}
|
||||
|
||||
iNew = -1;
|
||||
for (iOld = 0; iOld < argsOld.length; iOld++)
|
||||
{
|
||||
if (0 <= argsOld[iOld].indexOf("="))
|
||||
{
|
||||
iNew++;
|
||||
args[iNew] = argsOld[iOld];
|
||||
for (i = iOld + 1; i < argsOld.length && (-1 == argsOld[i].indexOf("=")); i++)
|
||||
{
|
||||
args[iNew] += " " + argsOld[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log("New arg count " + args.length);
|
||||
for (i = 0; i < args.length; i++)
|
||||
{
|
||||
log("Arg " + i + " = " + args[i] + "\r\n");
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i <= iNew; i++)
|
||||
{
|
||||
// is this the install dir param?
|
||||
if (args[i].startsWith(INSTALL_DIR))
|
||||
{
|
||||
// Make sure it is more the the param tag
|
||||
if (args[i].length() <= INSTALL_DIR.length())
|
||||
{
|
||||
return ERROR_BAD_INSTALL_DIR_PARAM;
|
||||
}
|
||||
|
||||
sInstallDir = args[i].substring(INSTALL_DIR.length()).trim();
|
||||
fileInstallDir = new File(sInstallDir);
|
||||
|
||||
// Make sure the install dir can be found
|
||||
if (!fileInstallDir.exists())
|
||||
{
|
||||
return ERROR_MISSING_INSTALL_DIR;
|
||||
}
|
||||
|
||||
// Make sure the install dir is a directory
|
||||
if (!fileInstallDir.isDirectory())
|
||||
{
|
||||
return ERROR_INSTALL_DIR_NOT_A_DIR;
|
||||
}
|
||||
}
|
||||
|
||||
// is this the properties file param?
|
||||
else if (args[i].startsWith(PROPERTY_FILE))
|
||||
{
|
||||
// Make sure it is more the the param tag
|
||||
if (args[i].length() <= PROPERTY_FILE.length())
|
||||
{
|
||||
return ERROR_BAD_PROPERTY_FILE_PARAM;
|
||||
}
|
||||
|
||||
sProperties = args[i].substring(PROPERTY_FILE.length()).trim();
|
||||
fileProperties = new File(sProperties);
|
||||
|
||||
// Make sure the properties file can be found
|
||||
if (!fileProperties.exists())
|
||||
{
|
||||
return ERROR_MISSING_PROPERTIES_FILE;
|
||||
}
|
||||
|
||||
// Read the properties
|
||||
try
|
||||
{
|
||||
fisProperties = new FileInputStream(fileProperties);
|
||||
properties = new Properties();
|
||||
properties.load(fisProperties);
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
return ERROR_UNABLE_TO_READ_PROPERTIES;
|
||||
}
|
||||
}
|
||||
|
||||
// Unknown parameter
|
||||
else
|
||||
{
|
||||
log(ERROR_UNKNOWN_PARAM, args[i]);
|
||||
return ERROR_UNKNOWN_PARAM;
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we got an install dir
|
||||
if (null == fileInstallDir)
|
||||
{
|
||||
return ERROR_MISSING_INSTALL_DIR_PARAM;
|
||||
}
|
||||
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
int findRequiredValues()
|
||||
{
|
||||
String[] rgsRequired = {
|
||||
"ATS_JAVA_HOME",
|
||||
"COMPUTERNAME"};
|
||||
int i;
|
||||
String sValue;
|
||||
|
||||
for (i = 0; i < rgsRequired.length; i++)
|
||||
{
|
||||
log("look for required value: " + rgsRequired[i]);
|
||||
|
||||
if (!properties.containsKey(rgsRequired[i]))
|
||||
{
|
||||
log("look for required value in envirement: " + rgsRequired[i]);
|
||||
if (null == (sValue = System.getProperty(rgsRequired[i])))
|
||||
{
|
||||
log("unable to find required value in envirement: " + rgsRequired[i]);
|
||||
return ERROR_REQUIRED_VALUE_MISSING;
|
||||
}
|
||||
log("found required value in envirement: " + rgsRequired[i] + " = " + sValue);
|
||||
properties.put(rgsRequired[i], sValue);
|
||||
}
|
||||
log("found required value: " + rgsRequired[i] + " = " + properties.get(rgsRequired[i]));
|
||||
}
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
int createServerKeystore()
|
||||
{
|
||||
int rc;
|
||||
String sKeytool = properties.get("ATS_JAVA_HOME") + "\\bin\\keytool.exe";
|
||||
String sHost = (String)properties.get("COMPUTERNAME");
|
||||
|
||||
log("keytool = " + sKeytool);
|
||||
log("host = " + sHost);
|
||||
|
||||
// Do not do anything if the server keystore has already been created
|
||||
if (keyStoreAlreadyExists())
|
||||
{
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
// Create the server keystore with the key that will be used for signing tokens
|
||||
if (ERROR_NO_ERROR == (rc =invokeCommand(sKeytool + " -genkey -alias signingKey -keystore " +
|
||||
sInstallDir + "ats\\etc\\keys\\server\\jks-store -dname \"cn=casaatsd@" + sHost +
|
||||
"\" -validity 3600 -keypass secret -storepass secret")))
|
||||
{
|
||||
// Export self-signed certificate for the signing key
|
||||
if (ERROR_NO_ERROR == (rc = invokeCommand(sKeytool + " -export -keystore " +
|
||||
sInstallDir + "ats\\etc\\keys\\server\\jks-store -alias signingKey -storepass secret -keypass secret -file " +
|
||||
sInstallDir + "ats\\etc\\keys\\casaatsdSigningCert")))
|
||||
{
|
||||
// Create a key for Tomcat to do SSL communications
|
||||
rc = invokeCommand(sKeytool + " -genkey -alias tomcat -keyalg RSA -keystore " +
|
||||
sInstallDir + "ats\\etc\\keys\\server\\jks-store -dname \"cn=" +
|
||||
sHost + "\" -validity 3600 -keypass secret -storepass secret");
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
boolean keyStoreAlreadyExists()
|
||||
{
|
||||
File fileKeystore = new File(sInstallDir + "ats\\etc\\keys\\server\\jks-store");
|
||||
|
||||
// Why is this always returning true? exists() also always returns true.
|
||||
// log("keystore (" + sInstallDir + "ats\\etc\\keys\\server\\jks-store" + ") already exists = " + (file.isFile()));
|
||||
// return (file.isFile());
|
||||
|
||||
File fileParent = fileKeystore.getParentFile();
|
||||
String[] rgChildren = fileParent.list();
|
||||
if (null != rgChildren)
|
||||
{
|
||||
for (int i = 0; i < rgChildren.length; i++)
|
||||
{
|
||||
log("child " + i + " = " + rgChildren[i]);
|
||||
if ("jks-store".equals(rgChildren[i]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int invokeCommand(String sCommand)
|
||||
{
|
||||
Process p;
|
||||
int rc;
|
||||
|
||||
log("invoke command: " + sCommand);
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
|
||||
try
|
||||
{
|
||||
p = runtime.exec(sCommand);
|
||||
try
|
||||
{
|
||||
rc = p.waitFor();
|
||||
log("invoke command return code: " + rc);
|
||||
}
|
||||
catch (InterruptedException ie)
|
||||
{
|
||||
log(ERROR_EXEC_INTERRUPTED, sCommand);
|
||||
return ERROR_EXEC_INTERRUPTED;
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
log("Ioexception");
|
||||
return ERROR_EXEC_FAILED;
|
||||
}
|
||||
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
void log(int err)
|
||||
{
|
||||
log(err, null);
|
||||
}
|
||||
|
||||
void log(int err, String s)
|
||||
{
|
||||
String sMessage = "";
|
||||
|
||||
switch (err)
|
||||
{
|
||||
case ERROR_NO_ERROR:
|
||||
sMessage = "No error";
|
||||
break;
|
||||
case ERROR_EXEC_FAILED:
|
||||
sMessage = "Execute command failed ";
|
||||
break;
|
||||
case ERROR_INVALID_NUMBER_OF_PARAMS:
|
||||
sMessage = "Invalid number of params";
|
||||
break;
|
||||
case ERROR_BAD_INSTALL_DIR_PARAM:
|
||||
sMessage = "Install dir parameter is bad";
|
||||
break;
|
||||
case ERROR_MISSING_INSTALL_DIR:
|
||||
sMessage = "Missing install dir";
|
||||
break;
|
||||
case ERROR_INSTALL_DIR_NOT_A_DIR:
|
||||
sMessage = "Install dir is not a dir";
|
||||
break;
|
||||
case ERROR_BAD_PROPERTY_FILE_PARAM:
|
||||
sMessage = "Invalid porperty file parameter";
|
||||
break;
|
||||
case ERROR_MISSING_PROPERTIES_FILE:
|
||||
sMessage = "Property file not found";
|
||||
break;
|
||||
case ERROR_UNABLE_TO_READ_PROPERTIES:
|
||||
sMessage = "Unable to read property file";
|
||||
break;
|
||||
case ERROR_UNKNOWN_PARAM:
|
||||
sMessage = "Unknown parameter: ";
|
||||
break;
|
||||
case ERROR_MISSING_INSTALL_DIR_PARAM:
|
||||
sMessage = "Install dir parameter is missing";
|
||||
break;
|
||||
case ERROR_REQUIRED_VALUE_MISSING:
|
||||
sMessage = "Required value is missing ";
|
||||
break;
|
||||
case ERROR_EXEC_INTERRUPTED:
|
||||
sMessage = "Execution iinterrupted: ";
|
||||
break;
|
||||
case ERROR_IO_EXCEPTION:
|
||||
sMessage = "IO Exception ";
|
||||
break;
|
||||
case ERROR_EXCEPTION:
|
||||
sMessage = "Exception ";
|
||||
break;
|
||||
default:
|
||||
sMessage = "Unknown error";
|
||||
break;
|
||||
}
|
||||
|
||||
if (null != s)
|
||||
{
|
||||
sMessage = sMessage + s;
|
||||
}
|
||||
log(sMessage);
|
||||
}
|
||||
|
||||
void log(String s)
|
||||
{
|
||||
/*
|
||||
try
|
||||
{
|
||||
fw.write(this.getClass().getName() + ": " + s + "\r\n");
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Copyright (C) 2004 Novell, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# Author: Greg Richardson <grichardson@novell.com>
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
DIST_SUBDIRS =
|
||||
|
||||
EXTRA_DIST = SetupAsWindowsService.java
|
||||
|
||||
if DEBUG
|
||||
TARGET_CFG = Debug
|
||||
DEBUG = -g
|
||||
else
|
||||
TARGET_CFG = Release
|
||||
DEBUG = -g:none
|
||||
endif
|
||||
|
||||
PACKAGE = SetupAsWindowsService
|
||||
TARGET_FILE = $(PACKAGE).class
|
||||
LOG_FILE = $(PACKAGE).log
|
||||
JAVAFILES = SetupAsWindowsService.java
|
||||
CLASSES = $(addprefix $(BUILDDIR)/, $(JAVAFILES:%.java=%.class))
|
||||
BUILDDIR = bin/$(TARGET_CFG)
|
||||
|
||||
.PHONY: package package-clean package-install package-uninstall
|
||||
|
||||
all: $(BUILDDIR) $(CLASSES)
|
||||
|
||||
$(BUILDDIR)/%.class: %.java
|
||||
@rm -f $(LOG_FILE) $@
|
||||
@echo [======== Compiling $@ ========]
|
||||
@javac $(DEBUG) -d $(BUILDDIR) $< 2> $(LOG_FILE)
|
||||
@echo $$CMD; \
|
||||
if eval $$CMD; then \
|
||||
ls -l $(BUILDDIR)/$(TARGET_FILE); \
|
||||
cp $(BUILDDIR)/$(TARGET_FILE) bin; \
|
||||
else \
|
||||
grep -a "ERROR:" $(LOG_FILE); \
|
||||
fi
|
||||
|
||||
$(BUILDDIR):
|
||||
[ -d $(BUILDDIR) ] || mkdir -p $(BUILDDIR)
|
||||
|
||||
|
||||
package-clean clean-local:
|
||||
rm -rf bin/Release/* bin/Release bin/Debug/* bin/Debug bin/* bin *.log
|
||||
|
||||
clean:
|
||||
rm -rf bin/Release/* bin/Release bin/Debug/* bin/Debug bin/* bin *.log
|
||||
|
||||
distclean-local: package-clean
|
||||
rm -f Makefile
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -f Makefile.in
|
||||
|
||||
|
||||
|
@ -1,517 +0,0 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright (C) 2006 Novell, Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, Novell, Inc.
|
||||
*
|
||||
* To contact Novell about this file by physical or electronic mail,
|
||||
* you may find current contact information at www.novell.com.
|
||||
*
|
||||
* Author: Greg Richardson <grichardson@novell.com>
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Summary description for SetupAsWindowsService
|
||||
*/
|
||||
public class SetupAsWindowsService
|
||||
{
|
||||
final static int ERROR_NO_ERROR = 0;
|
||||
final static int ERROR_INVALID_NUMBER_OF_PARAMS = -1;
|
||||
final static int ERROR_EXEC_FAILED = -2;
|
||||
final static int ERROR_EXEC_INTERRUPTED = -3;
|
||||
final static int ERROR_IO_EXCEPTION = -13;
|
||||
final static int ERROR_UNABLE_TO_READ_PROPERTIES = -16;
|
||||
final static int ERROR_MISSING_INSTALL_DIR = -18;
|
||||
final static int ERROR_INSTALL_DIR_NOT_A_DIR = -19;
|
||||
final static int ERROR_BAD_INSTALL_DIR_PARAM = -20;
|
||||
final static int ERROR_BAD_PROPERTY_FILE_PARAM = -21;
|
||||
final static int ERROR_MISSING_PROPERTIES_FILE = -22;
|
||||
final static int ERROR_MISSING_INSTALL_DIR_PARAM = -23;
|
||||
final static int ERROR_MISSING_PROPERTY_FILE_PARAM = -24;
|
||||
final static int ERROR_BAD_PROPERTY_PARAM = -29;
|
||||
final static int ERROR_EXCEPTION = -30;
|
||||
|
||||
final static String INSTALL_DIR_PROPERTY = "ATS_INSTALL_DIR";
|
||||
final static String PROPERTY_FILE_PARAM = "propertyfile=";
|
||||
final static String INSTALL_DIR = "installdir=";
|
||||
final static String PROPERTY_FILE = "propertyfile=";
|
||||
|
||||
Properties properties;
|
||||
File fileProperties;
|
||||
FileInputStream fisProperties;
|
||||
File fileOutput;
|
||||
//File file;
|
||||
//FileWriter fw;
|
||||
String sInstallDir;
|
||||
String sOutput;
|
||||
int rc;
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
SetupAsWindowsService p = new SetupAsWindowsService(args);
|
||||
System.exit(p.rc);
|
||||
}
|
||||
|
||||
SetupAsWindowsService(String[] args)
|
||||
{
|
||||
rc = ERROR_NO_ERROR;
|
||||
|
||||
properties = new Properties();
|
||||
fileProperties = null;
|
||||
fisProperties = null;
|
||||
fileOutput = null;
|
||||
|
||||
try
|
||||
{
|
||||
//file = new File("c:\\test6.log");
|
||||
//fw = new FileWriter(file);
|
||||
|
||||
// Process the arguments
|
||||
log("Process args");
|
||||
if (ERROR_NO_ERROR == (rc = processArgs(args)))
|
||||
{
|
||||
// Process the properties
|
||||
log("Process properties");
|
||||
if (ERROR_NO_ERROR == (rc = processProperties()))
|
||||
{
|
||||
log("setupService");
|
||||
rc = setupService();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
rc = ERROR_EXCEPTION;
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
log(rc);
|
||||
//fw.flush();
|
||||
//fw.close();
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int processArgs(String[] argsOld)
|
||||
{
|
||||
String sProperties;
|
||||
File fileInstallDir = null;
|
||||
int iEquals;
|
||||
String sKey;
|
||||
String sValue;
|
||||
int iOld;
|
||||
int i;
|
||||
String args[] = new String[argsOld.length];
|
||||
int iNew;
|
||||
|
||||
log("Original arg count " + argsOld.length);
|
||||
for (i = 0; i < argsOld.length; i++)
|
||||
{
|
||||
log("Arg " + i + " = " + argsOld[i] + "\r\n");
|
||||
}
|
||||
|
||||
// Validate the number of parameters
|
||||
if (args.length < 2)
|
||||
{
|
||||
return ERROR_INVALID_NUMBER_OF_PARAMS;
|
||||
}
|
||||
|
||||
iNew = -1;
|
||||
for (iOld = 0; iOld < argsOld.length; iOld++)
|
||||
{
|
||||
if (0 <= argsOld[iOld].indexOf("="))
|
||||
{
|
||||
iNew++;
|
||||
args[iNew] = argsOld[iOld];
|
||||
for (i = iOld + 1; i < argsOld.length && (-1 == argsOld[i].indexOf("=")); i++)
|
||||
{
|
||||
args[iNew] += " " + argsOld[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log("New arg count " + args.length);
|
||||
for (i = 0; i < args.length; i++)
|
||||
{
|
||||
if (null == args[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
log("arg[" + i + "] = " +args[i]);
|
||||
|
||||
// is this the install dir param?
|
||||
if (args[i].startsWith(INSTALL_DIR))
|
||||
{
|
||||
// Make sure it is more the the param tag
|
||||
if (args[i].length() <= INSTALL_DIR.length())
|
||||
{
|
||||
return ERROR_BAD_INSTALL_DIR_PARAM;
|
||||
}
|
||||
|
||||
sInstallDir = args[i].substring(INSTALL_DIR.length()).trim();
|
||||
fileInstallDir = new File(sInstallDir);
|
||||
|
||||
// Make sure the install dir can be found
|
||||
if (!fileInstallDir.exists())
|
||||
{
|
||||
return ERROR_MISSING_INSTALL_DIR;
|
||||
}
|
||||
|
||||
// Make sure the install dir is a directory
|
||||
if (!fileInstallDir.isDirectory())
|
||||
{
|
||||
return ERROR_INSTALL_DIR_NOT_A_DIR;
|
||||
}
|
||||
|
||||
properties.setProperty(INSTALL_DIR_PROPERTY, sInstallDir);
|
||||
}
|
||||
|
||||
// is this the properties file param?
|
||||
else if (args[i].startsWith(PROPERTY_FILE_PARAM))
|
||||
{
|
||||
// Make sure it is more than the param tag
|
||||
if (args[i].length() <= PROPERTY_FILE_PARAM.length())
|
||||
{
|
||||
return ERROR_BAD_PROPERTY_FILE_PARAM;
|
||||
}
|
||||
|
||||
sProperties = args[i].substring(PROPERTY_FILE_PARAM.length()).trim();
|
||||
fileProperties = new File(sProperties);
|
||||
|
||||
// Make sure the properties file can be found
|
||||
if (!fileProperties.exists())
|
||||
{
|
||||
return ERROR_MISSING_PROPERTIES_FILE;
|
||||
}
|
||||
|
||||
// Read the properties
|
||||
try
|
||||
{
|
||||
fisProperties = new FileInputStream(fileProperties);
|
||||
properties.load(fisProperties);
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
return ERROR_UNABLE_TO_READ_PROPERTIES;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle additional parameters
|
||||
else
|
||||
{
|
||||
if (-1 == (iEquals = args[i].indexOf("=")) ||
|
||||
0 == iEquals ||
|
||||
args[i].length() == iEquals)
|
||||
{
|
||||
return ERROR_BAD_PROPERTY_PARAM;
|
||||
}
|
||||
sKey = args[i].substring(0, iEquals);
|
||||
sValue = args[i].substring(iEquals + 1);
|
||||
properties.setProperty(sKey, sValue);
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we got an install dir
|
||||
if (null == fileInstallDir)
|
||||
{
|
||||
return ERROR_MISSING_INSTALL_DIR_PARAM;
|
||||
}
|
||||
|
||||
// Note: the properties file parameter is optional
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
int processProperties()
|
||||
{
|
||||
try
|
||||
{
|
||||
Enumeration e;
|
||||
String sKey;
|
||||
String sValue;
|
||||
|
||||
e = properties.propertyNames();
|
||||
|
||||
while (e.hasMoreElements())
|
||||
{
|
||||
sKey = (String)e.nextElement();
|
||||
sValue = (String)properties.get(sKey);
|
||||
|
||||
log("Property key = " + sKey + " Value = " + sValue);
|
||||
}
|
||||
}
|
||||
catch (Exception ex1)
|
||||
{
|
||||
return -111;
|
||||
}
|
||||
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
int setupService()
|
||||
{
|
||||
String sDirInstall = (String)properties.get(INSTALL_DIR_PROPERTY);
|
||||
String sDirCatalinaBase = sInstallDir + "ats/catalinabase";
|
||||
String sDirCatalinaHome = (String)properties.get("TOMCAT_HOME");
|
||||
String sExe = (String)properties.get("TOMCAT5");
|
||||
String sFileJaasConf = (String)properties.get("JAAS_CONF");
|
||||
String sDirConfig = sDirInstall + "ats/etc/svc";
|
||||
String sDirJavaHome = (String)properties.get("ATS_JAVA_HOME");
|
||||
String sLogPrefix = "casa-auth-token-svc";
|
||||
String sDirLogs = sDirCatalinaBase + "/logs";
|
||||
String sCommand = "";
|
||||
int iReturn = ERROR_NO_ERROR;
|
||||
|
||||
sCommand = sExe + " //IS//CasaAuthTokenService --StartClass org.apache.catalina.startup.Bootstrap --StopClass org.apache.catalina.startup.Bootstrap --StartParams start --StopParams stop";
|
||||
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
|
||||
{
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
sCommand = sExe + " //US//CasaAuthTokenService --Startup auto";
|
||||
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
|
||||
{
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
sCommand = sExe + " //US//CasaAuthTokenService --JvmOptions \"-Dcatalina.base=" + sDirCatalinaBase + "\"";
|
||||
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
|
||||
{
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
sCommand = sExe + " //US//CasaAuthTokenService ++JvmOptions \"-Dcatalina.home=" + sDirCatalinaHome + "\"";
|
||||
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
|
||||
{
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
sCommand = sExe + " //US//CasaAuthTokenService ++JvmOptions \"-Djava.endorsed.dirs=" + sDirCatalinaHome + "/common/endorsed\"";
|
||||
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
|
||||
{
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
sCommand = sExe + " //US//CasaAuthTokenService ++JvmOptions \"-Djava.security.auth.login.config=" + sFileJaasConf + "\"";
|
||||
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
|
||||
{
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
sCommand = sExe + " //US//CasaAuthTokenService ++JvmOptions \"-Dcom.novell.casa.authtoksvc.config=" + sDirConfig + "\"";
|
||||
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
|
||||
{
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
sCommand = sExe + " //US//CasaAuthTokenService ++JvmOptions \"-Dlog4j.configuration=file:" + sDirInstall + "/ats/etc/log4j.properties";
|
||||
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
|
||||
{
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
sCommand = sExe + " //US//CasaAuthTokenService ++JvmOptions \"-Djava.io.tmpdir=" + sDirCatalinaBase+ "/temp\"";
|
||||
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
|
||||
{
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
sCommand = sExe + " //US//CasaAuthTokenService --StartMode jvm --StopMode jvm";
|
||||
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
|
||||
{
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
sCommand = sExe + " //US//CasaAuthTokenService --JvmMs 128 --JvmMx 512";
|
||||
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
|
||||
{
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
sCommand = sExe + " //US//CasaAuthTokenService --Classpath \"" + sDirCatalinaHome + "/bin/bootstrap.jar\"";
|
||||
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
|
||||
{
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
sCommand = sExe + " //US//CasaAuthTokenService --Jvm \"" + sDirJavaHome + "/jre/bin/server/jvm.dll\"";
|
||||
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
|
||||
{
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
sCommand = sExe + " //US//CasaAuthTokenService --LogPath \"" + sDirLogs + "\"";
|
||||
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
|
||||
{
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
sCommand = sExe + " //US//CasaAuthTokenService --LogPrefix \"" + sLogPrefix + "_service.log\"";
|
||||
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
|
||||
{
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
sCommand = sExe + " //US//CasaAuthTokenService --StdOutput \"" + sDirLogs +
|
||||
File.separator + sLogPrefix + "_stdout.log\"";
|
||||
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
|
||||
{
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
sCommand = sExe + " //US//CasaAuthTokenService --StdError \"" + sDirLogs +
|
||||
File.separator + sLogPrefix + "_stderr.log\"";
|
||||
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
|
||||
{
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
sCommand = sExe + " //US//CasaAuthTokenService --DisplayName " + "CasaAuthTokenSvc";
|
||||
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
|
||||
{
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
sCommand = sExe + " //US//CasaAuthTokenService --Description " + "\"Casa Authentication Token Service\"";
|
||||
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
|
||||
{
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
int invokeCommand(String sCommand)
|
||||
{
|
||||
Process p;
|
||||
int rc;
|
||||
|
||||
log("invoke command: " + sCommand);
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
try
|
||||
{
|
||||
p = runtime.exec(sCommand);
|
||||
try
|
||||
{
|
||||
rc = p.waitFor();
|
||||
log("invoke command return code: " + rc);
|
||||
}
|
||||
catch (InterruptedException ie)
|
||||
{
|
||||
log(ERROR_EXEC_INTERRUPTED, sCommand);
|
||||
return ERROR_EXEC_INTERRUPTED;
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
log("IOException");
|
||||
return ERROR_EXEC_FAILED;
|
||||
}
|
||||
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void log(int err)
|
||||
{
|
||||
log(err, null);
|
||||
}
|
||||
|
||||
void log(int err, String s)
|
||||
{
|
||||
String sMessage = "";
|
||||
|
||||
switch (err)
|
||||
{
|
||||
case ERROR_NO_ERROR:
|
||||
sMessage = "No error";
|
||||
break;
|
||||
case ERROR_INVALID_NUMBER_OF_PARAMS:
|
||||
sMessage = "Invalid number of parameters: 4 expected";
|
||||
break;
|
||||
case ERROR_IO_EXCEPTION:
|
||||
sMessage = "IOException";
|
||||
break;
|
||||
case ERROR_EXEC_FAILED:
|
||||
sMessage = "Exec failed";
|
||||
break;
|
||||
case ERROR_EXEC_INTERRUPTED:
|
||||
sMessage = "Exec interrupted";
|
||||
break;
|
||||
case ERROR_UNABLE_TO_READ_PROPERTIES:
|
||||
sMessage = "nable to read properties";
|
||||
break;
|
||||
case ERROR_MISSING_INSTALL_DIR:
|
||||
sMessage = "Missing install directory";
|
||||
break;
|
||||
case ERROR_INSTALL_DIR_NOT_A_DIR:
|
||||
sMessage = "Install directory is not a directory";
|
||||
break;
|
||||
case ERROR_BAD_INSTALL_DIR_PARAM:
|
||||
sMessage = "Bad install directory parameter";
|
||||
break;
|
||||
case ERROR_BAD_PROPERTY_FILE_PARAM:
|
||||
sMessage = "Bad property file parameter";
|
||||
break;
|
||||
case ERROR_MISSING_PROPERTIES_FILE:
|
||||
sMessage = "Missing properties file";
|
||||
break;
|
||||
case ERROR_MISSING_INSTALL_DIR_PARAM:
|
||||
sMessage = "Missing install directory parameter";
|
||||
break;
|
||||
case ERROR_MISSING_PROPERTY_FILE_PARAM:
|
||||
sMessage = "Missing property file parameter";
|
||||
break;
|
||||
case ERROR_BAD_PROPERTY_PARAM:
|
||||
sMessage = "Bad property parameter";
|
||||
break;
|
||||
case ERROR_EXCEPTION:
|
||||
sMessage = "Exception";
|
||||
break;
|
||||
default:
|
||||
sMessage = "Unknown error: " + err;
|
||||
break;
|
||||
}
|
||||
|
||||
if (null != s)
|
||||
{
|
||||
sMessage = sMessage + s;
|
||||
}
|
||||
log(sMessage);
|
||||
}
|
||||
|
||||
void log(String s)
|
||||
{
|
||||
/*
|
||||
try
|
||||
{
|
||||
fw.write(this.getClass().getName() + ": " + s + "\r\n");
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Copyright (C) 2004 Novell, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# Author: Greg Richardson <grichardson@novell.com>
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
DIST_SUBDIRS =
|
||||
|
||||
EXTRA_DIST = ShutdownWindowsService.java
|
||||
|
||||
if DEBUG
|
||||
TARGET_CFG = Debug
|
||||
DEBUG = -g
|
||||
else
|
||||
TARGET_CFG = Release
|
||||
DEBUG = -g:none
|
||||
endif
|
||||
|
||||
PACKAGE = ShutdownWindowsService
|
||||
TARGET_FILE = $(PACKAGE).class
|
||||
LOG_FILE = $(PACKAGE).log
|
||||
JAVAFILES = ShutdownWindowsService.java
|
||||
CLASSES = $(addprefix $(BUILDDIR)/, $(JAVAFILES:%.java=%.class))
|
||||
BUILDDIR = bin/$(TARGET_CFG)
|
||||
|
||||
.PHONY: package package-clean package-install package-uninstall
|
||||
|
||||
all: $(BUILDDIR) $(CLASSES)
|
||||
|
||||
$(BUILDDIR)/%.class: %.java
|
||||
@rm -f $(LOG_FILE) $@
|
||||
@echo [======== Compiling $@ ========]
|
||||
@javac $(DEBUG) -d $(BUILDDIR) $< 2> $(LOG_FILE)
|
||||
@echo $$CMD; \
|
||||
if eval $$CMD; then \
|
||||
ls -l $(BUILDDIR)/$(TARGET_FILE); \
|
||||
cp $(BUILDDIR)/$(TARGET_FILE) bin; \
|
||||
else \
|
||||
grep -a "ERROR:" $(LOG_FILE); \
|
||||
fi
|
||||
|
||||
$(BUILDDIR):
|
||||
[ -d $(BUILDDIR) ] || mkdir -p $(BUILDDIR)
|
||||
|
||||
|
||||
package-clean clean-local:
|
||||
rm -rf bin/Release/* bin/Release bin/Debug/* bin/Debug bin/* bin *.log
|
||||
|
||||
clean:
|
||||
rm -rf bin/Release/* bin/Release bin/Debug/* bin/Debug bin/* bin *.log
|
||||
|
||||
distclean-local: package-clean
|
||||
rm -f Makefile
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -f Makefile.in
|
||||
|
||||
|
||||
|
@ -1,403 +0,0 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright (C) 2006 Novell, Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, Novell, Inc.
|
||||
*
|
||||
* To contact Novell about this file by physical or electronic mail,
|
||||
* you may find current contact information at www.novell.com.
|
||||
*
|
||||
* Author: Greg Richardson <grichardson@novell.com>
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Summary description for ShutdownWindowsService
|
||||
*/
|
||||
public class ShutdownWindowsService
|
||||
{
|
||||
final static int ERROR_NO_ERROR = 0;
|
||||
final static int ERROR_INVALID_NUMBER_OF_PARAMS = -1;
|
||||
final static int ERROR_EXEC_FAILED = -2;
|
||||
final static int ERROR_EXEC_INTERRUPTED = -3;
|
||||
final static int ERROR_IO_EXCEPTION = -13;
|
||||
final static int ERROR_UNABLE_TO_READ_PROPERTIES = -16;
|
||||
final static int ERROR_MISSING_INSTALL_DIR = -18;
|
||||
final static int ERROR_INSTALL_DIR_NOT_A_DIR = -19;
|
||||
final static int ERROR_BAD_INSTALL_DIR_PARAM = -20;
|
||||
final static int ERROR_BAD_PROPERTY_FILE_PARAM = -21;
|
||||
final static int ERROR_MISSING_PROPERTIES_FILE = -22;
|
||||
final static int ERROR_MISSING_INSTALL_DIR_PARAM = -23;
|
||||
final static int ERROR_MISSING_PROPERTY_FILE_PARAM = -24;
|
||||
final static int ERROR_BAD_PROPERTY_PARAM = -29;
|
||||
final static int ERROR_EXCEPTION = -30;
|
||||
|
||||
final static String INSTALL_DIR_PROPERTY = "ATS_INSTALL_DIR";
|
||||
final static String PROPERTY_FILE_PARAM = "propertyfile=";
|
||||
final static String INSTALL_DIR = "installdir=";
|
||||
final static String PROPERTY_FILE = "propertyfile=";
|
||||
|
||||
Properties properties;
|
||||
File fileProperties;
|
||||
FileInputStream fisProperties;
|
||||
File fileOutput;
|
||||
//File file;
|
||||
//FileWriter fw;
|
||||
String sInstallDir;
|
||||
String sOutput;
|
||||
int rc;
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
ShutdownWindowsService p = new ShutdownWindowsService(args);
|
||||
System.exit(ERROR_NO_ERROR);
|
||||
}
|
||||
|
||||
ShutdownWindowsService(String[] args)
|
||||
{
|
||||
rc = ERROR_NO_ERROR;
|
||||
|
||||
properties = new Properties();
|
||||
fileProperties = null;
|
||||
fisProperties = null;
|
||||
fileOutput = null;
|
||||
|
||||
try
|
||||
{
|
||||
//file = new File("c:\\test7.log");
|
||||
//fw = new FileWriter(file);
|
||||
|
||||
// Process the arguments
|
||||
if (ERROR_NO_ERROR == (rc = processArgs(args)))
|
||||
{
|
||||
// Process the properties
|
||||
if (ERROR_NO_ERROR == (rc = processProperties()))
|
||||
{
|
||||
rc = shutdownService();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
rc = ERROR_EXCEPTION;
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
log(rc);
|
||||
//fw.flush();
|
||||
//fw.close();
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int processArgs(String[] argsOld)
|
||||
{
|
||||
String sProperties;
|
||||
File fileInstallDir = null;
|
||||
int iEquals;
|
||||
String sKey;
|
||||
String sValue;
|
||||
int iOld;
|
||||
int i;
|
||||
String args[] = new String[argsOld.length];
|
||||
int iNew;
|
||||
|
||||
log("Original arg count " + argsOld.length);
|
||||
for (i = 0; i < argsOld.length; i++)
|
||||
{
|
||||
log("Arg " + i + " = " + argsOld[i] + "\r\n");
|
||||
}
|
||||
|
||||
// Validate the number of parameters
|
||||
if (args.length < 2)
|
||||
{
|
||||
return ERROR_INVALID_NUMBER_OF_PARAMS;
|
||||
}
|
||||
|
||||
iNew = -1;
|
||||
for (iOld = 0; iOld < argsOld.length; iOld++)
|
||||
{
|
||||
if (0 <= argsOld[iOld].indexOf("="))
|
||||
{
|
||||
iNew++;
|
||||
args[iNew] = argsOld[iOld];
|
||||
for (i = iOld + 1; i < argsOld.length && (-1 == argsOld[i].indexOf("=")); i++)
|
||||
{
|
||||
args[iNew] += " " + argsOld[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log("New arg count " + args.length);
|
||||
for (i = 0; i < args.length; i++)
|
||||
{
|
||||
if (null == args[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
log("arg[" + i + "] = " +args[i]);
|
||||
|
||||
// is this the install dir param?
|
||||
if (args[i].startsWith(INSTALL_DIR))
|
||||
{
|
||||
// Make sure it is more the the param tag
|
||||
if (args[i].length() <= INSTALL_DIR.length())
|
||||
{
|
||||
return ERROR_BAD_INSTALL_DIR_PARAM;
|
||||
}
|
||||
|
||||
sInstallDir = args[i].substring(INSTALL_DIR.length()).trim();
|
||||
fileInstallDir = new File(sInstallDir);
|
||||
|
||||
// Make sure the install dir can be found
|
||||
if (!fileInstallDir.exists())
|
||||
{
|
||||
return ERROR_MISSING_INSTALL_DIR;
|
||||
}
|
||||
|
||||
// Make sure the install dir is a directory
|
||||
if (!fileInstallDir.isDirectory())
|
||||
{
|
||||
return ERROR_INSTALL_DIR_NOT_A_DIR;
|
||||
}
|
||||
|
||||
properties.setProperty(INSTALL_DIR_PROPERTY, sInstallDir);
|
||||
}
|
||||
|
||||
// is this the properties file param?
|
||||
else if (args[i].startsWith(PROPERTY_FILE_PARAM))
|
||||
{
|
||||
// Make sure it is more than the param tag
|
||||
if (args[i].length() <= PROPERTY_FILE_PARAM.length())
|
||||
{
|
||||
return ERROR_BAD_PROPERTY_FILE_PARAM;
|
||||
}
|
||||
|
||||
sProperties = args[i].substring(PROPERTY_FILE_PARAM.length()).trim();
|
||||
fileProperties = new File(sProperties);
|
||||
|
||||
// Make sure the properties file can be found
|
||||
if (!fileProperties.exists())
|
||||
{
|
||||
return ERROR_MISSING_PROPERTIES_FILE;
|
||||
}
|
||||
|
||||
// Read the properties
|
||||
try
|
||||
{
|
||||
fisProperties = new FileInputStream(fileProperties);
|
||||
properties.load(fisProperties);
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
return ERROR_UNABLE_TO_READ_PROPERTIES;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle additional parameters
|
||||
else
|
||||
{
|
||||
if (-1 == (iEquals = args[i].indexOf("=")) ||
|
||||
0 == iEquals ||
|
||||
args[i].length() == iEquals)
|
||||
{
|
||||
return ERROR_BAD_PROPERTY_PARAM;
|
||||
}
|
||||
sKey = args[i].substring(0, iEquals);
|
||||
sValue = args[i].substring(iEquals + 1);
|
||||
properties.setProperty(sKey, sValue);
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we got an install dir
|
||||
if (null == fileInstallDir)
|
||||
{
|
||||
return ERROR_MISSING_INSTALL_DIR_PARAM;
|
||||
}
|
||||
|
||||
// Note: the properties file parameter is optional
|
||||
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
int processProperties()
|
||||
{
|
||||
try
|
||||
{
|
||||
Enumeration e;
|
||||
String sKey;
|
||||
String sValue;
|
||||
|
||||
e = properties.propertyNames();
|
||||
|
||||
while (e.hasMoreElements())
|
||||
{
|
||||
sKey = (String)e.nextElement();
|
||||
sValue = (String)properties.get(sKey);
|
||||
|
||||
log("Property key = " + sKey + " Value = " + sValue);
|
||||
}
|
||||
}
|
||||
catch (Exception ex1)
|
||||
{
|
||||
return -111;
|
||||
}
|
||||
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
int shutdownService()
|
||||
{
|
||||
String sExe = (String)properties.get("TOMCAT5");
|
||||
String sCommand = "";
|
||||
int iReturn = ERROR_NO_ERROR;
|
||||
|
||||
sCommand = sExe + " //SS//CasaAuthTokenService";
|
||||
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
|
||||
{
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
sCommand = sExe + " //DS//CasaAuthTokenService";
|
||||
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
|
||||
{
|
||||
return iReturn;
|
||||
}
|
||||
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
int invokeCommand(String sCommand)
|
||||
{
|
||||
Process p;
|
||||
int rc;
|
||||
|
||||
log("invoke command: " + sCommand);
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
try
|
||||
{
|
||||
p = runtime.exec(sCommand);
|
||||
try
|
||||
{
|
||||
rc = p.waitFor();
|
||||
log("invoke command return code: " + rc);
|
||||
}
|
||||
catch (InterruptedException ie)
|
||||
{
|
||||
log(ERROR_EXEC_INTERRUPTED, sCommand);
|
||||
return ERROR_EXEC_INTERRUPTED;
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
log("IOException");
|
||||
return ERROR_EXEC_FAILED;
|
||||
}
|
||||
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void log(int err)
|
||||
{
|
||||
log(err, null);
|
||||
}
|
||||
|
||||
void log(int err, String s)
|
||||
{
|
||||
String sMessage = "";
|
||||
|
||||
switch (err)
|
||||
{
|
||||
case ERROR_NO_ERROR:
|
||||
sMessage = "No error";
|
||||
break;
|
||||
case ERROR_INVALID_NUMBER_OF_PARAMS:
|
||||
sMessage = "Invalid number of parameters: 4 expected";
|
||||
break;
|
||||
case ERROR_IO_EXCEPTION:
|
||||
sMessage = "IOException";
|
||||
break;
|
||||
case ERROR_EXEC_FAILED:
|
||||
sMessage = "Exec failed";
|
||||
break;
|
||||
case ERROR_EXEC_INTERRUPTED:
|
||||
sMessage = "Exec interrupted";
|
||||
break;
|
||||
case ERROR_UNABLE_TO_READ_PROPERTIES:
|
||||
sMessage = "nable to read properties";
|
||||
break;
|
||||
case ERROR_MISSING_INSTALL_DIR:
|
||||
sMessage = "Missing install directory";
|
||||
break;
|
||||
case ERROR_INSTALL_DIR_NOT_A_DIR:
|
||||
sMessage = "Install directory is not a directory";
|
||||
break;
|
||||
case ERROR_BAD_INSTALL_DIR_PARAM:
|
||||
sMessage = "Bad install directory parameter";
|
||||
break;
|
||||
case ERROR_BAD_PROPERTY_FILE_PARAM:
|
||||
sMessage = "Bad property file parameter";
|
||||
break;
|
||||
case ERROR_MISSING_PROPERTIES_FILE:
|
||||
sMessage = "Missing properties file";
|
||||
break;
|
||||
case ERROR_MISSING_INSTALL_DIR_PARAM:
|
||||
sMessage = "Missing install directory parameter";
|
||||
break;
|
||||
case ERROR_MISSING_PROPERTY_FILE_PARAM:
|
||||
sMessage = "Missing property file parameter";
|
||||
break;
|
||||
case ERROR_BAD_PROPERTY_PARAM:
|
||||
sMessage = "Bad property parameter";
|
||||
break;
|
||||
case ERROR_EXCEPTION:
|
||||
sMessage = "Exception";
|
||||
break;
|
||||
default:
|
||||
sMessage = "Unknown error: " + err;
|
||||
break;
|
||||
}
|
||||
|
||||
if (null != s)
|
||||
{
|
||||
sMessage = sMessage + s;
|
||||
}
|
||||
log(sMessage);
|
||||
}
|
||||
|
||||
void log(String s)
|
||||
{
|
||||
/*
|
||||
try
|
||||
{
|
||||
fw.write(this.getClass().getName() + ": " + s + "\r\n");
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
#######################################################################
|
||||
#
|
||||
# Copyright (C) 2004 Novell, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# Author: Greg Richardson <grichardson@novell.com>
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
DIST_SUBDIRS =
|
||||
|
||||
EXTRA_DIST = UpdateWarFile.java
|
||||
|
||||
if DEBUG
|
||||
TARGET_CFG = Debug
|
||||
DEBUG = -g
|
||||
else
|
||||
TARGET_CFG = Release
|
||||
DEBUG = -g:none
|
||||
endif
|
||||
|
||||
PACKAGE = UpdateWarFile
|
||||
TARGET_FILE = $(PACKAGE).class
|
||||
LOG_FILE = $(PACKAGE).log
|
||||
JAVAFILES = UpdateWarFile.java
|
||||
BUILDDIR = bin/$(TARGET_CFG)
|
||||
CLASSES = $(addprefix $(BUILDDIR)/, $(JAVAFILES:%.java=%.class))
|
||||
|
||||
.PHONY: package package-clean package-install package-uninstall
|
||||
|
||||
all: $(BUILDDIR) $(CLASSES)
|
||||
|
||||
$(BUILDDIR)/%.class: %.java
|
||||
@rm -f $(LOG_FILE) $@
|
||||
@echo [======== Compiling $@ ========]
|
||||
@javac $(DEBUG) -d $(BUILDDIR) $< 2> $(LOG_FILE)
|
||||
@echo $$CMD; \
|
||||
if eval $$CMD; then \
|
||||
ls -l $(BUILDDIR)/$(TARGET_FILE); \
|
||||
cp $(BUILDDIR)/$(TARGET_FILE) bin; \
|
||||
else \
|
||||
grep -a "ERROR:" $(LOG_FILE); \
|
||||
fi
|
||||
|
||||
$(BUILDDIR):
|
||||
[ -d $(BUILDDIR) ] || mkdir -p $(BUILDDIR)
|
||||
|
||||
|
||||
package-clean clean-local:
|
||||
rm -rf bin/Release/* bin/Release bin/Debug/* bin/Debug bin/* bin *.log
|
||||
|
||||
clean:
|
||||
rm -rf bin/Release/* bin/Release bin/Debug/* bin/Debug bin/* bin *.log
|
||||
|
||||
distclean-local: package-clean
|
||||
rm -f Makefile
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -f Makefile.in
|
||||
|
||||
|
||||
|
@ -1,444 +0,0 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright (C) 2006 Novell, Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, Novell, Inc.
|
||||
*
|
||||
* To contact Novell about this file by physical or electronic mail,
|
||||
* you may find current contact information at www.novell.com.
|
||||
*
|
||||
* Author: Greg Richardson <grichardson@novell.com>
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
import java.lang.Throwable;
|
||||
import java.lang.NullPointerException;
|
||||
import java.util.*;
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import java.util.zip.*;
|
||||
import java.util.jar.*;
|
||||
|
||||
/**
|
||||
* Summary description for UpdateWarFile
|
||||
*/
|
||||
public class UpdateWarFile
|
||||
{
|
||||
final static String INSTALL_DIR_PARAM = "ATS_INSTALL_DIR=";
|
||||
|
||||
final static int ERROR_NO_ERROR = 0;
|
||||
final static int ERROR_IO_EXCEPTION = -1;
|
||||
final static int ERROR_INVALID_NUMBER_OF_PARAMS = -2;
|
||||
final static int ERROR_BAD_INSTALL_DIR_PARAM = -3;
|
||||
final static int ERROR_MISSING_INSTALL_DIR = -4;
|
||||
final static int ERROR_INSTALL_DIR_NOT_A_DIR = -5;
|
||||
final static int ERROR_MISSING_INSTALL_DIR_PARAM = -6;
|
||||
final static int ERROR_WAR_TEMPLATE_FILE_MISSING = -7;
|
||||
final static int ERROR_NEW_JAR_CANNOT_BE_REPLACED = -8;
|
||||
final static int ERROR_JAR_COPY_FAILED = -9;
|
||||
final static int ERROR_CREATE_WAR_FILE_FAILED = -10;
|
||||
final static int ERROR_CREATE_WAR_FOS_FAILED = -11;
|
||||
final static int ERROR_OPEN_JAR_TEMPLATE_FAILED = -12;
|
||||
final static int ERROR_JOS_FLUSH_FAILED = -13;
|
||||
final static int ERROR_ADD_FILE_TO_JAR_FAILED = -14;
|
||||
final static int ERROR_JOS_CLOSE_FAILED = -15;
|
||||
final static int ERROR_FOS_CLOSE_FAILED = -16;
|
||||
final static int ERROR_JFTEMPLATE_CLOSE_FAILED = -17;
|
||||
final static int ERROR_EXCEPTION = -18;
|
||||
|
||||
String sInstallDir;
|
||||
//File file;
|
||||
//FileWriter fw;
|
||||
int rc;
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
UpdateWarFile p = new UpdateWarFile(args);
|
||||
System.exit(p.rc);
|
||||
}
|
||||
|
||||
UpdateWarFile(String[] args)
|
||||
{
|
||||
sInstallDir = null;
|
||||
|
||||
try
|
||||
{
|
||||
//file = new File("c:\\test3.log");
|
||||
//fw = new FileWriter(file);
|
||||
|
||||
log("Here we go: " + args.length);
|
||||
for (int i = 0; i < args.length; i++)
|
||||
{
|
||||
log("Arg " + i + " = " + args[i]);
|
||||
}
|
||||
|
||||
// Process the arguments
|
||||
if (ERROR_NO_ERROR == (rc = processArgs(args)))
|
||||
{
|
||||
// Create the modified war file
|
||||
rc = createWarFile();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
rc = ERROR_EXCEPTION;
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
log(rc);
|
||||
//fw.flush();
|
||||
//fw.close();
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int processArgs(String[] argsOld)
|
||||
{
|
||||
File fileInstallDir = null;
|
||||
int iOld;
|
||||
int i;
|
||||
String args[] = new String[argsOld.length];
|
||||
int iNew;
|
||||
|
||||
log("Original arg count " + argsOld.length);
|
||||
for (i = 0; i < argsOld.length; i++)
|
||||
{
|
||||
log("Arg " + i + " = " + argsOld[i] + "\r\n");
|
||||
}
|
||||
|
||||
// Validate the number of parameters
|
||||
if (args.length < 1)
|
||||
{
|
||||
return ERROR_INVALID_NUMBER_OF_PARAMS;
|
||||
}
|
||||
|
||||
iNew = -1;
|
||||
for (iOld = 0; iOld < argsOld.length; iOld++)
|
||||
{
|
||||
if (0 <= argsOld[iOld].indexOf("="))
|
||||
{
|
||||
iNew++;
|
||||
args[iNew] = argsOld[iOld];
|
||||
for (i = iOld + 1; i < argsOld.length && (-1 == argsOld[i].indexOf("=")); i++)
|
||||
{
|
||||
args[iNew] += " " + argsOld[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log("New arg count " + args.length);
|
||||
for (i = 0; i < args.length; i++)
|
||||
{
|
||||
log("arg[" + i + "] = " + args[i]);
|
||||
|
||||
// is this the install dir param?
|
||||
if (args[i].startsWith(INSTALL_DIR_PARAM))
|
||||
{
|
||||
// Make sure it is more than the param tag
|
||||
if (args[i].length() <= INSTALL_DIR_PARAM.length())
|
||||
{
|
||||
return ERROR_BAD_INSTALL_DIR_PARAM;
|
||||
}
|
||||
|
||||
sInstallDir = args[i].substring(INSTALL_DIR_PARAM.length()).trim();
|
||||
fileInstallDir = new File(sInstallDir);
|
||||
|
||||
// Make sure the install dir can be found
|
||||
if (!fileInstallDir.exists())
|
||||
{
|
||||
return ERROR_MISSING_INSTALL_DIR;
|
||||
}
|
||||
|
||||
// Make sure the install dir is a directory
|
||||
if (!fileInstallDir.isDirectory())
|
||||
{
|
||||
return ERROR_INSTALL_DIR_NOT_A_DIR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we got an install dir
|
||||
if (null == fileInstallDir)
|
||||
{
|
||||
return ERROR_MISSING_INSTALL_DIR_PARAM;
|
||||
}
|
||||
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
int createWarFile()
|
||||
{
|
||||
String sWarTemplate = sInstallDir + "ats\\etc\\svc\\templates\\CasaAuthTokenSvc.war";
|
||||
String sWarNew = sInstallDir + "ats\\catalinabase\\webapps\\CasaAuthTokenSvc.war";
|
||||
File fileWarTemplate = new File(sWarTemplate);;
|
||||
File fileWarNew = new File(sWarNew);
|
||||
FileOutputStream fosWarNew = null;
|
||||
ZipOutputStream josWarNew = null;
|
||||
ZipFile jfTemplate = null;
|
||||
int rc = ERROR_NO_ERROR;
|
||||
|
||||
// Ensure that the war template exists
|
||||
log("looking for war template: " + sWarTemplate);
|
||||
if (!fileWarTemplate.exists())
|
||||
{
|
||||
rc = ERROR_WAR_TEMPLATE_FILE_MISSING;
|
||||
}
|
||||
|
||||
if (rc == ERROR_NO_ERROR)
|
||||
{
|
||||
// Ensure that the new jar name does not exist
|
||||
if (fileWarNew.exists())
|
||||
{
|
||||
log("war file already exists: " + sWarNew);
|
||||
if (!fileWarNew.delete())
|
||||
{
|
||||
log("could not delete war file: " + sWarNew);
|
||||
rc = ERROR_NEW_JAR_CANNOT_BE_REPLACED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rc == ERROR_NO_ERROR)
|
||||
{
|
||||
// Create/open the new jar
|
||||
try
|
||||
{
|
||||
log("create new war file output stream: " + sWarNew);
|
||||
fosWarNew = new FileOutputStream(fileWarNew);
|
||||
josWarNew = new ZipOutputStream(fosWarNew);
|
||||
}
|
||||
catch (IOException ioe0)
|
||||
{
|
||||
log(ioe0.toString());
|
||||
rc = ERROR_CREATE_WAR_FOS_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
if (rc == ERROR_NO_ERROR)
|
||||
{
|
||||
// Open the old jar
|
||||
try
|
||||
{
|
||||
jfTemplate = new ZipFile(sWarTemplate);
|
||||
}
|
||||
catch (IOException ioe1)
|
||||
{
|
||||
rc = ERROR_OPEN_JAR_TEMPLATE_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
if (rc == ERROR_NO_ERROR)
|
||||
{
|
||||
// Transfer the files
|
||||
rc = moveFilesFromJarToJar(josWarNew, jfTemplate);
|
||||
}
|
||||
|
||||
// Add the files
|
||||
if (rc == ERROR_NO_ERROR)
|
||||
{
|
||||
int i;
|
||||
String [] rgsFilesToAdd = new String[1];
|
||||
rgsFilesToAdd[0] = sInstallDir + "ats\\etc\\svc\\templates\\casa_crypto.properties";
|
||||
String [] rgsNames = new String[1];
|
||||
rgsNames[0] = "WEB-INF/classes/casa_crypto.properties";
|
||||
for (i = 0; i < rgsFilesToAdd.length; i++)
|
||||
{
|
||||
log("Adding file: " + rgsFilesToAdd[i] + " with name " + rgsNames[i]);
|
||||
rc = addFileToJar(rgsFilesToAdd[i], rgsNames[i], josWarNew);
|
||||
}
|
||||
}
|
||||
|
||||
// Close up
|
||||
if (null != josWarNew)
|
||||
{
|
||||
try
|
||||
{
|
||||
josWarNew.flush();
|
||||
}
|
||||
catch (IOException ioe2)
|
||||
{
|
||||
rc = ERROR_JOS_FLUSH_FAILED;
|
||||
}
|
||||
try
|
||||
{
|
||||
josWarNew.close();
|
||||
}
|
||||
catch (IOException ioe3)
|
||||
{
|
||||
rc = ERROR_JOS_CLOSE_FAILED;
|
||||
}
|
||||
try
|
||||
{
|
||||
fosWarNew.close();
|
||||
}
|
||||
catch (IOException ioe4)
|
||||
{
|
||||
rc = ERROR_FOS_CLOSE_FAILED;
|
||||
}
|
||||
}
|
||||
if (null != jfTemplate)
|
||||
{
|
||||
try
|
||||
{
|
||||
jfTemplate.close();
|
||||
}
|
||||
catch (IOException ioe5)
|
||||
{
|
||||
rc = ERROR_JFTEMPLATE_CLOSE_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int moveFilesFromJarToJar(ZipOutputStream josDst, ZipFile jfSrc)
|
||||
{
|
||||
int rc = ERROR_NO_ERROR;
|
||||
try
|
||||
{
|
||||
Enumeration entries = jfSrc.entries();
|
||||
ZipEntry jeLoop;
|
||||
InputStream isLoop;
|
||||
ZipEntry zeIndex;
|
||||
int bRead;
|
||||
byte [] b = new byte[4096];
|
||||
|
||||
while (entries.hasMoreElements())
|
||||
{
|
||||
jeLoop = (ZipEntry)entries.nextElement();
|
||||
|
||||
// Skip WEB-INF/classes/cypto.properties
|
||||
if (jeLoop.getName().equalsIgnoreCase("WEB-INF/classes/casa_crypto.properties"))
|
||||
{
|
||||
log("skipping: " + "WEB-INF/classes/casa_crypto.properties");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Move the rest of the files over
|
||||
else
|
||||
{
|
||||
log("Transferring jar file: " + jeLoop.getName());
|
||||
|
||||
// Create the input stream
|
||||
isLoop = jfSrc.getInputStream(jeLoop);
|
||||
|
||||
// Set up the output stream
|
||||
zeIndex = new ZipEntry(jeLoop.getName());
|
||||
josDst.putNextEntry( zeIndex);
|
||||
|
||||
// Transfer the file contents
|
||||
while (-1 != (bRead = isLoop.read(b)))
|
||||
{
|
||||
josDst.write(b, 0, bRead);
|
||||
}
|
||||
|
||||
// all done
|
||||
josDst.closeEntry();
|
||||
isLoop.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
rc = ERROR_JAR_COPY_FAILED;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
int addFileToJar(String sFilename, String sName, ZipOutputStream josJarNew)
|
||||
{
|
||||
FileInputStream fis;
|
||||
ZipEntry je;
|
||||
int bRead;
|
||||
byte [] b = new byte[4096];
|
||||
int rc = ERROR_NO_ERROR;
|
||||
|
||||
try
|
||||
{
|
||||
// Create the input stream
|
||||
fis = new FileInputStream(sFilename);
|
||||
|
||||
// Set up the output stream
|
||||
je = new ZipEntry(sName);
|
||||
josJarNew.putNextEntry(je);
|
||||
|
||||
// Tansfer the contents of the file
|
||||
while (-1 != (bRead = fis.read(b)))
|
||||
{
|
||||
josJarNew.write(b, 0, bRead);
|
||||
}
|
||||
|
||||
// All done
|
||||
fis.close();
|
||||
josJarNew.closeEntry();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log(e.toString());
|
||||
rc = ERROR_ADD_FILE_TO_JAR_FAILED;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
void log(int err)
|
||||
{
|
||||
log(err, null);
|
||||
}
|
||||
|
||||
void log(int err, String s)
|
||||
{
|
||||
String sMessage = "";
|
||||
|
||||
switch (err)
|
||||
{
|
||||
case ERROR_NO_ERROR:
|
||||
sMessage = "No error";
|
||||
break;
|
||||
case ERROR_INVALID_NUMBER_OF_PARAMS:
|
||||
sMessage = "Invalid number of parameters: 1make expected";
|
||||
break;
|
||||
case ERROR_EXCEPTION:
|
||||
sMessage = "Exception";
|
||||
break;
|
||||
default:
|
||||
sMessage = "Unknown error: " + err;
|
||||
break;
|
||||
}
|
||||
|
||||
if (null != s)
|
||||
{
|
||||
sMessage = sMessage + s;
|
||||
}
|
||||
log(sMessage);
|
||||
}
|
||||
|
||||
void log(String s)
|
||||
{
|
||||
/*
|
||||
try
|
||||
{
|
||||
fw.write(this.getClass().getName() + ": " + s + "\r\n");
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 9.00
|
||||
# Visual Studio 2005
|
||||
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "server-java_msi", "server-java_msi.vdproj", "{124289E1-BD76-485B-A779-C2372332D538}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CommandLauncher", "..\CommandLauncher\CommandLauncher.vcproj", "{B52EF84A-D745-4637-9F59-DBD6E21C179C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Mixed Platforms = Debug|Mixed Platforms
|
||||
@ -27,16 +25,6 @@ Global
|
||||
{124289E1-BD76-485B-A779-C2372332D538}.Release|Win32.Build.0 = Release
|
||||
{124289E1-BD76-485B-A779-C2372332D538}.Release|x86.ActiveCfg = Release
|
||||
{124289E1-BD76-485B-A779-C2372332D538}.Release|x86.Build.0 = Release
|
||||
{B52EF84A-D745-4637-9F59-DBD6E21C179C}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
|
||||
{B52EF84A-D745-4637-9F59-DBD6E21C179C}.Debug|Mixed Platforms.Build.0 = Debug|Win32
|
||||
{B52EF84A-D745-4637-9F59-DBD6E21C179C}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{B52EF84A-D745-4637-9F59-DBD6E21C179C}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{B52EF84A-D745-4637-9F59-DBD6E21C179C}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{B52EF84A-D745-4637-9F59-DBD6E21C179C}.Release|Mixed Platforms.ActiveCfg = Release|Win32
|
||||
{B52EF84A-D745-4637-9F59-DBD6E21C179C}.Release|Mixed Platforms.Build.0 = Release|Win32
|
||||
{B52EF84A-D745-4637-9F59-DBD6E21C179C}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{B52EF84A-D745-4637-9F59-DBD6E21C179C}.Release|Win32.Build.0 = Release|Win32
|
||||
{B52EF84A-D745-4637-9F59-DBD6E21C179C}.Release|x86.ActiveCfg = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user