More changes for the removal of the Axis dependencies.

Removed the log files created by the Windows INSTALL.

Corrected the "Author" for files created by Greg.

Tuned the ATS logs to be less chatty and have a greater backlog.

Updated the NOTICES file and added READMEs to provide information
about external packages included in the project.
This commit is contained in:
Juan Carlos Luciani
2007-03-17 06:39:46 +00:00
parent 33a49c686a
commit 7a44908936
26 changed files with 2650 additions and 2904 deletions

View File

@@ -18,7 +18,7 @@
* 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>
* Author: Greg Richardson <grichardson@novell.com>
*
***********************************************************************/
@@ -27,376 +27,378 @@ 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_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 String INSTALL_DIR = "installdir=";
final static String PROPERTY_FILE = "propertyfile=";
final static String INSTALL_DIR = "installdir=";
final static String PROPERTY_FILE = "propertyfile=";
String sInstallDir;
Properties properties;
int rc;
String sInstallDir;
Properties properties;
int rc;
// debug stuff
File file;
FileWriter fw;
// debug stuff
//File file;
//FileWriter fw;
public static void main(String[] args)
{
ClientKeystoreSetup p = new ClientKeystoreSetup(args);
System.exit(p.rc);
}
public static void main(String[] args)
{
ClientKeystoreSetup p = new ClientKeystoreSetup(args);
System.exit(p.rc);
}
ClientKeystoreSetup(String[] args)
{
rc = ERROR_NO_ERROR;
ClientKeystoreSetup(String[] args)
{
rc = ERROR_NO_ERROR;
try
{
// DEBUG STUFF
file = new File("c:\\test4.log");
fw = new FileWriter(file);
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
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();
}
}
// 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 (IOException e)
{
rc = ERROR_IO_EXCEPTION;
}
}
// DEBUG STUFF
log(rc);
//fw.flush();
//fw.close();
// DEBUG STUFF
}
catch (IOException e)
{
rc = ERROR_IO_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;
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");
}
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;
}
// 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];
}
}
}
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");
}
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;
}
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);
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 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 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;
}
// 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);
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;
}
// 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;
}
}
// 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;
}
}
// 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;
}
// Make sure we got an install dir
if (null == fileInstallDir)
{
return ERROR_MISSING_INSTALL_DIR_PARAM;
}
return ERROR_NO_ERROR;
}
return ERROR_NO_ERROR;
}
int findRequiredValues()
{
String[] rgsRequired = {
"ATS_JAVA_HOME"};
int i;
String sValue;
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]);
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;
}
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";
int createClientKeystore()
{
int rc;
String sKeytool = properties.get("ATS_JAVA_HOME") + "\\bin\\keytool.exe";
log("keytool = " + sKeytool);
log("keytool = " + sKeytool);
// Do not do anything if the server keystore has already been created
if (keyStoreAlreadyExists())
{
return ERROR_NO_ERROR;
}
// 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");
// 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;
}
return rc;
}
boolean keyStoreAlreadyExists()
{
File fileKeystore = new File(sInstallDir + "ats\\etc\\keys\\client\\jks-store");
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());
// 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;
}
}
}
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;
}
return false;
}
int invokeCommand(String sCommand)
{
Process p;
int rc;
int invokeCommand(String sCommand)
{
Process p;
int rc;
log("invoke command: " + sCommand);
Runtime runtime = Runtime.getRuntime();
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;
}
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;
}
return ERROR_NO_ERROR;
}
void log(int err)
{
log(err, null);
}
void log(int err)
{
log(err, null);
}
void log(int err, String s)
{
String sMessage = "";
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;
default:
sMessage = "Unknown error";
break;
}
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;
default:
sMessage = "Unknown error";
break;
}
if (null != s)
{
sMessage = sMessage + s;
}
log(sMessage);
}
if (null != s)
{
sMessage = sMessage + s;
}
log(sMessage);
}
void log(String s)
{
try
{
fw.write(this.getClass().getName() + ": " + s + "\r\n");
}
catch (IOException ioe)
{
}
}
void log(String s)
{
/*
try
{
fw.write(this.getClass().getName() + ": " + s + "\r\n");
}
catch (IOException ioe)
{
}
*/
}
}

View File

@@ -1,3 +1,28 @@
/***********************************************************************
*
* 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.
//
@@ -11,8 +36,8 @@
#include <errno.h>
WCHAR ** G_rgArgs; // Command line arguments
int G_cArg; // Count of command line arguments
FILE * G_pf;
int G_cArg; // Count of command line arguments
//FILE * G_pf;
// Forward declarations of functions included in this code module:
int processArguments(LPTSTR lpCmdLine);
@@ -24,476 +49,478 @@ _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
#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)
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hInstance);
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(nCmdShow);
UNREFERENCED_PARAMETER(hInstance);
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(nCmdShow);
int rc;
int rc;
_wfopen_s(&G_pf, L"C:\\CommandLauncher.log", L"a+");
//_wfopen_s(&G_pf, L"C:\\CommandLauncher.log", L"a+");
// Process the command line
if (ERROR_NO_ERROR != (rc = processArguments(lpCmdLine)))
{
return rc;
}
// Process the command line
if (ERROR_NO_ERROR != (rc = processArguments(lpCmdLine)))
{
return rc;
}
rc = executeCommand(G_cArg, G_rgArgs);
rc = executeCommand(G_cArg, G_rgArgs);
log(errorMessage(rc));
log(errorMessage(rc));
fwprintf(G_pf, L"CommandLauncher: return = %d\n", rc);
//fwprintf(G_pf, L"CommandLauncher: return = %d\n", rc);
fclose(G_pf);
//fclose(G_pf);
return rc;
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;
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);
//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;
}
// 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);
// 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;
}
// 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;
}
// 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 *));
// 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;
}
// 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;
}
// 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 the java.exe argument
iChar += 4;
// Move past any spaces
for (;L' ' == lpCmdLine[iChar]; iChar++)
{
// Intentionally left blank
}
// 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;
}
// 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;
}
// 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 the classpath option argument
iChar += 3;
// Move past any spaces
for (;L' ' == lpCmdLine[iChar]; iChar++)
{
// Intentionally left blank
}
// 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;
// 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
}
// 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;
// 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
}
}
// 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--;
}
else
{
iAssignment = 0;
iChar--;
}
// Move past any spaces (moving toward the start of the line)
for (;L' ' == lpCmdLine[iChar]; iChar--)
{
// Intentionally left blank
}
// 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;
// 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
}
// Move to the previous space (moving toward the start of the line)
for (;L' ' != lpCmdLine[iChar]; iChar--)
{
// Intentionally left blank
}
iClassStart = iChar + 1;
iClassStart = iChar + 1;
// Add the class argument
if (ERROR_NO_ERROR != (rc = addArg(3, lpCmdLine + iClassStart, iClassEnd - iClassStart + 1)))
{
goto ErrorOut;
}
// 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
}
// 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;
// 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;
}
// 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;
// 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++;
}
// 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
}
// 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;
// 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
}
}
// 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--;
}
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
}
// 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;
}
// 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++;
}
}
// Go on to the next arg
iArg++;
}
}
return ERROR_NO_ERROR;
return ERROR_NO_ERROR;
ErrorOut:
freeArgs();
log(errorMessage(rc));
return rc;
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 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;
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;
// 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
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;
}
// 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);
// Null out the argument
memset(G_rgArgs[iArg], 0, cb);
// Add a starting quote
// G_rgArgs[iArg][0] = L'\"';
// 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;
}
// 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'\"';
// Add a terminating quote
// G_rgArgs[iArg][cb-1] = L'\"';
return ERROR_NO_ERROR;
return ERROR_NO_ERROR;
}
void log(LPTSTR szMessage)
{
LPTSTR szT = L"";
if (NULL == szMessage)
szMessage = szT;
fwprintf(G_pf, L"JavaLauncher: %s\n", 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";
}
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
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]);
}
//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;
// 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 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 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 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 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;
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;
}
}
default:
rc = ERROR_EXEC_UNKNOWN;
break;
}
}
fwprintf(G_pf, L"ExecuteCommand returning %d\n", rc);
return rc;
//fwprintf(G_pf, L"ExecuteCommand returning %d\n", rc);
return rc;
}

View File

@@ -18,7 +18,7 @@
* 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>
* Author: Greg Richardson <grichardson@novell.com>
*
***********************************************************************/
@@ -30,347 +30,349 @@ import java.util.*;
*/
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_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 String FILE_KEY = "file=";
final static String FILTER_KEY = "filter=";
final static String FILE_KEY = "file=";
final static String FILTER_KEY = "filter=";
RandomAccessFile raf;
int rc;
String sFile;
String sFilter;
//RandomAccessFile raf;
int rc;
String sFile;
String sFilter;
public static void main(String[] args)
{
DeleteFile p = new DeleteFile(args);
System.exit(p.rc);
}
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;
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());
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();
}
// Process the arguments
if (ERROR_NO_ERROR == (rc = processArgs(args)))
{
rc = doDelete();
}
}
catch (IOException e)
{
rc = ERROR_IO_EXCEPTION;
}
finally
{
try
{
log(rc);
raf.close();
}
catch (Exception e1)
{
}
}
}
}
catch (IOException e)
{
rc = ERROR_IO_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;
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");
}
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;
}
// 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];
}
}
}
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("New arg count " + args.length);
for (i = 0; i < args.length; i++)
{
if (null == args[i])
{
continue;
}
log("arg[" + i + "] = " +args[i]);
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;
}
// 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;
}
// 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();
}
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;
}
// 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;
}
// 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();
}
sFilter = args[i].substring(FILTER_KEY.length()).trim();
}
// Handle additional parameters
else
{
return ERROR_UNKNOWN_PARAMETER;
}
}
// Handle additional parameters
else
{
return ERROR_UNKNOWN_PARAMETER;
}
}
// Make sure we got a file
if (null == sFile)
{
return ERROR_MISSING_FILE_PARAM;
}
// 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
// Note: the filter parameter is optional, if present the file is assumed to be a directory
return ERROR_NO_ERROR;
}
return ERROR_NO_ERROR;
}
int doDelete()
{
File file = new File(sFile);
int doDelete()
{
File file = new File(sFile);
log("Attempt to delete: " + 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 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");
// 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 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);
// 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);
}
}
// Attempt to delete the directory
deleteDirectory(file);
}
}
else
{
if (!file.isDirectory())
{
log("Delete file: " + sFile);
file.delete();
}
else
{
if (!file.isDirectory())
{
log("Delete file: " + sFile);
file.delete();
}
else
{
deleteDirectory(file);
}
}
else
{
deleteDirectory(file);
}
}
return ERROR_NO_ERROR;
}
return ERROR_NO_ERROR;
}
void deleteFiles(File file)
{
File fileDelete;
int i;
void deleteFiles(File file)
{
File fileDelete;
int i;
log("attempting to delete file");
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));
}
});
// 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);
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();
}
}
}
// 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;
void deleteDirectory(File file)
{
File fileDelete;
int i;
log("Delete directory: " + file.getAbsolutePath());
log("Delete directory: " + file.getAbsolutePath());
// Get the children of this directory
File[] rgFile = file.listFiles();
// Get the children of this directory
File[] rgFile = file.listFiles();
log(file.getAbsolutePath() + " has " + rgFile.length + " children");
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 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();
}
}
// 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)
{
log(err, null);
}
void log(int err, String s)
{
String sMessage = "";
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;
default:
sMessage = "Unknown error: " + err;
break;
}
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;
default:
sMessage = "Unknown error: " + err;
break;
}
if (null != s)
{
sMessage = sMessage + s;
}
log(sMessage);
}
if (null != s)
{
sMessage = sMessage + s;
}
log(sMessage);
}
void log(String s)
{
try
{
raf.writeUTF(this.getClass().getName() + ": " + s + "\r\n");
}
catch (IOException ioe)
{
}
}
void log(String s)
{
/*
try
{
raf.writeUTF(this.getClass().getName() + ": " + s + "\r\n");
}
catch (IOException ioe)
{
}
*/
}
}

View File

@@ -18,7 +18,7 @@
* To contact Novell about this file by physical or electronic mail,
* you may find current contact information at www.novell.com.
*
* Author: Greg Richardson
* Author: Greg Richardson <grichardson@novell.com>
*
***********************************************************************/
@@ -68,9 +68,9 @@ public class InitConfigFile
FileInputStream fisProperties;
File fileTemplate;
File fileOutput;
File file;
//File file;
//FileWriter fw;
RandomAccessFile raf;
//RandomAccessFile raf;
String[] rgsSearchFor;
String[] rgsReplaceWith;
String sInstallDir;
@@ -88,31 +88,30 @@ public class InitConfigFile
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");
//file = new File("c:\\test.log");
//fw = new FileWriter(file);
raf = new RandomAccessFile(file, "rw");
raf.seek(raf.length());
//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();
}
// Process the properties
if (ERROR_NO_ERROR == (rc = processProperties()))
{
rc = createOutputFile();
}
}
}
catch (IOException e)
{
@@ -123,7 +122,7 @@ public class InitConfigFile
try
{
log(rc, " " + sOutput + "\n\n\n");
raf.close();
//raf.close();
}
catch (Exception e1)
{
@@ -142,19 +141,19 @@ public class InitConfigFile
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++)
{
@@ -168,7 +167,7 @@ public class InitConfigFile
}
}
}
log("New arg count " + args.length);
for (i = 0; i < args.length; i++)
{
@@ -176,9 +175,9 @@ public class InitConfigFile
{
continue;
}
log("arg[" + i + "] = " +args[i]);
// is this the install dir param?
if (args[i].startsWith(INSTALL_DIR_PARAM))
{
@@ -187,26 +186,26 @@ public class InitConfigFile
{
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))
{
@@ -215,16 +214,16 @@ public class InitConfigFile
{
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
{
@@ -236,7 +235,7 @@ public class InitConfigFile
return ERROR_UNABLE_TO_READ_PROPERTIES;
}
}
else if (args[i].startsWith(TEMPLATE_FILE_PARAM))
{
// Make sure it is more than the param tag
@@ -244,10 +243,10 @@ public class InitConfigFile
{
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())
{
@@ -255,7 +254,7 @@ public class InitConfigFile
return ERROR_MISSING_TEMPLATE_FILE;
}
}
else if (args[i].startsWith(OUTPUT_FILE_PARAM))
{
// Make sure it is more than the param tag
@@ -263,11 +262,11 @@ public class InitConfigFile
{
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
@@ -275,14 +274,14 @@ public class InitConfigFile
{
return ERROR_BAD_ESCAPE_PATH_CHARS_PARAM;
}
String value = args[i].substring(ESCAPE_PATH_CHARS.length()).trim();
if (value.equalsIgnoreCase("true"))
{
escapePathCharsInReplaceString = true;
escapePathCharsInReplaceString = true;
}
}
// Handle additional parameters
else
{
@@ -298,27 +297,27 @@ public class InitConfigFile
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;
}
@@ -330,20 +329,20 @@ public class InitConfigFile
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)
{
@@ -372,7 +371,7 @@ public class InitConfigFile
String sLineOutput;
int iSearchFor;
int i;
try
{
// Open the files
@@ -382,7 +381,7 @@ public class InitConfigFile
{
return ERROR_UNABLE_TO_OPEN_TEMPLATE;
}
try
{
fwOutput = new FileWriter(fileOutput);
@@ -398,7 +397,7 @@ public class InitConfigFile
{
sLineOutput = sLineTemplate;
log("<-- " + sLineOutput);
// For each term to be replaced...
for (i = 0; i < rgsSearchFor.length; i++)
{
@@ -408,7 +407,7 @@ public class InitConfigFile
{
log("replacing " + rgsSearchFor[i] + " at position " + iSearchFor + " with " + rgsReplaceWith[i]);
sLineOutput = sLineOutput.substring(0, iSearchFor) + rgsReplaceWith[i] +
sLineOutput.substring(iSearchFor + rgsSearchFor[i].length());
sLineOutput.substring(iSearchFor + rgsSearchFor[i].length());
}
}
try
@@ -421,7 +420,7 @@ public class InitConfigFile
return -42;
}
}
// Clean up
fwOutput.flush();
fwOutput.close();
@@ -531,6 +530,7 @@ public class InitConfigFile
void log(String s)
{
/*
try
{
raf.writeUTF(this.getClass().getName() + ": " + s + "\r\n");
@@ -538,5 +538,6 @@ public class InitConfigFile
catch (IOException ioe)
{
}
*/
}
}

View File

@@ -48,8 +48,8 @@ public class MungeCryptoPropertiesFilePath
File fileInput;
File fileOutput;
File file;
FileWriter fw;
//File file;
//FileWriter fw;
String sInput;
String sOutput;
int rc;
@@ -63,28 +63,27 @@ public class MungeCryptoPropertiesFilePath
MungeCryptoPropertiesFilePath(String[] args)
{
rc = ERROR_NO_ERROR;
fileInput = null;
fileOutput = null;
try
{
file = new File("c:\\test5.log");
fw = new FileWriter(file);
//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 (IOException e)
{
@@ -95,8 +94,8 @@ public class MungeCryptoPropertiesFilePath
try
{
log(rc);
fw.flush();
fw.close();
//fw.flush();
//fw.close();
}
catch (Exception e1)
{
@@ -110,19 +109,19 @@ public class MungeCryptoPropertiesFilePath
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++)
{
@@ -136,17 +135,17 @@ public class MungeCryptoPropertiesFilePath
}
}
}
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
@@ -154,10 +153,10 @@ public class MungeCryptoPropertiesFilePath
{
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())
{
@@ -165,7 +164,7 @@ public class MungeCryptoPropertiesFilePath
return ERROR_MISSING_INPUT_FILE;
}
}
else if (args[i].startsWith(OUTPUT_FILE_PARAM))
{
// Make sure it is more than the param tag
@@ -173,24 +172,24 @@ public class MungeCryptoPropertiesFilePath
{
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;
}
@@ -201,7 +200,7 @@ public class MungeCryptoPropertiesFilePath
String sLineTemplate;
String sLineOutput;
int iSearchFor;
try
{
// Open the file
@@ -211,7 +210,7 @@ public class MungeCryptoPropertiesFilePath
{
return ERROR_CANNOT_READ_FILE;
}
try
{
fwOutput = new FileWriter(fileOutput);
@@ -227,7 +226,7 @@ public class MungeCryptoPropertiesFilePath
{
sLineOutput = sLineTemplate;
log("<-- " + sLineOutput);
if (sLineOutput.trim().startsWith(FILE_KEY))
{
// Replace all instances of the line separator on the line
@@ -235,7 +234,7 @@ public class MungeCryptoPropertiesFilePath
{
log("replacing \\ at position " + iSearchFor + " with //");
sLineOutput = sLineOutput.substring(0, iSearchFor) + "//" +
sLineOutput.substring(iSearchFor + 1);
sLineOutput.substring(iSearchFor + 1);
}
}
try
@@ -248,7 +247,7 @@ public class MungeCryptoPropertiesFilePath
return -42;
}
}
// Clean up
fwOutput.flush();
fwOutput.close();
@@ -278,48 +277,38 @@ public class MungeCryptoPropertiesFilePath
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;
default:
sMessage = "Unknown error: " + err;
break;
}
if (null != s)
{
sMessage = sMessage + s;
@@ -329,6 +318,7 @@ public class MungeCryptoPropertiesFilePath
void log(String s)
{
/*
try
{
fw.write(this.getClass().getName() + ": " + s + "\r\n");
@@ -336,5 +326,6 @@ public class MungeCryptoPropertiesFilePath
catch (IOException ioe)
{
}
*/
}
}

View File

@@ -18,7 +18,7 @@
* 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>
* Author: Greg Richardson <grichardson@novell.com>
*
***********************************************************************/
@@ -27,382 +27,384 @@ 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_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 String INSTALL_DIR = "installdir=";
final static String PROPERTY_FILE = "propertyfile=";
final static String INSTALL_DIR = "installdir=";
final static String PROPERTY_FILE = "propertyfile=";
String sInstallDir;
Properties properties;
int rc;
String sInstallDir;
Properties properties;
int rc;
// debug stuff
File file;
FileWriter fw;
// debug stuff
//File file;
//FileWriter fw;
public static void main(String[] args)
{
ServerKeystoreSetup p = new ServerKeystoreSetup(args);
System.exit(p.rc);
}
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);
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();
}
}
// 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 (IOException e)
{
rc = ERROR_IO_EXCEPTION;
}
}
// DEBUG STUFF
log(rc);
//fw.flush();
//fw.close();
// DEBUG STUFF
}
catch (IOException e)
{
rc = ERROR_IO_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;
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");
}
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;
}
// 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];
}
}
}
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");
}
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;
}
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);
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 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 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;
}
// 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);
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;
}
// 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;
}
}
// 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;
}
}
// 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;
}
// Make sure we got an install dir
if (null == fileInstallDir)
{
return ERROR_MISSING_INSTALL_DIR_PARAM;
}
return ERROR_NO_ERROR;
}
return ERROR_NO_ERROR;
}
int findRequiredValues()
{
String[] rgsRequired = {
"ATS_JAVA_HOME",
"COMPUTERNAME"};
int i;
String sValue;
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]);
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;
}
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");
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);
log("keytool = " + sKeytool);
log("host = " + sHost);
// Do not do anything if the server keystore has already been created
if (keyStoreAlreadyExists())
{
return ERROR_NO_ERROR;
}
// 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;
}
// 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");
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());
// 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;
}
}
}
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;
}
return false;
}
int invokeCommand(String sCommand)
{
Process p;
int rc;
int invokeCommand(String sCommand)
{
Process p;
int rc;
log("invoke command: " + sCommand);
Runtime runtime = Runtime.getRuntime();
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;
}
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)
{
log(err, null);
}
void log(int err, String s)
{
String sMessage = "";
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;
default:
sMessage = "Unknown error";
break;
}
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;
default:
sMessage = "Unknown error";
break;
}
if (null != s)
{
sMessage = sMessage + s;
}
log(sMessage);
}
if (null != s)
{
sMessage = sMessage + s;
}
log(sMessage);
}
void log(String s)
{
try
{
fw.write(this.getClass().getName() + ": " + s + "\r\n");
}
catch (IOException ioe)
{
}
}
void log(String s)
{
/*
try
{
fw.write(this.getClass().getName() + ": " + s + "\r\n");
}
catch (IOException ioe)
{
}
*/
}
}

View File

@@ -18,7 +18,7 @@
* 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>
* Author: Greg Richardson <grichardson@novell.com>
*
***********************************************************************/
@@ -30,482 +30,484 @@ import java.util.*;
*/
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_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 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=";
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;
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);
}
public static void main(String[] args)
{
SetupAsWindowsService p = new SetupAsWindowsService(args);
System.exit(p.rc);
}
SetupAsWindowsService(String[] args)
{
rc = ERROR_NO_ERROR;
SetupAsWindowsService(String[] args)
{
rc = ERROR_NO_ERROR;
properties = new Properties();
fileProperties = null;
fisProperties = null;
fileOutput = null;
properties = new Properties();
fileProperties = null;
fisProperties = null;
fileOutput = null;
try
{
file = new File("c:\\test6.log");
fw = new FileWriter(file);
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();
}
}
// 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 (IOException e)
{
rc = ERROR_IO_EXCEPTION;
}
finally
{
try
{
log(rc);
fw.flush();
fw.close();
}
catch (Exception e1)
{
}
}
}
}
catch (IOException e)
{
rc = ERROR_IO_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;
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");
}
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;
}
// 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];
}
}
}
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("New arg count " + args.length);
for (i = 0; i < args.length; i++)
{
if (null == args[i])
{
continue;
}
log("arg[" + i + "] = " +args[i]);
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;
}
// 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);
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 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 the install dir is a directory
if (!fileInstallDir.isDirectory())
{
return ERROR_INSTALL_DIR_NOT_A_DIR;
}
properties.setProperty(INSTALL_DIR_PROPERTY, 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;
}
// 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);
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;
}
// 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;
}
}
// 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);
}
}
// 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;
}
// 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;
}
// Note: the properties file parameter is optional
return ERROR_NO_ERROR;
}
int processProperties()
{
try
{
Enumeration e;
String sKey;
String sValue;
int processProperties()
{
try
{
Enumeration e;
String sKey;
String sValue;
e = properties.propertyNames();
e = properties.propertyNames();
while (e.hasMoreElements())
{
sKey = (String)e.nextElement();
sValue = (String)properties.get(sKey);
while (e.hasMoreElements())
{
sKey = (String)e.nextElement();
sValue = (String)properties.get(sKey);
log("Property key = " + sKey + " Value = " + sValue);
}
}
catch (Exception ex1)
{
return -111;
}
log("Property key = " + sKey + " Value = " + sValue);
}
}
catch (Exception ex1)
{
return -111;
}
return ERROR_NO_ERROR;
}
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;
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 + " //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 --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.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 \"-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.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 \"-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 \"-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 \"-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 ++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 --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 --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 --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 --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 --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 --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 --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 --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 --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;
}
sCommand = sExe + " //US//CasaAuthTokenService --Description " + "\"Casa Authentication Token Service\"";
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
{
return iReturn;
}
return ERROR_NO_ERROR;
}
return ERROR_NO_ERROR;
}
int invokeCommand(String sCommand)
{
Process p;
int rc;
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;
}
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;
}
return ERROR_NO_ERROR;
}
void log(int err)
{
log(err, null);
}
void log(int err)
{
log(err, null);
}
void log(int err, String s)
{
String sMessage = "";
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;
default:
sMessage = "Unknown error: " + err;
break;
}
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;
default:
sMessage = "Unknown error: " + err;
break;
}
if (null != s)
{
sMessage = sMessage + s;
}
log(sMessage);
}
if (null != s)
{
sMessage = sMessage + s;
}
log(sMessage);
}
void log(String s)
{
try
{
fw.write(this.getClass().getName() + ": " + s + "\r\n");
}
catch (IOException ioe)
{
}
}
void log(String s)
{
/*
try
{
fw.write(this.getClass().getName() + ": " + s + "\r\n");
}
catch (IOException ioe)
{
}
*/
}
}

View File

@@ -18,7 +18,7 @@
* 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>
* Author: Greg Richardson <grichardson@novell.com>
*
***********************************************************************/
@@ -30,368 +30,370 @@ import java.util.*;
*/
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_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 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=";
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;
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);
}
public static void main(String[] args)
{
ShutdownWindowsService p = new ShutdownWindowsService(args);
System.exit(ERROR_NO_ERROR);
}
ShutdownWindowsService(String[] args)
{
rc = ERROR_NO_ERROR;
ShutdownWindowsService(String[] args)
{
rc = ERROR_NO_ERROR;
properties = new Properties();
fileProperties = null;
fisProperties = null;
fileOutput = null;
properties = new Properties();
fileProperties = null;
fisProperties = null;
fileOutput = null;
try
{
file = new File("c:\\test7.log");
fw = new FileWriter(file);
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();
}
}
// Process the arguments
if (ERROR_NO_ERROR == (rc = processArgs(args)))
{
// Process the properties
if (ERROR_NO_ERROR == (rc = processProperties()))
{
rc = shutdownService();
}
}
}
catch (IOException e)
{
rc = ERROR_IO_EXCEPTION;
}
finally
{
try
{
log(rc);
fw.flush();
fw.close();
}
catch (Exception e1)
{
}
}
}
}
catch (IOException e)
{
rc = ERROR_IO_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;
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");
}
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;
}
// 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];
}
}
}
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("New arg count " + args.length);
for (i = 0; i < args.length; i++)
{
if (null == args[i])
{
continue;
}
log("arg[" + i + "] = " +args[i]);
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;
}
// 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);
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 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 the install dir is a directory
if (!fileInstallDir.isDirectory())
{
return ERROR_INSTALL_DIR_NOT_A_DIR;
}
properties.setProperty(INSTALL_DIR_PROPERTY, 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;
}
// 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);
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;
}
// 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;
}
}
// 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);
}
}
// 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;
}
// Make sure we got an install dir
if (null == fileInstallDir)
{
return ERROR_MISSING_INSTALL_DIR_PARAM;
}
// Note: the properties file parameter is optional
// Note: the properties file parameter is optional
return ERROR_NO_ERROR;
}
return ERROR_NO_ERROR;
}
int processProperties()
{
try
{
Enumeration e;
String sKey;
String sValue;
int processProperties()
{
try
{
Enumeration e;
String sKey;
String sValue;
e = properties.propertyNames();
e = properties.propertyNames();
while (e.hasMoreElements())
{
sKey = (String)e.nextElement();
sValue = (String)properties.get(sKey);
while (e.hasMoreElements())
{
sKey = (String)e.nextElement();
sValue = (String)properties.get(sKey);
log("Property key = " + sKey + " Value = " + sValue);
}
}
catch (Exception ex1)
{
return -111;
}
log("Property key = " + sKey + " Value = " + sValue);
}
}
catch (Exception ex1)
{
return -111;
}
return ERROR_NO_ERROR;
}
return ERROR_NO_ERROR;
}
int shutdownService()
{
String sExe = (String)properties.get("TOMCAT5");
String sCommand = "";
int iReturn = 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 + " //SS//CasaAuthTokenService";
if (ERROR_NO_ERROR != (iReturn = invokeCommand(sCommand)))
{
return iReturn;
}
sCommand = sExe + " //DS//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;
}
return ERROR_NO_ERROR;
}
int invokeCommand(String sCommand)
{
Process p;
int rc;
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;
}
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;
}
return ERROR_NO_ERROR;
}
void log(int err)
{
log(err, null);
}
void log(int err)
{
log(err, null);
}
void log(int err, String s)
{
String sMessage = "";
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;
default:
sMessage = "Unknown error: " + err;
break;
}
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;
default:
sMessage = "Unknown error: " + err;
break;
}
if (null != s)
{
sMessage = sMessage + s;
}
log(sMessage);
}
if (null != s)
{
sMessage = sMessage + s;
}
log(sMessage);
}
void log(String s)
{
try
{
fw.write(this.getClass().getName() + ": " + s + "\r\n");
}
catch (IOException ioe)
{
}
}
void log(String s)
{
/*
try
{
fw.write(this.getClass().getName() + ": " + s + "\r\n");
}
catch (IOException ioe)
{
}
*/
}
}

View File

@@ -18,7 +18,7 @@
* 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>
* Author: Greg Richardson <grichardson@novell.com>
*
***********************************************************************/
@@ -36,403 +36,405 @@ import java.util.jar.*;
*/
public class UpdateWarFile
{
final static String INSTALL_DIR_PARAM = "ATS_INSTALL_DIR=";
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_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;
String sInstallDir;
File file;
FileWriter fw;
int rc;
String sInstallDir;
//File file;
//FileWriter fw;
int rc;
public static void main(String[] args)
{
UpdateWarFile p = new UpdateWarFile(args);
System.exit(p.rc);
}
public static void main(String[] args)
{
UpdateWarFile p = new UpdateWarFile(args);
System.exit(p.rc);
}
UpdateWarFile(String[] args)
{
sInstallDir = null;
UpdateWarFile(String[] args)
{
sInstallDir = null;
try
{
file = new File("c:\\test3.log");
fw = new FileWriter(file);
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]);
}
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 (IOException e)
{
rc = ERROR_IO_EXCEPTION;
}
finally
{
try
{
log(rc);
fw.flush();
fw.close();
}
catch (Exception e1)
{
}
}
}
// Process the arguments
if (ERROR_NO_ERROR == (rc = processArgs(args)))
{
// Create the modified war file
rc = createWarFile();
}
}
catch (IOException e)
{
rc = ERROR_IO_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;
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");
}
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;
}
// 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];
}
}
}
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]);
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;
}
// 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);
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 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 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;
}
// Make sure we got an install dir
if (null == fileInstallDir)
{
return ERROR_MISSING_INSTALL_DIR_PARAM;
}
return ERROR_NO_ERROR;
}
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;
}
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)
{
// 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;
}
}
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;
}
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();
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());
// 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;
}
// 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;
}
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)
{
log(err, null);
}
void log(int err, String s)
{
String sMessage = "";
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;
default:
sMessage = "Unknown error: " + err;
break;
}
switch (err)
{
case ERROR_NO_ERROR:
sMessage = "No error";
break;
case ERROR_INVALID_NUMBER_OF_PARAMS:
sMessage = "Invalid number of parameters: 1make expected";
break;
default:
sMessage = "Unknown error: " + err;
break;
}
if (null != s)
{
sMessage = sMessage + s;
}
log(sMessage);
}
if (null != s)
{
sMessage = sMessage + s;
}
log(sMessage);
}
void log(String s)
{
try
{
fw.write(this.getClass().getName() + ": " + s + "\r\n");
}
catch (IOException ioe)
{
}
}
void log(String s)
{
/*
try
{
fw.write(this.getClass().getName() + ": " + s + "\r\n");
}
catch (IOException ioe)
{
}
*/
}
}

View File

@@ -111,6 +111,12 @@
}
"Entry"
{
"MsmKey" = "8:_55AF3B67412A49E3A568102FDADDC2FE"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_5B105FED430E4D998914B3562D4A8EA1"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
@@ -958,7 +964,7 @@
"SourcePath" = "8:..\\..\\..\\Svc\\external\\xmlsec\\xml-security-1_4_0\\libs\\xercesImpl.jar"
"TargetName" = "8:xercesImpl.jar"
"Tag" = "8:"
"Folder" = "8:_516714B01FD34E218E009D96264F30AC"
"Folder" = "8:_7F0AE158BB53414DA5BB29F14E55EEBB"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
@@ -1113,6 +1119,26 @@
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_55AF3B67412A49E3A568102FDADDC2FE"
{
"SourcePath" = "8:..\\..\\..\\Svc\\external\\xmlsec\\xml-security-1_4_0\\LICENSE"
"TargetName" = "8:LICENSE"
"Tag" = "8:"
"Folder" = "8:_7F0AE158BB53414DA5BB29F14E55EEBB"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_5B105FED430E4D998914B3562D4A8EA1"
{
"SourcePath" = "8:..\\UpdateWarFile\\bin\\UpdateWarFile.class"
@@ -1218,7 +1244,7 @@
"SourcePath" = "8:..\\..\\..\\Svc\\external\\xmlsec\\xml-security-1_4_0\\libs\\xmlsec-1.4.0.jar"
"TargetName" = "8:xmlsec-1.4.0.jar"
"Tag" = "8:"
"Folder" = "8:_516714B01FD34E218E009D96264F30AC"
"Folder" = "8:_7F0AE158BB53414DA5BB29F14E55EEBB"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
@@ -1278,7 +1304,7 @@
"SourcePath" = "8:..\\..\\..\\Svc\\external\\log4j\\logging-log4j-1.2.14\\dist\\lib\\log4j-1.2.14.jar"
"TargetName" = "8:log4j-1.2.14.jar"
"Tag" = "8:"
"Folder" = "8:_516714B01FD34E218E009D96264F30AC"
"Folder" = "8:_7F0AE158BB53414DA5BB29F14E55EEBB"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
@@ -1558,7 +1584,7 @@
"SourcePath" = "8:..\\..\\..\\Svc\\external\\xmlsec\\xml-security-1_4_0\\libs\\commons-logging.jar"
"TargetName" = "8:commons-logging.jar"
"Tag" = "8:"
"Folder" = "8:_516714B01FD34E218E009D96264F30AC"
"Folder" = "8:_7F0AE158BB53414DA5BB29F14E55EEBB"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
@@ -1828,6 +1854,28 @@
"Property" = "8:_168E54D12032489796CD7A843225EE70"
"Folders"
{
"{9EF0B969-E518-4E46-987F-47570745A589}:_7638BAE158EC4759991B2FC04061FADC"
{
"Name" = "8:external"
"AlwaysCreate" = "11:FALSE"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Property" = "8:_E580B31319AE4C55BC31CFF84AF8C6AE"
"Folders"
{
"{9EF0B969-E518-4E46-987F-47570745A589}:_7F0AE158BB53414DA5BB29F14E55EEBB"
{
"Name" = "8:apache.org"
"AlwaysCreate" = "11:FALSE"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Property" = "8:_B5D79599A831420BBDEBFD4FB0E2EA76"
"Folders"
{
}
}
}
}
}
}
"{9EF0B969-E518-4E46-987F-47570745A589}:_62B357DC6D484761A18291FA3525320C"