SMBMountShareEx mount permissions

Hi,

I am trying to mount a share programatically using SmbClient.framework. (SMBFramework 30064).


Here is my code:

SMBHANDLE mConnection;
uint64_t options = kSMBOptionSessionOnly;
NTSTATUS status = SMBOpenServerEx("smb://john:passwd@192.168.12.34/share1", &mConnection, options);
if (NT_SUCCESS(status)) {
  status = SMBMountShareEx(mConnection, nullptr,"/var/tmp/share1", MNT_DONTBROWSE, 0, 0, 0, nullptr, nullptr);
}


After mounting a share, I can navigate to mounted path and explore it from the Finder. However I see that the permissions for all the files from GetInfo shows "You have unknown access" and I cannot edit any file. finder throws -120 or the editing app cannot save that file.


If I mount the same share with the "mount" command, the GetInfo shows "You have custom access" and I can edit any file properly.


I tried with different mount options but nothing seems to solve the issue. Editing text files work but not word or excel file.


here is the output of mount command: the first one was mounted using "mount" command, the second was mounted using "SMBMountShareEx"

//vkawade@172.16.147.75/elc on /Users/vinay/mPoint (smbfs, nodev, nosuid, mounted by john)

//vkawade@172.16.147.75/elc on private/var/tmp/uuid:92588:device (smbfs, nodev, nosuid, nobrowse, mounted by john)


Any help would be highly appreciated!


Thanks,

Vink

I am trying to mount a share programatically using SmbClient.framework.

Last I checked SMBClient framework wasn’t public API.

What’s your high-level goal here? If you’re just trying to mount a file server in the standard way, you have two other options:

  • The older API (

    FSMountServerVolumeAsync
    and so on) in
    <CarbonCore/Files.h>
    .
  • Startin with 10.8, you can use

    NetFSMountURLAsync
    from
    <NetFS/NetFS.h>
    .

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Higher level goal is: I want this smb mounted silently and not appear in the Favorites/ side bar. I can do this using smb.framework.


I tried using

NetFSMountURLAsync, but could not set the mount options.

How do I set the MNT_DONTBROWSE option?


CFMutableDictionaryRef mountOpts = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(mountOpts, kNetFSMountAtMountDirKey, CFSTR("true"));
//CFDictionarySetValue(mountOpts, kNetFSMountFlagsKey, CFSTR("MNT_DONTBROWSE")); // *** enabling this gives internal error -6600
//CFDictionarySetValue(mountOpts, kNetFSMountFlagsKey, CFSTR("nobrowse")); // *** enabling this gives internal error -6600

CFMutableDictionaryRef openOpts = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(openOpts, kNAUIOptionKey, kNAUIOptionNoUI);

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%s", "smb://john:passwd@10.0.0.77"]];
NSURL *mPoint = [NSURL URLWithString:[NSString stringWithFormat:@"%s", "/var/tmp/myshare"]];
CFArrayRef mountpoints = NULL;

int result = NetFSMountURLSync((__bridge CFURLRef) url,                     
                           (__bridge CFURLRef) mPoint,
                            NULL,
                            NULL,
                            openOpts,
                            mountOpts,          
                            &mountpoints);

How do I set the

MNT_DONTBROWSE
option?

Using

kNetFSMountFlagsKey
. Your previous code is failing because the value of
kNetFSMountFlagsKey
is meant to be a number, not a string. So you could do this:
mountOpts = @{
    (__bridge NSString *) kNetFSMountAtMountDirKey: @YES,
    (__bridge NSString *) kNetFSMountFlagsKey: @(MNT_DONTBROWSE)
};
result = NetFSMountURLSync(
    …
    (__bridge CFDictionaryRef) mountOpts
    …
);

Note that I’ve also fixed

kNetFSMountAtMountDirKey
in the above example; you want a CFBoolean, not the string “true”.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks Eskimo, that worked.


However I am not able to hide the mountpoint. I am mounting at '/var/tmp/abc' and not '/Volume/", and it automatically appears in the Finder side-bar.


I was under the impression that 'MNT_DONTBROWSE' and mount path as non "/Volume/..." would make it hide. Mounting with the smb.framework does prevent the mounted share to appear in the Finder side bar.


Is there any mount option or open option to do that?

I was under the impression that 'MNT_DONTBROWSE' and mount path as non "/Volume/..." would make it hide.

I would expect the same.

Did you verify that

MNT_DONTBROWSE
‘stuck’? What does mount show?

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

There are two places on the side bar on Finder, where the mount point appears.


The "Favorite" and the "Shared".


Specifying "

MNT_DONTBROWSE" with NetFSMountURLSync, the mount point appears in the Favorites bar, but I do not see it in the "Shared" section. That is the only change I see with "MNT_DONTBROWSE" option.


However with Smb.framework, I am able to hide it from the Favorite section too. I tesed this on Yosimite 10.10.5.


Is there a way to mount a share at some hidden location and not let it appear on either Favorite or Shared side bar?


Thanks.

Is there a way to mount a share at some hidden location and not let it appear on either Favorite or Shared side bar?

I’m out of a ideas at this point. You should open DTS tech support incident and we can dig into it in more detail in that context.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
SMBMountShareEx mount permissions
 
 
Q