Esempio n. 1
0
        public static CompositeKey KeyFromCommandLine(CommandLineArgs args)
        {
            if(args == null) throw new ArgumentNullException("args");

            CompositeKey cmpKey = new CompositeKey();
            string strPassword = args[AppDefs.CommandLineOptions.Password];
            string strKeyFile = args[AppDefs.CommandLineOptions.KeyFile];
            string strUserAcc = args[AppDefs.CommandLineOptions.UserAccount];

            if(strPassword != null)
                cmpKey.AddUserKey(new KcpPassword(strPassword));

            if(strKeyFile != null)
            {
                try { cmpKey.AddUserKey(new KcpKeyFile(strKeyFile)); }
                catch(Exception exKey)
                {
                    MessageService.ShowWarning(strKeyFile, KPRes.KeyFileError, exKey);
                    return null;
                }
            }

            if(strUserAcc != null)
            {
                try { cmpKey.AddUserKey(new KcpUserAccount()); }
                catch(Exception exUA)
                {
                    MessageService.ShowWarning(exUA);
                    return null;
                }
            }

            return ((cmpKey.UserKeyCount > 0) ? cmpKey : null);
        }
Esempio n. 2
0
        public IpcEventArgs(string strName, CommandLineArgs clArgs)
        {
            if(strName == null) throw new ArgumentNullException("strName");

            m_strName = strName;
            m_args = clArgs;
        }
Esempio n. 3
0
		public void Initialize(MainForm form, CommandLineArgs cmdLineArgs,
			CipherPool cipherPool)
		{
			Debug.Assert(form != null);
			Debug.Assert(cmdLineArgs != null);
			Debug.Assert(cipherPool != null);

			m_form = form;
			m_cmdLineArgs = cmdLineArgs;
			m_cipherPool = cipherPool;
		}
Esempio n. 4
0
        public static void ProcessGlobalMessage(int nId, MainForm mf)
        {
            if(mf == null) throw new ArgumentNullException("mf");

            IpcParamEx ipcMsg = LoadIpcInfoFile(nId);
            if(ipcMsg == null) return;

            if(ipcMsg.Message == CmdOpenDatabase)
            {
                mf.UIBlockAutoUnlock(true);
                mf.EnsureVisibleForegroundWindow(true, true);
                mf.UIBlockAutoUnlock(false);

                // Don't try to open another database while a dialog
                // is displayed (3489098)
                if(GlobalWindowManager.WindowCount > 0) return;

                string[] vArgs = CommandLineArgs.SafeDeserialize(ipcMsg.Param0);
                if(vArgs == null) { Debug.Assert(false); return; }

                CommandLineArgs args = new CommandLineArgs(vArgs);
                Program.CommandLineArgs.CopyFrom(args);

                mf.OpenDatabase(mf.IocFromCommandLine(), KeyUtil.KeyFromCommandLine(
                    Program.CommandLineArgs), true);
            }
            else if(ipcMsg.Message == CmdOpenEntryUrl) OpenEntryUrl(ipcMsg, mf);
            else { Debug.Assert(false); }
        }
Esempio n. 5
0
        public static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.DoEvents(); // Required

            #if DEBUG
            string strInitialWorkDir = WinUtil.GetWorkingDirectory();
            #endif

            if(!CommonInit()) { CommonTerminate(); return; }

            if(m_appConfig.Application.Start.PluginCacheClearOnce)
            {
                PlgxCache.Clear();
                m_appConfig.Application.Start.PluginCacheClearOnce = false;
                AppConfigSerializer.Save(Program.Config);
            }

            m_cmdLineArgs = new CommandLineArgs(args);

            if(m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtRegister] != null)
            {
                ShellUtil.RegisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId,
                    KPRes.FileExtName, WinUtil.GetExecutable(), PwDefs.ShortProductName, false);
                MainCleanUp();
                return;
            }
            else if(m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtUnregister] != null)
            {
                ShellUtil.UnregisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId);
                MainCleanUp();
                return;
            }
            else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoad] != null)
            {
                // All important .NET assemblies are in memory now already
                try { SelfTest.Perform(); }
                catch(Exception) { Debug.Assert(false); }
                MainCleanUp();
                return;
            }
            /* else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoadRegister] != null)
            {
                string strPreLoadPath = WinUtil.GetExecutable().Trim();
                if(strPreLoadPath.StartsWith("\"") == false)
                    strPreLoadPath = "\"" + strPreLoadPath + "\"";
                ShellUtil.RegisterPreLoad(AppDefs.PreLoadName, strPreLoadPath,
                    @"--" + AppDefs.CommandLineOptions.PreLoad, true);
                MainCleanUp();
                return;
            }
            else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoadUnregister] != null)
            {
                ShellUtil.RegisterPreLoad(AppDefs.PreLoadName, string.Empty,
                    string.Empty, false);
                MainCleanUp();
                return;
            } */
            else if((m_cmdLineArgs[AppDefs.CommandLineOptions.Help] != null) ||
                (m_cmdLineArgs[AppDefs.CommandLineOptions.HelpLong] != null))
            {
                AppHelp.ShowHelp(AppDefs.HelpTopics.CommandLine, null);
                MainCleanUp();
                return;
            }
            else if(m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigSetUrlOverride] != null)
            {
                Program.Config.Integration.UrlOverride = m_cmdLineArgs[
                    AppDefs.CommandLineOptions.ConfigSetUrlOverride];
                AppConfigSerializer.Save(Program.Config);
                MainCleanUp();
                return;
            }
            else if(m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigClearUrlOverride] != null)
            {
                Program.Config.Integration.UrlOverride = string.Empty;
                AppConfigSerializer.Save(Program.Config);
                MainCleanUp();
                return;
            }
            else if(m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigGetUrlOverride] != null)
            {
                try
                {
                    string strFileOut = UrlUtil.EnsureTerminatingSeparator(
                        UrlUtil.GetTempPath(), false) + "KeePass_UrlOverride.tmp";
                    string strContent = ("[KeePass]\r\nKeeURLOverride=" +
                        Program.Config.Integration.UrlOverride + "\r\n");
                    File.WriteAllText(strFileOut, strContent);
                }
                catch(Exception) { Debug.Assert(false); }
                MainCleanUp();
                return;
            }
            else if(m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigSetLanguageFile] != null)
            {
                Program.Config.Application.LanguageFile = m_cmdLineArgs[
                    AppDefs.CommandLineOptions.ConfigSetLanguageFile];
                AppConfigSerializer.Save(Program.Config);
                MainCleanUp();
                return;
            }
            else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PlgxCreate] != null)
            {
                PlgxPlugin.CreateFromCommandLine();
                MainCleanUp();
                return;
            }
            else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PlgxCreateInfo] != null)
            {
                PlgxPlugin.CreateInfoFile(m_cmdLineArgs.FileName);
                MainCleanUp();
                return;
            }
            else if(m_cmdLineArgs[AppDefs.CommandLineOptions.ShowAssemblyInfo] != null)
            {
                MessageService.ShowInfo(Assembly.GetExecutingAssembly().ToString());
                MainCleanUp();
                return;
            }
            else if(m_cmdLineArgs[AppDefs.CommandLineOptions.MakeXmlSerializerEx] != null)
            {
                XmlSerializerEx.GenerateSerializers(m_cmdLineArgs);
                MainCleanUp();
                return;
            }
            #if (DEBUG && !KeePassLibSD)
            else if(m_cmdLineArgs[AppDefs.CommandLineOptions.MakePopularPasswordTable] != null)
            {
                PopularPasswords.MakeList();
                MainCleanUp();
                return;
            }
            #endif

            try { m_nAppMessage = NativeMethods.RegisterWindowMessage(m_strWndMsgID); }
            catch(Exception) { Debug.Assert(KeePassLib.Native.NativeLib.IsUnix()); }

            if(m_cmdLineArgs[AppDefs.CommandLineOptions.ExitAll] != null)
            {
                BroadcastAppMessageAndCleanUp(AppMessage.Exit);
                return;
            }
            else if(m_cmdLineArgs[AppDefs.CommandLineOptions.AutoType] != null)
            {
                BroadcastAppMessageAndCleanUp(AppMessage.AutoType);
                return;
            }
            else if(m_cmdLineArgs[AppDefs.CommandLineOptions.OpenEntryUrl] != null)
            {
                string strEntryUuid = m_cmdLineArgs[AppDefs.CommandLineOptions.Uuid];
                if(!string.IsNullOrEmpty(strEntryUuid))
                {
                    IpcParamEx ipUrl = new IpcParamEx(IpcUtilEx.CmdOpenEntryUrl,
                        strEntryUuid, null, null, null, null);
                    IpcUtilEx.SendGlobalMessage(ipUrl);
                }

                MainCleanUp();
                return;
            }
            else if(m_cmdLineArgs[AppDefs.CommandLineOptions.LockAll] != null)
            {
                BroadcastAppMessageAndCleanUp(AppMessage.Lock);
                return;
            }
            else if(m_cmdLineArgs[AppDefs.CommandLineOptions.UnlockAll] != null)
            {
                BroadcastAppMessageAndCleanUp(AppMessage.Unlock);
                return;
            }

            // Mutex mSingleLock = TrySingleInstanceLock(AppDefs.MutexName, true);
            bool bSingleLock = GlobalMutexPool.CreateMutex(AppDefs.MutexName, true);
            // if((mSingleLock == null) && m_appConfig.Integration.LimitToSingleInstance)
            if(!bSingleLock && m_appConfig.Integration.LimitToSingleInstance)
            {
                ActivatePreviousInstance(args);
                MainCleanUp();
                return;
            }

            Mutex mGlobalNotify = TryGlobalInstanceNotify(AppDefs.MutexNameGlobal);

            AutoType.InitStatic();

            UserActivityNotifyFilter nfActivity = new UserActivityNotifyFilter();
            Application.AddMessageFilter(nfActivity);

            #if DEBUG
            if(m_cmdLineArgs[AppDefs.CommandLineOptions.DebugThrowException] != null)
                throw new Exception(AppDefs.CommandLineOptions.DebugThrowException);

            m_formMain = new MainForm();
            Application.Run(m_formMain);
            #else
            try
            {
                if(m_cmdLineArgs[AppDefs.CommandLineOptions.DebugThrowException] != null)
                    throw new Exception(AppDefs.CommandLineOptions.DebugThrowException);

                m_formMain = new MainForm();
                Application.Run(m_formMain);
            }
            catch(Exception exPrg) { MessageService.ShowFatal(exPrg); }
            #endif

            Application.RemoveMessageFilter(nfActivity);

            Debug.Assert(GlobalWindowManager.WindowCount == 0);
            Debug.Assert(MessageService.CurrentMessageCount == 0);

            MainCleanUp();

            #if DEBUG
            string strEndWorkDir = WinUtil.GetWorkingDirectory();
            Debug.Assert(strEndWorkDir.Equals(strInitialWorkDir, StrUtil.CaseIgnoreCmp));
            #endif

            if(mGlobalNotify != null) { GC.KeepAlive(mGlobalNotify); }
            // if(mSingleLock != null) { GC.KeepAlive(mSingleLock); }
        }
Esempio n. 6
0
        public static CompositeKey KeyFromCommandLine(CommandLineArgs args)
        {
            if(args == null) throw new ArgumentNullException("args");

            CompositeKey cmpKey = new CompositeKey();
            string strPassword = args[AppDefs.CommandLineOptions.Password];
            string strPasswordEnc = args[AppDefs.CommandLineOptions.PasswordEncrypted];
            string strPasswordStdIn = args[AppDefs.CommandLineOptions.PasswordStdIn];
            string strKeyFile = args[AppDefs.CommandLineOptions.KeyFile];
            string strUserAcc = args[AppDefs.CommandLineOptions.UserAccount];

            if(strPassword != null)
                cmpKey.AddUserKey(new KcpPassword(strPassword));
            else if(strPasswordEnc != null)
                cmpKey.AddUserKey(new KcpPassword(StrUtil.DecryptString(strPasswordEnc)));
            else if(strPasswordStdIn != null)
            {
                KcpPassword kcpPw = ReadPasswordStdIn(true);
                if(kcpPw != null) cmpKey.AddUserKey(kcpPw);
            }

            if(strKeyFile != null)
            {
                if(Program.KeyProviderPool.IsKeyProvider(strKeyFile))
                {
                    KeyProviderQueryContext ctxKP = new KeyProviderQueryContext(
                        IOConnectionInfo.FromPath(args.FileName), false, false);

                    bool bPerformHash;
                    byte[] pbProvKey = Program.KeyProviderPool.GetKey(strKeyFile, ctxKP,
                        out bPerformHash);
                    if((pbProvKey != null) && (pbProvKey.Length > 0))
                    {
                        try { cmpKey.AddUserKey(new KcpCustomKey(strKeyFile, pbProvKey, bPerformHash)); }
                        catch(Exception exCKP)
                        {
                            MessageService.ShowWarning(exCKP);
                            return null;
                        }

                        Array.Clear(pbProvKey, 0, pbProvKey.Length);
                    }
                    else return null; // Provider has shown error message
                }
                else // Key file
                {
                    try { cmpKey.AddUserKey(new KcpKeyFile(strKeyFile)); }
                    catch(Exception exKey)
                    {
                        MessageService.ShowWarning(strKeyFile, KPRes.KeyFileError, exKey);
                        return null;
                    }
                }
            }

            if(strUserAcc != null)
            {
                try { cmpKey.AddUserKey(new KcpUserAccount()); }
                catch(Exception exUA)
                {
                    MessageService.ShowWarning(exUA);
                    return null;
                }
            }

            if(cmpKey.UserKeyCount > 0)
            {
                ClearKeyOptions(args, true);
                return cmpKey;
            }

            return null;
        }
Esempio n. 7
0
        private static void ClearKeyOptions(CommandLineArgs args, bool bOnlyIfOptionEnabled)
        {
            if(args == null) { Debug.Assert(false); return; }

            if(bOnlyIfOptionEnabled && !Program.Config.Security.ClearKeyCommandLineParams)
                return;

            args.Remove(AppDefs.CommandLineOptions.Password);
            args.Remove(AppDefs.CommandLineOptions.PasswordEncrypted);
            args.Remove(AppDefs.CommandLineOptions.PasswordStdIn);
            args.Remove(AppDefs.CommandLineOptions.KeyFile);
            args.Remove(AppDefs.CommandLineOptions.PreSelect);
            args.Remove(AppDefs.CommandLineOptions.UserAccount);
        }
Esempio n. 8
0
        internal static string[] MakeCtxIndependent(string[] vCmdLineArgs)
        {
            if(vCmdLineArgs == null) { Debug.Assert(false); return new string[0]; }

            CommandLineArgs cl = new CommandLineArgs(vCmdLineArgs);
            List<string> lFlt = new List<string>();

            foreach(string strArg in vCmdLineArgs)
            {
                KeyValuePair<string, string> kvpArg = CommandLineArgs.GetParameter(strArg);
                if(kvpArg.Key.Equals(AppDefs.CommandLineOptions.PasswordStdIn, StrUtil.CaseIgnoreCmp))
                {
                    KcpPassword kcpPw = ReadPasswordStdIn(true);

                    if((cl[AppDefs.CommandLineOptions.Password] == null) &&
                        (cl[AppDefs.CommandLineOptions.PasswordEncrypted] == null) &&
                        (kcpPw != null))
                    {
                        lFlt.Add("-" + AppDefs.CommandLineOptions.Password + ":" +
                            kcpPw.Password.ReadString()); // No quote wrapping/encoding
                    }
                }
                else lFlt.Add(strArg);
            }

            return lFlt.ToArray();
        }
Esempio n. 9
0
        public static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.DoEvents();

            int nRandomSeed = (int)DateTime.Now.Ticks;
            // Prevent overflow (see Random class constructor)
            if(nRandomSeed == int.MinValue) nRandomSeed = 17;
            m_rndGlobal = new Random(nRandomSeed);

            // Set global localized strings
            PwDatabase.LocalizedAppName = PwDefs.ShortProductName;
            Kdb4File.DetermineLanguageId();

            m_appConfig = AppConfigSerializer.Load();
            if(m_appConfig.Logging.Enabled)
                AppLogEx.Open(PwDefs.ShortProductName);

            AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep();

            string strHelpFile = UrlUtil.StripExtension(WinUtil.GetExecutable()) +
                ".chm";
            AppHelp.LocalHelpFile = strHelpFile;

            string strLangFile = m_appConfig.Application.LanguageFile;
            if((strLangFile != null) && (strLangFile.Length > 0))
            {
                strLangFile = UrlUtil.GetFileDirectory(WinUtil.GetExecutable(), true) +
                    strLangFile;

                try
                {
                    m_kpTranslation = KPTranslation.LoadFromFile(strLangFile);

                    KPRes.SetTranslatedStrings(
                        m_kpTranslation.SafeGetStringTableDictionary(
                        "KeePass.Resources.KPRes"));
                    KLRes.SetTranslatedStrings(
                        m_kpTranslation.SafeGetStringTableDictionary(
                        "KeePassLib.Resources.KLRes"));
                }
                catch(FileNotFoundException) { } // Ignore
                catch(Exception) { Debug.Assert(false); }
            }

            m_cmdLineArgs = new CommandLineArgs(args);

            if(m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtRegister] != null)
            {
                ShellUtil.RegisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId,
                    KPRes.FileExtName, WinUtil.GetExecutable(), PwDefs.ShortProductName, false);
                MainCleanUp();
                return;
            }
            else if(m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtUnregister] != null)
            {
                ShellUtil.UnregisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId);
                MainCleanUp();
                return;
            }
            else if((m_cmdLineArgs[AppDefs.CommandLineOptions.Help] != null) ||
                (m_cmdLineArgs[AppDefs.CommandLineOptions.HelpLong] != null))
            {
                AppHelp.ShowHelp(AppDefs.HelpTopics.CommandLine, null);
                MainCleanUp();
                return;
            }

            try { m_nAppMessage = NativeMethods.RegisterWindowMessage(m_strWndMsgID); }
            catch(Exception) { Debug.Assert(false); }

            if(m_cmdLineArgs[AppDefs.CommandLineOptions.ExitAll] != null)
            {
                try
                {
                    NativeMethods.SendMessage((IntPtr)NativeMethods.HWND_BROADCAST,
                        m_nAppMessage, (IntPtr)AppMessage.Exit, IntPtr.Zero);
                }
                catch(Exception) { Debug.Assert(false); }

                MainCleanUp();
                return;
            }

            Mutex mSingleLock = TrySingleInstanceLock(AppDefs.MutexName, true);
            if((mSingleLock == null) && m_appConfig.Integration.LimitToSingleInstance)
            {
                ActivatePreviousInstance(args);
                MainCleanUp();
                return;
            }

            Mutex mGlobalNotify = TryGlobalInstanceNotify(AppDefs.MutexNameGlobal);

            #if DEBUG
            m_formMain = new MainForm();
            Application.Run(m_formMain);
            #else
            try
            {
                m_formMain = new MainForm();
                Application.Run(m_formMain);
            }
            catch(Exception exPrg)
            {
                MessageService.ShowFatal(exPrg);
            }
            #endif

            Debug.Assert(GlobalWindowManager.WindowCount == 0);
            Debug.Assert(MessageService.CurrentMessageCount == 0);

            MainCleanUp();

            if(mGlobalNotify != null) { GC.KeepAlive(mGlobalNotify); }
            if(mSingleLock != null) { GC.KeepAlive(mSingleLock); }
        }
Esempio n. 10
0
		public static void Main(string[] args)
		{
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			Application.DoEvents(); // Required

			InitEnvSecurity();

			int nRandomSeed = (int)DateTime.Now.Ticks;
			// Prevent overflow (see Random class constructor)
			if(nRandomSeed == int.MinValue) nRandomSeed = 17;
			m_rndGlobal = new Random(nRandomSeed);

			// Set global localized strings
			PwDatabase.LocalizedAppName = PwDefs.ShortProductName;
			Kdb4File.DetermineLanguageId();

			m_appConfig = AppConfigSerializer.Load();
			if(m_appConfig.Logging.Enabled)
				AppLogEx.Open(PwDefs.ShortProductName);

			AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep();

			m_ecasTriggers = m_appConfig.Application.TriggerSystem;
			m_ecasTriggers.SetToInitialState();

			string strHelpFile = UrlUtil.StripExtension(WinUtil.GetExecutable()) + ".chm";
			AppHelp.LocalHelpFile = strHelpFile;

			string strLangFile = m_appConfig.Application.LanguageFile;
			if((strLangFile != null) && (strLangFile.Length > 0))
			{
				strLangFile = UrlUtil.GetFileDirectory(WinUtil.GetExecutable(), true,
					false) + strLangFile;

				try
				{
					m_kpTranslation = KPTranslation.LoadFromFile(strLangFile);

					KPRes.SetTranslatedStrings(
						m_kpTranslation.SafeGetStringTableDictionary(
						"KeePass.Resources.KPRes"));
					KLRes.SetTranslatedStrings(
						m_kpTranslation.SafeGetStringTableDictionary(
						"KeePassLib.Resources.KLRes"));

					StrUtil.RightToLeft = m_kpTranslation.Properties.RightToLeft;
				}
				catch(FileNotFoundException) { } // Ignore
				catch(Exception) { Debug.Assert(false); }
			}

			if(m_appConfig.Application.Start.PluginCacheClearOnce)
			{
				PlgxCache.Clear();
				m_appConfig.Application.Start.PluginCacheClearOnce = false;
				AppConfigSerializer.Save(Program.Config);
			}

			m_cmdLineArgs = new CommandLineArgs(args);

			if(m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtRegister] != null)
			{
				ShellUtil.RegisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId,
					KPRes.FileExtName, WinUtil.GetExecutable(), PwDefs.ShortProductName, false);
				MainCleanUp();
				return;
			}
			else if(m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtUnregister] != null)
			{
				ShellUtil.UnregisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId);
				MainCleanUp();
				return;
			}
			else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoad] != null)
			{
				// All important .NET assemblies are in memory now already
				try { SelfTest.Perform(); }
				catch(Exception) { Debug.Assert(false); }
				MainCleanUp();
				return;
			}
			/* else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoadRegister] != null)
			{
				string strPreLoadPath = WinUtil.GetExecutable().Trim();
				if(strPreLoadPath.StartsWith("\"") == false)
					strPreLoadPath = "\"" + strPreLoadPath + "\"";
				ShellUtil.RegisterPreLoad(AppDefs.PreLoadName, strPreLoadPath,
					@"--" + AppDefs.CommandLineOptions.PreLoad, true);
				MainCleanUp();
				return;
			}
			else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoadUnregister] != null)
			{
				ShellUtil.RegisterPreLoad(AppDefs.PreLoadName, string.Empty,
					string.Empty, false);
				MainCleanUp();
				return;
			} */
			else if((m_cmdLineArgs[AppDefs.CommandLineOptions.Help] != null) ||
				(m_cmdLineArgs[AppDefs.CommandLineOptions.HelpLong] != null))
			{
				AppHelp.ShowHelp(AppDefs.HelpTopics.CommandLine, null);
				MainCleanUp();
				return;
			}
			else if(m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigSetUrlOverride] != null)
			{
				Program.Config.Integration.UrlOverride = m_cmdLineArgs[
					AppDefs.CommandLineOptions.ConfigSetUrlOverride];
				AppConfigSerializer.Save(Program.Config);
				MainCleanUp();
				return;
			}
			else if(m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigClearUrlOverride] != null)
			{
				Program.Config.Integration.UrlOverride = string.Empty;
				AppConfigSerializer.Save(Program.Config);
				MainCleanUp();
				return;
			}
			else if(m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigGetUrlOverride] != null)
			{
				try
				{
					string strFileOut = UrlUtil.EnsureTerminatingSeparator(
						Path.GetTempPath(), false) + "KeePass_UrlOverride.tmp";
					string strContent = ("[KeePass]\r\nKeeURLOverride=" +
						Program.Config.Integration.UrlOverride + "\r\n");
					File.WriteAllText(strFileOut, strContent);
				}
				catch(Exception) { Debug.Assert(false); }
				MainCleanUp();
				return;
			}
			else if(m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigSetLanguageFile] != null)
			{
				Program.Config.Application.LanguageFile = m_cmdLineArgs[
					AppDefs.CommandLineOptions.ConfigSetLanguageFile];
				AppConfigSerializer.Save(Program.Config);
				MainCleanUp();
				return;
			}
			else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PlgxCreate] != null)
			{
				PlgxPlugin.CreateFromCommandLine();
				MainCleanUp();
				return;
			}
			else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PlgxCreateInfo] != null)
			{
				PlgxPlugin.CreateInfoFile(m_cmdLineArgs.FileName);
				MainCleanUp();
				return;
			}
#if (DEBUG && !KeePassLibSD)
			else if(m_cmdLineArgs[AppDefs.CommandLineOptions.MakePopularPasswordTable] != null)
			{
				PopularPasswords.MakeList();
				MainCleanUp();
				return;
			}
#endif

			try { m_nAppMessage = NativeMethods.RegisterWindowMessage(m_strWndMsgID); }
			catch(Exception) { Debug.Assert(false); }

			if(m_cmdLineArgs[AppDefs.CommandLineOptions.ExitAll] != null)
			{
				BroadcastAppMessageAndCleanUp(AppMessage.Exit);
				return;
			}
			else if(m_cmdLineArgs[AppDefs.CommandLineOptions.AutoType] != null)
			{
				BroadcastAppMessageAndCleanUp(AppMessage.AutoType);
				return;
			}
			else if(m_cmdLineArgs[AppDefs.CommandLineOptions.OpenEntryUrl] != null)
			{
				string strEntryUuid = m_cmdLineArgs[AppDefs.CommandLineOptions.Uuid];
				if(!string.IsNullOrEmpty(strEntryUuid))
				{
					IpcParamEx ipUrl = new IpcParamEx(IpcUtilEx.CmdOpenEntryUrl,
						strEntryUuid, null, null, null, null);
					IpcUtilEx.SendGlobalMessage(ipUrl);
				}

				MainCleanUp();
				return;
			}
			else if(m_cmdLineArgs[AppDefs.CommandLineOptions.LockAll] != null)
			{
				BroadcastAppMessageAndCleanUp(AppMessage.Lock);
				return;
			}
			else if(m_cmdLineArgs[AppDefs.CommandLineOptions.UnlockAll] != null)
			{
				BroadcastAppMessageAndCleanUp(AppMessage.Unlock);
				return;
			}

			Mutex mSingleLock = TrySingleInstanceLock(AppDefs.MutexName, true);
			if((mSingleLock == null) && m_appConfig.Integration.LimitToSingleInstance)
			{
				ActivatePreviousInstance(args);
				MainCleanUp();
				return;
			}

			Mutex mGlobalNotify = TryGlobalInstanceNotify(AppDefs.MutexNameGlobal);

			AutoType.InitStatic();

			UserActivityNotifyFilter nfActivity = new UserActivityNotifyFilter();
			Application.AddMessageFilter(nfActivity);

#if DEBUG
			m_formMain = new MainForm();
			Application.Run(m_formMain);
#else
			try
			{
				m_formMain = new MainForm();
				Application.Run(m_formMain);
			}
			catch(Exception exPrg) { MessageService.ShowFatal(exPrg); }
#endif

			Application.RemoveMessageFilter(nfActivity);

			Debug.Assert(GlobalWindowManager.WindowCount == 0);
			Debug.Assert(MessageService.CurrentMessageCount == 0);

			MainCleanUp();

			if(mGlobalNotify != null) { GC.KeepAlive(mGlobalNotify); }
			if(mSingleLock != null) { GC.KeepAlive(mSingleLock); }
		}
		private static void OpenDatabaseFile(EcasAction a, EcasContext ctx)
		{
			string strPath = EcasUtil.GetParamString(a.Parameters, 0, true);
			if(string.IsNullOrEmpty(strPath)) return;

			string strIOUserName = EcasUtil.GetParamString(a.Parameters, 1, true);
			string strIOPassword = EcasUtil.GetParamString(a.Parameters, 2, true);

			IOConnectionInfo ioc = IOFromParameters(strPath, strIOUserName, strIOPassword);
			if(ioc == null) return;

			string strPassword = EcasUtil.GetParamString(a.Parameters, 3, true);
			string strKeyFile = EcasUtil.GetParamString(a.Parameters, 4, true);
			bool bUserAccount = StrUtil.StringToBool(EcasUtil.GetParamString(
				a.Parameters, 5, true));

			CompositeKey cmpKey = null;
			if(!string.IsNullOrEmpty(strPassword) || !string.IsNullOrEmpty(strKeyFile) ||
				bUserAccount)
			{
				List<string> vArgs = new List<string>();
				if(!string.IsNullOrEmpty(strPassword))
					vArgs.Add("-" + AppDefs.CommandLineOptions.Password + ":" + strPassword);
				if(!string.IsNullOrEmpty(strKeyFile))
					vArgs.Add("-" + AppDefs.CommandLineOptions.KeyFile + ":" + strKeyFile);
				if(bUserAccount)
					vArgs.Add("-" + AppDefs.CommandLineOptions.UserAccount);

				CommandLineArgs cmdArgs = new CommandLineArgs(vArgs.ToArray());
				cmpKey = KeyUtil.KeyFromCommandLine(cmdArgs);
			}

			Program.MainForm.OpenDatabase(ioc, cmpKey, ioc.IsLocalFile());
		}
Esempio n. 12
0
        public static CompositeKey KeyFromCommandLine(CommandLineArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            CompositeKey cmpKey         = new CompositeKey();
            string       strPassword    = args[AppDefs.CommandLineOptions.Password];
            string       strPasswordEnc = args[AppDefs.CommandLineOptions.PasswordEncrypted];
            string       strKeyFile     = args[AppDefs.CommandLineOptions.KeyFile];
            string       strUserAcc     = args[AppDefs.CommandLineOptions.UserAccount];

            if (strPassword != null)
            {
                cmpKey.AddUserKey(new KcpPassword(strPassword));
            }
            else if (strPasswordEnc != null)
            {
                cmpKey.AddUserKey(new KcpPassword(StrUtil.DecryptString(strPasswordEnc)));
            }

            if (strKeyFile != null)
            {
                if (Program.KeyProviderPool.IsKeyProvider(strKeyFile))
                {
                    KeyProviderQueryContext ctxKP = new KeyProviderQueryContext(
                        IOConnectionInfo.FromPath(args.FileName), false, false);

                    bool   bPerformHash;
                    byte[] pbProvKey = Program.KeyProviderPool.GetKey(strKeyFile, ctxKP,
                                                                      out bPerformHash);
                    if ((pbProvKey != null) && (pbProvKey.Length > 0))
                    {
                        try { cmpKey.AddUserKey(new KcpCustomKey(strKeyFile, pbProvKey, bPerformHash)); }
                        catch (Exception exCKP)
                        {
                            MessageService.ShowWarning(exCKP);
                            return(null);
                        }

                        Array.Clear(pbProvKey, 0, pbProvKey.Length);
                    }
                    else
                    {
                        return(null);                     // Provider has shown error message
                    }
                }
                else                 // Key file
                {
                    try { cmpKey.AddUserKey(new KcpKeyFile(strKeyFile)); }
                    catch (Exception exKey)
                    {
                        MessageService.ShowWarning(strKeyFile, KPRes.KeyFileError, exKey);
                        return(null);
                    }
                }
            }

            if (strUserAcc != null)
            {
                try { cmpKey.AddUserKey(new KcpUserAccount()); }
                catch (Exception exUA)
                {
                    MessageService.ShowWarning(exUA);
                    return(null);
                }
            }

            if (cmpKey.UserKeyCount > 0)
            {
                ClearKeyOptions(args, true);
                return(cmpKey);
            }

            return(null);
        }
Esempio n. 13
0
        public static void Main(string[] args)
        {
            #if DEBUG
            // Program.DesignMode should not be queried before executing
            // Main (e.g. by a static Control) when running the program
            // normally
            Debug.Assert(!m_bDesignModeQueried);
            #endif
            m_bDesignMode = false; // Designer doesn't call Main method

            m_cmdLineArgs = new CommandLineArgs(args);

            // Before loading the configuration
            string strWaDisable = m_cmdLineArgs[
                AppDefs.CommandLineOptions.WorkaroundDisable];
            if(!string.IsNullOrEmpty(strWaDisable))
                MonoWorkarounds.SetEnabled(strWaDisable, false);

            DpiUtil.ConfigureProcess();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.DoEvents(); // Required

            #if DEBUG
            string strInitialWorkDir = WinUtil.GetWorkingDirectory();
            #endif

            if(!CommonInit()) { CommonTerminate(); return; }

            if(m_appConfig.Application.Start.PluginCacheClearOnce)
            {
                PlgxCache.Clear();
                m_appConfig.Application.Start.PluginCacheClearOnce = false;
                AppConfigSerializer.Save(Program.Config);
            }

            if(m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtRegister] != null)
            {
                ShellUtil.RegisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId,
                    KPRes.FileExtName, WinUtil.GetExecutable(), PwDefs.ShortProductName, false);
                MainCleanUp();
                return;
            }
            if(m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtUnregister] != null)
            {
                ShellUtil.UnregisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId);
                MainCleanUp();
                return;
            }
            if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoad] != null)
            {
                // All important .NET assemblies are in memory now already
                try { SelfTest.Perform(); }
                catch(Exception) { Debug.Assert(false); }
                MainCleanUp();
                return;
            }
            /* if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoadRegister] != null)
            {
                string strPreLoadPath = WinUtil.GetExecutable().Trim();
                if(strPreLoadPath.StartsWith("\"") == false)
                    strPreLoadPath = "\"" + strPreLoadPath + "\"";
                ShellUtil.RegisterPreLoad(AppDefs.PreLoadName, strPreLoadPath,
                    @"--" + AppDefs.CommandLineOptions.PreLoad, true);
                MainCleanUp();
                return;
            }
            if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoadUnregister] != null)
            {
                ShellUtil.RegisterPreLoad(AppDefs.PreLoadName, string.Empty,
                    string.Empty, false);
                MainCleanUp();
                return;
            } */
            if((m_cmdLineArgs[AppDefs.CommandLineOptions.Help] != null) ||
                (m_cmdLineArgs[AppDefs.CommandLineOptions.HelpLong] != null))
            {
                AppHelp.ShowHelp(AppDefs.HelpTopics.CommandLine, null);
                MainCleanUp();
                return;
            }
            if(m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigSetUrlOverride] != null)
            {
                Program.Config.Integration.UrlOverride = m_cmdLineArgs[
                    AppDefs.CommandLineOptions.ConfigSetUrlOverride];
                AppConfigSerializer.Save(Program.Config);
                MainCleanUp();
                return;
            }
            if(m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigClearUrlOverride] != null)
            {
                Program.Config.Integration.UrlOverride = string.Empty;
                AppConfigSerializer.Save(Program.Config);
                MainCleanUp();
                return;
            }
            if(m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigGetUrlOverride] != null)
            {
                try
                {
                    string strFileOut = UrlUtil.EnsureTerminatingSeparator(
                        UrlUtil.GetTempPath(), false) + "KeePass_UrlOverride.tmp";
                    string strContent = ("[KeePass]\r\nKeeURLOverride=" +
                        Program.Config.Integration.UrlOverride + "\r\n");
                    File.WriteAllText(strFileOut, strContent);
                }
                catch(Exception) { Debug.Assert(false); }
                MainCleanUp();
                return;
            }
            if(m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigSetLanguageFile] != null)
            {
                Program.Config.Application.LanguageFile = m_cmdLineArgs[
                    AppDefs.CommandLineOptions.ConfigSetLanguageFile];
                AppConfigSerializer.Save(Program.Config);
                MainCleanUp();
                return;
            }
            if(m_cmdLineArgs[AppDefs.CommandLineOptions.PlgxCreate] != null)
            {
                PlgxPlugin.CreateFromCommandLine();
                MainCleanUp();
                return;
            }
            if(m_cmdLineArgs[AppDefs.CommandLineOptions.PlgxCreateInfo] != null)
            {
                PlgxPlugin.CreateInfoFile(m_cmdLineArgs.FileName);
                MainCleanUp();
                return;
            }
            if(m_cmdLineArgs[AppDefs.CommandLineOptions.ShowAssemblyInfo] != null)
            {
                MessageService.ShowInfo(Assembly.GetExecutingAssembly().ToString());
                MainCleanUp();
                return;
            }
            if(m_cmdLineArgs[AppDefs.CommandLineOptions.MakeXmlSerializerEx] != null)
            {
                XmlSerializerEx.GenerateSerializers(m_cmdLineArgs);
                MainCleanUp();
                return;
            }
            if(m_cmdLineArgs[AppDefs.CommandLineOptions.MakeXspFile] != null)
            {
                XspArchive.CreateFile(m_cmdLineArgs.FileName, m_cmdLineArgs["d"]);
                MainCleanUp();
                return;
            }
            if(m_cmdLineArgs[AppDefs.CommandLineOptions.Version] != null)
            {
                Console.WriteLine(PwDefs.ShortProductName + " " + PwDefs.VersionString);
                Console.WriteLine(PwDefs.Copyright);
                MainCleanUp();
                return;
            }
            #if DEBUG
            if(m_cmdLineArgs[AppDefs.CommandLineOptions.TestGfx] != null)
            {
                List<Image> lImg = new List<Image>();
                lImg.Add(Properties.Resources.B16x16_Browser);
                lImg.Add(Properties.Resources.B48x48_Keyboard_Layout);
                ImageArchive aHighRes = new ImageArchive();
                aHighRes.Load(Properties.Resources.Images_Client_HighRes);
                lImg.Add(aHighRes.GetForObject("C12_IRKickFlash"));
                if(File.Exists("Test.png"))
                    lImg.Add(Image.FromFile("Test.png"));
                Image img = GfxUtil.ScaleTest(lImg.ToArray());
                img.Save("GfxScaleTest.png", ImageFormat.Png);
                return;
            }
            #endif
            // #if (DEBUG && !KeePassLibSD)
            // if(m_cmdLineArgs[AppDefs.CommandLineOptions.MakePopularPasswordTable] != null)
            // {
            //	PopularPasswords.MakeList();
            //	MainCleanUp();
            //	return;
            // }
            // #endif

            try { m_nAppMessage = NativeMethods.RegisterWindowMessage(m_strWndMsgID); }
            catch(Exception) { Debug.Assert(NativeLib.IsUnix()); }

            if(m_cmdLineArgs[AppDefs.CommandLineOptions.ExitAll] != null)
            {
                BroadcastAppMessageAndCleanUp(AppMessage.Exit);
                return;
            }
            if(m_cmdLineArgs[AppDefs.CommandLineOptions.AutoType] != null)
            {
                BroadcastAppMessageAndCleanUp(AppMessage.AutoType);
                return;
            }
            if(m_cmdLineArgs[AppDefs.CommandLineOptions.AutoTypeSelected] != null)
            {
                BroadcastAppMessageAndCleanUp(AppMessage.AutoTypeSelected);
                return;
            }
            if(m_cmdLineArgs[AppDefs.CommandLineOptions.OpenEntryUrl] != null)
            {
                string strEntryUuid = m_cmdLineArgs[AppDefs.CommandLineOptions.Uuid];
                if(!string.IsNullOrEmpty(strEntryUuid))
                {
                    IpcParamEx ipUrl = new IpcParamEx(IpcUtilEx.CmdOpenEntryUrl,
                        strEntryUuid, null, null, null, null);
                    IpcUtilEx.SendGlobalMessage(ipUrl);
                }

                MainCleanUp();
                return;
            }
            if(m_cmdLineArgs[AppDefs.CommandLineOptions.LockAll] != null)
            {
                BroadcastAppMessageAndCleanUp(AppMessage.Lock);
                return;
            }
            if(m_cmdLineArgs[AppDefs.CommandLineOptions.UnlockAll] != null)
            {
                BroadcastAppMessageAndCleanUp(AppMessage.Unlock);
                return;
            }
            if(m_cmdLineArgs[AppDefs.CommandLineOptions.IpcEvent] != null)
            {
                string strName = m_cmdLineArgs[AppDefs.CommandLineOptions.IpcEvent];
                if(!string.IsNullOrEmpty(strName))
                {
                    string[] vFlt = KeyUtil.MakeCtxIndependent(args);

                    IpcParamEx ipEvent = new IpcParamEx(IpcUtilEx.CmdIpcEvent, strName,
                        CommandLineArgs.SafeSerialize(vFlt), null, null, null);
                    IpcUtilEx.SendGlobalMessage(ipEvent);
                }

                MainCleanUp();
                return;
            }

            // Mutex mSingleLock = TrySingleInstanceLock(AppDefs.MutexName, true);
            bool bSingleLock = GlobalMutexPool.CreateMutex(AppDefs.MutexName, true);
            // if((mSingleLock == null) && m_appConfig.Integration.LimitToSingleInstance)
            if(!bSingleLock && m_appConfig.Integration.LimitToSingleInstance)
            {
                ActivatePreviousInstance(args);
                MainCleanUp();
                return;
            }

            Mutex mGlobalNotify = TryGlobalInstanceNotify(AppDefs.MutexNameGlobal);

            AutoType.InitStatic();

            UserActivityNotifyFilter nfActivity = new UserActivityNotifyFilter();
            Application.AddMessageFilter(nfActivity);

            #if DEBUG
            if(m_cmdLineArgs[AppDefs.CommandLineOptions.DebugThrowException] != null)
                throw new Exception(AppDefs.CommandLineOptions.DebugThrowException);

            m_formMain = new MainForm();
            Application.Run(m_formMain);
            #else
            try
            {
                if(m_cmdLineArgs[AppDefs.CommandLineOptions.DebugThrowException] != null)
                    throw new Exception(AppDefs.CommandLineOptions.DebugThrowException);

                m_formMain = new MainForm();
                Application.Run(m_formMain);
            }
            catch(Exception exPrg)
            {
                // Catch message box exception;
                // https://sourceforge.net/p/keepass/patches/86/
                try { MessageService.ShowFatal(exPrg); }
                catch(Exception) { Console.Error.WriteLine(exPrg.ToString()); }
            }
            #endif

            Application.RemoveMessageFilter(nfActivity);

            Debug.Assert(GlobalWindowManager.WindowCount == 0);
            Debug.Assert(MessageService.CurrentMessageCount == 0);

            MainCleanUp();

            #if DEBUG
            string strEndWorkDir = WinUtil.GetWorkingDirectory();
            Debug.Assert(strEndWorkDir.Equals(strInitialWorkDir, StrUtil.CaseIgnoreCmp));
            #endif

            if(mGlobalNotify != null) { GC.KeepAlive(mGlobalNotify); }
            // if(mSingleLock != null) { GC.KeepAlive(mSingleLock); }
        }
Esempio n. 14
0
        public static CompositeKey KeyFromCommandLine(CommandLineArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            CompositeKey cmpKey           = new CompositeKey();
            string       strPassword      = args[AppDefs.CommandLineOptions.Password];
            string       strPasswordEnc   = args[AppDefs.CommandLineOptions.PasswordEncrypted];
            string       strPasswordStdIn = args[AppDefs.CommandLineOptions.PasswordStdIn];
            string       strKeyFile       = args[AppDefs.CommandLineOptions.KeyFile];
            string       strUserAcc       = args[AppDefs.CommandLineOptions.UserAccount];

            Action <byte[]> fAddPwB = delegate(byte[] pbPw)
            {
                cmpKey.AddUserKey(new KcpPassword(pbPw,
                                                  Program.Config.Security.MasterPassword.RememberWhileOpen));
            };

            Action <string> fAddPwS = delegate(string strPw)
            {
                byte[] pb = StrUtil.Utf8.GetBytes(strPw);
                try { fAddPwB(pb); }
                finally { MemUtil.ZeroByteArray(pb); }
            };

            if (strPassword != null)
            {
                fAddPwS(strPassword);
            }
            else if (strPasswordEnc != null)
            {
                fAddPwS(StrUtil.DecryptString(strPasswordEnc));
            }
            else if (strPasswordStdIn != null)
            {
                ProtectedString ps = ReadPasswordStdIn(true);
                if (ps != null)
                {
                    byte[] pb = ps.ReadUtf8();
                    try { fAddPwB(pb); }
                    finally { MemUtil.ZeroByteArray(pb); }
                }
            }

            if (strKeyFile != null)
            {
                if (Program.KeyProviderPool.IsKeyProvider(strKeyFile))
                {
                    KeyProviderQueryContext ctxKP = new KeyProviderQueryContext(
                        IOConnectionInfo.FromPath(args.FileName), false, false);

                    bool   bPerformHash;
                    byte[] pbProvKey = Program.KeyProviderPool.GetKey(strKeyFile, ctxKP,
                                                                      out bPerformHash);
                    if ((pbProvKey != null) && (pbProvKey.Length > 0))
                    {
                        try { cmpKey.AddUserKey(new KcpCustomKey(strKeyFile, pbProvKey, bPerformHash)); }
                        catch (Exception exCKP)
                        {
                            MessageService.ShowWarning(exCKP);
                            return(null);
                        }
                        finally { MemUtil.ZeroByteArray(pbProvKey); }
                    }
                    else
                    {
                        return(null);                     // Provider has shown error message
                    }
                }
                else                 // Key file
                {
                    try { cmpKey.AddUserKey(new KcpKeyFile(strKeyFile)); }
                    catch (Exception exKey)
                    {
                        MessageService.ShowWarning(strKeyFile, KPRes.KeyFileError, exKey);
                        return(null);
                    }
                }
            }

            if (strUserAcc != null)
            {
                try { cmpKey.AddUserKey(new KcpUserAccount()); }
                catch (Exception exUA)
                {
                    MessageService.ShowWarning(exUA);
                    return(null);
                }
            }

            if (cmpKey.UserKeyCount > 0)
            {
                ClearKeyOptions(args, true);
                return(cmpKey);
            }

            return(null);
        }
Esempio n. 15
0
        public static void ProcessGlobalMessage(int nId, MainForm mf, bool bOneInstance)
        {
            if (mf == null)
            {
                throw new ArgumentNullException("mf");
            }

            IpcParamEx ipcMsg = LoadIpcInfoFile(nId, bOneInstance);

            if (ipcMsg == null)
            {
                return;
            }

            if (ipcMsg.Message == CmdOpenDatabase)
            {
                mf.UIBlockAutoUnlock(true);
                mf.EnsureVisibleForegroundWindow(true, true);
                mf.UIBlockAutoUnlock(false);

                string[] vArgs = CommandLineArgs.SafeDeserialize(ipcMsg.Param0);
                if (vArgs == null)
                {
                    Debug.Assert(false); return;
                }

                CommandLineArgs args = new CommandLineArgs(vArgs);
                Program.CommandLineArgs.CopyFrom(args);

                mf.OpenDatabase(mf.IocFromCommandLine(), KeyUtil.KeyFromCommandLine(
                                    Program.CommandLineArgs), true);
            }
            else if (ipcMsg.Message == CmdOpenEntryUrl)
            {
                OpenEntryUrl(ipcMsg, mf);
            }
            else if (ipcMsg.Message == CmdIpcEvent)
            {
                try
                {
                    if (IpcUtilEx.IpcEvent == null)
                    {
                        return;
                    }

                    string strName = ipcMsg.Param0;
                    if (string.IsNullOrEmpty(strName))
                    {
                        Debug.Assert(false); return;
                    }

                    string[] vArgs = CommandLineArgs.SafeDeserialize(ipcMsg.Param1);
                    if (vArgs == null)
                    {
                        Debug.Assert(false); return;
                    }

                    CommandLineArgs clArgs = new CommandLineArgs(vArgs);

                    IpcEventArgs e = new IpcEventArgs(strName, clArgs);
                    IpcUtilEx.IpcEvent(null, e);
                }
                catch (Exception) { Debug.Assert(false); }
            }
            else
            {
                Debug.Assert(false);
            }
        }
Esempio n. 16
0
        public static void ProcessGlobalMessage(int nId, MainForm mf)
        {
            if(mf == null) throw new ArgumentNullException("mf");

            IpcParamEx ipcMsg = LoadIpcInfoFile(nId);
            if(ipcMsg == null) return;

            if(ipcMsg.Message == CmdOpenDatabase)
            {
                mf.UIBlockAutoUnlock(true);
                mf.EnsureVisibleForegroundWindow(true, true);
                mf.UIBlockAutoUnlock(false);

                string[] vArgs = CommandLineArgs.SafeDeserialize(ipcMsg.Param0);
                if(vArgs == null) { Debug.Assert(false); return; }

                CommandLineArgs args = new CommandLineArgs(vArgs);
                Program.CommandLineArgs.CopyFrom(args);

                mf.OpenDatabase(IOConnectionInfo.FromPath(args.FileName),
                    KeyUtil.KeyFromCommandLine(Program.CommandLineArgs), true);
            }
            else if(ipcMsg.Message == CmdOpenEntryUrl) OpenEntryUrl(ipcMsg, mf);
            else { Debug.Assert(false); }
        }
        private static CompositeKey KeyFromParams(EcasAction a, int iPassword,
            int iKeyFile, int iUserAccount)
        {
            string strPassword = EcasUtil.GetParamString(a.Parameters, iPassword, true);
            string strKeyFile = EcasUtil.GetParamString(a.Parameters, iKeyFile, true);
            bool bUserAccount = StrUtil.StringToBool(EcasUtil.GetParamString(
                a.Parameters, iUserAccount, true));

            CompositeKey cmpKey = null;
            if(!string.IsNullOrEmpty(strPassword) || !string.IsNullOrEmpty(strKeyFile) ||
                bUserAccount)
            {
                List<string> vArgs = new List<string>();
                if(!string.IsNullOrEmpty(strPassword))
                    vArgs.Add("-" + AppDefs.CommandLineOptions.Password + ":" + strPassword);
                if(!string.IsNullOrEmpty(strKeyFile))
                    vArgs.Add("-" + AppDefs.CommandLineOptions.KeyFile + ":" + strKeyFile);
                if(bUserAccount)
                    vArgs.Add("-" + AppDefs.CommandLineOptions.UserAccount);

                CommandLineArgs cmdArgs = new CommandLineArgs(vArgs.ToArray());
                cmpKey = KeyUtil.KeyFromCommandLine(cmdArgs);
            }

            return cmpKey;
        }
Esempio n. 18
0
        internal void CopyFrom(CommandLineArgs args)
        {
            if(args == null) throw new ArgumentNullException("args");

            m_vFileNames.Clear();
            foreach(string strFile in args.FileNames)
            {
                m_vFileNames.Add(strFile);
            }

            m_vParams.Clear();
            foreach(KeyValuePair<string, string> kvp in args.Parameters)
            {
                if(!string.IsNullOrEmpty(kvp.Key))
                    m_vParams[kvp.Key] = kvp.Value;
            }
        }