예제 #1
0
        public override void Remove(string host, string type, byte[] key)
        {
            bool sync = false;

            lock (pool)
            {
                for (int i = 0; i < pool.Count; i++)
                {
                    HostKey hk = (HostKey)(pool[i]);
                    if (host == null || (hk.IsMatched(host) && (type == null || (hk.GetType().Equals(
                                                                                     type) && (key == null || Util.Array_equals(key, hk.key))))))
                    {
                        string hosts = hk.GetHost();
                        if (hosts.Equals(host) || ((hk is KnownHosts.HashedHostKey) && ((KnownHosts.HashedHostKey
                                                                                         )hk).IsHashed()))
                        {
                            pool.RemoveElement(hk);
                        }
                        else
                        {
                            hk.host = DeleteSubString(hosts, host);
                        }
                        sync = true;
                    }
                }
            }
            if (sync)
            {
                try
                {
                    Sync();
                }
                catch (Exception)
                {
                }
            }
        }
예제 #2
0
        public override void Add(HostKey hostkey, UserInfo userinfo)
        {
            int    type = hostkey.type;
            string host = hostkey.GetHost();

            byte[]  key = hostkey.key;
            HostKey hk  = null;

            lock (pool)
            {
                for (int i = 0; i < pool.Count; i++)
                {
                    hk = (HostKey)(pool[i]);
                    if (hk.IsMatched(host) && hk.type == type)
                    {
                    }
                }
            }
            hk = hostkey;
            pool.Add(hk);
            string bar = GetKnownHostsRepositoryID();

            if (bar != null)
            {
                bool     foo = true;
                FilePath goo = new FilePath(bar);
                if (!goo.Exists())
                {
                    foo = false;
                    if (userinfo != null)
                    {
                        foo = userinfo.PromptYesNo(bar + " does not exist.\n" + "Are you sure you want to create it?"
                                                   );
                        goo = goo.GetParentFile();
                        if (foo && goo != null && !goo.Exists())
                        {
                            foo = userinfo.PromptYesNo("The parent directory " + goo + " does not exist.\n" +
                                                       "Are you sure you want to create it?");
                            if (foo)
                            {
                                if (!goo.Mkdirs())
                                {
                                    userinfo.ShowMessage(goo + " has not been created.");
                                    foo = false;
                                }
                                else
                                {
                                    userinfo.ShowMessage(goo + " has been succesfully created.\nPlease check its access permission."
                                                         );
                                }
                            }
                        }
                        if (goo == null)
                        {
                            foo = false;
                        }
                    }
                }
                if (foo)
                {
                    try
                    {
                        Sync(bar);
                    }
                    catch (Exception e)
                    {
                        System.Console.Error.WriteLine("sync known_hosts: " + e);
                    }
                }
            }
        }
예제 #3
0
		public override void Add(HostKey hostkey, UserInfo userinfo)
		{
			int type = hostkey.type;
			string host = hostkey.GetHost();
			byte[] key = hostkey.key;
			HostKey hk = null;
			lock (pool)
			{
				for (int i = 0; i < pool.Count; i++)
				{
					hk = (HostKey)(pool[i]);
					if (hk.IsMatched(host) && hk.type == type)
					{
					}
				}
			}
			hk = hostkey;
			pool.Add(hk);
			string bar = GetKnownHostsRepositoryID();
			if (bar != null)
			{
				bool foo = true;
				FilePath goo = new FilePath(bar);
				if (!goo.Exists())
				{
					foo = false;
					if (userinfo != null)
					{
						foo = userinfo.PromptYesNo(bar + " does not exist.\n" + "Are you sure you want to create it?"
							);
						goo = goo.GetParentFile();
						if (foo && goo != null && !goo.Exists())
						{
							foo = userinfo.PromptYesNo("The parent directory " + goo + " does not exist.\n" +
								 "Are you sure you want to create it?");
							if (foo)
							{
								if (!goo.Mkdirs())
								{
									userinfo.ShowMessage(goo + " has not been created.");
									foo = false;
								}
								else
								{
									userinfo.ShowMessage(goo + " has been succesfully created.\nPlease check its access permission."
										);
								}
							}
						}
						if (goo == null)
						{
							foo = false;
						}
					}
				}
				if (foo)
				{
					try
					{
						Sync(bar);
					}
					catch (Exception e)
					{
						System.Console.Error.WriteLine("sync known_hosts: " + e);
					}
				}
			}
		}