diff options
Diffstat (limited to 'src/ppp-manager')
-rw-r--r-- | src/ppp-manager/Makefile.in | 50 | ||||
-rw-r--r-- | src/ppp-manager/nm-ppp-manager.c | 259 | ||||
-rw-r--r-- | src/ppp-manager/nm-ppp-manager.h | 8 |
3 files changed, 148 insertions, 169 deletions
diff --git a/src/ppp-manager/Makefile.in b/src/ppp-manager/Makefile.in index 897a50334..f8f55d2c8 100644 --- a/src/ppp-manager/Makefile.in +++ b/src/ppp-manager/Makefile.in @@ -38,16 +38,11 @@ subdir = src/ppp-manager DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/compiler_warnings.m4 \ - $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/gtk-doc.m4 \ - $(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/intlmacosx.m4 \ - $(top_srcdir)/m4/intltool.m4 $(top_srcdir)/m4/introspection.m4 \ - $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \ - $(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/libnl-check.m4 \ - $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ - $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ - $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/nls.m4 \ - $(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/progtest.m4 \ - $(top_srcdir)/configure.ac + $(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/intltool.m4 \ + $(top_srcdir)/m4/libnl-check.m4 $(top_srcdir)/m4/libtool.m4 \ + $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ + $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ + $(top_srcdir)/m4/nls.m4 $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d @@ -101,7 +96,7 @@ nm_pppd_plugin_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ -o $@ @WITH_PPP_TRUE@am_nm_pppd_plugin_la_rpath = -rpath $(pppd_plugindir) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) -depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp +depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ @@ -133,6 +128,7 @@ ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ +ACLOCAL_AMFLAGS = @ACLOCAL_AMFLAGS@ ALL_LINGUAS = @ALL_LINGUAS@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ @@ -141,6 +137,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +CATALOGS = @CATALOGS@ +CATOBJEXT = @CATOBJEXT@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -157,7 +155,6 @@ DHCLIENT_PATH = @DHCLIENT_PATH@ DHCLIENT_VERSION = @DHCLIENT_VERSION@ DHCPCD_PATH = @DHCPCD_PATH@ DISABLE_DEPRECATED = @DISABLE_DEPRECATED@ -DLLTOOL = @DLLTOOL@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ @@ -166,7 +163,6 @@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ -GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ GETTEXT_PACKAGE = @GETTEXT_PACKAGE@ GIO_CFLAGS = @GIO_CFLAGS@ GIO_LIBS = @GIO_LIBS@ @@ -175,8 +171,8 @@ GLIB_GENMARSHAL = @GLIB_GENMARSHAL@ GLIB_LIBS = @GLIB_LIBS@ GMODULE_CFLAGS = @GMODULE_CFLAGS@ GMODULE_LIBS = @GMODULE_LIBS@ +GMOFILES = @GMOFILES@ GMSGFMT = @GMSGFMT@ -GMSGFMT_015 = @GMSGFMT_015@ GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ GNUTLS_LIBS = @GNUTLS_LIBS@ GREP = @GREP@ @@ -191,23 +187,13 @@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +INSTOBJEXT = @INSTOBJEXT@ INTLLIBS = @INTLLIBS@ INTLTOOL_EXTRACT = @INTLTOOL_EXTRACT@ INTLTOOL_MERGE = @INTLTOOL_MERGE@ INTLTOOL_PERL = @INTLTOOL_PERL@ INTLTOOL_UPDATE = @INTLTOOL_UPDATE@ -INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@ -INTROSPECTION_CFLAGS = @INTROSPECTION_CFLAGS@ -INTROSPECTION_COMPILER = @INTROSPECTION_COMPILER@ -INTROSPECTION_GENERATE = @INTROSPECTION_GENERATE@ -INTROSPECTION_GIRDIR = @INTROSPECTION_GIRDIR@ -INTROSPECTION_LIBS = @INTROSPECTION_LIBS@ -INTROSPECTION_MAKEFILE = @INTROSPECTION_MAKEFILE@ -INTROSPECTION_SCANNER = @INTROSPECTION_SCANNER@ -INTROSPECTION_TYPELIBDIR = @INTROSPECTION_TYPELIBDIR@ IPTABLES_PATH = @IPTABLES_PATH@ -IWMX_SDK_CFLAGS = @IWMX_SDK_CFLAGS@ -IWMX_SDK_LIBS = @IWMX_SDK_LIBS@ KERNEL_FIRMWARE_DIR = @KERNEL_FIRMWARE_DIR@ LD = @LD@ LDFLAGS = @LDFLAGS@ @@ -215,8 +201,6 @@ LIBDL = @LIBDL@ LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ -LIBICONV = @LIBICONV@ -LIBINTL = @LIBINTL@ LIBM = @LIBM@ LIBNL_CFLAGS = @LIBNL_CFLAGS@ LIBNL_LIBS = @LIBNL_LIBS@ @@ -225,15 +209,13 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ -LTLIBICONV = @LTLIBICONV@ -LTLIBINTL = @LTLIBINTL@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ -MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ +MKINSTALLDIRS = @MKINSTALLDIRS@ MSGFMT = @MSGFMT@ -MSGFMT_015 = @MSGFMT_015@ +MSGFMT_OPTS = @MSGFMT_OPTS@ MSGMERGE = @MSGMERGE@ NM = @NM@ NMEDIT = @NMEDIT@ @@ -259,9 +241,12 @@ PKGCONFIG_PATH = @PKGCONFIG_PATH@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +POFILES = @POFILES@ POLKIT_CFLAGS = @POLKIT_CFLAGS@ POLKIT_LIBS = @POLKIT_LIBS@ POSUB = @POSUB@ +PO_IN_DATADIR_FALSE = @PO_IN_DATADIR_FALSE@ +PO_IN_DATADIR_TRUE = @PO_IN_DATADIR_TRUE@ PPPD_PLUGIN_DIR = @PPPD_PLUGIN_DIR@ RANLIB = @RANLIB@ RESOLVCONF_PATH = @RESOLVCONF_PATH@ @@ -276,13 +261,10 @@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ VERSION = @VERSION@ XGETTEXT = @XGETTEXT@ -XGETTEXT_015 = @XGETTEXT_015@ -XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ -ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ diff --git a/src/ppp-manager/nm-ppp-manager.c b/src/ppp-manager/nm-ppp-manager.c index 41b5ef1a7..1258b8f62 100644 --- a/src/ppp-manager/nm-ppp-manager.c +++ b/src/ppp-manager/nm-ppp-manager.c @@ -66,10 +66,14 @@ static gboolean impl_ppp_manager_set_ip4_config (NMPPPManager *manager, #include "nm-ppp-manager-glue.h" +static void _ppp_cleanup (NMPPPManager *manager); + #define NM_PPPD_PLUGIN PLUGINDIR "/nm-pppd-plugin.so" #define PPP_MANAGER_SECRET_TRIES "ppp-manager-secret-tries" typedef struct { + gboolean disposed; + GPid pid; NMDBusManager *dbus_manager; char *dbus_path; @@ -78,7 +82,6 @@ typedef struct { NMActRequest *act_req; DBusGMethodInvocation *pending_secrets_context; - guint32 secrets_id; guint32 ppp_watch_id; guint32 ppp_timeout_handler; @@ -164,11 +167,19 @@ dispose (GObject *object) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (object); - nm_ppp_manager_stop (NM_PPP_MANAGER (object)); + if (priv->disposed == FALSE) { + priv->disposed = TRUE; + + _ppp_cleanup (NM_PPP_MANAGER (object)); - if (priv->act_req) - g_object_unref (priv->act_req); - g_object_unref (priv->dbus_manager); + if (priv->act_req) { + g_object_unref (priv->act_req); + priv->act_req = NULL; + } + + g_object_unref (priv->dbus_manager); + priv->dbus_manager = NULL; + } G_OBJECT_CLASS (nm_ppp_manager_parent_class)->dispose (object); } @@ -192,7 +203,8 @@ set_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_PARENT_IFACE: - g_free (priv->parent_iface); + if (priv->parent_iface) + g_free (priv->parent_iface); priv->parent_iface = g_value_dup_string (value); break; default: @@ -315,9 +327,12 @@ monitor_stats (NMPPPManager *manager) NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); priv->monitor_fd = socket (AF_INET, SOCK_DGRAM, 0); - if (priv->monitor_fd > 0) + if (priv->monitor_fd > 0) { + g_warn_if_fail (priv->monitor_id == 0); + if (priv->monitor_id) + g_source_remove (priv->monitor_id); priv->monitor_id = g_timeout_add_seconds (5, monitor_cb, manager); - else + } else nm_log_warn (LOGD_PPP, "could not monitor PPP stats: %s", strerror (errno)); } @@ -335,147 +350,87 @@ remove_timeout_handler (NMPPPManager *manager) } static void -cancel_get_secrets (NMPPPManager *self) -{ - NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); - - if (priv->secrets_id) { - nm_act_request_cancel_secrets (priv->act_req, priv->secrets_id); - priv->secrets_id = 0; - } -} - -static gboolean -extract_details_from_connection (NMConnection *connection, - const char **username, - const char **password, - GError **error) -{ - NMSettingConnection *s_con; - NMSetting *setting; - const char *connection_type; - - g_return_val_if_fail (connection != NULL, FALSE); - g_return_val_if_fail (username != NULL, FALSE); - g_return_val_if_fail (password != NULL, FALSE); - - s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION)); - g_assert (s_con); - - connection_type = nm_setting_connection_get_connection_type (s_con); - g_assert (connection_type); - - setting = nm_connection_get_setting_by_name (connection, connection_type); - if (!setting) { - g_set_error_literal (error, NM_PPP_MANAGER_ERROR, NM_PPP_MANAGER_ERROR_UNKOWN, - "Missing type-specific setting; no secrets could be found."); - return FALSE; - } - - /* FIXME: push this down to the settings and keep PPP manager generic */ - if (NM_IS_SETTING_PPPOE (setting)) { - *username = nm_setting_pppoe_get_username (NM_SETTING_PPPOE (setting)); - *password = nm_setting_pppoe_get_password (NM_SETTING_PPPOE (setting)); - } else if (NM_IS_SETTING_GSM (setting)) { - *username = nm_setting_gsm_get_username (NM_SETTING_GSM (setting)); - *password = nm_setting_gsm_get_password (NM_SETTING_GSM (setting)); - } else if (NM_IS_SETTING_CDMA (setting)) { - *username = nm_setting_cdma_get_username (NM_SETTING_CDMA (setting)); - *password = nm_setting_cdma_get_password (NM_SETTING_CDMA (setting)); - } - - return TRUE; -} - -static void -ppp_secrets_cb (NMActRequest *req, - guint32 call_id, - NMConnection *connection, - GError *error, - gpointer user_data) -{ - NMPPPManager *self = NM_PPP_MANAGER (user_data); - NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); - const char *username = NULL; - const char *password = NULL; - GError *local = NULL; - - g_return_if_fail (priv->pending_secrets_context != NULL); - g_return_if_fail (req == priv->act_req); - g_return_if_fail (call_id == priv->secrets_id); - - if (error) { - nm_log_warn (LOGD_PPP, "%s", error->message); - dbus_g_method_return_error (priv->pending_secrets_context, error); - goto out; - } - - if (!extract_details_from_connection (connection, &username, &password, &local)) { - nm_log_warn (LOGD_PPP, "%s", local->message); - dbus_g_method_return_error (priv->pending_secrets_context, local); - g_clear_error (&local); - goto out; - } - - /* This is sort of a hack but... - * pppd plugin only ever needs username and password. Passing the full - * connection there would mean some bloat: the plugin would need to link - * against libnm-util just to parse this. So instead, let's just send what - * it needs. - */ - dbus_g_method_return (priv->pending_secrets_context, username, password); - -out: - priv->pending_secrets_context = NULL; - priv->secrets_id = 0; -} - -static void impl_ppp_manager_need_secrets (NMPPPManager *manager, DBusGMethodInvocation *context) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); NMConnection *connection; + NMSettingConnection *s_con; + const char *connection_type; const char *setting_name; - const char *username = NULL; - const char *password = NULL; guint32 tries; GPtrArray *hints = NULL; - GError *error = NULL; - NMSettingsGetSecretsFlags flags = NM_SETTINGS_GET_SECRETS_FLAG_ALLOW_INTERACTION; + const char *hint1 = NULL, *hint2 = NULL; connection = nm_act_request_get_connection (priv->act_req); + s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION)); + g_assert (s_con); + + connection_type = nm_setting_connection_get_connection_type (s_con); + g_assert (connection_type); + nm_connection_clear_secrets (connection); setting_name = nm_connection_need_secrets (connection, &hints); if (!setting_name) { - /* Use existing secrets from the connection */ - if (extract_details_from_connection (connection, &username, &password, &error)) { - /* Send existing secrets to the PPP plugin */ + NMSetting *setting; + + setting = nm_connection_get_setting_by_name (connection, connection_type); + if (setting) { + const char *username = NULL; + const char *password = NULL; + + /* FIXME: push this down to the settings and keep PPP manager generic */ + if (NM_IS_SETTING_PPPOE (setting)) { + username = nm_setting_pppoe_get_username (NM_SETTING_PPPOE (setting)); + password = nm_setting_pppoe_get_password (NM_SETTING_PPPOE (setting)); + } else if (NM_IS_SETTING_GSM (setting)) { + username = nm_setting_gsm_get_username (NM_SETTING_GSM (setting)); + password = nm_setting_gsm_get_password (NM_SETTING_GSM (setting)); + } else if (NM_IS_SETTING_CDMA (setting)) { + username = nm_setting_cdma_get_username (NM_SETTING_CDMA (setting)); + password = nm_setting_cdma_get_password (NM_SETTING_CDMA (setting)); + } + + /* If secrets are not required, send the existing username and password + * back to the PPP plugin immediately. + */ priv->pending_secrets_context = context; - ppp_secrets_cb (priv->act_req, priv->secrets_id, connection, NULL, manager); + nm_ppp_manager_update_secrets (manager, + priv->parent_iface, + username ? username : "", + password ? password : "", + NULL); } else { - nm_log_warn (LOGD_PPP, "%s", error->message); - dbus_g_method_return_error (priv->pending_secrets_context, error); - g_clear_error (&error); + GError *err = NULL; + + g_set_error (&err, NM_PPP_MANAGER_ERROR, NM_PPP_MANAGER_ERROR_UNKOWN, + "Missing type-specific setting; no secrets could be found."); + nm_log_warn (LOGD_PPP, "%s", err->message); + dbus_g_method_return_error (context, err); } return; } - /* Only ask for completely new secrets after retrying them once; some devices - * appear to ask a few times when they actually don't even care what you - * pass back. - */ + /* Extract hints */ + if (hints) { + if (hints->len > 0) + hint1 = g_ptr_array_index (hints, 0); + if (hints->len > 1) + hint2 = g_ptr_array_index (hints, 1); + } + tries = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (connection), PPP_MANAGER_SECRET_TRIES)); - if (tries > 1) - flags |= NM_SETTINGS_GET_SECRETS_FLAG_REQUEST_NEW; - - priv->secrets_id = nm_act_request_get_secrets (priv->act_req, - setting_name, - flags, - hints ? g_ptr_array_index (hints, 0) : NULL, - ppp_secrets_cb, - manager); + /* Only ask for completely new secrets after retrying them once; some PPP + * servers (T-Mobile USA) appear to ask a few times when they actually don't + * even care what you pass back. + */ + nm_act_request_get_secrets (priv->act_req, + setting_name, + tries > 1 ? TRUE : FALSE, + SECRETS_CALLER_PPP, + hint1, + hint2); g_object_set_data (G_OBJECT (connection), PPP_MANAGER_SECRET_TRIES, GUINT_TO_POINTER (++tries)); priv->pending_secrets_context = context; @@ -766,7 +721,7 @@ pppd_timed_out (gpointer data) NMPPPManager *manager = NM_PPP_MANAGER (data); nm_log_warn (LOGD_PPP, "pppd timed out or didn't initialize our dbus module"); - nm_ppp_manager_stop (manager); + _ppp_cleanup (manager); g_signal_emit (manager, signals[STATE_CHANGED], 0, NM_PPP_STATUS_DEAD); @@ -1027,6 +982,46 @@ nm_ppp_manager_start (NMPPPManager *manager, return priv->pid > 0; } +void +nm_ppp_manager_update_secrets (NMPPPManager *manager, + const char *device, + const char *username, + const char *password, + const char *error_message) +{ + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); + + g_return_if_fail (NM_IS_PPP_MANAGER (manager)); + g_return_if_fail (device != NULL); + g_return_if_fail (priv->pending_secrets_context != NULL); + + if (error_message) { + g_return_if_fail (username == NULL); + g_return_if_fail (password == NULL); + } else { + g_return_if_fail (username != NULL); + g_return_if_fail (password != NULL); + } + + if (error_message) { + GError *err = NULL; + + g_set_error (&err, NM_PPP_MANAGER_ERROR, NM_PPP_MANAGER_ERROR_UNKOWN, "%s", error_message); + nm_log_warn (LOGD_PPP, "%s", error_message); + dbus_g_method_return_error (priv->pending_secrets_context, err); + g_error_free (err); + } else { + /* This is sort of a hack but... + pppd plugin only ever needs username and password. + Passing the full connection there would mean some bloat: + the plugin would need to link against libnm-util just to parse this. + So instead, let's just send what it needs */ + + dbus_g_method_return (priv->pending_secrets_context, username, password); + } + priv->pending_secrets_context = NULL; +} + static gboolean ensure_killed (gpointer data) { @@ -1043,8 +1038,8 @@ ensure_killed (gpointer data) return FALSE; } -void -nm_ppp_manager_stop (NMPPPManager *manager) +static void +_ppp_cleanup (NMPPPManager *manager) { NMPPPManagerPrivate *priv; @@ -1052,8 +1047,6 @@ nm_ppp_manager_stop (NMPPPManager *manager) priv = NM_PPP_MANAGER_GET_PRIVATE (manager); - cancel_get_secrets (manager); - if (priv->monitor_id) { g_source_remove (priv->monitor_id); priv->monitor_id = 0; diff --git a/src/ppp-manager/nm-ppp-manager.h b/src/ppp-manager/nm-ppp-manager.h index 5a8c73e4c..516841573 100644 --- a/src/ppp-manager/nm-ppp-manager.h +++ b/src/ppp-manager/nm-ppp-manager.h @@ -16,7 +16,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Copyright (C) 2008 Novell, Inc. - * Copyright (C) 2008 - 2010 Red Hat, Inc. + * Copyright (C) 2008 Red Hat, Inc. */ #ifndef NM_PPP_MANAGER_H @@ -63,7 +63,11 @@ gboolean nm_ppp_manager_start (NMPPPManager *manager, guint32 timeout_secs, GError **err); -void nm_ppp_manager_stop (NMPPPManager *manager); +void nm_ppp_manager_update_secrets (NMPPPManager *manager, + const char *device, + const char *username, + const char *password, + const char *error_message); #define NM_PPP_MANAGER_ERROR nm_ppp_manager_error_quark() |