Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: implement workaround for root privilege issues on macOS #73

Merged
merged 11 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
66 changes: 66 additions & 0 deletions src/main_elevate.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#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];

int len = snprintf(
NULL,
0,
"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
);

//
// Something went wrong trying
// to obtain the necessary length of the string.
//
if (len <= 0)
return 1;

snprintf(
str,
len + 1,
"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
);
kernel-dev marked this conversation as resolved.
Show resolved Hide resolved

int code = execlp (
"osascript",
"osascript",
"-e",
str,
NULL);

return code;
}
2 changes: 1 addition & 1 deletion src/res/MacOSXBundleInfo.plist.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundleLongVersionString</key>
<string>${MACOSX_BUNDLE_LONG_VERSION_STRING}</string>
<key>CFBundleName</key>
<string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
kernel-dev marked this conversation as resolved.
Show resolved Hide resolved
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
Expand Down