Hey liebes OS X Entwicklerforum!
Ich habe ein Problem in einem Projekt, in dem ich per NSTask den apache starten will. Dafür brauche ich allerdings root-Rechte und daher habe ich mich der Apple Doc zur Authorization bedient. Leider funktioniert das ganze nicht ganz so wie gewünscht.. Man wird nach dem Passwort gefragt und ich gebe es ein, das funktioniert alles, aber wenn ich mir per NSAlert den Output des NSTasks ausgeben lasse bekomme ich nur: "This operation requires root"
Hier mein Code:
Alles anzeigen
Alles anzeigen
Was habe ich falsch gemacht?
Liebe Grüße und Danke im Vorraus!
ThePat
Ich habe ein Problem in einem Projekt, in dem ich per NSTask den apache starten will. Dafür brauche ich allerdings root-Rechte und daher habe ich mich der Apple Doc zur Authorization bedient. Leider funktioniert das ganze nicht ganz so wie gewünscht.. Man wird nach dem Passwort gefragt und ich gebe es ein, das funktioniert alles, aber wenn ich mir per NSAlert den Output des NSTasks ausgeben lasse bekomme ich nur: "This operation requires root"
Hier mein Code:
Quellcode
Quellcode
- - (NSString*) startApache {
- AuthorizationItem authItem;
- authItem.name = "de.PAT.ApacheControl.startApache";
- authItem.valueLength = 0;
- authItem.value = NULL;
- authItem.flags = 0;
- AuthorizationRights authRights = { 1, &authItem };
- AuthorizationFlags authFlags = kAuthorizationFlagDefaults | kAuthorizationFlagInteractionAllowed | kAuthorizationFlagPreAuthorize | kAuthorizationFlagExtendRights;
- OSStatus status = AuthorizationCopyRights(_authRef, &authRights, kAuthorizationEmptyEnvironment, authFlags, NULL);
- if(status != errAuthorizationSuccess) {
- /** ERR **/
- return false;
- } else {
- NSTask* task = [NSTask new];
- [task setLaunchPath: @"/usr/sbin/apachectl"];
- [task setArguments: [NSArray arrayWithObjects: @"start", nil]];
- NSPipe* pipe = [NSPipe pipe];
- [task setStandardOutput: pipe];
- [task launch];
- NSData* data = [[pipe fileHandleForReading] readDataToEndOfFile];
- [task waitUntilExit];
- NSString* output = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
- return output;
- }
- }
Was habe ich falsch gemacht?
Liebe Grüße und Danke im Vorraus!
ThePat