* DBUS revamp is complete possible to have various

authentication methods, ptys etc.
  * version bumped to 0.6.9 to bring closer in line with NM
  * nm-pptp-service-pppd-plugin.c -> nm-pppd-plugin.c:
    The pppd plugin has now been generalised to work with
    any ppp protocol. (Options do not exist in the config
    dialog yet however)
  * src/Makefile.am: fixed to install pppd plugin correctly
    (unsure about -fPIC usage!)


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1790 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Antony Mee 2006-06-02 07:10:01 +00:00
parent 8e193af7d6
commit 771b93a674
10 changed files with 669 additions and 276 deletions

View file

@ -1,5 +1,4 @@
Antony Mee <A.J.Mee@ncl.ac.uk>
Antony Mee <eemynotna@gmail.com>
Tim Niemueller <tim@niemueller.de>
Dan Williams <dcbw@redhat.com>
David Zeuthen <davidz@redhat.com>

View file

@ -1,3 +1,15 @@
2006-06-01 Antony Mee <eemynotna@gmail.com>
* DBUS revamp is complete possible to have various
authentication methods, ptys etc.
* version bumped to 0.6.9 to bring closer in line with NM
* nm-pptp-service-pppd-plugin.c -> nm-pppd-plugin.c:
The pppd plugin has now been generalised to work with
any ppp protocol. (Options do not exist in the config
dialog yet however)
* src/Makefile.am: fixed to install pppd plugin correctly
(unsure about -fPIC usage!)
2006-04-23 Dan Williams <dcbw@redhat.com>
Patch from j@bootlab.org
@ -14,7 +26,7 @@
searching (and finding) install-sh in ../.., which lead to
problems.
2005-11-17 Antony Mee <A.J.Mee@ncl.ac.uk>
2005-11-17 Antony Mee <eemynotna@gmail.com>
* started work based on openvpn work

View file

@ -73,6 +73,8 @@ lookup_pass (const char *vpn_name, const char *vpn_service, gboolean *is_session
}
if (password != NULL && username != NULL) {
// Statically set the authentication type for now.
passwords = g_slist_append (passwords, g_strdup("CHAP"));
passwords = g_slist_append (passwords, g_strdup (username));
passwords = g_slist_append (passwords, g_strdup (password));
if (strcmp (data1->keyring, "session") == 0)
@ -195,6 +197,8 @@ get_passwords (const char *vpn_name, const char *vpn_service, gboolean retry)
username = gnome_two_password_dialog_get_username (GNOME_TWO_PASSWORD_DIALOG (dialog));
password = gnome_two_password_dialog_get_password (GNOME_TWO_PASSWORD_DIALOG (dialog));
// Statically set the authentication type for now.
result = g_slist_append (result, g_strdup("CHAP"));
result = g_slist_append (result, username);
result = g_slist_append (result, password);

View file

@ -1,6 +1,6 @@
AC_PREREQ(2.52)
AC_INIT(NetworkManager-pptp, 0.1.0, A.J.Mee@ncl.ac.uk, NetworkManager-pptp)
AC_INIT(NetworkManager-pptp, 0.6.9, eemynotna@gmail.com, NetworkManager-pptp)
AC_CONFIG_AUX_DIR(.)
AM_INIT_AUTOMAKE([subdir-objects])
AM_MAINTAINER_MODE

View file

@ -3,7 +3,7 @@
*
* nm-pptp.c : GNOME UI dialogs for configuring PPTP connections
*
* Copyright (C) 2005 Antony Mee <A.J.Mee@ncl.ac.uk>
* Copyright (C) 2005 Antony Mee <eemynotna@gmail.com>
* Based on work by Tim Niemueller <tim@niemueller.de>
* and David Zeuthen, <davidz@redhat.com>
*

View file

@ -13,9 +13,13 @@ AM_CPPFLAGS = \
-DLIBDIR=\""$(libdir)"\" \
-DLIBEXECDIR=\""$(libexecdir)"\" \
-DLOCALSTATEDIR=\""$(localstatedir)"\" \
-DDATADIR=\"$(datadir)\"
-DDATADIR=\"$(datadir)\" \
-fPIC
bin_PROGRAMS = nm-pptp-service nm-pptp-service-pppd-plugin.so
bin_PROGRAMS = nm-pptp-service
pppdplugindir = $(libdir)/pppd/2.4.3
pppdplugin_PROGRAMS = nm-pppd-plugin.so
nm_pptp_service_SOURCES = \
nm-pptp-service.c \
@ -33,13 +37,13 @@ nm_pptp_service_LDADD = \
$(GTHREAD_LIBS)
nm_pptp_service_pppd_plugin_so_SOURCES = \
nm-pptp-service-pppd-plugin.c
nm_pppd_plugin_so_SOURCES = \
nm-pppd-plugin.c
nm_pptp_service_pppd_plugin_so_LDFLAGS = \
-shared
nm_pppd_plugin_so_LDFLAGS = \
-shared
nm_pptp_service_pppd_plugin_so_LDADD = \
nm_pppd_plugin_so_LDADD = \
$(DBUS_LIBS) \
$(GTHREAD_LIBS)

View file

@ -0,0 +1,517 @@
/* nm-pptp-service - pptp integration with NetworkManager
*
* Antony J Mee <eemynotna at gmail dot 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.
*
*/
#include "pppd/pppd.h"
#include "pppd/fsm.h"
#include "pppd/ipcp.h"
#include "static_credentials.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-pptp-service.h"
#include "nm-ppp-service.h"
#include "nm-utils.h"
typedef struct NmPPPData
{
DBusConnection *con;
gboolean got_auth_info;
char *auth_type;
char *username;
char *password;
} NmPPPData;
char pppd_version[] = PPPD_VERSION;
NmPPPData plugin_data;
int plugin_init();
void pptp_ip_up(void *opaque, int arg);
void pptp_ip_down(void *opaque, int arg);
void pptp_exit_notify(void *opaque, int arg);
int pptp_chap_passwd_hook(char *user, char *passwd);
int pptp_chap_check_hook(void);
void send_config_error (DBusConnection *con, const char *item);
gboolean pptp_get_auth_items (NmPPPData *data);
gboolean pptp_store_auth_info (NmPPPData *data, char **auth_items, int num_auth_items);
gboolean pptp_dbus_prepare_connection(NmPPPData *data);
static DBusHandlerResult pptp_dbus_message_handler (DBusConnection *con, DBusMessage *message, void *user_data);
void pptp_dbus_kill_connection(NmPPPData *data);
gboolean pptp_dbus_prepare_connection(NmPPPData *data)
{
DBusMessage * message = NULL;
DBusError error;
DBusObjectPathVTable vtable = { NULL,
&pptp_dbus_message_handler,
NULL, NULL, NULL, NULL };
g_return_val_if_fail (data != NULL, FALSE);
if (data->con != NULL) return TRUE;
dbus_error_init (&error);
data->con = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
if ((data->con == NULL) || dbus_error_is_set (&error))
{
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 (&error);
dbus_bus_request_name (data->con, 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 (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 (&error))
{
dbus_error_free (&error);
data->con = NULL;
}
if (data->con == NULL) return FALSE;
return TRUE;
}
void pptp_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);
}
/*
* pptp_dbus_message_handler
*
* Handle requests for our services.
*
*/
static DBusHandlerResult pptp_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 ("pptp_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_VPN_STATE_INIT) || (data->state == NM_VPN_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_PPTP, NM_DBUS_VPN_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_pptp_dbus_start_vpn (con, message, data);
// else if (strcmp ("stopConnection", method) == 0)
// reply = nm_pptp_dbus_stop_vpn (con, message, data);
// else if (strcmp ("getState", method) == 0)
// reply = nm_pptp_dbus_get_state (con, message, data);
// else if (strcmp ("signalConfigError", method) == 0)
// nm_pptp_dbus_process_helper_config_error (con, message, data);
// else if (strcmp ("signalIP4Config", method) == 0)
// nm_pptp_dbus_process_helper_ip4_config (con, message, data);
// else if (strcmp ("getAuthInfo", method) == 0)
// nm_pptp_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);
}
int pptp_chap_check_hook(void)
{
if (! pptp_get_auth_items (&plugin_data))
{
return 0;
}
if (strcmp("CHAP",plugin_data.auth_type)!=0)
{
info("nm-pptp: No CHAP authentication available!");
return 0;
}
info("nm-pptp: CHAP check hook.");
return 1;
}
int pptp_chap_passwd_hook(char *user, char *passwd)
{
info("nm-pptp: CHAP credentials requested.");
if (user == NULL)
{
info("nm-pptp: pppd didn't provide username buffer");
return -1;
}
if (passwd == NULL)
{
info("nm-pptp: pppd didn't provide password buffer");
return -1;
}
if (plugin_data.username == NULL)
{
info("nm-pptp: CHAP username not set");
return -1;
}
if (plugin_data.password == NULL)
{
info("nm-pptp: CHAP password not set");
return -1;
}
if (strlen(plugin_data.username) >= MAXNAMELEN)
{
info("nm-pptp: CHAP username too long!");
return -1;
}
if (strlen(plugin_data.password) >= MAXSECRETLEN)
{
info("nm-pptp: CHAP password too long!");
return -1;
}
strcpy(user, plugin_data.username);
user[MAXNAMELEN-1]='\0';
strcpy(passwd, plugin_data.password);
passwd[MAXSECRETLEN-1]='\0';
// info("nm-pptp: CHAP authenticating as '%s' with '%s'",user,passwd);
//
// Forget the username and password?
//
// if (plugin_data.username!=NULL) g_free(plugin_data.username);
// if (plugin_data.password!=NULL) g_free(plugin_data.password);
return 0;
}
void pptp_exit_notify(void *opaque, int arg)
{
NmPPPData *data = (NmPPPData *)opaque;
pptp_dbus_kill_connection(data);
}
void pptp_ip_down(void *opaque, int arg)
{
DBusConnection *con = (DBusConnection *)opaque;
return;
}
void pptp_ip_up(void *opaque, int arg)
{
NmPPPData *data = (NmPPPData *)opaque;
DBusConnection *con = data->con;
DBusMessage *message;
char * str_ifname = NULL;
// guint32 * uint_ip4_dns = NULL;
guint32 uint_ip4_dns1 = 0;
guint32 uint_ip4_dns2 = 0;
guint32 uint_ip4_dns_len = 0;
// guint32 * uint_ip4_wins = NULL;
guint32 uint_ip4_wins1 = 0;
guint32 uint_ip4_wins2 = 0;
guint32 uint_ip4_wins_len = 0;
guint32 uint_ip4_address = 0;
guint32 uint_ip4_ptp_address = 0;
guint32 uint_ip4_netmask = 0xFFFFFFFF; /* Default mask of 255.255.255.255 */
guint32 i=0;
g_return_if_fail (con != NULL);
if (ipcp_gotoptions[ifunit].ouraddr==0) {
info ("nm-pptp-service-pptp-helper didn't receive an Internal IP4 Address from pptp.");
send_config_error (con, "IP4 Address");
return;
}
uint_ip4_address=ipcp_gotoptions[ifunit].ouraddr;
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE_PPTP, NM_DBUS_PATH_PPTP, NM_DBUS_INTERFACE_PPTP, "signalIP4Config")))
{
info ("send_config_error(): Couldn't allocate the dbus message");
return;
}
if (ipcp_gotoptions[ifunit].dnsaddr) {
if (ipcp_gotoptions[ifunit].dnsaddr[0]!=0) {
uint_ip4_dns_len++;
uint_ip4_dns1=ipcp_gotoptions[ifunit].dnsaddr[0];
if (ipcp_gotoptions[ifunit].dnsaddr[1]!=0) {
uint_ip4_dns_len++;
uint_ip4_dns2=ipcp_gotoptions[ifunit].dnsaddr[1];
}
}
}
if (ipcp_gotoptions[ifunit].winsaddr) {
if (ipcp_gotoptions[ifunit].winsaddr[0]!=0) {
uint_ip4_wins_len++;
uint_ip4_wins1=ipcp_gotoptions[ifunit].winsaddr[0];
if (ipcp_gotoptions[ifunit].winsaddr[1]!=0) {
uint_ip4_wins_len++;
uint_ip4_wins2=ipcp_gotoptions[ifunit].winsaddr[1];
}
}
}
if (ifname==NULL) {
info ("nm-pptp-service-pptp-helper didn't receive a tunnel device name.");
send_config_error (con, "IP4 Address");
}
str_ifname = g_strdup(ifname);
dbus_message_append_args (message,
DBUS_TYPE_STRING, &str_ifname,
DBUS_TYPE_UINT32, &uint_ip4_address,
DBUS_TYPE_UINT32, &uint_ip4_ptp_address,
DBUS_TYPE_UINT32, &uint_ip4_netmask,
// Array workaround
DBUS_TYPE_UINT32, &uint_ip4_dns1,
DBUS_TYPE_UINT32, &uint_ip4_dns2,
DBUS_TYPE_UINT32, &uint_ip4_dns_len,
DBUS_TYPE_UINT32, &uint_ip4_wins1,
DBUS_TYPE_UINT32, &uint_ip4_wins2,
DBUS_TYPE_UINT32, &uint_ip4_wins_len,
DBUS_TYPE_INVALID);
if (!dbus_connection_send (con, message, NULL)) {
info ("pptp_ip_up(): could not send dbus message");
dbus_message_unref (message);
g_strdup(str_ifname);
return;
}
g_strdup(str_ifname);
dbus_message_unref (message);
return;
}
/*
* send_config_error
*
* Notify nm-pptp-service of a config error from 'pptp'.
*
*/
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_PPTP, NM_DBUS_PATH_PPTP, NM_DBUS_INTERFACE_PPTP, "signalConfigError")))
{
nm_warning ("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))
nm_warning ("send_config_error(): could not send dbus message");
dbus_message_unref (message);
}
/*
* pptp_get_auth_items
*
* Request credentials from PPTP service.
*
*/
gboolean pptp_get_auth_items (NmPPPData *data)
{
DBusConnection *con;
int num_auth_items = -1;
char *auth_items[3] = { NULL, NULL, NULL };
// char **auth_items = NULL;
DBusMessage *message = NULL;
DBusMessage *reply = NULL;
if (!pptp_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_PPTP, NM_DBUS_PATH_PPTP, NM_DBUS_INTERFACE_PPTP, "getAuthInfo")))
{
nm_warning("nm-pptp: 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-pptp: no reply to getAuthInfo message.");
return FALSE;
}
if (!(dbus_message_get_args (reply, NULL,
DBUS_TYPE_STRING, &(auth_items[0]),
DBUS_TYPE_STRING, &(auth_items[1]),
DBUS_TYPE_STRING, &(auth_items[2]),
// DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &auth_items, &num_auth_items,
DBUS_TYPE_INVALID)))
{
dbus_message_unref (reply);
return FALSE;
}
num_auth_items=3;
if (!pptp_store_auth_info (data, auth_items, num_auth_items))
{
//dbus_free_string_array (auth_items);
dbus_message_unref (reply);
return FALSE;
}
//dbus_free_string_array (auth_items);
dbus_message_unref (reply);
return TRUE;
}
/*
* pptp_store_auth_info
*
* Decode and temporarily store the authentication info provided.
*
*/
gboolean pptp_store_auth_info (NmPPPData *data, char **auth_items, int num_auth_items)
{
int i=0;
g_return_val_if_fail (auth_items != NULL, FALSE);
g_return_val_if_fail (num_auth_items >= 1, FALSE);
nm_warning ("PPTP will authenticate using '%s'.", auth_items[0]);
if (strcmp ("CHAP", auth_items[0]) == 0) {
g_return_val_if_fail (num_auth_items >= 3, FALSE);
if (data->auth_type!=NULL) g_free(data->auth_type);
if (data->username!=NULL) g_free(data->username);
if (data->password!=NULL) g_free(data->password);
data->auth_type=g_strdup(auth_items[0]);
data->username=g_strdup(auth_items[1]);
data->password=g_strdup(auth_items[2]);
} else if (strcmp ("NONE", auth_items[0]) == 0) {
if (data->auth_type!=NULL) g_free(data->auth_type);
if (data->username!=NULL) g_free(data->username);
if (data->password!=NULL) g_free(data->password);
data->auth_type=g_strdup(auth_items[0]);
} else {
nm_warning ("PPTP authentication type '%s' is not allowed.", auth_items[0]);
return FALSE;
}
data->got_auth_info=TRUE;
return TRUE;
}
int plugin_init()
{
// DBusConnection * con = NULL;
// DBusMessage * message = NULL;
// DBusError error;
// g_type_init ();
// if (!g_thread_supported ())
// g_thread_init (NULL);
// dbus_error_init (&error);
// con = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
// if ((con == NULL) || dbus_error_is_set (&error))
// {
// dbus_error_free (&error);
// info("Could not get the system bus. Make sure the message bus daemon is running?");
// return -1;
// }
// dbus_connection_set_exit_on_disconnect (con, FALSE);
//
//
// dbus_error_free (&error);
// add_options(ppp_options);
chap_check_hook = pptp_chap_check_hook;
chap_passwd_hook = pptp_chap_passwd_hook;
add_notifier(&ip_down_notifier, pptp_ip_down, (void *) &plugin_data);
add_notifier(&ip_up_notifier, pptp_ip_up, (void *) &plugin_data);
add_notifier(&exitnotify, pptp_exit_notify, (void *) &plugin_data);
info("nm-pptp: plugin initialized.");
return 0;
}

View file

@ -1,249 +0,0 @@
/* nm-pptp-service - pptp integration with NetworkManager
*
* 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.
*
* (C) Copyright 2005 Red Hat, Inc.
*/
#include "pppd/pppd.h"
#include "pppd/fsm.h"
#include "pppd/ipcp.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-pptp-service.h"
#include "nm-utils.h"
char pppd_version[] = PPPD_VERSION;
static void pptp_ip_up(void *opaque, int arg);
static void pptp_ip_down(void *opaque, int arg);
int pptp_chap_passwd(char *user, char *passwd);
static void send_config_error (DBusConnection *con, const char *item);
/* nm_warning ("nm-pptp-service-pptp-helper didn't receive a Tunnel Device from pptp, or the tunnel device was not valid UTF-8.");
send_config_error (con, "Tunnel Device");
nm_warning ("nm-pptp-service-pptp-helper didn't receive an Internal IP4 Address from pptp.");
send_config_error (con, "IP4 Address");
*/
int plugin_init()
{
DBusConnection * con = NULL;
DBusError error;
g_type_init ();
if (!g_thread_supported ())
g_thread_init (NULL);
dbus_error_init (&error);
con = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
if ((con == NULL) || dbus_error_is_set (&error))
{
dbus_error_free (&error);
info("Could not get the system bus. Make sure the message bus daemon is running?");
return -1;
}
dbus_connection_set_exit_on_disconnect (con, FALSE);
// add_options(ldap_options);
chap_passwd_hook = pptp_chap_passwd;
add_notifier(&ip_down_notifier, pptp_ip_down, (void *) con);
add_notifier(&ip_up_notifier, pptp_ip_up, (void *) con);
info("nm-pptp: plugin initialized.");
dbus_error_free (&error);
return 0;
}
int pptp_chap_passwd(char *user, char *passwd)
{
memcpy(passwd, "YOUR PASSWORD IN HERE!!",MAXSECRETLEN);
passwd[MAXSECRETLEN-1]='\0';
return 0;
}
static void pptp_ip_down(void *opaque, int arg)
{
DBusConnection *con = (DBusConnection *)opaque;
return;
}
static void pptp_ip_up(void *opaque, int arg)
{
DBusConnection *con = (DBusConnection *)opaque;
DBusMessage *message;
char * str_ifname = NULL;
// guint32 * uint_ip4_dns = NULL;
guint32 uint_ip4_dns1 = 0;
guint32 uint_ip4_dns2 = 0;
guint32 uint_ip4_dns_len = 0;
// guint32 * uint_ip4_wins = NULL;
guint32 uint_ip4_wins1 = 0;
guint32 uint_ip4_wins2 = 0;
guint32 uint_ip4_wins_len = 0;
guint32 uint_ip4_address = 0;
guint32 uint_ip4_ptp_address = 0;
guint32 uint_ip4_netmask = 0xFFFFFFFF; /* Default mask of 255.255.255.255 */
guint32 i=0;
g_return_if_fail (con != NULL);
if (ipcp_gotoptions[ifunit].ouraddr==0) {
info ("nm-pptp-service-pptp-helper didn't receive an Internal IP4 Address from pptp.");
send_config_error (con, "IP4 Address");
return;
}
uint_ip4_address=ipcp_gotoptions[ifunit].ouraddr;
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE_PPTP, NM_DBUS_PATH_PPTP, NM_DBUS_INTERFACE_PPTP, "signalIP4Config")))
{
info ("send_config_error(): Couldn't allocate the dbus message");
return;
}
if (ipcp_gotoptions[ifunit].dnsaddr) {
if (ipcp_gotoptions[ifunit].dnsaddr[0]!=0) {
uint_ip4_dns_len++;
uint_ip4_dns1=ipcp_gotoptions[ifunit].dnsaddr[0];
if (ipcp_gotoptions[ifunit].dnsaddr[1]!=0) {
uint_ip4_dns_len++;
uint_ip4_dns2=ipcp_gotoptions[ifunit].dnsaddr[1];
}
}
// if (uint_ip4_dns_len > 0)
// {
// uint_ip4_dns = g_new0(guint32,uint_ip4_dns_len);
// for (i = 0; i < uint_ip4_dns_len; ++i)
// uint_ip4_dns[i] = ipcp_gotoptions[ifunit].dnsaddr[i];
// }
}
if (ipcp_gotoptions[ifunit].winsaddr) {
if (ipcp_gotoptions[ifunit].winsaddr[0]!=0) {
uint_ip4_wins_len++;
uint_ip4_wins1=ipcp_gotoptions[ifunit].winsaddr[0];
if (ipcp_gotoptions[ifunit].winsaddr[1]!=0) {
uint_ip4_wins_len++;
uint_ip4_wins2=ipcp_gotoptions[ifunit].winsaddr[1];
}
}
// if (uint_ip4_wins_len > 0)
// {
// uint_ip4_wins = g_new0(guint32,uint_ip4_wins_len);
// for (i = 0; i < uint_ip4_wins_len; ++i)
// uint_ip4_wins[i] = ipcp_gotoptions[ifunit].winsaddr[i];
// }
}
if (ifname==NULL) {
info ("nm-pptp-service-pptp-helper didn't receive a tunnel device name.");
send_config_error (con, "IP4 Address");
}
str_ifname = g_strdup(ifname);
/* Print out some debug info.
info("Sending config IFNAME: %s",str_ifname);
nm_warning("Sending config IPLOCAL: %s", ip_ntoa(uint_ip4_address));
nm_warning("Sending config NETMASK: %s", ip_ntoa(uint_ip4_netmask));
nm_warning("Sending config DNS1: %s", ip_ntoa(uint_ip4_dns1));
nm_warning("Sending config DNS2: %s", ip_ntoa(uint_ip4_dns2));
nm_warning("Sending config NDNS: %d", uint_ip4_dns_len);
nm_warning("Sending config WINS1: %s", ip_ntoa(uint_ip4_wins1));
nm_warning("Sending config WINS2: %s", ip_ntoa(uint_ip4_wins2));
nm_warning("Sending config NWINS: %d", uint_ip4_wins_len); */
dbus_message_append_args (message,
DBUS_TYPE_STRING, &str_ifname,
DBUS_TYPE_UINT32, &uint_ip4_address,
DBUS_TYPE_UINT32, &uint_ip4_ptp_address,
DBUS_TYPE_UINT32, &uint_ip4_netmask,
// Array workaround
DBUS_TYPE_UINT32, &uint_ip4_dns1,
DBUS_TYPE_UINT32, &uint_ip4_dns2,
DBUS_TYPE_UINT32, &uint_ip4_dns_len,
DBUS_TYPE_UINT32, &uint_ip4_wins1,
DBUS_TYPE_UINT32, &uint_ip4_wins2,
DBUS_TYPE_UINT32, &uint_ip4_wins_len,
//
// For some reason DBUS_TYPE_ARRAYs don't seem to like working inside the pppd plugin
//
// testing with:
// pppd pty "/usr/sbin/pptp SOME.SERVER.IP --nolaunchpppd" nodetach remotename SOME.SERVER user MYUSER usepeerdns plugin nm-pptp-service-pppd-plugin.so
//
// Fails with (given pointers and allocated arrays with g_new0() ):
// 13646: assertion failed "value != NULL" file "dbus-string.c" line 235 function _dbus_string_init_const_len
// Fatal signal 6
//
// Or if fixed [2] arrays are used:
// Fatal signal 11
//
// DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &uint_ip4_dns, uint_ip4_dns_len,
// DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &uint_ip4_wins, uint_ip4_wins_len,
DBUS_TYPE_INVALID);
if (!dbus_connection_send (con, message, NULL)) {
info ("pptp_ip_up(): could not send dbus message");
dbus_message_unref (message);
return;
}
dbus_message_unref (message);
return;
}
/*
* send_config_error
*
* Notify nm-pptp-service of a config error from 'pptp'.
*
*/
static 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_PPTP, NM_DBUS_PATH_PPTP, NM_DBUS_INTERFACE_PPTP, "signalConfigError")))
{
nm_warning ("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))
nm_warning ("send_config_error(): could not send dbus message");
dbus_message_unref (message);
}

View file

@ -1,8 +1,8 @@
/* nm-pptp-service - pptp integration with NetworkManager
*
* Antony Mee <a.j.mee@ncl.ac.uk>
* Based on work by Tim Niemueller <tim@niemueller.de>
* and Dan Williams <dcbw@redhat.com>
* Antony J Mee <eemynotna at gmail dot com>
* 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
@ -64,7 +64,7 @@ static const char *pppd_binary_paths[] =
NULL
};
#define NM_PPTP_HELPER_PATH "nm-pptp-service-pppd-plugin.so"
#define NM_PPTP_HELPER_PATH "nm-pppd-plugin.so"
typedef struct NmPPTPData
{
@ -76,10 +76,14 @@ typedef struct NmPPTPData
guint helper_timer;
char *str_ip4_vpn_gateway;
struct in_addr ip4_vpn_gateway;
char **auth_items;
int num_auth_items;
} NmPPTPData;
static gboolean nm_pptp_dbus_handle_stop_vpn (NmPPTPData *data);
static gboolean nm_pptp_store_auth_info (NmPPTPData *data,
char **auth_items, int num_auth_items);
/*
@ -436,10 +440,10 @@ static gint nm_pptp_start_pptp_binary (NmPPTPData *data, char **data_items, cons
g_ptr_array_add (pptp_argv, (gpointer) "10");
// Set the username...
for (i = 0; i < num_items; ++i) {
if ( strcmp( data_items[i], "username" ) == 0) {
/* if ( strcmp( data_items[i], "username" ) == 0) {
g_ptr_array_add (pptp_argv, (gpointer) "user");
g_ptr_array_add (pptp_argv, (gpointer) data_items[++i]);
} else if ( strcmp( data_items[i], "remote" ) == 0) {
} else */ if ( strcmp( data_items[i], "remote" ) == 0) {
g_ptr_array_add (pptp_argv, (gpointer) "remotename");
g_ptr_array_add (pptp_argv, (gpointer) data_items[++i]);
} else if ( (strcmp( data_items[i], "encrypt-mppe" ) == 0) &&
@ -584,6 +588,31 @@ static gboolean nm_pptp_config_options_validate (char **data_items, int num_item
return TRUE;
}
/*
* nm_pptp_store_auth_info
*
* Decode and temporarily store the authentication info provided.
*
*/
static gboolean nm_pptp_store_auth_info (NmPPTPData *data,
char **auth_items, int num_auth_items)
{
// nm_warning("nm_pptp_store_auth_info: enter");
g_return_val_if_fail (auth_items != NULL, FALSE);
g_return_val_if_fail (num_auth_items >= 1, FALSE);
if ((data->auth_items=g_strdupv(auth_items))==NULL)
{
data->num_auth_items=-1;
// nm_warning("nm_pptp_store_auth_info: failed");
return FALSE;
}
data->num_auth_items=num_auth_items;
// nm_warning("nm_pptp_store_auth_info: done");
return TRUE;
}
/*
* nm_pptp_dbus_handle_start_vpn
*
@ -594,8 +623,8 @@ static gboolean nm_pptp_dbus_handle_start_vpn (DBusMessage *message, NmPPTPData
{
char ** data_items = NULL;
int num_items = -1;
char ** password_items = NULL;
int num_passwords = -1;
char ** auth_items = NULL;
int num_auth_items = -1;
char ** user_routes = NULL;
int user_routes_count = -1;
const char * name = NULL;
@ -613,7 +642,7 @@ static gboolean nm_pptp_dbus_handle_start_vpn (DBusMessage *message, NmPPTPData
if (!dbus_message_get_args (message, &error,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_STRING, &user_name,
DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &password_items, &num_passwords,
DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &auth_items, &num_auth_items,
DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &data_items, &num_items,
DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &user_routes, &user_routes_count,
DBUS_TYPE_INVALID))
@ -630,6 +659,12 @@ static gboolean nm_pptp_dbus_handle_start_vpn (DBusMessage *message, NmPPTPData
goto out;
}
if (!nm_pptp_store_auth_info (data, auth_items, num_auth_items))
{
nm_pptp_dbus_signal_failure (data, NM_DBUS_VPN_SIGNAL_LOGIN_FAILED);
goto out;
}
/* Now we can finally try to activate the VPN */
if ((pptp_fd = nm_pptp_start_pptp_binary (data, data_items, num_items)) >= 0)
{
@ -638,7 +673,7 @@ static gboolean nm_pptp_dbus_handle_start_vpn (DBusMessage *message, NmPPTPData
out:
dbus_free_string_array (data_items);
dbus_free_string_array (password_items);
dbus_free_string_array (auth_items);
dbus_free_string_array (user_routes);
if (!success)
nm_pptp_set_state (data, NM_VPN_STATE_STOPPED);
@ -671,6 +706,31 @@ static gboolean nm_pptp_dbus_handle_stop_vpn (NmPPTPData *data)
return TRUE;
}
/*
* nm_pptp_dbus_handle_chap_check
*
* Stop the running pppd dameon.
*
*/
static gboolean nm_pptp_dbus_handle_chap_check (NmPPTPData *data)
{
g_return_val_if_fail (data != NULL, FALSE);
if (data->pid > 0)
{
nm_pptp_set_state (data, NM_VPN_STATE_STOPPING);
kill (data->pid, SIGTERM);
nm_info ("Terminated pppd with PID %d.", data->pid);
data->pid = 0;
nm_pptp_set_state (data, NM_VPN_STATE_STOPPED);
nm_pptp_schedule_quit_timer (data, 10000);
}
return TRUE;
}
/*
* nm_pptp_dbus_start_vpn
@ -779,6 +839,44 @@ static DBusMessage *nm_pptp_dbus_get_state (DBusConnection *con, DBusMessage *me
return reply;
}
/*
* nm_pptp_dbus_get_auth_info
*
* Pass authentication information to the PPPD plugin.
*
*/
static DBusMessage *nm_pptp_dbus_get_auth_info (DBusConnection *con, DBusMessage *message, NmPPTPData *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);
nm_info("Attempting getAuthInfo reply");
if (data->auth_items==NULL) {
nm_warning("Authentication not recieved yet. Sending 'NONE'.");
data->auth_items = g_strsplit("NONE empty empty"," ",3);
data->num_auth_items = 3;
}
// g_return_val_if_fail (data->auth_items != NULL, NULL);
// g_return_val_if_fail (data->num_auth_items >= 1, NULL);
nm_info("Building getAuthInfo reply");
if ((reply = dbus_message_new_method_return (message)))
dbus_message_append_args (reply,
DBUS_TYPE_STRING, &(data->auth_items[0]),
DBUS_TYPE_STRING, &(data->auth_items[1]),
DBUS_TYPE_STRING, &(data->auth_items[2]),
// DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &(data->auth_items), &(data->num_auth_items),
DBUS_TYPE_INVALID);
if (!reply)
nm_info("Build of getAuthInfo reply failed ");
nm_info("Should reply ");
return reply;
}
/*
* nm_pptp_dbus_process_helper_config_error
@ -843,6 +941,10 @@ static void nm_pptp_dbus_process_helper_ip4_config (DBusConnection *con, DBusMes
if (data->state != NM_VPN_STATE_STARTING)
return;
/* If IP is up then we don't need to leave the auth info lying around */
g_strfreev (data->auth_items);
data->num_auth_items=-1;
nm_pptp_cancel_helper_timer (data);
if (dbus_message_get_args(message, NULL,
@ -962,6 +1064,8 @@ static DBusHandlerResult nm_pptp_dbus_message_handler (DBusConnection *con, DBus
nm_pptp_dbus_process_helper_config_error (con, message, data);
else if (strcmp ("signalIP4Config", method) == 0)
nm_pptp_dbus_process_helper_ip4_config (con, message, data);
else if (strcmp ("getAuthInfo", method) == 0)
reply = nm_pptp_dbus_get_auth_info (con, message, data);
else
handled = FALSE;
@ -1051,6 +1155,7 @@ DBusConnection *nm_pptp_dbus_init (NmPPTPData *data)
goto out;
}
dbus_connection_set_exit_on_disconnect (connection, FALSE);
dbus_connection_setup_with_g_main (connection, NULL);
dbus_error_init (&error);
@ -1103,7 +1208,7 @@ static void sigterm_handler (int signum)
{
nm_info ("nm-pptp-service caught SIGINT/SIGTERM");
// g_main_loop_quit (vpn_data->loop);
g_main_loop_quit (vpn_data->loop);
}
@ -1143,7 +1248,8 @@ int main( int argc, char *argv[] )
g_main_loop_unref (vpn_data->loop);
if (vpn_data->str_ip4_vpn_gateway != NULL) g_free( vpn_data->str_ip4_vpn_gateway );
g_strfreev (vpn_data->auth_items);
g_free (vpn_data->str_ip4_vpn_gateway);
g_free (vpn_data);
exit (0);

View file

@ -1,8 +1,8 @@
/* nm-pptp-service - pptp integration with NetworkManager
*
* Antony Mee <a.j.mee@ncl.ac.uk>
* Based on work by Tim Niemueller <tim@niemueller.de>
* and Dan Williams <dcbw@redhat.com>
* Antony J Mee <eemynotna at gmail dot com>
* 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