networkAgent: Drop VPN plugin cache

libnm doesn't only search for plugins in the regular VPN plugin directory,
but also in the legacy location and the directory pointed to by the
NM_VPN_PLUGIN_DIR environment variable (if set).

We don't monitor the additional directories, so it's possible for our cache
to become outdated.

Instead of trying to play catch-up with libnm's internals, do what nm-applet
does and use the appropriate API to look up the plugin on each request.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/2386
This commit is contained in:
Florian Müllner 2020-03-13 22:09:33 +01:00 committed by Georges Basile Stavracas Neto
parent 69ea038a8f
commit eb7533bbf1
4 changed files with 17 additions and 43 deletions

View File

@ -15,6 +15,5 @@ var LOCALEDIR = '@datadir@/locale';
/* other standard directories */ /* other standard directories */
var LIBEXECDIR = '@libexecdir@'; var LIBEXECDIR = '@libexecdir@';
var PKGDATADIR = '@datadir@/@PACKAGE_NAME@'; var PKGDATADIR = '@datadir@/@PACKAGE_NAME@';
var VPNDIR = '@vpndir@';
/* g-i package versions */ /* g-i package versions */
var LIBMUTTER_API_VERSION = '@LIBMUTTER_API_VERSION@' var LIBMUTTER_API_VERSION = '@LIBMUTTER_API_VERSION@'

View File

@ -7,7 +7,6 @@ jsconf.set10('HAVE_BLUETOOTH', bt_dep.found())
jsconf.set10('HAVE_NETWORKMANAGER', have_networkmanager) jsconf.set10('HAVE_NETWORKMANAGER', have_networkmanager)
jsconf.set('datadir', datadir) jsconf.set('datadir', datadir)
jsconf.set('libexecdir', libexecdir) jsconf.set('libexecdir', libexecdir)
jsconf.set('vpndir', vpndir)
config_js = configure_file( config_js = configure_file(
input: 'config.js.in', input: 'config.js.in',

View File

@ -615,14 +615,6 @@ var NetworkAgent = class {
this._vpnRequests = { }; this._vpnRequests = { };
this._notifications = { }; this._notifications = { };
this._pluginDir = Gio.file_new_for_path(Config.VPNDIR);
try {
let monitor = this._pluginDir.monitor(Gio.FileMonitorFlags.NONE, null);
monitor.connect('changed', () => (this._vpnCacheBuilt = false));
} catch (e) {
log('Failed to create monitor for VPN plugin dir: %s'.format(e.message));
}
this._native.connect('new-request', this._newRequest.bind(this)); this._native.connect('new-request', this._newRequest.bind(this));
this._native.connect('cancel-request', this._cancelRequest.bind(this)); this._native.connect('cancel-request', this._cancelRequest.bind(this));
@ -770,9 +762,7 @@ var NetworkAgent = class {
let vpnSetting = connection.get_setting_vpn(); let vpnSetting = connection.get_setting_vpn();
let serviceType = vpnSetting.service_type; let serviceType = vpnSetting.service_type;
this._buildVPNServiceCache(); let binary = this._findAuthBinary(serviceType);
let binary = this._vpnBinaries[serviceType];
if (!binary) { if (!binary) {
log('Invalid VPN service type (cannot find authentication binary)'); log('Invalid VPN service type (cannot find authentication binary)');
@ -788,36 +778,26 @@ var NetworkAgent = class {
this._vpnRequests[requestId] = vpnRequest; this._vpnRequests[requestId] = vpnRequest;
} }
_buildVPNServiceCache() { _findAuthBinary(serviceType) {
if (this._vpnCacheBuilt) const plugin = NM.VpnPluginInfo.new_search_file(null, serviceType);
return;
this._vpnCacheBuilt = true; if (plugin === null)
this._vpnBinaries = { }; return null;
NM.VpnPluginInfo.list_load().forEach(plugin => { const fileName = plugin.get_auth_dialog();
let service = plugin.get_service(); if (!GLib.file_test(fileName, GLib.FileTest.IS_EXECUTABLE)) {
let fileName = plugin.get_auth_dialog(); log('VPN plugin at %s is not executable'.format(fileName));
let supportsHints = plugin.supports_hints(); return null;
let externalUIMode = false; }
let prop = plugin.lookup_property('GNOME', 'supports-external-ui-mode'); const prop = plugin.lookup_property('GNOME', 'supports-external-ui-mode');
if (prop) { const trimmedProp = prop ? prop.trim().toLowerCase() : '';
prop = prop.trim().toLowerCase();
externalUIMode = ['true', 'yes', 'on', '1'].includes(prop);
}
if (GLib.file_test(fileName, GLib.FileTest.IS_EXECUTABLE)) { return {
let binary = { fileName, externalUIMode, supportsHints }; fileName,
this._vpnBinaries[service] = binary; supportsHints: plugin.supports_hints(),
externalUIMode: ['true', 'yes', 'on', '1'].includes(trimmedProp),
plugin.get_aliases().forEach(alias => { };
this._vpnBinaries[alias] = binary;
});
} else {
log('VPN plugin at %s is not executable'.format(fileName));
}
});
} }
}; };
var Component = NetworkAgent; var Component = NetworkAgent;

View File

@ -114,12 +114,8 @@ if get_option('networkmanager')
nm_deps += dependency('libnm', version: nm_req) nm_deps += dependency('libnm', version: nm_req)
nm_deps += dependency('libsecret-1', version: secret_req) nm_deps += dependency('libsecret-1', version: secret_req)
vpndir = nm_deps[0].get_pkgconfig_variable('vpnservicedir')
have_networkmanager = true have_networkmanager = true
else else
vpndir = prefix
have_networkmanager = false have_networkmanager = false
endif endif