Determine the user name that was used to login to a network server

When using the mount command on macOS, I can see mounted network servers like this:

//tt@mynas.local/NAS on /Volumes/NAS (smbfs, nodev, nosuid, mounted by thomas)

In this example "thomas" is my macOS user name, under which I mounted the "NAS" volume.

But there's also the "tt" name before the "@" - and that's what I'm interested in getting - that's the user name known to the server, i.e. the name I logged in on the server when the connection prompt appeared.

How do I get this name (tt) via macOS APIs? I can get it via "mount", but that requires parsing and is inefficient, and so I like to avoid that if possible.

man mount mentions getfsent(), but in my testing it only lists internal volumes, not network volumes.

Answered by Thomas Tempelmann in 779379022

The remote user name can be found in the f_mntfromname field from the statfs() call.

This might get you in the right direction, the APIs are somewhat similar. https://unix.stackexchange.com/questions/406301/how-to-get-nfs-user-list-and-kill-connection

Accepted Answer

The remote user name can be found in the f_mntfromname field from the statfs() call.

Determine the user name that was used to login to a network server
 
 
Q