2

I am an iPhone Developer, now I am making an App that need to run commands (like "launchctl") The only way I can launcht is with root privileges, but i dont know how to get root privileges.

I want to call it with System("launchctl....") or there is other way?

Thanks in advance ;)

AlvaroAV
  • 10,335
  • 12
  • 60
  • 91
BRIT
  • 55
  • 2
  • 4
  • 2
    You're aware that apps for distribution on the app store simply can't do this? If you want to distribute on jailbreak, that's another matter, but it sounds like you're looking at the app store... – lxt May 09 '11 at 20:58
  • no, no, i want to make an App for Cydia (jailbroken devices) – BRIT May 10 '11 at 02:33

4 Answers4

1

I built a jailbreak app once that was trying to do something similar. I wasn't using launchctl, but I was issuing a call using system().

What I found was that even if I let my app run as user root, which requires more than what edc1591 outlined in his comment above, system calls would still run whatever command you passed it (e.g. launchctl) with user mobile privileges. (Aside: I think the reason might be related to this issue).

If you want to do that, I found a rather convoluted way of doing so. See that answer here.

Community
  • 1
  • 1
Nate
  • 31,017
  • 13
  • 83
  • 207
1

First of all, using system(); is a C method and is not very reliable at all for executing commands like that, (I know from experience). What you would want to do, is copy the NSTask.h file from the foundation.framework into your project window and use it. the way to find it is by opening a new project for the mac and clicking show in finder on the foundation.framework and then copy it. (Make sure to remove the lines near the top that check if you have Mac OS 10.6 or greater)

Then try running it. If it still doesn't have the right privileges, try looking into setuid(); but other than that, i don't know how it's done. Maybe you can contact the developer of iFile, he would know how...

Jailpod
  • 150
  • 10
1

You cannot get root privileges if your going to distribute this in the App Store. However, you can get root access if you're developing this for jailbroken devices.

edc1591
  • 10,146
  • 6
  • 40
  • 63
  • I am developing for Jailbroken Devices – BRIT May 09 '11 at 21:16
  • In that case, for the app to run as root you need to fake codesign it with `ldid`, `chmod` the binary to 755 and make sure the app is installed in /Applications on the device. – edc1591 May 09 '11 at 21:21
  • and if I do that, I will be able to run commands (system("launchctl..")) as root? – BRIT May 09 '11 at 21:41
  • Do you know where I can get a tutorial? – BRIT May 10 '11 at 02:34
  • Nope sorry. Try googling around or ask in #iphonedev on irc.saurik.com. They can be pretty helpful. – edc1591 May 10 '11 at 02:54
  • @edc1591, this is not sufficient. I have an app that I've successfully run as root, but executing system("launchctl ...") from within the app does not work. – Nate Jun 28 '11 at 05:47
  • 1
    Wouldn't really consider this an answer. More of a comment. – Damien Roche Jun 17 '12 at 19:38
0

Unfortunately, there is no Apple sanctioned way to do this. In other words, apps that require root access will not be approved for use in the App Store. It is possible that Apple will grant an exception, but that's is seriously, extremely, unlikely.

Moshe
  • 57,511
  • 78
  • 272
  • 425