def mount_share_at_path(share_path, mount_path):
    """Mounts a share at the specified path

    Args:
        share_path: String URL with all auth info to connect to file share.
        mount_path: Path to mount share on.

    Returns:
        The mount point or raises an error
    """
    sh_url = CFURLCreateWithString(None, share_path, None)
    mo_url = CFURLCreateWithString(None, mount_path, None)
    # Set UI to reduced interaction
    open_options = {NetFS.kNAUIOptionKey: NetFS.kNAUIOptionNoUI}
    # Allow mounting sub-directories of root shares
    # Also specify the share should be mounted directly at (not under)
    # mount_path
    mount_options = {
        NetFS.kNetFSAllowSubMountsKey: True,
        NetFS.kNetFSMountAtMountDirKey: True
    }
    # Mount!
    result, output = NetFS.NetFSMountURLSync(sh_url, mo_url, None, None,
                                             open_options, mount_options, None)
    # Check if it worked
    if result != 0:
        raise Exception('Error mounting url "%s" at path "%s": %s' %
                        (share_path, mount_path, output))
    # Return the mountpath
    return str(output[0])
Exemplo n.º 2
0
def mount_share(share_path):
    """Mounts a share at /Volumes

    Args:
        share_path: String URL with all auth info to connect to file share.

    Returns:
        The mount point or raises an error.
    """
    sh_url = CFURLCreateWithString(None, share_path, None)

    # Set UI to reduced interaction
    if is_high_sierra():
        open_options = None
    else:
        open_options = {NetFS.kNAUIOptionKey: NetFS.kNAUIOptionNoUI}
    # Allow mounting sub-directories of root shares
    if is_high_sierra():
        mount_options = None
    else:
        mount_options = {NetFS.kNetFSAllowSubMountsKey: True}
    # Build our connected pointers for our results
    result, output = NetFS.NetFSMountURLSync(
        sh_url, None, None, None, open_options, mount_options, None)

    # Check if it worked
    if result != 0:
        raise Exception('Error mounting url "%s": %s' % (share_path, output))
    # Return the mountpath
    return str(output[0])
Exemplo n.º 3
0
def mount_share(share_url):
    '''Mounts a share at /Volumes, returns the mount point or raises an error'''
    # Uses some constants defined in NetFS.h
    # /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/
    #    Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/NetFS.framework/
    #    Versions/A/Headers/NetFS.h
    sh_url = CFURLCreateWithString(None, share_url, None)
    # Set UI to reduced interaction
    #open_options = {NetFS.kNAUIOptionKey: NetFS.kNAUIOptionNoUI}
    # can't look up the values for those constants in 10.13, so we'll just
    # hardcode them
    open_options = {'UIOption': 'NoUI'}
    # Allow mounting sub-directories of root shares
    #mount_options = {NetFS.kNetFSAllowSubMountsKey: True}
    # can't look up the values for those constants in 10.13, so we'll just
    # hardcode them
    mount_options = {'AllowSubMounts': True}
    # Mount!
    result, mountpoints = NetFS.NetFSMountURLSync(sh_url, None, None, None,
                                                  open_options, mount_options,
                                                  None)
    # Check if it worked
    if result != 0:
        if result in (-6600, errno.EINVAL, errno.ENOTSUP, errno.EAUTH):
            # -6600 is kNetAuthErrorInternal in NetFS.h 10.9+
            # errno.EINVAL is returned if an afp share needs a login in some
            #               versions of OS X
            # errno.ENOTSUP is returned if an afp share needs a login in some
            #               versions of OS X
            # errno.EAUTH is returned if authentication fails (SMB for sure)
            raise ShareAuthenticationNeededException()
        raise ShareMountException('Error mounting url "%s": %s, error %s' %
                                  (share_url, os.strerror(result), result))
    # Return the mountpath
    return str(mountpoints[0])
def mount_share(share_path: str) -> str:
    """Mount a share at /Volumes.

    :param str share_path: Path of the share.

    :returns: The mount path.

    :raises Exception: If there's an error mounting.
    """

    # Mounts a share at /Volumes, returns the mount point or raises an error
    sh_url = CFURLCreateWithString(None, share_path, None)
    # Set UI to reduced interaction
    open_options = {NetFS.kNAUIOptionKey: NetFS.kNAUIOptionNoUI}
    # Allow mounting sub-directories of root shares
    mount_options = {NetFS.kNetFSAllowSubMountsKey: True}
    # Mount!
    result, output = NetFS.NetFSMountURLSync(
        sh_url, None, None, None, open_options, mount_options, None
    )
    # Check if it worked
    if result != 0:
        raise Exception('Error mounting url "{}": {}'.format(share_path, output))
    # Return the mount path
    return str(output[0])
def mount_share(share_path):
    # Mounts a share at /Volumes, returns the mount point or raises an error
    sh_url = CFURLCreateWithString(None, share_path, None)
    # Set UI to reduced interaction
    open_options = {NetFS.kNAUIOptionKey: NetFS.kNAUIOptionNoUI}
    # Allow mounting sub-directories of root shares
    mount_options = {NetFS.kNetFSAllowSubMountsKey: True}
    # Mount!
    result, output = NetFS.NetFSMountURLSync(sh_url, None, None, None,
                                             open_options, mount_options, None)
    # Check if it worked
    if result != 0:
        raise Exception('Error mounting url "%s": %s' % (share_path, output))
    # Return the mountpath
    return str(output[0])
Exemplo n.º 6
0
def mount_share_with_credentials(share_url, username, password):
    '''Mounts a share at /Volumes, returns the mount point or raises an error
    Include username and password as parameters, not in the share_path URL'''
    sh_url = CFURLCreateWithString(None, share_url, None)
    # Set UI to reduced interaction
    open_options = {NetFS.kNAUIOptionKey: NetFS.kNAUIOptionNoUI}
    # Allow mounting sub-directories of root shares
    mount_options = {NetFS.kNetFSAllowSubMountsKey: True}
    # Mount!
    result, mountpoints = NetFS.NetFSMountURLSync(
        sh_url, None, username, password, open_options, mount_options, None)
    # Check if it worked
    if result != 0:
        raise ShareMountException('Error mounting url "%s": %s, error %s'
                                  % (share_url, os.strerror(result), result))
    # Return the mountpath
    return str(mountpoints[0])
Exemplo n.º 7
0
def mount_share(share_url):
    '''Mounts a share at /Volumes, returns the mount point or raises an error'''
    sh_url = CFURLCreateWithString(None, share_url, None)
    # Set UI to reduced interaction
    open_options = {NetFS.kNAUIOptionKey: NetFS.kNAUIOptionNoUI}
    # Allow mounting sub-directories of root shares
    mount_options = {NetFS.kNetFSAllowSubMountsKey: True}
    # Mount!
    result, mountpoints = NetFS.NetFSMountURLSync(
        sh_url, None, None, None, open_options, mount_options, None)
    # Check if it worked
    if result != 0:
        if result in (-6600, errno.EINVAL, errno.ENOTSUP, errno.EAUTH):
            # -6600 is kNetAuthErrorInternal in NetFS.h 10.9+
            # errno.EINVAL is returned if an afp share needs a login in some
            #               versions of OS X
            # errno.ENOTSUP is returned if an afp share needs a login in some
            #               versions of OS X
            # errno.EAUTH is returned if authentication fails (SMB for sure)
            raise ShareAuthenticationNeededException()
        raise ShareMountException('Error mounting url "%s": %s, error %s'
                                  % (share_url, os.strerror(result), result))
    # Return the mountpath
    return str(mountpoints[0])