internal SmbComTreeConnectAndX(SmbSession session, string path, string service, ServerMessageBlock
			 andx) : base(andx)
		{
			this._session = session;
			this.path = path;
			this._service = service;
			Command = SmbComTreeConnectAndx;
		}
Example #2
0
		internal SmbTree(SmbSession session, string share, string service)
		{
			// used by SmbFile.isOpen
			this.Session = session;
			this.Share = share.ToUpper();
			if (service != null && service.StartsWith("??") == false)
			{
				this.Service = service;
			}
			Service0 = this.Service;
			ConnectionState = 0;
		}
Example #3
0
        internal virtual SmbSession GetSmbSession(NtlmPasswordAuthentication auth)
        {
            lock (this)
            {
                SmbSession ssn;
                long now;

                ssn = Sessions.FirstOrDefault(s => s.Matches(auth));
                if (ssn != null)
                {
                    ssn.Auth = auth;
                    return ssn;
                }

                if (SmbConstants.SoTimeout > 0 && SessionExpiration < (now = Runtime.CurrentTimeMillis()))
                {
                    SessionExpiration = now + SmbConstants.SoTimeout;

                    foreach (var session in Sessions.Where(s => s.Expiration < now))
                    {
                        session.Logoff(false);
                    }
                }
                ssn = new SmbSession(Address, Port, LocalAddr, LocalPort, auth);
                ssn.transport = this;
                Sessions.Add(ssn);
                return ssn;
            }
        }
		/// <exception cref="SharpCifs.Smb.SmbException"></exception>
		internal SmbComSessionSetupAndX(SmbSession session, ServerMessageBlock andx, object
			 cred) : base(andx)
		{
			Command = SmbComSessionSetupAndx;
			this.Session = session;
			this.Cred = cred;
			_sessionKey = session.transport.SessionKey;
			_capabilities = session.transport.Capabilities;
            if (session.transport.Server.Security == SmbConstants.SecurityUser)
			{
				if (cred is NtlmPasswordAuthentication)
				{
					NtlmPasswordAuthentication auth = (NtlmPasswordAuthentication)cred;
					if (auth == NtlmPasswordAuthentication.Anonymous)
					{
						_lmHash = new byte[0];
						_ntHash = new byte[0];
						_capabilities &= ~SmbConstants.CapExtendedSecurity;
					}
					else
					{
						if (session.transport.Server.EncryptedPasswords)
						{
							_lmHash = auth.GetAnsiHash(session.transport.Server.EncryptionKey);
							_ntHash = auth.GetUnicodeHash(session.transport.Server.EncryptionKey);
							// prohibit HTTP auth attempts for the null session
							if (_lmHash.Length == 0 && _ntHash.Length == 0)
							{
								throw new RuntimeException("Null setup prohibited.");
							}
						}
						else
						{
						    if (DisablePlainTextPasswords)
							{
								throw new RuntimeException("Plain text passwords are disabled");
							}
						    if (UseUnicode)
						    {
						        // plain text
						        string password = auth.GetPassword();
						        _lmHash = new byte[0];
						        _ntHash = new byte[(password.Length + 1) * 2];
						        WriteString(password, _ntHash, 0);
						    }
						    else
						    {
						        // plain text
						        string password = auth.GetPassword();
						        _lmHash = new byte[(password.Length + 1) * 2];
						        _ntHash = new byte[0];
						        WriteString(password, _lmHash, 0);
						    }
						}
					}
					_accountName = auth.Username;
					if (UseUnicode)
					{
						_accountName = _accountName.ToUpper();
					}
					_primaryDomain = auth.Domain.ToUpper();
				}
				else
				{
					if (cred is byte[])
					{
						_blob = (byte[])cred;
					}
					else
					{
						throw new SmbException("Unsupported credential type");
					}
				}
			}
			else
			{
                if (session.transport.Server.Security == SmbConstants.SecurityShare)
				{
					if (cred is NtlmPasswordAuthentication)
					{
						NtlmPasswordAuthentication auth = (NtlmPasswordAuthentication)cred;
						_lmHash = new byte[0];
						_ntHash = new byte[0];
						_accountName = auth.Username;
						if (UseUnicode)
						{
							_accountName = _accountName.ToUpper();
						}
						_primaryDomain = auth.Domain.ToUpper();
					}
					else
					{
						throw new SmbException("Unsupported credential type");
					}
				}
				else
				{
					throw new SmbException("Unsupported");
				}
			}
		}