Skip to content

Commit

Permalink
fix: implement workaround for root privilege issues on macOS (#73)
Browse files Browse the repository at this point in the history
* add: elevation workaround for macOS
  • Loading branch information
kernel-dev committed May 25, 2023
1 parent 7e5dc13 commit 910f2ed
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/builditmac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
cp dist/SOURCE.URL cslol-manager-macos/
cp build/cslol-tools/wad-* cslol-manager-macos/
cp -R build/cslol-manager.app cslol-manager-macos/
cp build/cslol-manager-elevate cslol-manager-macos/cslol-manager.app/Contents/MacOS/
plutil -replace CFBundleExecutable -string cslol-manager-elevate cslol-manager-macos/cslol-manager.app/Contents/Info.plist
plutil -replace CFBundleName -string cslol-manager-elevate cslol-manager-macos/cslol-manager.app/Contents/Info.plist
mkdir cslol-manager-macos/cslol-manager.app/Contents/MacOS/cslol-tools
cp build/cslol-tools/mod-tools cslol-manager-macos/cslol-manager.app/Contents/MacOS/cslol-tools
tar caf cslol-manager-macos.tar.xz cslol-manager-macos/
Expand Down
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
cmake_minimum_required(VERSION 3.20)

project(cslol-manager LANGUAGES CXX)
project(cslol-manager LANGUAGES CXX C)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOUIC ON)
Expand Down Expand Up @@ -51,6 +53,9 @@ elseif(APPLE)
src/main.cpp
src/res/icon.icns
)
add_executable(cslol-manager-elevate
src/main_elevate.c
)
set_target_properties(cslol-manager
PROPERTIES
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/src/res/MacOSXBundleInfo.plist.in"
Expand Down
48 changes: 48 additions & 0 deletions src/main_elevate.c
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;
}

0 comments on commit 910f2ed

Please sign in to comment.