Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Cocoa/run sudo



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 writeData:[adminPass
dataUsingEncoding:NSUTF8StringEncoding]];

[target launch];

//try again :-/
[writeHandle writeData:[adminPass
dataUsingEncoding:NSUTF8StringEncoding]];


result=[[NSString alloc] initWithData:[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.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.