Working as a Linux Systems Administrator I frequently work with the init system on Linux sytems. OS X has a similar system called launchd.
The init system used in Linux reads init-scripts from /etc/init.d/. These scripts are regular bash-scripts that tells init.d what to do with a defined application. OS X reads XML files from /System/Library/LaunchDaemons/. In OS X you can control these services using the command “launchctl”.
I’ll show you how to add some extra security features to the tftp server in OS X and how to start it using launchctl. This will give you a quick overview on how launchd works.
First off all you have to add some new lines to tftp.plist.
Open tftp.plist in your favorite editor.
mate /System/Library/LaunchDaemons/tftp.plist
Under the key “ProgramArguments” add a new string
<string>-s</string>
This will chroot tftp to the directory configured in the string below. By default this string is /private/tftpboot/. This means that you have to put the files that you want you clients to reach under this directory.
You may also want to add the -l flag to enable logging to syslog. Have a look at “man tftpd” for additional arguments.
If you want to learn more about how plist files are built, take a look athttp://developer.apple.com/macosx/launchd.html
You can now start the tftp service using the following command:
sudo launchctl load \
-w /System/Library/LaunchDaemons/tftp.plist
And stopped with:
sudo launchctl unload \
-w /System/Library/LaunchDaemonds/tftp.plist
Please remember that the tftp protocol allows any user to read and write files to your system. Use with caution.
Lets check that everything works:
cd /private/tftpboot
sudo touch test-file
sudo chmod 666 test-file
cd $HOME
touch test-file
echo "TESTINGTESTING" > test-file
tftp localhost
put test-file
If there no errors are returned, everything works fine!
launchctl has a interactive mode, take a look at it:
sudo launchctl
Running “help” should give you alot of usefull information.