SMB Share Execution Properties

The SMB server provides a set of service properties to support the execution of a command or script when SMB shares are connected or disconnected. These properties are configurable with the sharectl command and are applied to all shares. You can use the command or script to perform automated administrative tasks each time a share is mapped (connected) or unmapped (disconnected). These scripts and commands are run as superuser. For example, you might use a command to create home directories or to monitor resources.

You must be superuser or assume an equivalent role to use sharectl to configure these properties.

The service property names and values are as follows:

  • map – The value of this property is a command to execute when the client connects to the share. The command can take the following arguments, which are substituted when the command is executed:

    • %D Domain or workgroup name of %U.

    • %h Server host name.

    • %I IP address of the client system.

    • %i Local IP address to which the client is connected.

    • %L Server NetBIOS name.

    • %M Client host name, or "" if the host name is not available.

    • %m Client NetBIOS name, or "" if not available. This option is valid only for NetBIOS connections (port 139).

    • %P Root directory of the share.

    • %S Share name.

    • %U Windows user name.

    • %u UID of the UNIX user.

  • unmap – The value of this property is a command to execute when the client disconnects from the share. The command can use the same arguments that are described for the map property.

  • disposition=[continue|terminate] – This property controls whether to disconnect the share or proceed if the map command fails. This property has meaning only when the map property has been set. Otherwise, it has no effect.

    Valid values for the disposition property are:

    • continue Proceed with the share connection if the map command fails. This is the default behavior when the disposition property is not specified.

    • terminate Disconnect the share if the map command fails.

Example 1-1 Using SMB Share Execution Properties

The following sharectl examples show how you might set the map, unmap, and disposition properties:

$ sharectl set -p map="/tmp/map_script %U" smb
$ sharectl set -p unmap=/tmp/unmap_script smb
$ sharectl set -p disposition=terminate smb

The first command runs the /tmp/map_script Windows-username command when a share is mapped. The second command runs the /tmp/unmap_script command when a share is unmapped. The third command specifies that the share will disconnect if the command fails during the mapping operation.