-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: implement workaround for root privilege issues on macOS (#73)
* add: elevation workaround for macOS
- Loading branch information
1 parent
7e5dc13
commit 910f2ed
Showing
3 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include <unistd.h> | ||
#include <mach-o/dyld.h> | ||
#include <limits.h> | ||
#include <libgen.h> | ||
|
||
#define COMMAND_CHAR_COUNT_MAX 1000 + PATH_MAX | ||
|
||
int main() | ||
{ | ||
char pathBuff[PATH_MAX]; | ||
uint32_t buffSize = PATH_MAX; | ||
|
||
// | ||
// Find the absolute path | ||
// of this executable. | ||
// | ||
if (_NSGetExecutablePath(pathBuff, &buffSize) != KERN_SUCCESS) | ||
return -1; | ||
|
||
// | ||
// Remove the file component of the abs. path. | ||
// | ||
char *parentDir = dirname(pathBuff); | ||
|
||
char str[COMMAND_CHAR_COUNT_MAX]; | ||
|
||
sprintf( | ||
str, | ||
"do shell script \"sudo %s/cslol-manager >/dev/null 2>&1 &\"" | ||
" with prompt \"CSLOL-Manager needs administrator privileges to restart.\"" | ||
" with administrator privileges" | ||
" without altering line endings", | ||
parentDir | ||
); | ||
|
||
int code = execlp ( | ||
"osascript", | ||
"osascript", | ||
"-e", | ||
str, | ||
NULL); | ||
|
||
return code; | ||
} |