2020-09-29 16:42:22 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2019-09-25 13:13:40 +02:00
|
|
|
/*
|
2008-11-04 22:32:57 +00:00
|
|
|
* Copyright (C) 2008 Novell, Inc.
|
|
|
|
|
* Copyright (C) 2008 Red Hat, Inc.
|
|
|
|
|
*/
|
2007-08-15 14:30:06 +00:00
|
|
|
|
2016-04-28 18:58:08 +02:00
|
|
|
#include <config.h>
|
2016-02-19 14:57:48 +01:00
|
|
|
#define ___CONFIG_H__
|
2014-11-13 10:07:02 -05:00
|
|
|
|
2007-08-15 14:30:06 +00:00
|
|
|
#include <pppd/pppd.h>
|
|
|
|
|
#include <pppd/fsm.h>
|
|
|
|
|
#include <pppd/ipcp.h>
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
#include <netinet/in.h>
|
2018-01-08 16:45:43 +01:00
|
|
|
#include <net/if.h>
|
2007-08-15 14:30:06 +00:00
|
|
|
#include <arpa/inet.h>
|
2014-06-12 09:59:38 -05:00
|
|
|
#include <dlfcn.h>
|
2007-08-15 14:30:06 +00:00
|
|
|
|
2014-06-12 09:59:38 -05:00
|
|
|
#define INET6
|
|
|
|
|
#include <pppd/eui64.h>
|
|
|
|
|
#include <pppd/ipv6cp.h>
|
|
|
|
|
|
2015-07-17 14:38:54 +02:00
|
|
|
#include "nm-default.h"
|
2018-01-02 13:37:06 +01:00
|
|
|
|
2014-07-05 16:23:30 -04:00
|
|
|
#include "nm-dbus-interface.h"
|
2018-01-02 13:37:06 +01:00
|
|
|
|
2007-08-15 14:30:06 +00:00
|
|
|
#include "nm-pppd-plugin.h"
|
|
|
|
|
#include "nm-ppp-status.h"
|
|
|
|
|
|
2007-11-26 16:59:47 +00:00
|
|
|
int plugin_init(void);
|
|
|
|
|
|
2007-08-15 14:30:06 +00:00
|
|
|
char pppd_version[] = VERSION;
|
|
|
|
|
|
2019-05-05 15:00:37 +02:00
|
|
|
static struct {
|
|
|
|
|
GDBusConnection *dbus_connection;
|
|
|
|
|
char * ipparam;
|
|
|
|
|
} gl;
|
2007-10-10 14:36:31 +00:00
|
|
|
|
2007-08-15 14:30:06 +00:00
|
|
|
static void
|
2019-06-13 18:23:21 +02:00
|
|
|
nm_phasechange(int arg)
|
2007-08-15 14:30:06 +00:00
|
|
|
{
|
2007-11-26 16:59:47 +00:00
|
|
|
NMPPPStatus ppp_status = NM_PPP_STATUS_UNKNOWN;
|
|
|
|
|
char * ppp_phase;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-05-05 15:00:37 +02:00
|
|
|
g_return_if_fail(G_IS_DBUS_CONNECTION(gl.dbus_connection));
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2007-08-15 14:30:06 +00:00
|
|
|
switch (arg) {
|
|
|
|
|
case PHASE_DEAD:
|
2007-11-26 16:59:47 +00:00
|
|
|
ppp_status = NM_PPP_STATUS_DEAD;
|
|
|
|
|
ppp_phase = "dead";
|
2007-08-15 14:30:06 +00:00
|
|
|
break;
|
|
|
|
|
case PHASE_INITIALIZE:
|
2007-11-26 16:59:47 +00:00
|
|
|
ppp_status = NM_PPP_STATUS_INITIALIZE;
|
|
|
|
|
ppp_phase = "initialize";
|
2007-08-15 14:30:06 +00:00
|
|
|
break;
|
|
|
|
|
case PHASE_SERIALCONN:
|
2007-11-26 16:59:47 +00:00
|
|
|
ppp_status = NM_PPP_STATUS_SERIALCONN;
|
|
|
|
|
ppp_phase = "serial connection";
|
2007-08-15 14:30:06 +00:00
|
|
|
break;
|
|
|
|
|
case PHASE_DORMANT:
|
2007-11-26 16:59:47 +00:00
|
|
|
ppp_status = NM_PPP_STATUS_DORMANT;
|
|
|
|
|
ppp_phase = "dormant";
|
2007-08-15 14:30:06 +00:00
|
|
|
break;
|
|
|
|
|
case PHASE_ESTABLISH:
|
2007-11-26 16:59:47 +00:00
|
|
|
ppp_status = NM_PPP_STATUS_ESTABLISH;
|
|
|
|
|
ppp_phase = "establish";
|
2007-08-15 14:30:06 +00:00
|
|
|
break;
|
|
|
|
|
case PHASE_AUTHENTICATE:
|
2007-11-26 16:59:47 +00:00
|
|
|
ppp_status = NM_PPP_STATUS_AUTHENTICATE;
|
|
|
|
|
ppp_phase = "authenticate";
|
2007-08-15 14:30:06 +00:00
|
|
|
break;
|
|
|
|
|
case PHASE_CALLBACK:
|
2007-11-26 16:59:47 +00:00
|
|
|
ppp_status = NM_PPP_STATUS_CALLBACK;
|
|
|
|
|
ppp_phase = "callback";
|
2007-08-15 14:30:06 +00:00
|
|
|
break;
|
|
|
|
|
case PHASE_NETWORK:
|
2007-11-26 16:59:47 +00:00
|
|
|
ppp_status = NM_PPP_STATUS_NETWORK;
|
|
|
|
|
ppp_phase = "network";
|
2007-08-15 14:30:06 +00:00
|
|
|
break;
|
|
|
|
|
case PHASE_RUNNING:
|
2007-11-26 16:59:47 +00:00
|
|
|
ppp_status = NM_PPP_STATUS_RUNNING;
|
|
|
|
|
ppp_phase = "running";
|
2007-08-15 14:30:06 +00:00
|
|
|
break;
|
|
|
|
|
case PHASE_TERMINATE:
|
2007-11-26 16:59:47 +00:00
|
|
|
ppp_status = NM_PPP_STATUS_TERMINATE;
|
|
|
|
|
ppp_phase = "terminate";
|
2007-08-15 14:30:06 +00:00
|
|
|
break;
|
|
|
|
|
case PHASE_DISCONNECT:
|
2007-11-26 16:59:47 +00:00
|
|
|
ppp_status = NM_PPP_STATUS_DISCONNECT;
|
|
|
|
|
ppp_phase = "disconnect";
|
2007-08-15 14:30:06 +00:00
|
|
|
break;
|
|
|
|
|
case PHASE_HOLDOFF:
|
2007-11-26 16:59:47 +00:00
|
|
|
ppp_status = NM_PPP_STATUS_HOLDOFF;
|
|
|
|
|
ppp_phase = "holdoff";
|
2007-08-15 14:30:06 +00:00
|
|
|
break;
|
|
|
|
|
case PHASE_MASTER:
|
2007-11-26 16:59:47 +00:00
|
|
|
ppp_status = NM_PPP_STATUS_MASTER;
|
|
|
|
|
ppp_phase = "master";
|
2007-08-15 14:30:06 +00:00
|
|
|
break;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2007-08-15 14:30:06 +00:00
|
|
|
default:
|
2007-11-26 16:59:47 +00:00
|
|
|
ppp_phase = "unknown";
|
2007-08-15 14:30:06 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-05-05 15:00:37 +02:00
|
|
|
g_message("nm-ppp-plugin: status %d / phase '%s'", ppp_status, ppp_phase);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2008-03-07 18:04:59 +00:00
|
|
|
if (ppp_status != NM_PPP_STATUS_UNKNOWN) {
|
2019-05-05 15:00:37 +02:00
|
|
|
g_dbus_connection_call(gl.dbus_connection,
|
|
|
|
|
NM_DBUS_SERVICE,
|
|
|
|
|
gl.ipparam,
|
|
|
|
|
NM_DBUS_INTERFACE_PPP,
|
|
|
|
|
"SetState",
|
|
|
|
|
g_variant_new("(u)", ppp_status),
|
|
|
|
|
G_VARIANT_TYPE("()"),
|
|
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
|
-1,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2008-03-07 18:04:59 +00:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-10-22 09:54:28 +02:00
|
|
|
if (ppp_status == NM_PPP_STATUS_RUNNING) {
|
2019-05-05 15:00:37 +02:00
|
|
|
gs_unref_variant GVariant *ret = NULL;
|
|
|
|
|
char new_name[IF_NAMESIZE];
|
|
|
|
|
int ifindex;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-05-05 15:00:37 +02:00
|
|
|
ifindex = if_nametoindex(ifname);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-01-08 17:03:53 +01:00
|
|
|
/* Make a sync call to ensure that when the call
|
|
|
|
|
* terminates the interface already has its final
|
|
|
|
|
* name. */
|
2019-05-05 15:00:37 +02:00
|
|
|
ret = g_dbus_connection_call_sync(gl.dbus_connection,
|
|
|
|
|
NM_DBUS_SERVICE,
|
|
|
|
|
gl.ipparam,
|
|
|
|
|
NM_DBUS_INTERFACE_PPP,
|
|
|
|
|
"SetIfindex",
|
|
|
|
|
g_variant_new("(i)", ifindex),
|
|
|
|
|
G_VARIANT_TYPE("()"),
|
|
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
|
25000,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-01-08 17:03:53 +01:00
|
|
|
/* Update the name in pppd if NM changed it */
|
2019-05-05 15:00:37 +02:00
|
|
|
if (if_indextoname(ifindex, new_name) && !nm_streq0(ifname, new_name)) {
|
2018-01-08 17:03:53 +01:00
|
|
|
g_message("nm-ppp-plugin: interface name changed from '%s' to '%s'", ifname, new_name);
|
2018-09-11 21:53:04 +02:00
|
|
|
g_strlcpy(ifname, new_name, IF_NAMESIZE);
|
2018-01-08 17:03:53 +01:00
|
|
|
}
|
2018-01-08 16:45:43 +01:00
|
|
|
}
|
2007-10-10 14:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
2019-06-13 18:23:21 +02:00
|
|
|
static void
|
|
|
|
|
nm_phasechange_hook(void *data, int arg)
|
|
|
|
|
{
|
|
|
|
|
/* We send the nofication in exitnotify instead */
|
|
|
|
|
if (arg == PHASE_DEAD)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
nm_phasechange(arg);
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-15 14:30:06 +00:00
|
|
|
static void
|
|
|
|
|
nm_ip_up(void *data, int arg)
|
|
|
|
|
{
|
2008-08-04 21:37:11 +00:00
|
|
|
ipcp_options opts = ipcp_gotoptions[0];
|
|
|
|
|
ipcp_options peer_opts = ipcp_hisoptions[0];
|
2014-08-19 17:05:38 -04:00
|
|
|
GVariantBuilder builder;
|
2008-08-04 21:37:11 +00:00
|
|
|
guint32 pppd_made_up_address = htonl(0x0a404040 + ifunit);
|
2007-10-10 14:36:31 +00:00
|
|
|
|
2019-05-05 15:00:37 +02:00
|
|
|
g_return_if_fail(G_IS_DBUS_CONNECTION(gl.dbus_connection));
|
2008-03-11 16:37:41 +00:00
|
|
|
|
2019-05-05 15:00:37 +02:00
|
|
|
g_message("nm-ppp-plugin: ip-up event");
|
2009-10-05 12:12:45 -07:00
|
|
|
|
2007-10-10 14:36:31 +00:00
|
|
|
if (!opts.ouraddr) {
|
2019-05-05 15:00:37 +02:00
|
|
|
g_warning("nm-ppp-plugin: didn't receive an internal IP from pppd!");
|
2019-06-13 18:23:21 +02:00
|
|
|
nm_phasechange(PHASE_DEAD);
|
2007-08-15 14:30:06 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-19 17:05:38 -04:00
|
|
|
g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
|
2007-08-15 14:30:06 +00:00
|
|
|
|
2018-01-08 16:45:43 +01:00
|
|
|
/* Keep sending the interface name to be backwards compatible
|
|
|
|
|
* with older versions of NM during a package upgrade, where
|
|
|
|
|
* NM is not restarted and the pppd plugin was not loaded. */
|
2014-08-19 17:05:38 -04:00
|
|
|
g_variant_builder_add(&builder,
|
|
|
|
|
"{sv}",
|
|
|
|
|
NM_PPP_IP4_CONFIG_INTERFACE,
|
|
|
|
|
g_variant_new_string(ifname));
|
2008-01-21 15:30:39 +00:00
|
|
|
|
2014-08-19 17:05:38 -04:00
|
|
|
g_variant_builder_add(&builder,
|
|
|
|
|
"{sv}",
|
|
|
|
|
NM_PPP_IP4_CONFIG_ADDRESS,
|
|
|
|
|
g_variant_new_uint32(opts.ouraddr));
|
2008-01-21 15:30:39 +00:00
|
|
|
|
2008-08-04 21:37:11 +00:00
|
|
|
/* Prefer the peer options remote address first, _unless_ pppd made the
|
|
|
|
|
* address up, at which point prefer the local options remote address,
|
|
|
|
|
* and if that's not right, use the made-up address as a last resort.
|
|
|
|
|
*/
|
|
|
|
|
if (peer_opts.hisaddr && (peer_opts.hisaddr != pppd_made_up_address)) {
|
2014-08-19 17:05:38 -04:00
|
|
|
g_variant_builder_add(&builder,
|
|
|
|
|
"{sv}",
|
|
|
|
|
NM_PPP_IP4_CONFIG_GATEWAY,
|
|
|
|
|
g_variant_new_uint32(peer_opts.hisaddr));
|
2008-08-04 21:37:11 +00:00
|
|
|
} else if (opts.hisaddr) {
|
2014-08-19 17:05:38 -04:00
|
|
|
g_variant_builder_add(&builder,
|
|
|
|
|
"{sv}",
|
|
|
|
|
NM_PPP_IP4_CONFIG_GATEWAY,
|
|
|
|
|
g_variant_new_uint32(opts.hisaddr));
|
2008-08-04 21:37:11 +00:00
|
|
|
} else if (peer_opts.hisaddr == pppd_made_up_address) {
|
|
|
|
|
/* As a last resort, use the made-up address */
|
2014-08-19 17:05:38 -04:00
|
|
|
g_variant_builder_add(&builder,
|
|
|
|
|
"{sv}",
|
|
|
|
|
NM_PPP_IP4_CONFIG_GATEWAY,
|
|
|
|
|
g_variant_new_uint32(peer_opts.ouraddr));
|
2008-01-21 15:30:39 +00:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-08-19 17:05:38 -04:00
|
|
|
g_variant_builder_add(&builder, "{sv}", NM_PPP_IP4_CONFIG_PREFIX, g_variant_new_uint32(32));
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2007-10-10 14:36:31 +00:00
|
|
|
if (opts.dnsaddr[0] || opts.dnsaddr[1]) {
|
2014-08-19 17:05:38 -04:00
|
|
|
guint32 dns[2];
|
|
|
|
|
int len = 0;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2007-10-10 14:36:31 +00:00
|
|
|
if (opts.dnsaddr[0])
|
2014-08-19 17:05:38 -04:00
|
|
|
dns[len++] = opts.dnsaddr[0];
|
2007-10-10 14:36:31 +00:00
|
|
|
if (opts.dnsaddr[1])
|
2014-08-19 17:05:38 -04:00
|
|
|
dns[len++] = opts.dnsaddr[1];
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-08-19 17:05:38 -04:00
|
|
|
g_variant_builder_add(
|
|
|
|
|
&builder,
|
|
|
|
|
"{sv}",
|
|
|
|
|
NM_PPP_IP4_CONFIG_DNS,
|
|
|
|
|
g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, dns, len, sizeof(guint32)));
|
2007-08-15 14:30:06 +00:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2007-10-10 14:36:31 +00:00
|
|
|
if (opts.winsaddr[0] || opts.winsaddr[1]) {
|
2014-08-19 17:05:38 -04:00
|
|
|
guint32 wins[2];
|
|
|
|
|
int len = 0;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2007-10-10 14:36:31 +00:00
|
|
|
if (opts.winsaddr[0])
|
2014-08-19 17:05:38 -04:00
|
|
|
wins[len++] = opts.winsaddr[0];
|
2007-10-10 14:36:31 +00:00
|
|
|
if (opts.winsaddr[1])
|
2014-08-19 17:05:38 -04:00
|
|
|
wins[len++] = opts.winsaddr[1];
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-08-19 17:05:38 -04:00
|
|
|
g_variant_builder_add(
|
|
|
|
|
&builder,
|
|
|
|
|
"{sv}",
|
|
|
|
|
NM_PPP_IP4_CONFIG_WINS,
|
|
|
|
|
g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, wins, len, sizeof(guint32)));
|
2007-08-15 14:30:06 +00:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-05-05 15:00:37 +02:00
|
|
|
g_message("nm-ppp-plugin: sending IPv4 config to NetworkManager...");
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-05-05 15:00:37 +02:00
|
|
|
g_dbus_connection_call(gl.dbus_connection,
|
|
|
|
|
NM_DBUS_SERVICE,
|
|
|
|
|
gl.ipparam,
|
|
|
|
|
NM_DBUS_INTERFACE_PPP,
|
|
|
|
|
"SetIp4Config",
|
|
|
|
|
g_variant_new("(a{sv})", &builder),
|
|
|
|
|
G_VARIANT_TYPE("()"),
|
|
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
|
-1,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2007-08-15 14:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-19 17:05:38 -04:00
|
|
|
static GVariant *
|
|
|
|
|
eui64_to_variant(eui64_t eui)
|
2014-06-12 09:59:38 -05:00
|
|
|
{
|
|
|
|
|
guint64 iid;
|
|
|
|
|
|
|
|
|
|
G_STATIC_ASSERT(sizeof(iid) == sizeof(eui));
|
|
|
|
|
|
|
|
|
|
memcpy(&iid, &eui, sizeof(eui));
|
2014-08-19 17:05:38 -04:00
|
|
|
return g_variant_new_uint64(iid);
|
2014-06-12 09:59:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
nm_ip6_up(void *data, int arg)
|
|
|
|
|
{
|
|
|
|
|
ipv6cp_options *ho = &ipv6cp_hisoptions[0];
|
|
|
|
|
ipv6cp_options *go = &ipv6cp_gotoptions[0];
|
2014-08-19 17:05:38 -04:00
|
|
|
GVariantBuilder builder;
|
2014-06-12 09:59:38 -05:00
|
|
|
|
2019-05-05 15:00:37 +02:00
|
|
|
g_return_if_fail(G_IS_DBUS_CONNECTION(gl.dbus_connection));
|
2014-06-12 09:59:38 -05:00
|
|
|
|
2019-05-05 15:00:37 +02:00
|
|
|
g_message("nm-ppp-plugin: ip6-up event");
|
2014-06-12 09:59:38 -05:00
|
|
|
|
2014-08-19 17:05:38 -04:00
|
|
|
g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
|
2018-01-08 16:45:43 +01:00
|
|
|
/* Keep sending the interface name to be backwards compatible
|
|
|
|
|
* with older versions of NM during a package upgrade, where
|
|
|
|
|
* NM is not restarted and the pppd plugin was not loaded. */
|
2014-08-19 17:05:38 -04:00
|
|
|
g_variant_builder_add(&builder,
|
|
|
|
|
"{sv}",
|
|
|
|
|
NM_PPP_IP6_CONFIG_INTERFACE,
|
|
|
|
|
g_variant_new_string(ifname));
|
|
|
|
|
g_variant_builder_add(&builder, "{sv}", NM_PPP_IP6_CONFIG_OUR_IID, eui64_to_variant(go->ourid));
|
|
|
|
|
g_variant_builder_add(&builder,
|
|
|
|
|
"{sv}",
|
|
|
|
|
NM_PPP_IP6_CONFIG_PEER_IID,
|
|
|
|
|
eui64_to_variant(ho->hisid));
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-06-12 09:59:38 -05:00
|
|
|
/* DNS is done via DHCPv6 or router advertisements */
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-05-05 15:00:37 +02:00
|
|
|
g_message("nm-ppp-plugin: sending IPv6 config to NetworkManager...");
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-05-05 15:00:37 +02:00
|
|
|
g_dbus_connection_call(gl.dbus_connection,
|
|
|
|
|
NM_DBUS_SERVICE,
|
|
|
|
|
gl.ipparam,
|
|
|
|
|
NM_DBUS_INTERFACE_PPP,
|
|
|
|
|
"SetIp6Config",
|
|
|
|
|
g_variant_new("(a{sv})", &builder),
|
|
|
|
|
G_VARIANT_TYPE("()"),
|
|
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
|
-1,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2014-06-12 09:59:38 -05:00
|
|
|
}
|
|
|
|
|
|
2008-04-16 20:05:09 +00:00
|
|
|
static int
|
2011-04-26 13:49:05 -05:00
|
|
|
get_chap_check(void)
|
2008-04-16 20:05:09 +00:00
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2011-04-26 13:49:05 -05:00
|
|
|
get_pap_check(void)
|
2008-04-16 20:05:09 +00:00
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-11 16:37:41 +00:00
|
|
|
static int
|
|
|
|
|
get_credentials(char *username, char *password)
|
|
|
|
|
{
|
2019-05-05 15:00:37 +02:00
|
|
|
gs_unref_variant GVariant *ret = NULL;
|
|
|
|
|
gs_free_error GError *error = NULL;
|
|
|
|
|
const char * my_username;
|
|
|
|
|
const char * my_password;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-04-15 16:54:38 +02:00
|
|
|
if (!password) {
|
2008-04-16 20:05:09 +00:00
|
|
|
/* pppd is checking pap support; return 1 for supported */
|
2014-04-15 16:54:38 +02:00
|
|
|
g_return_val_if_fail(username, -1);
|
2008-04-16 20:05:09 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-04-15 16:54:38 +02:00
|
|
|
g_return_val_if_fail(username, -1);
|
2019-05-05 15:00:37 +02:00
|
|
|
g_return_val_if_fail(G_IS_DBUS_CONNECTION(gl.dbus_connection), -1);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-05-05 15:00:37 +02:00
|
|
|
g_message("nm-ppp-plugin: passwd-hook, requesting credentials...");
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-05-05 15:00:37 +02:00
|
|
|
ret = g_dbus_connection_call_sync(gl.dbus_connection,
|
|
|
|
|
NM_DBUS_SERVICE,
|
|
|
|
|
gl.ipparam,
|
|
|
|
|
NM_DBUS_INTERFACE_PPP,
|
|
|
|
|
"NeedSecrets",
|
|
|
|
|
NULL,
|
|
|
|
|
G_VARIANT_TYPE("(ss)"),
|
|
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
|
-1,
|
|
|
|
|
NULL,
|
|
|
|
|
&error);
|
2014-08-19 17:05:38 -04:00
|
|
|
if (!ret) {
|
2019-05-05 15:00:37 +02:00
|
|
|
g_warning("nm-ppp-plugin: could not get secrets: %s", error->message);
|
2008-03-11 16:37:41 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-05-05 15:00:37 +02:00
|
|
|
g_message("nm-ppp-plugin: got credentials from NetworkManager");
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-08-19 17:05:38 -04:00
|
|
|
g_variant_get(ret, "(&s&s)", &my_username, &my_password);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-05-05 15:00:37 +02:00
|
|
|
g_strlcpy(username, my_username, MAXNAMELEN);
|
|
|
|
|
g_strlcpy(password, my_password, MAXSECRETLEN);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2008-04-16 20:05:09 +00:00
|
|
|
return 1;
|
2008-03-11 16:37:41 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-15 14:30:06 +00:00
|
|
|
static void
|
|
|
|
|
nm_exit_notify(void *data, int arg)
|
|
|
|
|
{
|
2019-05-05 15:00:37 +02:00
|
|
|
g_return_if_fail(G_IS_DBUS_CONNECTION(gl.dbus_connection));
|
2008-03-11 16:37:41 +00:00
|
|
|
|
2019-06-13 18:23:21 +02:00
|
|
|
/* We wait until this point to notify dead phase to make sure that
|
|
|
|
|
* the serial port has recovered already its original settings.
|
|
|
|
|
*/
|
|
|
|
|
nm_phasechange(PHASE_DEAD);
|
|
|
|
|
|
2019-05-05 15:00:37 +02:00
|
|
|
g_message("nm-ppp-plugin: cleaning up");
|
2009-10-05 12:12:45 -07:00
|
|
|
|
2019-05-05 15:00:37 +02:00
|
|
|
g_clear_object(&gl.dbus_connection);
|
|
|
|
|
nm_clear_g_free(&gl.ipparam);
|
2007-08-15 14:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
2014-06-12 09:59:38 -05:00
|
|
|
static void
|
|
|
|
|
add_ip6_notifier(void)
|
|
|
|
|
{
|
|
|
|
|
static struct notifier **notifier = NULL;
|
|
|
|
|
static gsize load_once = 0;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-06-12 09:59:38 -05:00
|
|
|
if (g_once_init_enter(&load_once)) {
|
|
|
|
|
void *handle = dlopen(NULL, RTLD_NOW | RTLD_GLOBAL);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-06-12 09:59:38 -05:00
|
|
|
if (handle) {
|
|
|
|
|
notifier = dlsym(handle, "ipv6_up_notifier");
|
|
|
|
|
dlclose(handle);
|
|
|
|
|
}
|
|
|
|
|
g_once_init_leave(&load_once, 1);
|
|
|
|
|
}
|
|
|
|
|
if (notifier)
|
|
|
|
|
add_notifier(notifier, nm_ip6_up, NULL);
|
|
|
|
|
else
|
|
|
|
|
g_message("nm-ppp-plugin: no IPV6CP notifier support; IPv6 not available");
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-10 14:36:31 +00:00
|
|
|
int
|
|
|
|
|
plugin_init(void)
|
2007-08-15 14:30:06 +00:00
|
|
|
{
|
2019-05-05 15:00:37 +02:00
|
|
|
gs_free_error GError *err = NULL;
|
2007-10-10 14:36:31 +00:00
|
|
|
|
2019-05-05 15:00:37 +02:00
|
|
|
g_message("nm-ppp-plugin: initializing");
|
2009-10-05 12:12:45 -07:00
|
|
|
|
2019-05-05 15:00:37 +02:00
|
|
|
nm_assert(!gl.dbus_connection);
|
|
|
|
|
nm_assert(!gl.ipparam);
|
2007-08-15 14:30:06 +00:00
|
|
|
|
2019-05-05 15:00:37 +02:00
|
|
|
gl.dbus_connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
|
|
|
|
|
if (!gl.dbus_connection) {
|
|
|
|
|
g_warning("nm-pppd-plugin: couldn't connect to system bus: %s", err->message);
|
2014-08-19 17:05:38 -04:00
|
|
|
return -1;
|
|
|
|
|
}
|
2007-08-15 14:30:06 +00:00
|
|
|
|
2019-05-05 15:00:37 +02:00
|
|
|
gl.ipparam = g_strdup(ipparam);
|
|
|
|
|
|
2008-03-11 16:37:41 +00:00
|
|
|
chap_passwd_hook = get_credentials;
|
2008-04-16 20:05:09 +00:00
|
|
|
chap_check_hook = get_chap_check;
|
2008-03-11 16:37:41 +00:00
|
|
|
pap_passwd_hook = get_credentials;
|
2008-04-16 20:05:09 +00:00
|
|
|
pap_check_hook = get_pap_check;
|
2008-03-11 16:37:41 +00:00
|
|
|
|
2019-06-13 18:23:21 +02:00
|
|
|
add_notifier(&phasechange, nm_phasechange_hook, NULL);
|
2008-03-07 18:04:59 +00:00
|
|
|
add_notifier(&ip_up_notifier, nm_ip_up, NULL);
|
2019-05-05 15:00:37 +02:00
|
|
|
add_notifier(&exitnotify, nm_exit_notify, NULL);
|
2014-06-12 09:59:38 -05:00
|
|
|
add_ip6_notifier();
|
2007-08-15 14:30:06 +00:00
|
|
|
|
2007-10-10 14:36:31 +00:00
|
|
|
return 0;
|
2007-08-15 14:30:06 +00:00
|
|
|
}
|