Authenticate 执行SMB2认证
(ctx context.Context, host string, port int, cred Credential, domain string, timeout time.Duration, session *common.ScanSession)
| 481 | |
| 482 | // Authenticate 执行SMB2认证 |
| 483 | func (a *SMB2Authenticator) Authenticate(ctx context.Context, host string, port int, cred Credential, domain string, timeout time.Duration, session *common.ScanSession) (*AuthResult, error) { |
| 484 | timeoutCtx, cancel := context.WithTimeout(ctx, timeout) |
| 485 | defer cancel() |
| 486 | |
| 487 | conn, err := session.DialTCP(ctx, "tcp", fmt.Sprintf("%s:%d", host, port), timeout) |
| 488 | if err != nil { |
| 489 | return &AuthResult{ |
| 490 | Success: false, |
| 491 | ErrorType: classifySMBError(err), |
| 492 | Error: err, |
| 493 | }, nil |
| 494 | } |
| 495 | |
| 496 | d := &smb2.Dialer{ |
| 497 | Initiator: &smb2.NTLMInitiator{ |
| 498 | User: cred.Username, |
| 499 | Password: cred.Password, |
| 500 | Domain: domain, |
| 501 | }, |
| 502 | } |
| 503 | |
| 504 | s, err := d.DialContext(timeoutCtx, conn) |
| 505 | if err != nil { |
| 506 | _ = conn.Close() |
| 507 | return &AuthResult{ |
| 508 | Success: false, |
| 509 | ErrorType: classifySMBError(err), |
| 510 | Error: fmt.Errorf("SMB2认证失败: %w", err), |
| 511 | }, nil |
| 512 | } |
| 513 | |
| 514 | // 尝试列举共享来验证认证成功 |
| 515 | _, _ = s.ListSharenames() |
| 516 | |
| 517 | return &AuthResult{ |
| 518 | Success: true, |
| 519 | Conn: &smb2SessionWrapper{s, conn}, |
| 520 | ErrorType: ErrorTypeUnknown, |
| 521 | Error: nil, |
| 522 | }, nil |
| 523 | } |
| 524 | |
| 525 | // ListShares 列举SMB2共享 |
| 526 | func (a *SMB2Authenticator) ListShares(ctx context.Context, host string, port int, cred Credential, domain string, timeout time.Duration, session *common.ScanSession) ([]string, error) { |
nothing calls this directly
no test coverage detected