Cocoa/run sudo
Cocoa/run sudo
- Subject: Cocoa/run sudo
- From: Michael Mulligan <email@hidden>
- Date: Tue, 02 Sep 2003 09:24:43 -0400
Hello all,
I was browsing the archives to the cocoa mailing lists, and I came across
this posting:
http://cocoa.mamasam.com/COCOADEV/2003/08/1/70182.php
I am now in a similar situation and I was wondering if anybody might be able
to help. I have written a function that runs some command with some set of
arguments under sudo, and it seems to work...just not the first time I run
my program. The first time I run it, it hangs, waiting for me to enter my
password, but after force quitting and running it again, everything is fine
(as if the password was entered from the first run and I still have like a 5
minute ticket). Obviously I can't tell my users to run my app, force quit,
and then run it again, so I was wondering if anybody had any ideas as to how
to go about resolving? (and yes, I know that the security framework is out
there and exists for a reason and I do hope to implement that later, but
right now I need a quick and dirty solution)
Thanks in advance for your time and consideration!
-Mike
The code snippet is as follows (if this is helpful):
//args is basically an array that would have -S, cp, a, b, nil so that sudo
-S cp a b would be run
-(NSString *)runAsSudoCommand:(NSArray *)args
{
//[...]
[target setLaunchPath:@"/usr/bin/sudo"];
[target setArguments:args];
[target setStandardInput:psswrdPipe];
[target setStandardOutput:outPipe];
writeHandle=[psswrdPipe fileHandleForWriting];
outHandle=[outPipe fileHandleForReading];
//try to write the password to sudo
[writeHandle write
Data:[adminPass
dataUsingEncoding:NSUTF8StringEncoding]];
[target launch];
//try again :-/
[writeHandle write
Data:[adminPass
dataUsingEncoding:NSUTF8StringEncoding]];
result=[[NSString alloc] initWith
Data:[outHandle readDataToEndOfFile]
encoding:NSASCIIStringEncoding];
// [...]
return result;
}
-Mike
__________
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me
spread!
__________
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.