Commit 6049543f authored by David Smith's avatar David Smith Committed by david

Lots of Mac changes: new prefpane UI, uses a helper tool instead of shell...

Lots of Mac changes: new prefpane UI, uses a helper tool instead of shell scripts, closer to 10.5 compatibility

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6465 b35dd754-fafc-0310-a699-88a17e54d16e
parent 684c6966
......@@ -2,14 +2,19 @@
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>EnvironmentVariables</key>
<dict>
<key>WILDFIRE_HOME</key>
<string>/usr/local/wildfire/</string>
</dict>
<key>Label</key>
<string>org.jivesoftware.wildfire</string>
<key>OnDemand</key>
<false/>
<key>ProgramArguments</key>
<array>
<string>/usr/local/wildfire/bin/extra/wildfire-launchd-wrapper.sh</string>
</array>
<key>Program</key>
<string>/usr/local/wildfire/bin/extra/wildfire-launchd-wrapper.sh</string>
<key>RunAtLoad</key>
<false/>
<key>ServiceDescription</key>
......
#!/bin/bash
#determine safe uid/gid
WILDFIRE_USER=`nireport / /users name | grep "wildfire"`
WILDFIRE_GID=`nireport / /users gid | sort -n | egrep -v "\b[5-9][0-9]{2,5}\b" | tail -n 1`
let "WILDFIRE_GID=$WILDFIRE_GID+1"
echo $WILDFIRE_GID > /private/tmp/wildfiregid
if [ -z $WILDFIRE_USER] ; then
WILDFIRE_UID=`nireport / /users uid | sort -n | egrep -v "\b[5-9][0-9]{2,5}\b" | tail -n 1`
let "WILDFIRE_UID=$WILDFIRE_UID+1"
echo $WILDFIRE_UID
#create user
niutil -create . /users/wildfire
#set properties
niutil -createprop . /users/wildfire gid $WILDFIRE_GID
niutil -createprop . /users/wildfire uid $WILDFIRE_UID
niutil -createprop . /users/wildfire shell /usr/bin/false
niutil -createprop . /users/wildfire home /usr/local/wildfire/
niutil -createprop . /users/wildfire realname "Jive Wildfire"
niutil -createprop . /users/wildfire passwd '*'
fi
\ No newline at end of file
NIUTIL_PRESENT=`which niutil`
if [ -z $NIUTIL_PRESENT] ; then
echo "No niutil"
WILDFIRE_USER=`dscl . -search /Users name wildfire | awk '{print $1}'`
WILDFIRE_GID=`dscl . -readall /Users PrimaryGroupID | awk '/PrimaryGroupID/{print $2}' | sort -n | egrep -v "\b[5-9][0-9]{2,5}\b" | tail -n 1`
let "WILDFIRE_GID=$WILDFIRE_GID+1"
echo $WILDFIRE_GID > /private/tmp/wildfiregid
if [ -z $WILDFIRE_USER ] ; then
WILDFIRE_UID=`dscl . -readall /Users UniqueID | awk '/UniqueID/{print $2}' | sort -n | egrep -v "\b[5-9][0-9]{2,5}\b" | tail -n 1`
let "WILDFIRE_UID=$WILDFIRE_UID+1"
echo $WILDFIRE_UID
#create user
dscl . -create /Users/wildfire
#set properties
dscl . -create /Users/wildfire PrimaryGroupID $WILDFIRE_GID
dscl . -create /Users/wildfire UniqueID $WILDFIRE_UID
dscl . -create /Users/wildfire UserShell /usr/bin/false
dscl . -create /Users/wildfire NFSHomeDirectory /usr/local/wildfire/
dscl . -create /Users/wildfire RealName "Jive Wildfire"
dscl . -passwd /Users/wildfire '*'
fi
else
WILDFIRE_USER=`nireport / /users name | grep "wildfire"`
WILDFIRE_GID=`nireport / /users gid | sort -n | egrep -v "\b[5-9][0-9]{2,5}\b" | tail -n 1`
let "WILDFIRE_GID=$WILDFIRE_GID+1"
echo $WILDFIRE_GID > /private/tmp/wildfiregid
if [ -z $WILDFIRE_USER] ; then
WILDFIRE_UID=`nireport / /users uid | sort -n | egrep -v "\b[5-9][0-9]{2,5}\b" | tail -n 1`
let "WILDFIRE_UID=$WILDFIRE_UID+1"
echo $WILDFIRE_UID
#create user
niutil -create . /users/wildfire
#set properties
niutil -createprop . /users/wildfire gid $WILDFIRE_GID
niutil -createprop . /users/wildfire uid $WILDFIRE_UID
niutil -createprop . /users/wildfire shell /usr/bin/false
niutil -createprop . /users/wildfire home /usr/local/wildfire/
niutil -createprop . /users/wildfire realname "Jive Wildfire"
niutil -createprop . /users/wildfire passwd '*'
fi
fi
{
IBClasses = (
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
{CLASS = NSObject; LANGUAGE = ObjC; },
{
CLASS = NSPreferencePane;
LANGUAGE = ObjC;
......@@ -12,24 +13,20 @@
};
SUPERCLASS = NSObject;
},
{CLASS = SFAuthorizationView; LANGUAGE = ObjC; SUPERCLASS = NSView; },
{CLASS = WilfireStartStop; LANGUAGE = ObjC; SUPERCLASS = NSButton; },
{
ACTIONS = {
openAdminInterface = id;
openAdminInterfaceSSL = id;
toggleAutoStart = id;
toggleServer = id;
};
ACTIONS = {openAdminInterface = id; toggleAutoStart = id; toggleServer = id; };
CLASS = wildfirePrefPane;
LANGUAGE = ObjC;
OUTLETS = {
authView = SFAuthorizationView;
autoStartCheckbox = NSButton;
startButton = NSButton;
statusDescription = NSTextField;
statusMessage = NSTextField;
statusProgress = NSProgressIndicator;
viewAdminButton = NSButton;
viewAdminButtonSSL = NSButton;
};
SUPERCLASS = NSPreferencePane;
}
......
......@@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
<string>1155 145 481 349 0 0 1680 1028 </string>
<string>35 145 481 349 0 0 1280 778 </string>
<key>IBFramework Version</key>
<string>446.1</string>
<key>IBOpenObjects</key>
......
#include <unistd.h>
#include <stdbool.h>
#include <CoreFoundation/CoreFoundation.h>
static void CFQRelease(CFTypeRef cf)
// A version of CFRelease that's tolerant of NULL.
{
if (cf != NULL) {
CFRelease(cf);
}
}
static int GetPathToSelf(char **pathToSelfPtr)
// A drop-in replacement for GetPathToSelf() from MoreAuthSample's MoreSecurity.c,
// implemented using CoreFoundation. From CocoaDev.com
{
int err = 0;
assert( pathToSelfPtr != NULL);
assert(*pathToSelfPtr == NULL);
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef executableURL = NULL;
CFStringRef pathStringRef = NULL;
char *path = NULL;
if (mainBundle != NULL) {
executableURL = CFBundleCopyExecutableURL(mainBundle);
if (executableURL != NULL) {
pathStringRef = CFURLCopyFileSystemPath(executableURL, kCFURLPOSIXPathStyle);
if (pathStringRef != NULL) {
CFIndex pathSize = CFStringGetLength(pathStringRef) + 1;
path = (char *)calloc(pathSize,1);
if (path != NULL) {
Boolean gotCString = CFStringGetCString(pathStringRef, path, pathSize, kCFStringEncodingUTF8);
if (!gotCString) {
free(path);
path = NULL;
}
}
}
}
}
*pathToSelfPtr = path;
// Do the CF memory management.
CFQRelease(executableURL);
CFQRelease(pathStringRef);
assert(*pathToSelfPtr != NULL);
if (*pathToSelfPtr == NULL)
{
err = -1;
}
return err;
}
static bool wildfireIsRunning()
{
FILE *ps;
char buff[1024];
if((ps=popen("/bin/ps auxww | fgrep -v 'fgrep' | fgrep wildfire/lib/startup.jar", "r")) == NULL)
{
return false;
}
else
{
bool running = false;
if(fgets(buff, 1024, ps)) {
running = true;
}
pclose(ps);
return running;
}
}
static void toggleStartWildfireAtBoot()
{
CFURLRef propFile = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
CFSTR("/Library/LaunchDaemons/org.jivesoftware.wildfire.plist"),
kCFURLPOSIXPathStyle,
false);
CFDataRef xmlData;
CFURLCreateDataAndPropertiesFromResource (kCFAllocatorDefault,
propFile,
&xmlData,
NULL,
NULL,
NULL);
CFPropertyListRef props = CFPropertyListCreateFromXMLData(kCFAllocatorDefault,
xmlData,
kCFPropertyListMutableContainersAndLeaves,
NULL);
if(CFGetTypeID(props) == CFDictionaryGetTypeID()) {
CFMutableDictionaryRef propsDict = (CFMutableDictionaryRef)props;
CFBooleanRef currentValue = CFDictionaryGetValue(propsDict,CFSTR("RunAtLoad"));
CFDictionaryReplaceValue(propsDict, CFSTR("RunAtLoad"), ((currentValue == kCFBooleanTrue) ? kCFBooleanFalse : kCFBooleanTrue));
CFQRelease(xmlData);
xmlData = CFPropertyListCreateXMLData(kCFAllocatorDefault,(CFPropertyListRef)propsDict);
CFURLWriteDataAndPropertiesToResource(propFile,xmlData,NULL,NULL);
}
CFQRelease(props);
CFQRelease(xmlData);
CFQRelease(propFile);
}
static void toggleWildfire()
{
char *args[4];
args[0] = "launchctl";
if(wildfireIsRunning())
args[1] = "unload";
else
args[1] = "load";
args[2] = "/Library/LaunchDaemons/org.jivesoftware.wildfire.plist";
args[3] = NULL;
execv("/bin/launchctl", args);
}
int main(int inArgsCount, char * const inArgs[])
{
char* selfPath = NULL;
int err = GetPathToSelf(&selfPath);
const char* correctPath = "/Library/PreferencePanes/Wildfire.prefPane/Contents/MacOS/HelperTool";
if(err == 0 && strncmp(correctPath, selfPath, strlen(correctPath)) == 0) {
setuid(0);
if(inArgs[1] && strlen(inArgs[1]) == strlen("boot") && strncmp("boot", inArgs[1], strlen("boot")) == 0) {
toggleStartWildfireAtBoot();
} else {
toggleWildfire();
}
}
return 1;
}
\ No newline at end of file
#!/bin/bash
CURRENT_FLAG=`sudo awk '/RunAtLoad/{getline; print}' /Library/LaunchDaemons/org.jivesoftware.wildfire.plist | tr -d '\n' | grep true`
echo "Current flag is $CURRENT_FLAG"
if [ -z "$CURRENT_FLAG" ] ; then
CURRENT_FLAG="false"
NEW_FLAG="true"
else
CURRENT_FLAG="true"
NEW_FLAG="false"
fi
sudo sed -i "" -e "/RunAtLoad/ {
n
s/$CURRENT_FLAG/$NEW_FLAG/
}" /Library/LaunchDaemons/org.jivesoftware.wildfire.plist
......@@ -9,8 +9,8 @@
//
#import <PreferencePanes/PreferencePanes.h>
#import <Security/Authorization.h>
#import <Security/AuthorizationTags.h>
#import <Security/Security.h>
#import <SecurityInterface/SFAuthorizationView.h>
#include <unistd.h>
// 'ps' command to use to check for running wildfire daemon
......@@ -25,16 +25,10 @@ NSString *plistPath = @"/Library/LaunchDaemons/org.jivesoftware.wildfire.plist";
IBOutlet NSButton *startButton;
IBOutlet NSButton *autoStartCheckbox;
IBOutlet NSButton *viewAdminButton;
IBOutlet NSButton *viewAdminButtonSSL;
IBOutlet NSTextField *statusMessage;
IBOutlet NSTextField *statusDescription;
IBOutlet NSProgressIndicator *statusProgress;
AuthorizationRef authorizationRef;
AuthorizationRights authRights;
AuthorizationRights *authorizedRights;
AuthorizationFlags authFlags;
OSStatus ourStatus;
IBOutlet SFAuthorizationView *authView;
NSTimer *statusTimer;
}
......@@ -42,7 +36,6 @@ NSString *plistPath = @"/Library/LaunchDaemons/org.jivesoftware.wildfire.plist";
- (IBAction)toggleServer:(id)sender;
- (IBAction)toggleAutoStart:(id)sender;
- (IBAction)openAdminInterface:(id)sender;
- (IBAction)openAdminInterfaceSSL:(id)sender;
- (void)mainViewDidLoad;
- (void)updateStatus;
- (void)startServer;
......
......@@ -8,6 +8,7 @@
// Concept taken from MySQL preference panel, as well as some borrowed code.
//
#import <Security/Security.h>
#import <CoreFoundation/CoreFoundation.h>
#import "wildfirePrefPane.h"
......@@ -15,53 +16,28 @@
- (void)mainViewDidLoad
{
authRights.count = 0;
authRights.items = NULL;
authFlags = kAuthorizationFlagDefaults;
ourStatus = AuthorizationCreate(&authRights, kAuthorizationEmptyEnvironment, authFlags, &authorizationRef);
AuthorizationItem authItems[1]; // we only want to get authorization for one command
authItems[0].name = kAuthorizationRightExecute; // we want the right to execute
char *cmd = [[[NSBundle bundleForClass:[self class]] pathForAuxiliaryExecutable:@"HelperTool"] fileSystemRepresentation];
authItems[0].value = cmd; // the path to the helper tool
authItems[0].valueLength = strlen(cmd); // length of the command
authItems[0].flags = 0; // no extra flags
AuthorizationRights authRights;
authRights.count = 1; // we have one item
authRights.items = authItems; // here is the values for our item
[authView setAuthorizationRights:&authRights];
[authView setAutoupdate:YES];
[authView setDelegate:self];
[authView updateStatus:self];
[statusProgress setStyle:NSProgressIndicatorSpinningStyle];
[statusProgress setDisplayedWhenStopped:NO];
BOOL isStartingAtBoot = [[[NSMutableDictionary dictionaryWithContentsOfFile:plistPath] objectForKey:@"RunAtLoad"] boolValue];
[autoStartCheckbox setState:(isStartingAtBoot ? NSOnState : NSOffState)];
[self updateStatus];
}
- (void)dealloc
{
AuthorizationFree(authorizationRef, kAuthorizationFlagDestroyRights);
authorizationRef = NULL;
[super dealloc];
}
- (void)updateStatus
{
NSLog(@"updateStatus called");
if ([self isRunning] == NO)
{
NSLog(@"isRunning == NO");
[statusMessage setStringValue:@"Stopped"];
[statusMessage setTextColor:[NSColor redColor]];
[statusDescription setStringValue:@"The Wildfire server is currently stopped.\nTo start it, use the \"Start Wildfire\" button.\nPlease be aware that it may take a few seconds for the server to start up."];
[startButton setTitle:@"Start Wildfire"];
[viewAdminButton setHidden:YES];
[viewAdminButtonSSL setHidden:YES];
}
else
{
NSLog(@"isRunning == YES");
[statusMessage setStringValue:@"Running"];
[statusMessage setTextColor:[NSColor greenColor]];
[statusDescription setStringValue:@"The Wildfire server is currently running.\nTo stop it, use the \"Stop Wildfire\" button.\nYou may access the admin interface by using one of the buttons below."];
[startButton setTitle:@"Stop Wildfire"];
[viewAdminButton setHidden:NO];
[viewAdminButtonSSL setHidden:NO];
}
}
- (BOOL)isRunning
{
FILE *ps;
......@@ -103,113 +79,54 @@
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:stringURL]];
}
- (IBAction)openAdminInterfaceSSL:(id)sender
{
NSString *stringURL = @"https://localhost:9091/";
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:stringURL]];
}
- (IBAction)toggleAutoStart:(id)sender
{
NSMutableDictionary *launchSettings = [NSMutableDictionary dictionaryWithContentsOfFile:plistPath];
BOOL isStartingAtBoot = [[launchSettings objectForKey:@"RunAtLoad"] boolValue];
AuthorizationItem authItems[1]; // we only want to get authorization for one command
BOOL authorized = NO; // are we authorized?
char *args[6];
char *command = [[[NSBundle bundleForClass:[self class]] pathForResource:@"autostartsetter" ofType:@"sh"] fileSystemRepresentation];
authItems[0].name = kAuthorizationRightExecute; // we want the right to execute
authItems[0].value = command; // the path to the startup script
authItems[0].valueLength = strlen(command); // length of the command
authItems[0].flags = 0; // no extra flags
authRights.count = 1; // we have one item
authRights.items = authItems; // here is the values for our item
// by setting the kAuthorizationFlagExtendRights flag, we are telling
// the security framework to bring up the authorization panel and ask for
// our password in order to get root privelages to execute the startup script
authFlags = kAuthorizationFlagInteractionAllowed | kAuthorizationFlagExtendRights;
// lets find out if we are authorized
ourStatus = AuthorizationCopyRights(authorizationRef,&authRights,
kAuthorizationEmptyEnvironment, authFlags, NULL);
char *args[2];
args[0] = "boot";
args[1] = NULL;
authorized = (errAuthorizationSuccess==ourStatus);
if (authorized)
{
// we are authorized, so let's tell the security framework to execute
// our command as root
args[0] = [(isStartingAtBoot ? @"true/false" : @"false/true") cStringUsingEncoding:NSASCIIStringEncoding];
args[1] = NULL;
ourStatus = AuthorizationExecuteWithPrivileges(authorizationRef,
command,
kAuthorizationFlagDefaults, args, NULL);
// wait for the server to start
OSStatus ourStatus = AuthorizationExecuteWithPrivileges([[authView authorization] authorizationRef],
[authView authorizationRights]->items[0].value,
kAuthorizationFlagDefaults, args, NULL);
if(ourStatus != errAuthorizationSuccess)
{
// alert user the startup has failed
NSBeginAlertSheet(
@"Error!",
@"OK",
nil,
nil,
[NSApp mainWindow],
self,
nil,
nil,
self,
@"Could not start the Wildfire server.",
nil);
[statusTimer invalidate];
[self checkStatus];
}
else
{
// wait for the daemon to start so that we can update the status
//sleep(2);
}
}
else
{
// there was an error getting authentication, either the user entered the
// wrong password or isn't in the admin group
NSBeginAlertSheet(@"Authentication Error!", @"OK", nil, nil, [NSApp mainWindow],
self, nil, nil, self, @"An error occured while receiving authentication to start Wildfire.",
if(ourStatus != errAuthorizationSuccess)
{
// alert user the startup has failed
NSBeginAlertSheet(
@"Error!",
@"OK",
nil,
nil,
[NSApp mainWindow],
self,
nil,
nil,
self,
@"Could not start the Wildfire server.",
nil);
[statusTimer invalidate];
[self checkStatus];
}
[self checkStatus];
}
[self updateStatus];
}
- (IBAction)toggleServer:(id)sender
{
NSLog(@"Toggling WildFire from prefpane");
[statusMessage setHidden:YES];
[statusProgress startAnimation:self];
[startButton setEnabled:NO];
if(![self isRunning])
{
[statusMessage setStringValue:@"Starting"];
[self startServer];
statusTimer = [NSTimer scheduledTimerWithTimeInterval:6 target:self
statusTimer = [NSTimer scheduledTimerWithTimeInterval:4 target:self
selector:@selector(checkStatus) userInfo:nil repeats:NO];
}
else
{
[statusMessage setStringValue:@"Stopping"];
[self stopServer];
statusTimer = [NSTimer scheduledTimerWithTimeInterval:6 target:self
statusTimer = [NSTimer scheduledTimerWithTimeInterval:4 target:self
selector:@selector(checkStatus) userInfo:nil repeats:NO];
}
[self updateStatus];
......@@ -218,171 +135,91 @@
- (void)checkStatus
{
[statusProgress stopAnimation:self];
[statusMessage setHidden:NO];
[startButton setEnabled:YES];
[self updateStatus];
}
- (void)updateStatus
{
if ([self isRunning] == NO)
{
[statusMessage setStringValue:@"Stopped"];
[statusMessage setTextColor:[NSColor redColor]];
[statusDescription setStringValue:@"The server may take a few seconds to start up."];
[startButton setTitle:@"Start Wildfire"];
[viewAdminButton setEnabled:NO];
}
else
{
[statusMessage setStringValue:@"Running"];
[statusMessage setTextColor:[NSColor greenColor]];
[statusDescription setStringValue:@"The server may take a few seconds to stop."];
[startButton setTitle:@"Stop Wildfire"];
[viewAdminButton setEnabled:YES];
}
BOOL isStartingAtBoot = [[[NSMutableDictionary dictionaryWithContentsOfFile:plistPath] objectForKey:@"RunAtLoad"] boolValue];
[autoStartCheckbox setState:(isStartingAtBoot ? NSOnState : NSOffState)];
}
- (void)startServer
{
// setup our authorization environment.
AuthorizationItem authItems[1]; // we only want to get authorization for one command
BOOL authorized = NO; // are we authorized?
char *args[4];
//lame workaround for a bug
char *command = "/usr/bin/sudo";
authItems[0].name = kAuthorizationRightExecute; // we want the right to execute
authItems[0].value = command; // the path to the startup script
authItems[0].valueLength = strlen(command); // length of the command
authItems[0].flags = 0; // no extra flags
authRights.count = 1; // we have one item
authRights.items = authItems; // here is the values for our item
// by setting the kAuthorizationFlagExtendRights flag, we are telling
// the security framework to bring up the authorization panel and ask for
// our password in order to get root privelages to execute the startup script
authFlags = kAuthorizationFlagInteractionAllowed | kAuthorizationFlagExtendRights;
// lets find out if we are authorized
ourStatus = AuthorizationCopyRights(authorizationRef,&authRights,
kAuthorizationEmptyEnvironment, authFlags, NULL);
authorized = (errAuthorizationSuccess==ourStatus);
if (authorized)
{
// we are authorized, so let's tell the security framework to execute
// our command as root
args[0] = "launchctl";
args[1] = "load";
args[2] = "/Library/LaunchDaemons/org.jivesoftware.wildfire.plist";
args[3] = NULL;
ourStatus = AuthorizationExecuteWithPrivileges(authorizationRef,
command,
kAuthorizationFlagDefaults, args, NULL);
// wait for the server to start
if(ourStatus != errAuthorizationSuccess)
{
// alert user the startup has failed
NSBeginAlertSheet(
@"Error!",
@"OK",
nil,
nil,
[NSApp mainWindow],
self,
nil,
nil,
self,
@"Could not start the Wildfire server.",
nil);
[statusTimer invalidate];
[self checkStatus];
}
else
{
// wait for the daemon to start so that we can update the status
//sleep(2);
}
}
else
{
// there was an error getting authentication, either the user entered the
// wrong password or isn't in the admin group
NSBeginAlertSheet(@"Authentication Error!", @"OK", nil, nil, [NSApp mainWindow],
self, nil, nil, self, @"An error occured while receiving authentication to start Wildfire.",
nil);
char *args[0];
args[1] = NULL;
OSStatus ourStatus = AuthorizationExecuteWithPrivileges([[authView authorization] authorizationRef],
[authView authorizationRights]->items[0].value,
kAuthorizationFlagDefaults, args, NULL);
// wait for the server to start
if(ourStatus != errAuthorizationSuccess)
{
// alert user the startup has failed
NSBeginAlertSheet(
@"Error!",
@"OK",
nil,
nil,
[NSApp mainWindow],
self,
nil,
nil,
self,
@"Could not start the Wildfire server.",
nil);
[statusTimer invalidate];
[self checkStatus];
}
[self checkStatus];
}
}
- (void) stopServer
{
// setup our authorization environment.
AuthorizationItem authItems[1]; // we only want to get authorization for one command
BOOL authorized = NO; // are we authorized?
char *args[4];
char *args[1];
args[0] = NULL;
OSStatus ourStatus = AuthorizationExecuteWithPrivileges([[authView authorization] authorizationRef],
[authView authorizationRights]->items[0].value,
kAuthorizationFlagDefaults, args, NULL);
//lame workaround for a bug
char *command = "/usr/bin/sudo";
authItems[0].name = kAuthorizationRightExecute; // we want the right to execute
authItems[0].value = command; // the path to the startup script
authItems[0].valueLength = strlen(command); // length of the command
authItems[0].flags = 0; // no extra flags
authRights.count = 1; // we have one item
authRights.items = authItems; // here is the values for our item
// by setting the kAuthorizationFlagExtendRights flag, we are telling
// the security framework to bring up the authorization panel and ask for
// our password in order to get root privelages to execute the startup script
authFlags = kAuthorizationFlagInteractionAllowed | kAuthorizationFlagExtendRights;
// lets find out if we are authorized
ourStatus = AuthorizationCopyRights(authorizationRef,&authRights,
kAuthorizationEmptyEnvironment, authFlags, NULL);
authorized = (errAuthorizationSuccess==ourStatus);
if (authorized)
{
// we are authorized, so let's tell the security framework to execute
// our command as root
args[0] = "launchctl";
args[1] = "unload";
args[2] = "/Library/LaunchDaemons/org.jivesoftware.wildfire.plist";
args[3] = NULL;
ourStatus = AuthorizationExecuteWithPrivileges(authorizationRef,
command,
kAuthorizationFlagDefaults, args, NULL);
if(ourStatus != errAuthorizationSuccess)
{
// alert user the startup has failed
NSBeginAlertSheet(
@"Error!",
@"OK",
nil,
nil,
[NSApp mainWindow],
self,
nil,
nil,
self,
@"Could not stop the Wildfire server.",
nil);
[statusTimer invalidate];
[self checkStatus];
}
else
{
// wait for the daemon to start so that we can update the status
//sleep(2);
}
}
else
{
// there was an error getting authentication, either the user entered the
// wrong password or isn't in the admin group
NSBeginAlertSheet(@"Authentication Error!", @"OK", nil, nil, [NSApp mainWindow],
self, nil, nil, self, @"An error occured while receiving authentication to stop Wildfire.",
nil);
if(ourStatus != errAuthorizationSuccess)
{
// alert user the startup has failed
NSBeginAlertSheet(
@"Error!",
@"OK",
nil,
nil,
[NSApp mainWindow],
self,
nil,
nil,
self,
@"Could not stop the Wildfire server.",
nil);
[statusTimer invalidate];
[self checkStatus];
}
[self checkStatus];
}
}
@end
......@@ -7,7 +7,10 @@
objects = {
/* Begin PBXBuildFile section */
6387AE500B29E3FF00E98223 /* autostartsetter.sh in Resources */ = {isa = PBXBuildFile; fileRef = 6387AE4F0B29E3FF00E98223 /* autostartsetter.sh */; };
633BEA0B0B39DF03003AD355 /* SecurityInterface.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 633BEA0A0B39DF03003AD355 /* SecurityInterface.framework */; };
633BEA7A0B39EB60003AD355 /* authTool.c in Sources */ = {isa = PBXBuildFile; fileRef = 633BEA790B39EB60003AD355 /* authTool.c */; };
633BEAAD0B39EEF8003AD355 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 633BEAAC0B39EEF8003AD355 /* CoreFoundation.framework */; };
6358CFF40B39F6B800BFA7DC /* HelperTool in CopyFiles */ = {isa = PBXBuildFile; fileRef = 633BEA760B39EB2B003AD355 /* HelperTool */; };
650096350A60403400B6046A /* jivesoftware_logo.png in Resources */ = {isa = PBXBuildFile; fileRef = 650096340A60403400B6046A /* jivesoftware_logo.png */; };
65E2E73A0A5E8F2900DFFC2E /* wildfire-logo.png in Resources */ = {isa = PBXBuildFile; fileRef = 65E2E7390A5E8F2900DFFC2E /* wildfire-logo.png */; };
65E2E74C0A5EAE6600DFFC2E /* wildfirePrefPaneLogo.tiff in Resources */ = {isa = PBXBuildFile; fileRef = 65E2E74B0A5EAE6600DFFC2E /* wildfirePrefPaneLogo.tiff */; };
......@@ -21,17 +24,43 @@
8D202CF40486D31800D8A456 /* PreferencePanes.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F506C035013D953901CA16C8 /* PreferencePanes.framework */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
633BEA860B39ED7D003AD355 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 089C1669FE841209C02AAC07 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 633BEA750B39EB2B003AD355;
remoteInfo = HelperTool;
};
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
6358CFDD0B39F5F700BFA7DC /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 6;
files = (
6358CFF40B39F6B800BFA7DC /* HelperTool in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
089C1672FE841209C02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
089C167EFE841241C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
089C167FFE841241C02AAC07 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
32DBCFA20370C41700C91783 /* wildfirePrefPane_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wildfirePrefPane_Prefix.pch; sourceTree = "<group>"; };
6387AE4F0B29E3FF00E98223 /* autostartsetter.sh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.script.sh; path = autostartsetter.sh; sourceTree = "<group>"; };
633BEA0A0B39DF03003AD355 /* SecurityInterface.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SecurityInterface.framework; path = /System/Library/Frameworks/SecurityInterface.framework; sourceTree = "<absolute>"; };
633BEA760B39EB2B003AD355 /* HelperTool */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = HelperTool; sourceTree = BUILT_PRODUCTS_DIR; };
633BEA790B39EB60003AD355 /* authTool.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = authTool.c; sourceTree = "<group>"; };
633BEAAC0B39EEF8003AD355 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = /System/Library/Frameworks/CoreFoundation.framework; sourceTree = "<absolute>"; };
650096340A60403400B6046A /* jivesoftware_logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = jivesoftware_logo.png; sourceTree = "<group>"; };
65E2E7390A5E8F2900DFFC2E /* wildfire-logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "wildfire-logo.png"; sourceTree = "<group>"; };
65E2E74B0A5EAE6600DFFC2E /* wildfirePrefPaneLogo.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = wildfirePrefPaneLogo.tiff; sourceTree = "<group>"; };
65E2E7C80A5EF1F200DFFC2E /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/Security.framework; sourceTree = "<absolute>"; };
65E2E7C80A5EF1F200DFFC2E /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = /System/Library/Frameworks/Security.framework; sourceTree = "<absolute>"; };
8D202CF70486D31800D8A456 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
8D202CF80486D31800D8A456 /* Wildfire.prefPane */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Wildfire.prefPane; sourceTree = BUILT_PRODUCTS_DIR; };
F506C035013D953901CA16C8 /* PreferencePanes.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PreferencePanes.framework; path = /System/Library/Frameworks/PreferencePanes.framework; sourceTree = "<absolute>"; };
......@@ -41,6 +70,14 @@
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
633BEA740B39EB2B003AD355 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
633BEAAD0B39EEF8003AD355 /* CoreFoundation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
8D202CF20486D31800D8A456 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
......@@ -48,6 +85,7 @@
8D202CF30486D31800D8A456 /* Cocoa.framework in Frameworks */,
8D202CF40486D31800D8A456 /* PreferencePanes.framework in Frameworks */,
65E2E7C90A5EF1F200DFFC2E /* Security.framework in Frameworks */,
633BEA0B0B39DF03003AD355 /* SecurityInterface.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -69,7 +107,6 @@
089C1671FE841209C02AAC07 /* Frameworks and Libraries */ = {
isa = PBXGroup;
children = (
65E2E7C80A5EF1F200DFFC2E /* Security.framework */,
1058C7ACFEA557BF11CA2CBB /* Linked Frameworks */,
1058C7AEFEA557BF11CA2CBB /* Other Frameworks */,
);
......@@ -80,7 +117,6 @@
isa = PBXGroup;
children = (
65E2E74B0A5EAE6600DFFC2E /* wildfirePrefPaneLogo.tiff */,
6387AE4F0B29E3FF00E98223 /* autostartsetter.sh */,
8D202CF70486D31800D8A456 /* Info.plist */,
089C167DFE841241C02AAC07 /* InfoPlist.strings */,
65E2E7380A5E8F1600DFFC2E /* Images */,
......@@ -101,8 +137,11 @@
1058C7ACFEA557BF11CA2CBB /* Linked Frameworks */ = {
isa = PBXGroup;
children = (
1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */,
633BEAAC0B39EEF8003AD355 /* CoreFoundation.framework */,
633BEA0A0B39DF03003AD355 /* SecurityInterface.framework */,
F506C035013D953901CA16C8 /* PreferencePanes.framework */,
65E2E7C80A5EF1F200DFFC2E /* Security.framework */,
1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */,
);
name = "Linked Frameworks";
sourceTree = "<group>";
......@@ -120,6 +159,7 @@
isa = PBXGroup;
children = (
8D202CF80486D31800D8A456 /* Wildfire.prefPane */,
633BEA760B39EB2B003AD355 /* HelperTool */,
);
name = Products;
sourceTree = "<group>";
......@@ -128,6 +168,7 @@
isa = PBXGroup;
children = (
32DBCFA20370C41700C91783 /* wildfirePrefPane_Prefix.pch */,
633BEA790B39EB60003AD355 /* authTool.c */,
);
name = "Other Sources";
sourceTree = "<group>";
......@@ -156,6 +197,22 @@
/* End PBXHeadersBuildPhase section */
/* Begin PBXNativeTarget section */
633BEA750B39EB2B003AD355 /* HelperTool */ = {
isa = PBXNativeTarget;
buildConfigurationList = 633BEA7B0B39EB60003AD355 /* Build configuration list for PBXNativeTarget "HelperTool" */;
buildPhases = (
633BEA730B39EB2B003AD355 /* Sources */,
633BEA740B39EB2B003AD355 /* Frameworks */,
);
buildRules = (
);
dependencies = (
);
name = HelperTool;
productName = HelperTool;
productReference = 633BEA760B39EB2B003AD355 /* HelperTool */;
productType = "com.apple.product-type.tool";
};
8D202CE80486D31800D8A456 /* Wildfire */ = {
isa = PBXNativeTarget;
buildConfigurationList = 65E2E7290A5E8C0F00DFFC2E /* Build configuration list for PBXNativeTarget "Wildfire" */;
......@@ -165,10 +222,12 @@
8D202CF00486D31800D8A456 /* Sources */,
8D202CF20486D31800D8A456 /* Frameworks */,
8D202CF50486D31800D8A456 /* Rez */,
6358CFDD0B39F5F700BFA7DC /* CopyFiles */,
);
buildRules = (
);
dependencies = (
633BEA870B39ED7D003AD355 /* PBXTargetDependency */,
);
name = Wildfire;
productInstallPath = "$(HOME)/Library/PreferencePanes";
......@@ -185,8 +244,10 @@
hasScannedForEncodings = 1;
mainGroup = 089C166AFE841209C02AAC07 /* wildfirePrefPane */;
projectDirPath = "";
projectRoot = "";
targets = (
8D202CE80486D31800D8A456 /* Wildfire */,
633BEA750B39EB2B003AD355 /* HelperTool */,
);
};
/* End PBXProject section */
......@@ -201,7 +262,6 @@
65E2E73A0A5E8F2900DFFC2E /* wildfire-logo.png in Resources */,
65E2E74C0A5EAE6600DFFC2E /* wildfirePrefPaneLogo.tiff in Resources */,
650096350A60403400B6046A /* jivesoftware_logo.png in Resources */,
6387AE500B29E3FF00E98223 /* autostartsetter.sh in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -218,6 +278,14 @@
/* End PBXRezBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
633BEA730B39EB2B003AD355 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
633BEA7A0B39EB60003AD355 /* authTool.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
8D202CF00486D31800D8A456 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
......@@ -228,6 +296,14 @@
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
633BEA870B39ED7D003AD355 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 633BEA750B39EB2B003AD355 /* HelperTool */;
targetProxy = 633BEA860B39ED7D003AD355 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin PBXVariantGroup section */
089C167DFE841241C02AAC07 /* InfoPlist.strings */ = {
isa = PBXVariantGroup;
......@@ -248,6 +324,125 @@
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */
633BEA7C0B39EB60003AD355 /* Development */ = {
isa = XCBuildConfiguration;
buildSettings = {
COPY_PHASE_STRIP = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
INSTALL_PATH = "$(HOME)/bin";
PREBINDING = NO;
PRODUCT_NAME = HelperTool;
SYMROOT = "$(PROJECT_DIR)/build";
ZERO_LINK = YES;
};
name = Development;
};
633BEA7D0B39EB60003AD355 /* Development copy */ = {
isa = XCBuildConfiguration;
buildSettings = {
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
INSTALL_PATH = "$(HOME)/bin";
PREBINDING = NO;
PRODUCT_NAME = HelperTool;
SYMROOT = "$(PROJECT_DIR)/build";
ZERO_LINK = YES;
};
name = "Development copy";
};
633BEA7E0B39EB60003AD355 /* Deployment */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = (
i386,
ppc,
);
COPY_PHASE_STRIP = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_ENABLE_FIX_AND_CONTINUE = NO;
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_MODEL_TUNING = G5;
INSTALL_PATH = "$(HOME)/bin";
PREBINDING = NO;
PRODUCT_NAME = HelperTool;
SYMROOT = "$(PROJECT_DIR)/build";
ZERO_LINK = NO;
};
name = Deployment;
};
633BEA7F0B39EB60003AD355 /* Default */ = {
isa = XCBuildConfiguration;
buildSettings = {
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
INSTALL_PATH = "$(HOME)/bin";
PREBINDING = NO;
PRODUCT_NAME = HelperTool;
SYMROOT = "$(PROJECT_DIR)/build";
ZERO_LINK = YES;
};
name = Default;
};
63707F330B2F3E94001D44AE /* Development copy */ = {
isa = XCBuildConfiguration;
buildSettings = {
GCC_C_LANGUAGE_STANDARD = gnu99;
MACOSX_DEPLOYMENT_TARGET = 10.4;
SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
};
name = "Development copy";
};
63707F340B2F3E94001D44AE /* Development copy */ = {
isa = XCBuildConfiguration;
buildSettings = {
COPY_PHASE_STRIP = NO;
DEBUGGING_SYMBOLS = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
DSTROOT = "$(PROJECT_DIR)/../../../macpkg";
FRAMEWORK_SEARCH_PATHS = "\"$(SYSTEM_DEVELOPER_DIR)/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks\"";
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_ENABLE_TRIGRAPHS = NO;
GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = wildfirePrefPane_Prefix.pch;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO;
GCC_WARN_FOUR_CHARACTER_CONSTANTS = NO;
GCC_WARN_UNKNOWN_PRAGMAS = NO;
HEADER_SEARCH_PATHS = "";
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = /Library/PreferencePanes;
LIBRARY_SEARCH_PATHS = "";
LIBRARY_STYLE = Bundle;
MACOSX_DEPLOYMENT_TARGET = 10.4;
OPTIMIZATION_CFLAGS = "-O0";
OTHER_CFLAGS = "";
OTHER_LDFLAGS = (
"-bundle",
"-twolevel_namespace",
);
OTHER_REZFLAGS = "";
PRODUCT_NAME = Wildfire;
SECTORDER_FLAGS = "";
SYMROOT = "$(PROJECT_DIR)/build";
WARNING_CFLAGS = (
"-Wmost",
"-Wno-four-char-constants",
"-Wno-unknown-pragmas",
);
WRAPPER_EXTENSION = prefPane;
ZERO_LINK = NO;
};
name = "Development copy";
};
65E2E72A0A5E8C0F00DFFC2E /* Development */ = {
isa = XCBuildConfiguration;
buildSettings = {
......@@ -377,28 +572,47 @@
65E2E72E0A5E8C0F00DFFC2E /* Development */ = {
isa = XCBuildConfiguration;
buildSettings = {
GCC_C_LANGUAGE_STANDARD = gnu99;
MACOSX_DEPLOYMENT_TARGET = 10.4;
};
name = Development;
};
65E2E72F0A5E8C0F00DFFC2E /* Deployment */ = {
isa = XCBuildConfiguration;
buildSettings = {
GCC_C_LANGUAGE_STANDARD = gnu99;
MACOSX_DEPLOYMENT_TARGET = 10.4;
SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
};
name = Deployment;
};
65E2E7300A5E8C0F00DFFC2E /* Default */ = {
isa = XCBuildConfiguration;
buildSettings = {
GCC_C_LANGUAGE_STANDARD = gnu99;
MACOSX_DEPLOYMENT_TARGET = 10.4;
};
name = Default;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
633BEA7B0B39EB60003AD355 /* Build configuration list for PBXNativeTarget "HelperTool" */ = {
isa = XCConfigurationList;
buildConfigurations = (
633BEA7C0B39EB60003AD355 /* Development */,
633BEA7D0B39EB60003AD355 /* Development copy */,
633BEA7E0B39EB60003AD355 /* Deployment */,
633BEA7F0B39EB60003AD355 /* Default */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Default;
};
65E2E7290A5E8C0F00DFFC2E /* Build configuration list for PBXNativeTarget "Wildfire" */ = {
isa = XCConfigurationList;
buildConfigurations = (
65E2E72A0A5E8C0F00DFFC2E /* Development */,
63707F340B2F3E94001D44AE /* Development copy */,
65E2E72B0A5E8C0F00DFFC2E /* Deployment */,
65E2E72C0A5E8C0F00DFFC2E /* Default */,
);
......@@ -409,6 +623,7 @@
isa = XCConfigurationList;
buildConfigurations = (
65E2E72E0A5E8C0F00DFFC2E /* Development */,
63707F330B2F3E94001D44AE /* Development copy */,
65E2E72F0A5E8C0F00DFFC2E /* Deployment */,
65E2E7300A5E8C0F00DFFC2E /* Default */,
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment