/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
#include "java.h"
static int numOptions = 0;
static int numProps = 0;
static int maxOptions = 0;
static int maxProps = 0;
/*
* Prototypes for functions internal to launcher.
*/
static jboolean ParseArguments(int *pargc, char ***pargv, char **pJavaHome, char **pTempDir, jboolean *pShowConsole, jboolean *pUseAnswerFileOption, char **pAnswerFile, jboolean *pUseAlternateRootOption, char **pAlternateRoot, jboolean *pStoreAnswerFile, char **pAnswerFileLocation, jboolean *pLogLevelOption, jboolean *pUseLogsLocation, char **pLogsLocation, int *pret);
static void DeleteWorkingDirectory(void);
static void PrepareToExit();
#ifdef WIN32
#else
static void HandleSignalAndExit(int sig);
static void HandleSignalAndAbort(int sig);
#endif
static void PrintUsage(void);
static const char *SetExecName(const char *program);
/*
* Entry point.
*/
int
{
char *s;
int ret;
int i;
int j;
int size;
const char *apphome;
const char *execname;
int zipError;
/* Used for saving answer file. */
/* Use Alternate Root */
/* Logs Location */
/* Dry Run file location */
/* Log Level */
/* reference to Open Installer Framework zip File */
/* reference to jdk zip File */
#ifdef WIN32
#else
unsigned long long requiredDisk;
unsigned long long availableDisk;
#endif
/* Compute the name of the executable */
{
return 1;
}
/* Check if another instance is already running */
progname = s + 1;
++argv;
--argc;
#ifdef WIN32
#else
/* Signals to ignore */
/* Signals to run exit handler */
/* Signals to run exit handler and dump core */
#endif
/*
* Parse command line options and convert any relative paths in the
* argument list to absolute paths. This function will also remove
* the program name from argv so that the argument list conforms
* to the Java argument list format.
*/
if (!ParseArguments(&argc, &argv, &javahome, &tmpdir, &showconsole, &useAnswerFileOption, &answerFile, &useAlternateRootOption, &alternateRoot, &storeAnswerFile, &answerFileLocation, &logLevelOption, &useLogsLocation, &logsLocation, &ret))
return ret;
/* Remove it after console mode support has been turned on */
/* Create the temporary directory */
s = GetLocalizedMessage("checking_disk_space");
statusf(s);
s = NULL;
/* if tmpdir explicitly set, override environment variables on relevant platforms */
#ifdef WIN32
{
}
#endif
#ifdef LINUX
{
}
#endif
/* if tmpdir has not already been set through command line option get it... */
{
tmpdir = GetTempDir();
}
{
return 1;
}
/*
* Create the working directory and protect against the possibility that
* the working directory may already exist.
*/
#ifdef WIN32
#else
#endif
{
{
return 1;
}
}
/* Check that there enough temporary space */
requiredDisk = 0;
{
/* Get the uncompressed size of the embedded files */
i = 0;
{
}
/* Reset application home to the working directory */
}
/* Add a little extra for the SetupSDK's native executable */
requiredDisk += 100000;
ret = 0;
#ifdef WIN32
if (!GetDiskFreeSpaceEx(workdir,
(PULARGE_INTEGER) &freebytes))
ret = 1;
#else
{
{
/*
* If there is an overflow, we can safely assume that there
* is plenty of free disk space
*/
}
else
{
ret = 1;
}
}
#endif
if (ret)
{
return 1;
}
else if (requiredDisk > availableDisk)
{
/*
* This is workaround for Windows printf quirk - second lli will
* be printed with zero value if printed directly
*/
return 1;
}
/* Find out where the JRE is that we will be using. */
s = GetLocalizedMessage("checking_java");
statusf(s);
s = NULL;
ret = 0;
if (javahome)
{
/* Make sure version is OK */
{
return 1;
}
}
/* if javahome is not explicitly passed, then check public JREs on the machine. */
else
{
{
Look at the installer bundled to see if there is a bundled JDK.
Prior to this the installer bundle itself has to be unzipped
in temp dir. */
ret = 1;
}
}
{
{
return 1;
}
}
/* Check to see if there is a bundled jdk.zip in the installer bundle. */
/* If Java is not found in the environment, then check to see if there is a jdk.zip
in package directory. If found one, then unzip it and use it to launch installer.
This will only be valid in case of Java EE SDK bundles that includes a jdk in them. */
{
{
return 1;
}
/* Now check to make sure that the bundled version is okay. */
/* Make sure version is OK */
{
ret = 1;
}
}
else
{
return ret;
}
}
/* Could have wrapped this repeated piece of code in a method, but too many arguments to pass,
Moreover this is a temp. fix */
{
{
return 1;
}
}
{
{
return 1;
}
}
{
{
return 1;
}
}
/* Set CLASSPATH */
{
return 1;
}
for (i = 0; i < j; i++)
{
for (i = 0; i < NUM_JDK_CLASSPATH; i++)
strcpy(s, CLASSPATH_OPTION);
for (i = 0; i < NUM_JDK_CLASSPATH; i++)
{
strcat(s, jdkClassPath[i]);
strcat(s, PATH_SEPARATOR);
}
}
else
{
strcpy(s, CLASSPATH_OPTION);
}
for (i = 0; i < j; i++)
{
strcat(s, PATH_SEPARATOR);
strcat(s, appclasspath[i]);
}
AddOption(s);
s = NULL;
/* Set the "java.io.tmpdir" property */
AddOption(s);
s = NULL;
/* pass the temp dir */
AddOption(s);
s = NULL;
/* Set the "java.endorsed.dir" property to use the default XML parser */
/* TODO FIX AddOption(StrDup(ENDORSED_DIRS_OPTION)); */
/* Set the "-Xmx" argument high enough so load the main class */
/* Set debug option */
if (isDebug)
{
}
/* Set Creator installation options */
if (noPortVerification)
{
}
if (noDomainCreation)
{
}
if (visiblePassword)
{
}
/* Set Open Installer Specific parameters */
/* Setup default options first */
/* Setup INSTALL_ENGINE Option */
/* Setup INSTALL_RESOURCE */
sprintf(s, INSTALL_RESOURCE_OPTION "%s" FILE_SEPARATOR "install" FILE_SEPARATOR "metadata",workdir);
AddOption(s);
s = NULL;
/* Setup DEFAULT_RESOURCE */
sprintf(s, DEFAULT_RESOURCE_OPTION "%s" FILE_SEPARATOR "install" FILE_SEPARATOR "lib" FILE_SEPARATOR "resources/",workdir);
AddOption(s);
s = NULL;
/* Setup SIMS Native File */
AddOption(s);
s = NULL;
/* Set the "DEFAULT_PRODUCTID_PROP" property */
/* Set the "PKG_FORMAT_PROP" property */
/* Set the "PLATFORM_PLUGIN_PROP" property */
s = (char *)MemAlloc(strlen(PLATFORM_PLUGIN_PROP) + strlen(workdir) + strlen(PLATFORM_PLUGIN_PATH) + 10);
#ifdef WIN32
#else
#endif
s = NULL;
/* Set the "PROVIDER_PATH_PROP" property */
#ifdef WIN32
#else
#endif
s = NULL;
/* Set the "DRY_RUN_FILE_PROP" property */
if (storeAnswerFile)
{
s = NULL;
}
/* CONDITIONAL */
/* Set the "ANSWER_FILE_PROP" property */
if (useAnswerFileOption)
{
#ifdef WIN32
sprintf(s, ANSWER_FILE_PROP ",file:///%s" FILE_SEPARATOR "install.windows.properties,%s" ,workdir, answerFile);
#else
sprintf(s, ANSWER_FILE_PROP ",file://%s" FILE_SEPARATOR "install.properties,%s" ,workdir, answerFile);
#endif
}
else
{
/* assign default */
#ifdef WIN32
#else
#endif
}
s = NULL;
/* CONDITIONAL */
/* Set the "LOGS-LOCATION" property */
if (useLogsLocation)
{
}
else
{
}
s = NULL;
/* CONDITIONAL */
/* Set the "ALTERNATE_ROOT_PROP" property */
{
s = NULL;
}
/* Set savestate file */
/* Set the "INSTALLABLE_UNIT_PROP" property */
s = NULL;
/* Set the "MEDIA_LOCATION_PROP" property */
#ifdef WIN32
#else
#endif
s = NULL;
/*
* Change the working directory to the directory where the executable
* is located since the SetupSDK classes expect that. Conversion of
* any relative paths in the argument list should have already been
* converted to absolute paths before this step.
*/
ret = 1;
#ifdef WIN32
if (SetCurrentDirectory(apphome))
ret = 0;
#else
ret = 0;
#endif
if (ret)
{
return ret;
}
/* Create a console if necessary */
if (showconsole)
/* Invoke Java */
s = GetLocalizedMessage("executing_java");
statusf(s);
s = NULL;
return ret;
}
{
#ifdef WIN32
return JNI_TRUE;
return JNI_TRUE;
#else
if (path[0] == FILE_SEPARATOR_CHAR)
return JNI_TRUE;
#endif
return JNI_FALSE;
}
#ifndef WIN32
/*
* Find the absolute path for the executable.
*/
static char *
{
const char *envvar;
if (IsAbsolutePath(program))
{
{
}
return execpath;
}
{
size += MAXPATHLEN;
{
}
return execpath;
}
/* Look in PATH environment variable */
if (envvar)
{
char *tokstr;
char *currentpath;
{
/*
* Look for the Java executable and, if found, find its
* installation directory
*/
*tokstr++ = '\0';
if (strlen(currentpath) == 0)
currentpath = ".";
{
}
}
}
return execpath;
}
#endif /* #ifndef WIN32 */
/*
* Compute the name of the executable
*/
static const char *
{
if (!execname)
{
#ifdef WIN32
int ret;
{
size += MAXPATHLEN;
}
if (ret)
{
}
else
{
}
#else
#endif
}
return execname;
}
/*
* Return the name of the executable. Used in java_md.c to find the JRE area.
*/
const char *
{
return execname;
}
/*
* If app is "/foo/x" then return "/foo".
*/
const char *
{
if (!applicationHome)
{
if (execname)
{
}
}
return applicationHome;
}
/*
* Adds a new VM option with the given given name and value.
*/
static void
{
/*
* Expand options array if needed to accomodate at least one more
* VM option.
*/
if (numOptions >= maxOptions)
{
{
maxOptions = 4;
}
else
{
maxOptions *= 2;
}
}
}
/*
* Adds a new proerty with the given given name and value.
* These properties are to be passed to OpenInstaller's EngineBootstrap Java Class.
*/
static void
{
/*
* Expand Props array if needed to accomodate at least one more
* VM Props.
*/
{
{
maxProps= 50;
}
else
{
maxProps *= 2;
}
}
}
/*
* Parses command line arguments.
*/
static jboolean
ParseArguments(int *pargc, char ***pargv, char **pJavaHome, char **pTempDir, jboolean *pShowConsole, jboolean *pUseAnswerFileOption, char **pAnswerFile, jboolean *pUseAlternateRootOption,
char **pAlternateRoot, jboolean *pStoreAnswerFile, char **pAnswerFileLocation, jboolean *pLogLevelOption, jboolean *pUseLogsLocation, char **pLogsLocation, int *pret)
{
char *arg;
int appArgc;
*pret = 1;
appArgc = 0;
{
{
*pret = 0;
PrintUsage();
goto error;
}
/*
-Check if -a is passed, if so validate the file and set Answer-Files property.
if not, then set it to "-p Answer-Files=,file://<InstallDir>/install.properties".
TODO: Validate the given file name for readability */
{
if (argc < 1)
{
PrintUsage();
goto error;
}
/* Convert the path to absolute path, otherwise the file
gets written to the temp directory that is eventually cleaned up
immediately after installation. */
{
/* PrintUsage(); */
goto error;
}
appArgc += 2;
}
/*Check if -l is passed, if so validate the file and set Logs-Location property.
if not, then set it to "-p Logs-Location=<Directory>".
TODO: Validate the given directory for readability */
{
if (argc < 1)
{
PrintUsage();
goto error;
}
{
/* PrintUsage(); */
goto error;
}
appArgc += 2;
}
/*-Check if -n is passed, if so validate the file and set Dry-Run-File property.
if not, then set it to "-p Dry-Run-File=<Non Existing filename>".
TODO: Validate the given directory for readability */
{
if (argc < 1)
{
/* PrintUsage(); */
goto error;
}
/* Convert the path to absolute path, otherwise the file
gets written to the temp directory that is eventually cleaned up
immediately after installation. */
/* If the file already exists, then bail out */
{
/* PrintUsage(); */
goto error;
}
appArgc += 2;
}
/* Check if -s is passed for silent */
{
appArgc++;
}
/* Check if -q is passed for setting log level to warning */
{
appArgc++;
}
{
appArgc++;
}
/* Check if -j is passed for setting custom javahome */
{
if (argc < 1)
{
PrintUsage();
goto error;
}
}
else
{
PrintUsage();
goto error;
}
}
/* CONDITIONAL */
/* Set the Default Log Level property */
if (*pLogLevelOption == JNI_FALSE)
{
}
#ifdef WIN32
/* If running in GUI mode, check if there are enough colors */
if (!consoleOption)
{
int colordepth = 0;
if (dc)
{
}
/* At least 256 colors are needed */
if (colordepth < 8)
{
if (MessageBox(statusdialog, message, GetTitle(), MB_YESNO | MB_ICONEXCLAMATION | MB_APPLMODAL) == IDYES)
{
appArgc++;
}
if (!consoleOption)
{
PrintUsage();
goto error;
}
}
}
#else
#ifndef LINUX
/* If running in GUI mode, check that GUI is available */
/* This whole section is being skipped for Linux - Motif is obsoleted there */
if (!consoleOption)
{
{
goto error;
}
}
#endif
#ifndef ALLOW_AWT_HEADLESS
/*
* If running in console or silent mode, check that X11 libraries can be
* loaded since the AWT libraries are linked to them
*/
{
goto error;
}
#endif
#endif
if (appArgc >= 0)
{
int i = 0;
if (consoleOption)
{
/* Defer allocation of and printing to terminal */
*pShowConsole = JNI_TRUE;
appArgv[i++] = "-nodisplay";
}
}
return JNI_TRUE;
/*
if (appArgv)
{
free(appArgv);
appArgv = NULL;
}
if (cwd)
{
free(cwd);
cwd = NULL;
}
if (*pJavaHome)
{
free(*pJavaHome);
*pJavaHome = NULL;
}
if (*pTempDir)
{
free(*pTempDir);
*pTempDir = NULL;
}
if (*pAnswerFile)
{
free(*pAnswerFile);
*pAnswerFile= NULL;
}
if (*pAlternateRoot)
{
free(pAlternateRoot);
*pAlternateRoot= NULL;
}
if (*pLogsLocation)
{
free(pLogsLocation);
*pLogsLocation= NULL;
}
if (*pAnswerFileLocation)
{
free(pAnswerFileLocation);
*pAnswerFileLocation= NULL;
}
*pargv = NULL;
*/
return JNI_FALSE;
}
/*
* Returns a pointer to a block of at least 'size' bytes of memory.
* Prints error message and exits if the memory could not be allocated.
*/
void *
{
if (p == NULL)
{
perror("Out of memory");
exit(1);
}
return p;
}
/*
* Returns a pointer to a copy of the specified string.
* Prints error message and exits if the memory could not be allocated.
*/
char *
{
return newstr;
}
/*
* Checks the version information from the java.version property.
*/
{
{
}
return ret;
}
/*
* Checks the version information against the specified string.
*/
{
int i;
/* Find a matching supported version */
for (i = 0; i < NUM_SUPPORTED_VM_VERSIONS; i++)
{
return JNI_TRUE;
}
return JNI_FALSE;
}
/*
* Checks that the Java class file exists and is readable
*/
{
{
/* If the class file is gone, then the uninstall succeeded */
/*
if (access(classfile, R_OK) == 0)
ret = JNI_TRUE;
*/
}
return ret;
}
/*
* Custom version of strchr() that properly ignores the specified character
* if it is part of a multi-byte character.
*/
char
*_strchr(const char *s, int c)
{
const char *t;
if (!s)
return NULL;
for (t = s; *t; t++)
{
if (*t != c || !IsMultiByteChar(s, t - s))
continue;
return (char *)t;
}
return NULL;
}
/*
* Custom version of strrchr() that properly ignores the specified character
* if it is part of a multi-byte character.
*/
char
*_strrchr(const char *s, int c)
{
const char *t;
if (!s)
return NULL;
for (t = s + strlen(s); t >= s; t--)
{
if (*t != c || !IsMultiByteChar(s, t - s))
continue;
return (char *)t;
}
return NULL;
}
/*
* Prints default usage message.
*/
static void
{
char *message;
/*
char *classname = GetJavaClassName();
if (strcmp(classname,"appserv_uninstall") ==0)
message = GetLocalizedMessage("uninstallusage");
else
message = GetLocalizedMessage("installusage");
*/
}
static void
{
/*
char *message = GetLocalizedMessage("performing_cleanup");
statusf(message);
free(message);
message = NULL;
*/
#ifdef WIN32
SetCurrentDirectory("..");
#endif
if (doCleanup)
Cleanup();
}
#ifdef WIN32
{
return EXCEPTION_CONTINUE_SEARCH;
}
#else
static void
{
_exit(255);
}
static void
{
abort();
}
#endif
static void
{
if (workdir)
}
/*
* Find and return the absolute path of the given file.
*/
char *
#ifdef WIN32
{
size += MAXPATHLEN;
}
#else
size += MAXPATHLEN;
#endif
{
}
else
{
}
return absolutePath;
}
/*
* Unzip the contents of a zip file into the specified directory.
*/
{
char *s;
int i;
int j;
return JNI_FALSE;
i = 0;
{
/* Skip any entries that don't match the entry subdirectory filter */
goto leave_zip_entry;
{
len = j;
}
/*
* Important note: we expect that the entry name is not an
* absolute path and we need to parse the entry name using
* a Unix file separator character instead of the native
* file separator
*/
{
*s = '\0';
#ifdef WIN32
#else
#endif
/* Skip directory entries */
if (strlen(s + 1) == 0)
goto leave_zip_entry;
/* Use the native file separator so that it is a valid path */
*s++ = FILE_SEPARATOR_CHAR;
}
{
return JNI_FALSE;
}
}
return JNI_TRUE;
}