내 코코아 응용 프로그램에서 루트 권한으로 다른 응용 프로그램을 실행해야하지만 작동하지 않습니다! NSTask에는 필요한 권한이 없습니다. AuthorizationCreate 섹션에서 필요한 권한을 얻을 수 있습니다. NSTask를 실행하면 다른 응용 프로그램을 실행하는 부분입니다.NSTask 및 AuthorizationCreate
myStatus는 errAuthorizationSuccess를 반환합니다.
여기에 코드
//Authorization Create
AuthorizationRef myAuthorizationRef;
OSStatus myStatus;
myStatus = AuthorizationCreate (NULL, kAuthorizationEmptyEnvironment,
kAuthorizationFlagExtendRights | kAuthorizationFlagInteractionAllowed , &myAuthorizationRef);
AuthorizationItem myItems[1];
myItems[0].name = "com.myOrganization.myProduct.myRight1";
myItems[0].valueLength = 0;
myItems[0].value = NULL;
myItems[0].flags = 0;
AuthorizationRights myRights;
myRights.count = sizeof (myItems)/sizeof (myItems[0]);
myRights.items = myItems;
AuthorizationFlags myFlags;
myFlags = kAuthorizationFlagDefaults |
kAuthorizationFlagInteractionAllowed |
kAuthorizationFlagExtendRights;
myStatus = AuthorizationCopyRights (myAuthorizationRef, &myRights,
kAuthorizationEmptyEnvironment, myFlags, NULL);
if (myStatus==errAuthorizationSuccess)
{
//Running NSTask
//setting license
NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath: @"/opt/cprocsp/sbin/cpconfig"];
NSArray *arguments;
arguments = [NSArray arrayWithObjects:@"-license", @"-set",
@"lalala", nil];
[task setArguments: arguments];
NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
[task launch];
NSData *data;
data = [file readDataToEndOfFile];
NSString *string;
string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog (@"grep returned:\n%@", string);
[_logs insertText:string];
}
myStatus = AuthorizationFree (myAuthorizationRef,
kAuthorizationFlagDestroyRights);
내가 STPrivilege 그 때문에 ARC 프로젝트를 사용할 수 없습니다에게 있습니다. 내가 뭘 잘못하고있어? Thx 도움.
이에 대한 답변을합니까. 질문 도움? http://stackoverflow.com/questions/4050687/how-to-use-nstask-as-root – trojanfoe
Nope :( AuthorizeExecuteWithPrivileges()는 더 이상 사용되지 않으며 STPrivilegedTask는 내가 쓸 수 없으므로 ( – Dimson
) 앱이 샌드 박스로되어 있습니까? 인증 서비스가있는 경우 작동하지 않습니다. – sjs