예제 #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 = 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 HashedHostKey) &&
                             ((HashedHostKey)hk).isHashed()))
                        {
                            pool.Remove(hk);
                        }
                        else
                        {
                            hk.host = deleteSubString(hosts, host);
                        }
                        sync = true;
                    }
                }
            }
            if (sync)
            {
                try { Sync(); }
                catch /*(Exception e)*/ { };
            }
        }
예제 #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 = pool[i];
                    if (hk.isMatched(host) && hk.type == type)
                    {
                        /*
                         *    if(Util.array_equals(hk.key, key)){ return; }
                         *    if(hk.host.Equals(host)){
                         *      hk.key=key;
                         *      return;
                         *    }
                         *    else{
                         *      hk.host=deleteSubString(hk.host, host);
                         *      break;
                         *    }
                         */
                    }
                }
            }

            hk = hostkey;

            pool.Add(hk);

            string bar = getKnownHostsRepositoryID();

            if (bar != null)
            {
                bool     foo = true;
                FileInfo goo = new FileInfo(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?"
                                                   );
                        DirectoryInfo dgoo = Directory.GetParent(bar);
                        if (foo && dgoo != null && !dgoo.Exists)
                        {
                            foo = userinfo.promptYesNo("The parent directory " + goo + " does not exist.\n" +
                                                       "Are you sure you want to create it?"
                                                       );
                            if (foo)
                            {
                                if (!dgoo.mkdirs())
                                {
                                    userinfo.showMessage(goo + " has not been created.");
                                    foo = false;
                                }
                                else
                                {
                                    userinfo.showMessage(goo + " has been succesfully created.\nPlease check its access permission.");
                                }
                            }
                        }
                        if (dgoo == null)
                        {
                            foo = false;
                        }
                    }
                }
                if (foo)
                {
                    try
                    {
                        Sync(bar);
                    }
                    catch (Exception e) { 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 = pool[i];
                    if (hk.isMatched(host) && hk.type == type)
                    {
                        /*
                              if(Util.array_equals(hk.key, key)){ return; }
                              if(hk.host.Equals(host)){
                                hk.key=key;
                                return;
                              }
                              else{
                                hk.host=deleteSubString(hk.host, host);
                                break;
                              }
                        */
                    }
                }
            }

            hk = hostkey;

            pool.Add(hk);

            string bar = getKnownHostsRepositoryID();
            if (bar != null)
            {
                bool foo = true;
                FileInfo goo = new FileInfo(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?"
                                                 );
                        DirectoryInfo dgoo = Directory.GetParent(bar);
                        if (foo && dgoo != null && !dgoo.Exists)
                        {
                            foo = userinfo.promptYesNo("The parent directory " + goo + " does not exist.\n" +
                                                     "Are you sure you want to create it?"
                                                     );
                            if (foo)
                            {
                                if (!dgoo.mkdirs())
                                {
                                    userinfo.showMessage(goo + " has not been created.");
                                    foo = false;
                                }
                                else
                                {
                                    userinfo.showMessage(goo + " has been succesfully created.\nPlease check its access permission.");
                                }
                            }
                        }
                        if (dgoo == null) foo = false;
                    }
                }
                if (foo)
                {
                    try
                    {
                        Sync(bar);
                    }
                    catch (Exception e) { Console.Error.WriteLine("sync known_hosts: " + e); }
                }
            }
        }