Table of Contents

Class SambaHelper

Namespace
VisioForge.Core.Helpers
Assembly
VisioForge.Core.dll

Helper class for SMB/CIFS share authentication using Windows networking APIs.

public static class SambaHelper

Inheritance

Inherited Members

Methods

ConnectToShare(string, string, string, string, BaseContext)

Connects to an SMB share with credentials.

public static bool ConnectToShare(string uncPath, string username, string password, string domain, BaseContext context = null)

Parameters

uncPath string

The UNC path (e.g., \server\share\file.avi).

username string

The username. When null/empty, the call is a no-op (the caller is expected to access the share anonymously / as the current user).

password string

The password. When non-empty, username must also be supplied — otherwise the call is rejected so a half-configured credential pair can't silently fall through to anonymous access.

domain string

The domain (optional).

context BaseContext

Optional logging context. When null, errors fall through to Trace.

Returns

bool

true if the share was authenticated successfully or no credentials were supplied (anonymous path). false when authentication was attempted and failed, or when only a password (no username) was supplied.

Remarks

The password argument is a managed String and therefore cannot be reliably zeroed (the CLR is free to copy or relocate string instances during GC). This is a known limitation — callers that need stronger guarantees should hold the password in a SecureString or pinned char[] upstream and pass the decoded form only at the lowest level. We minimize residual exposure by dropping our local references as soon as WNetAddConnection2 returns and not stashing any credential field on this helper.

Exceptions

ArgumentException

Thrown when uncPath is null/empty or doesn't begin with the UNC prefix \, or when username / domain contain a path separator (</code> or /). Embedded separators in the credential parts would misroute the WNetAddConnection2 credential string and risk path traversal / injection.

DisconnectFromShare(string, BaseContext)

Disconnects from an SMB share.

public static void DisconnectFromShare(string uncPath, BaseContext context = null)

Parameters

uncPath string

The UNC path.

context BaseContext

Optional logging context. When null, warnings fall through to Trace.