Class SambaHelper
- Namespace
- VisioForge.Core.Helpers
- Assembly
- VisioForge.Core.dll
Helper class for SMB/CIFS share authentication using Windows networking APIs.
public static class SambaHelperInheritance
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
uncPathstring-
The UNC path (e.g., \server\share\file.avi).
usernamestring-
The username. When null/empty, the call is a no-op (the caller is expected to access the share anonymously / as the current user).
passwordstring-
The password. When non-empty,
usernamemust also be supplied — otherwise the call is rejected so a half-configured credential pair can't silently fall through to anonymous access. domainstring-
The domain (optional).
contextBaseContext-
Optional logging context. When null, errors fall through to Trace.
Returns
- bool
-
trueif the share was authenticated successfully or no credentials were supplied (anonymous path).falsewhen 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
uncPathis null/empty or doesn't begin with the UNC prefix\, or whenusername/domaincontain 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
uncPathstring-
The UNC path.
contextBaseContext-
Optional logging context. When null, warnings fall through to Trace.