diff options
author | Tim Niemueller <tim@niemueller.de> | 2006-08-19 15:17:04 +0000 |
---|---|---|
committer | Tim Niemueller <tim@niemueller.de> | 2006-08-19 15:17:04 +0000 |
commit | 3627396981b901e09804dbea51aae6377282ac34 (patch) | |
tree | ded838fba6de35ac91adb074c1b478f1d1467d3b | |
parent | 1883054226e245eea549440ef538359abe8754c8 (diff) | |
download | NetworkManager-3627396981b901e09804dbea51aae6377282ac34.tar.gz |
2006-08-19 Tim Niemueller <tim@niemueller.de>
* src/ppp-manager/*: removed, now in src/dialup/manager
and src/dialup/ppp
* src/Makefile.am
src/NetworkManager.c
src/NetworkManagerDbus.c
src/NetworkManagerMain.h
src/NetworkManagerPolicy.c
src/NetworkManagerSystem.h
src/nm-dbus-nm.c: Remove old dialup code, add support for new
dialup manager
* src/NetworkManagerDialup.h: removed, belonged to old dialup system
* src/vpn-manager/nm-dbus-vpn.c: Readability fixes
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/branches/SoC_2006@1979 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/NetworkManager.c | 21 | ||||
-rw-r--r-- | src/NetworkManagerDbus.c | 74 | ||||
-rw-r--r-- | src/NetworkManagerDialup.h | 14 | ||||
-rw-r--r-- | src/NetworkManagerMain.h | 8 | ||||
-rw-r--r-- | src/NetworkManagerPolicy.c | 5 | ||||
-rw-r--r-- | src/NetworkManagerSystem.h | 5 | ||||
-rw-r--r-- | src/nm-dbus-nm.c | 125 | ||||
-rw-r--r-- | src/ppp-manager/.cvsignore | 4 | ||||
-rw-r--r-- | src/ppp-manager/Makefile.am | 65 | ||||
-rw-r--r-- | src/ppp-manager/nm-ppp-service.c | 1421 | ||||
-rw-r--r-- | src/ppp-manager/nm-ppp-service.h | 32 | ||||
-rw-r--r-- | src/ppp-manager/nm-ppp.conf | 20 | ||||
-rw-r--r-- | src/ppp-manager/nm-ppp.h | 74 | ||||
-rw-r--r-- | src/ppp-manager/nm-pppd-plugin.c | 568 | ||||
-rw-r--r-- | src/ppp-manager/nm-pppd-plugin.h | 31 | ||||
-rw-r--r-- | src/vpn-manager/nm-dbus-vpn.c | 6 |
17 files changed, 101 insertions, 2376 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 5520d5556b..d389bb92e3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,10 +1,11 @@ -SUBDIRS=named-manager vpn-manager dhcp-manager ppp-manager backends +SUBDIRS=named-manager vpn-manager dhcp-manager dialup backends INCLUDES = -I${top_srcdir} \ -I${top_srcdir}/include \ -I${top_srcdir}/src/named-manager \ -I${top_srcdir}/src/vpn-manager \ -I${top_srcdir}/src/dhcp-manager \ + -I${top_srcdir}/src/dialup/manager \ -I${top_srcdir}/utils \ -I${top_srcdir}/libnm-util @@ -121,6 +122,7 @@ NetworkManager_LDADD = \ ./named-manager/libnamed-manager.la \ ./vpn-manager/libvpn-manager.la \ ./dhcp-manager/libdhcp-manager.la \ + ./dialup/manager/libdialup-manager.la \ ./backends/libnmbackend.la \ $(top_builddir)/libnm-util/libnm-util.la diff --git a/src/NetworkManager.c b/src/NetworkManager.c index 6c98d6495d..3dd21b5467 100644 --- a/src/NetworkManager.c +++ b/src/NetworkManager.c @@ -52,6 +52,8 @@ #include "nm-named-manager.h" #include "nm-vpn-act-request.h" #include "nm-dbus-vpn.h" +#include "nm-dialup-act-request.h" +#include "nm-dbus-dialup.h" #include "nm-netlink-monitor.h" #include "nm-dhcp-manager.h" #include "nm-logging.h" @@ -447,15 +449,13 @@ static NMData *nm_data_new (gboolean enable_test_devices) /* Initialize the device list mutex to protect additions/deletions to it. */ data->dev_list_mutex = g_mutex_new (); - data->dialup_list_mutex = g_mutex_new (); - if (!data->dev_list_mutex || !data->dialup_list_mutex) + if (!data->dev_list_mutex) { nm_data_free (data); nm_warning ("could not initialize data structure locks."); return NULL; } nm_register_mutex_desc (data->dev_list_mutex, "Device List Mutex"); - nm_register_mutex_desc (data->dialup_list_mutex, "DialUp List Mutex"); /* Initialize the access point lists */ data->allowed_ap_list = nm_ap_list_new (NETWORK_TYPE_ALLOWED); @@ -499,13 +499,17 @@ static void device_stop_and_free (NMDevice *dev, gpointer user_data) */ static void nm_data_free (NMData *data) { - NMVPNActRequest *req; + NMVPNActRequest *vpn_act_req; + NMDialupActRequest *dialup_act_req; g_return_if_fail (data != NULL); /* Kill any active VPN connection */ - if ((req = nm_vpn_manager_get_vpn_act_request (data->vpn_manager))) - nm_vpn_manager_deactivate_vpn_connection (data->vpn_manager, nm_vpn_act_request_get_parent_dev (req)); + if ((vpn_act_req = nm_vpn_manager_get_vpn_act_request (data->vpn_manager))) + nm_vpn_manager_deactivate_vpn_connection (data->vpn_manager, nm_vpn_act_request_get_parent_dev (vpn_act_req)); + + if ((dialup_act_req = nm_dialup_manager_get_dialup_act_request (data->dialup_manager))) + nm_dialup_manager_deactivate_dialup_connection (data->dialup_manager); if (data->netlink_monitor) { @@ -527,6 +531,7 @@ static void nm_data_free (NMData *data) nm_vpn_manager_dispose (data->vpn_manager); nm_dhcp_manager_dispose (data->dhcp_manager); g_object_unref (data->named_manager); + nm_dialup_manager_dispose (data->dialup_manager); g_main_loop_unref (data->main_loop); g_main_context_unref (data->main_context); @@ -769,12 +774,14 @@ int main( int argc, char *argv[] ) nm_data->vpn_manager = nm_vpn_manager_new (nm_data); nm_data->dhcp_manager = nm_dhcp_manager_new (nm_data); nm_data->named_manager = nm_named_manager_new (nm_data->dbus_connection); + nm_data->dialup_manager = nm_dialup_manager_new (nm_data); /* If NMI is running, grab allowed wireless network lists from it ASAP */ if (nm_dbus_is_info_daemon_running (nm_data->dbus_connection)) { nm_policy_schedule_allowed_ap_list_update (nm_data); nm_dbus_vpn_schedule_vpn_connections_update (nm_data); + nm_dbus_dialup_schedule_dialup_connections_update (nm_data); } /* Right before we init hal, we have to make sure our mainloop @@ -797,7 +804,7 @@ int main( int argc, char *argv[] ) nm_system_enable_loopback (); /* Get modems, ISDN, and so on's configuration from the system */ - nm_data->dialup_list = nm_system_get_dialup_config (); + // nm_data->dialup_list = nm_system_get_dialup_config (); /* Run the main loop */ nm_policy_schedule_device_change_check (nm_data); diff --git a/src/NetworkManagerDbus.c b/src/NetworkManagerDbus.c index a550fa2894..7611c1aedc 100644 --- a/src/NetworkManagerDbus.c +++ b/src/NetworkManagerDbus.c @@ -40,9 +40,11 @@ #include "nm-dbus-device.h" #include "nm-dbus-net.h" #include "nm-dbus-vpn.h" +#include "nm-dbus-dialup.h" #include "nm-dbus-nmi.h" #include "nm-utils.h" #include "nm-dhcp-manager.h" +#include "nm-dialup-manager.h" static char *get_nmi_match_string (const char *owner); @@ -300,8 +302,24 @@ NMState nm_get_app_state_from_data (NMData *data) return NM_STATE_ASLEEP; act_dev = nm_get_active_device (data); - if (!act_dev && !data->modem_active) - return NM_STATE_DISCONNECTED; + if (!act_dev) + { + nm_info ("AppState: No active device"); + + if ( nm_dialup_manager_is_connecting(data->dialup_manager) ) + { + nm_info ("AppState: dialup is connecting"); + return NM_STATE_DIALUP_CONNECTING; + } + else if ( nm_dialup_manager_is_connected(data->dialup_manager) ) + { + nm_info ("AppState: dialup is connected"); + return NM_STATE_DIALUP_CONNECTED; + } + else + return NM_STATE_DISCONNECTED; + + } if (nm_device_is_activating (act_dev)) return NM_STATE_CONNECTING; @@ -486,6 +504,17 @@ static DBusHandlerResult nm_dbus_signal_filter (DBusConnection *connection, DBus handled = TRUE; } } + else if (dbus_message_is_signal (message, NMI_DBUS_INTERFACE, "DialupConnectionUpdate")) + { + char *name = NULL; + + if (dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) + { + nm_debug ("NetworkManagerInfo triggered update of dialup connection '%s'", name); + nm_dbus_dialup_update_one_dialup_connection (data->dbus_connection, name, data); + handled = TRUE; + } + } else if (dbus_message_is_signal (message, NMI_DBUS_INTERFACE, "UserInterfaceActivated")) { nm_device_802_11_wireless_set_scan_interval (data, NULL, NM_WIRELESS_SCAN_INTERVAL_ACTIVE); @@ -521,6 +550,7 @@ static DBusHandlerResult nm_dbus_signal_filter (DBusConnection *connection, DBus dbus_bus_add_match (connection, match, NULL); nm_policy_schedule_allowed_ap_list_update (data); nm_dbus_vpn_schedule_vpn_connections_update (data); + nm_dbus_dialup_schedule_dialup_connections_update (data); g_free (match); handled = TRUE; } @@ -548,6 +578,8 @@ static DBusHandlerResult nm_dbus_signal_filter (DBusConnection *connection, DBus handled = TRUE; else if (nm_vpn_manager_process_name_owner_changed (data->vpn_manager, service, old_owner, new_owner) == TRUE) handled = TRUE; + else if (nm_dialup_manager_process_name_owner_changed (data->dialup_manager, service, old_owner, new_owner) == TRUE) + handled = TRUE; else if (nm_named_manager_process_name_owner_changed (data->named_manager, service, old_owner, new_owner) == TRUE) handled = TRUE; } @@ -556,6 +588,8 @@ static DBusHandlerResult nm_dbus_signal_filter (DBusConnection *connection, DBus handled = TRUE; else if (nm_vpn_manager_process_signal (data->vpn_manager, message) == TRUE) handled = TRUE; + else if (nm_dialup_manager_process_signal (data->dialup_manager, message) == TRUE) + handled = TRUE; if (dbus_error_is_set (&error)) dbus_error_free (&error); @@ -679,6 +713,37 @@ static DBusHandlerResult nm_dbus_vpn_message_handler (DBusConnection *connection /* + * nm_dbus_dialup_message_handler + * + * Dispatch messages against our NetworkManager DialupConnections object + * + */ +static DBusHandlerResult nm_dbus_dialup_message_handler (DBusConnection *connection, DBusMessage *message, void *user_data) +{ + NMData *data = (NMData *)user_data; + gboolean handled = TRUE; + DBusMessage *reply = NULL; + NMDbusCBData cb_data; + + g_return_val_if_fail (data != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); + g_return_val_if_fail (data->vpn_methods != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); + g_return_val_if_fail (connection != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); + g_return_val_if_fail (message != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); + + cb_data.data = data; + cb_data.dev = NULL; + handled = nm_dbus_method_dispatch (data->dialup_methods, connection, message, &cb_data, &reply); + if (reply) + { + dbus_connection_send (connection, reply, NULL); + dbus_message_unref (reply); + } + + return (handled ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED); +} + + +/* * nm_dbus_is_info_daemon_running * * Ask dbus whether or not the info daemon is providing its dbus service @@ -777,6 +842,7 @@ DBusConnection *nm_dbus_init (NMData *data) DBusObjectPathVTable nm_vtable = {NULL, &nm_dbus_nm_message_handler, NULL, NULL, NULL, NULL}; DBusObjectPathVTable devices_vtable = {NULL, &nm_dbus_devices_message_handler, NULL, NULL, NULL, NULL}; DBusObjectPathVTable vpn_vtable = {NULL, &nm_dbus_vpn_message_handler, NULL, NULL, NULL, NULL}; + DBusObjectPathVTable dialup_vtable = {NULL, &nm_dbus_dialup_message_handler, NULL, NULL, NULL, NULL}; char * owner; int flags, ret; @@ -798,10 +864,12 @@ DBusConnection *nm_dbus_init (NMData *data) data->device_methods = nm_dbus_device_methods_setup (); data->net_methods = nm_dbus_net_methods_setup (); data->vpn_methods = nm_dbus_vpn_methods_setup (); + data->dialup_methods = nm_dbus_dialup_methods_setup (); if ( !dbus_connection_register_object_path (connection, NM_DBUS_PATH, &nm_vtable, data) || !dbus_connection_register_fallback (connection, NM_DBUS_PATH_DEVICES, &devices_vtable, data) - || !dbus_connection_register_object_path (connection, NM_DBUS_PATH_VPN, &vpn_vtable, data)) + || !dbus_connection_register_object_path (connection, NM_DBUS_PATH_VPN, &vpn_vtable, data) + || !dbus_connection_register_object_path (connection, NM_DBUS_PATH_DIALUP, &dialup_vtable, data)) { nm_error ("nm_dbus_init() could not register D-BUS handlers. Cannot continue."); connection = NULL; diff --git a/src/NetworkManagerDialup.h b/src/NetworkManagerDialup.h deleted file mode 100644 index 4af82b9835..0000000000 --- a/src/NetworkManagerDialup.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _NETWORK_MANAGER_DIALUP_H -#define _NETWORK_MANAGER_DIALUP_H - -#define NM_DIALUP_TYPE_MODEM 1 -#define NM_DIALUP_TYPE_ISDN 2 - -typedef struct NMDialUpConfig -{ - char *name; /* user-readable name, unique */ - void *data; /* backend internal data */ - unsigned int type; /* type: modem or ISDN, currently */ -} NMDialUpConfig; - -#endif /* _NETWORK_MANAGER_DIALUP_H */ diff --git a/src/NetworkManagerMain.h b/src/NetworkManagerMain.h index 24b703a241..c7e551c1be 100644 --- a/src/NetworkManagerMain.h +++ b/src/NetworkManagerMain.h @@ -50,6 +50,8 @@ typedef struct NMActRequest NMActRequest; typedef struct NMVPNActRequest NMVPNActRequest; typedef struct NMVPNManager NMVPNManager; typedef struct NMDHCPManager NMDHCPManager; +typedef struct NMDialupActRequest NMDialupActRequest; +typedef struct NMDialupManager NMDialupManager; #define DHCP_SERVICE_NAME "com.redhat.dhcp" #define DHCP_OBJECT_PATH "/com/redhat/dhcp" @@ -66,12 +68,14 @@ typedef struct NMData NMNamedManager * named_manager; NMVPNManager * vpn_manager; NMDHCPManager * dhcp_manager; + NMDialupManager * dialup_manager; DBusConnection * dbus_connection; NMDbusMethodList * nm_methods; NMDbusMethodList * device_methods; NMDbusMethodList * net_methods; NMDbusMethodList * vpn_methods; + NMDbusMethodList * dialup_methods; GMainContext * main_context; GMainLoop * main_loop; @@ -83,12 +87,8 @@ typedef struct NMData GMutex * dev_list_mutex; gboolean wireless_enabled; - gboolean modem_active; gboolean asleep; - GSList * dialup_list; - GMutex * dialup_list_mutex; - struct NMAccessPointList *allowed_ap_list; struct NMAccessPointList *invalid_ap_list; } NMData; diff --git a/src/NetworkManagerPolicy.c b/src/NetworkManagerPolicy.c index 37bfdf472f..f97339a778 100644 --- a/src/NetworkManagerPolicy.c +++ b/src/NetworkManagerPolicy.c @@ -38,6 +38,7 @@ #include "nm-dbus-nmi.h" #include "nm-device-802-11-wireless.h" #include "nm-device-802-3-ethernet.h" +#include "nm-dialup-manager.h" /* @@ -190,6 +191,10 @@ static NMDevice * nm_policy_auto_get_best_device (NMData *data, NMAccessPoint ** if (data->asleep) return NULL; + if (nm_dialup_manager_is_connecting(data->dialup_manager) || + nm_dialup_manager_is_connected(data->dialup_manager) ) + return NULL; + for (elt = data->dev_list; elt != NULL; elt = g_slist_next (elt)) { guint dev_type; diff --git a/src/NetworkManagerSystem.h b/src/NetworkManagerSystem.h index ccd020ab06..4e16a66c07 100644 --- a/src/NetworkManagerSystem.h +++ b/src/NetworkManagerSystem.h @@ -76,11 +76,6 @@ gboolean nm_system_device_set_up_down_with_iface (const char *iface, gboolean gboolean nm_system_device_update_resolv_conf (void *data, int len, const char *domain_name); -GSList * nm_system_get_dialup_config (void); -void nm_system_deactivate_all_dialup (GSList *list); -gboolean nm_system_activate_dialup (GSList *list, const char *dialup); -gboolean nm_system_deactivate_dialup (GSList *list, const char *dialup); - void nm_system_set_hostname (NMIP4Config *config); void nm_system_activate_nis (NMIP4Config *config); void nm_system_shutdown_nis (void); diff --git a/src/nm-dbus-nm.c b/src/nm-dbus-nm.c index 64b33b46ac..82adb12232 100644 --- a/src/nm-dbus-nm.c +++ b/src/nm-dbus-nm.c @@ -31,7 +31,6 @@ #include "NetworkManagerDbusUtils.h" #include "NetworkManagerUtils.h" #include "NetworkManagerPolicy.h" -#include "NetworkManagerDialup.h" #include "NetworkManagerSystem.h" #include "NetworkManager.h" #include "nm-ap-security.h" @@ -97,123 +96,6 @@ static DBusMessage *nm_dbus_nm_get_devices (DBusConnection *connection, DBusMess } -static DBusMessage *nm_dbus_nm_get_dialup (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data) -{ - DBusMessage *reply = NULL; - DBusMessageIter iter; - - g_return_val_if_fail (data != NULL, NULL); - g_return_val_if_fail (data->data != NULL, NULL); - g_return_val_if_fail (connection != NULL, NULL); - g_return_val_if_fail (message != NULL, NULL); - - /* Check for no dialup devices */ - if (!data->data->dialup_list) - return (nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "NoDialup", - "There are no available dialup devices.")); - - reply = dbus_message_new_method_return (message); - if (!reply) - return NULL; - - dbus_message_iter_init_append (reply, &iter); - if (nm_try_acquire_mutex (data->data->dialup_list_mutex, __FUNCTION__)) - { - DBusMessageIter iter_array; - GSList *elt; - - dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &iter_array); - - for (elt = data->data->dialup_list; elt; elt = g_slist_next (elt)) - { - NMDialUpConfig *config = (NMDialUpConfig *) elt->data; - dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_STRING, &config->name); - } - - dbus_message_iter_close_container (&iter, &iter_array); - nm_unlock_mutex (data->data->dialup_list_mutex, __FUNCTION__); - } - else - { - dbus_message_unref (reply); - reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "Retry", - "NetworkManager could not lock dialup list, try again."); - } - - return reply; -} - - -static DBusMessage *nm_dbus_nm_activate_dialup (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data) -{ - DBusMessage *reply = NULL; - NMData *nm_data = (NMData *) data->data; - const char *dialup; - - g_return_val_if_fail (data != NULL, NULL); - g_return_val_if_fail (data->data != NULL, NULL); - g_return_val_if_fail (connection != NULL, NULL); - g_return_val_if_fail (message != NULL, NULL); - - reply = dbus_message_new_method_return (message); - if (!reply) - return NULL; - - if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &dialup, DBUS_TYPE_INVALID)) - { - reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "InvalidArguments", - "NetworkManager::activateDialup called with invalid arguments."); - goto out; - } - - nm_lock_mutex (nm_data->dialup_list_mutex, __FUNCTION__); - if (!nm_system_activate_dialup (nm_data->dialup_list, dialup)) - reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "ActivationFailed", - "Failed to activate the dialup device."); - else - nm_data->modem_active = TRUE; - nm_unlock_mutex (nm_data->dialup_list_mutex, __FUNCTION__); - -out: - return reply; -} - - -static DBusMessage *nm_dbus_nm_deactivate_dialup (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data) -{ - DBusMessage *reply = NULL; - NMData *nm_data = (NMData *) data->data; - const char *dialup; - - g_return_val_if_fail (data != NULL, NULL); - g_return_val_if_fail (data->data != NULL, NULL); - g_return_val_if_fail (connection != NULL, NULL); - g_return_val_if_fail (message != NULL, NULL); - - reply = dbus_message_new_method_return (message); - if (!reply) - return NULL; - - if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &dialup, DBUS_TYPE_INVALID)) - { - reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "InvalidArguments", - "NetworkManager::deactivateDialup called with invalid arguments."); - goto out; - } - - nm_lock_mutex (nm_data->dialup_list_mutex, __FUNCTION__); - if (!nm_system_deactivate_dialup (nm_data->dialup_list, dialup)) - reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "DeactivationFailed", - "Failed to deactivate the dialup device."); - else - nm_data->modem_active = FALSE; - nm_unlock_mutex (nm_data->dialup_list_mutex, __FUNCTION__); - -out: - return reply; -} - - /* * nm_dbus_nm_set_active_device * @@ -563,10 +445,6 @@ static DBusMessage *nm_dbus_nm_sleep (DBusConnection *connection, DBusMessage *m } nm_unlock_mutex (app_data->dev_list_mutex, __FUNCTION__); - nm_lock_mutex (app_data->dialup_list_mutex, __FUNCTION__); - nm_system_deactivate_all_dialup (app_data->dialup_list); - app_data->modem_active = FALSE; - nm_unlock_mutex (app_data->dialup_list_mutex, __FUNCTION__); } return NULL; @@ -625,9 +503,6 @@ NMDbusMethodList *nm_dbus_nm_methods_setup (void) NMDbusMethodList *list = nm_dbus_method_list_new (NULL); nm_dbus_method_list_add_method (list, "getDevices", nm_dbus_nm_get_devices); - nm_dbus_method_list_add_method (list, "getDialup", nm_dbus_nm_get_dialup); - nm_dbus_method_list_add_method (list, "activateDialup", nm_dbus_nm_activate_dialup); - nm_dbus_method_list_add_method (list, "deactivateDialup", nm_dbus_nm_deactivate_dialup); nm_dbus_method_list_add_method (list, "setActiveDevice", nm_dbus_nm_set_active_device); nm_dbus_method_list_add_method (list, "createWirelessNetwork", nm_dbus_nm_create_wireless_network); nm_dbus_method_list_add_method (list, "setWirelessEnabled", nm_dbus_nm_set_wireless_enabled); diff --git a/src/ppp-manager/.cvsignore b/src/ppp-manager/.cvsignore deleted file mode 100644 index 207401d476..0000000000 --- a/src/ppp-manager/.cvsignore +++ /dev/null @@ -1,4 +0,0 @@ -Makefile -Makefile.in -nm-ppp-service -nm-pppd-plugin.so diff --git a/src/ppp-manager/Makefile.am b/src/ppp-manager/Makefile.am deleted file mode 100644 index 2e8466da97..0000000000 --- a/src/ppp-manager/Makefile.am +++ /dev/null @@ -1,65 +0,0 @@ -INCLUDES = -I${top_srcdir} \ - -I${top_srcdir}/include \ - -I${top_srcdir}/utils \ - -I${top_srcdir}/src \ - -I${top_srcdir}/src/named-manager - -#noinst_LTLIBRARIES = libppp-manager.la - -#libppp_manager_la_SOURCES = nm-dbus-vpn.c - -#libppp_manager_la_CPPFLAGS = $(DBUS_CFLAGS) \ -# $(GTHREAD_CFLAGS) \ -# $(HAL_CFLAGS) \ -# -g \ -# -Wall \ -# -DDBUS_API_SUBJECT_TO_CHANGE \ -# -DG_DISABLE_DEPRECATED \ -# -DBINDIR=\"$(bindir)\" \ -# -DDATADIR=\"$(datadir)\" \ -# -DSYSCONFDIR=\"$(sysconfdir)\" - - -#libppp_manager_la_LIBADD = $(DBUS_LIBS) $(GTHREAD_LIBS) - - -bin_PROGRAMS = nm-ppp-service - -AM_CPPFLAGS = \ - $(DBUS_CFLAGS) \ - $(GTHREAD_CFLAGS) \ - -Wall \ - -DDBUS_API_SUBJECT_TO_CHANGE \ - -DG_DISABLE_DEPRECATED \ - -DBINDIR=\"$(bindir)\" \ - -DPREFIX=\""$(prefix)"\" \ - -DSYSCONFDIR=\""$(sysconfdir)"\" \ - -DVERSION="\"$(VERSION)\"" \ - -DLIBDIR=\""$(libdir)"\" \ - -DLIBEXECDIR=\""$(libexecdir)"\" \ - -DLOCALSTATEDIR=\""$(localstatedir)"\" \ - -DDATADIR=\"$(datadir)\" \ - -fPIC - -nm_ppp_service_SOURCES = \ - nm-ppp-service.c \ - nm-ppp-service.h - -nm_ppp_service_LDADD = \ - $(DBUS_LIBS) \ - $(GTHREAD_LIBS) - -nm_pppd_plugindir = $(libdir)/pppd/`grep VERSION $(incdir)/pppd/patchlevel.h | awk -F\" '{ print $$2 }'` -nm_pppd_plugin_PROGRAMS = nm-pppd-plugin.so - -nm_pppd_plugin_so_SOURCES = \ - nm-pppd-plugin.h \ - nm-pppd-plugin.c \ - nm-ppp-service.h - -nm_pppd_plugin_so_LDFLAGS = -shared -nm_pppd_plugin_so_LDADD = $(DBUS_LIBS) \ - $(GTHREAD_LIBS) - -CLEANFILES = *~ - diff --git a/src/ppp-manager/nm-ppp-service.c b/src/ppp-manager/nm-ppp-service.c deleted file mode 100644 index f7b58771c3..0000000000 --- a/src/ppp-manager/nm-ppp-service.c +++ /dev/null @@ -1,1421 +0,0 @@ -/* nm-ppp-supervisor - pppd supervisor - * - * Tim Niemueller <tim@niemueller.de> - * Based on work by Dan Williams <dcbw@redhat.com> - * - * 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 2 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ - * - */ - - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib/gi18n.h> -#include <dbus/dbus.h> -#include <dbus/dbus-glib-lowlevel.h> -#include <dbus/dbus-glib.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <signal.h> -#include <sys/stat.h> -#include <sys/wait.h> -#include <sys/socket.h> -#include <sys/types.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <ctype.h> - -#include <NetworkManager/NetworkManager.h> - -#include "nm-ppp-service.h" -#include "nm-utils.h" - -#define NM_PPPD_PLUGIN "nm-pppd-plugin.so" - -typedef struct _NmPPP_IOData -{ - char *username; - char *password; - gint child_stdin_fd; - gint child_stdout_fd; - gint child_stderr_fd; -} NmPPP_IOData; - -typedef struct _NmPPPData -{ - GMainLoop *loop; - DBusConnection *con; - NMPPPState state; - gboolean use_wvdial; - GPid pid; - guint quit_timer; - guint helper_timer; - gint connection_type; - guint connect_timer; - guint connect_count; - NmPPP_IOData *io_data; -} NmPPPData; - -static gboolean nm_ppp_dbus_handle_stop_pppd (NmPPPData *data); - - -static inline const char *nm_find_pppd (void) -{ - static const char *pppd_binary_paths[] = - { - "/usr/local/sbin/pppd", - "/usr/sbin/pppd", - "/sbin/pppd", - NULL - }; - - const char **pppd_binary = pppd_binary_paths; - - while (*pppd_binary != NULL) { - if (g_file_test (*pppd_binary, G_FILE_TEST_EXISTS)) - break; - pppd_binary++; - } - - return *pppd_binary; -} - - -static inline const char *nm_find_wvdial (void) -{ - static const char *wvdial_binary_paths[] = - { - "/usr/local/bin/wvdial", - "/usr/bin/wvdial", - "/bin/wvdial", - NULL - }; - - const char **wvdial_binary = wvdial_binary_paths; - - while (*wvdial_binary != NULL) { - if (g_file_test (*wvdial_binary, G_FILE_TEST_EXISTS)) - break; - wvdial_binary++; - } - - return *wvdial_binary; -} - - -/* - * nm_dbus_create_error_message - * - * Make a DBus error message - * - */ -static DBusMessage * -nm_dbus_create_error_message (DBusMessage *message, const char *exception_namespace, - const char *exception, const char *format, ...) -{ - char *exception_text; - DBusMessage *reply; - va_list args; - char error_text[512]; - - va_start (args, format); - vsnprintf (error_text, 512, format, args); - va_end (args); - - exception_text = g_strdup_printf ("%s.%s", exception_namespace, exception); - reply = dbus_message_new_error (message, exception_text, error_text); - g_free (exception_text); - - return (reply); -} - - -/* - * nm_ppp_dbus_signal_failure - * - * Signal the bus that some PPP operation failed. - * - */ -static void -nm_ppp_dbus_signal_failure (NmPPPData *data, const char *sig) -{ - DBusMessage *message; - const char *error_msg = NULL; - - g_return_if_fail (data != NULL); - g_return_if_fail (sig != NULL); - - /* - if ( strcmp (signal, NM_DBUS_VPN_SIGNAL_LOGIN_FAILED) == 0 ) - error_msg = _("The VPN login failed because the user name and password were not accepted or the certificate password was wrong."); - else if (strcmp (signal, NM_DBUS_VPN_SIGNAL_LAUNCH_FAILED) == 0 ) - error_msg = _("The VPN login failed because the VPN program could not be started."); - else if (strcmp (signal, NM_DBUS_VPN_SIGNAL_CONNECT_FAILED) == 0 ) - error_msg = _("The VPN login failed because the VPN program could not connect to the VPN server."); - else if (strcmp (signal, NM_DBUS_VPN_SIGNAL_VPN_CONFIG_BAD) == 0 ) - error_msg = _("The VPN login failed because the VPN configuration options were invalid."); - else if (strcmp (signal, NM_DBUS_VPN_SIGNAL_IP_CONFIG_BAD) == 0 ) - error_msg = _("The VPN login failed because the VPN program received an invalid configuration from the VPN server."); - else - */ - error_msg = _("PPP connection failed"); - - if (!error_msg) - return; - - if (!(message = dbus_message_new_signal (NM_DBUS_PATH_PPP, NM_DBUS_INTERFACE_PPP, sig))) - { - nm_warning ("Not enough memory for new dbus message!"); - return; - } - - dbus_message_append_args (message, DBUS_TYPE_STRING, &error_msg, DBUS_TYPE_INVALID); - if (!dbus_connection_send (data->con, message, NULL)) - nm_warning ("Could not raise the signal!"); - - dbus_message_unref (message); -} - - -/* - * nm_ppp_dbus_signal_state_change - * - * Signal the bus that our state changed. - * - */ -static void -nm_ppp_dbus_signal_state_change (NmPPPData *data, NMPPPState old_state) -{ - DBusMessage *message; - - g_return_if_fail (data != NULL); - - if (!(message = dbus_message_new_signal (NM_DBUS_PATH_PPP, NM_DBUS_INTERFACE_PPP, NM_DBUS_PPP_SIGNAL_STATE_CHANGE))) - { - nm_warning ("nm_openppp_dbus_signal_state_change(): Not enough memory for new dbus message!"); - return; - } - - dbus_message_append_args (message, DBUS_TYPE_UINT32, &old_state, DBUS_TYPE_UINT32, &(data->state), DBUS_TYPE_INVALID); - - nm_info("nm_ppp_dbus_signal_state_change(): signaling state change %d -> %d", old_state, data->state); - - if (!dbus_connection_send (data->con, message, NULL)) - nm_warning ("nm_ppp_dbus_signal_state_change(): Could not raise the signal!"); - - dbus_message_unref (message); -} - - -/* - * nm_ppp_set_state - * - * Set our state and make sure to signal the bus. - * - */ -static void -nm_ppp_set_state (NmPPPData *data, NMPPPState new_state) -{ - NMPPPState old_state; - - g_return_if_fail (data != NULL); - - old_state = data->state; - - if (old_state != new_state) - { - data->state = new_state; - nm_ppp_dbus_signal_state_change (data, old_state); - } -} - - -/* - * nm_ppp_quit_timer_cb - * - * Callback to quit nm-ppp-service after a certain period of time. - * - */ -static gboolean -nm_ppp_quit_timer_cb (NmPPPData *data) -{ - data->quit_timer = 0; - - g_return_val_if_fail (data != NULL, FALSE); - - g_main_loop_quit (data->loop); - - return FALSE; -} - - -/* - * nm_ppp_schedule_quit_timer - * - * If ppp isn't running, and we haven't been asked to do anything in a while, - * then we just exit since NetworkManager will re-launch us later. - * - */ -static void -nm_ppp_schedule_quit_timer (NmPPPData *data, guint interval) -{ - g_return_if_fail (data != NULL); - - if (data->quit_timer == 0) - data->quit_timer = g_timeout_add (interval, (GSourceFunc) nm_ppp_quit_timer_cb, data); -} - - -/* - * nm_ppp_cancel_quit_timer - * - * Cancel a quit timer that we've scheduled before. - * - */ -static void -nm_ppp_cancel_quit_timer (NmPPPData *data) -{ - g_return_if_fail (data != NULL); - - if (data->quit_timer > 0) - g_source_remove (data->quit_timer); -} - - - - -/* - * nm_ppp_helper_timer_cb - * - * If we haven't received the IP4 config info from the helper before the timeout - * occurs, we kill ppp - * - */ -static gboolean -nm_ppp_helper_timer_cb (NmPPPData *data) -{ - data->helper_timer = 0; - - g_return_val_if_fail (data != NULL, FALSE); - - nm_ppp_dbus_signal_failure (data, NM_DBUS_PPP_SIGNAL_CONNECT_FAILED); - nm_warning("4"); - nm_ppp_dbus_handle_stop_pppd (data); - - return FALSE; -} - - -/* - * nm_ppp_schedule_helper_timer - * - * Once ppp is running, we wait for the helper to return the IP4 configuration - * information to us. If we don't receive that information within 7 seconds, - * we kill ppp - * - */ -static void -nm_ppp_schedule_helper_timer (NmPPPData *data) -{ - g_return_if_fail (data != NULL); - - if (data->helper_timer == 0) - data->helper_timer = g_timeout_add (50000, (GSourceFunc) nm_ppp_helper_timer_cb, data); -} - - -/* - * nm_ppp_cancel_helper_timer - * - * Cancel a helper timer that we've scheduled before. - * - */ -static void -nm_ppp_cancel_helper_timer (NmPPPData *data) -{ - g_return_if_fail (data != NULL); - - if (data->helper_timer > 0) - g_source_remove (data->helper_timer); -} - - - -/* - * ppp_watch_cb - * - * Watch our child ppp process and get notified of events from it. - * - */ -static void -ppp_watch_cb (GPid pid, gint status, gpointer user_data) -{ - guint error = -1; - - NmPPPData *data = (NmPPPData *)user_data; - - if (WIFEXITED (status)) - { - error = WEXITSTATUS (status); - if (error != 0) - nm_warning ("ppp exited with error code %d", error); - } - else if (WIFSTOPPED (status)) - nm_warning ("ppp stopped unexpectedly with signal %d", WSTOPSIG (status)); - else if (WIFSIGNALED (status)) - nm_warning ("ppp died with signal %d", WTERMSIG (status)); - else - nm_warning ("ppp died from an unknown cause"); - - /* Reap child if needed. */ - waitpid (data->pid, NULL, WNOHANG); - data->pid = 0; - - /* Must be after data->state is set since signals use data->state */ - /* This is still code from vpnc, ppp does not supply useful exit codes :-/ */ - switch (error) - { - case 2: /* Couldn't log in due to bad user/pass */ - nm_ppp_dbus_signal_failure (data, NM_DBUS_PPP_SIGNAL_LOGIN_FAILED); - break; - - case 1: /* Other error (couldn't bind to address, etc) */ - nm_ppp_dbus_signal_failure (data, NM_DBUS_PPP_SIGNAL_CONNECT_FAILED); - break; - - default: - break; - } - - nm_ppp_set_state (data, NM_PPP_STATE_STOPPED); - nm_ppp_schedule_quit_timer (data, 10000); -} - - - -/* - * write_config_option - * - * Helper that writes a formatted string to an fd - * - */ -static inline void -write_config_option (int fd, const char *format, ...) -{ - char * string; - va_list args; - int x; - - va_start (args, format); - string = g_strdup_vprintf (format, args); - printf("Writing config: %s", string); - x = write (fd, string, strlen (string)); - g_free (string); - va_end (args); -} - - -/* - * nm_ppp_start_pppd_binary - * - * Start the ppp binary with a set of arguments and a config file. - * - */ -static gint -nm_ppp_start_pppd_binary (NmPPPData *data, - char **data_items, const int num_items, - char **passwords, const int num_passwords - ) -{ - GPid pid; - const char *ppp_binary = NULL; - GError *error = NULL; - GSource *ppp_watch; - gint stdin_fd = -1; - gint stdout_fd = -1; - gint stderr_fd = -1; - int i = 0; - - char *username = NULL; - char *speed = NULL; - char *tty = NULL; - char *flowcontrol = NULL; - char *plugin = NULL; - char *number = NULL; - char *init_1 = NULL; - char *init_2 = NULL; - char *init_3 = NULL; - char *init_4 = NULL; - char *init_5 = NULL; - char *init_6 = NULL; - char *init_7 = NULL; - char *init_8 = NULL; - char *init_9 = NULL; - char *volume = "0"; - - g_return_val_if_fail (data != NULL, -1); - - data->pid = 0; - - if ( (num_items == 0) || (data_items == NULL) ) { - return -1; - } - - /* Find ppp, it's always needed */ - ppp_binary = nm_find_pppd(); - if (!ppp_binary) { - nm_info ("Could not find ppp binary."); - return -1; - } - - // Note that it should be guaranteed that num_items % 2 == 0 - // Parse parameters - for (i = 0; i < num_items; ++i) { - if ( (strcmp( data_items[i], "use-wvdial" ) == 0) && - (strcmp( data_items[++i], "yes" ) == 0) ) { - data->use_wvdial = TRUE; - } else if ( strcmp( data_items[i], "speed" ) == 0) { - speed = data_items[++i]; - } else if ( strcmp( data_items[i], "number" ) == 0) { - number = data_items[++i]; - } else if ( strcmp( data_items[i], "init_1" ) == 0) { - init_1 = data_items[++i]; - } else if ( strcmp( data_items[i], "init_2" ) == 0) { - init_2 = data_items[++i]; - } else if ( strcmp( data_items[i], "init_3" ) == 0) { - init_3 = data_items[++i]; - } else if ( strcmp( data_items[i], "init_4" ) == 0) { - init_4 = data_items[++i]; - } else if ( strcmp( data_items[i], "init_5" ) == 0) { - init_5 = data_items[++i]; - } else if ( strcmp( data_items[i], "init_6" ) == 0) { - init_6 = data_items[++i]; - } else if ( strcmp( data_items[i], "init_7" ) == 0) { - init_7 = data_items[++i]; - } else if ( strcmp( data_items[i], "init_8" ) == 0) { - init_8 = data_items[++i]; - } else if ( strcmp( data_items[i], "init_9" ) == 0) { - init_9 = data_items[++i]; - } else if ( strcmp( data_items[i], "ttyname" ) == 0) { - tty = data_items[++i]; - } else if ( strcmp( data_items[i], "volume" ) == 0) { - volume = data_items[++i]; - } else if ( strcmp( data_items[i], "flowcontrol" ) == 0) { - ++i; - if ( (strcmp( data_items[i], "crtscts" ) == 0) || - (strcmp( data_items[i], "xonxoff" ) == 0) ) { - flowcontrol = data_items[i]; - } - } else if ( strcmp( data_items[i], "plugin" ) == 0) { - plugin = data_items[++i]; - } else if ( strcmp( data_items[i], "username" ) == 0) { - username = data_items[++i]; - } - - - - /* - // Device, either tun or tap - g_ptr_array_add (ppp_argv, (gpointer) "--dev"); - if ( (dev != NULL) ) { - g_ptr_array_add (ppp_argv, (gpointer) dev); - } else { - // Versions prior to 0.3.0 didn't set this so we default for - // tun for these configs - g_ptr_array_add (ppp_argv, (gpointer) "tun"); - } - */ - } - - if ( data->use_wvdial ) { - GPtrArray *wvdial_argv = NULL; - - // Find wvdial, it's always needed - const char *wvdial_binary = nm_find_wvdial(); - if (!wvdial_binary) { - nm_info ("Could not find wvdial binary."); - return -1; - } - - wvdial_argv = g_ptr_array_new (); - - // create wvdial command line - g_ptr_array_add (wvdial_argv, (gpointer) (wvdial_binary)); - g_ptr_array_add (wvdial_argv, "--config-stdin"); - g_ptr_array_add (wvdial_argv, NULL); - - - if (!g_spawn_async_with_pipes (NULL, (char **) wvdial_argv->pdata, NULL, - G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, &stdin_fd, - &stdout_fd, &stderr_fd, &error)) { - - g_ptr_array_free (wvdial_argv, TRUE); - nm_warning ("ppp failed to start. error: '%s'", error->message); - g_error_free(error); - return -1; - } else { - - GString *fc = g_string_new( flowcontrol ); - fc = g_string_ascii_up( fc ); - - write_config_option (stdin_fd, "[Dialer Defaults]\n"); - write_config_option (stdin_fd, "Modem = %s\n", tty); - write_config_option (stdin_fd, "Baud = %s\n", speed); - write_config_option (stdin_fd, "SetVolume = %s\n", volume); - write_config_option (stdin_fd, "Dial Command = %s\n", "ATDT"); - write_config_option (stdin_fd, "Username = %s\n", username); - write_config_option (stdin_fd, "Password = %s\n", passwords[0]); - write_config_option (stdin_fd, "Phone = %s\n", number); - - if ( flowcontrol != NULL ) { - write_config_option (stdin_fd, "FlowControl = %s\n", fc->str); - } - if ( init_1 != NULL ) { - write_config_option (stdin_fd, "Init1 = %s\n", init_1); - } - if ( init_2 != NULL ) { - write_config_option (stdin_fd, "Init2 = %s\n", init_2); - } - if ( init_3 != NULL ) { - write_config_option (stdin_fd, "Init3 = %s\n", init_3); - } - if ( init_4 != NULL ) { - write_config_option (stdin_fd, "Init4 = %s\n", init_4); - } - if ( init_5 != NULL ) { - write_config_option (stdin_fd, "Init5 = %s\n", init_5); - } - if ( init_6 != NULL ) { - write_config_option (stdin_fd, "Init6 = %s\n", init_6); - } - if ( init_7 != NULL ) { - write_config_option (stdin_fd, "Init7 = %s\n", init_7); - } - if ( init_8 != NULL ) { - write_config_option (stdin_fd, "Init8 = %s\n", init_8); - } - if ( init_9 != NULL ) { - write_config_option (stdin_fd, "Init9 = %s\n", init_9); - } - - write_config_option (stdin_fd, "PPPD Option 1 = %s\n", "plugin"); - write_config_option (stdin_fd, "PPPD Option 2 = %s\n", "nm-pppd-plugin.so"); - - g_string_free( fc, TRUE ); - g_ptr_array_free (wvdial_argv, TRUE); - } - } else { - GPtrArray *ppp_argv; - - // Create pppd command line - - ppp_argv = g_ptr_array_new (); - g_ptr_array_add (ppp_argv, (gpointer) (ppp_binary)); - g_ptr_array_add (ppp_argv, NULL); - - if (!g_spawn_async_with_pipes (NULL, (char **) ppp_argv->pdata, NULL, - G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, &stdin_fd, - &stdout_fd, &stderr_fd, &error)) - { - g_ptr_array_free (ppp_argv, TRUE); - nm_warning ("ppp failed to start. error: '%s'", error->message); - g_error_free(error); - return -1; - } - g_ptr_array_free (ppp_argv, TRUE); - nm_info ("ppp started with pid %d", pid); - } - - data->pid = pid; - ppp_watch = g_child_watch_source_new (pid); - g_source_set_callback (ppp_watch, (GSourceFunc) ppp_watch_cb, data, NULL); - g_source_attach (ppp_watch, NULL); - g_source_unref (ppp_watch); - - { - NmPPP_IOData *io_data; - - io_data = g_new0 (NmPPP_IOData, 1); - io_data->child_stdin_fd = stdin_fd; - io_data->child_stdout_fd = stdout_fd; - io_data->child_stderr_fd = stderr_fd; - io_data->username = g_strdup(username); - io_data->password = g_strdup(passwords[0]); - - data->io_data = io_data; - } - - - nm_ppp_schedule_helper_timer (data); - - return stdin_fd; -} - - -typedef enum OptType -{ - OPT_TYPE_UNKNOWN = 0, - OPT_TYPE_ADDRESS, - OPT_TYPE_ASCII, - OPT_TYPE_INTEGER, - OPT_TYPE_NONE -} OptType; - -typedef struct Option -{ - const char *name; - OptType type; -} Option; - -/* - * nm_ppp_config_options_validate - * - * Make sure the config options are sane - * - */ -static gboolean -nm_ppp_config_options_validate (char **data_items, int num_items) -{ - Option allowed_opts[] = { - { "use-wvdial", OPT_TYPE_ASCII }, - { "speed", OPT_TYPE_INTEGER }, - { "lock", OPT_TYPE_ASCII }, - { "modem", OPT_TYPE_ASCII }, - { "crtscts", OPT_TYPE_ASCII }, - { "asyncmap", OPT_TYPE_ASCII }, - { "init_1", OPT_TYPE_ASCII }, - { "init_2", OPT_TYPE_ASCII }, - { "init_3", OPT_TYPE_ASCII }, - { "init_4", OPT_TYPE_ASCII }, - { "init_5", OPT_TYPE_ASCII }, - { "init_6", OPT_TYPE_ASCII }, - { "init_7", OPT_TYPE_ASCII }, - { "init_8", OPT_TYPE_ASCII }, - { "init_9", OPT_TYPE_ASCII }, - { "ttyname", OPT_TYPE_ASCII }, - { "username", OPT_TYPE_ASCII }, - { "volume", OPT_TYPE_ASCII }, - { "flowcontrol", OPT_TYPE_ASCII }, - { "number", OPT_TYPE_ASCII }, - { "plugin", OPT_TYPE_ASCII }, - { NULL, OPT_TYPE_UNKNOWN } }; - - unsigned int i; - - g_return_val_if_fail (data_items != NULL, FALSE); - g_return_val_if_fail (num_items >= 2, FALSE); - - /* Must be an even numbers of config options */ - if ((num_items % 2) != 0) { - nm_warning ("The number of PPP config options was not even."); - return FALSE; - } - - for (i = 0; i < num_items; i += 2) { - Option *opt = NULL; - unsigned int t, len; - char *opt_value; - - if (!data_items[i] || !data_items[i+1]) return FALSE; - opt_value = data_items[i+1]; - - /* Find the option in the allowed list */ - for (t = 0; t < sizeof (allowed_opts) / sizeof (Option); t++) - { - opt = &allowed_opts[t]; - if (opt->name && !strcmp (opt->name, data_items[i])) - break; - } - if (!opt->name) /* not found */ - { - nm_warning ("PPP option '%s' is not allowed.", data_items[i]); - return FALSE; - } - - /* Don't allow control characters at all */ - len = strlen (opt_value); - for (t = 0; t < len; t++) - { - if (iscntrl (opt_value[t])) - { - nm_warning ("There were invalid characters in the PPP option '%s' - '%s'.", data_items[i], opt_value); - return FALSE; - } - } - - /* Validate the option's data */ - switch (opt->type) - { - case OPT_TYPE_ASCII: - /* What other characters should we reject?? */ - break; - - case OPT_TYPE_NONE: - /* These have blank data */ - break; - - case OPT_TYPE_ADDRESS: - /* Can be any legal hostname or IP address */ - break; - - case OPT_TYPE_INTEGER: - break; - - default: - return FALSE; - break; - } - } - - return TRUE; -} - - -/* - * nm_ppp_dbus_handle_start_pppd - * - * Parse message arguments and start the VPN connection. - * - */ -static gboolean -nm_ppp_dbus_handle_start_pppd (DBusMessage *message, NmPPPData *data) -{ - char ** data_items = NULL; - int num_items = -1; - char ** password_items = NULL; - int num_passwords = -1; - DBusError error; - gboolean success = FALSE; - gint ppp_fd = -1; - - g_return_val_if_fail (message != NULL, FALSE); - g_return_val_if_fail (data != NULL, FALSE); - - nm_ppp_set_state (data, NM_PPP_STATE_STARTING); - - dbus_error_init (&error); - if (!dbus_message_get_args (message, &error, - DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &password_items, &num_passwords, - DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &data_items, &num_items, - DBUS_TYPE_INVALID)) - { - nm_warning ("Could not process the request because its arguments were invalid. dbus said: '%s'", error.message); - nm_ppp_dbus_signal_failure (data, NM_DBUS_PPP_SIGNAL_PPP_CONFIG_BAD); - dbus_error_free (&error); - goto out; - } - - if (!nm_ppp_config_options_validate (data_items, num_items)) - { - nm_ppp_dbus_signal_failure (data, NM_DBUS_PPP_SIGNAL_PPP_CONFIG_BAD); - goto out; - } - - /* Now we can finally try to activate the PPP */ if ((ppp_fd = nm_ppp_start_pppd_binary (data, data_items, num_items, password_items, num_passwords)) >= 0) { - // Everything ok - success = TRUE; - } - -out: - dbus_free_string_array (data_items); - dbus_free_string_array (password_items); - if (!success) - nm_ppp_set_state (data, NM_PPP_STATE_STOPPED); - return success; -} - - -/* - * nm_ppp_dbus_handle_stop_pppd - * - * Stop the running ppp dameon. - * - */ -static gboolean -nm_ppp_dbus_handle_stop_pppd (NmPPPData *data) -{ - g_return_val_if_fail (data != NULL, FALSE); - - if (data->pid > 0) - { - nm_ppp_set_state (data, NM_PPP_STATE_STOPPING); - - kill (data->pid, SIGINT); - nm_info ("Terminated ppp daemon with PID %d.", data->pid); - data->pid = 0; - - nm_ppp_set_state (data, NM_PPP_STATE_STOPPED); - nm_ppp_schedule_quit_timer (data, 10000); - } - - return TRUE; -} - - -/* - * nm_ppp_dbus_start_pppd - * - * Begin a PPP connection. - * - */ -static DBusMessage * -nm_ppp_dbus_start_pppd (DBusConnection *con, DBusMessage *message, NmPPPData *data) -{ - DBusMessage *reply = NULL; - - g_return_val_if_fail (data != NULL, NULL); - g_return_val_if_fail (con != NULL, NULL); - g_return_val_if_fail (message != NULL, NULL); - - switch (data->state) - { - case NM_PPP_STATE_STARTING: - reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE_PPP, NM_DBUS_PPP_STARTING_IN_PROGRESS, - "Could not process the request because the PPP connection is already being started."); - break; - - case NM_PPP_STATE_STARTED: - reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE_PPP, NM_DBUS_PPP_ALREADY_STARTED, - "Could not process the request because a PPP connection was already active."); - break; - - case NM_PPP_STATE_STOPPING: - reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE_PPP, NM_DBUS_PPP_STOPPING_IN_PROGRESS, - "Could not process the request because the PPP connection is being stopped."); - break; - - case NM_PPP_STATE_STOPPED: - nm_ppp_cancel_quit_timer (data); - nm_ppp_dbus_handle_start_pppd (message, data); - reply = dbus_message_new_method_return (message); - break; - - default: - g_assert_not_reached(); - break; - } - - return reply; -} - - -/* - * nm_ppp_dbus_stop_ppp - * - * Terminate a PPP connection. - * - */ -static DBusMessage * -nm_ppp_dbus_stop_pppd (DBusConnection *con, DBusMessage *message, NmPPPData *data) -{ - DBusMessage *reply = NULL; - - g_return_val_if_fail (data != NULL, NULL); - g_return_val_if_fail (con != NULL, NULL); - g_return_val_if_fail (message != NULL, NULL); - - switch (data->state) - { - case NM_PPP_STATE_STOPPING: - reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE_PPP, NM_DBUS_PPP_STOPPING_IN_PROGRESS, - "Could not process the request because the PPP connection is already being stopped."); - break; - - case NM_PPP_STATE_STOPPED: - reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE_PPP, NM_DBUS_PPP_ALREADY_STOPPED, - "Could not process the request because no PPP connection was active."); - break; - - case NM_PPP_STATE_STARTING: - case NM_PPP_STATE_STARTED: - nm_warning("5"); - nm_ppp_dbus_handle_stop_pppd (data); - reply = dbus_message_new_method_return (message); - break; - - default: - g_assert_not_reached(); - break; - } - - return reply; -} - - -/* - * nm_ppp_dbus_get_state - * - * Return some state information to NetworkManager. - * - */ -static DBusMessage * -nm_ppp_dbus_get_state (DBusConnection *con, DBusMessage *message, NmPPPData *data) -{ - DBusMessage *reply = NULL; - - g_return_val_if_fail (data != NULL, NULL); - g_return_val_if_fail (con != NULL, NULL); - g_return_val_if_fail (message != NULL, NULL); - - if ((reply = dbus_message_new_method_return (message))) - dbus_message_append_args (reply, DBUS_TYPE_UINT32, &(data->state), DBUS_TYPE_INVALID); - - return reply; -} - - -/* - * nm_ppp_dbus_process_helper_config_error - * - * Signal the bus that the helper could not get all the configuration information - * it needed. - * - */ -static void -nm_ppp_dbus_process_helper_config_error (DBusConnection *con, DBusMessage *message, NmPPPData *data) -{ - char *error_item; - - g_return_if_fail (data != NULL); - g_return_if_fail (con != NULL); - g_return_if_fail (message != NULL); - - /* Only accept the config info if we're in STARTING state */ - if (data->state != NM_PPP_STATE_STARTING) - return; - - if (dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &error_item, DBUS_TYPE_INVALID)) - { - nm_warning ("ppp helper did not receive adequate configuration information from ppp. It is missing '%s'.", error_item); - nm_ppp_dbus_signal_failure (data, NM_DBUS_PPP_SIGNAL_IP_CONFIG_BAD); - } - - nm_ppp_cancel_helper_timer (data); - nm_ppp_dbus_handle_stop_pppd (data); -} - - -/* - * nm_ppp_dbus_process_helper_ip4_config - * - * Signal the bus - * - */ -static void -nm_ppp_dbus_process_helper_ip4_config (DBusConnection *con, DBusMessage *message, NmPPPData *data) -{ - char * ifname; - guint32 ip4_gateway; - guint32 ip4_address; - guint32 ip4_ptpaddr; - guint32 ip4_netmask; - guint32 ip4_dns_1; - guint32 ip4_dns_2; - guint32 * ip4_dns; - guint32 ip4_dns_len; - guint32 ip4_nbns_1; - guint32 ip4_nbns_2; - guint32 * ip4_nbns; - guint32 ip4_nbns_len; - gboolean success = FALSE; - guint32 ip4_zero = 0; - - g_return_if_fail (data != NULL); - g_return_if_fail (con != NULL); - g_return_if_fail (message != NULL); - - /* Only accept the config info if we're in STARTING state */ - if (data->state != NM_PPP_STATE_STARTING) { - nm_warning ("IP4 config received while not in STARTING state"); - return; - } - - nm_ppp_cancel_helper_timer (data); - - nm_info ("Processing ip4 config message"); - - if (dbus_message_get_args(message, NULL, - DBUS_TYPE_STRING, &ifname, - DBUS_TYPE_UINT32, &ip4_address, - DBUS_TYPE_UINT32, &ip4_ptpaddr, - DBUS_TYPE_UINT32, &ip4_netmask, - DBUS_TYPE_UINT32, &ip4_dns_1, - DBUS_TYPE_UINT32, &ip4_dns_2, - DBUS_TYPE_UINT32, &ip4_nbns_1, - DBUS_TYPE_UINT32, &ip4_nbns_2, - DBUS_TYPE_INVALID)) { - - DBusMessage *sig; - - if (!(sig = dbus_message_new_signal (NM_DBUS_PATH_PPP, NM_DBUS_INTERFACE_PPP, NM_DBUS_PPP_SIGNAL_IP4_CONFIG))) { - nm_warning ("Not enough memory for new dbus message!"); - } else { - - GArray *ip4_dns_buf = g_array_new(TRUE, TRUE, sizeof(guint32)); - GArray *ip4_nbns_buf = g_array_new(TRUE, TRUE, sizeof(guint32)); - - guint32 *tmp; - - if ( ip4_dns_1 != 0 ) { - tmp = &ip4_dns_1; - g_array_append_val ( ip4_dns_buf, tmp ); - } - if ( ip4_dns_2 != 0 ) { - tmp = &ip4_dns_2; - g_array_append_val ( ip4_dns_buf, tmp ); - } - if ( ip4_dns_buf->len == 0 ) { - // we have to have a dummy at least - tmp = &ip4_zero; - g_array_append_val ( ip4_dns_buf, tmp ); - } - - if ( ip4_nbns_1 != 0 ) { - tmp = &ip4_nbns_1; - g_array_append_val ( ip4_nbns_buf, tmp ); - } - if ( ip4_nbns_2 != 0 ) { - tmp = &ip4_nbns_2; - g_array_append_val ( ip4_nbns_buf, tmp ); - } - if ( ip4_nbns_buf->len == 0 ) { - // we have to have a dummy at least - tmp = &ip4_zero; - g_array_append_val ( ip4_nbns_buf, tmp ); - } - - ip4_dns = (guint32 *)ip4_dns_buf->data; - ip4_nbns = (guint32 *)ip4_nbns_buf->data; - ip4_dns_len = ip4_dns_buf->len; - ip4_nbns_len = ip4_nbns_buf->len; - - dbus_message_append_args (sig, - DBUS_TYPE_STRING, &ifname, - DBUS_TYPE_UINT32, &ip4_gateway, - DBUS_TYPE_UINT32, &ip4_address, - DBUS_TYPE_UINT32, &ip4_ptpaddr, - DBUS_TYPE_UINT32, &ip4_netmask, - DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &ip4_dns, ip4_dns_len, - DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &ip4_nbns, ip4_nbns_len, - DBUS_TYPE_INVALID); - - nm_warning("Sending IP configuration"); - if (!dbus_connection_send (data->con, sig, NULL)) { - nm_warning ("Could not raise the "NM_DBUS_PPP_SIGNAL_IP4_CONFIG" signal!"); - goto out; - } - - dbus_message_unref (sig); - - g_array_free( ip4_dns_buf, FALSE ); - g_array_free( ip4_nbns_buf, FALSE ); - - nm_ppp_set_state (data, NM_PPP_STATE_STARTED); - success = TRUE; - } - } else { - nm_warning("Could not parse args for signalIP4Config"); - } - -out: - if (!success) - { - nm_warning ("Received invalid IP4 Config information from helper, terminating ppp."); - nm_warning("7"); - nm_ppp_dbus_handle_stop_pppd (data); - } -} - - -/* - * nm_ppp_dbus_get_auth_info - * - * Pass authentication information to the PPPD plugin. - * - */ -static DBusMessage * -nm_ppp_dbus_get_auth_info (DBusConnection *con, DBusMessage *message, NmPPPData *data) -{ - DBusMessage *reply = NULL; - - g_return_val_if_fail (data != NULL, NULL); - g_return_val_if_fail (con != NULL, NULL); - g_return_val_if_fail (message != NULL, NULL); - - if (data->io_data == NULL) { - nm_warning("Should never happen: program not started but it already requests config data"); - return NULL; - } - - if ( (data->io_data->username == NULL) || - (data->io_data->password == NULL) ) { - nm_warning("Should never happen: no user/pass credentials available"); - return NULL; - } - - if ((reply = dbus_message_new_method_return (message))) { - dbus_message_append_args (reply, - DBUS_TYPE_STRING, &(data->io_data->username), - DBUS_TYPE_STRING, &(data->io_data->password), - DBUS_TYPE_INVALID); - } else { - nm_info("Build of getAuthInfo reply failed "); - } - - return reply; -} - - - -/* - * nm_ppp_dbus_message_handler - * - * Handle requests for our services. - * - */ -static DBusHandlerResult -nm_ppp_dbus_message_handler (DBusConnection *con, DBusMessage *message, void *user_data) -{ - NmPPPData *data = (NmPPPData *)user_data; - const char *method; - const char *path; - DBusMessage *reply = NULL; - gboolean handled = TRUE; - - g_return_val_if_fail (data != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); - g_return_val_if_fail (con != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); - g_return_val_if_fail (message != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); - - method = dbus_message_get_member (message); - path = dbus_message_get_path (message); - - nm_info ("nm_ppp_dbus_message_handler() got method '%s' for path '%s'.", method, path); - - /* If we aren't ready to accept dbus messages, don't */ - if ((data->state == NM_PPP_STATE_INIT) || (data->state == NM_PPP_STATE_SHUTDOWN)) - { - nm_warning ("Received dbus messages but couldn't handle them due to INIT or SHUTDOWN states."); - reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE_PPP, NM_DBUS_PPP_WRONG_STATE, - "Could not process the request due to current state of STATE_INIT or STATE_SHUTDOWN."); - goto reply; - } - - if (strcmp ("startConnection", method) == 0) - reply = nm_ppp_dbus_start_pppd (con, message, data); - else if (strcmp ("stopConnection", method) == 0) - reply = nm_ppp_dbus_stop_pppd (con, message, data); - else if (strcmp ("getState", method) == 0) - reply = nm_ppp_dbus_get_state (con, message, data); - else if (strcmp ("signalConfigError", method) == 0) - nm_ppp_dbus_process_helper_config_error (con, message, data); - else if (strcmp ("signalIP4Config", method) == 0) - nm_ppp_dbus_process_helper_ip4_config (con, message, data); - else if (strcmp ("getAuthInfo", method) == 0) - reply = nm_ppp_dbus_get_auth_info (con, message, data); - else - handled = FALSE; - - reply: - if (reply) - { - dbus_connection_send (con, reply, NULL); - dbus_message_unref (reply); - } - - return (handled ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED); -} - - -/* - * nm_ppp_dbus_filter - * - * Handle signals from the bus, like NetworkManager network state - * signals. - * - */ -static DBusHandlerResult -nm_ppp_dbus_filter (DBusConnection *con, DBusMessage *message, void *user_data) -{ - NmPPPData *data = (NmPPPData *)user_data; - gboolean handled = FALSE; - DBusError error; - - g_return_val_if_fail (data != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); - g_return_val_if_fail (con != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); - g_return_val_if_fail (message != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); - - if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) { - char *service; - char *old_owner; - char *new_owner; - - dbus_error_init (&error); - if ( dbus_message_get_args (message, &error, - DBUS_TYPE_STRING, &service, - DBUS_TYPE_STRING, &old_owner, - DBUS_TYPE_STRING, &new_owner, - DBUS_TYPE_INVALID)) - { - gboolean old_owner_good = (old_owner && (strlen (old_owner) > 0)); - gboolean new_owner_good = (new_owner && (strlen (new_owner) > 0)); - - if ((!old_owner_good && new_owner_good) && (strcmp (service, NM_DBUS_SERVICE) == 0)) /* Equivalent to old ServiceCreated signal */ - { - } - else if ((old_owner_good && !new_owner_good) && (strcmp (service, NM_DBUS_SERVICE) == 0)) /* Equivalent to old ServiceDeleted signal */ - { - /* If NM goes away, we don't stick around */ - nm_warning("1"); - nm_ppp_dbus_handle_stop_pppd (data); - g_main_loop_quit (data->loop); - } - } - } else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceNoLongerActive")) - { - /* If the active device goes down our PPP is certainly not going to work. */ - nm_warning("2"); - nm_ppp_dbus_handle_stop_pppd (data); - } - - return (handled ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED); -} - - -/* - * nm_ppp_dbus_init - * - * Grab our connection to the system bus, return NULL if anything goes wrong. - * - */ -static DBusConnection * -nm_ppp_dbus_init (NmPPPData *data) -{ - DBusConnection *connection = NULL; - DBusError error; - DBusObjectPathVTable vtable = { NULL, &nm_ppp_dbus_message_handler, NULL, NULL, NULL, NULL }; - - g_return_val_if_fail (data != NULL, NULL); - - dbus_error_init (&error); - if (!(connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error))) - { - nm_warning ("Error connecting to system bus: '%s'", error.message); - goto out; - } - - dbus_connection_setup_with_g_main (connection, NULL); - - dbus_error_init (&error); - dbus_bus_request_name (connection, NM_DBUS_SERVICE_PPP, 0, &error); - if (dbus_error_is_set (&error)) - { - nm_warning ("Could not acquire the dbus service. dbus_bus_request_name() says: '%s'", error.message); - goto out; - } - - if (!dbus_connection_register_object_path (connection, NM_DBUS_PATH_PPP, &vtable, data)) - { - nm_warning ("Could not register a dbus handler for nm-ppp-service. Not enough memory?"); - return NULL; - } - - if (!dbus_connection_add_filter (connection, nm_ppp_dbus_filter, data, NULL)) - return NULL; - - dbus_error_init (&error); - dbus_bus_add_match (connection, - "type='signal'," - "interface='" NM_DBUS_INTERFACE "'," - "sender='" NM_DBUS_SERVICE "'," - "path='" NM_DBUS_PATH "'", - &error); - if (dbus_error_is_set (&error)) - goto out; - - dbus_bus_add_match (connection, - "type='signal'," - "interface='" DBUS_INTERFACE_DBUS "'," - "sender='" DBUS_SERVICE_DBUS "'", - &error); - if (dbus_error_is_set (&error)) - goto out; - -out: - if (dbus_error_is_set (&error)) - { - dbus_error_free (&error); - connection = NULL; - } - return connection; -} - - - -NmPPPData *ppp_data = NULL; - -static void -sigterm_handler (int signum) -{ - nm_info ("nm-ppp-service caught SIGINT/SIGTERM"); - - g_main_loop_quit (ppp_data->loop); -} - - -/* - * main - * - */ -int -main( int argc, char *argv[] ) -{ - struct sigaction action; - sigset_t block_mask; - - g_type_init (); - if (!g_thread_supported ()) - g_thread_init (NULL); - - ppp_data = g_malloc0 (sizeof (NmPPPData)); - ppp_data->state = NM_PPP_STATE_INIT; - ppp_data->loop = g_main_loop_new (NULL, FALSE); - - if (!(ppp_data->con = nm_ppp_dbus_init (ppp_data))) - exit (EXIT_FAILURE); - - action.sa_handler = sigterm_handler; - sigemptyset (&block_mask); - action.sa_mask = block_mask; - action.sa_flags = 0; - sigaction (SIGINT, &action, NULL); - sigaction (SIGTERM, &action, NULL); - - nm_ppp_set_state (ppp_data, NM_PPP_STATE_STOPPED); - g_main_loop_run (ppp_data->loop); - - nm_ppp_dbus_handle_stop_pppd (ppp_data); - - g_main_loop_unref (ppp_data->loop); - g_free (ppp_data); - - exit (EXIT_SUCCESS); -} diff --git a/src/ppp-manager/nm-ppp-service.h b/src/ppp-manager/nm-ppp-service.h deleted file mode 100644 index 2e12af13cc..0000000000 --- a/src/ppp-manager/nm-ppp-service.h +++ /dev/null @@ -1,32 +0,0 @@ -/* nm-ppp-supervisor - ppp supervisor - * - * Tim Niemueller <tim@niemueller.de> - * Based on work by Dan Williams <dcbw@redhat.com> - * - * 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 2 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef NM_PPP_SERVICE_H -#define NM_PPP_SERVICE_H - -#include "nm-ppp.h" - -#define NM_DBUS_SERVICE_PPP "org.freedesktop.NetworkManager.ppp" -#define NM_DBUS_INTERFACE_PPP "org.freedesktop.NetworkManager.ppp" -#define NM_DBUS_PATH_PPP "/org/freedesktop/NetworkManager/ppp" - - -#endif diff --git a/src/ppp-manager/nm-ppp.conf b/src/ppp-manager/nm-ppp.conf deleted file mode 100644 index 8dc8c3aa16..0000000000 --- a/src/ppp-manager/nm-ppp.conf +++ /dev/null @@ -1,20 +0,0 @@ -<!DOCTYPE busconfig PUBLIC - "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" - "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> -<busconfig> - <policy user="root"> - <allow own="org.freedesktop.NetworkManager.ppp"/> - <allow send_destination="org.freedesktop.NetworkManager.ppp"/> - <allow send_interface="org.freedesktop.NetworkManager.ppp"/> - </policy> - <policy at_console="true"> - <allow send_destination="org.freedesktop.NetworkManager.ppp"/> - <allow send_interface="org.freedesktop.NetworkManager.ppp"/> - </policy> - <policy context="default"> - <deny own="org.freedesktop.NetworkManager.ppp"/> - <deny send_destination="org.freedesktop.NetworkManager.ppp"/> - <deny send_interface="org.freedesktop.NetworkManager.ppp"/> - </policy> -</busconfig> - diff --git a/src/ppp-manager/nm-ppp.h b/src/ppp-manager/nm-ppp.h deleted file mode 100644 index 121ec0ac75..0000000000 --- a/src/ppp-manager/nm-ppp.h +++ /dev/null @@ -1,74 +0,0 @@ -/* nm-ppp.h -- PPP connections - * - * Tim Niemueller [www.niemueller.de] - * - * 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 2 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2006 Tim Niemueller - */ - -#ifndef NETWORK_MANAGER_PPP_H -#define NETWORK_MANAGER_PPP_H - -/* - * PPP supervisor signals - */ -#define NM_DBUS_PPP_STARTING_IN_PROGRESS "StartingInProgress" -#define NM_DBUS_PPP_ALREADY_STARTED "AlreadyStarted" -#define NM_DBUS_PPP_STOPPING_IN_PROGRESS "StoppingInProgress" -#define NM_DBUS_PPP_ALREADY_STOPPED "AlreadyStopped" -#define NM_DBUS_PPP_WRONG_STATE "WrongState" -#define NM_DBUS_PPP_BAD_ARGUMENTS "BadArguments" - -#define NM_DBUS_PPP_SIGNAL_LOGIN_FAILED "LoginFailed" -#define NM_DBUS_PPP_SIGNAL_LAUNCH_FAILED "LaunchFailed" -#define NM_DBUS_PPP_SIGNAL_CONNECT_FAILED "ConnectFailed" -#define NM_DBUS_PPP_SIGNAL_PPP_CONFIG_BAD "PPPConfigBad" -#define NM_DBUS_PPP_SIGNAL_IP_CONFIG_BAD "IPConfigBad" -#define NM_DBUS_PPP_SIGNAL_STATE_CHANGE "StateChange" -#define NM_DBUS_PPP_SIGNAL_IP4_CONFIG "IP4Config" - - -/* - * PPP connection states - */ -typedef enum NMPPPState -{ - NM_PPP_STATE_UNKNOWN = 0, - NM_PPP_STATE_INIT, - NM_PPP_STATE_SHUTDOWN, - NM_PPP_STATE_STARTING, - NM_PPP_STATE_STARTED, - NM_PPP_STATE_STOPPING, - NM_PPP_STATE_STOPPED -} NMPPPState; - - -/* - * PPP connection activation stages - */ -typedef enum NMPPPActStage -{ - NM_PPP_ACT_STAGE_UNKNOWN = 0, - NM_PPP_ACT_STAGE_DISCONNECTED, - NM_PPP_ACT_STAGE_PREPARE, - NM_PPP_ACT_STAGE_CONNECT, - NM_PPP_ACT_STAGE_IP_CONFIG_GET, - NM_PPP_ACT_STAGE_ACTIVATED, - NM_PPP_ACT_STAGE_FAILED, - NM_PPP_ACT_STAGE_CANCELED -} NMPPPActStage; - -#endif diff --git a/src/ppp-manager/nm-pppd-plugin.c b/src/ppp-manager/nm-pppd-plugin.c deleted file mode 100644 index 6e39ed33f4..0000000000 --- a/src/ppp-manager/nm-pppd-plugin.c +++ /dev/null @@ -1,568 +0,0 @@ -/* nm-pptp-service - pptp (and other pppd) integration with NetworkManager - * - * (C) 2005-2006 Antony J Mee <eemynotna at gmail dot com> - * (C) 2006 Tim Niemueller <tim@niemueller.de> - * - * 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 2 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ -#include <pppd/pppd.h> - -#include <pppd/fsm.h> -#include <pppd/ipcp.h> - -#include <sys/types.h> -#include <unistd.h> -#include <glib.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <regex.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <dbus/dbus.h> -#include <dbus/dbus-glib-lowlevel.h> -#include <dbus/dbus-glib.h> -#include <NetworkManager/NetworkManager.h> - -#include "nm-ppp-service.h" -#include "nm-ppp.h" -#include "nm-pppd-plugin.h" - -typedef struct NmPPPData -{ - DBusConnection *con; - gboolean got_auth_info; - char *username; - char *password; - int pppd_pid; -} NmPPPData; - -char pppd_version[] = VERSION; - -NmPPPData plugin_data; - -void nm_ip_up(void *opaque, int arg); -void nm_ip_down(void *opaque, int arg); -void nm_exit_notify(void *opaque, int arg); - -int nm_chap_passwd_hook(char *username, char *password); -int nm_chap_check_hook(void); - -int nm_pap_passwd_hook(char *username, char *passwordd); -int nm_pap_check_hook(void); - -void nm_notify_pid (NmPPPData *data); -void send_config_error (DBusConnection *con, const char *item); -gboolean nm_get_auth_items (NmPPPData *data); -gboolean nm_store_auth_info (NmPPPData *data, char *username, char *password); -gboolean nm_dbus_prepare_connection(NmPPPData *data); -DBusHandlerResult nm_dbus_message_handler (DBusConnection *con, DBusMessage *message, void *user_data); -void nm_dbus_kill_connection(NmPPPData *data); - -// void is needed to avoid "no previous prototype" warning/error -int plugin_init(void); - -gboolean -nm_dbus_prepare_connection(NmPPPData *data) -{ - //DBusMessage * message = NULL; - DBusError err; - //DBusObjectPathVTable vtable = { NULL, - // &nm_dbus_message_handler, - // NULL, NULL, NULL, NULL }; - - g_return_val_if_fail (data != NULL, FALSE); - if (data->con != NULL) return TRUE; - - - dbus_error_init (&err); - data->con = dbus_bus_get (DBUS_BUS_SYSTEM, &err); - if ((data->con == NULL) || dbus_error_is_set (&err)) - { - info("Could not get the system bus. Make sure the message bus daemon is running?"); - goto out; - } - dbus_connection_set_exit_on_disconnect (data->con, FALSE); - -// dbus_error_init (&err); -// dbus_bus_request_name (data->con, NM_DBUS_SERVICE_PPP, 0, &err); -// if (dbus_error_is_set (&err)) -// { -// nm_warning ("Could not acquire the dbus service. dbus_bus_request_name() says: '%s'", error.message); -// goto out; -// } - -// if (!dbus_connection_register_object_path (data->con, NM_DBUS_PATH_PPP, &vtable, data)) -// { -// nm_warning ("Could not register a dbus handler for nm-ppp-service. Not enough memory?"); -// dbus_connection_unref(data->con); -// data->con = NULL; -// } -out: - if (dbus_error_is_set (&err)) - { - dbus_error_free (&err); - data->con = NULL; - } - if (data->con == NULL) return FALSE; - return TRUE; -} - -void nm_dbus_kill_connection(NmPPPData *data) -{ - g_return_if_fail (data != NULL); - - if (data->con != NULL) - dbus_connection_unref(data->con); - if (data->username!=NULL) g_free(data->username); - if (data->password!=NULL) g_free(data->password); -} - -/* - * nm_dbus_message_handler - * - * Handle requests for our services. - * - */ -DBusHandlerResult -nm_dbus_message_handler (DBusConnection *con, DBusMessage *message, void *user_data) -{ - NmPPPData *data = (NmPPPData *)user_data; - const char *method; - const char *path; - DBusMessage *reply = NULL; - gboolean handled = TRUE; - - g_return_val_if_fail (data != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); - g_return_val_if_fail (con != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); - g_return_val_if_fail (message != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); - - method = dbus_message_get_member (message); - path = dbus_message_get_path (message); - - info ("nm_dbus_message_handler() got method '%s' for path '%s'.", method, path); - - handled = FALSE; - - if (reply) { - dbus_connection_send (con, reply, NULL); - dbus_message_unref (reply); - } - - return (handled ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED); -} - - -int -nm_chap_check_hook(void) -{ - plugin_data.pppd_pid=getpid(); - nm_notify_pid (&plugin_data); - - if (! nm_get_auth_items (&plugin_data)) { - return 0; - } - - // for now we do no authenticate the peer - return 0; -} - -int -nm_chap_passwd_hook(char *username, char *password) -{ - info("nm-pppd-plugin: CHAP credentials requested."); - - if (username == NULL) { - info("nm-pppd-plugin: pppd didn't provide username buffer"); - return -1; - } - - if (password == NULL) { - info("nm-pppd-plugin: pppd didn't provide password buffer"); - return -1; - } - - if (plugin_data.username == NULL) { - info("nm-pppd-plugin: CHAP username not set"); - return -1; - } - - if (plugin_data.password == NULL) { - info("nm-pppd-plugin: CHAP password not set"); - return -1; - } - - if (strlen(plugin_data.username) >= MAXNAMELEN) { - info("nm-pppd-plugin: CHAP username too long!"); - return -1; - } - - if (strlen(plugin_data.password) >= MAXSECRETLEN) { - info("nm-pppd-plugin: CHAP password too long!"); - return -1; - } - - strncpy(username, plugin_data.username, MAXNAMELEN); - username[MAXNAMELEN-1]='\0'; - strncpy(password, plugin_data.password, MAXSECRETLEN); - password[MAXSECRETLEN-1]='\0'; - - return 0; -} - - -int -nm_pap_check_hook(void) -{ - plugin_data.pppd_pid=getpid(); - nm_notify_pid (&plugin_data); - - if (! nm_get_auth_items (&plugin_data)) { - return 0; - } - - // for now we do authenticate the peer - return 0; -} - -int -nm_pap_passwd_hook(char *username, char *password) -{ - info("nm-pppd-plugin: PAP credentials requested."); - - if (username == NULL) { - info("nm-pppd-plugin: pppd didn't provide username buffer"); - return -1; - } - - if (password == NULL) { - info("nm-pppd-plugin: pppd didn't provide password buffer"); - return 1; - } - - if (plugin_data.username == NULL) { - info("nm-pppd-plugin: PAP username not set"); - return 0; - } - - if (plugin_data.password == NULL) { - info("nm-pppd-plugin: PAP password not set"); - return 0; - } - - if (strlen(plugin_data.username) >= MAXNAMELEN) { - info("nm-pppd-plugin: PAP username too long!"); - return 0; - } - - if (strlen(plugin_data.password) >= MAXSECRETLEN) { - info("nm-pppd-plugin: PAP password too long!"); - return 0; - } - - strncpy(username, plugin_data.username, MAXNAMELEN); - username[MAXNAMELEN-1]='\0'; - strncpy(password, plugin_data.password, MAXSECRETLEN); - password[MAXSECRETLEN-1]='\0'; - - return 1; -} - - -void -nm_exit_notify(void *opaque, int arg) -{ - NmPPPData *data = (NmPPPData *)opaque; - - nm_dbus_kill_connection(data); -} - -void -nm_ip_down(void *opaque, int arg) -{ - // DBusConnection *con = (DBusConnection *)opaque; - return; -} - -void -nm_ip_up(void *opaque, int arg) -{ - NmPPPData *data = (NmPPPData *)opaque; - DBusConnection *con = data->con; - DBusMessage *message; - - char * ppp_ifname = NULL; - guint32 ip4_dns_1 = 0; - guint32 ip4_dns_2 = 0; - guint32 ip4_wins_1 = 0; - guint32 ip4_wins_2 = 0; - guint32 ip4_address = 0; - guint32 ip4_ptp_address = 0; - guint32 ip4_netmask = 0xFFFFFFFF; /* Default mask of 255.255.255.255 */ - - - g_return_if_fail (con != NULL); - if (!nm_dbus_prepare_connection(data)) return; - - if (ipcp_gotoptions[ifunit].ouraddr==0) { - info ("nm-pppd-plugin: didn't receive an Internal IP4 Address from ppp."); - send_config_error (con, "IP4 Address"); - return; - } - ip4_address=ipcp_gotoptions[ifunit].ouraddr; - - if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE_PPP, - NM_DBUS_PATH_PPP, - NM_DBUS_INTERFACE_PPP, - "signalIP4Config"))) - { - info ("nm-pppd-plugin::nm_ip_up(): Couldn't allocate the dbus message"); - return; - } - - - if (ipcp_gotoptions[ifunit].dnsaddr[0] != 0) { - ip4_dns_1 = ipcp_gotoptions[ifunit].dnsaddr[0]; - } - if (ipcp_gotoptions[ifunit].dnsaddr[1] != 0) { - ip4_dns_2 = ipcp_gotoptions[ifunit].dnsaddr[1]; - } - - if (ipcp_gotoptions[ifunit].winsaddr[0] != 0) { - ip4_wins_1 = ipcp_gotoptions[ifunit].winsaddr[0]; - } - if (ipcp_gotoptions[ifunit].winsaddr[1] != 0) { - ip4_wins_2 = ipcp_gotoptions[ifunit].winsaddr[1]; - } - - - - if (ifname == NULL) { - info ("nm-pppd-plugin: didn't receive a tunnel device name."); - send_config_error (con, "IP4 Address"); - goto out; - } - ppp_ifname = g_strdup(ifname); - - info("nm-pppd-plugin: sending ip4 config information"); - - if (! dbus_message_append_args (message, - DBUS_TYPE_STRING, &ppp_ifname, - DBUS_TYPE_UINT32, &ip4_address, - DBUS_TYPE_UINT32, &ip4_ptp_address, - DBUS_TYPE_UINT32, &ip4_netmask, - DBUS_TYPE_UINT32, &ip4_dns_1, - DBUS_TYPE_UINT32, &ip4_dns_2, - DBUS_TYPE_UINT32, &ip4_wins_1, - DBUS_TYPE_UINT32, &ip4_wins_2, - DBUS_TYPE_INVALID)) { - info("nm-pppd-plugin::nm_ip_up(): could not append message args"); - goto out; - } - - if (!dbus_connection_send (con, message, NULL)) { - info ("nm-pppd-plugin::nm_ip_up(): could not send dbus message"); - goto out; - } else { - info ("nm-pppd-plugin::nm_ip_up(): successfully sent dbus message"); - } - - out: - g_free(ppp_ifname); - dbus_message_unref (message); - return; -} - - -/* - * send_config_error - * - * Notify nm-ppp-starter of a config error from pppd. - * -*/ -void -send_config_error (DBusConnection *con, const char *item) -{ - DBusMessage *message; - - g_return_if_fail (con != NULL); - g_return_if_fail (item != NULL); - - if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE_PPP, - NM_DBUS_PATH_PPP, - NM_DBUS_INTERFACE_PPP, - "signalConfigError"))) - { - info ("send_config_error(): Couldn't allocate the dbus message"); - return; - } - - dbus_message_append_args (message, DBUS_TYPE_STRING, &item, DBUS_TYPE_INVALID); - if (!dbus_connection_send (con, message, NULL)) - info ("send_config_error(): could not send dbus message"); - - dbus_message_unref (message); -} - - -/* - * nm_notify_pid - * - * Let the pppd starter service know our PID - * so that pppd may be killed later. - * - */ -void -nm_notify_pid (NmPPPData *data) -{ - DBusConnection *con; - DBusMessage *message = NULL; - - if (!nm_dbus_prepare_connection(data)) - return; - - con = data->con; - if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE_PPP, - NM_DBUS_PATH_PPP, - NM_DBUS_INTERFACE_PPP, - "notifyPID"))) - { - info ("nm-pppd-plugin: Couldn't allocate the notifyPID dbus message"); - return; - } - - dbus_message_append_args (message, - DBUS_TYPE_UINT32, &(data->pppd_pid), - DBUS_TYPE_INVALID); - - if ( ! dbus_connection_send (con, message, NULL)) { - info ("nm-pppd-plugin::nm_notify_pid(): could not send dbus message"); - } else { - // info("Sent notify message: %d",data->pppd_pid); - } - - dbus_message_unref (message); -} - - -/* - * nm_get_auth_items - * - * Request credentials from PPP service. - * - */ -gboolean -nm_get_auth_items (NmPPPData *data) -{ - if ( data->got_auth_info ) { - return TRUE; - } else { - DBusConnection *con; - DBusMessage *message = NULL; - DBusMessage *reply = NULL; - - gchar *username = NULL; - gchar *password = NULL; - - if (!nm_dbus_prepare_connection(data)) - return FALSE; - - con = data->con; - - g_return_val_if_fail (con != NULL,FALSE); - if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE_PPP, - NM_DBUS_PATH_PPP, - NM_DBUS_INTERFACE_PPP, - "getAuthInfo"))) - { - info("nm-pppd-plugin: failed to create getAuthInfo message."); - return FALSE; - } - - reply = dbus_connection_send_with_reply_and_block (con, message, -1, NULL); - dbus_message_unref (message); - if (!reply) - { - info("nm-pppd-plugin: no reply to getAuthInfo message."); - return FALSE; - } - - if (!(dbus_message_get_args (reply, NULL, - DBUS_TYPE_STRING, &username, - DBUS_TYPE_STRING, &password, - DBUS_TYPE_INVALID))) - { - dbus_message_unref (reply); - return FALSE; - } - - - - if (!nm_store_auth_info (data, username, password)) - { - dbus_message_unref (reply); - return FALSE; - } - - dbus_message_unref (reply); - return TRUE; - } -} - -/* - * nm_store_auth_info - * - * Decode and temporarily store the authentication info provided. - * - */ -gboolean -nm_store_auth_info (NmPPPData *data, char *username, char *password) -{ - - g_return_val_if_fail (username != NULL, FALSE); - g_return_val_if_fail (password != NULL, FALSE); - - if (data->username!=NULL) g_free(data->username); - if (data->password!=NULL) g_free(data->password); - data->username=g_strdup(username); - data->password=g_strdup(password); - - data->got_auth_info=TRUE; - - return TRUE; -} - -int -plugin_init() -{ - memset(&plugin_data, 0, sizeof(plugin_data)); - nm_dbus_prepare_connection( &plugin_data ); - - chap_check_hook = nm_chap_check_hook; - chap_passwd_hook = nm_chap_passwd_hook; - - pap_check_hook = nm_pap_check_hook; - pap_passwd_hook = nm_pap_passwd_hook; - - add_notifier(&ip_down_notifier, nm_ip_down, (void *) &plugin_data); - add_notifier(&ip_up_notifier, nm_ip_up, (void *) &plugin_data); - add_notifier(&exitnotify, nm_exit_notify, (void *) &plugin_data); - - info("nm-pppd-plugin: plugin initialized."); - return 0; -} - diff --git a/src/ppp-manager/nm-pppd-plugin.h b/src/ppp-manager/nm-pppd-plugin.h deleted file mode 100644 index fb084e2ec1..0000000000 --- a/src/ppp-manager/nm-pppd-plugin.h +++ /dev/null @@ -1,31 +0,0 @@ -/* nm-ppp-starter - pptp (and other ppp) integration with NetworkManager - * - * (C) 2005-2006 by Antony J Mee <eemynotna at gmail dot com> - * (C) 2006 Tim Niemueller <tim@niemueller.de> - * Based on openvpn work by Tim Niemueller <tim@niemueller.de> - * and Dan Williams <dcbw@redhat.com> - * - * 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 2 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef NM_PPPD_PLUGIN_H -#define NM_PPPD_PLUGIN_H - -#define NM_DBUS_SERVICE_PPPD "org.freedesktop.NetworkManager.pppd" -#define NM_DBUS_INTERFACE_PPPD "org.freedesktop.NetworkManager.pppd" -#define NM_DBUS_PATH_PPPD "/org/freedesktop/NetworkManager/pppd" - -#endif diff --git a/src/vpn-manager/nm-dbus-vpn.c b/src/vpn-manager/nm-dbus-vpn.c index 95796ab07b..989e4a1057 100644 --- a/src/vpn-manager/nm-dbus-vpn.c +++ b/src/vpn-manager/nm-dbus-vpn.c @@ -660,8 +660,10 @@ static DBusMessage *nm_dbus_vpn_get_vpn_connection_properties (DBusConnection *c if (req && (nm_vpn_act_request_get_connection (req) == vpn)) stage = nm_vpn_act_request_get_stage (req); - dbus_message_append_args (reply, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &user_name, - DBUS_TYPE_STRING, &service_name, DBUS_TYPE_UINT32, &stage, DBUS_TYPE_INVALID); + dbus_message_append_args (reply, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_STRING, &user_name, + DBUS_TYPE_STRING, &service_name, DBUS_TYPE_UINT32, &stage, DBUS_TYPE_INVALID); good = TRUE; } } |