1

I need something to run in my jailbreaked iPhone, "ifconfig en0 down", for example, which need to be ran with root privilege.

Although my application was installed with cydia and run under root permission, I dont have any way to call a command line tool with the same permissions, the these are diff ways i have tried :

1.calling system("ifconfig en0 down"); ->I got a "permission denied" notice in xcode's console;

2.using NSTask to run ifconfig directly, got the same problem(I copied NSTask.h file from mac osx framework, and it works!).

3.using NSTask to run "/bin/bash" with a bash script which requires and password interactive, but while i try to use NSPipe to interacte with the task, it doesnt response at all.

Some code would be like this :

NSPipe *p1 = [NSPipe pipe];
[self.task setStandardOutput:p1];

self.output= [p1 fileHandleForReading];

NSPipe *p2 = [NSPipe pipe];
[self.task setStandardInput:p2];

self.input = [p2 fileHandleForWriting];


[self.task launch];

NSLog(@"Launched...");

sleep(1);
[self.input writeData:[@"alpine" dataUsingEncoding:NSASCIIStringEncoding]];
NSLog(@"Password wrote...");

And i got notices from xcode's device console below...

Jun 25 22:10:30 unknown Demo[653] <Warning>: Launched...
Jun 25 22:10:30 unknown UIKitApplication:com.newland.Demo[0xefba][653] <Notice>: We trust you have received the usual lecture from the local System
Jun 25 22:10:30 unknown UIKitApplication:com.newland.Demo[0xefba][653] <Notice>: Administrator. It usually boils down to these three things:
Jun 25 22:10:30 unknown UIKitApplication:com.newland.Demo[0xefba][653] <Notice>:     #1) Respect the privacy of others.
Jun 25 22:10:30 unknown UIKitApplication:com.newland.Demo[0xefba][653] <Notice>:     #2) Think before you type.
Jun 25 22:10:30 unknown UIKitApplication:com.newland.Demo[0xefba][653] <Notice>:     #3) With great power comes great responsibility.
Jun 25 22:10:30 unknown UIKitApplication:com.newland.Demo[0xefba][653] <Notice>: Password:
Jun 25 22:10:31 unknown Demo[653] <Warning>: Password wrote...

And another problem is, before the NSTask is quit, the foreground process is frozen and i cant operate my application at all.

I found another command line tool named visudo which can make me interact with command line tool without input root user's password, but i dont want to try this way because i need everything go through codes.

All i want to know is how to get a interact with process created by NSTask and make is run with root privilege, or is there any way i can run a command line tool all programmly with root privilege?

Thanks a lot :)

0 Answers0