/// <exception cref="NSch.JSchException"></exception>
        private Session CreateSession(CredentialsProvider credentialsProvider, FS fs, string
                                      user, string pass, string host, int port, OpenSshConfig.Host hc)
        {
            Session session = CreateSession(hc, user, host, port, fs);

            if (pass != null)
            {
                session.SetPassword(pass);
            }
            string strictHostKeyCheckingPolicy = hc.GetStrictHostKeyChecking();

            if (strictHostKeyCheckingPolicy != null)
            {
                session.SetConfig("StrictHostKeyChecking", strictHostKeyCheckingPolicy);
            }
            string pauth = hc.GetPreferredAuthentications();

            if (pauth != null)
            {
                session.SetConfig("PreferredAuthentications", pauth);
            }
            if (credentialsProvider != null && (!hc.IsBatchMode() || !credentialsProvider.IsInteractive
                                                    ()))
            {
                session.SetUserInfo(new CredentialsProviderUserInfo(session, credentialsProvider)
                                    );
            }
            Configure(hc, session);
            return(session);
        }
Example #2
0
 /// <exception cref="NSch.JSchException"></exception>
 public override Session GetSession(string user, string pass, string host, int port
                                    , CredentialsProvider credentialsProvider, FS fs)
 {
     lock (this)
     {
         if (config == null)
         {
             config = OpenSshConfig.Get(fs);
         }
         OpenSshConfig.Host hc = config.Lookup(host);
         host = hc.GetHostName();
         if (port <= 0)
         {
             port = hc.GetPort();
         }
         if (user == null)
         {
             user = hc.GetUser();
         }
         Session session = CreateSession(hc, user, host, port, fs);
         if (pass != null)
         {
             session.SetPassword(pass);
         }
         string strictHostKeyCheckingPolicy = hc.GetStrictHostKeyChecking();
         if (strictHostKeyCheckingPolicy != null)
         {
             session.SetConfig("StrictHostKeyChecking", strictHostKeyCheckingPolicy);
         }
         string pauth = hc.GetPreferredAuthentications();
         if (pauth != null)
         {
             session.SetConfig("PreferredAuthentications", pauth);
         }
         if (credentialsProvider != null && (!hc.IsBatchMode() || !credentialsProvider.IsInteractive
                                                 ()))
         {
             session.SetUserInfo(new CredentialsProviderUserInfo(session, credentialsProvider)
                                 );
         }
         Configure(hc, session);
         return(session);
     }
 }
        /// <exception cref="NSch.JSchException"></exception>
        private Session CreateSession(CredentialsProvider credentialsProvider, FS fs, string
			 user, string pass, string host, int port, OpenSshConfig.Host hc)
        {
            Session session = CreateSession(hc, user, host, port, fs);
            if (pass != null)
            {
                session.SetPassword(pass);
            }
            string strictHostKeyCheckingPolicy = hc.GetStrictHostKeyChecking();
            if (strictHostKeyCheckingPolicy != null)
            {
                session.SetConfig("StrictHostKeyChecking", strictHostKeyCheckingPolicy);
            }
            string pauth = hc.GetPreferredAuthentications();
            if (pauth != null)
            {
                session.SetConfig("PreferredAuthentications", pauth);
            }
            if (credentialsProvider != null && (!hc.IsBatchMode() || !credentialsProvider.IsInteractive
                ()))
            {
                session.SetUserInfo(new CredentialsProviderUserInfo(session, credentialsProvider)
                    );
            }
            Configure(hc, session);
            return session;
        }
		/// <exception cref="NSch.JSchException"></exception>
		public override Session GetSession(string user, string pass, string host, int port
			, CredentialsProvider credentialsProvider, FS fs)
		{
			lock (this)
			{
				if (config == null)
				{
					config = OpenSshConfig.Get(fs);
				}
				OpenSshConfig.Host hc = config.Lookup(host);
				host = hc.GetHostName();
				if (port <= 0)
				{
					port = hc.GetPort();
				}
				if (user == null)
				{
					user = hc.GetUser();
				}
				Session session = CreateSession(hc, user, host, port, fs);
				if (pass != null)
				{
					session.SetPassword(pass);
				}
				string strictHostKeyCheckingPolicy = hc.GetStrictHostKeyChecking();
				if (strictHostKeyCheckingPolicy != null)
				{
					session.SetConfig("StrictHostKeyChecking", strictHostKeyCheckingPolicy);
				}
				string pauth = hc.GetPreferredAuthentications();
				if (pauth != null)
				{
					session.SetConfig("PreferredAuthentications", pauth);
				}
				if (credentialsProvider != null && (!hc.IsBatchMode() || !credentialsProvider.IsInteractive
					()))
				{
					session.SetUserInfo(new CredentialsProviderUserInfo(session, credentialsProvider)
						);
				}
				Configure(hc, session);
				return session;
			}
		}
Example #5
0
 /// <exception cref="NGit.Errors.TransportException"></exception>
 public override RemoteSession GetSession(URIish uri, CredentialsProvider credentialsProvider
                                          , FS fs, int tms)
 {
     lock (this)
     {
         string user = uri.GetUser();
         string pass = uri.GetPass();
         string host = uri.GetHost();
         int    port = uri.GetPort();
         try
         {
             if (config == null)
             {
                 config = OpenSshConfig.Get(fs);
             }
             OpenSshConfig.Host hc = config.Lookup(host);
             host = hc.GetHostName();
             if (port <= 0)
             {
                 port = hc.GetPort();
             }
             if (user == null)
             {
                 user = hc.GetUser();
             }
             Session session = CreateSession(hc, user, host, port, fs);
             if (pass != null)
             {
                 session.SetPassword(pass);
             }
             string strictHostKeyCheckingPolicy = hc.GetStrictHostKeyChecking();
             if (strictHostKeyCheckingPolicy != null)
             {
                 session.SetConfig("StrictHostKeyChecking", strictHostKeyCheckingPolicy);
             }
             string pauth = hc.GetPreferredAuthentications();
             if (pauth != null)
             {
                 session.SetConfig("PreferredAuthentications", pauth);
             }
             if (credentialsProvider != null && (!hc.IsBatchMode() || !credentialsProvider.IsInteractive
                                                     ()))
             {
                 session.SetUserInfo(new CredentialsProviderUserInfo(session, credentialsProvider)
                                     );
             }
             Configure(hc, session);
             if (!session.IsConnected())
             {
                 session.Connect(tms);
             }
             return(new JschSession(session, uri));
         }
         catch (JSchException je)
         {
             Exception c = je.InnerException;
             if (c is UnknownHostException)
             {
                 throw new TransportException(uri, JGitText.Get().unknownHost);
             }
             if (c is ConnectException)
             {
                 throw new TransportException(uri, c.Message);
             }
             throw new TransportException(uri, je.Message, je);
         }
     }
 }
		/// <exception cref="NGit.Errors.TransportException"></exception>
		public override RemoteSession GetSession(URIish uri, CredentialsProvider credentialsProvider
			, FS fs, int tms)
		{
			lock (this)
			{
				string user = uri.GetUser();
				string pass = uri.GetPass();
				string host = uri.GetHost();
				int port = uri.GetPort();
				try
				{
					if (config == null)
					{
						config = OpenSshConfig.Get(fs);
					}
					OpenSshConfig.Host hc = config.Lookup(host);
					host = hc.GetHostName();
					if (port <= 0)
					{
						port = hc.GetPort();
					}
					if (user == null)
					{
						user = hc.GetUser();
					}
					Session session = CreateSession(hc, user, host, port, fs);
					if (pass != null)
					{
						session.SetPassword(pass);
					}
					string strictHostKeyCheckingPolicy = hc.GetStrictHostKeyChecking();
					if (strictHostKeyCheckingPolicy != null)
					{
						session.SetConfig("StrictHostKeyChecking", strictHostKeyCheckingPolicy);
					}
					string pauth = hc.GetPreferredAuthentications();
					if (pauth != null)
					{
						session.SetConfig("PreferredAuthentications", pauth);
					}
					if (credentialsProvider != null && (!hc.IsBatchMode() || !credentialsProvider.IsInteractive
						()))
					{
						session.SetUserInfo(new CredentialsProviderUserInfo(session, credentialsProvider)
							);
					}
					Configure(hc, session);
					if (!session.IsConnected())
					{
						session.Connect(tms);
					}
					return new JschSession(session, uri);
				}
				catch (JSchException je)
				{
					Exception c = je.InnerException;
					if (c is UnknownHostException)
					{
						throw new TransportException(uri, JGitText.Get().unknownHost);
					}
					if (c is ConnectException)
					{
						throw new TransportException(uri, c.Message);
					}
					throw new TransportException(uri, je.Message, je);
				}
			}
		}