1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor: remove unused OSX platform code

This commit is contained in:
sudden6 2020-06-15 15:12:34 +02:00
parent adfc91bc46
commit 8768f6be37
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
7 changed files with 0 additions and 589 deletions

View File

@ -563,11 +563,6 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Fr
src/platform/camera/v4l2.cpp src/platform/camera/v4l2.cpp
src/platform/camera/v4l2.h src/platform/camera/v4l2.h
) )
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(${PROJECT_NAME}_SOURCES ${${PROJECT_NAME}_SOURCES}
src/platform/install_osx.cpp
src/platform/install_osx.h
)
endif() endif()
if (UNIX) if (UNIX)

View File

@ -1,11 +0,0 @@
The qTox OS X updater is a mix of objective C and Go compiled as static binaries used do effortless updates in the background.
It uses Objective C to access Apples own security framework and call some long dead APIs in order to give the statically linked go updater permissions to install the latest build without prompting the user for every file.
* Release commits: ``https://github.com/Tox/qTox_updater``
* Development commits: ``https://github.mit.edu/sean-2/updater``
Compiling:
* ```clang qtox_sudo.m -framework corefoundation -framework security -framework cocoa -Os -o qtox_sudo```
* ```go build updater.go```

View File

@ -1,273 +0,0 @@
// Modifications listed here GPLv3: https://gist.githubusercontent.com/stqism/2e82352026915f8f6ab3/raw/fca6f6f16fb8d61a64b6053dacf50c3433c2e0af/gistfile1.txt
//
// Copyright 2009 Performant Design, LLC. All rights reserved.
// Copyright (C) 2014 Tox Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <http://www.gnu.org/licenses/>.
//
#import <Cocoa/Cocoa.h>
#include <sys/stat.h>
#include <unistd.h>
#include <Security/Authorization.h>
#include <Security/AuthorizationTags.h>
char *addFileToPath(const char *path, const char *filename) {
char *outbuf;
char *lc;
lc = (char *)path + strlen(path) - 1;
if (lc < path || *lc != '/') {
lc = NULL;
}
while (*filename == '/') {
filename++;
}
outbuf = malloc(strlen(path) + strlen(filename) + 1 + (lc == NULL ? 1 : 0));
sprintf(outbuf, "%s%s%s", path, (lc == NULL) ? "/" : "", filename);
return outbuf;
}
int isExecFile(const char *name) {
struct stat s;
return (!access(name, X_OK) && !stat(name, &s) && S_ISREG(s.st_mode));
}
char *which(const char *filename)
{
char *path, *p, *n;
path = getenv("PATH");
if (!path) {
return NULL;
}
p = path = strdup(path);
while (p) {
n = strchr(p, ':');
if (n) {
*n++ = '\0';
}
if (*p != '\0') {
p = addFileToPath(p, filename);
if (isExecFile(p)) {
free(path);
return p;
}
free(p);
}
p = n;
}
free(path);
return NULL;
}
int cocoaSudo(char *executable, char *commandArgs[], char *icon, char *prompt) {
int retVal = 1;
OSStatus status;
AuthorizationRef authRef;
AuthorizationItem right = {kAuthorizationRightExecute, 0, NULL, 0};
AuthorizationRights rightSet = {1, &right};
AuthorizationEnvironment myAuthorizationEnvironment;
AuthorizationItem kAuthEnv[2];
myAuthorizationEnvironment.items = kAuthEnv;
AuthorizationFlags flags = kAuthorizationFlagDefaults;
if (prompt && icon) {
kAuthEnv[0].name = kAuthorizationEnvironmentPrompt;
kAuthEnv[0].valueLength = strlen(prompt);
kAuthEnv[0].value = prompt;
kAuthEnv[0].flags = 0;
kAuthEnv[1].name = kAuthorizationEnvironmentIcon;
kAuthEnv[1].valueLength = strlen(icon);
kAuthEnv[1].value = icon;
kAuthEnv[1].flags = 0;
myAuthorizationEnvironment.count = 2;
}
else if (prompt) {
kAuthEnv[0].name = kAuthorizationEnvironmentPrompt;
kAuthEnv[0].valueLength = strlen(prompt);
kAuthEnv[0].value = prompt;
kAuthEnv[0].flags = 0;
myAuthorizationEnvironment.count = 1;
}
else if (icon) {
kAuthEnv[0].name = kAuthorizationEnvironmentIcon;
kAuthEnv[0].valueLength = strlen(icon);
kAuthEnv[0].value = icon;
kAuthEnv[0].flags = 0;
myAuthorizationEnvironment.count = 1;
}
else {
myAuthorizationEnvironment.count = 0;
}
status = AuthorizationCreate(NULL, &myAuthorizationEnvironment, flags, &authRef);
if (status != errAuthorizationSuccess) {
NSLog(@"Could not create authorization reference object.");
status = errAuthorizationBadAddress;
}
else {
flags = kAuthorizationFlagDefaults |
kAuthorizationFlagInteractionAllowed |
kAuthorizationFlagPreAuthorize |
kAuthorizationFlagExtendRights;
status = AuthorizationCopyRights(authRef, &rightSet, &myAuthorizationEnvironment, flags, NULL);
}
if (status == errAuthorizationSuccess) {
FILE *ioPipe;
char buffer[1024];
int bytesRead;
flags = kAuthorizationFlagDefaults;
status = AuthorizationExecuteWithPrivileges(authRef, executable, flags, commandArgs, &ioPipe);
/* Just pipe processes' stdout to our stdout for now; hopefully can add stdin pipe later as well */
for (;;) {
bytesRead = fread(buffer, sizeof(char), 1024, ioPipe);
if (bytesRead < 1) {
break;
}
write(STDOUT_FILENO, buffer, bytesRead * sizeof(char));
}
pid_t pid;
int pidStatus;
do {
pid = wait(&pidStatus);
}
while (pid != -1);
if (status == errAuthorizationSuccess) {
retVal = 0;
}
}
else {
AuthorizationFree(authRef, kAuthorizationFlagDestroyRights);
authRef = NULL;
if (status != errAuthorizationCanceled) {
// pre-auth failed
NSLog(@"Pre-auth failed");
}
}
return retVal;
}
void usage(char *appNameFull) {
char *appName = strrchr(appNameFull, '/');
if (appName == NULL) {
appName = appNameFull;
}
else {
appName++;
}
fprintf(stderr, "usage: %s command\n", appName);
}
int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = 1;
int programArgsStartAt = 1;
char *icon = NULL;
char *prompt = NULL;
if (programArgsStartAt >= argc) {
usage(argv[0]);
}
else {
char *executable;
if (strchr(argv[programArgsStartAt], '/')) {
executable = isExecFile(argv[programArgsStartAt]) ? strdup(argv[programArgsStartAt]) : NULL;
}
else {
executable = which(argv[programArgsStartAt]);
}
if (executable) {
char **commandArgs = malloc((argc - programArgsStartAt) * sizeof(char**));
memcpy(commandArgs, argv + programArgsStartAt + 1, (argc - programArgsStartAt - 1) * sizeof(char**));
commandArgs[argc - programArgsStartAt - 1] = NULL;
retVal = cocoaSudo(executable, commandArgs, icon, prompt);
free(commandArgs);
free(executable);
}
else {
fprintf(stderr, "Unable to find %s\n", argv[programArgsStartAt]);
usage(argv[0]);
}
}
if (prompt) {
free(prompt);
}
[pool release];
return retVal;
}

View File

@ -1,133 +0,0 @@
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"os/user"
"syscall"
"github.com/kardianos/osext"
)
var custom_user string
func fs_type(path string) int {
//name := "FileOrDir"
f, err := os.Open(path)
if err != nil {
fmt.Println(err)
return -1
}
defer f.Close()
fi, err := f.Stat()
if err != nil {
fmt.Println(err)
return -1
}
switch mode := fi.Mode(); {
case mode.IsDir():
return 0
case mode.IsRegular():
return 1
}
return -1
}
func install(path string, pathlen int) int {
files, _ := ioutil.ReadDir(path)
for _, file := range files {
if fs_type(path+file.Name()) == 1 {
addpath := ""
if len(path) != pathlen {
addpath = path[pathlen:len(path)]
}
fmt.Print("Installing: ")
fmt.Println("/Applications/qtox.app/Contents/" + addpath + file.Name())
if _, err := os.Stat("/Applications/qtox.app/Contents/" + file.Name()); os.IsNotExist(err) {
newfile := exec.Command("/usr/libexec/authopen", "-c", "-x", "-m", "drwxrwxr-x+", "/Applications/qtox.app/Contents/"+addpath+file.Name())
newfile.Run()
}
cat := exec.Command("/bin/cat", path+file.Name())
auth := exec.Command("/usr/libexec/authopen", "-w", "/Applications/qtox.app/Contents/"+addpath+file.Name())
auth.Stdin, _ = cat.StdoutPipe()
auth.Stdout = os.Stdout
auth.Stderr = os.Stderr
_ = auth.Start()
_ = cat.Run()
_ = auth.Wait()
} else {
install(path+file.Name()+"/", pathlen)
}
}
return 0
}
func main() {
syscall.Setuid(0)
usr, e := user.Current()
if e != nil {
log.Fatal(e)
}
CHECK:
if usr.Name != "System Administrator" {
fmt.Println("Not running as root, relaunching")
appdir, _ := osext.Executable()
appdir_len := len(appdir)
sudo_path := appdir[0:(appdir_len-7)] + "qtox_sudo" //qtox_sudo is a fork of cocoasudo with all of its flags and other features stripped out
if _, err := os.Stat(sudo_path); os.IsNotExist(err) {
fmt.Println("Error: No qtox_sudo binary installed, falling back")
custom_user = usr.Name
usr.Name = "System Administrator"
goto CHECK
}
relaunch := exec.Command(sudo_path, appdir, usr.Name)
relaunch.Stdout = os.Stdout
relaunch.Stderr = os.Stderr
relaunch.Run()
return
} else {
if len(os.Args) > 1 || custom_user != "" {
if custom_user == "" {
custom_user = os.Args[1]
}
update_dir := "/Users/" + custom_user + "/Library/Preferences/tox/update/"
if _, err := os.Stat(update_dir); os.IsNotExist(err) {
fmt.Println("Error: No update folder, is check for updates enabled?")
return
}
fmt.Println("qTox Updater")
killqtox := exec.Command("/usr/bin/killall", "qtox")
_ = killqtox.Run()
install(update_dir, len(update_dir))
os.RemoveAll(update_dir)
fmt.Println("Update metadata wiped, launching qTox")
launchqtox := exec.Command("/usr/bin/open", "-b", "chat.tox.qtox")
launchqtox.Run()
} else {
fmt.Println("Error: no user passed")
}
}
}

View File

@ -43,10 +43,6 @@
#include <sodium.h> #include <sodium.h>
#include <stdio.h> #include <stdio.h>
#if defined(Q_OS_OSX)
#include "platform/install_osx.h"
#endif
#if defined(Q_OS_UNIX) #if defined(Q_OS_UNIX)
#include "platform/posixsignalnotifier.h" #include "platform/posixsignalnotifier.h"
#endif #endif
@ -202,13 +198,6 @@ int main(int argc, char* argv[])
qWarning() << "Couldn't load font"; qWarning() << "Couldn't load font";
} }
#if defined(Q_OS_OSX)
// TODO: Add setting to enable this feature.
// osx::moveToAppFolder();
osx::migrateProfiles();
#endif
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0)) #if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
qsrand(time(nullptr)); qsrand(time(nullptr));
#endif #endif

View File

@ -1,122 +0,0 @@
/*
Copyright © 2015-2019 by The qTox Project Contributors
This file is part of qTox, a Qt-based graphical interface for Tox.
qTox is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
qTox is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with qTox. If not, see <http://www.gnu.org/licenses/>.
*/
#include "install_osx.h"
#include <QApplication>
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QMessageBox>
#include <QProcess>
#include <QStandardPaths>
#include <unistd.h>
void osx::moveToAppFolder()
{
if (qApp->applicationDirPath() != "/Applications/qtox.app/Contents/MacOS") {
qDebug() << "OS X: Not in Applications folder";
QMessageBox AskInstall;
AskInstall.setIcon(QMessageBox::Question);
AskInstall.setWindowModality(Qt::ApplicationModal);
AskInstall.setText("Move to Applications folder?");
AskInstall.setInformativeText("I can move myself to the Applications folder, keeping your "
"downloads folder less cluttered.\r\n");
AskInstall.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
AskInstall.setDefaultButton(QMessageBox::Yes);
int AskInstallAttempt = AskInstall.exec(); // Actually ask the user
if (AskInstallAttempt == QMessageBox::Yes) {
QProcess* sudoprocess = new QProcess;
QProcess* qtoxprocess = new QProcess;
QString bindir = qApp->applicationDirPath();
QString appdir = bindir;
appdir.chop(15);
QString sudo = bindir + "/qtox_sudo rsync -avzhpltK " + appdir + " /Applications";
QString qtox = "open /Applications/qtox.app";
QString appdir_noqtox = appdir;
appdir_noqtox.chop(8);
if ((appdir_noqtox + "qtox.app") != appdir) // quick safety check
{
qDebug() << "OS X: Attempted to delete non-qTox directory!";
exit(EXIT_UPDATE_MACX_FAIL);
}
QDir old_app(appdir);
sudoprocess->start(sudo); // Where the magic actually happens, safety checks ^
sudoprocess->waitForFinished();
if (old_app.removeRecursively()) // We've just deleted the running program
qDebug() << "OS X: Cleaned up old directory";
else
qDebug() << "OS X: The directory failed to delete (this should never happen)";
if (fork() != 0) // Forking is required otherwise it won't actually cleanly launch
exit(EXIT_UPDATE_MACX);
qtoxprocess->start(qtox);
exit(0); // Actually kills it
}
}
}
// migrateProfiles() is compatabilty code that can be removed down the line when the time seems
// right.
void osx::migrateProfiles()
{
QString oldPath = QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)
+ QDir::separator() + "Library" + QDir::separator()
+ "Preferences" + QDir::separator() + "tox");
QFileInfo checkDir(oldPath);
QString newPath = QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)
+ QDir::separator() + "Library" + QDir::separator()
+ "Application Support" + QDir::separator() + "Tox");
QDir dir;
if (!checkDir.exists() || !checkDir.isDir()) {
qDebug() << "OS X: Old settings directory not detected";
return;
}
qDebug() << "OS X: Old settings directory detected migrating to default";
if (!dir.rename(oldPath, newPath)) {
qDebug() << "OS X: Profile migration failed. ~/Library/Application Support/Tox already "
"exists. Using alternate migration method.";
QString OSXMigrater = "../Resources/OSX-Migrater.sh";
QProcess::execute(OSXMigrater);
QMessageBox MigrateProfile;
MigrateProfile.setIcon(QMessageBox::Information);
MigrateProfile.setWindowModality(Qt::ApplicationModal);
MigrateProfile.setText("Alternate profile migration method used.");
MigrateProfile.setInformativeText(
"It has been detected that your profiles \nwhere migrated to the new settings "
"directory; \nusing the alternate migration method. \n\nA backup can be found in your: "
"\n/Users/[USER]/.Tox-Backup[DATE-TIME] \n\nJust in case. \r\n");
MigrateProfile.exec();
}
}
// End migrateProfiles() compatibility code

View File

@ -1,34 +0,0 @@
/*
Copyright © 2015-2019 by The qTox Project Contributors
This file is part of qTox, a Qt-based graphical interface for Tox.
qTox is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
qTox is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with qTox. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <QtCore/qsystemdetection.h>
#ifndef Q_OS_OSX
#error "This file is only meant to be compiled for Mac OSX targets"
#endif
namespace osx {
static constexpr int EXIT_UPDATE_MACX =
218; // We track our state using unique exit codes when debugging
static constexpr int EXIT_UPDATE_MACX_FAIL = 216;
void moveToAppFolder();
void migrateProfiles();
}