Binding an individual user's agent to a privileged port
From "Getting started with launchd" (http://developer.apple.com/macosx/launchd.html):
"Of particular interest is that launchd can run a job as a non-root user, but still bind it to a privileged port. This removes one common reason to run daemons as root." Is it possible for a user agent to be bound to a privileged port? This might sound like an odd thing to do, but I wish to automatically mount a remote SMB share on my local machine using SSH port forwarding. Unfortunately, since Finder is too stupid to let me mount shares at alternative ports on localhost (it tells me that I should just access the files locally!) and mount_smbfs doesn't take a port argument, I need to bind the remote ports 139 and 445 to the same ports on my local machine. I want this as an agent rather than a daemon for the purposes of SSH key management. It needs to run as an agent in the GUI context when I log in, as this is where the automatic SSH_AUTH_SOCK facility in Leopard lives. As far as I can tell, there are two ways of demonstrating to launchd that you have the authority to perform privileged operations such as binding to a port < 1024: putting a plist file in /Library/Launch*, or running launchctl sudo. The former means that the operation would be executed for all users, and the latter is sort of missing the point of the original exercise (not to mention bringing file permissions problems of its own). Is what I am trying to do possible with launchd? Hamish
At 22:23 +0000 23/1/08, Hamish Allan wrote:
Is it possible for a user agent to be bound to a privileged port?
No. Take a look at Figure 3 in TN2083. <http://developer.apple.com/technotes/tn2005/tn2083.html#FIGLAUNCHTREE> launchd agents are managed by the per-user launchds. Those launchds have irrevocably dropped all privileges. Thus, there's no way for them to be able to bind to a privileged port on your behalf. At 22:23 +0000 23/1/08, Hamish Allan wrote:
As far as I can tell, there are two ways of demonstrating to launchd that you have the authority to perform privileged operations such as binding to a port < 1024: putting a plist file in /Library/Launch*, or running launchctl sudo.
I believe you mean "/Library/LaunchDaemons" and not "/Library/Launch*". The latter would include agents (in "/Library/LaunchAgents"), which are restricted as I've described above. btw These two mechanism are fundamentally the same. o When you put a file in "/Library/LaunchDaemons", it is consulted by the root launchd at system startup. o When you run launchctl using sudo, it always talks to the root launchd. Thus, in both cases the launchd job gets loaded into the root launchd, which is the only one capable of binding to privileged ports. S+E -- Quinn "The Eskimo!" <http://www.apple.com/developer/> Apple Developer Relations, Developer Technical Support, Core OS/Hardware
participants (2)
-
Hamish Allan
-
Quinn