Question

I am developing for Jailbroken iPhone. I need to write(copy) a file to iPhone System Folders (/Library/LaunchDaemons) to which only ROOT has write access. How can i write a file to such folders through my Code. I know i can use NSFileManager's copyItemAtPath:toPath method to copy the file, but i cant write as i dont have permission to write on such folders.

Any Suggestions??

Was it helpful?

Solution

i think i have found the answer to this question. In order to write to System folders you need to have permission to write on that folder. My app had a Daemon attached to it, so i had to copy that Daemon to /System/Library/LaunchDaemons to make that Daemon work. So as i am developing for JB iphone and people are going to install my app using Cydia, why not to make Cydia install the files of my app to proper locations. I made Cydia to copy the Daemon file into /System/Library/LaunchDaemon folder. Now the question is how Cydia will know where to paste the files. Answer is simple, just make the proper folders in .deb file and cydia will paste the files located in the folders inside the .deb file.

For Example if you have a Daemon and you want Cydia to paste it to /System/Library/LaunchDaemons , make the file structure like this before making a .deb

+- MyApp
   +- Applications
      +Myapp.app
   +-DEBIAN
    -control
   +-System
     +-Library
       +-LaunchDaemons
         +- com.myLaunchDaemon.plist

Cydia while installing your app will paste the com.myLaunchDaemon.plist file in System/Library/LaunchDaemons, reboot and you are good to go.

OTHER TIPS

Your app could run as root or setuid root.

Instead of running your whole app as root it is much better design to have a small helper tool that will install the files. Then only that helper tool has to run as root.

For more info about SUID binaries check http://en.wikipedia.org/wiki/Setuid as a good start.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top