From 009f73e44233a3e13a652060d7c8eff0e6b621d4 Mon Sep 17 00:00:00 2001 From: dveditz Date: Sun, 7 Jun 1998 09:47:23 +0000 Subject: [PATCH] merging from SMARTUPDATE_BRANCH git-svn-id: svn://10.0.0.236/trunk@3448 18797224-902f-48f8-a5cc-f745e15eee43 --- .../netscape/softupdate/FolderSpec.java | 18 - .../netscape/softupdate/InstallDelete.java | 185 ++++ .../netscape/softupdate/InstallExecute.java | 10 +- .../netscape/softupdate/InstallFile.java | 109 ++- .../netscape/softupdate/InstallObject.java | 6 +- .../netscape/softupdate/InstallPatch.java | 18 +- .../classes/netscape/softupdate/Makefile | 1 + .../netscape/softupdate/ProgressDetails.java | 5 +- .../netscape/softupdate/ProgressMediator.java | 11 +- .../softupdate/SoftUpdateResourceBundle.java | 8 + .../netscape/softupdate/SoftwareUpdate.java | 899 +++++++++--------- .../classes/netscape/softupdate/Strings.java | 32 + .../softupdate/SymProgressDetails.java | 1 + .../softupdate/SymProgressWindow.java | 3 +- .../netscape/softupdate/VersionRegistry.java | 107 +++ .../netscape/softupdate/WinProfile.java | 16 +- .../netscape/softupdate/WinProfileItem.java | 3 + .../classes/netscape/softupdate/WinReg.java | 3 +- .../netscape/softupdate/WinRegItem.java | 3 + .../netscape/softupdate/WinRegValue.java | 1 - .../classes/netscape/softupdate/makefile.win | 1 + mozilla/modules/softupdt/include/gdiff.h | 54 +- mozilla/modules/softupdt/include/softupdt.h | 16 +- 23 files changed, 1010 insertions(+), 500 deletions(-) create mode 100644 mozilla/modules/softupdt/classes/netscape/softupdate/InstallDelete.java diff --git a/mozilla/modules/softupdt/classes/netscape/softupdate/FolderSpec.java b/mozilla/modules/softupdt/classes/netscape/softupdate/FolderSpec.java index 9d3072a80cb..021af08174c 100644 --- a/mozilla/modules/softupdt/classes/netscape/softupdate/FolderSpec.java +++ b/mozilla/modules/softupdt/classes/netscape/softupdate/FolderSpec.java @@ -96,10 +96,6 @@ final class FolderSpec { */ String MakeFullPath(String relativePath) throws SoftUpdateException { - // Security check. Make sure that we do not have '.. in the name - if ( (GetSecurityTargetID() == SoftwareUpdate.LIMITED_INSTALL) && - ( relativePath.regionMatches(0, "..", 0, 2))) - throw new SoftUpdateException(Strings.error_IllegalPath(), SoftwareUpdate.ILLEGAL_RELATIVE_PATH ); String fullPath = GetDirectoryPath() + GetNativePath ( relativePath ); return fullPath; } @@ -141,20 +137,6 @@ final class FolderSpec { private native String NativePickDefaultDirectory() throws SoftUpdateException; - /* - * GetSecurityTarget - * returns security object associated with the directory - */ - netscape.security.Target - GetSecurityTarget() - { - int secID = GetSecurityTargetID(); - return netscape.security.Target.findTarget( SoftwareUpdate.targetNames[secID] ); - } - - private native int - GetSecurityTargetID(); - public String toString() { String path; diff --git a/mozilla/modules/softupdt/classes/netscape/softupdate/InstallDelete.java b/mozilla/modules/softupdt/classes/netscape/softupdate/InstallDelete.java new file mode 100644 index 00000000000..e83f64d1732 --- /dev/null +++ b/mozilla/modules/softupdt/classes/netscape/softupdate/InstallDelete.java @@ -0,0 +1,185 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +package netscape.softupdate ; + +import java.lang.*; +import netscape.security.PrivilegeManager; +import netscape.security.Target; +import netscape.security.AppletSecurity; + +/* InstallDelete + * deletes the specified file from the disk + */ + +class InstallDelete extends InstallObject { + private String finalFile = null; // final file to be deleted + private String registryName; // final file to be deleted + + int deleteStatus; + static final int DELETE_FILE = 1; + static final int DELETE_COMPONENT = 2; + + + + /* Constructor + inFolder - a folder object representing the directory that contains the file + inRelativeFileName - a relative path and file name + */ + + InstallDelete(SoftwareUpdate inSoftUpdate, FolderSpec inFolder, + String inRelativeFileName) throws SoftUpdateException + { + super(inSoftUpdate); + deleteStatus = DELETE_FILE; + finalFile = inFolder.MakeFullPath(inRelativeFileName); + processInstallDelete(); + } + + /* Constructor + inRegistryName - name of the component in the registry + */ + InstallDelete(SoftwareUpdate inSoftUpdate, String inRegistryName) + throws SoftUpdateException + { + super(inSoftUpdate); + deleteStatus = DELETE_COMPONENT; + registryName = inRegistryName; + processInstallDelete(); + } + + private void processInstallDelete() throws SoftUpdateException + { + int err; + + /* Request impersonation privileges */ + netscape.security.PrivilegeManager privMgr; + Target impersonation, target; + + privMgr = AppletSecurity.getPrivilegeManager(); + impersonation = Target.findTarget( SoftwareUpdate.IMPERSONATOR ); + privMgr.enablePrivilege( impersonation ); + + /* check the security permissions */ + target = Target.findTarget( SoftwareUpdate.INSTALL_PRIV ); + + privMgr.enablePrivilege( target, softUpdate.GetPrincipal() ); + + if (deleteStatus == DELETE_COMPONENT) + { + /* Check if the component is in the registry */ + err = VersionRegistry.inRegistry(registryName); + if (err != VersionRegistry.REGERR_OK) + { + throw( new SoftUpdateException(Strings.error_NotInRegistry() + registryName, err)); + } + else + { + finalFile = VersionRegistry.componentPath(registryName); + } + } + + /* Check if the file exists and is not read only */ + if (finalFile != null) + { + err = NativeCheckFileStatus(); + if (err == 0) + { + /* System.out.println("File exists and is not read only" + finalFile);*/ + } + else if (err == SoftwareUpdate.FILE_DOES_NOT_EXIST) + { + /*throw( new SoftUpdateException(Strings.error_FileDoesNotExist() + finalFile, err));*/ + } + else if (err == SoftwareUpdate.FILE_READ_ONLY) + { + throw( new SoftUpdateException(Strings.error_FileReadOnly() + finalFile, err)); + } + else if (err == SoftwareUpdate.FILE_IS_DIRECTORY) + { + throw( new SoftUpdateException(Strings.error_FileIsDirectory() + finalFile, err)); + } + else + { + throw( new SoftUpdateException(Strings.error_Unexpected() + finalFile, err)); + } + } + } + + // no set-up necessary + protected void Prepare() throws SoftUpdateException {} + + /* Complete + * Completes the install by deleting the file + * Security hazard: make sure we request the right permissions + */ + protected void Complete() throws SoftUpdateException + { + int err = -1; + Target execTarget; + netscape.security.PrivilegeManager privMgr; + Target impersonation; + privMgr = AppletSecurity.getPrivilegeManager(); + impersonation = Target.findTarget( SoftwareUpdate.IMPERSONATOR ); + privMgr.enablePrivilege( impersonation ); + execTarget = Target.findTarget( SoftwareUpdate.INSTALL_PRIV ); + privMgr.enablePrivilege( execTarget, softUpdate.GetPrincipal() ); + if (deleteStatus == DELETE_COMPONENT) + { + err = VersionRegistry.deleteComponent(registryName); + } + if ((deleteStatus == DELETE_FILE) || (err == VersionRegistry.REGERR_OK)) + { + if (finalFile != null) + { + err = NativeComplete(); + if ((err != 0) && (err != SoftwareUpdate.FILE_DOES_NOT_EXIST)) + { + privMgr.revertPrivilege( execTarget ); + throw( new SoftUpdateException(Strings.error_Unexpected() + finalFile, err)); + } + } + } + else + { + throw( new SoftUpdateException(Strings.error_Unexpected() + finalFile, err)); + } + return; + } + + + protected void Abort() + { + ; + } + + private native int NativeComplete() throws SoftUpdateException; + private native int NativeCheckFileStatus() throws SoftUpdateException; + + public String toString() + { + if (deleteStatus == DELETE_FILE) + { + return Strings.details_DeleteFile() + finalFile; + } + else + { + return Strings.details_DeleteComponent() + registryName; + } + } + +} diff --git a/mozilla/modules/softupdt/classes/netscape/softupdate/InstallExecute.java b/mozilla/modules/softupdt/classes/netscape/softupdate/InstallExecute.java index 7ae341dc16e..ce898c2d20c 100644 --- a/mozilla/modules/softupdt/classes/netscape/softupdate/InstallExecute.java +++ b/mozilla/modules/softupdt/classes/netscape/softupdate/InstallExecute.java @@ -53,23 +53,23 @@ class InstallExecute extends InstallObject { privMgr.enablePrivilege( impersonation ); /* check the security permissions */ - target = Target.findTarget( SoftwareUpdate.targetNames[SoftwareUpdate.FULL_INSTALL] ); + target = Target.findTarget( SoftwareUpdate.INSTALL_PRIV ); /* XXX: we need a way to indicate that a dialog box should appear.*/ privMgr.enablePrivilege( target, softUpdate.GetPrincipal() ); } - /* ExtractFile + /* Prepare * Extracts file out of the JAR archive into the temp directory */ - protected void ExtractFile() throws SoftUpdateException + protected void Prepare() throws SoftUpdateException { netscape.security.PrivilegeManager privMgr; Target impersonation; Target execTarget; privMgr = AppletSecurity.getPrivilegeManager(); impersonation = Target.findTarget( SoftwareUpdate.IMPERSONATOR ); - execTarget = Target.findTarget( SoftwareUpdate.targetNames[SoftwareUpdate.FULL_INSTALL] ); + execTarget = Target.findTarget( SoftwareUpdate.INSTALL_PRIV ); privMgr.enablePrivilege( impersonation ); privMgr.enablePrivilege( execTarget, softUpdate.GetPrincipal() ); tempFile = softUpdate.ExtractJARFile( jarLocation, null ); @@ -94,7 +94,7 @@ class InstallExecute extends InstallObject { privMgr = AppletSecurity.getPrivilegeManager(); impersonation = Target.findTarget( SoftwareUpdate.IMPERSONATOR ); privMgr.enablePrivilege( impersonation ); - execTarget = Target.findTarget( SoftwareUpdate.targetNames[SoftwareUpdate.FULL_INSTALL] ); + execTarget = Target.findTarget( SoftwareUpdate.INSTALL_PRIV ); privMgr.enablePrivilege( execTarget, softUpdate.GetPrincipal() ); NativeComplete(); privMgr.revertPrivilege( execTarget ); diff --git a/mozilla/modules/softupdt/classes/netscape/softupdate/InstallFile.java b/mozilla/modules/softupdt/classes/netscape/softupdate/InstallFile.java index a3fd921c119..68cbd169272 100644 --- a/mozilla/modules/softupdt/classes/netscape/softupdate/InstallFile.java +++ b/mozilla/modules/softupdt/classes/netscape/softupdate/InstallFile.java @@ -36,8 +36,13 @@ final class InstallFile extends InstallObject { private String jarLocation; // Location in the JAR private String tempFile; // temporary file location private String finalFile; // final file destination - private netscape.security.Target target; // security target + private String regPackageName; // Name of the package we are installing + private String userPackageName; // User-readable package name + private Target target; // security target private boolean force; // whether install is forced + private boolean replace = false; // whether file exists + private boolean bChild = false; // whether file is a child + private boolean bUpgrade = false; // whether file is an upgrade /* Constructor inSoftUpdate - softUpdate object we belong to @@ -55,8 +60,8 @@ final class InstallFile extends InstallObject { String inPartialPath, boolean forceInstall) throws SoftUpdateException { - super(inSoftUpdate); - tempFile = null; + super(inSoftUpdate); + tempFile = null; vrName = inVRName; versionInfo = inVInfo; jarLocation = inJarLocation; @@ -72,16 +77,32 @@ final class InstallFile extends InstallObject { privMgr.enablePrivilege( impersonation ); /* check the security permissions */ - target = folderSpec.GetSecurityTarget(); + target = Target.findTarget( SoftwareUpdate.INSTALL_PRIV ); /* XXX: we need a way to indicate that a dialog box should appear. */ privMgr.enablePrivilege( target, softUpdate.GetPrincipal() ); + + userPackageName = inSoftUpdate.GetUserPackageName(); + regPackageName = inSoftUpdate.GetRegPackageName(); + + // determine Child status + if ( regPackageName.length() == 0 ) { + // in the "current communicator package" absolute pathnames (start + // with slash) indicate shared files -- all others are children + bChild = ( vrName.charAt(0) != '/' ); + } + else { + bChild = vrName.startsWith(regPackageName); + } + + replace = NativeDoesFileExist(); + } - /* ExtractFile + /* Prepare * Extracts file out of the JAR archive into the temp directory */ - protected void ExtractFile() throws SoftUpdateException + protected void Prepare() throws SoftUpdateException { netscape.security.PrivilegeManager privMgr; Target impersonation; @@ -101,6 +122,8 @@ final class InstallFile extends InstallObject { protected void Complete() throws SoftUpdateException { int err; + Integer refCount; + int rc; /* Check the security for our target */ netscape.security.PrivilegeManager privMgr; @@ -115,15 +138,67 @@ final class InstallFile extends InstallObject { if ( 0 == err || SoftwareUpdate.REBOOT_NEEDED == err ) { - VersionRegistry.installComponent(vrName, finalFile, versionInfo); - if ( err != 0 ) - throw( new SoftUpdateException(finalFile, err)); - } - else - throw( new SoftUpdateException(Strings.error_InstallFileUnexpected() + finalFile, err)); + // we ignore all registry errors because they're not + // important enough to abort an otherwise OK install. + if (!bChild) + { + int found; + found = VersionRegistry.uninstallFileExists(regPackageName, vrName); + if (found != VersionRegistry.REGERR_OK) + bUpgrade = false; + else + bUpgrade = true; + } + else if ( VersionRegistry.REGERR_OK == VersionRegistry.inRegistry(vrName)) + { + bUpgrade = true; + } + else + { + bUpgrade = false; + } + + refCount = VersionRegistry.getRefCount(vrName); + if (!bUpgrade) + { + if (refCount != null) + { + rc = 1 + refCount.intValue(); + VersionRegistry.installComponent(vrName, finalFile, versionInfo, rc ); + + } + else + { + if (replace) + VersionRegistry.installComponent(vrName, finalFile, versionInfo, 2); + else + VersionRegistry.installComponent(vrName, finalFile, versionInfo, 1); + } + } + else if (bUpgrade) + { + if (refCount == null) + { + VersionRegistry.installComponent(vrName, finalFile, versionInfo, 1); + } + else + { + VersionRegistry.installComponent(vrName, finalFile, versionInfo ); + } + } + + if ( !bChild && !bUpgrade ) { + VersionRegistry.uninstallAddFile(regPackageName, vrName); + } + } + + if ( err == SoftwareUpdate.REBOOT_NEEDED ) { + throw( new SoftUpdateException(finalFile, err)); + } + else if ( err != 0 ) { + throw( new SoftUpdateException(Strings.error_InstallFileUnexpected() + finalFile, err)); + } - // Eventually, put extracted files into proper locations - // System.out.println("File installed: " + finalFile); } protected void Abort() @@ -133,9 +208,13 @@ final class InstallFile extends InstallObject { private native void NativeAbort(); private native int NativeComplete(); + private native boolean NativeDoesFileExist(); public String toString() { - return "Copy file to " + finalFile; + if ( replace ) + return Strings.details_ReplaceFile() + finalFile; + else + return Strings.details_InstallFile() + finalFile; } } diff --git a/mozilla/modules/softupdt/classes/netscape/softupdate/InstallObject.java b/mozilla/modules/softupdt/classes/netscape/softupdate/InstallObject.java index 42a65cfaf5e..ca42b2f7048 100644 --- a/mozilla/modules/softupdt/classes/netscape/softupdate/InstallObject.java +++ b/mozilla/modules/softupdt/classes/netscape/softupdate/InstallObject.java @@ -27,6 +27,7 @@ import java.lang.*; * encapsulates a single action * The way your subclass is used: * Constructor should collect all the data needed to perform the action + * Prepare() does any lengthy set-up action (uncompressing, patching, etc.) * Complete() is called to complete the action * Abort() is called when update is aborted * You are guaranteed to be called with Complete() or Abort() before finalize @@ -42,7 +43,10 @@ abstract class InstallObject { softUpdate = (SoftwareUpdate) inSoftUpdate; } - /* Override with your action */ + /* Override with your set-up action */ + abstract protected void Prepare() throws SoftUpdateException; + + /* Override with your Completion action */ abstract protected void Complete() throws SoftUpdateException; /* Override with an explanatory string for the progress dialog */ diff --git a/mozilla/modules/softupdt/classes/netscape/softupdate/InstallPatch.java b/mozilla/modules/softupdt/classes/netscape/softupdate/InstallPatch.java index 853beac8a89..bcc915d18ce 100644 --- a/mozilla/modules/softupdt/classes/netscape/softupdate/InstallPatch.java +++ b/mozilla/modules/softupdt/classes/netscape/softupdate/InstallPatch.java @@ -96,8 +96,7 @@ final class InstallPatch extends InstallObject { Target impersonation = Target.findTarget( SoftwareUpdate.IMPERSONATOR ); - Target priv = Target.findTarget( - SoftwareUpdate.targetNames[ SoftwareUpdate.FULL_INSTALL ] ); + Target priv = Target.findTarget( SoftwareUpdate.INSTALL_PRIV ); privMgr.enablePrivilege( impersonation ); privMgr.enablePrivilege( priv, softUpdate.GetPrincipal() ); @@ -105,12 +104,18 @@ final class InstallPatch extends InstallObject { - protected void ApplyPatch() throws SoftUpdateException + protected void Prepare() throws SoftUpdateException { + int err; String srcname; boolean deleteOldSrc; - checkPrivileges(); + PrivilegeManager privMgr = AppletSecurity.getPrivilegeManager(); + Target impersonation = + Target.findTarget( SoftwareUpdate.IMPERSONATOR ); + Target priv = Target.findTarget( SoftwareUpdate.INSTALL_PRIV ); + privMgr.enablePrivilege( impersonation ); + privMgr.enablePrivilege( priv, softUpdate.GetPrincipal() ); patchURL = softUpdate.ExtractJARFile( jarLocation, targetfile ); @@ -178,13 +183,16 @@ final class InstallPatch extends InstallObject { else { // nothing -- old intermediate patched file was - // deleted by superceding patch + // deleted by a superceding patch } } protected void Abort() { + // clean up patched file unless it has been already + // deleted by a superceding patch + String tmp = (String)softUpdate.patchList.get( targetfile ); if ( tmp.compareTo( patchedfile ) == 0 ) NativeDeleteFile( patchedfile ); diff --git a/mozilla/modules/softupdt/classes/netscape/softupdate/Makefile b/mozilla/modules/softupdt/classes/netscape/softupdate/Makefile index 48abf0d7c50..e2fb9f1b2ed 100644 --- a/mozilla/modules/softupdt/classes/netscape/softupdate/Makefile +++ b/mozilla/modules/softupdt/classes/netscape/softupdate/Makefile @@ -20,6 +20,7 @@ DEPTH = ../../../../.. PACKAGE = netscape/softupdate JSRCS = FolderSpec.java \ + InstallDelete.java \ InstallExecute.java \ InstallFile.java \ InstallPatch.java \ diff --git a/mozilla/modules/softupdt/classes/netscape/softupdate/ProgressDetails.java b/mozilla/modules/softupdt/classes/netscape/softupdate/ProgressDetails.java index eaf80286e5c..d359e818679 100644 --- a/mozilla/modules/softupdt/classes/netscape/softupdate/ProgressDetails.java +++ b/mozilla/modules/softupdt/classes/netscape/softupdate/ProgressDetails.java @@ -19,7 +19,6 @@ * ProgressWindow * */ - package netscape.softupdate ; import java.awt.* ; @@ -56,4 +55,8 @@ class ProgressDetails extends SymProgressDetails pm = null; } } + //{{DECLARE_CONTROLS + //}} + //{{DECLARE_MENUS + //}} } diff --git a/mozilla/modules/softupdt/classes/netscape/softupdate/ProgressMediator.java b/mozilla/modules/softupdt/classes/netscape/softupdate/ProgressMediator.java index d4846f5c10c..1e003dda144 100644 --- a/mozilla/modules/softupdt/classes/netscape/softupdate/ProgressMediator.java +++ b/mozilla/modules/softupdt/classes/netscape/softupdate/ProgressMediator.java @@ -19,7 +19,6 @@ * ProgressMediator.java 4/16/97 * @author atotic */ - package netscape.softupdate; /** @@ -162,13 +161,19 @@ class ProgressMediator { UserApproved(); } + /* flash item on visible progress window */ + protected void + SetStatus(InstallObject install) + { + if (progress != null) + progress.progress.setText( install.toString() ); + } + /* Add it to the details list if showing */ protected void ScheduleForInstall(InstallObject install) { String s = install.toString(); - if (progress != null) // Display text in progress area - progress.progress.setText(s); if (details != null) details.detailArea.appendText(s + "\n"); } diff --git a/mozilla/modules/softupdt/classes/netscape/softupdate/SoftUpdateResourceBundle.java b/mozilla/modules/softupdt/classes/netscape/softupdate/SoftUpdateResourceBundle.java index bb968e56f20..9725ba2a75f 100644 --- a/mozilla/modules/softupdt/classes/netscape/softupdate/SoftUpdateResourceBundle.java +++ b/mozilla/modules/softupdt/classes/netscape/softupdate/SoftUpdateResourceBundle.java @@ -74,6 +74,14 @@ public class SoftUpdateResourceBundle extends ListResourceBundle { {"s37", "Installing Java class files in the \"Java Download\" directory. This form of access allows new files to be added to this single directory on your computer's main hard disk, potentially replacing other files that have previously been installed in the directory. "}, {"s38", "Installing software on your computer's main hard disk, potentially deleting other files on the hard disk. Each time a program that has this form of access attempts to install software, it must display a dialog box that lets you choose whether to go ahead with the installation. If you go ahead, the installation program can execute any software on your computer. This potentially dangerous form of access is typically requested by an installation program after you have downloaded new software or a new version of software that you have previously installed. You should not grant this form of access unless you are installing or updating software from a reliable source."}, {"s39", "Installing software on your computer's main hard disk without giving you any warning, potentially deleting other files on the hard disk. Any software on the hard disk may be executed in the process. This is an extremely dangerous form of access. It should be granted by system administrators only."}, + {"s40", "Failure while deleting file. File does not exist. "}, + {"s41", "Failure while deleting file. File is read only. "}, + {"s42", "Failure while deleting file. File is a directory. "}, + {"s43", "Delete file "}, + {"s44", "Failure while deleting component. Component not found in registry. "}, + {"s45", "Delete component "}, + {"s46", "Replace file "}, + {"s47", "Install file "}, // stop localizing }; } diff --git a/mozilla/modules/softupdt/classes/netscape/softupdate/SoftwareUpdate.java b/mozilla/modules/softupdt/classes/netscape/softupdate/SoftwareUpdate.java index 986b4a0cc2e..4625739c2f0 100644 --- a/mozilla/modules/softupdt/classes/netscape/softupdate/SoftwareUpdate.java +++ b/mozilla/modules/softupdt/classes/netscape/softupdate/SoftwareUpdate.java @@ -40,137 +40,101 @@ import netscape.javascript.JSObject; final public class SoftwareUpdate { /* Security strategy - * Only two main targets, limited and full install - * Limited install is Java folders only, full install everything else * Each routine that does something unsafe checks the permissions there */ - static String targetNames[] = { - "LimitedInstall", // Install Java classes into a single directory - "SoftwareInstall", // Any other install actions - "SilentInstall" // Install without any UI - }; + // leave the numeric constants for backward compatibility! public static final int LIMITED_INSTALL= 0; public static final int FULL_INSTALL = 1; public static final int SILENT_INSTALL = 2; protected static final String IMPERSONATOR = "Impersonator"; + public static final String INSTALL_PRIV = "SoftwareInstall"; + public static final String SILENT_PRIV = "SilentInstall"; + public static final String FOLDER_FILE_URL = "File URL"; /* Errors -200 to -300 */ - static final int BAD_PACKAGE_NAME = -200; - static final int UNEXPECTED_ERROR = -201; - static final int ACCESS_DENIED = -202; - static final int TOO_MANY_CERTIFICATES = -203; // Installer file must have 1 certificate - static final int NO_INSTALLER_CERTIFICATE = -204; // Installer file must have a certificate - static final int NO_CERTIFICATE = -205; // Extracted file is not signed - static final int NO_MATCHING_CERTIFICATE = -206; // Extracted file does not match installer certificate - static final int UNKNOWN_JAR_FILE = -207; // JAR file has not been opened - static final int INVALID_ARGUMENTS = -208; // Bad arguments to a function - static final int ILLEGAL_RELATIVE_PATH = -209; // Illegal relative path - static final int USER_CANCELLED = -210; // User cancelled - static final int INSTALL_NOT_STARTED = -211; - static final int SILENT_MODE_DENIED = -212; - static final int NO_SUCH_COMPONENT = -213; // no such component in the registry. + public static final int BAD_PACKAGE_NAME = -200; + public static final int UNEXPECTED_ERROR = -201; + public static final int ACCESS_DENIED = -202; + public static final int TOO_MANY_CERTIFICATES = -203; // Installer file must have 1 certificate + public static final int NO_INSTALLER_CERTIFICATE = -204; // Installer file must have a certificate + public static final int NO_CERTIFICATE = -205; // Extracted file is not signed + public static final int NO_MATCHING_CERTIFICATE = -206; // Extracted file does not match installer certificate + public static final int UNKNOWN_JAR_FILE = -207; // JAR file has not been opened + public static final int INVALID_ARGUMENTS = -208; // Bad arguments to a function + public static final int ILLEGAL_RELATIVE_PATH = -209; // Illegal relative path + public static final int USER_CANCELLED = -210; // User cancelled + public static final int INSTALL_NOT_STARTED = -211; + public static final int SILENT_MODE_DENIED = -212; + public static final int NO_SUCH_COMPONENT = -213; // no such component in the registry. + public static final int FILE_DOES_NOT_EXIST = -214; //File cannot be deleted as it does not exist + public static final int FILE_READ_ONLY = -215; // File cannot be deleted as it is read only. + public static final int FILE_IS_DIRECTORY = -216; // File cannot be deleted as it is a directory + public static final int NOT_IN_REGISTRY = -217; // Component not found in registry + public static final int APPLE_SINGLE_ERR = -218; // error in AppleSingle unpacking - static final int SUCCESS = 0; - static final int REBOOT_NEEDED = 999; + public static final int SUCCESS = 0; + public static final int REBOOT_NEEDED = 999; - static { - /* Create security targets */ - netscape.security.UserTarget t1, t2, t3; - netscape.security.Principal sysPrin = PrivilegeManager.getSystemPrincipal(); - // t1 = new netscape.security.Target(targetNames[EXTRACT_JAR_FILE], sysPrin).registerTarget(); - t1 = new netscape.security.UserTarget(targetNames[LIMITED_INSTALL], sysPrin, - UserDialogHelper.targetRiskMedium(), - UserDialogHelper.targetRiskColorMedium(), - Strings.targetDesc_LimitedInstall(), - Strings.getString("s37"), - Strings.targetUrl_LimitedInstall() - ); - t1 = (UserTarget)t1.registerTarget(); - - Target[] tarray; - tarray = new Target[1]; - tarray[0] = t1; - t2 = new netscape.security.UserTarget(targetNames[FULL_INSTALL], sysPrin, - UserDialogHelper.targetRiskHigh(), - UserDialogHelper.targetRiskColorHigh(), - Strings.targetDesc_FullInstall(), - Strings.getString("s38"), - Strings.targetUrl_FullInstall(), - tarray); - t2 = (UserTarget)t2.registerTarget(); - tarray[0] = t2; - t3 = new netscape.security.UserTarget(targetNames[SILENT_INSTALL], sysPrin, - UserDialogHelper.targetRiskHigh(), - UserDialogHelper.targetRiskColorHigh(), - Strings.targetDesc_SilentInstall(), - Strings.getString("s39"), - Strings.targetUrl_SilentInstall(), - tarray); - t3 = (UserTarget)t3.registerTarget(); - }; - - protected String packageName; // Name of the package we are installing - protected String userPackageName; // User-readable package name - protected Vector installedFiles; // List of files/processes to be installed + protected String packageName; // Name of the package we are installing + protected String userPackageName; // User-readable package name + protected Vector installedFiles; // List of files/processes to be installed protected Hashtable patchList; // files that have been patched (orig name is key) - protected VersionInfo versionInfo; // Component version info - + protected VersionInfo versionInfo; // Component version info private FolderSpec packageFolder; // default folder for package - private ProgressMediator progress; // Progress feedback + private ProgressMediator progress; // Progress feedback private int userChoice; // User feedback: -1 unknown, 0 is cancel, 1 is OK - private boolean silent; // Silent upgrade? + private boolean silent; // Silent upgrade? private boolean force; // Force install? private int lastError; // the most recent non-zero error + - /** - * @param env JavaScript environment (this inside the installer). Contains installer directives - * @param inUserPackageName Name of tha package installed. This name is displayed to the user - */ - public - SoftwareUpdate( JSObject env, String inUserPackageName) - { - userPackageName = inUserPackageName; - installPrincipal = null; - packageName = null; - packageFolder = null; - progress = null; - patchList = new java.util.Hashtable(); - zigPtr = 0; - userChoice = -1; + /** + * @param env JavaScript environment (this inside the installer). Contains installer directives + * @param inUserPackageName Name of tha package installed. This name is displayed to the user + */ + public + SoftwareUpdate( JSObject env, String inUserPackageName) + { + userPackageName = inUserPackageName; + installPrincipal = null; + packageName = null; + packageFolder = null; + progress = null; + patchList = new java.util.Hashtable(); + zigPtr = 0; + userChoice = -1; lastError = 0; - /* Need to verify that this is a SoftUpdate JavaScript object */ - VerifyJSObject(env); - jarName = (String) env.getMember("src"); + /* Need to verify that this is a SoftUpdate JavaScript object */ + VerifyJSObject(env); + jarName = (String) env.getMember("src"); + try + { + silent = ((Boolean) env.getMember("silent")).booleanValue(); + force = ((Boolean) env.getMember("force")).booleanValue(); + } + catch (Throwable t) + { + System.out.println("Unexpected throw getting silent/force" ); + silent = false; + force = false; + } + } - try - { - silent = ((Boolean) env.getMember("silent")).booleanValue(); - force = ((Boolean) env.getMember("force")).booleanValue(); - } - catch (Throwable t) - { - System.out.println("Unexpected throw getting silent/force" ); - silent = false; - force = false; - } - } - - protected void - finalize() throws Throwable - { - CleanUp(); - super.finalize(); - } - - /* VerifyJSObject - * Make sure that JSObject is of type SoftUpdate. - * Since SoftUpdate JSObject can only be created by C code - * we cannot be spoofed - */ - private native void - VerifyJSObject(JSObject obj); + protected void + finalize() throws Throwable + { + CleanUp(); + super.finalize(); + } + /* VerifyJSObject + * Make sure that JSObject is of type SoftUpdate. + * Since SoftUpdate JSObject can only be created by C code + * we cannot be spoofed + */ + private native void + VerifyJSObject(JSObject obj); /* * Reads in the installer certificate, and creates its principal */ @@ -181,8 +145,8 @@ final public class SoftwareUpdate { certArray = getCertificates( zigPtr, installerJarName ); - if ( certArray == null || certArray.length == 0 ) - throw new SoftUpdateException( Strings.error_NoCertificate(), NO_INSTALLER_CERTIFICATE) ; + if ( certArray == null || certArray.length == 0 ) + throw new SoftUpdateException( Strings.error_NoCertificate(), NO_INSTALLER_CERTIFICATE) ; if ( certArray.length > 1 ) throw new SoftUpdateException( Strings.error_TooManyCertificates(), TOO_MANY_CERTIFICATES); @@ -210,10 +174,9 @@ final public class SoftwareUpdate { privMgr.enablePrivilege( impersonation ); /* check the security permissions */ - target = Target.findTarget( targetNames[SILENT_INSTALL] ); + target = Target.findTarget( SILENT_PRIV ); - /* XXX: we need a way to indicate that a dialog box should appear.*/ - privMgr.enablePrivilege( target, GetPrincipal() ); + privMgr.checkPrivilegeGranted( target, GetPrincipal(), null ); } catch(Throwable t) { @@ -226,12 +189,8 @@ final public class SoftwareUpdate { * pop up */ private void - RequestSecurityPrivileges(int securityLevel) + RequestSecurityPrivileges() { - if ((securityLevel != LIMITED_INSTALL) && - (securityLevel != FULL_INSTALL)) - securityLevel = FULL_INSTALL; - netscape.security.PrivilegeManager privMgr; Target impersonation, target; @@ -240,10 +199,8 @@ final public class SoftwareUpdate { privMgr.enablePrivilege( impersonation ); /* check the security permissions */ - target = Target.findTarget( SoftwareUpdate.targetNames[securityLevel] ); -// System.out.println("Asking for privileges "); + target = Target.findTarget( INSTALL_PRIV ); privMgr.enablePrivilege( target, GetPrincipal() ); -// System.out.println("Got privileges "); } protected final netscape.security.Principal @@ -256,6 +213,11 @@ final public class SoftwareUpdate { return userPackageName; } + protected final String + GetRegPackageName() { + return packageName; + } + protected final boolean GetSilent() { return silent; @@ -272,7 +234,6 @@ final public class SoftwareUpdate { return null; } - /** * @return the most recent non-zero error code * @see ResetError @@ -303,40 +264,38 @@ final public class SoftwareUpdate { + /** + * @return the folder object suitable to be passed into AddSubcomponent + * @param folderID One of the predefined folder names + * @see AddSubcomponent + */ + public FolderSpec + GetFolder(String folderID) + { + FolderSpec spec = null; + try + { + int errCode = 0; - - /** - * @return the folder object suitable to be passed into AddSubcomponent - * @param folderID One of the predefined folder names - * @see AddSubcomponent - */ - public FolderSpec - GetFolder(String folderID) - { - FolderSpec spec = null; - try - { - int errCode = 0; - - if (folderID.compareTo("Installed") != 0) - { - spec = new FolderSpec(folderID, packageName, userPackageName); - if (folderID == "User Pick") // Force the prompt - { - String ignore = spec.GetDirectoryPath(); - } - } - } - catch (Throwable e) - { - return null; - } - return spec; - } + if ((folderID.compareTo("Installed") != 0) && (folderID.compareTo(FOLDER_FILE_URL) != 0)) + { + spec = new FolderSpec(folderID, packageName, userPackageName); + if (folderID == "User Pick") // Force the prompt + { + String ignore = spec.GetDirectoryPath(); + } + } + } + catch (Throwable e) + { + return null; + } + return spec; + } /** - * @return the full path to a component as it is known to the + * @return the full path to a component as it is known to the * Version Registry * @param component Version Registry component name */ @@ -484,7 +443,7 @@ final public class SoftwareUpdate { Target target; PrivilegeManager privMgr; privMgr = AppletSecurity.getPrivilegeManager(); - target = Target.findTarget( targetNames[LIMITED_INSTALL] ); + target = Target.findTarget( INSTALL_PRIV ); privMgr.checkPrivilegeEnabled(target); @@ -546,33 +505,44 @@ final public class SoftwareUpdate { StartInstall(String vrPackageName, VersionInfo inVInfo, int securityLevel) + { + // ignore securityLevel + return StartInstall( vrPackageName, inVInfo ); + } + + + /** + * An new form that doesn't require the security level + */ + public int + StartInstall(String vrPackageName, VersionInfo inVInfo ) { int errcode = SUCCESS; ResetError(); - try - { - if ( (vrPackageName == null) ) - throw new SoftUpdateException( Strings.error_BadPackageName() , INVALID_ARGUMENTS ); + try + { + if ( (vrPackageName == null) ) + throw new SoftUpdateException( Strings.error_BadPackageName() , INVALID_ARGUMENTS ); - packageName = vrPackageName; - while ( packageName.endsWith("/")) // Make sure that package name does not end with '/' - { - char c[] = new char[packageName.length() - 1]; - packageName.getChars(0, packageName.length() -1, c, 0); - packageName = new String( c ); - // System.out.println("Truncated package name is " + packageName); + packageName = vrPackageName; + while ( packageName.endsWith("/")) // Make sure that package name does not end with '/' + { + char c[] = new char[packageName.length() - 1]; + packageName.getChars(0, packageName.length() -1, c, 0); + packageName = new String( c ); + // System.out.println("Truncated package name is " + packageName); - } - versionInfo = inVInfo; - installedFiles = new java.util.Vector(); + } + versionInfo = inVInfo; + installedFiles = new java.util.Vector(); - /* JAR initalization */ - /* open the file, create a principal out of installer file certificate */ - OpenJARFile(); + /* JAR initalization */ + /* open the file, create a principal out of installer file certificate */ + OpenJARFile(); InitializeInstallerCertificate(); CheckSilentPrivileges(); - RequestSecurityPrivileges(securityLevel); + RequestSecurityPrivileges(); progress = new ProgressMediator(this); progress.StartInstall(); @@ -583,30 +553,36 @@ final public class SoftwareUpdate { packageFolder = new FolderSpec("Installed", path, userPackageName); } } - - catch(SoftUpdateException e) + catch(SoftUpdateException e) + { + errcode = e.GetError(); + } + catch(ForbiddenTargetException e) { - errcode = e.GetError(); - } - catch(Exception e) - { - e.printStackTrace(); - errcode = UNEXPECTED_ERROR; + errcode = ACCESS_DENIED; } + catch(Exception e) + { + e.printStackTrace(); + errcode = UNEXPECTED_ERROR; + } saveError( errcode ); return errcode; - } + } /** - * An alternate form that doesn't require the security level + * another StartInstall() simplification -- version as string */ public int - StartInstall(String vrPackageName, VersionInfo inVInfo ) + StartInstall(String vrPackageName, String inVer ) { - return StartInstall( vrPackageName, inVInfo, FULL_INSTALL ); + return StartInstall( vrPackageName, new VersionInfo( inVer ) ); } + + + /* * UI feedback */ @@ -632,11 +608,10 @@ final public class SoftwareUpdate { FinalizeInstall() { boolean rebootNeeded = false; - int result = SUCCESS; - try - { - - if (packageName == null) // didn't call StartInstall() + int result = SUCCESS; + try + { + if (packageName == null) // probably didn't call StartInstall() { throw new SoftUpdateException( Strings.error_WinProfileMustCallStart(), @@ -669,6 +644,7 @@ final public class SoftwareUpdate { try // Main loop { + VersionRegistry.uninstallCreate(packageName, userPackageName); while ( ve.hasMoreElements() ) { ie = (InstallObject)ve.nextElement(); @@ -676,7 +652,7 @@ final public class SoftwareUpdate { ie.Complete(); } catch (SoftUpdateException e) { - if (e.GetError() == REBOOT_NEEDED) + if (e.GetError() == REBOOT_NEEDED) rebootNeeded = true; else throw e; @@ -684,23 +660,23 @@ final public class SoftwareUpdate { } } catch (Throwable e) - { - if (ie != null) + { + if (ie != null) ie.Abort(); while (ve.hasMoreElements()) - { - try - { - ie = (InstallObject)ve.nextElement(); - ie.Abort(); - } - catch(Throwable t) - { - // t.printStackTrace(); - } + { + try + { + ie = (InstallObject)ve.nextElement(); + ie.Abort(); + } + catch(Throwable t) + { + // t.printStackTrace(); + } } - throw(e); // Rethrow out of main loop + throw(e); // Rethrow out of main loop } // add overall version for package @@ -709,24 +685,24 @@ final public class SoftwareUpdate { result = VersionRegistry.installComponent( packageName, null, versionInfo ); } - } - catch (SoftUpdateException e) - { - result = e.GetError(); - } - catch (netscape.security.AppletSecurityException e) - { - result = ACCESS_DENIED; - } - catch (Throwable e) - { - e.printStackTrace(); - System.out.println( Strings.error_Unexpected() + " FinalizeInstall"); - result = UNEXPECTED_ERROR; - } - finally - { - if ( installedFiles != null ) + } + catch (SoftUpdateException e) + { + result = e.GetError(); + } + catch (ForbiddenTargetException e) + { + result = ACCESS_DENIED; + } + catch (Throwable e) + { + e.printStackTrace(); + System.out.println( Strings.error_Unexpected() + " FinalizeInstall"); + result = UNEXPECTED_ERROR; + } + finally + { + if ( installedFiles != null ) installedFiles.removeAllElements(); CleanUp(); } @@ -736,59 +712,58 @@ final public class SoftwareUpdate { saveError( result ); return result; - } +} - /** - * Aborts the install :), cleans up all the installed files - */ - public synchronized void AbortInstall() - { - try - { - if (installedFiles != null) - { - java.util.Enumeration ve = GetInstallQueue(); - while ( ve.hasMoreElements() ) - { - InstallObject ie; - ie = (InstallObject)ve.nextElement(); - try // We just want to loop through all of them if possible - { - ie.Abort(); - } - catch (Throwable t) - { - } - } - installedFiles.removeAllElements(); - installedFiles = null; - } - CloseJARFile(); - } - catch (Throwable e) - { - System.out.println( Strings.error_Unexpected() + " AbortInstall"); - e.printStackTrace(); - } - finally - { - try { - CleanUp(); - } - catch (Throwable e) { - e.printStackTrace(); - } - } - } - - /* - * CleanUp - * call it when done with the install - * - */ - private synchronized void CleanUp() - { + /** + * Aborts the install :), cleans up all the installed files + */ + public synchronized void AbortInstall() + { + try + { + if (installedFiles != null) + { + java.util.Enumeration ve = GetInstallQueue(); + while ( ve.hasMoreElements() ) + { + InstallObject ie; + ie = (InstallObject)ve.nextElement(); + try // We just want to loop through all of them if possible + { + ie.Abort(); + } + catch (Throwable t) + { + } + } + installedFiles.removeAllElements(); + installedFiles = null; + } + CloseJARFile(); + } + catch (Throwable e) + { + System.out.println( Strings.error_Unexpected() + " AbortInstall"); + e.printStackTrace(); + } + finally + { + try { + CleanUp(); + } + catch (Throwable e) { + e.printStackTrace(); + } + } + } + /* + * CleanUp + * call it when done with the install + * + */ + private synchronized void CleanUp() + { if (progress != null) progress.Complete(); @@ -818,11 +793,20 @@ final public class SoftwareUpdate { * Do not call installedFiles.addElement directly, because this routine also handles * progress messages */ - protected void ScheduleForInstall(InstallObject ob) + protected void ScheduleForInstall(InstallObject ob) throws SoftUpdateException { + // flash current item + if (progress != null) + progress.SetStatus( ob ); + + // do any unpacking or other set-up + ob.Prepare(); + + + // Add to installation list if we haven't thrown out + installedFiles.addElement( ob ); if (progress != null) progress.ScheduleForInstall( ob ); - installedFiles.addElement( ob ); } /** @@ -846,8 +830,6 @@ final public class SoftwareUpdate { return name; } - - /** * Extract a file from JAR archive to the disk, and update the * version registry. Actually, keep a record of elements to be installed. FinalizeInstall() @@ -868,30 +850,23 @@ final public class SoftwareUpdate { * @param relativePath where the file should be copied to on the local disk. * Relative to folder * if null, use the path to the JAR source. - * @param forceInstall if true, file is always replaced - * XXX Subdirectory stuff NOT IMPLEMENED YET - * jarSource and localDestionation can also point to directories. In this case, - * directory will be recursively copied from jarSource to localDestination, with - * version of each file specified in VersionInfo agument. If - * one points to a file, and another to a directory, that is an error. - * If jarSource points to a directory and localDestination doesn't exist it - * is created as a directory. - */ - public int AddSubcomponent(String name, - VersionInfo version, - String jarSource, - FolderSpec folderSpec, - String relativePath, - boolean forceInstall) - { - InstallFile ie; - int result = SUCCESS; - try - { + * @param forceInstall if true, file is always replaced + */ + public int AddSubcomponent(String name, + VersionInfo version, + String jarSource, + FolderSpec folderSpec, + String relativePath, + boolean forceInstall) + { + InstallFile ie; + int result = SUCCESS; + try + { if ( jarSource == null || jarSource.length() == 0 || folderSpec == null ) throw (new SoftUpdateException( "", INVALID_ARGUMENTS )); - if (packageName == null) { + if (packageName == null) { // probably didn't call StartInstall() throw new SoftUpdateException( Strings.error_BadPackageNameAS(), BAD_PACKAGE_NAME); @@ -904,51 +879,50 @@ final public class SoftwareUpdate { else name = GetQualifiedRegName( name ); - if ( (relativePath == null) || (relativePath.length() == 0)) - relativePath = jarSource; + if ( (relativePath == null) || (relativePath.length() == 0)) + relativePath = jarSource; - /* Check for existence of the newer version */ + /* Check for existence of the newer version */ - boolean versionNewer = false; - if ( (forceInstall == false ) && - (version != null) && - ( VersionRegistry.validateComponent( name ) == 0 ) ) - { - VersionInfo oldVersion = VersionRegistry.componentVersion(name); - if ( version.compareTo( oldVersion ) > 0 ) - versionNewer = true; - } - else - versionNewer = true; + boolean versionNewer = false; + if ( (forceInstall == false ) && + (version != null) && + ( VersionRegistry.validateComponent( name ) == 0 ) ) + { + VersionInfo oldVersion = VersionRegistry.componentVersion(name); + if ( version.compareTo( oldVersion ) > 0 ) + versionNewer = true; + } + else + versionNewer = true; - if (versionNewer) - { - ie = new InstallFile( this, name, version, jarSource, + if (versionNewer) + { + ie = new InstallFile( this, name, version, jarSource, folderSpec, relativePath, forceInstall ); - ie.ExtractFile(); - ScheduleForInstall( ie ); - } - } - catch (SoftUpdateException e) - { - result = e.GetError(); - } - catch (netscape.security.AppletSecurityException e) - { - result = ACCESS_DENIED; - } - catch (Throwable e) - { - System.out.println(Strings.error_Unexpected() + "AddSubcomponent"); - e.printStackTrace(); - result = UNEXPECTED_ERROR; - } + ScheduleForInstall( ie ); + } + } + catch (SoftUpdateException e) + { + result = e.GetError(); + } + catch (ForbiddenTargetException e) + { + result = ACCESS_DENIED; + } + catch (Throwable e) + { + System.out.println(Strings.error_Unexpected() + "AddSubcomponent"); + e.printStackTrace(); + result = UNEXPECTED_ERROR; + } saveError( result ); - return result; - } - + return result; + } + /** * Various alternate flavors of AddSubcomponent() */ @@ -1005,8 +979,7 @@ final public class SoftwareUpdate { return AddSubcomponent( regname, version, jarSource, folderSpec, relativePath, force ); } - - /** + /** * executes the file * @param jarSource name of the file to execute inside JAR archive * @param args command-line argument string (Win/Unix only) @@ -1017,37 +990,34 @@ final public class SoftwareUpdate { return Execute( jarSource, null ); } - public int - Execute(String jarSource, String args) - { + public int + Execute(String jarSource, String args) + { int errcode = SUCCESS; - try - { - InstallExecute ie = new InstallExecute( this, jarSource, args ); - ie.ExtractFile(); - ScheduleForInstall( ie ); - } - catch (SoftUpdateException e) - { - errcode = e.GetError(); - } - catch (netscape.security.AppletSecurityException e) - { - errcode = ACCESS_DENIED; - } - catch (Throwable e) - { - e.printStackTrace(); - System.out.println(Strings.error_Unexpected() + "Execute"); - errcode = UNEXPECTED_ERROR; - } + try + { + InstallExecute ie = new InstallExecute( this, jarSource, args); + ScheduleForInstall( ie ); + } + catch (SoftUpdateException e) + { + errcode = e.GetError(); + } + catch (ForbiddenTargetException e) + { + errcode = ACCESS_DENIED; + } + catch (Throwable e) + { + e.printStackTrace(); + System.out.println(Strings.error_Unexpected() + "Execute"); + errcode = UNEXPECTED_ERROR; + } saveError( errcode ); - return errcode; - } - - + return errcode; + } /** * Mac-only, simulates Mac toolbox Gestalt function @@ -1077,7 +1047,7 @@ final public class SoftwareUpdate { return a; } - private native int + private native int NativeGestalt(String selector) throws SoftUpdateException; @@ -1098,7 +1068,6 @@ final public class SoftwareUpdate { try { InstallPatch ip = new InstallPatch(this, rname, version, patchname); - ip.ApplyPatch(); ScheduleForInstall( ip ); } catch (SoftUpdateException e) { @@ -1133,7 +1102,6 @@ final public class SoftwareUpdate { InstallPatch ip = new InstallPatch( this, rname, version, patchname, folder, filename ); - ip.ApplyPatch(); ScheduleForInstall( ip ); } catch (SoftUpdateException e) { @@ -1154,60 +1122,114 @@ final public class SoftwareUpdate { return Patch( regName, versionInfo, patchname, folder, file ); } - private native int NativeDeleteFile(String path); - private native int NativeVerifyDiskspace (String path, int bytesRequired); - private native int NativeMakeDirectory (String path); - private native String[] ExtractDirEntries(String Dir); + private native int NativeMakeDirectory (String path); - public int DeleteFile( FolderSpec folder, String relativeFileName ) + /** + * This method deletes the specified file from the disk. It does not look + * for the file in the registry and is guaranteed to muddle any uninstall + * reference counting. Its main purpose is to delete files installed or + * created outside of SmartUpdate. + */ + public int DeleteFile(FolderSpec folder, String relativeFileName) + { + int errcode = SUCCESS; + + try + { + InstallDelete id = new InstallDelete( this, folder, relativeFileName ); + ScheduleForInstall( id ); + } + catch (SoftUpdateException e) + { + errcode = e.GetError(); + if (errcode == FILE_DOES_NOT_EXIST) { + errcode = SUCCESS; + } + } + catch (netscape.security.AppletSecurityException e) + { + errcode = ACCESS_DENIED; + } + catch (Throwable e) + { + e.printStackTrace(); + errcode = UNEXPECTED_ERROR; + } + + saveError( errcode ); + return errcode; + } + + + /** + * This method finds named registry component and deletes both the file and the + * entry in the Client VR. registryName is the name of the component in the registry. + * Returns usual errors codes + code to indicate item doesn't exist in registry, registry + * item wasn't a file item, or the related file doesn't exist. If the file is in use we will + * store the name and to try to delete it on subsequent start-ups until we're successful. + */ + public int DeleteComponent(String registryName) { - // deletes specified file from disk w/o looking in the registry. folder object obtained - // using GetFolder() representing directory containing file. relative path and file name - // Returns usual error codes + an error indicating file does not exist. - - String path; - int status = -1; - - try - { - path = ((FolderSpec)folder).MakeFullPath(relativeFileName); - status = NativeDeleteFile(path); - } - catch ( Exception e ) - { - path = null; - } - return status; + int errcode = SUCCESS; + + try + { + InstallDelete id = new InstallDelete( this, registryName ); + ScheduleForInstall( id ); + } + catch (SoftUpdateException e) + { + errcode = e.GetError(); + if (errcode == FILE_DOES_NOT_EXIST) { + errcode = SUCCESS; + } + } + catch (netscape.security.AppletSecurityException e) + { + errcode = ACCESS_DENIED; + } + catch (Throwable e) + { + e.printStackTrace(); + errcode = UNEXPECTED_ERROR; + } + if (errcode == FILE_DOES_NOT_EXIST) + { + errcode = SUCCESS; + } + saveError( errcode ); + return errcode; } - - public int DeleteComponent(String registryName) - { - // Finds named registry component and deletes both the file and the entry in the Client - // VR. registryNameThe name of the component in the registry. - // Returns usual errors codes + code to indicate item doesn't exist in registry, registry - // item wasn't a file item, or the related file doesn't exist. If the file is in use we will - // store the name and to try to delete it on subsequent start-ups until we're successful. - - int status = -1; - - FolderSpec spec = (FolderSpec)GetComponentFolder(registryName, null); - - if (spec != null) - { - status = VersionRegistry.deleteComponent(registryName); - if ( status == 0 ) - status = DeleteFile(spec, ""); /*XXX*/ - } - return status; - } - - + public FolderSpec GetFolder( String targetFolder, String subdirectory ) { - return GetFolder( GetFolder(targetFolder), subdirectory ); + if (targetFolder.compareTo(FOLDER_FILE_URL) == 0) + { + String newPath; + String path = NativeFileURLToNative("/"+subdirectory ); + if ( path != null ) + { + if (path.endsWith(System.getProperty("file.separator"))) + { + return new FolderSpec("Installed", path, userPackageName); + } + else + { + newPath = path + System.getProperty("file.separator"); + return new FolderSpec("Installed", newPath, userPackageName); + } + } + else + return null; + } + else + return GetFolder( GetFolder(targetFolder), subdirectory ); } + private native long NativeDiskSpaceAvailable (String path); + private native String NativeFileURLToNative (String path); + private native String[] ExtractDirEntries(String Dir); public FolderSpec GetFolder( FolderSpec folder, String subdir ) { @@ -1230,32 +1252,34 @@ final public class SoftwareUpdate { if (path != null) { - newPath = path + System.getProperty("file.separator"); - spec = new FolderSpec("Installed", newPath, userPackageName); - if (spec != null) - { - if (NativeMakeDirectory(path) != 0) - spec = null; - } + if (path.endsWith(System.getProperty("file.separator"))) + { + spec = new FolderSpec("Installed", path, userPackageName); + } + else + { + newPath = path + System.getProperty("file.separator"); + spec = new FolderSpec("Installed", newPath, userPackageName); + } } } return spec; } - - - // Returns true if there is enough free diskspace, false if there isn't. - // The drive containg the folder is checked for # of free bytes. - - public boolean VerifyDiskspace( FolderSpec folder, int bytesRequired ) + + + /** + * This method returns true if there is enough free diskspace, false if there isn't. + * The drive containg the folder is checked for # of free bytes. + */ + public long DiskSpaceAvailable( FolderSpec folder ) { String path = folder.toString(); if (path == null) - return false; - - return ( (NativeVerifyDiskspace (path, bytesRequired)) != 0); + return 0; + return NativeDiskSpaceAvailable (path); } @@ -1340,7 +1364,7 @@ final public class SoftwareUpdate { (FolderSpec) folderSpec, subdir + matchingFiles[i], forceInstall ); - ie.ExtractFile(); + ScheduleForInstall( ie ); } } @@ -1414,4 +1438,15 @@ final public class SoftwareUpdate { return AddDirectory( regName, version, jarSource, folder, subdir, force ); } + + // Uninstall + + public int Uninstall(String packageName) + { + return NativeUninstall(packageName); + } + + private native int NativeUninstall (String packageName); + } + diff --git a/mozilla/modules/softupdt/classes/netscape/softupdate/Strings.java b/mozilla/modules/softupdt/classes/netscape/softupdate/Strings.java index 4743eca526e..21277769f52 100644 --- a/mozilla/modules/softupdt/classes/netscape/softupdate/Strings.java +++ b/mozilla/modules/softupdt/classes/netscape/softupdate/Strings.java @@ -157,6 +157,22 @@ class Strings { static String details_ExecuteProgress() { return getString("s16"); + } + + static String details_DeleteFile() { + return getString("s43"); + } + + static String details_DeleteComponent() { + return getString("s45"); + } + + static String details_ReplaceFile() { + return getString("s46"); + } + + static String details_InstallFile() { + return getString("s47"); } // ERROR STRINGS @@ -229,4 +245,20 @@ class Strings { return error_Prefix() + getString("s32"); } + static String error_FileDoesNotExist() { + return error_Prefix() + getString("s40"); + } + + static String error_FileReadOnly() { + return error_Prefix() + getString("s41"); + } + + static String error_FileIsDirectory() { + return error_Prefix() + getString("s42"); + } + + static String error_NotInRegistry() { + return error_Prefix() + getString("s44"); + } + } \ No newline at end of file diff --git a/mozilla/modules/softupdt/classes/netscape/softupdate/SymProgressDetails.java b/mozilla/modules/softupdt/classes/netscape/softupdate/SymProgressDetails.java index 7a218b7bd03..33518b15fd2 100644 --- a/mozilla/modules/softupdt/classes/netscape/softupdate/SymProgressDetails.java +++ b/mozilla/modules/softupdt/classes/netscape/softupdate/SymProgressDetails.java @@ -48,6 +48,7 @@ public class SymProgressDetails extends Frame { add(label1); detailArea = new java.awt.TextArea(); detailArea.reshape(insets().left + 12,insets().top + 60,536,216); + detailArea.setFont(new Font("Dialog", Font.PLAIN, 10)); add(detailArea); btnCancel = new java.awt.Button("xxxCxxx"); btnCancel.reshape(insets().left + 464,insets().top + 288,84,26); diff --git a/mozilla/modules/softupdt/classes/netscape/softupdate/SymProgressWindow.java b/mozilla/modules/softupdt/classes/netscape/softupdate/SymProgressWindow.java index dac91345a64..e8f94ba41af 100644 --- a/mozilla/modules/softupdt/classes/netscape/softupdate/SymProgressWindow.java +++ b/mozilla/modules/softupdt/classes/netscape/softupdate/SymProgressWindow.java @@ -18,7 +18,6 @@ /* A basic extension of the java.awt.Window class */ - package netscape.softupdate; import java.awt.*; @@ -47,7 +46,7 @@ public class SymProgressWindow extends Frame { add(status); progress = new java.awt.Label("xxxxxxxxxxx"); progress.reshape(insets().left + 12,insets().top + 48,472,40); - progress.setFont(new Font("Courier", Font.PLAIN, 14)); + progress.setFont(new Font("Dialog", Font.PLAIN, 10)); add(progress); install = new java.awt.Button("xxxxxIxxx"); install.reshape(insets().left + 12,insets().top + 96,108,32); diff --git a/mozilla/modules/softupdt/classes/netscape/softupdate/VersionRegistry.java b/mozilla/modules/softupdt/classes/netscape/softupdate/VersionRegistry.java index 11e54339d7e..e4426225929 100644 --- a/mozilla/modules/softupdt/classes/netscape/softupdate/VersionRegistry.java +++ b/mozilla/modules/softupdt/classes/netscape/softupdate/VersionRegistry.java @@ -78,6 +78,17 @@ final class VersionRegistry implements RegistryErrors { protected static native int installComponent( String name, String path, VersionInfo version ); + protected static int installComponent( String name, String path, + VersionInfo version, int refCount ) + { + int err = installComponent( name, path, version ); + + if ( err == REGERR_OK ) + err = setRefCount( name, refCount ); + return err; + } + + /** * Delete component. * @param component Registry path of the item to delete @@ -118,6 +129,102 @@ final class VersionRegistry implements RegistryErrors { protected static Enumeration elements() { return new VerRegEnumerator(); } + + /** + * Set the refcount of a named component. + * @param component Registry path of the item to check + * @param refcount value to be set + * @return Error code + */ + protected static native int setRefCount( String component, int refcount ); + + /** + * Return the refcount of a named component. + * @param component Registry path of the item to check + * @return the value of refCount + */ + protected static native Integer getRefCount( String component ); + + /** + * Creates a node for the item in the Uninstall list. + * @param regPackageName Registry name of the package we are installing + * @return userPackagename User-readable package name + * @return Error code + */ + protected static int uninstallCreate( String regPackageName, String userPackageName ) + { + String temp = convertPackageName(regPackageName); + regPackageName = temp; + return uninstallCreateNode(regPackageName, userPackageName); + } + + protected static native int uninstallCreateNode( String regPackageName, String userPackageName ); + + /** + * Replaces all '/' with '_',in the given string.If an '_' already exists in the + * given string, it is escaped by adding another '_' to it. + * @param regPackageName Registry name of the package we are installing + * @return modified String + */ + private static String convertPackageName( String regPackageName ) + { + String tempStr = regPackageName; + String convertedPackageName; + boolean bSharedUninstall = false; + + if (regPackageName.startsWith("/")) + bSharedUninstall = true; + + int index = tempStr.indexOf('_'); + while (index != -1) + { + StringBuffer temp = new StringBuffer(tempStr); + temp.insert(index + 1, '_'); + tempStr = temp.toString(); + index = tempStr.indexOf('_', index + 2); + } + + convertedPackageName = tempStr.replace('/', '_'); + if (bSharedUninstall) + { + StringBuffer temp = new StringBuffer(convertedPackageName); + temp.setCharAt(0, '/'); + convertedPackageName = temp.toString(); + } + return convertedPackageName; + } + + + /** + * Adds the file as a property of the Shared Files node under the appropriate + * packageName node in the Uninstall list. + * @param regPackageName Registry name of the package installed + * @param vrName registry name of the shared file + * @return Error code + */ + protected static int uninstallAddFile( String regPackageName, String vrName ) + { + String temp = convertPackageName(regPackageName); + regPackageName = temp; + return uninstallAddFileToList(regPackageName, vrName); + } + + protected static native int uninstallAddFileToList( String regPackageName, String vrName ); + + /** + * Checks if the shared file exists in the uninstall list of the package + * @param regPackageName Registry name of the package installed + * @param vrName registry name of the shared file + * @return true or false + */ + protected static int uninstallFileExists( String regPackageName, String vrName ) + { + String temp = convertPackageName(regPackageName); + regPackageName = temp; + return uninstallFileExistsInList(regPackageName, vrName); + } + + protected static native int uninstallFileExistsInList( String regPackageName, String vrName ); } diff --git a/mozilla/modules/softupdt/classes/netscape/softupdate/WinProfile.java b/mozilla/modules/softupdt/classes/netscape/softupdate/WinProfile.java index 42b3e303074..ec5f52f9b5b 100644 --- a/mozilla/modules/softupdt/classes/netscape/softupdate/WinProfile.java +++ b/mozilla/modules/softupdt/classes/netscape/softupdate/WinProfile.java @@ -32,6 +32,19 @@ final class WinProfile { private Target impersonation; private UserTarget target; +// static final String INI_TARGET = "WindowsIniFile"; + +// /* create the target */ +// static { +// target = new ParameterizedTarget( +// INI_TARGET, +// PrivilegeManager.getSystemPrincipal(), +// UserDialogHelper.targetRiskMedium(), +// UserDialogHelper.targetRiskColorMedium(), +// Strings.targetDesc_WinIni(), +// Strings.targetUrl_WinIni() ); +// target = (ParameterizedTarget)target.registerTarget(); +// }; WinProfile( SoftwareUpdate suObj, FolderSpec folder, String file ) throws SoftUpdateException @@ -41,8 +54,7 @@ final class WinProfile { principal = suObj.GetPrincipal(); privMgr = PrivilegeManager.getPrivilegeManager(); impersonation = Target.findTarget( SoftwareUpdate.IMPERSONATOR ); - target = (UserTarget)Target.findTarget( - SoftwareUpdate.targetNames[SoftwareUpdate.FULL_INSTALL] ); + target = (UserTarget)Target.findTarget( SoftwareUpdate.INSTALL_PRIV ); } /** diff --git a/mozilla/modules/softupdt/classes/netscape/softupdate/WinProfileItem.java b/mozilla/modules/softupdt/classes/netscape/softupdate/WinProfileItem.java index 258ebe40960..8dfed0f2a05 100644 --- a/mozilla/modules/softupdt/classes/netscape/softupdate/WinProfileItem.java +++ b/mozilla/modules/softupdt/classes/netscape/softupdate/WinProfileItem.java @@ -68,4 +68,7 @@ final class WinProfileItem extends InstallObject { // no need for special clean-up protected void Abort() {} + + // no need for set-up + protected void Prepare() throws SoftUpdateException {} } diff --git a/mozilla/modules/softupdt/classes/netscape/softupdate/WinReg.java b/mozilla/modules/softupdt/classes/netscape/softupdate/WinReg.java index abe3d386abc..ec0e68e2717 100644 --- a/mozilla/modules/softupdt/classes/netscape/softupdate/WinReg.java +++ b/mozilla/modules/softupdt/classes/netscape/softupdate/WinReg.java @@ -64,8 +64,7 @@ final class WinReg { principal = suObj.GetPrincipal(); privMgr = PrivilegeManager.getPrivilegeManager(); impersonation = Target.findTarget( SoftwareUpdate.IMPERSONATOR ); - target = (UserTarget)Target.findTarget( - SoftwareUpdate.targetNames[ SoftwareUpdate.FULL_INSTALL ] ); + target = (UserTarget)Target.findTarget( SoftwareUpdate.INSTALL_PRIV ); } diff --git a/mozilla/modules/softupdt/classes/netscape/softupdate/WinRegItem.java b/mozilla/modules/softupdt/classes/netscape/softupdate/WinRegItem.java index 69a12cf15d3..e98dcfd40e4 100644 --- a/mozilla/modules/softupdt/classes/netscape/softupdate/WinRegItem.java +++ b/mozilla/modules/softupdt/classes/netscape/softupdate/WinRegItem.java @@ -132,4 +132,7 @@ final class WinRegItem extends InstallObject // no need for special clean-up protected void Abort() {} + + // no need for set-up + protected void Prepare() throws SoftUpdateException {} } diff --git a/mozilla/modules/softupdt/classes/netscape/softupdate/WinRegValue.java b/mozilla/modules/softupdt/classes/netscape/softupdate/WinRegValue.java index 20c0829614c..e9381a4481f 100644 --- a/mozilla/modules/softupdt/classes/netscape/softupdate/WinRegValue.java +++ b/mozilla/modules/softupdt/classes/netscape/softupdate/WinRegValue.java @@ -15,7 +15,6 @@ * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ - package netscape.softupdate; diff --git a/mozilla/modules/softupdt/classes/netscape/softupdate/makefile.win b/mozilla/modules/softupdt/classes/netscape/softupdate/makefile.win index a0317fb1926..3af7d4c75a9 100644 --- a/mozilla/modules/softupdt/classes/netscape/softupdate/makefile.win +++ b/mozilla/modules/softupdt/classes/netscape/softupdate/makefile.win @@ -24,6 +24,7 @@ JAVA_SOURCEPATH=$(DEPTH)\modules\softupdt\classes DEPTH=..\..\..\..\.. PACKAGE=netscape\softupdate JSRCS=FolderSpec.java \ + InstallDelete.java \ InstallExecute.java \ InstallFile.java \ InstallPatch.java \ diff --git a/mozilla/modules/softupdt/include/gdiff.h b/mozilla/modules/softupdt/include/gdiff.h index 93c975f4d1c..6f59d510c40 100644 --- a/mozilla/modules/softupdt/include/gdiff.h +++ b/mozilla/modules/softupdt/include/gdiff.h @@ -37,6 +37,9 @@ #define GDIFF_CS_NONE 0 #define GDIFF_CS_MD5 1 #define GDIFF_CS_SHA 2 +#define GDIFF_CS_CRC32 32 + +#define CRC32_LEN 4 /*-------------------------------------- * GDIFF opcodes @@ -53,6 +56,7 @@ #define COPY32LONG 254 #define COPY64 255 +/* instruction sizes */ #define ADD16SIZE 2 #define ADD32SIZE 4 #define COPY16BYTESIZE 3 @@ -67,20 +71,50 @@ /*-------------------------------------- * error codes *------------------------------------*/ -#define ERR_OK 0 -#define ERR_ARGS 1 -#define ERR_ACCESS 2 -#define ERR_MEM 3 -#define ERR_HEADER 4 -#define ERR_BADDIFF 5 -#define ERR_OPCODE 6 -#define ERR_OLDFILE 7 -#define ERR_CHKSUMTYPE 8 -#define ERR_CHECKSUM 9 +#define GDIFF_OK 0 +#define GDIFF_ERR_UNKNOWN -1 +#define GDIFF_ERR_ARGS -2 +#define GDIFF_ERR_ACCESS -3 +#define GDIFF_ERR_MEM -4 +#define GDIFF_ERR_HEADER -5 +#define GDIFF_ERR_BADDIFF -6 +#define GDIFF_ERR_OPCODE -7 +#define GDIFF_ERR_OLDFILE -8 +#define GDIFF_ERR_CHKSUMTYPE -9 +#define GDIFF_ERR_CHECKSUM -10 + + +/*-------------------------------------- + * types + *------------------------------------*/ +#ifndef AIX +typedef unsigned char uchar; +#endif + +typedef struct _diffdata { + XP_File fSrc; + XP_File fOut; + XP_File fDiff; + uint8 checksumType; + uint8 checksumLength; + uchar* oldChecksum; + uchar* newChecksum; + XP_Bool bMacAppleSingle; + XP_Bool bWin32BoundImage; + uchar* databuf; + uint32 bufsize; +} DIFFDATA; + +typedef DIFFDATA* pDIFFDATA; + /*-------------------------------------- * miscellaneous *------------------------------------*/ + +#define APPFLAG_W32BOUND "autoinstall:Win32PE" +#define APPFLAG_APPLESINGLE "autoinstall:AppleSingle" + #ifndef TRUE #define TRUE 1 #endif diff --git a/mozilla/modules/softupdt/include/softupdt.h b/mozilla/modules/softupdt/include/softupdt.h index a98fcfdcff9..d95d1940276 100644 --- a/mozilla/modules/softupdt/include/softupdt.h +++ b/mozilla/modules/softupdt/include/softupdt.h @@ -27,6 +27,12 @@ XP_BEGIN_PROTOS #define FORCE_INSTALL 1 #define SILENT_INSTALL 2 +/* Initialize Software Update */ +extern int SU_Startup(void); + +/* Cleanup Software Update */ +extern int SU_Shutdown(void); + /* StartSoftwareUpdate * performs the update, and calls the callback function with the */ @@ -43,9 +49,13 @@ extern XP_Bool SU_StartSoftwareUpdate(MWContext * context, NET_StreamClass * SU_NewStream (int format_out, void * registration, URL_Struct * request, MWContext *context); -int PR_CALLBACK JavaGetBoolPref(char *pref_name); -int PR_CALLBACK IsJavaSecurityEnabled(); -int PR_CALLBACK IsJavaSecurityDefaultTo30Enabled(); +int32 SU_PatchFile( char* srcfile, XP_FileType srctype, + char* patchfile, XP_FileType patchtype, + char* targfile, XP_FileType targtype ); + +int32 SU_Uninstall(char *regPackageName); +int32 SU_EnumUninstall(void** context, char* packageName, + int32 len1, char*regPackageName, int32 len2); #define AUTOUPDATE_ENABLE_PREF "autoupdate.enabled" #define CONTENT_ENCODING_HEADER "Content-encoding"