fix pkexec support and do not call pkexec at all if the install dir is not found (#274)

This commit is contained in:
Thomas Debesse
2023-12-15 08:07:37 +01:00
committed by GitHub
parent 410cd919dc
commit 8fee2fb964

View File

@@ -9,15 +9,17 @@ export default class PkexecUtil {
this._pkexec = GLib.find_program_in_path('pkexec');
// Currently hardcoded in policy file.
this._bin = '/usr/sbin/' + name;
this._dir = this.dir();
this._dir = this.dir();
}
dir() {
let uri = (new Error()).stack.split('\n')[1];
if (!uri.startsWith('install@file://')) {
let prefix = this.constructor.name + '@file://'
if (!uri.startsWith(prefix)) {
log('[FREON] failed to guess extension directory');
return null;
}
return Gio.File.new_for_path(uri.substring(15)).get_parent().get_path();
return Gio.File.new_for_path(uri.substring(prefix.length)).get_parent().get_path();
}
available_pkexec() {
@@ -37,6 +39,11 @@ export default class PkexecUtil {
}
install() {
if (!this._dir)
{
log('[FREON] cannot find ' + this._name + ' pkexec policy file ' + this._policy);
return false;
}
try {
this.run('install "' + this._dir + '/policies/' + this._policy + '" ' + this._actions);
} catch(e) {}