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); } }
internal SmbComTreeConnectAndX(SmbSession session, string path, string service, ServerMessageBlock andx) : base(andx) { this._session = session; this.path = path; this._service = service; Command = SmbComTreeConnectAndx; }
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; }
/// <exception cref="WinrtCifs.Smb.SmbException"></exception> private static NtlmChallenge Interrogate(NbtAddress addr) { UniAddress dc = new UniAddress(addr); SmbTransport trans = SmbTransport.GetSmbTransport(dc, 0); if (Username == null) { trans.Connect(); if (SmbTransport.LogStatic.Level >= 3) { SmbTransport.LogStatic.WriteLine("Default credentials (jcifs.smb.client.username/password)" + " not specified. SMB signing may not work propertly." + " Skipping DC interrogation." ); } } else { SmbSession ssn = trans.GetSmbSession(NtlmPasswordAuthentication.Default ); ssn.GetSmbTree(LogonShare, null).TreeConnect(null, null); } return(new NtlmChallenge(trans.Server.EncryptionKey, dc)); }
/// <exception cref="WinrtCifs.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"); } } }