SmbMount

1. Overview

The SmbMount module provides SMB/CIFS repository access for BastionGuard Backup. It models network shares, mounts and unmounts CIFS paths, inventories active mounts, and persists remembered share definitions without serializing passwords.

The file declares multiple related types that cooperate inside the same utility layer.

The implementation is written in Vala and uses GLib/GIO together with the application utility namespaces required by the file.


2. Dependencies and Integration

The module imports:

  • GLib
  • Gee
  • Json
  • TeeJee.Logging
  • TeeJee.FileSystem
  • TeeJee.JsonHelper
  • TeeJee.ProcessHelper
  • TeeJee.Misc

Key runtime integrations include:

  • JSON-GLib – structured configuration or metadata serialization
  • Gee – typed lists, maps, queues, or collection operations
  • GIO/GLib streams – filesystem and process I/O

3. Declared Types

3.1 SmbShare

public class SmbShare : GLib.Object

This class encapsulates the state and operations described by this source file.

3.2 SmbMount

public class SmbMount : GLib.Object

This class encapsulates the state and operations described by this source file.


4. State, Properties, Constants, and Signals

Public and protected state

  • public string server – Runtime state used by the module.
  • public string share – Runtime state used by the module.
  • public string subpath – Runtime state used by the module.
  • public string username – Runtime state used by the module.
  • public string domain – Runtime state used by the module.
  • public string label – Filesystem or user-facing label.
  • public string mount_point – Filesystem mount location.
  • public string password – In-memory credential; the source intentionally avoids serializing it.
  • public bool save_credentials – Whether the caller requested credential persistence.
  • public string unc_path – Filesystem-related value used for unc path.
  • public string display_name – Name or identifier for display name.
  • public static string mount_root – Runtime state used by the module.

Internal state

  • private const string SHARES_CONF – Compile-time constant used by this module.

5. Public API and Operational Methods

5.1 to_json()

public Json.Object to_json()

Implements the to json operation for this module.

  • Reads or writes structured JSON data.

5.2 from_json()

public static SmbShare from_json(Json.Object obj)

Implements the from json operation for this module.

  • Reads or writes structured JSON data.

5.3 is_available()

public static bool is_available(out string error_message)

Evaluates is available and returns a Boolean capability or state result.

5.4 mount()

public static string mount(SmbShare share, out string error_message)

Validates CIFS tooling, creates a deterministic runtime mount point, builds mount options from the share definition, mounts the UNC path, and returns the mounted path.

  • Executes an external process or generated shell command and uses its return status as part of the result.
  • Performs filesystem access and handles files or directories through GLib or TeeJee helpers.
  • Processes credential-related values that should remain protected in memory and logs.

5.5 unmount()

public static bool unmount(SmbShare share)

Unmounts the requested filesystem or resource and reports the result.

5.6 unmount_path()

public static bool unmount_path(string mount_point)

Unmounts the requested filesystem or resource and reports the result.

5.7 is_mounted_at()

public static bool is_mounted_at(string mount_point)

Evaluates is mounted at and returns a Boolean capability or state result.

  • Performs filesystem access and handles files or directories through GLib or TeeJee helpers.
  • Catches runtime errors locally and reports them through the logging layer or return value.

5.8 list_active_mounts()

public static Gee.ArrayList<SmbShare> list_active_mounts()

Enumerates active mounts and returns or displays the resulting collection.

  • Performs filesystem access and handles files or directories through GLib or TeeJee helpers.
  • Reads or writes structured JSON data.
  • Catches runtime errors locally and reports them through the logging layer or return value.

5.9 load_saved_shares()

public static Gee.ArrayList<SmbShare> load_saved_shares()

Loads saved shares from persistent or system resources.

  • Performs filesystem access and handles files or directories through GLib or TeeJee helpers.
  • Reads or writes structured JSON data.
  • Catches runtime errors locally and reports them through the logging layer or return value.

5.10 save_share()

public static void save_share(SmbShare share)

Persists share using the module storage format.

5.11 forget_share()

public static void forget_share(SmbShare share)

Implements the forget share operation for this module.


6. Internal Helpers

6.1 write_shares()

private static void write_shares(Gee.ArrayList&lt;SmbShare&gt; list)

Serializes remembered SMB share definitions to JSON while excluding passwords.


7. Filesystem Paths and Resource Locations

The source references the following absolute or template paths:

//%s/%s
/etc/bastionguard-backup/smb-shares.json
/proc/mounts
/run/bastionguard-backup/smb
/smb

Some values are templates completed at runtime with application names, process IDs, device identifiers, or file names.


8. External Commands and System Interfaces

The module constructs, checks, or parses commands containing:

Failed to mount the network share.
SmbMount.mount(): mount -t cifs -o %s %s %s
mount -t cifs -o %s \"%s\" \"%s\"
mount.cifs

Execution success is determined from command exit status and, where applicable, parsed standard output or standard error.


9. Operational Flow

  1. Read or discover source data and normalize it into the module data model.
  2. Apply the requested operation and update runtime or persistent state.
  3. Finalize the operation and release files, mounts, child processes, widgets, or cached state.

10. Error Handling and Diagnostics

  • GLib and filesystem exceptions are caught locally in the operations that can fail.
  • The TeeJee logging layer records errors, debug state, generated commands, and operational messages.
  • Boolean, nullable, or empty-string return values communicate recoverable failures to callers.
  • Some methods return detailed diagnostics through output parameters in addition to their primary status value.

11. Runtime and Security Considerations

  • External commands: command availability, quoting, locale, privileges, and output format can affect behavior.
  • Dynamic command construction: caller-controlled values must be validated and escaped before being inserted into shell commands.
  • Sensitive data: credentials and passphrases should not be logged or persisted without protected storage and restrictive permissions.
  • Linux-specific paths: the module depends on Linux virtual filesystems or privileged system directories.
  • Output parsing: parsers depend on stable external-command or system-file formats and should be tested across distributions.
  • Shared state: static caches and global switches are shared by all callers and are not automatically thread-isolated.
  • Privilege and cleanup: mount or encryption operations should always pair successful setup with deterministic unmount or lock cleanup.

12. Licensing

The source is distributed under the GNU General Public License version 2 or any later version.

The source header identifies:

Copyright 2025-2026 Calogero Scarnà — BastionGuard Backup