Starting a file server (possibly NFSD) in snow leopard without requiring root? - macos

I want my OS X app to share files via the loopback device. I want to do this so that my app can make a directory of frequently changing, read only files available to the user without messing with the users home directory. The files will be severed from the Application Support directory but the user will not have to concern themselves with this.
Apple recommend using an NFS server to do this (see the 'alternatives' section of this Q&A):
http://developer.apple.com/mac/library/qa/qa2001/qa1242.html
As far as I can tell nfsd must be ran as root, which I'd prefer to avoid (asking the user for a password whenever the app starts would be a horrible UX).
Is it possible to start an nfsd instance without root?
Are there any alternative NFS servers which I could include with the app? (I couldn't find any)
Are there any alternatives servers that I could use? (The server would have to be AFP, SMB or WebDAV as these are the protocols that Finder can mount - I couldn't find any such servers).

I'm not sure I understand your use case but have you considered using a file system mounted from an OS X disk image? Disk images on OS X are very robust and very flexible: you can pretty much have any kind of file system(s) created on one image and can mount or dismount them at will and at whatever mount point(s) you like. See the man page for hdiutil for more info.
If the "files" you are trying to serve are not actually disk files, then you might want to look at MacFUSE, the mostly widely used implementation of FUSE for OS X.

Use MacFUSE. This is by far the easiest way to implement a file system.

Related

How to query if a particular folder is shared or enumerate folders shared from the local machine on osx in C/C++ or Objective C

I'm currently developing on macOS High Sierra (not Windows) using Qt. Just using regular macOS rather than macOS server. I'm happy to write Mac-only code outside the Qt bubble to fix this problem, obviously.
I'm looking for a way to programmatically check in C/C++ or Objective-C whether a particular local folder is shared on the local network. Alternatively I'd like to retrieve a list of all shared folders. I'd like the method to work on a reasonably large range of macOS versions e.g. 10.9 to 10.14.
I need to do this in order to rewrite paths to local files as UNC paths so that they are accessible from a Windows client machine on the same network via SMB sharing with suitable credentials. This does assume shared folders have already been setup but if they haven't the user will receive an error and be prompted to share suitable folders.
I can share/un-share and see the sharing status of a folder using the Get Info dialog in Finder but I'm looking for something I can use within an application.
Things I've tried without success:
Searching for other instances of the problem
NSURL class - doesn't document a resource name to query for its sharing status.
smbutil doesn't seem to list shares being shared from the machine it's running on.
smbd doesn't seem to have any command line options to query shared folders.
The various configuration files mentioned in the smbutil and smbd.conf man pages don't contain a list of shared folders
mdls doesn't contain any relevant metadata in the output for folders that are shared.
ls -l# doesn't list any extra information for shared folders
Sharing an unusually named folder and greping the hard disk for the folder name including binary files to see if this information is persisted somewhere. Presumably it is persisted somehow because the folder is shared after rebooting but I can't find any record of the folder name anywhere.
OpenDirectory services seem to contain lots of references to SMB in the headers but I can't see a way to use OpenDirectory to get a list of folders shared from the local machine.
Sharing the root folder so that the rewriting is trivial. This works but it's pretty undesirable to share a root folder.
Perhaps there's a better way of doing the access that will sidestep the need for having and querying SMB shares...?
Found the answer elsewhere on stackexchange answered by mivk.
Run the following command and capture the output.
sharing -l
This gives a slightly verbose list of file shares with separate details for afp and smb which can be parsed to get a list of shared folders on the local machine. Tested on Catalina. It's possible that this command will fail to run if file sharing is not enabled in System Preferences.

The intended usage of /Library/Application Support/ on OS X

My understanding is that the system-wide application support folder (i.e. /Library/Application Support/ as opposed to ~/Library/Application Support/ ) should be used by applications for storing files that are shared by all users on the machine.
What confuses me, however, is that the regular user does not have writing permission into it. Assuming that messing around with file permissions is not the correct way to go, what is then the usage of such a folder?
I have checked out an application that uses this folder (VirtualBox) and it seems that it creates its own subfolder and writes onto it during installation only (when admin credentials are active).
Initially I thought /Library/Application Support/ was used very dynamically by applications during normal usage, but I am starting to suspect I was wrong. This folder is very rarely written into (possibly just once) and is mostly used to read from.
Am I correct? If so, where is the recommended place to write user-shared application data that is frequently read and written?
'All Users' also imply superuser permission.
I think, [/Library/Application Support/] best suit for the Privileged Helper Tools.
Am I correct? If so, where is the recommended place to write user-shared application data that is frequently read and written?
For this purpose, there is [/Users/Shared/Library/Application Support].

Silverlight 5 Trusted Mode. Accessing FileSystem and Local drives

Is there any way, any chance at all to access entire filesystem in SL app with elevated trust?
That will work both in Windows and Mac?
Through AutomationFactory,PInvoke or unmanaged code?
I need an app that could read local drives, folders and files.
UDP: Ok, seems it's possible to read folders and files using classes of System.IO from mscorlib. Although you still can't get information about local mounted drives. There is no DriveInfo in Silverlight's mscorlib :(
Ok I have an idea about this.
It is straightforward enough with Windows, to get the list of the local drives you can use AutomationFactory. There is plenty amount of examples if you google it. Search for something called SilverlightFileExplorer.
Now on a Mac you can use Directory.EnumerateDirectories("/") and then it gets all the folders in the root. Including Volumes folder which contains shortcuts to the local drives. I'm not an expert of Berkeley System Distribution (BSD) Unix filesystems, so I can't really promise that it would work on any Mac, but this approach works on mine.
I'm still playing around with that. When I get working prototype I'll probably share it through github or something.

automatic Samba share script

I have an Ubuntu 10.04 server running Samba.
I want to write a script (for Linux or Windows computer) that, given the IP of this server and the path of the shared Samba folder, can automatically create a "network drive" icon on the desktop. Both machines are on a local network.
I realize this will be different for linux/windows.
Any suggestions? I'm just not sure where to start. Thanks!
For Windows machines, you want to look at net use. For instance, to map the share "Data" on 192.168.0.2 to Z:, you'd write net use Z: \\192.168.0.2\Data. There is a lot of options, so check net help use for a complete list. For instance, you might want to look at /persistent, which would automatically recreate the share every time you log in.
Or you could put this in a .BAT file which is executed when logging in.
On linux, I think you'd generally have to be root to do this, as it'd require a mount command. I know some desktop environments (such as GNOME) get around this, but to acually mount it you need root. The command to mount the same share at the mountpoint /mnt/Data would simply be mount //192.168.0.2/Data /mnt/Data, if you allow anyone access. If you require a logon, you need to add -o User=YOURUSER. You will then be prompted for a password.
(Note that this requires the CIFS/SMB drivers to work)

Can I hide a directory/path from Launch Services?

I would like to be able to build test applications (e.g. the nightly Minefield/Firefox) without Launch Services deciding that they're the best way to open their assigned file types.
Is there a way to hide my ~/src directory from Launch Services, so that Finder won't register applications in that folder?
I don't know of a way to do that hiding, but you can change the bundle ID of your development apps so that they don't get treated as the preferred app for that content type/URI scheme by LaunchServices.
and for Firefox specifically, the answer is: if OS X finds multiple applications that can handle an URL scheme, it will use the app with the highest version number. So, to fake out OS X, you can edit mozilla-central/browser/app/macbuild/Contents/Info.plist.in, and change the CFBundleShortVersionString from
<string>%APP_VERSION%</string>
to
<string>0.%APP_VERSION%</string>
This way, OS X will think the app is, say, version 0.3.2apre1, and it'll prefer the "real" version of Firefox.
A more general solution might be possible. OS X will prefer apps on a local volume to apps on a remote volume, and among local apps, it'll prefer those on the boot volume. So it might be possible to do some type of loopback mount, and keep your source code on a looped-back "volume", which again will lower its priority.
How OS X decides which app to launch for a given document or URL:
Launch Services Programming Guide: Preferred Applications

Resources