diff --git a/vpn-daemons/pptp/ChangeLog b/vpn-daemons/pptp/ChangeLog index f6bc0e5c7f..5d4a6b9b9b 100644 --- a/vpn-daemons/pptp/ChangeLog +++ b/vpn-daemons/pptp/ChangeLog @@ -1,3 +1,7 @@ +2008-07-20 Dan Williams + + Port to NM 0.7 VPN plugin API + 2008-04-27 Dan Williams * properties/Makefile.am diff --git a/vpn-daemons/pptp/Makefile.am b/vpn-daemons/pptp/Makefile.am index f6704c82dc..10e60c3c5e 100644 --- a/vpn-daemons/pptp/Makefile.am +++ b/vpn-daemons/pptp/Makefile.am @@ -1,24 +1,20 @@ +AUTOMAKE_OPTIONS = foreign + if WITH_GNOME -SUBDIRS = src auth-dialog auth-dialog-general properties po +SUBDIRS = src auth-dialog properties po else SUBDIRS = src endif dbusservicedir = $(sysconfdir)/dbus-1/system.d -dbusservice_DATA = nm-ppp-starter.conf +dbusservice_DATA = nm-pptp-service.conf -nmvpnservice_in_files = nm-ppp-starter.name.in nmvpnservicedir = $(sysconfdir)/NetworkManager/VPN -nmvpnservice_DATA = $(nmvpnservice_in_files:.name.in=.name) - -%.name: %.name.in Makefile - @sed -e "s|%bindir%|$(bindir)|g" \ - -e "s|%libdir%|$(libdir)|g" \ - -e "s|%libexecdir%|$(libexecdir)|g" $< > $@ +nmvpnservice_DATA = nm-pptp-service.name if WITH_GNOME desktopdir = $(datadir)/applications -desktop_in_files = nm-ppp.desktop.in +desktop_in_files = nm-pptp.desktop.in desktop_DATA = $(desktop_in_files:.desktop.in=.desktop) @INTLTOOL_DESKTOP_RULE@ @@ -26,14 +22,18 @@ icondir = $(datadir)/icons/hicolor/48x48/apps icon_DATA = gnome-mime-application-x-pptp-settings.png endif -EXTRA_DIST =\ - $(nmvpnservice_in_files) \ - $(dbusservice_DATA) \ - $(desktop_in_files) \ - $(icon_DATA) \ - intltool-extract.in \ - intltool-merge.in \ - intltool-update.in +nm-pptp-service.name: $(srcdir)/nm-pptp-service.name.in Makefile + sed -e 's|[@]BINDIR[@]|$(bindir)|g' \ + < $(srcdir)/nm-pptp-service.name.in \ + > nm-pptp-service.name -CLEANFILES = $(desktop_DATA) $(nmvpnservice_DATA) *~ +EXTRA_DIST = nm-pptp-service.name.in \ + $(dbusservice_DATA) \ + $(desktop_in_files) \ + $(icon_DATA) \ + intltool-extract.in \ + intltool-merge.in \ + intltool-update.in + +CLEANFILES = $(nmvpnservice_DATA) $(desktop_DATA) *~ DISTCLEANFILES = intltool-extract intltool-merge intltool-update diff --git a/vpn-daemons/pptp/README b/vpn-daemons/pptp/README index 39c577d633..b26aa2d0d5 100644 --- a/vpn-daemons/pptp/README +++ b/vpn-daemons/pptp/README @@ -1,15 +1,17 @@ PPTP support for NetworkManager -Added by Antony Mee http://www.students.ncl.ac.uk/a.j.mee -Based entirely on OpenVPN support by Tim Niemueller http://www.niemueller.de - This requires the Linux PPTP client installed http://pptpclient.sourceforge.net/ -TODO: Support for passwords stored outside of /etc/ppp/chap-secrets +0.7.x version: +(C) 2008 Dan Williams , and Tambet Ingo -Code released under the GPL. See COPYING file in the NetworkManager -directory. +0.6.x version: +(C) 2005 - 2007 Antony Mee http://www.students.ncl.ac.uk/a.j.mee +Based entirely on OpenVPN support by Tim Niemueller http://www.niemueller.de + + +Theory of operation +------------------------------ -Aachen, 2005/11/12 diff --git a/vpn-daemons/pptp/auth-dialog-general/.cvsignore b/vpn-daemons/pptp/auth-dialog-general/.cvsignore deleted file mode 100644 index 5abaefa0ec..0000000000 --- a/vpn-daemons/pptp/auth-dialog-general/.cvsignore +++ /dev/null @@ -1,5 +0,0 @@ -Makefile.in -Makefile -nm-ppp-auth-dialog-general -.libs -.deps diff --git a/vpn-daemons/pptp/auth-dialog-general/Makefile.am b/vpn-daemons/pptp/auth-dialog-general/Makefile.am deleted file mode 100644 index 1fcefadb95..0000000000 --- a/vpn-daemons/pptp/auth-dialog-general/Makefile.am +++ /dev/null @@ -1,115 +0,0 @@ -INCLUDES = -I${top_srcdir} -I${top_srcdir}/utils - -libexec_PROGRAMS = nm-ppp-auth-dialog-general - -nm_ppp_auth_dialog_general_CPPFLAGS = \ - $(GTHREAD_CFLAGS) \ - $(GTK_CFLAGS) \ - $(LIBGNOMEUI_CFLAGS) \ - $(GNOMEKEYRING_CFLAGS) \ - -DICONDIR=\""$(datadir)/pixmaps"\" \ - -DGLADEDIR=\""$(gladedir)"\" \ - -DAUTH_MODULES_DIR=\""$(libgenericauthmodulesdir)"\" \ - -DBINDIR=\""$(bindir)"\" \ - -DDBUS_API_SUBJECT_TO_CHANGE \ - -DG_DISABLE_DEPRECATED \ - -DGDK_DISABLE_DEPRECATED \ - -DGNOME_DISABLE_DEPRECATED \ - -DGNOMELOCALEDIR=\"$(datadir)/locale\" \ - -DVERSION=\"$(VERSION)\" \ - $(NULL) - -nm_ppp_auth_dialog_general_SOURCES = \ - main.c \ - gnome-generic-auth-dialog.c \ - gnome-generic-auth-dialog.h \ - $(NULL) - -nm_ppp_auth_dialog_general_LDADD = \ - $(GTK_LIBS) \ - $(LIBGNOMEUI_LIBS) \ - $(GNOMEKEYRING_LIBS) \ - $(NULL) - -libgenericauthmodulesdir=$(libdir)/NetworkManager/gnome-generic-auth -libgenericauthmodules_LTLIBRARIES = \ - libanonymous-auth-module.la \ - libchap-auth-module.la \ - libmschapv2-auth-module.la - -libanonymous_auth_module_la_SOURCES = \ - anonymous-auth-module.c - -libmschapv2_auth_module_la_SOURCES = \ - mschapv2-auth-module.c - -libchap_auth_module_la_SOURCES = \ - chap-auth-module.c - -gladedir = $(datadir)/gnome-generic-auth -glade_DATA = nm-ppp-auth.glade - -libanonymous_auth_module_la_CFLAGS = \ - $(GLADE_CFLAGS) \ - $(GTK_CFLAGS) \ - $(GCONF_CFLAGS) \ - $(LIBGNOMEUI_CFLAGS) \ - -DICONDIR=\""$(datadir)/pixmaps"\" \ - -DGLADEDIR=\""$(gladedir)"\" \ - -DAUTH_MODULES_DIR=\""$(libgenericauthmodulesdir)"\" \ - -DG_DISABLE_DEPRECATED \ - -DGDK_DISABLE_DEPRECATED \ - -DGNOME_DISABLE_DEPRECATED \ - -DGNOMELOCALEDIR=\"$(datadir)/locale\" \ - -DVERSION=\"$(VERSION)\" - -libanonymous_auth_module_la_LIBADD = \ - $(GLADE_LIBS) \ - $(GTK_LIBS) \ - $(GCONF_LIBS) \ - $(LIBGNOMEUI_LIBS) - -libchap_auth_module_la_CFLAGS = \ - $(GLADE_CFLAGS) \ - $(GTK_CFLAGS) \ - $(GCONF_CFLAGS) \ - $(LIBGNOMEUI_CFLAGS) \ - -DICONDIR=\""$(datadir)/pixmaps"\" \ - -DGLADEDIR=\""$(gladedir)"\" \ - -DAUTH_MODULES_DIR=\""$(libgenericauthmodulesdir)"\" \ - -DG_DISABLE_DEPRECATED \ - -DGDK_DISABLE_DEPRECATED \ - -DGNOME_DISABLE_DEPRECATED \ - -DGNOMELOCALEDIR=\"$(datadir)/locale\" \ - -DVERSION=\"$(VERSION)\" - -libmschapv2_auth_module_la_CFLAGS = \ - $(GLADE_CFLAGS) \ - $(GTK_CFLAGS) \ - $(GCONF_CFLAGS) \ - $(LIBGNOMEUI_CFLAGS) \ - -DICONDIR=\""$(datadir)/pixmaps"\" \ - -DGLADEDIR=\""$(gladedir)"\" \ - -DAUTH_MODULES_DIR=\""$(libgenericauthmodulesdir)"\" \ - -DG_DISABLE_DEPRECATED \ - -DGDK_DISABLE_DEPRECATED \ - -DGNOME_DISABLE_DEPRECATED \ - -DGNOMELOCALEDIR=\"$(datadir)/locale\" \ - -DVERSION=\"$(VERSION)\" - -libchap_auth_module_la_LIBADD = \ - $(GLADE_LIBS) \ - $(GTK_LIBS) \ - $(GCONF_LIBS) \ - $(LIBGNOMEUI_LIBS) - -libmschapv2_auth_module_la_LIBADD = \ - $(GLADE_LIBS) \ - $(GTK_LIBS) \ - $(GCONF_LIBS) \ - $(LIBGNOMEUI_LIBS) - -EXTRA_DIST = \ - $(glade_DATA) - -CLEANFILES = *.bak *.gladep *~ diff --git a/vpn-daemons/pptp/auth-dialog-general/anonymous-auth-module.c b/vpn-daemons/pptp/auth-dialog-general/anonymous-auth-module.c deleted file mode 100644 index a8b0469135..0000000000 --- a/vpn-daemons/pptp/auth-dialog-general/anonymous-auth-module.c +++ /dev/null @@ -1,149 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include - -#define GNOME_GENERIC_AUTH_MODULE_SUBJECT_TO_CHANGE -#include "gnome-generic-auth-module.h" - -/* Stuff to be provided by the specific instance */ -typedef struct _GnomeGenericAuthModuleImpl GnomeGenericAuthModuleImpl; - -struct _GnomeGenericAuthModuleImpl { - GnomeGenericAuthModule parent; - - GladeXML *xml; - - GtkWidget *widget; - -// GtkEntry *w_connection_name; -// GtkEntry *w_remote; -}; - -#define GLADE_FILE "nm-ppp-auth.glade" -#define GLADE_WIDGET "auth-none-widget" - -#define AUTH_TYPE "NONE" -#define AUTH_TYPE_DISPLAY_NAME "None (Anonymous)" - - -void -impl_clear_widget (GnomeGenericAuthModuleImpl *impl) -{ -// g_return_if_fail(impl!=NULL); -} - -static const char * -impl_get_display_name (GnomeGenericAuthModule *self) -{ - return AUTH_TYPE_DISPLAY_NAME; -} - - -static const char * -impl_get_auth_type (GnomeGenericAuthModule *self) -{ - return AUTH_TYPE; -} - -static GtkWidget * -impl_get_widget (GnomeGenericAuthModule *self) -{ - GnomeGenericAuthModuleImpl *impl = (GnomeGenericAuthModuleImpl *) self->data; - - impl_clear_widget (impl); -// -// if (connection_name != NULL) { -// if ((opt = impl->connection_name_opt) != NULL) { -// vpnui_opt_set(opt,connection_name); -// } -// } -// -// for (item=properties; item != NULL; item = g_slist_next(g_slist_next(item))) -// { -// if (item->data==NULL) continue; -// if ((g_slist_next(item))->data==NULL) continue; -// opt = impl_opt_bygconf(impl,(char *)item->data); -// if (opt==NULL) continue; -// vpnui_opt_set(opt, (char *)(g_slist_next(item))->data); -// } -// -// if (routes != NULL) { -// GString *route_str; -// char *str; -// -// route_str = g_string_new (""); -// for (item = routes; item != NULL; item = g_slist_next (item)) { -// if (item != routes) g_string_append_c(route_str, ' '); -// g_string_append(route_str, (const char *) item->data); -// } -// str = g_string_free (route_str, FALSE); -// -// vpnui_opt_set(impl->routes_opt,str); -// vpnui_opt_set(impl->routes_toggle_opt,"yes"); -// g_free (str); -// } -// -// vpnui_expand_reset_all(impl); -// - return impl->widget; -} - -static GnomeGenericAuthModule* -impl_get_object (void) -{ - char *glade_file; - GnomeGenericAuthModuleImpl *impl; - - impl = g_new0 (GnomeGenericAuthModuleImpl, 1); - - glade_file = g_strdup_printf ("%s/%s", GLADEDIR, GLADE_FILE); - impl->xml = glade_xml_new (glade_file, NULL, GETTEXT_PACKAGE); - g_free( glade_file ); - if (impl->xml != NULL) { - - impl->widget = glade_xml_get_widget(impl->xml, GLADE_WIDGET); - -// impl_setup(impl); - -// impl->callback = NULL; - -// if (impl->w_import_button!=NULL) { -// g_signal_connect (GTK_OBJECT (impl->w_import_button), -// "clicked", G_CALLBACK (import_button_clicked), impl); -// } -// -// /* make the widget reusable */ -// g_signal_connect (GTK_OBJECT (impl->widget), "delete-event", -// G_CALLBACK (gtk_widget_hide_on_delete), NULL); -// - impl_clear_widget (impl); - - impl->parent.get_display_name = impl_get_display_name; - impl->parent.get_auth_type = impl_get_auth_type; - impl->parent.get_widget = impl_get_widget; - impl->parent.data = impl; - - return &(impl->parent); - } else { - g_free (impl); - return NULL; - } -} - -const char * -get_auth_type (void) -{ - return AUTH_TYPE; -} - -GnomeGenericAuthModule* -gnome_generic_auth_module_factory (void) -{ - return impl_get_object(); -} - - diff --git a/vpn-daemons/pptp/auth-dialog-general/chap-auth-module.c b/vpn-daemons/pptp/auth-dialog-general/chap-auth-module.c deleted file mode 100644 index 02d74f2512..0000000000 --- a/vpn-daemons/pptp/auth-dialog-general/chap-auth-module.c +++ /dev/null @@ -1,204 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include - -#define GNOME_GENERIC_AUTH_MODULE_SUBJECT_TO_CHANGE -#include "gnome-generic-auth-module.h" - -/* Stuff to be provided by the specific instance */ -typedef struct _GnomeGenericAuthModuleImpl GnomeGenericAuthModuleImpl; - -struct _GnomeGenericAuthModuleImpl { - GnomeGenericAuthModule parent; - - GladeXML *xml; - - GtkWidget *widget; - - GtkEntry *w_username; - GtkEntry *w_password; - -}; - -#define GLADE_FILE "nm-ppp-auth.glade" -#define GLADE_WIDGET "auth-chap-widget" -//#define GLADE_WIDGET "table1" - -#define AUTH_TYPE "CHAP" -#define AUTH_TYPE_DISPLAY_NAME "CHAP Version 1" - -static void -entry_changed (GtkWidget *widget,gpointer data) -{ -// GnomeGenericAuthModuleImpl *impl = (GnomeGenericAuthModuleImpl *) data; - g_warning("Entry: %s (%s)",gtk_entry_get_text(GTK_ENTRY(widget)), gtk_widget_get_name(widget)); -} - -static void -clear_widget (GnomeGenericAuthModuleImpl *impl) -{ -GList *children; -GList *i; -GtkWidget *w; -g_warning("Clearing widget"); - gtk_entry_set_text(impl->w_username,""); - gtk_entry_set_text(impl->w_password,""); - gtk_widget_grab_focus (GTK_WIDGET(impl->w_username)); -//g_warning("Username %s", GTK_WIDGET_CAN_FOCUS(impl->w_username) ? "Can focus" : "Can't focus" ); -//g_warning("Username %s", GTK_WIDGET_VISIBLE(impl->w_username) ? "Is visible" : "Is not visible"); -//g_warning("Username %s", GTK_WIDGET_SENSITIVE(impl->w_username) ? "Is sensitive" : "Is not sensitive"); -//g_warning("Widget: %s",gtk_widget_get_name(impl->widget)); - impl->w_username = GTK_ENTRY(glade_xml_get_widget(impl->xml, "username")); - g_signal_connect (impl->w_username, "changed", G_CALLBACK (entry_changed), impl); -// gtk_widget_grab_focus (GTK_WIDGET(impl->w_username)); - gtk_widget_child_focus (GTK_WIDGET(impl->w_username),GTK_DIR_TAB_FORWARD); - - children = gtk_container_get_children (GTK_CONTAINER (impl->widget)); - for (i = children; i != NULL; i = g_list_next (i)) { - w = GTK_WIDGET (i->data); - g_warning("Has child: %s",gtk_widget_get_name(w)); - } - g_list_free (children); -} - -static void -goto_next (GtkWidget *widget,gpointer data) -{ - GnomeGenericAuthModuleImpl *impl = (GnomeGenericAuthModuleImpl *) data; -g_warning("Goto next!"); - if (strcmp(gtk_widget_get_name(widget),"username")==0) { - gtk_widget_grab_focus (GTK_WIDGET(impl->w_password)); - } else if (strcmp(gtk_widget_get_name(widget),"password")==0) { - } -} - -static gboolean -impl_set_user (GnomeGenericAuthModule *self, const char *user) -{ - GnomeGenericAuthModuleImpl *impl = (GnomeGenericAuthModuleImpl *) self->data; - - gtk_entry_set_text(impl->w_username,user); - return TRUE; -} - -static const char * -impl_get_user (GnomeGenericAuthModule *self) -{ - GnomeGenericAuthModuleImpl *impl = (GnomeGenericAuthModuleImpl *) self->data; - - return gtk_entry_get_text(impl->w_username); -} - -static gboolean -impl_set_secret (GnomeGenericAuthModule *self, const char *object, const char *secret) -{ - GnomeGenericAuthModuleImpl *impl = (GnomeGenericAuthModuleImpl *) self->data; - - if (strcmp(object,"password")==0) { - gtk_entry_set_text(impl->w_password,secret); - } else { - return FALSE; - } - - return TRUE; -} - -static GSList * -impl_get_secrets (GnomeGenericAuthModule *self) -{ - GnomeGenericAuthModuleImpl *impl = (GnomeGenericAuthModuleImpl *) self->data; - GSList *secrets=NULL; - - secrets = - g_slist_append(secrets, g_strdup("password")); - secrets = - g_slist_append(secrets, g_strdup(gtk_entry_get_text(impl->w_password))); - - return secrets; -} - -static const char * -impl_get_display_name (GnomeGenericAuthModule *self) -{ - return AUTH_TYPE_DISPLAY_NAME; -} - - -static const char * -impl_get_auth_type (GnomeGenericAuthModule *self) -{ - return AUTH_TYPE; -} - -static GtkWidget * -impl_get_widget (GnomeGenericAuthModule *self) -{ - GnomeGenericAuthModuleImpl *impl = (GnomeGenericAuthModuleImpl *) self->data; - - clear_widget (impl); - - return impl->widget; -} - -static GnomeGenericAuthModule* -impl_get_object (void) -{ - char *glade_file; - GnomeGenericAuthModuleImpl *impl; -// GtkWidget *w; - -g_warning("get widget"); - impl = g_new0 (GnomeGenericAuthModuleImpl, 1); - glade_file = g_strdup_printf ("%s/%s", GLADEDIR, GLADE_FILE); - impl->xml = glade_xml_new (glade_file, NULL, GETTEXT_PACKAGE); - g_free( glade_file ); - if (impl->xml != NULL) { - - impl->widget = glade_xml_get_widget(impl->xml, GLADE_WIDGET); - - /* make the widget reusable */ - g_signal_connect (GTK_OBJECT (impl->widget), "delete-event", - G_CALLBACK (gtk_widget_hide_on_delete), NULL); - - impl->w_username = GTK_ENTRY(glade_xml_get_widget(impl->xml,"username")); - impl->w_password = GTK_ENTRY(glade_xml_get_widget(impl->xml,"password")); - g_signal_connect (impl->w_username, "activate", G_CALLBACK (goto_next), impl); - g_signal_connect (impl->w_password, "activate", G_CALLBACK (goto_next), impl); - - gtk_widget_show_all(impl->widget); - clear_widget (impl); - - impl->parent.get_user = impl_get_user; - impl->parent.set_user = impl_set_user; - impl->parent.get_secrets = impl_get_secrets; - impl->parent.set_secret = impl_set_secret; - impl->parent.get_display_name = impl_get_display_name; - impl->parent.get_auth_type = impl_get_auth_type; - impl->parent.get_widget = impl_get_widget; - impl->parent.data = impl; - - return &(impl->parent); - } else { - g_free (impl); - return NULL; - } -} - - -const char * -get_auth_type (void) -{ - return AUTH_TYPE; -} - -GnomeGenericAuthModule* -gnome_generic_auth_module_factory (void) -{ - return impl_get_object(); -} - - diff --git a/vpn-daemons/pptp/auth-dialog-general/gnome-generic-auth-dialog.c b/vpn-daemons/pptp/auth-dialog-general/gnome-generic-auth-dialog.c deleted file mode 100644 index fa8efb7ac0..0000000000 --- a/vpn-daemons/pptp/auth-dialog-general/gnome-generic-auth-dialog.c +++ /dev/null @@ -1,947 +0,0 @@ -/* gnome-password-dialog.c - A use password prompting dialog widget. - - Copyright (C) 2006 - - This is free software; you can redistribute it and/or modify it under - the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This software 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this package; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. - - Authors: Antony J Mee - Based loosely on the gnome-two-password-dialog code by: - Ramiro Estrugo -*/ - -#ifdef HAVE_CONFIG_H -#include -#endif -//#include "gnome-i18nP.h" -#define GNOME_GENERIC_AUTH_MODULE_SUBJECT_TO_CHANGE -#include "gnome-generic-auth-module.h" -#include "gnome-generic-auth-dialog.h" -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -#include -#include - -#include -#include -#define GNOME_GENERIC_AUTH_DIALOG_MODULES_DIR AUTH_MODULES_DIR - -/* Layout constants */ -static const guint DIALOG_BORDER_WIDTH = 6; -//static const guint CAPTION_TABLE_BORDER_WIDTH = 4; - -struct GnomeGenericAuthDialogDetails -{ - /* Attributes */ - GSList *allowed_auth_types; - - /* Attributes */ - GSList *auth_modules; - GnomeGenericAuthModule *current_module; - - GtkWidget *remember_session_button; - GtkWidget *remember_forever_button; - - GtkWidget *current_widget; - GtkWidget *widget_holder; - GtkWidget *current_widget_old_parent; - GtkComboBox *auth_type_combo; - - - char *user; - char *domain; - char *server; - char *protocol; - guint32 port; - - gboolean found_multiple_types; - - /* TODO: */ -// gboolean can_remember_1; -// char *remember_label_text2; -// gboolean can_remember_2; -// char *remember_label_text2; - -}; - - -/* GnomeGenericAuthDialogClass methods */ -static void gnome_generic_auth_dialog_class_init (GnomeGenericAuthDialogClass *dialog); -static void gnome_generic_auth_dialog_init (GnomeGenericAuthDialog *dialog); - -/* GObjectClass methods */ -static void gnome_generic_auth_dialog_finalize (GObject *object); - - -/* GtkDialog callbacks */ -//static void dialog_show_callback (GtkWidget *widget, -// gpointer callback_data); -static void dialog_close_callback (GtkWidget *widget, - gpointer callback_data); - -static gpointer parent_class; - -GType -gnome_generic_auth_dialog_get_type (void) -{ - static GType type = 0; - - if (!type) { - static const GTypeInfo info = { - sizeof (GnomeGenericAuthDialogClass), - NULL, NULL, - (GClassInitFunc) gnome_generic_auth_dialog_class_init, - NULL, NULL, - sizeof (GnomeGenericAuthDialog), 0, - (GInstanceInitFunc) gnome_generic_auth_dialog_init, - NULL - }; - - type = g_type_register_static (gtk_dialog_get_type(), - "GnomeGenericAuthDialog", - &info, 0); - - parent_class = g_type_class_ref (gtk_dialog_get_type()); - } - - return type; -} - -static void save_to_keyring_as_needed(GnomeGenericAuthDialog *dialog) -{ - switch (gnome_generic_auth_dialog_get_remember (dialog)) - { - case GNOME_GENERIC_AUTH_DIALOG_REMEMBER_SESSION: -// save_auth_info (connection_name, service_name, "session", auth_type, username, password); - break; - case GNOME_GENERIC_AUTH_DIALOG_REMEMBER_FOREVER: -// save_auth_info (connection_name, service_name, NULL, auth_type, username, password); - break; - default: - break; - } -} - -static void load_module (GnomeGenericAuthDialog *dialog, const char *path) -{ - GModule *module; - GnomeGenericAuthModule* (*module_factory) (void) = NULL; - const char* (*module_get_auth_type) (void) = NULL; - GnomeGenericAuthModule* impl; - gboolean allowed = FALSE; - const char *provided_auth_type; - - module = g_module_open (path, G_MODULE_BIND_LAZY); - if (module == NULL) { - g_warning ("Cannot open module '%s'", path); - goto out; - } - - if (!g_module_symbol (module, "get_auth_type", - (gpointer) &module_get_auth_type)) { - g_warning ("Cannot locate function 'get_auth_type' in '%s': %s", - path, g_module_error ()); - g_module_close (module); - goto out; - } - - provided_auth_type = module_get_auth_type (); - if (dialog->details->allowed_auth_types==NULL) { - allowed=TRUE; - } else { - GSList *item; - for (item=dialog->details->allowed_auth_types; item!=NULL; item=g_slist_next(item)) { - if ((item->data!=NULL) && (strcmp(item->data,provided_auth_type)==0)) { - allowed=TRUE; - break; - } - } - } - if (!allowed) goto out; - - if (!g_module_symbol (module, "gnome_generic_auth_module_factory", - (gpointer) &module_factory)) { - g_warning ("Cannot locate function 'gnome_generic_auth_module_factory' in '%s': %s", - path, g_module_error ()); - g_module_close (module); - goto out; - } - - impl = module_factory (); - if (impl == NULL) { - g_warning ("Function 'gnome_generic_auth_widget_factory' in '%s' returned NULL", path); - g_module_close (module); - goto out; - } - -// Inflict some state upon the module! - impl->override_user=(dialog->details->user!=NULL); - impl->override_domain=(dialog->details->user!=NULL); - impl->override_server=(dialog->details->user!=NULL); - impl->override_protocol=(dialog->details->user!=NULL); - impl->override_port=(dialog->details->port!=0); - - dialog->details->auth_modules = g_slist_append (dialog->details->auth_modules, impl); - -out: - ; -} - -static void -load_all_modules (GnomeGenericAuthDialog *dialog) -{ - GDir *dir; - - /* Load all VPN UI modules by inspecting .name files */ - if ((dir = g_dir_open (GNOME_GENERIC_AUTH_DIALOG_MODULES_DIR, 0, NULL)) != NULL) { - const char *f; - - while ((f = g_dir_read_name (dir)) != NULL) { - char *so_path; -// GKeyFile *keyfile; - - if (!g_str_has_suffix (f, ".so")) - continue; - - so_path = g_strdup_printf ("%s/%s", GNOME_GENERIC_AUTH_DIALOG_MODULES_DIR, f); - - load_module (dialog, so_path); - g_free (so_path); - } - g_dir_close (dir); - } -} - -static void -gnome_generic_auth_dialog_class_init (GnomeGenericAuthDialogClass * klass) -{ - G_OBJECT_CLASS (klass)->finalize = gnome_generic_auth_dialog_finalize; -} - -static void -gnome_generic_auth_dialog_init (GnomeGenericAuthDialog *dialog) -{ - dialog->details = g_new0 (GnomeGenericAuthDialogDetails, 1); - dialog->details->auth_modules = NULL; - dialog->details->allowed_auth_types = NULL; - -// dialog->details->secondary_password_label = g_strdup ( _("_Secondary Password:") ); -} - -/* GObjectClass methods */ -static void -gnome_generic_auth_dialog_finalize (GObject *object) -{ - GnomeGenericAuthDialog *dialog; - - dialog = GNOME_GENERIC_AUTH_DIALOG (object); - -// g_object_unref (dialog->details->username_entry); -// g_object_unref (dialog->details->domain_entry); -// g_object_unref (dialog->details->password_entry); -// g_object_unref (dialog->details->password_entry_secondary); - - if (dialog->details->allowed_auth_types != NULL) { - g_slist_foreach(dialog->details->allowed_auth_types,(GFunc)g_free,NULL); - g_slist_free(dialog->details->allowed_auth_types); - } -// g_slist_foreach(dialog->details->auth_modules,(GFunc)destroy_auth_method,NULL) - if (dialog->details->auth_modules != NULL) { - g_slist_foreach(dialog->details->auth_modules,(GFunc)g_free,NULL); - g_slist_free(dialog->details->auth_modules); - } - - if (G_OBJECT_CLASS (parent_class)->finalize != NULL) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - -static void auth_widget_reparent(GnomeGenericAuthDialog *dialog, GtkWidget *new_parent) -{ - if (dialog->details->current_widget==NULL) { - if (dialog->details->current_widget_old_parent!=NULL) { - g_error("parent previously was not restored to widget"); - } - return; - } - if ((new_parent==NULL) && (dialog->details->current_widget_old_parent==NULL)) { - return; - } else if (new_parent==NULL) { - gtk_widget_reparent(dialog->details->current_widget,dialog->details->current_widget_old_parent); - dialog->details->current_widget_old_parent=NULL; - return; - } else if (dialog->details->current_widget_old_parent==NULL) { - dialog->details->current_widget_old_parent=gtk_widget_get_parent(dialog->details->current_widget); - } - - gtk_widget_reparent(dialog->details->current_widget,new_parent); -} - -static void auth_widget_get_current(GnomeGenericAuthDialog *dialog) -{ - GSList *auth_modules; - - if (dialog->details->current_widget!=NULL) { - auth_widget_reparent(dialog,NULL); - dialog->details->current_widget=NULL; - } - - auth_modules=dialog->details->auth_modules; - - if (dialog->details->current_module != NULL) { - dialog->details->current_widget = dialog->details->current_module->get_widget (dialog->details->current_module); - } -} - -static void -dialog_close_callback (GtkWidget *widget, gpointer user_data) -{ - GnomeGenericAuthDialog *dialog = (GnomeGenericAuthDialog *) user_data; - - auth_widget_reparent(dialog,NULL); - gtk_widget_hide (widget); -} - -static void -auth_type_changed_callback (GtkWidget *widget, gpointer user_data) -{ - GnomeGenericAuthDialog *dialog = (GnomeGenericAuthDialog *) user_data; - GList *i; - GList *children; - GtkWidget *w; - GSList *auth_modules; - GtkWidget *widget_holder; -// GtkWidget *widget_holder_parent; - GtkComboBox *auth_type_combo; - - auth_modules=dialog->details->auth_modules; - widget_holder = dialog->details->widget_holder; - auth_type_combo = dialog->details->auth_type_combo; - - g_return_if_fail(widget_holder!=NULL); - g_return_if_fail(GTK_IS_CONTAINER(widget_holder)); - - auth_widget_reparent(dialog,NULL); - - /* show appropriate child */ - dialog->details->current_module = (GnomeGenericAuthModule *) - g_slist_nth_data (auth_modules, - gtk_combo_box_get_active (GTK_COMBO_BOX(auth_type_combo))); - if (dialog->details->current_module == NULL) return; - - auth_widget_get_current(dialog); - auth_widget_reparent(dialog,dialog->details->widget_holder); - -// dialog->details->current_module->set_validity_changed_callback ( -// dialog->details->current_module, -// auth_widget_validity_changed, NULL); -} - -gboolean -gnome_generic_auth_dialog_set_secret (GnomeGenericAuthDialog *dialog, const char *object, const char *secret) -{ - GnomeGenericAuthModule *module; - - g_return_val_if_fail(dialog!=NULL,FALSE); - g_return_val_if_fail(dialog->details!=NULL,FALSE); - module = dialog->details->current_module; - g_return_val_if_fail(module!=NULL,FALSE); - g_return_val_if_fail(module->set_secret!=NULL,FALSE); - - return module->set_secret(module,object,secret); -} - -const char * -gnome_generic_auth_dialog_get_secret (GnomeGenericAuthDialog *dialog, const char *object) -{ - GnomeGenericAuthModule *module; - GSList *item; - GSList *secrets; - const char *secret=NULL; - - g_return_val_if_fail(dialog!=NULL,NULL); - g_return_val_if_fail(dialog->details!=NULL,NULL); - module = dialog->details->current_module; - g_return_val_if_fail(module!=NULL,NULL); - g_return_val_if_fail(module->get_secrets!=NULL,NULL); - - secrets=module->get_secrets(module); - - for(item=secrets; - (item!=NULL) && (g_slist_next(item)!=NULL) ; - item=g_slist_next(g_slist_next(item))) { - if (strcmp(object,(const char *)item->data)==0) { - secret=(const char *)(g_slist_next(item)->data); - break; - } - } - - g_slist_free(secrets); - return secret; -} - -gboolean -gnome_generic_auth_dialog_set_secrets (GnomeGenericAuthDialog *dialog, GSList *secrets) -{ - GnomeGenericAuthModule *module; - GSList *item; - gboolean result = TRUE; - const char *object; - const char *secret; - - g_return_val_if_fail(dialog!=NULL,FALSE); - g_return_val_if_fail(dialog->details!=NULL,FALSE); - module = dialog->details->current_module; - g_return_val_if_fail(module!=NULL,FALSE); - g_return_val_if_fail(module->set_secret!=NULL,FALSE); - - for(item=secrets; - (item!=NULL) && (g_slist_next(item)!=NULL) ; - item=g_slist_next(g_slist_next(item))) { - object=(const char *)(item->data); - secret=(const char *)(g_slist_next(item)->data); - result &= module->set_secret(module,object,secret); - } - return result; -} - -GSList * -gnome_generic_auth_dialog_get_secrets (GnomeGenericAuthDialog *dialog) -{ - GnomeGenericAuthModule *module; - - g_return_val_if_fail(dialog!=NULL,NULL); - g_return_val_if_fail(dialog->details!=NULL,NULL); - module = dialog->details->current_module; - g_return_val_if_fail(module!=NULL,NULL); - g_return_val_if_fail(module->get_secrets!=NULL,NULL); - - return module->get_secrets(module); -} - -gboolean -gnome_generic_auth_dialog_set_user (GnomeGenericAuthDialog *dialog, const char *user) -{ - GnomeGenericAuthModule *module; - - g_return_val_if_fail(dialog!=NULL,FALSE); - g_return_val_if_fail(dialog->details!=NULL,FALSE); - if (dialog->details->user!=NULL) return FALSE; - - module = dialog->details->current_module; - g_return_val_if_fail(module!=NULL,FALSE); - g_return_val_if_fail(module->set_user!=NULL,FALSE); - - return module->set_user(module,user); -} - -const char * -gnome_generic_auth_dialog_get_user (GnomeGenericAuthDialog *dialog) -{ - GnomeGenericAuthModule *module; - - g_return_val_if_fail(dialog!=NULL,NULL); - g_return_val_if_fail(dialog->details!=NULL,NULL); - if (dialog->details->user!=NULL) return dialog->details->user; - - module = dialog->details->current_module; - g_return_val_if_fail(module!=NULL,NULL); - g_return_val_if_fail(module->get_user!=NULL,NULL); - - return module->get_user(module); -} - -gboolean -gnome_generic_auth_dialog_set_domain (GnomeGenericAuthDialog *dialog, const char *domain) -{ - GnomeGenericAuthModule *module; - - g_return_val_if_fail(dialog!=NULL,FALSE); - g_return_val_if_fail(dialog->details!=NULL,FALSE); - if (dialog->details->domain!=NULL) return FALSE; - - module = dialog->details->current_module; - g_return_val_if_fail(module!=NULL,FALSE); - g_return_val_if_fail(module->set_domain!=NULL,FALSE); - - return module->set_domain(module,domain); -} - -const char * -gnome_generic_auth_dialog_get_domain (GnomeGenericAuthDialog *dialog) -{ - GnomeGenericAuthModule *module; - - g_return_val_if_fail(dialog!=NULL,NULL); - g_return_val_if_fail(dialog->details!=NULL,NULL); - if (dialog->details->domain!=NULL) return dialog->details->domain; - - module = dialog->details->current_module; - g_return_val_if_fail(module!=NULL,NULL); - g_return_val_if_fail(module->get_domain!=NULL,NULL); - return module->get_domain(module); -} - -gboolean -gnome_generic_auth_dialog_set_server (GnomeGenericAuthDialog *dialog, const char *server) -{ - GnomeGenericAuthModule *module; - - g_return_val_if_fail(dialog!=NULL,FALSE); - g_return_val_if_fail(dialog->details!=NULL,FALSE); - if (dialog->details->server!=NULL) return FALSE; - - module = dialog->details->current_module; - g_return_val_if_fail(module!=NULL,FALSE); - g_return_val_if_fail(module->set_server!=NULL,FALSE); - - return module->set_server(module,server); -} - -const char * -gnome_generic_auth_dialog_get_server (GnomeGenericAuthDialog *dialog) -{ - GnomeGenericAuthModule *module; - - g_return_val_if_fail(dialog!=NULL,NULL); - g_return_val_if_fail(dialog->details!=NULL,NULL); - if (dialog->details->server!=NULL) return dialog->details->server; - - module = dialog->details->current_module; - g_return_val_if_fail(module!=NULL,NULL); - g_return_val_if_fail(module->get_server!=NULL,NULL); - return module->get_server(module); -} - -gboolean -gnome_generic_auth_dialog_set_port (GnomeGenericAuthDialog *dialog, guint32 port) -{ - GnomeGenericAuthModule *module; - - g_return_val_if_fail(dialog!=NULL,FALSE); - g_return_val_if_fail(dialog->details!=NULL,FALSE); - if (dialog->details->port!=0) return FALSE; - - module = dialog->details->current_module; - g_return_val_if_fail(module!=NULL,FALSE); - g_return_val_if_fail(module->set_port!=NULL,FALSE); - - return module->set_port(module,port); -} - -guint32 -gnome_generic_auth_dialog_get_port (GnomeGenericAuthDialog *dialog) -{ - GnomeGenericAuthModule *module; - - g_return_val_if_fail(dialog!=NULL,0); - g_return_val_if_fail(dialog->details!=NULL,0); - if (dialog->details->port!=0) return dialog->details->port; - - module = dialog->details->current_module; - g_return_val_if_fail(module!=NULL,0); - g_return_val_if_fail(module->get_port!=NULL,0); - return module->get_port(module); -} - -gboolean -gnome_generic_auth_dialog_set_protocol (GnomeGenericAuthDialog *dialog, const char *protocol) -{ - GnomeGenericAuthModule *module; - - g_return_val_if_fail(dialog!=NULL,FALSE); - g_return_val_if_fail(dialog->details!=NULL,FALSE); - if (dialog->details->protocol!=NULL) return FALSE; - - module = dialog->details->current_module; - g_return_val_if_fail(module!=NULL,FALSE); - g_return_val_if_fail(module->set_protocol!=NULL,FALSE); - - return module->set_protocol(module,protocol); -} - -const char * -gnome_generic_auth_dialog_get_protocol (GnomeGenericAuthDialog *dialog) -{ - GnomeGenericAuthModule *module; - - g_return_val_if_fail(dialog!=NULL,NULL); - g_return_val_if_fail(dialog->details!=NULL,NULL); - if (dialog->details->protocol!=NULL) return dialog->details->protocol; - - module = dialog->details->current_module; - g_return_val_if_fail(module!=NULL,NULL); - g_return_val_if_fail(module->get_protocol!=NULL,NULL); - return module->get_protocol(module); -} - -const char * -gnome_generic_auth_dialog_get_auth_type (GnomeGenericAuthDialog *dialog) -{ - GnomeGenericAuthModule *module; - - g_return_val_if_fail(dialog!=NULL,NULL); - g_return_val_if_fail(dialog->details!=NULL,NULL); - module = dialog->details->current_module; - g_return_val_if_fail(dialog->details->current_module!=NULL,NULL); - - return module->get_auth_type(module); -} - -gboolean -gnome_generic_auth_dialog_set_auth_type (GnomeGenericAuthDialog *dialog, - const char *auth_type) -{ - GSList *item; - int i=0; - - g_return_val_if_fail (GNOME_IS_GENERIC_AUTH_DIALOG (dialog),FALSE); - g_return_val_if_fail (dialog->details->auth_type_combo != NULL,FALSE); - - for (item = dialog->details->auth_modules; item != NULL; item = g_slist_next (item)) { - GnomeGenericAuthModule *auth_module = (GnomeGenericAuthModule *)item->data; - if (strcmp(auth_type,auth_module->get_auth_type(auth_module))==0) { - gtk_combo_box_set_active (dialog->details->auth_type_combo, i); - return TRUE; - } - i++; - } - return FALSE; -} - - -gboolean -gnome_generic_auth_dialog_lookup_in_keyring (GnomeGenericAuthDialog *dialog) { - GList *keyring_result; - GList *item; - const char *auth_type=NULL; - GnomeKeyringNetworkPasswordData *data; - const char *previous_auth_type=NULL; - const char *first_auth_type=NULL; - GnomeGenericAuthModule *module; - - - g_return_val_if_fail (GNOME_IS_GENERIC_AUTH_DIALOG (dialog),FALSE); - - if (dialog->details->current_module!=NULL) - auth_type = gnome_generic_auth_dialog_get_auth_type(dialog); - if (auth_type==NULL) dialog->details->found_multiple_types=FALSE; - - if (gnome_keyring_find_network_password_sync (dialog->details->user, - dialog->details->domain, - dialog->details->server, - NULL, /* object */ - dialog->details->protocol, - auth_type, - dialog->details->port, - &keyring_result) != GNOME_KEYRING_RESULT_OK) - return FALSE; -// if (dialog->details->found_keys != NULL) -// gnome_keyring_network_password_list_free (dialog->details->found_keys); -// found_keys=NULL; - - // Find the first auth_type we are allowed to use - first_auth_type=NULL; - for (item = keyring_result; item != NULL; item=g_list_next(item)) { - data = (GnomeKeyringNetworkPasswordData *)item->data; - if (gnome_generic_auth_dialog_set_auth_type(dialog,data->authtype)) { - if (first_auth_type==NULL) first_auth_type=data->authtype; - if ((previous_auth_type!=NULL) && - (strcmp(previous_auth_type,data->authtype)!=0)) { - dialog->details->found_multiple_types=TRUE; - break; - } - } - } - - if (first_auth_type==NULL) { - gnome_keyring_network_password_list_free (keyring_result); - return FALSE; - } - - gnome_generic_auth_dialog_set_auth_type(dialog,first_auth_type); - module = dialog->details->current_module; - - for (item = keyring_result; item != NULL; item=g_list_next(item)) { - data = (GnomeKeyringNetworkPasswordData *)item->data; - if (strcmp(data->authtype,first_auth_type)==0) { - if (data->user!=NULL) gnome_generic_auth_dialog_set_user(dialog, data->user); - if (data->server!=NULL) gnome_generic_auth_dialog_set_server(dialog, data->server); - if (data->domain!=NULL) gnome_generic_auth_dialog_set_domain(dialog, data->domain); - if (data->protocol!=NULL) gnome_generic_auth_dialog_set_protocol(dialog, data->protocol); - if (data->port!=0) gnome_generic_auth_dialog_set_port(dialog, data->port); - if (data->object!=NULL || data->password!=NULL) - gnome_generic_auth_dialog_set_secret(dialog, data->object, data->password); - if (strcmp(data->keyring,"session")==0) - gnome_generic_auth_dialog_set_remember (dialog, GNOME_GENERIC_AUTH_DIALOG_REMEMBER_SESSION); - else - gnome_generic_auth_dialog_set_remember (dialog, GNOME_GENERIC_AUTH_DIALOG_REMEMBER_FOREVER); - - - } - } - - gnome_keyring_network_password_list_free (keyring_result); - return TRUE; -} - -/* Public GnomeGenericAuthDialog methods */ -GtkWidget * -gnome_generic_auth_dialog_new (const char *dialog_title, - const char *message, - const char *user, - const char *domain, - const char *server, - const char *protocol, - guint32 port, - const char **allowed_types) -{ - GnomeGenericAuthDialog *dialog; - GtkWidget *widget_holder; - GtkLabel *message_label; - GtkLabel *auth_type_label; - GtkWidget *auth_type_hbox; - GtkComboBox *auth_type_combo_box; - GtkWidget *hbox; - GtkWidget *vbox; - GtkWidget *dialog_icon; - GSList *allowed_auth_types=NULL; - GSList *item; - const char **types; - - dialog = GNOME_GENERIC_AUTH_DIALOG (gtk_widget_new (gnome_generic_auth_dialog_get_type (), NULL)); - - dialog->details->user=NULL; - dialog->details->server=NULL; - dialog->details->protocol=NULL; - dialog->details->domain=NULL; - dialog->details->port=0; - if (user!=NULL) dialog->details->user=g_strdup(user); - if (server!=NULL) dialog->details->server=g_strdup(server); - if (protocol!=NULL) dialog->details->protocol=g_strdup(protocol); - if (domain!=NULL) dialog->details->domain=g_strdup(domain); - if (port!=0) dialog->details->port=port; - - if (allowed_types!=NULL) { - for (types=allowed_types; *types !=NULL; *types++) { - allowed_auth_types=g_slist_append(allowed_auth_types,g_strdup(*types)); - } - dialog->details->allowed_auth_types = allowed_auth_types; - } - - load_all_modules(dialog); - - if (dialog->details->auth_modules==NULL) { - g_warning("gnome-generic-auth-dialog: Cannot find any authentication modules!"); - g_free(dialog); - return NULL; - } - - gtk_window_set_title (GTK_WINDOW (dialog), dialog_title); - gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); - gtk_dialog_add_buttons (GTK_DIALOG (dialog), - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, - NULL); - - /* Setup the dialog */ - gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); - - gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); - gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); - - gtk_container_set_border_width (GTK_CONTAINER (dialog), DIALOG_BORDER_WIDTH); - - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); - -// g_signal_connect (dialog, "show", -// G_CALLBACK (dialog_show_callback), dialog); - g_signal_connect (dialog, "close", - G_CALLBACK (dialog_close_callback), dialog); - - /* The table that holds the captions */ -// Get the current auth_widget. - widget_holder = gtk_hbox_new(FALSE,0); - g_object_ref (widget_holder); - dialog->details->widget_holder = GTK_WIDGET(widget_holder); - - /* fill in possibly choices in the druid when adding a connection */ - auth_type_hbox = gtk_hbox_new(FALSE,6); - auth_type_label = GTK_LABEL (gtk_label_new (_("Authentication Type:"))); - gtk_label_set_justify (auth_type_label, GTK_JUSTIFY_LEFT); - gtk_label_set_line_wrap (auth_type_label, TRUE); - - gtk_box_pack_start (GTK_BOX (auth_type_hbox), - GTK_WIDGET (auth_type_label), - TRUE, /* expand */ - TRUE, /* fill */ - 5); /* padding */ - auth_type_combo_box = GTK_COMBO_BOX(gtk_combo_box_new_text ()); - dialog->details->auth_type_combo = auth_type_combo_box; - for (item = dialog->details->auth_modules; item != NULL; item = g_slist_next (item)) { - GnomeGenericAuthModule *auth_module = (GnomeGenericAuthModule *)item->data; - gtk_combo_box_append_text (GTK_COMBO_BOX(auth_type_combo_box), auth_module->get_display_name(auth_module)); - } - g_signal_connect (auth_type_combo_box, "changed", - G_CALLBACK (auth_type_changed_callback), (gpointer) dialog); - gtk_box_pack_end (GTK_BOX (auth_type_hbox), GTK_WIDGET(auth_type_combo_box), TRUE, TRUE, 0); - - //g_object_unref (widget_holder); - - - /* Adds some eye-candy to the dialog */ - hbox = gtk_hbox_new (FALSE, 12); - dialog_icon = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION, GTK_ICON_SIZE_DIALOG); - gtk_misc_set_alignment (GTK_MISC (dialog_icon), 0.5, 0.0); - gtk_box_pack_start (GTK_BOX (hbox), dialog_icon, FALSE, FALSE, 0); - - gtk_box_set_spacing (GTK_BOX (GTK_DIALOG(dialog)->vbox), 12); - gtk_container_set_border_width (GTK_CONTAINER(hbox), 6); - gtk_box_set_spacing (GTK_BOX (hbox), 12); - - /* Fills the vbox */ - vbox = gtk_vbox_new (FALSE, 0); - - if (message) { - message_label = GTK_LABEL (gtk_label_new (message)); - gtk_label_set_justify (message_label, GTK_JUSTIFY_LEFT); - gtk_label_set_line_wrap (message_label, TRUE); - - gtk_box_pack_start (GTK_BOX (vbox), - GTK_WIDGET (message_label), - TRUE, /* expand */ - TRUE, /* fill */ - 5); /* padding */ - } - -// THe following will be the widget from the plugin! - gtk_box_pack_start (GTK_BOX (vbox), auth_type_hbox, - TRUE, TRUE, 5); - gtk_box_pack_start (GTK_BOX (vbox), widget_holder, - TRUE, TRUE, 5); - - - gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 5); - - gtk_box_pack_start (GTK_BOX (GTK_DIALOG(dialog)->vbox), - hbox, - TRUE, /* expand */ - TRUE, /* fill */ - 0); /* padding */ - - gtk_widget_show (GTK_DIALOG (dialog)->vbox); - - dialog->details->remember_session_button = - gtk_check_button_new_with_mnemonic (_("_Remember for this session")); - dialog->details->remember_forever_button = - gtk_check_button_new_with_mnemonic (_("_Save in keyring")); - - gtk_box_pack_start (GTK_BOX (vbox), dialog->details->remember_session_button, - TRUE, TRUE, 6); - gtk_box_pack_start (GTK_BOX (vbox), dialog->details->remember_forever_button, - TRUE, TRUE, 0); - - if (!gnome_generic_auth_dialog_lookup_in_keyring(dialog)) { - g_warning("Lookup failed"); - gtk_combo_box_set_active (auth_type_combo_box, 0); - } - - return GTK_WIDGET (dialog); -} - -gboolean -gnome_generic_auth_dialog_run_and_block (GnomeGenericAuthDialog *dialog) -{ - gint button_clicked; - - g_return_val_if_fail (dialog != NULL, FALSE); - g_return_val_if_fail (GNOME_IS_GENERIC_AUTH_DIALOG (dialog), FALSE); - - button_clicked = gtk_dialog_run (GTK_DIALOG (dialog)); - - save_to_keyring_as_needed(dialog); - - auth_widget_reparent(dialog,NULL); - gtk_widget_hide (GTK_WIDGET (dialog)); - - return button_clicked == GTK_RESPONSE_OK; -} - -GnomeKeyringNetworkPasswordData * -gnome_generic_auth_dialog_get_password_data (GnomeGenericAuthDialog *dialog) -{ - g_return_val_if_fail (GNOME_IS_GENERIC_AUTH_DIALOG (dialog), NULL); - -// return g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->details->username_entry))); - return NULL; -} - -void -gnome_generic_auth_dialog_set_show_remember (GnomeGenericAuthDialog *dialog, - gboolean show_remember) -{ - if (show_remember) { - gtk_widget_show (dialog->details->remember_session_button); - gtk_widget_show (dialog->details->remember_forever_button); - } else { - gtk_widget_hide (dialog->details->remember_session_button); - gtk_widget_hide (dialog->details->remember_forever_button); - } -} - -void -gnome_generic_auth_dialog_set_remember (GnomeGenericAuthDialog *dialog, - GnomeGenericAuthDialogRemember remember) -{ - gboolean session, forever; - - session = FALSE; - forever = FALSE; - if (remember == GNOME_GENERIC_AUTH_DIALOG_REMEMBER_SESSION) { - session = TRUE; - } else if (remember == GNOME_GENERIC_AUTH_DIALOG_REMEMBER_FOREVER){ - forever = TRUE; - } - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->details->remember_session_button), - session); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->details->remember_forever_button), - forever); -} - -GnomeGenericAuthDialogRemember -gnome_generic_auth_dialog_get_remember (GnomeGenericAuthDialog *dialog) -{ - gboolean session, forever; - - session = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->details->remember_session_button)); - forever = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->details->remember_forever_button)); - if (forever) { - return GNOME_GENERIC_AUTH_DIALOG_REMEMBER_FOREVER; - } else if (session) { - return GNOME_GENERIC_AUTH_DIALOG_REMEMBER_SESSION; - } - return GNOME_GENERIC_AUTH_DIALOG_REMEMBER_NOTHING; -} - diff --git a/vpn-daemons/pptp/auth-dialog-general/gnome-generic-auth-dialog.h b/vpn-daemons/pptp/auth-dialog-general/gnome-generic-auth-dialog.h deleted file mode 100644 index 096a303442..0000000000 --- a/vpn-daemons/pptp/auth-dialog-general/gnome-generic-auth-dialog.h +++ /dev/null @@ -1,105 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ - -/* gnome-generic-auth-dialog.h - A use a dialog widget with a combo - * selection box to choose a sub-widget - * which in turn then provides appropriate - * widgets for a particular type of - * authentication - Based of gnome-two-password-dialog.[ch] - from the Gnome Library. - - This is free software; you can redistribute it and/or modify it under - the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This software 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the Gnome Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. - - Authors: Antony J Mee -*/ - -#ifndef GNOME_GENERIC_AUTH_DIALOG_H -#define GNOME_GENERIC_AUTH_DIALOG_H - -#include - -G_BEGIN_DECLS - -#define GNOME_TYPE_GENERIC_AUTH_DIALOG (gnome_generic_auth_dialog_get_type ()) -#define GNOME_GENERIC_AUTH_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_TYPE_GENERIC_AUTH_DIALOG, GnomeGenericAuthDialog)) -#define GNOME_GENERIC_AUTH_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_TYPE_GENERIC_AUTH_DIALOG, GnomeGenericAuthDialogClass)) -#define GNOME_IS_GENERIC_AUTH_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_TYPE_GENERIC_AUTH_DIALOG)) -#define GNOME_IS_GENERIC_AUTH_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_GENERIC_AUTH_DIALOG)) - -typedef struct GnomeGenericAuthDialog GnomeGenericAuthDialog; -typedef struct GnomeGenericAuthDialogClass GnomeGenericAuthDialogClass; -typedef struct GnomeGenericAuthDialogDetails GnomeGenericAuthDialogDetails; - -struct GnomeGenericAuthDialog -{ - GtkDialog gtk_dialog; - - GnomeGenericAuthDialogDetails *details; -}; - -struct GnomeGenericAuthDialogClass -{ - GtkDialogClass parent_class; -}; - -typedef enum { - GNOME_GENERIC_AUTH_DIALOG_REMEMBER_NOTHING, - GNOME_GENERIC_AUTH_DIALOG_REMEMBER_SESSION, - GNOME_GENERIC_AUTH_DIALOG_REMEMBER_FOREVER -} GnomeGenericAuthDialogRemember; - - -GType gnome_generic_auth_dialog_get_type (void); -GtkWidget *gnome_generic_auth_dialog_new (const char *dialog_title, - const char *message, - const char *user, - const char *domain, - const char *server, - const char *protocol, - guint32 port, - const char **allowed_types); - -gboolean gnome_generic_auth_dialog_run_and_block (GnomeGenericAuthDialog *dialog); - -/* Attribute mutators */ -gboolean gnome_generic_auth_dialog_set_auth_type (GnomeGenericAuthDialog *dialog, const char *auth_type); -gboolean gnome_generic_auth_dialog_set_user (GnomeGenericAuthDialog *dialog, const char *user); -gboolean gnome_generic_auth_dialog_set_server (GnomeGenericAuthDialog *dialog, const char *server); -gboolean gnome_generic_auth_dialog_set_domain (GnomeGenericAuthDialog *dialog, const char *domain); -gboolean gnome_generic_auth_dialog_set_protocol (GnomeGenericAuthDialog *dialog, const char *protocol); -gboolean gnome_generic_auth_dialog_set_port (GnomeGenericAuthDialog *dialog, guint32 port); - -//void gnome_generic_auth_dialog_set_allowed_auth_types (GnomeGenericAuthDialog *dialog, -// GSList *allowed_auth_types); - -void gnome_generic_auth_dialog_set_show_remember (GnomeGenericAuthDialog *dialog, - gboolean show_remember); -void gnome_generic_auth_dialog_set_remember (GnomeGenericAuthDialog *dialog, - GnomeGenericAuthDialogRemember remember); -GnomeGenericAuthDialogRemember gnome_generic_auth_dialog_get_remember (GnomeGenericAuthDialog *dialog); - -/* Attribute accessors */ -const char *gnome_generic_auth_dialog_get_auth_type (GnomeGenericAuthDialog *dialog); -const char *gnome_generic_auth_dialog_get_user (GnomeGenericAuthDialog *dialog); -const char *gnome_generic_auth_dialog_get_domain (GnomeGenericAuthDialog *dialog); -const char *gnome_generic_auth_dialog_get_server (GnomeGenericAuthDialog *dialog); -const char *gnome_generic_auth_dialog_get_protocol (GnomeGenericAuthDialog *dialog); -guint32 gnome_generic_auth_dialog_get_port (GnomeGenericAuthDialog *dialog); -GSList *gnome_generic_auth_dialog_get_secrets (GnomeGenericAuthDialog *dialog); - -G_END_DECLS - -#endif /* GNOME_GENERIC_AUTH_DIALOG_H */ diff --git a/vpn-daemons/pptp/auth-dialog-general/gnome-generic-auth-module.h b/vpn-daemons/pptp/auth-dialog-general/gnome-generic-auth-module.h deleted file mode 100644 index 52cecc7040..0000000000 --- a/vpn-daemons/pptp/auth-dialog-general/gnome-generic-auth-module.h +++ /dev/null @@ -1,106 +0,0 @@ -/*************************************************************************** - * CVSID: $Id$ - * - * gnome-generic-auth-widget.h : Public interface for generic auth widgets - * - * Copyright (C) 2006 Antony J Mee, - * - * === - * NOTE NOTE NOTE: All source for nm-vpn-properties is licensed to you - * under your choice of the Academic Free License version 2.0, or the - * GNU General Public License version 2. - * === - * - * Licensed under the Academic Free License version 2.0 - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - **************************************************************************/ - -#ifndef GNOME_GENERIC_AUTH_MODULE_H -#define GNOME_GENERIC_AUTH_MODULE_H - -#ifndef GNOME_GENERIC_AUTH_MODULE_SUBJECT_TO_CHANGE -#error "Please define GNOME_GENERIC_AUTH_MODULE_SUBJECT_TO_CHANGE to acknowledge your understanding that NetworkManager hasn't reached 1.0 and is subject to protocol and API churn. See the README for a full explanation." - -#endif - - - -#include -#include - -struct _GnomeGenericAuthModule; -typedef struct _GnomeGenericAuthModule GnomeGenericAuthModule; - -typedef void (*GnomeGenericAuthModuleValidityCallback) (GnomeGenericAuthModule *self, - gboolean is_valid, - gpointer user_data); - -struct _GnomeGenericAuthModule { - const char *(*get_display_name) (GnomeGenericAuthModule *self); - const char *(*get_auth_type) (GnomeGenericAuthModule *self); - const char *(*get_domain) (GnomeGenericAuthModule *self); - const char *(*get_server) (GnomeGenericAuthModule *self); - const char *(*get_protocol) (GnomeGenericAuthModule *self); - const char *(*get_user) (GnomeGenericAuthModule *self); - GSList *(*get_secrets) (GnomeGenericAuthModule *self); - guint32 (*get_port) (GnomeGenericAuthModule *self); - - gboolean (*set_domain) (GnomeGenericAuthModule *self, const char *domain); - gboolean (*set_user) (GnomeGenericAuthModule *self, const char *user); - gboolean (*set_server) (GnomeGenericAuthModule *self, const char *server); - gboolean (*set_protocol) (GnomeGenericAuthModule *self, const char *protocol); - gboolean (*set_port) (GnomeGenericAuthModule *self, guint32 port); - gboolean (*set_secret) (GnomeGenericAuthModule *self, const char *object, const char *secret); - - GtkWidget *(*get_widget) (GnomeGenericAuthModule *self); - - gboolean override_user; - gboolean override_domain; - gboolean override_server; - gboolean override_protocol; - gboolean override_port; - - -// void (*set_validity_changed_callback) (GnomeGenericAuthModule *self, -// GnomeGenericAuthModuleValidityCallback cb, -// gpointer user_data); - -// gboolean (*is_valid) (GnomeGenericAuthModule *self); - - /* - * get_confirmation_details: - * retval is allocated and must be freed - */ -// void (*get_confirmation_details)(GnomeGenericAuthModule *self, gchar **retval); - -// char *(*get_connection_name) (GnomeGenericAuthModule *self); - -// GSList *(*get_properties) (GnomeGenericAuthModule *self); - -// GSList *(*get_routes) (GnomeGenericAuthModule *self); - -// gboolean (*can_export) (GnomeGenericAuthModule *self); - -// gboolean (*import_file) (GnomeGenericAuthModule *self, const char *path); - -// gboolean (*export) (GnomeGenericAuthModule *self, GSList *properties, GSList *routes, const char *connection_name); - - gpointer data; -}; - -#endif /* GNOME_GENERIC_AUTH_MODULE_H */ - diff --git a/vpn-daemons/pptp/auth-dialog-general/keyring.png b/vpn-daemons/pptp/auth-dialog-general/keyring.png deleted file mode 100644 index caade38ad3..0000000000 Binary files a/vpn-daemons/pptp/auth-dialog-general/keyring.png and /dev/null differ diff --git a/vpn-daemons/pptp/auth-dialog-general/main.c b/vpn-daemons/pptp/auth-dialog-general/main.c deleted file mode 100644 index 28b5e4c00a..0000000000 --- a/vpn-daemons/pptp/auth-dialog-general/main.c +++ /dev/null @@ -1,169 +0,0 @@ -/* NetworkManager Wireless Applet -- Display wireless access points and allow user control - * - * Dan Williams - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * (C) Copyright 2004 Red Hat, Inc. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include - -#include "gnome-generic-auth-dialog.h" - -#define SERVICE_NAME "org.freedesktop.NetworkManager.ppp_starter" - -static GSList * -get_passwords (const char *connection_name, const char *service_name, gboolean retry) -{ - GSList *result; - char *prompt; - GnomeGenericAuthDialog *dialog; -// GnomeGenericAuthDialogRemember remember; - - result = NULL; - - g_return_val_if_fail (connection_name != NULL, NULL); - - prompt = g_strdup_printf (_("You need to authenticate to access '%s'."), connection_name); - dialog = GNOME_GENERIC_AUTH_DIALOG( - gnome_generic_auth_dialog_new ( - _("Authenticate Connection"), - prompt, - NULL, /* User */ - NULL, /* Domain */ - connection_name, /* Server - fixed */ - service_name, /* Protocol - Fixed */ - 0, /* Port - can vary */ - NULL /* Allowed auth types */ - )); - if (dialog==NULL) { - return NULL; - } - g_free (prompt); - - gnome_generic_auth_dialog_set_show_remember (dialog, TRUE); - //gnome_generic_auth_dialog_set_remember (dialog, GNOME_GENERIC_AUTH_DIALOG_REMEMBER_NOTHING); - - gtk_widget_show (GTK_WIDGET(dialog)); - - if (gnome_generic_auth_dialog_run_and_block (dialog)) - { - GSList *secrets; - GSList *item; - const char *username; -// char *password; - const char *auth_type; - - username = gnome_generic_auth_dialog_get_user (dialog); - auth_type = gnome_generic_auth_dialog_get_auth_type (dialog); - secrets = gnome_generic_auth_dialog_get_secrets (dialog); - - result = g_slist_append (result, g_strdup(auth_type)); - result = g_slist_append (result, g_strdup(username)); - - for (item=secrets; item!=NULL; item=g_slist_next(item)) - { - g_free(item->data); - item = g_slist_next(item); - result = g_slist_append (result, item->data); - } - g_slist_free(secrets); - - } - - gtk_widget_destroy (GTK_WIDGET(dialog)); - return result; -} - -int -main (int argc, char *argv[]) -{ - GSList *i; - GSList *passwords; - static gboolean retry = FALSE; - static gchar *connection_name = NULL; - static gchar *auth_types = NULL; - static gchar *service_name = NULL; - GError *error = NULL; - GOptionContext *context; - GnomeProgram *program; - GOptionEntry entries[] = - { - { "reprompt", 'r', 0, G_OPTION_ARG_NONE, &retry, "Reprompt for passwords", NULL}, - { "name", 'n', 0, G_OPTION_ARG_STRING, &connection_name, "Name of connection", NULL}, - { "service", 's', 0, G_OPTION_ARG_STRING, &service_name, "Service type", NULL}, - { "authtype", 'a', 0, G_OPTION_ARG_STRING_ARRAY, &auth_types, "Authentication Types", NULL}, - { NULL } - }; - char buf[1]; - - bindtextdomain (GETTEXT_PACKAGE, NULL); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - passwords = NULL; - - context = g_option_context_new ("- ppp auth dialog"); - g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); - - program = gnome_program_init ("nm-ppp-auth-dialog", VERSION, - LIBGNOMEUI_MODULE, - argc, argv, - GNOME_PARAM_GOPTION_CONTEXT, context, - GNOME_PARAM_NONE); - - if (connection_name == NULL || service_name == NULL) { - fprintf (stderr, "Have to supply both name and service\n"); - goto out; - } - - if (strcmp (service_name, SERVICE_NAME) != 0) { - fprintf (stderr, "This dialog only works with the '%s' service\n", SERVICE_NAME); - goto out; - } - - passwords = get_passwords (connection_name, service_name, retry); - if (passwords == NULL) - goto out; - - /* dump the passwords to stdout */ - for (i = passwords; i != NULL; i = g_slist_next (i)) { - char *password = (char *) i->data; - printf ("%s\n", password); - } - printf ("\n\n"); - /* for good measure, flush stdout since Kansas is going Bye-Bye */ - fflush (stdout); - - g_slist_foreach (passwords, (GFunc)g_free, NULL); - g_slist_free (passwords); - - /* wait for data on stdin */ - fread (buf, sizeof (char), sizeof (buf), stdin); - -out: - g_object_unref (program); - - return passwords != NULL ? 0 : 1; -} diff --git a/vpn-daemons/pptp/auth-dialog-general/mschapv2-auth-module.c b/vpn-daemons/pptp/auth-dialog-general/mschapv2-auth-module.c deleted file mode 100644 index 428a59fbce..0000000000 --- a/vpn-daemons/pptp/auth-dialog-general/mschapv2-auth-module.c +++ /dev/null @@ -1,190 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include - -#define GNOME_GENERIC_AUTH_MODULE_SUBJECT_TO_CHANGE -#include "gnome-generic-auth-module.h" - -/* Stuff to be provided by the specific instance */ -typedef struct _GnomeGenericAuthModuleImpl GnomeGenericAuthModuleImpl; - -struct _GnomeGenericAuthModuleImpl { - GnomeGenericAuthModule parent; - - GladeXML *xml; - - GtkWidget *widget; - - GtkEntry *w_remotename; - GtkEntry *w_username; - GtkEntry *w_password; - -}; - -#define GLADE_FILE "nm-ppp-auth.glade" -#define GLADE_WIDGET "auth-mschapv2-widget" - -#define AUTH_TYPE "MSCHAPV2" -#define AUTH_TYPE_DISPLAY_NAME "MS CHAP V2" - - -static void -clear_widget (GnomeGenericAuthModuleImpl *impl) -{ - gtk_entry_set_text(impl->w_username,""); - gtk_entry_set_text(impl->w_password,""); - gtk_widget_grab_focus (GTK_WIDGET(impl->w_username)); -} - -static void -goto_next (GtkWidget *widget,gpointer data) -{ - GnomeGenericAuthModuleImpl *impl = (GnomeGenericAuthModuleImpl *) data; -g_warning("Goto next!"); - if (strcmp(gtk_widget_get_name(widget),"remotename")==0) { - gtk_widget_grab_focus (GTK_WIDGET(impl->w_username)); - } else if (strcmp(gtk_widget_get_name(widget),"username")==0) { - gtk_widget_grab_focus (GTK_WIDGET(impl->w_password)); - } else if (strcmp(gtk_widget_get_name(widget),"password")==0) { - } -} - -static gboolean -impl_set_user (GnomeGenericAuthModule *self, const char *user) -{ - GnomeGenericAuthModuleImpl *impl = (GnomeGenericAuthModuleImpl *) self->data; - - gtk_entry_set_text(impl->w_username,user); - return TRUE; -} - -static const char * -impl_get_user (GnomeGenericAuthModule *self) -{ - GnomeGenericAuthModuleImpl *impl = (GnomeGenericAuthModuleImpl *) self->data; - - return gtk_entry_get_text(impl->w_username); -} - -static gboolean -impl_set_secret (GnomeGenericAuthModule *self, const char *object, const char *secret) -{ - GnomeGenericAuthModuleImpl *impl = (GnomeGenericAuthModuleImpl *) self->data; - -g_warning("Setting secret: %s=%s",object,secret); - if (strcmp(object,"remotename")==0) { - gtk_entry_set_text(impl->w_remotename,secret); - } else if (strcmp(object,"password")==0) { - gtk_entry_set_text(impl->w_password,secret); - } else { - return FALSE; - } - - return TRUE; -} - -static GSList * -impl_get_secrets (GnomeGenericAuthModule *self) -{ - GnomeGenericAuthModuleImpl *impl = (GnomeGenericAuthModuleImpl *) self->data; - GSList *secrets=NULL; - - secrets = - g_slist_append(secrets, g_strdup("password")); - secrets = - g_slist_append(secrets, g_strdup(gtk_entry_get_text(impl->w_password))); - secrets = - g_slist_append(secrets, g_strdup("remotename")); - secrets = - g_slist_append(secrets, g_strdup(gtk_entry_get_text(impl->w_remotename))); - - return secrets; -} - -static const char * -impl_get_display_name (GnomeGenericAuthModule *self) -{ - return AUTH_TYPE_DISPLAY_NAME; -} - - -static const char * -impl_get_auth_type (GnomeGenericAuthModule *self) -{ - return AUTH_TYPE; -} - -static GtkWidget * -impl_get_widget (GnomeGenericAuthModule *self) -{ - GnomeGenericAuthModuleImpl *impl = (GnomeGenericAuthModuleImpl *) self->data; - - clear_widget (impl); - - return impl->widget; -} - -static GnomeGenericAuthModule* -impl_get_object (void) -{ - char *glade_file; - GnomeGenericAuthModuleImpl *impl; -// GtkWidget *w; - - impl = g_new0 (GnomeGenericAuthModuleImpl, 1); - glade_file = g_strdup_printf ("%s/%s", GLADEDIR, GLADE_FILE); - impl->xml = glade_xml_new (glade_file, NULL, GETTEXT_PACKAGE); - g_free( glade_file ); - if (impl->xml != NULL) { - - impl->widget = glade_xml_get_widget(impl->xml, GLADE_WIDGET); - - /* make the widget reusable */ - g_signal_connect (GTK_OBJECT (impl->widget), "delete-event", - G_CALLBACK (gtk_widget_hide_on_delete), NULL); - - impl->w_remotename = GTK_ENTRY(glade_xml_get_widget(impl->xml,"remotename")); - impl->w_username = GTK_ENTRY(glade_xml_get_widget(impl->xml,"username")); - impl->w_password = GTK_ENTRY(glade_xml_get_widget(impl->xml,"password")); - - g_signal_connect (impl->w_remotename, "activate", G_CALLBACK (goto_next), impl); - g_signal_connect (impl->w_username, "activate", G_CALLBACK (goto_next), impl); - g_signal_connect (impl->w_password, "activate", G_CALLBACK (goto_next), impl); - - gtk_widget_show_all(impl->widget); - clear_widget (impl); - - impl->parent.get_user = impl_get_user; - impl->parent.set_user = impl_set_user; - impl->parent.get_secrets = impl_get_secrets; - impl->parent.set_secret = impl_set_secret; - impl->parent.get_display_name = impl_get_display_name; - impl->parent.get_auth_type = impl_get_auth_type; - impl->parent.get_widget = impl_get_widget; - impl->parent.data = impl; - - return &(impl->parent); - } else { - g_free (impl); - return NULL; - } -} - - -const char * -get_auth_type (void) -{ - return AUTH_TYPE; -} - -GnomeGenericAuthModule* -gnome_generic_auth_module_factory (void) -{ - return impl_get_object(); -} - - diff --git a/vpn-daemons/pptp/auth-dialog-general/nm-ppp-auth.glade b/vpn-daemons/pptp/auth-dialog-general/nm-ppp-auth.glade deleted file mode 100644 index 0bf9474fb3..0000000000 --- a/vpn-daemons/pptp/auth-dialog-general/nm-ppp-auth.glade +++ /dev/null @@ -1,594 +0,0 @@ - - - - - - - - 5 - Authentication Required - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_CENTER_ALWAYS - True - False - False - True - False - False - GDK_WINDOW_TYPE_HINT_DIALOG - GDK_GRAVITY_NORTH_WEST - False - - - - True - False - 0 - - - - True - GTK_BUTTONBOX_END - - - - True - True - True - gtk-cancel - True - GTK_RELIEF_NORMAL - True - -6 - - - - - - True - True - True - gtk-ok - True - GTK_RELIEF_NORMAL - True - -5 - - - - - 0 - False - True - GTK_PACK_END - - - - - - True - False - 12 - - - - True - 0.5 - 0 - 0 - 0 - - - 0 - False - True - - - - - - True - False - 12 - - - - True - <span weight="bold" size="larger">Authentication Information</span> - -The connection '%s' may need some form of authentication. - -Please select an appropriate authentication type and provide the necessary credentials below: - - False - True - GTK_JUSTIFY_LEFT - True - False - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - False - 0 - - - - True - _Authentication Type: - True - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - auth-type - - - 0 - False - False - - - - - - True - True - - - 0 - True - True - - - - - 0 - True - True - - - - - - - - - - True - 0.5 - 0.5 - 1 - 1 - 0 - 0 - 80 - 21 - - - - True - False - 0 - - - - True - True - _Remember for this session - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - False - False - - - - - - True - True - _Save in keyring - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - False - False - - - - - - - 0 - True - True - - - - - 0 - True - True - - - - - 0 - True - True - - - - - - - - 2 - 82 - 116 - auth-none-window - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - False - False - True - False - False - GDK_WINDOW_TYPE_HINT_NORMAL - GDK_GRAVITY_NORTH_WEST - - - - True - - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - - - - - - 12 - auth-chap-window - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - False - False - True - False - False - GDK_WINDOW_TYPE_HINT_NORMAL - GDK_GRAVITY_NORTH_WEST - - - - True - False - 0 - - - - True - 2 - 2 - False - 12 - 12 - - - - True - _Username: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - username - - - 0 - 1 - 0 - 1 - fill - - - - - - - True - _Password: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - password - - - 0 - 1 - 1 - 2 - fill - - - - - - - True - True - True - True - 0 - - True - * - False - - - 1 - 2 - 0 - 1 - - - - - - - True - True - True - False - 0 - - True - * - False - - - 1 - 2 - 1 - 2 - - - - - - 0 - True - True - - - - - - - - auth-mschapv2-window - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - False - False - True - False - False - GDK_WINDOW_TYPE_HINT_NORMAL - GDK_GRAVITY_NORTH_WEST - - - - 6 - True - False - 0 - - - - True - 3 - 2 - False - 12 - 12 - - - - True - _Password: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - password - - - 0 - 1 - 2 - 3 - fill - - - - - - - True - True - True - False - 0 - - True - * - False - - - 1 - 2 - 2 - 3 - - - - - - - True - True - True - True - 0 - - True - * - False - - - 1 - 2 - 1 - 2 - - - - - - - True - _Username: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - username - - - 0 - 1 - 1 - 2 - fill - - - - - - - True - _Remote name: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - remotename - - - 0 - 1 - 0 - 1 - fill - - - - - - - True - True - True - True - 0 - - True - * - False - - - 1 - 2 - 0 - 1 - - - - - - 0 - True - True - - - - - - - diff --git a/vpn-daemons/pptp/auth-dialog/Makefile.am b/vpn-daemons/pptp/auth-dialog/Makefile.am index b0aebb23a7..1afa647b98 100644 --- a/vpn-daemons/pptp/auth-dialog/Makefile.am +++ b/vpn-daemons/pptp/auth-dialog/Makefile.am @@ -1,8 +1,9 @@ -INCLUDES = -I${top_srcdir} -I${top_srcdir}/utils +INCLUDES = -I${top_srcdir} -libexec_PROGRAMS = nm-ppp-auth-dialog +libexec_PROGRAMS = nm-pptp-auth-dialog -nm_ppp_auth_dialog_CPPFLAGS = \ +nm_pptp_auth_dialog_CPPFLAGS = \ + $(NM_UTILS_CFLAGS) \ $(GTHREAD_CFLAGS) \ $(GTK_CFLAGS) \ $(LIBGNOMEUI_CFLAGS) \ @@ -18,13 +19,13 @@ nm_ppp_auth_dialog_CPPFLAGS = \ -DVERSION=\"$(VERSION)\" \ $(NULL) -nm_ppp_auth_dialog_SOURCES = \ +nm_pptp_auth_dialog_SOURCES = \ main.c \ gnome-two-password-dialog.c \ gnome-two-password-dialog.h \ $(NULL) -nm_ppp_auth_dialog_LDADD = \ +nm_pptp_auth_dialog_LDADD = \ $(GTK_LIBS) \ $(LIBGNOMEUI_LIBS) \ $(GNOMEKEYRING_LIBS) \ diff --git a/vpn-daemons/pptp/auth-dialog/gnome-two-password-dialog.c b/vpn-daemons/pptp/auth-dialog/gnome-two-password-dialog.c index b15d8d3ba7..f00037922d 100644 --- a/vpn-daemons/pptp/auth-dialog/gnome-two-password-dialog.c +++ b/vpn-daemons/pptp/auth-dialog/gnome-two-password-dialog.c @@ -159,7 +159,6 @@ gnome_two_password_dialog_finalize (GObject *object) g_free (password_dialog->details->remember_label_text); g_free (password_dialog->details->secondary_password_label); - g_free (password_dialog->details); if (G_OBJECT_CLASS (parent_class)->finalize != NULL) @@ -463,16 +462,15 @@ gnome_two_password_dialog_new (const char *dialog_title, gtk_widget_show_all (GTK_DIALOG (password_dialog)->vbox); password_dialog->details->remember_session_button = - gtk_check_button_new_with_mnemonic (_("_Remember password for this session")); + gtk_check_button_new_with_mnemonic (_("_Remember passwords for this session")); password_dialog->details->remember_forever_button = - gtk_check_button_new_with_mnemonic (_("_Save password in keyring")); + gtk_check_button_new_with_mnemonic (_("_Save passwords in keyring")); gtk_box_pack_start (GTK_BOX (vbox), password_dialog->details->remember_session_button, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), password_dialog->details->remember_forever_button, FALSE, FALSE, 0); - - + gnome_two_password_dialog_set_username (password_dialog, username); gnome_two_password_dialog_set_password (password_dialog, password); gnome_two_password_dialog_set_readonly_domain (password_dialog, readonly_username); diff --git a/vpn-daemons/pptp/auth-dialog/main.c b/vpn-daemons/pptp/auth-dialog/main.c index 5d24218e2a..3ddb9e727f 100644 --- a/vpn-daemons/pptp/auth-dialog/main.c +++ b/vpn-daemons/pptp/auth-dialog/main.c @@ -16,7 +16,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * (C) Copyright 2004 Red Hat, Inc. + * (C) Copyright 2008 Red Hat, Inc. */ #ifdef HAVE_CONFIG_H @@ -29,87 +29,118 @@ #include #include +#include +#include + +#include "../src/nm-pptp-service.h" #include "gnome-two-password-dialog.h" -#define VPN_SERVICE "org.freedesktop.NetworkManager.ppp_starter" +#define KEYRING_CID_TAG "connection-id" +#define KEYRING_SN_TAG "setting-name" +#define KEYRING_SK_TAG "setting-key" + +static char * +find_one_password (const char *vpn_id, + const char *vpn_name, + const char *vpn_service, + const char *secret_name, + gboolean *is_session) +{ + GList *found_list = NULL; + GnomeKeyringResult ret; + GnomeKeyringFound *found; + char *secret; + + ret = gnome_keyring_find_itemsv_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET, + &found_list, + KEYRING_CID_TAG, + GNOME_KEYRING_ATTRIBUTE_TYPE_STRING, + vpn_id, + KEYRING_SN_TAG, + GNOME_KEYRING_ATTRIBUTE_TYPE_STRING, + NM_SETTING_VPN_PROPERTIES_SETTING_NAME, + KEYRING_SK_TAG, + GNOME_KEYRING_ATTRIBUTE_TYPE_STRING, + secret_name, + NULL); + if ((ret != GNOME_KEYRING_RESULT_OK) || (g_list_length (found_list) == 0)) + return NULL; + + found = (GnomeKeyringFound *) found_list->data; + + if (strcmp (found->keyring, "session") == 0) + *is_session = TRUE; + else + *is_session = FALSE; + + secret = found->secret ? g_strdup (found->secret) : NULL; + gnome_keyring_found_list_free (found_list); + + return secret; +} static GSList * -lookup_pass (const char *vpn_name, const char *vpn_service, char *auth_type, gboolean *is_session) +lookup_pass (const char *vpn_id, const char *vpn_name, const char *vpn_service, gboolean *is_session) { - GSList *passwords; - GList *keyring_result; + GSList *passwords = NULL; + char *password; - passwords = NULL; - - if (gnome_keyring_find_network_password_sync (NULL, /* user */ - NULL, /* domain */ - vpn_name, /* server */ - NULL, /* object */ - vpn_service, /* protocol */ - auth_type, /* authtype */ - 0, /* port */ - &keyring_result) != GNOME_KEYRING_RESULT_OK) - return FALSE; - - if (keyring_result != NULL && g_list_length (keyring_result) == 1) { - GnomeKeyringNetworkPasswordData *data = - (GnomeKeyringNetworkPasswordData *)keyring_result->data; - char *username = NULL; - char *password = NULL; - char *auth_type = NULL; - - username = data->user; - password = data->password; - auth_type = data->authtype; - - if (password != NULL && username != NULL && auth_type != NULL) { -// Statically set the authentication type for now. - passwords = g_slist_append (passwords, g_strdup(auth_type)); - passwords = g_slist_append (passwords, g_strdup (username)); - passwords = g_slist_append (passwords, g_strdup (password)); - if (strcmp (data->keyring, "session") == 0) - *is_session = TRUE; - else - *is_session = FALSE; - } - - gnome_keyring_network_password_list_free (keyring_result); - } + password = find_one_password (vpn_id, vpn_name, vpn_service, "password", is_session); + if (password) + passwords = g_slist_append (passwords, password); return passwords; } -static void save_vpn_password (const char *vpn_name, const char *vpn_service, const char *keyring, - const char *auth_type, const char *username, const char *password) +static void +save_vpn_password (const char *vpn_id, + const char *vpn_name, + const char *vpn_service, + const char *keyring, + const char *secret_name, + const char *secret) { - guint32 item_id; - GnomeKeyringResult keyring_result; + char *display_name; + GnomeKeyringResult ret; + GnomeKeyringAttributeList *attrs = NULL; + guint32 id = 0; - keyring_result = gnome_keyring_set_network_password_sync (keyring, - username, - NULL, - vpn_name, - NULL, - vpn_service, - auth_type, - 0, - password, - &item_id); - if (keyring_result != GNOME_KEYRING_RESULT_OK) - { - g_warning ("Couldn't store authentication information in keyring, code %d", (int) keyring_result); - } + display_name = g_strdup_printf ("VPN %s secret for %s/%s/" NM_SETTING_VPN_PROPERTIES_SETTING_NAME, + secret_name, + vpn_name, + vpn_service); + attrs = gnome_keyring_attribute_list_new (); + gnome_keyring_attribute_list_append_string (attrs, + KEYRING_CID_TAG, + vpn_id); + gnome_keyring_attribute_list_append_string (attrs, + KEYRING_SN_TAG, + NM_SETTING_VPN_PROPERTIES_SETTING_NAME); + gnome_keyring_attribute_list_append_string (attrs, + KEYRING_SK_TAG, + secret_name); + + ret = gnome_keyring_item_create_sync (keyring, + GNOME_KEYRING_ITEM_GENERIC_SECRET, + display_name, + attrs, + secret, + TRUE, + &id); + gnome_keyring_attribute_list_free (attrs); + g_free (display_name); } static GSList * -get_passwords (const char *vpn_name, const char *vpn_service, gboolean retry) +get_passwords (const char *vpn_id, + const char *vpn_name, + const char *vpn_service, + gboolean retry) { GSList *result; char *prompt; - GtkWidget *dialog; - char *keyring_authtype; - char *keyring_username; + GtkWidget *dialog; char *keyring_password; gboolean keyring_is_session; GSList *keyring_result; @@ -117,36 +148,34 @@ get_passwords (const char *vpn_name, const char *vpn_service, gboolean retry) result = NULL; keyring_password = NULL; - keyring_username = NULL; keyring_result = NULL; + g_return_val_if_fail (vpn_id != NULL, NULL); g_return_val_if_fail (vpn_name != NULL, NULL); /* Use the system user name, since the VPN might have a different user name */ if (!retry) { - if ((result = lookup_pass (vpn_name, vpn_service, "CHAP", &keyring_is_session)) != NULL) { + if ((result = lookup_pass (vpn_id, vpn_name, vpn_service, &keyring_is_session)) != NULL) { return result; } } else { - if ((keyring_result = lookup_pass (vpn_name, vpn_service, "CHAP", &keyring_is_session)) != NULL) { - keyring_authtype = g_strdup ((char *) keyring_result->data); - keyring_username = g_strdup ((char *) (g_slist_next (keyring_result))->data); - keyring_password = g_strdup ((char *) (g_slist_next (g_slist_next (keyring_result)))->data); - } + if ((keyring_result = lookup_pass (vpn_id, vpn_name, vpn_service, &keyring_is_session)) != NULL) + keyring_password = g_strdup ((char *) (g_slist_next (keyring_result))->data); + g_slist_foreach (keyring_result, (GFunc)g_free, NULL); g_slist_free (keyring_result); } - prompt = g_strdup_printf (_("You need to authenticate to access '%s'."), vpn_name); - dialog = gnome_two_password_dialog_new (_("Authenticate Connection"), prompt, NULL, NULL, FALSE); + prompt = g_strdup_printf (_("You need to authenticate to access the Virtual Private Network '%s'."), vpn_name); + dialog = gnome_two_password_dialog_new (_("Authenticate VPN"), prompt, NULL, NULL, FALSE); g_free (prompt); + gnome_two_password_dialog_set_show_username (GNOME_TWO_PASSWORD_DIALOG (dialog), FALSE); gnome_two_password_dialog_set_show_userpass_buttons (GNOME_TWO_PASSWORD_DIALOG (dialog), FALSE); - gnome_two_password_dialog_set_show_username (GNOME_TWO_PASSWORD_DIALOG (dialog), TRUE); gnome_two_password_dialog_set_show_domain (GNOME_TWO_PASSWORD_DIALOG (dialog), FALSE); gnome_two_password_dialog_set_show_remember (GNOME_TWO_PASSWORD_DIALOG (dialog), TRUE); gnome_two_password_dialog_set_show_password_secondary (GNOME_TWO_PASSWORD_DIALOG (dialog), FALSE); - //gnome_two_password_dialog_set_password_secondary_label (GNOME_TWO_PASSWORD_DIALOG (dialog), _("_Group Password:")); + /* use the same keyring storage options as from the items we put in the entry boxes */ remember = GNOME_TWO_PASSWORD_DIALOG_REMEMBER_NOTHING; if (keyring_result != NULL) { @@ -158,9 +187,6 @@ get_passwords (const char *vpn_name, const char *vpn_service, gboolean retry) gnome_two_password_dialog_set_remember (GNOME_TWO_PASSWORD_DIALOG (dialog), remember); /* if retrying, put in the passwords from the keyring */ - if (keyring_username != NULL) { - gnome_two_password_dialog_set_username (GNOME_TWO_PASSWORD_DIALOG (dialog), keyring_username); - } if (keyring_password != NULL) { gnome_two_password_dialog_set_password (GNOME_TWO_PASSWORD_DIALOG (dialog), keyring_password); } @@ -169,25 +195,18 @@ get_passwords (const char *vpn_name, const char *vpn_service, gboolean retry) if (gnome_two_password_dialog_run_and_block (GNOME_TWO_PASSWORD_DIALOG (dialog))) { - char *username; char *password; - char *auth_type; - 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. - auth_type = g_strdup("CHAP"); - result = g_slist_append (result, auth_type); - result = g_slist_append (result, g_strdup(username)); - result = g_slist_append (result, g_strdup(password)); + result = g_slist_append (result, password); switch (gnome_two_password_dialog_get_remember (GNOME_TWO_PASSWORD_DIALOG (dialog))) { case GNOME_TWO_PASSWORD_DIALOG_REMEMBER_SESSION: - save_vpn_password (vpn_name, vpn_service, "session", auth_type, username, password); + save_vpn_password (vpn_id, vpn_name, vpn_service, "session", "password", password); break; case GNOME_TWO_PASSWORD_DIALOG_REMEMBER_FOREVER: - save_vpn_password (vpn_name, vpn_service, NULL, auth_type, username, password); + save_vpn_password (vpn_id, vpn_name, vpn_service, NULL, "password", password); break; default: break; @@ -195,10 +214,8 @@ get_passwords (const char *vpn_name, const char *vpn_service, gboolean retry) } - if (keyring_username!=NULL) g_free (keyring_username); - if (keyring_password!=NULL) g_free (keyring_password); + g_free (keyring_password); - gtk_widget_hide (dialog); gtk_widget_destroy (dialog); return result; @@ -207,22 +224,23 @@ get_passwords (const char *vpn_name, const char *vpn_service, gboolean retry) int main (int argc, char *argv[]) { - GSList *i; GSList *passwords; static gboolean retry = FALSE; static gchar *vpn_name = NULL; + static gchar *vpn_id = NULL; static gchar *vpn_service = NULL; - GError *error = NULL; + char buf[1]; + int ret; GOptionContext *context; GnomeProgram *program; GOptionEntry entries[] = { { "reprompt", 'r', 0, G_OPTION_ARG_NONE, &retry, "Reprompt for passwords", NULL}, + { "id", 'i', 0, G_OPTION_ARG_STRING, &vpn_id, "ID of VPN connection", NULL}, { "name", 'n', 0, G_OPTION_ARG_STRING, &vpn_name, "Name of VPN connection", NULL}, { "service", 's', 0, G_OPTION_ARG_STRING, &vpn_service, "VPN service type", NULL}, { NULL } }; - char buf[1]; bindtextdomain (GETTEXT_PACKAGE, NULL); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); @@ -230,35 +248,35 @@ main (int argc, char *argv[]) passwords = NULL; - context = g_option_context_new ("- ppp auth dialog"); + context = g_option_context_new ("- pptp auth dialog"); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); - - program = gnome_program_init ("nm-ppp-auth-dialog", VERSION, + + program = gnome_program_init ("nm-pptp-auth-dialog", VERSION, LIBGNOMEUI_MODULE, argc, argv, GNOME_PARAM_GOPTION_CONTEXT, context, GNOME_PARAM_NONE); - if (vpn_name == NULL || vpn_service == NULL) { - fprintf (stderr, "Have to supply both name and service\n"); + + if (vpn_id == NULL || vpn_name == NULL || vpn_service == NULL) { + fprintf (stderr, "Have to supply ID, name, and service\n"); goto out; } - if (strcmp (vpn_service, VPN_SERVICE) != 0) { - fprintf (stderr, "This dialog only works with the '%s' service\n", VPN_SERVICE); + if (strcmp (vpn_service, NM_DBUS_SERVICE_PPTP) != 0) { + fprintf (stderr, "This dialog only works with the '%s' service\n", NM_DBUS_SERVICE_PPTP); goto out; } - passwords = get_passwords (vpn_name, vpn_service, retry); + passwords = get_passwords (vpn_id, vpn_name, vpn_service, retry); if (passwords == NULL) goto out; /* dump the passwords to stdout */ - for (i = passwords; i != NULL; i = g_slist_next (i)) { - char *password = (char *) i->data; - printf ("%s\n", password); - } + + printf ("%s\n%s\n", NM_PPTP_KEY_PASSWORD, (char *) passwords->data); printf ("\n\n"); + /* for good measure, flush stdout since Kansas is going Bye-Bye */ fflush (stdout); @@ -266,7 +284,7 @@ main (int argc, char *argv[]) g_slist_free (passwords); /* wait for data on stdin */ - fread (buf, sizeof (char), sizeof (buf), stdin); + ret = fread (buf, sizeof (char), sizeof (buf), stdin); out: g_object_unref (program); diff --git a/vpn-daemons/pptp/configure.in b/vpn-daemons/pptp/configure.in index 84129bc29f..2794893a8a 100644 --- a/vpn-daemons/pptp/configure.in +++ b/vpn-daemons/pptp/configure.in @@ -1,10 +1,11 @@ AC_PREREQ(2.59) -AC_INIT(NetworkManager-ppp_vpn, 0.7.0-beta, eemynotna@gmail.com, NetworkManager-ppp_vpn) - +AC_INIT(NetworkManager-pptp, 0.7.0, dcbw@redhat.com, NetworkManager-pptp) +AC_CONFIG_AUX_DIR(.) AM_INIT_AUTOMAKE([1.9 foreign no-dist-gzip dist-bzip2 subdir-objects]) +AM_MAINTAINER_MODE -AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_HEADER(config.h) dnl dnl Require programs @@ -14,66 +15,23 @@ AM_PROG_CC_C_O AC_PROG_INSTALL AC_PROG_LIBTOOL - dnl dnl Required headers dnl AC_HEADER_STDC AC_CHECK_HEADERS(fcntl.h paths.h sys/ioctl.h sys/time.h syslog.h unistd.h) -AC_ARG_WITH(pppd, AC_HELP_STRING([--with-pppd=DISTRO], [Specify path to pppd.h (and patchlevel.h)])) -AC_ARG_WITH(pppd-version, AC_HELP_STRING([--with-pppd-version=DISTRO], [Version of pppd.h])) -if test "z$with_pppd" != "z"; then - AC_MSG_CHECKING([for $with_pppd/pppd.h]) - if test -f "$with_pppd/pppd.h"; then - PPPD_CFLAGS="-I $with_pppd" - PPPD_VERSION=`grep VERSION $with_pppd/patchlevel.h | awk '{print $3}' | sed -e 's/\s*"\s*//g'` - found_pppd_headers=yes - AC_MSG_RESULT(found version $PPPD_VERSION) - else - AC_MSG_ERROR(not found in $with_pppd) - fi +AC_CHECK_HEADERS(pppd/pppd.h,, + AC_MSG_ERROR(couldn't find pppd.h. pppd development headers are required.)) + +AC_ARG_WITH([pppd-plugin-dir], AS_HELP_STRING([--with-pppd-plugin-dir=DIR], [path to the pppd plugins directory])) + +if test -n "$with_pppd_plugin_dir" ; then + PPPD_PLUGIN_DIR="$with_pppd_plugin_dir" +else + PPPD_PLUGIN_DIR="${libdir}/pppd/2.4.4" fi - -if test "z$found_pppd_headers" = "z"; then - AC_MSG_CHECKING([for pppd.h under $prefix/include]) - find_pppd_h=`find $prefix/include -name pppd.h | xargs | awk '{print $1}'` - if echo $find_pppd_h | grep pppd.h; then - with_pppd=`dirname $find_pppd_h` - PPPD_CFLAGS="-I $with_pppd" - PPPD_VERSION=`grep VERSION $with_pppd/patchlevel.h | awk '{print $3}' | sed -e 's/\s*"\s*//g'` - found_pppd_headers=yes - AC_MSG_RESULT(found version $PPPD_VERSION) - else - AC_MSG_RESULT(not found) - fi -fi - -if test "z$found_pppd_headers" = "z"; then - if test "z$PPPD_VERSION" = "z"; then - AC_MSG_RESULT(Couldn't find pppd.h trying to determine pppd version to use in tree headers) - ##### Find PPPD executable - AC_CHECK_PROG(PPPD,pppd,pppd) - if test "z$PPPD" = "z"; then - AC_MSG_ERROR(Cannot compile without pppd) - fi - AC_MSG_RESULT(pppd version not found attempting to run 'pppd --version') - PPPD_VERSION=`$PPPD --version 2>&1 | awk '{print $3}'` - if test "z$PPPD_VERSION" = "z"; then - AC_MSG_ERROR(Couldn't determine the version of your pppd package.) - fi - fi - - if ! test -d "src/external/$PPPD_VERSION"; then - AC_MSG_ERROR(pppd headers could not be found) - fi - - AC_MSG_RESULT(Found in source headers for pppd version $PPPD_VERSION) - PPPD_CFLAGS="-I ./external/$PPPD_VERSION" -fi - -AC_SUBST([PPPD_VERSION]) -AC_SUBST(PPPD_CFLAGS) +AC_SUBST(PPPD_PLUGIN_DIR) dnl dnl Checks for typedefs, structures, and compiler characteristics. @@ -95,7 +53,7 @@ dnl AC_ARG_WITH(gnome, AC_HELP_STRING([--without-gnome], [Build NetworkManager-pptp without GNOME support, e.g. vpn service only])) AM_CONDITIONAL(WITH_GNOME, test x"$with_gnome" != xno) -GETTEXT_PACKAGE=NetworkManager-ppp_vpn +GETTEXT_PACKAGE=NetworkManager-pptp AC_SUBST(GETTEXT_PACKAGE) AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package]) @@ -106,13 +64,13 @@ PKG_CHECK_MODULES(GTHREAD, gthread-2.0) AC_SUBST(GTHREAD_CFLAGS) AC_SUBST(GTHREAD_LIBS) -PKG_CHECK_MODULES(DBUS, dbus-glib-1 >= 0.30) -AC_SUBST(DBUS_CFLAGS) -AC_SUBST(DBUS_LIBS) +PKG_CHECK_MODULES(DBUS, dbus-glib-1 >= 0.74) +AC_SUBST(DBUS_GLIB_CFLAGS) +AC_SUBST(DBUS_GLIB_LIBS) -PKG_CHECK_MODULES(NETWORK_MANAGER, NetworkManager >= 0.4.1 libnm-util >= 0.7.0) -AC_SUBST(NETWORK_MANAGER_CFLAGS) -AC_SUBST(NETWORK_MANAGER_LIBS) +PKG_CHECK_MODULES(NM_UTILS, NetworkManager >= 0.7.0 libnm-util libnm_glib libnm_glib_vpn) +AC_SUBST(NM_UTILS_CFLAGS) +AC_SUBST(NM_UTILS_LIBS) if test x"$with_gnome" != xno; then PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.6) @@ -140,19 +98,6 @@ if test x"$with_gnome" != xno; then AC_SUBST(GNOMEKEYRING_LIBS) fi -AC_ARG_ENABLE(nm-vpn-dbus-old, -AC_HELP_STRING([ --enable-nm-vpn-dbus-old], [Build Plugin to use old non-'DBUS Dict' NetworkManager VPN interface [default=no]]), -enable_nm_vpn_dbus_old="$enableval", enable_nm_vpn_dbus_old=no) -NM_VPN_CFLAGS= -if test "x$enable_nm_vpn_dbus_old" = "xyes" ; then - NM_VPN_CFLAGS="-DNM_VPN_USE_OLD_DBUS_INTERFACE" -fi -AC_SUBST(NM_VPN_CFLAGS) - -AC_ARG_ENABLE(bluetooth, [ --enable-bluetooth Build Bluetooth bits [default=no]], enable_bluetooth="$enableval", enable_bluetooth=no) -if test "x$enable_bluetooth" = "xyes" ; then - BUILD_BLUETOOTH="yes" -fi AC_ARG_ENABLE(more-warnings, AC_HELP_STRING([--enable-more-warnings], [Maximum compiler warnings]), set_more_warnings="$enableval",[ @@ -186,13 +131,11 @@ else AC_MSG_RESULT(no) fi -AC_CONFIG_FILES([ +AC_OUTPUT([ Makefile src/Makefile auth-dialog/Makefile -auth-dialog-general/Makefile properties/Makefile po/Makefile.in ]) -AC_OUTPUT diff --git a/vpn-daemons/pptp/nm-ppp-starter.conf b/vpn-daemons/pptp/nm-ppp-starter.conf deleted file mode 100644 index 8289c2a5f6..0000000000 --- a/vpn-daemons/pptp/nm-ppp-starter.conf +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - diff --git a/vpn-daemons/pptp/nm-ppp-starter.name.in b/vpn-daemons/pptp/nm-ppp-starter.name.in deleted file mode 100644 index 10d69d3373..0000000000 --- a/vpn-daemons/pptp/nm-ppp-starter.name.in +++ /dev/null @@ -1,8 +0,0 @@ -[VPN Connection] -name=ppp -service=org.freedesktop.NetworkManager.ppp_starter -program=@BINDIR@/nm-ppp-starter - -[GNOME] -auth-dialog=@LIBEXECDIR@/nm-ppp-auth-dialog -properties=@PREFIX@/${LIB}/libnm-ppp-properties diff --git a/vpn-daemons/pptp/nm-pptp-service.conf b/vpn-daemons/pptp/nm-pptp-service.conf new file mode 100644 index 0000000000..aa5400d19d --- /dev/null +++ b/vpn-daemons/pptp/nm-pptp-service.conf @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/vpn-daemons/pptp/nm-pptp-service.name.in b/vpn-daemons/pptp/nm-pptp-service.name.in new file mode 100644 index 0000000000..8fcb113936 --- /dev/null +++ b/vpn-daemons/pptp/nm-pptp-service.name.in @@ -0,0 +1,8 @@ +[VPN Connection] +name=pptp +service=org.freedesktop.NetworkManager.pptp +program=@BINDIR@/nm-pptp-service + +[GNOME] +auth-dialog=nm-pptp-auth-dialog +properties=libnm-pptp-properties diff --git a/vpn-daemons/pptp/nm-ppp.desktop.in b/vpn-daemons/pptp/nm-pptp.desktop.in similarity index 58% rename from vpn-daemons/pptp/nm-ppp.desktop.in rename to vpn-daemons/pptp/nm-pptp.desktop.in index def9f072ff..48370f219b 100644 --- a/vpn-daemons/pptp/nm-ppp.desktop.in +++ b/vpn-daemons/pptp/nm-pptp.desktop.in @@ -1,9 +1,9 @@ [Desktop Entry] Encoding=UTF-8 -_Name=VPN Connection Manager (PPP generic) -_GenericName=VPN Connection Manager (PPP generic) -_Comment=Add, Remove, and Edit VPN Connections -Exec=nm-vpn-properties --import-service org.freedesktop.NetworkManager.ppp_starter --import-file %f +_Name=PPTP VPN Connection Manager +_GenericName=PPTP VPN Connection Manager +_Comment=Add, Remove, and Edit PPTP VPN Connections +Exec=nm-vpn-properties --import-service org.freedesktop.NetworkManager.pptp --import-file %f Icon=gnome-mime-application-x-ppp-settings Terminal=false Type=Application diff --git a/vpn-daemons/pptp/po/POTFILES.in b/vpn-daemons/pptp/po/POTFILES.in index 3cd788455e..458888ed13 100644 --- a/vpn-daemons/pptp/po/POTFILES.in +++ b/vpn-daemons/pptp/po/POTFILES.in @@ -1,12 +1,9 @@ # List of source files containing translatable strings. # Please keep this file sorted alphabetically. -auth-dialog-general/gnome-generic-auth-dialog.c -auth-dialog-general/main.c -auth-dialog-general/nm-ppp-auth.glade auth-dialog/gnome-two-password-dialog.c auth-dialog/main.c -nm-ppp.desktop.in -properties/nm-ppp-dialog.glade -properties/nm-ppp-properties.c -properties/vpnui_impl.c -src/nm-ppp-starter.c +nm-pptp.desktop.in +properties/advanced-dialog.c +properties/nm-pptp-dialog.glade +properties/nm-pptp.c +src/nm-pptp-service.c diff --git a/vpn-daemons/pptp/properties/Makefile.am b/vpn-daemons/pptp/properties/Makefile.am index 4cf00df1e7..f5453afc00 100644 --- a/vpn-daemons/pptp/properties/Makefile.am +++ b/vpn-daemons/pptp/properties/Makefile.am @@ -1,32 +1,22 @@ +lib_LTLIBRARIES = libnm-pptp-properties.la +libnm_pptp_properties_la_SOURCES = \ + nm-pptp.c \ + nm-pptp.h \ + advanced-dialog.c \ + advanced-dialog.h \ + import-export.c \ + import-export.h -lib_LTLIBRARIES = libnm-ppp-properties.la +gladedir = $(datadir)/gnome-vpn-properties/pptp +glade_DATA = nm-pptp-dialog.glade -libnm_ppp_properties_la_SOURCES = \ - nm-ppp-properties.c \ - vpnui_impl.c \ - vpnui_expand.c \ - vpnui_opt.c \ - vpnui_validate.c \ - vpnui_variant.c \ - util_lists.c \ - vpnui_impl.h \ - vpnui_opt.h \ - vpnui_expand.h \ - vpnui_validate.h \ - vpnui_variant.h \ - util_lists.h \ - vpnui_impl.h - -gladedir = $(datadir)/gnome-vpn-properties/ppp -glade_DATA = nm-ppp-dialog.glade - -libnm_ppp_properties_la_CFLAGS = \ +libnm_pptp_properties_la_CFLAGS = \ $(GLADE_CFLAGS) \ $(GTK_CFLAGS) \ $(GCONF_CFLAGS) \ $(LIBGNOMEUI_CFLAGS) \ - $(NETWORK_MANAGER_CFLAGS) \ + $(NM_UTILS_CFLAGS) \ -DICONDIR=\""$(datadir)/pixmaps"\" \ -DGLADEDIR=\""$(gladedir)"\" \ -DG_DISABLE_DEPRECATED \ @@ -35,14 +25,14 @@ libnm_ppp_properties_la_CFLAGS = \ -DGNOMELOCALEDIR=\"$(datadir)/locale\" \ -DVERSION=\"$(VERSION)\" -libnm_ppp_properties_la_LIBADD = \ +libnm_pptp_properties_la_LIBADD = \ $(GLADE_LIBS) \ $(GTK_LIBS) \ $(GCONF_LIBS) \ $(LIBGNOMEUI_LIBS) \ - $(NETWORK_MANAGER_LIBS) + $(NM_UTILS_LIBS) -libnm_ppp_properties_la_LDFLAGS = \ +libnm_pptp_properties_la_LDFLAGS = \ -avoid-version CLEANFILES = *.bak *.gladep *~ diff --git a/vpn-daemons/pptp/properties/advanced-dialog.c b/vpn-daemons/pptp/properties/advanced-dialog.c new file mode 100644 index 0000000000..7ab8b9b17b --- /dev/null +++ b/vpn-daemons/pptp/properties/advanced-dialog.c @@ -0,0 +1,478 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/*************************************************************************** + * + * Copyright (C) 2008 Dan Williams, + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + **************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include "advanced-dialog.h" +#include "nm-pptp.h" +#include "../src/nm-pptp-service.h" + +#define COL_NAME 0 +#define COL_VALUE 1 +#define COL_TAG 2 + +#define TAG_PAP 0 +#define TAG_CHAP 1 +#define TAG_MSCHAP 2 +#define TAG_MSCHAPV2 3 + +static void +nm_gvalue_destroy (gpointer data) +{ + GValue *value = (GValue *) data; + + g_value_unset (value); + g_slice_free (GValue, value); +} + +static const char *advanced_keys[] = { + NM_PPTP_KEY_REFUSE_EAP, + NM_PPTP_KEY_REFUSE_PAP, + NM_PPTP_KEY_REFUSE_CHAP, + NM_PPTP_KEY_REFUSE_MSCHAP, + NM_PPTP_KEY_REFUSE_MSCHAPV2, + NM_PPTP_KEY_REQUIRE_MPPE, + NM_PPTP_KEY_REQUIRE_MPPE_40, + NM_PPTP_KEY_REQUIRE_MPPE_128, + NM_PPTP_KEY_MPPE_STATEFUL, + NM_PPTP_KEY_NOBSDCOMP, + NM_PPTP_KEY_NODEFLATE, + NM_PPTP_KEY_NO_VJ_COMP, + NM_PPTP_KEY_LCP_ECHO_FAILURE, + NM_PPTP_KEY_LCP_ECHO_INTERVAL, + NULL +}; + +static void +copy_values (gpointer key, gpointer data, gpointer user_data) +{ + GHashTable *hash = (GHashTable *) user_data; + GValue *value = (GValue *) data; + const char **i; + + for (i = &advanced_keys[0]; *i; i++) { + if (strcmp ((const char *) key, *i)) + continue; + + if (G_VALUE_HOLDS_STRING (value)) { + g_hash_table_insert (hash, + g_strdup ((const char *) key), + str_to_gvalue (g_value_get_string (value))); + } else if (G_VALUE_HOLDS_INT (value)) { + g_hash_table_insert (hash, + g_strdup ((const char *) key), + int_to_gvalue (g_value_get_int (value))); + } else if (G_VALUE_HOLDS_UINT (value)) { + g_hash_table_insert (hash, + g_strdup ((const char *) key), + uint_to_gvalue (g_value_get_uint (value))); + } else if (G_VALUE_HOLDS_BOOLEAN (value)) { + g_hash_table_insert (hash, + g_strdup ((const char *) key), + bool_to_gvalue (g_value_get_boolean (value))); + } + } +} + +GHashTable * +advanced_dialog_new_hash_from_connection (NMConnection *connection, + GError **error) +{ + GHashTable *hash; + NMSettingVPNProperties *s_vpn_props; + + hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, nm_gvalue_destroy); + + s_vpn_props = (NMSettingVPNProperties *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN_PROPERTIES); + if (s_vpn_props && s_vpn_props->data) + g_hash_table_foreach (s_vpn_props->data, copy_values, hash); + + return hash; +} + +static void +mppe_toggled_cb (GtkWidget *check, gpointer user_data) +{ + GladeXML *xml = (GladeXML *) user_data; + GtkWidget *widget; + gboolean use_mppe; + + use_mppe = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)); + + widget = glade_xml_get_widget (xml, "ppp_mppe_security_label"); + gtk_widget_set_sensitive (widget, use_mppe); + + widget = glade_xml_get_widget (xml, "ppp_mppe_security_combo"); + if (!use_mppe) + gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0); /* default */ + gtk_widget_set_sensitive (widget, use_mppe); + + widget = glade_xml_get_widget (xml, "ppp_allow_stateful_mppe"); + if (!use_mppe) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE); + gtk_widget_set_sensitive (widget, use_mppe); +} + +#define SEC_INDEX_DEFAULT 0 +#define SEC_INDEX_MPPE_128 1 +#define SEC_INDEX_MPPE_40 2 + +static void +setup_security_combo (GladeXML *xml, GHashTable *hash) +{ + GtkWidget *widget; + GtkListStore *store; + GtkTreeIter iter; + int active = -1; + GValue *value; + + g_return_if_fail (xml != NULL); + g_return_if_fail (hash != NULL); + + widget = glade_xml_get_widget (xml, "ppp_mppe_security_combo"); + + store = gtk_list_store_new (1, G_TYPE_STRING); + + /* Default */ + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, _("All Available (Default)"), -1); + + /* MPPE-128 */ + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, _("128-bit (most secure)"), -1); + if (active < 0) { + value = g_hash_table_lookup (hash, NM_PPTP_KEY_REQUIRE_MPPE_128); + if (value && G_VALUE_HOLDS_BOOLEAN (value) && g_value_get_boolean (value)) + active = SEC_INDEX_MPPE_128; + } + + /* MPPE-40 */ + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, _("40-bit (less secure)"), -1); + if (active < 0) { + value = g_hash_table_lookup (hash, NM_PPTP_KEY_REQUIRE_MPPE_40); + if (value && G_VALUE_HOLDS_BOOLEAN (value) && g_value_get_boolean (value)) + active = SEC_INDEX_MPPE_40; + } + + gtk_combo_box_set_model (GTK_COMBO_BOX (widget), GTK_TREE_MODEL (store)); + g_object_unref (store); + gtk_combo_box_set_active (GTK_COMBO_BOX (widget), active < 0 ? SEC_INDEX_DEFAULT : active); +} + +static void +check_toggled_cb (GtkCellRendererToggle *cell, gchar *path_str, gpointer user_data) +{ + GladeXML *xml = GLADE_XML (user_data); + GtkWidget *widget; + GtkTreePath *path = gtk_tree_path_new_from_string (path_str); + GtkTreeModel *model; + GtkTreeIter iter; + gboolean toggle_item; + + widget = glade_xml_get_widget (xml, "ppp_auth_methods"); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget)); + + gtk_tree_model_get_iter (model, &iter, path); + gtk_tree_model_get (model, &iter, COL_VALUE, &toggle_item, -1); + + toggle_item ^= 1; + + /* set new value */ + gtk_list_store_set (GTK_LIST_STORE (model), &iter, COL_VALUE, toggle_item, -1); + + gtk_tree_path_free (path); +} + +static void +auth_methods_setup (GladeXML *xml, GHashTable *hash) +{ + GtkWidget *widget; + GtkListStore *store; + GtkTreeIter iter; + GValue *value; + gboolean allowed; + gboolean use_mppe = FALSE; + GtkCellRendererToggle *check_renderer; + GtkCellRenderer *text_renderer; + GtkTreeViewColumn *column; + gint offset; + + store = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_UINT); + + /* Check for MPPE */ + value = g_hash_table_lookup (hash, NM_PPTP_KEY_REQUIRE_MPPE); + if (value && G_VALUE_HOLDS_BOOLEAN (value) && g_value_get_boolean (value)) + use_mppe = TRUE; + + /* Or MPPE-128 */ + value = g_hash_table_lookup (hash, NM_PPTP_KEY_REQUIRE_MPPE_128); + if (value && G_VALUE_HOLDS_BOOLEAN (value) && g_value_get_boolean (value)) + use_mppe = TRUE; + + /* Or MPPE-40 */ + value = g_hash_table_lookup (hash, NM_PPTP_KEY_REQUIRE_MPPE_40); + if (value && G_VALUE_HOLDS_BOOLEAN (value) && g_value_get_boolean (value)) + use_mppe = TRUE; + + /* PAP */ + value = g_hash_table_lookup (hash, NM_PPTP_KEY_REFUSE_PAP); + allowed = (value && G_VALUE_HOLDS_BOOLEAN (value) && g_value_get_boolean (value)) ? FALSE : TRUE; + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, COL_NAME, _("PAP"), COL_VALUE, allowed, COL_TAG, TAG_PAP, -1); + + /* CHAP */ + value = g_hash_table_lookup (hash, NM_PPTP_KEY_REFUSE_CHAP); + allowed = (value && G_VALUE_HOLDS_BOOLEAN (value) && g_value_get_boolean (value)) ? FALSE : TRUE; + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, COL_NAME, _("CHAP"), COL_VALUE, allowed, COL_TAG, TAG_CHAP, -1); + + /* MSCHAP */ + value = g_hash_table_lookup (hash, NM_PPTP_KEY_REFUSE_MSCHAP); + allowed = (value && G_VALUE_HOLDS_BOOLEAN (value) && g_value_get_boolean (value)) ? FALSE : TRUE; + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, COL_NAME, _("MSCHAP"), COL_VALUE, allowed, COL_TAG, TAG_MSCHAP, -1); + + /* PAP */ + value = g_hash_table_lookup (hash, NM_PPTP_KEY_REFUSE_MSCHAPV2); + allowed = (value && G_VALUE_HOLDS_BOOLEAN (value) && g_value_get_boolean (value)) ? FALSE : TRUE; + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, COL_NAME, _("MSCHAPv2"), COL_VALUE, allowed, COL_TAG, TAG_MSCHAPV2, -1); + + /* Set up the tree view */ + widget = glade_xml_get_widget (xml, "ppp_auth_methods"); + gtk_tree_view_set_model (GTK_TREE_VIEW (widget), GTK_TREE_MODEL (store)); + + check_renderer = GTK_CELL_RENDERER_TOGGLE (gtk_cell_renderer_toggle_new ()); + g_signal_connect (check_renderer, "toggled", G_CALLBACK (check_toggled_cb), xml); + + offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (widget), + -1, "", GTK_CELL_RENDERER (check_renderer), + "active", COL_VALUE, + NULL); + column = gtk_tree_view_get_column (GTK_TREE_VIEW (widget), offset - 1); + gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column), GTK_TREE_VIEW_COLUMN_FIXED); + gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 30); + gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE); + + text_renderer = gtk_cell_renderer_text_new (); + offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (widget), + -1, "", text_renderer, + "text", COL_NAME, + NULL); + column = gtk_tree_view_get_column (GTK_TREE_VIEW (widget), offset - 1); + gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE); +} + +GtkWidget * +advanced_dialog_new (GHashTable *hash) +{ + GladeXML *xml; + GtkWidget *dialog = NULL; + char *glade_file = NULL; + GtkWidget *widget; + GValue *value; + + g_return_val_if_fail (hash != NULL, NULL); + + glade_file = g_strdup_printf ("%s/%s", GLADEDIR, "nm-pptp-dialog.glade"); + xml = glade_xml_new (glade_file, "pptp-advanced-dialog", GETTEXT_PACKAGE); + if (xml == NULL) + goto out; + + dialog = glade_xml_get_widget (xml, "pptp-advanced-dialog"); + if (!dialog) { + g_object_unref (G_OBJECT (xml)); + goto out; + } + gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + + g_object_set_data_full (G_OBJECT (dialog), "glade-xml", + xml, (GDestroyNotify) g_object_unref); + + + setup_security_combo (xml, hash); + + widget = glade_xml_get_widget (xml, "ppp_use_mppe"); + g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (mppe_toggled_cb), xml); + + value = g_hash_table_lookup (hash, NM_PPTP_KEY_REQUIRE_MPPE); + if (value && G_VALUE_HOLDS_BOOLEAN (value)) { + if (g_value_get_boolean (value)) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE); + } + mppe_toggled_cb (widget, xml); + + value = g_hash_table_lookup (hash, NM_PPTP_KEY_MPPE_STATEFUL); + if (value && G_VALUE_HOLDS_BOOLEAN (value)) { + widget = glade_xml_get_widget (xml, "ppp_allow_stateful_mppe"); + if (g_value_get_boolean (value)) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE); + } + + widget = glade_xml_get_widget (xml, "ppp_allow_bsdcomp"); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE); + value = g_hash_table_lookup (hash, NM_PPTP_KEY_NOBSDCOMP); + if (value && G_VALUE_HOLDS_BOOLEAN (value)) { + if (g_value_get_boolean (value)) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE); + } + + widget = glade_xml_get_widget (xml, "ppp_allow_deflate"); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE); + value = g_hash_table_lookup (hash, NM_PPTP_KEY_NODEFLATE); + if (value && G_VALUE_HOLDS_BOOLEAN (value)) { + if (g_value_get_boolean (value)) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE); + } + + widget = glade_xml_get_widget (xml, "ppp_usevj"); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE); + value = g_hash_table_lookup (hash, NM_PPTP_KEY_NO_VJ_COMP); + if (value && G_VALUE_HOLDS_BOOLEAN (value)) { + if (g_value_get_boolean (value)) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE); + } + + value = g_hash_table_lookup (hash, NM_PPTP_KEY_LCP_ECHO_INTERVAL); + if (value && G_VALUE_HOLDS_UINT (value)) { + widget = glade_xml_get_widget (xml, "ppp_send_echo_packets"); + if (g_value_get_uint (value)) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE); + } + + auth_methods_setup (xml, hash); + +out: + g_free (glade_file); + return dialog; +} + +GHashTable * +advanced_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error) +{ + GHashTable *hash; + GtkWidget *widget; + GladeXML *xml; + GtkTreeModel *model; + GtkTreeIter iter; + gboolean valid; + + g_return_val_if_fail (dialog != NULL, NULL); + if (error) + g_return_val_if_fail (*error == NULL, NULL); + + xml = g_object_get_data (G_OBJECT (dialog), "glade-xml"); + g_return_val_if_fail (xml != NULL, NULL); + + hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, nm_gvalue_destroy); + + widget = glade_xml_get_widget (xml, "ppp_use_mppe"); + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) { + + widget = glade_xml_get_widget (xml, "ppp_mppe_security_combo"); + switch (gtk_combo_box_get_active (GTK_COMBO_BOX (widget))) { + case SEC_INDEX_MPPE_128: + g_hash_table_insert (hash, g_strdup (NM_PPTP_KEY_REQUIRE_MPPE_128), bool_to_gvalue (TRUE)); + break; + case SEC_INDEX_MPPE_40: + g_hash_table_insert (hash, g_strdup (NM_PPTP_KEY_REQUIRE_MPPE_40), bool_to_gvalue (TRUE)); + break; + default: + g_hash_table_insert (hash, g_strdup (NM_PPTP_KEY_REQUIRE_MPPE), bool_to_gvalue (TRUE)); + break; + } + + widget = glade_xml_get_widget (xml, "ppp_allow_stateful_mppe"); + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) + g_hash_table_insert (hash, g_strdup (NM_PPTP_KEY_MPPE_STATEFUL), bool_to_gvalue (TRUE)); + } + + widget = glade_xml_get_widget (xml, "ppp_allow_bsdcomp"); + if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) + g_hash_table_insert (hash, g_strdup (NM_PPTP_KEY_NOBSDCOMP), bool_to_gvalue (TRUE)); + + widget = glade_xml_get_widget (xml, "ppp_allow_deflate"); + if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) + g_hash_table_insert (hash, g_strdup (NM_PPTP_KEY_NODEFLATE), bool_to_gvalue (TRUE)); + + widget = glade_xml_get_widget (xml, "ppp_usevj"); + if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) + g_hash_table_insert (hash, g_strdup (NM_PPTP_KEY_NO_VJ_COMP), bool_to_gvalue (TRUE)); + + widget = glade_xml_get_widget (xml, "ppp_send_echo_packets"); + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) { + g_hash_table_insert (hash, g_strdup (NM_PPTP_KEY_LCP_ECHO_FAILURE), uint_to_gvalue (5)); + g_hash_table_insert (hash, g_strdup (NM_PPTP_KEY_LCP_ECHO_INTERVAL), uint_to_gvalue (30)); + } + + widget = glade_xml_get_widget (xml, "ppp_auth_methods"); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget)); + valid = gtk_tree_model_get_iter_first (model, &iter); + while (valid) { + gboolean allowed; + guint32 tag; + + gtk_tree_model_get (model, &iter, COL_VALUE, &allowed, COL_TAG, &tag, -1); + switch (tag) { + case TAG_PAP: + if (!allowed) + g_hash_table_insert (hash, g_strdup (NM_PPTP_KEY_REFUSE_PAP), bool_to_gvalue (TRUE)); + break; + case TAG_CHAP: + if (!allowed) + g_hash_table_insert (hash, g_strdup (NM_PPTP_KEY_REFUSE_CHAP), bool_to_gvalue (TRUE)); + break; + case TAG_MSCHAP: + if (!allowed) + g_hash_table_insert (hash, g_strdup (NM_PPTP_KEY_REFUSE_MSCHAP), bool_to_gvalue (TRUE)); + break; + case TAG_MSCHAPV2: + if (!allowed) + g_hash_table_insert (hash, g_strdup (NM_PPTP_KEY_REFUSE_MSCHAPV2), bool_to_gvalue (TRUE)); + break; + default: + break; + } + + valid = gtk_tree_model_iter_next (model, &iter); + } + + return hash; +} + diff --git a/vpn-daemons/pptp/src/nm-ppp-starter.h b/vpn-daemons/pptp/properties/advanced-dialog.h similarity index 52% rename from vpn-daemons/pptp/src/nm-ppp-starter.h rename to vpn-daemons/pptp/properties/advanced-dialog.h index 9d2a01d0a9..6752e11f65 100644 --- a/vpn-daemons/pptp/src/nm-ppp-starter.h +++ b/vpn-daemons/pptp/properties/advanced-dialog.h @@ -1,8 +1,7 @@ -/* nm-ppp-starter - pptp (and other ppp) integration with NetworkManager +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/*************************************************************************** * - * Antony J Mee - * Based on openvpn work by Tim Niemueller - * and Dan Williams + * Copyright (C) 2008 Dan Williams, * * 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 @@ -18,13 +17,21 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - */ + **************************************************************************/ -#ifndef NM_PPP_SERVICE_H -#define NM_PPP_SERVICE_H +#ifndef _AUTH_HELPERS_H_ +#define _AUTH_HELPERS_H_ -#define NM_DBUS_SERVICE_PPP_STARTER "org.freedesktop.NetworkManager.ppp_starter" -#define NM_DBUS_INTERFACE_PPP_STARTER "org.freedesktop.NetworkManager.ppp_starter" -#define NM_DBUS_PATH_PPP_STARTER "/org/freedesktop/NetworkManager/ppp_starter" +#include +#include +#include + +#include + +GtkWidget *advanced_dialog_new (GHashTable *hash); + +GHashTable *advanced_dialog_new_hash_from_connection (NMConnection *connection, GError **error); + +GHashTable *advanced_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error); #endif diff --git a/vpn-daemons/pptp/properties/import-export.c b/vpn-daemons/pptp/properties/import-export.c new file mode 100644 index 0000000000..4b2be7c899 --- /dev/null +++ b/vpn-daemons/pptp/properties/import-export.c @@ -0,0 +1,81 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/*************************************************************************** + * + * Copyright (C) 2008 Dan Williams, + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + **************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include "import-export.h" +#include "nm-pptp.h" +#include "../src/nm-pptp-service.h" + +NMConnection * +do_import (const char *path, char **lines, GError **error) +{ + NMConnection *connection = NULL; + NMSettingConnection *s_con; + NMSettingVPN *s_vpn; + NMSettingVPNProperties *s_vpn_props; + char *last_dot; + + connection = nm_connection_new (); + s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ()); + nm_connection_add_setting (connection, NM_SETTING (s_con)); + + s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ()); + s_vpn->service_type = g_strdup (NM_DBUS_SERVICE_PPTP); + nm_connection_add_setting (connection, NM_SETTING (s_vpn)); + + s_vpn_props = NM_SETTING_VPN_PROPERTIES (nm_setting_vpn_properties_new ()); + nm_connection_add_setting (connection, NM_SETTING (s_vpn_props)); + + s_con->id = g_path_get_basename (path); + last_dot = strrchr (s_con->id, '.'); + if (last_dot) + *last_dot = '\0'; + + return connection; +} + +gboolean +do_export (const char *path, NMConnection *connection, GError **error) +{ + return FALSE; +} + + + diff --git a/vpn-daemons/pptp/src/nm-pppd-plugin.h b/vpn-daemons/pptp/properties/import-export.h similarity index 57% rename from vpn-daemons/pptp/src/nm-pppd-plugin.h rename to vpn-daemons/pptp/properties/import-export.h index 11f8d04437..1c5fbc9f1f 100644 --- a/vpn-daemons/pptp/src/nm-pppd-plugin.h +++ b/vpn-daemons/pptp/properties/import-export.h @@ -1,8 +1,7 @@ -/* nm-ppp-starter - pptp (and other ppp) integration with NetworkManager +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/*************************************************************************** * - * Antony J Mee - * Based on openvpn work by Tim Niemueller - * and Dan Williams + * Copyright (C) 2008 Dan Williams, * * 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 @@ -18,13 +17,16 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - */ + **************************************************************************/ -#ifndef NM_PPPD_PLUGIN_H -#define NM_PPPD_PLUGIN_H +#ifndef _IMPORT_EXPORT_H_ +#define _IMPORT_EXPORT_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" +#include +#include + +NMConnection *do_import (const char *path, char **lines, GError **error); + +gboolean do_export (const char *path, NMConnection *connection, GError **error); #endif diff --git a/vpn-daemons/pptp/properties/nm-ppp-dialog.glade b/vpn-daemons/pptp/properties/nm-ppp-dialog.glade deleted file mode 100644 index c95116011b..0000000000 --- a/vpn-daemons/pptp/properties/nm-ppp-dialog.glade +++ /dev/null @@ -1,2307 +0,0 @@ - - - - - - - - - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - False - False - True - False - False - GDK_WINDOW_TYPE_HINT_NORMAL - GDK_GRAVITY_NORTH_WEST - True - False - - - - True - False - 12 - - - - True - True - True - True - GTK_POS_TOP - False - False - - - - 12 - True - False - 6 - - - - True - 2 - 2 - False - 6 - 12 - - - - True - Connection na_me: - True - True - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - connection-name - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 0 - 1 - fill - - - - - - - True - True - True - True - 0 - - True - * - False - - - 1 - 2 - 0 - 1 - - - - - - - True - This is the friendly name that will be used to identify this network connection, -e.g. "Campus VPN" or "Corporate Network" - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 1 - 2 - 1 - 2 - fill - - - - - - 0 - False - True - - - - - - False - True - Requires existing network connection - True - GTK_RELIEF_NORMAL - True - True - False - True - - - 0 - False - False - - - - - - True - False - 12 - - - - True - Typ_e: - True - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - ppp-connection-type - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - - False - True - - - 0 - True - True - - - - - 0 - False - True - - - - - - True - False - 0 - - - - False - 4 - - - - True - False - 12 - - - - True - _Gateway: - True - False - GTK_JUSTIFY_LEFT - False - False - 1 - 0.5 - 0 - 0 - pptp-remote - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - Host name or IP address of the PPTP server - True - True - True - 0 - - True - * - False - - - 0 - True - True - - - - - 0 - False - False - - - - - 0 - True - True - - - - - - False - 4 - - - - True - False - 12 - - - - True - Telep_hone number: - True - False - GTK_JUSTIFY_LEFT - False - False - 1 - 0.5 - 0 - 0 - phone-number - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - Host name or IP address of the PPTP server - True - True - True - 0 - - True - * - False - - - 0 - True - True - - - - - 0 - False - False - - - - - 0 - True - True - - - - - - True - False - 6 - - - - True - 2 - 2 - False - 6 - 12 - - - - True - C_hannel: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - bt-channel - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 1 - 2 - fill - - - - - - - True - True - True - True - 3 - - True - * - False - - - 1 - 2 - 1 - 2 - - - - - - - True - Host name or IP address of the PPTP server - True - True - True - 17 - 00:00:00:00 - True - * - False - - - 1 - 2 - 0 - 1 - - - - - - - True - False - 12 - - - - True - _Device address: - True - False - GTK_JUSTIFY_LEFT - False - False - 1 - 0.5 - 0 - 0 - bt-bdaddr - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - 0 - 1 - 0 - 1 - fill - fill - - - - - 0 - True - True - - - - - - True - GTK_BUTTONBOX_END - 0 - - - - True - True - GTK_RELIEF_NORMAL - True - - - - True - 0.5 - 0.5 - 0 - 0 - 0 - 0 - 0 - 0 - - - - True - False - 2 - - - - True - gtk-find - 4 - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - Find Device - True - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - - - - - - 0 - True - True - - - - - 0 - True - True - - - - - 0 - False - True - - - - - - True - GTK_BUTTONBOX_END - 0 - - - - True - True - True - GTK_RELIEF_NORMAL - True - - - - True - 0.5 - 0.5 - 0 - 0 - 0 - 0 - 0 - 0 - - - - True - False - 2 - - - - True - gtk-add - 4 - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - _Import Saved Configuration... - True - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - - - - - - 0 - False - True - GTK_PACK_END - - - - - False - True - - - - - - True - Connection - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - tab - - - - - - 12 - True - 4 - 2 - False - 6 - 12 - - - - True - _Access point name: - True - False - GTK_JUSTIFY_LEFT - False - False - 1 - 0.5 - 0 - 0 - gprs-apn - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 0 - 1 - fill - - - - - - - True - Service providers GPRS access point from device config - True - True - True - 0 - - True - * - False - - - 1 - 2 - 0 - 1 - - - - - - - True - IP a_ddress: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - gprs-ip-address - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 1 - 2 - fill - - - - - - - True - Service providers IP address - True - True - True - 0 - - True - * - False - - - 1 - 2 - 1 - 2 - - - - - - - True - _Packet type: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - gprs-packet-type - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 2 - 3 - fill - - - - - - - True - True - True - True - 0 - - True - * - False - 9 - - - 1 - 2 - 2 - 3 - - - - - - - True - Context _number: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - gprs-context-num - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 3 - 4 - fill - - - - - - - True - True - True - True - 0 - - True - * - False - 3 - - - 1 - 2 - 3 - 4 - - - - - - False - True - - - - - - True - GPRS Options - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - tab - - - - - - 12 - True - False - 0 - - - - True - False - 6 - - - - True - When this check box is cleared the "noauth" option is passed to pppd. - True - _Authenticate peer - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - False - False - - - - - - True - When checked the "refuse-eap" option is passed to pppd. - True - Refuse _EAP - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - False - False - - - - - - True - When checked the "refuse-chap" option is passed to pppd. - True - Refuse C_HAP - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - False - False - - - - - - True - When checked the "refuse-mschap" option is passed to pppd. - True - Refuse _MS CHAP - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - False - False - - - - - 0 - False - False - - - - - False - True - - - - - - True - Authentication - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - tab - - - - - - 12 - True - False - 18 - - - - True - False - 6 - - - - True - <b>Compression</b> - False - True - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - 0.5 - 0.5 - 1 - 1 - 0 - 0 - 12 - 0 - - - - True - False - 6 - - - - True - When checked the 'require-mppc' option is passed to pppd - True - _Require MPPC compression - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - False - False - - - - - - True - If Deflate compression is not allowed the 'nodefate' option is passed to pppd - True - Allow _Deflate compression - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - False - False - - - - - - True - If BSD compression is not allowed the 'nobsdcomp' option is passed to pppd - True - Allow B_SD Compression - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - False - False - - - - - - - 0 - False - True - - - - - 0 - False - True - - - - - - True - False - 6 - - - - True - <b>Encryption</b> - False - True - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - 0.5 - 0.5 - 1 - 1 - 0 - 0 - 12 - 0 - - - - True - False - 6 - - - - True - True - Require MPPE _encryption - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - False - False - - - - - - True - True - Require 128 bit M_PPE encryption - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - False - False - - - - - - True - True - Enable stateful _MPPE - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - False - False - - - - - - - 0 - False - True - - - - - 0 - True - True - - - - - False - True - - - - - - True - Compression & Encryption - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - tab - - - - - - 12 - True - False - 18 - - - - True - 2 - 2 - False - 6 - 12 - - - - True - A list of extra options to pppd as would be typed on the command line - True - True - True - 0 - - True - * - False - - - 1 - 2 - 0 - 1 - - - - - - - True - Custom _PPP options: - True - False - GTK_JUSTIFY_LEFT - False - False - 1 - 0.5 - 0 - 0 - ppp-extra - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 0 - 1 - fill - - - - - - - True - For security reasons, options entered in the box above are checked against a list of allowed options before a connection is established. Currently there are no options on the list. - False - True - GTK_JUSTIFY_LEFT - True - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 1 - 2 - 1 - 2 - fill - - - - - - - True - - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 1 - 2 - fill - - - - - - 0 - False - True - - - - - - True - False - 6 - - - - True - <b>IP Options</b> - False - True - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - 0.5 - 0.5 - 1 - 1 - 0 - 0 - 12 - 0 - - - - True - False - 6 - - - - True - When checked this sets the pppd 'usepeerdns' option - True - Use peer _DNS - True - GTK_RELIEF_NORMAL - True - True - False - True - - - 0 - False - False - - - - - - True - When checked this sets the pppd 'noipdefault' option - True - Require explicit IP _address - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - False - False - - - - - - True - When checked the 'lock' option is passed to pppd - True - E_xclusive device access (UUCP-style lock) - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - False - False - - - - - - True - When checked this sets the pppd 'debug' option and adds some extra information from the NetworkManager plugin - True - Debug _output - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - False - False - - - - - - - 0 - True - True - - - - - 0 - False - True - - - - - - True - False - 18 - - - - True - False - 6 - - - - True - <b>Packet Parameters</b> - False - True - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - 0.5 - 0.5 - 1 - 1 - 0 - 0 - 12 - 0 - - - - True - 2 - 2 - False - 6 - 12 - - - - True - M_TU: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - mtu - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 0 - 1 - fill - - - - - - - 75 - True - Maximum Transmit Unit - True - 1 - 0 - False - GTK_UPDATE_ALWAYS - False - False - 1000 0 100000 10 100 100 - - - 1 - 2 - 0 - 1 - - - - - - - True - M_RU: - True - False - GTK_JUSTIFY_CENTER - False - False - 0 - 0.5 - 0 - 0 - mru - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 1 - 2 - fill - - - - - - - True - Maximum Receive Unit - True - 1 - 0 - False - GTK_UPDATE_ALWAYS - False - False - 1000 0 10000 10 100 100 - - - 1 - 2 - 1 - 2 - - - - - - - - 0 - True - True - - - - - 0 - False - True - - - - - - True - False - 6 - - - - True - <b>Delays &amp; Timeouts</b> - False - True - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - 0.5 - 0.5 - 1 - 1 - 0 - 0 - 12 - 0 - - - - True - 3 - 2 - False - 6 - 12 - - - - True - Co_nnect delay: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - ppp-connect-delay - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 0 - 1 - fill - - - - - - - True - Disconnect after this many LCP echo requests fail - True - 1 - 0 - False - GTK_UPDATE_ALWAYS - False - False - 0 0 30000 100 1000 1000 - - - 1 - 2 - 0 - 1 - - - - - - - True - LCP echo fail_ure: - True - False - GTK_JUSTIFY_CENTER - False - False - 0 - 0.5 - 0 - 0 - lcp-echo-failure - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 1 - 2 - fill - - - - - - - True - Disconnect after this many LCP echo requests fail - True - 1 - 0 - False - GTK_UPDATE_ALWAYS - False - False - 10 0 1000 1 10 10 - - - 1 - 2 - 1 - 2 - - - - - - - True - LCP echo inter_val: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - lcp-echo-interval - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 2 - 3 - fill - - - - - - - True - Time in seconds between echo requests - True - 1 - 0 - False - GTK_UPDATE_ALWAYS - False - False - 10 0 1000 1 10 10 - - - 1 - 2 - 2 - 3 - - - - - - - - 0 - True - True - - - - - 0 - False - True - - - - - 0 - False - True - - - - - False - True - - - - - - True - PPP Options - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - tab - - - - - - 12 - True - False - 6 - - - - True - True - _Modem connection - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - False - False - - - - - - True - True - _Hardware RTS/CTS - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - False - False - - - - - False - True - - - - - - True - Serial Options - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - tab - - - - - - 12 - True - False - 6 - - - - True - True - _Peer DNS through tunnel - True - GTK_RELIEF_NORMAL - True - True - False - True - - - 0 - False - False - - - - - - True - True - _Only use VPN connection for these addresses: - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - False - False - - - - - - True - 0.5 - 0.5 - 1 - 1 - 0 - 0 - 12 - 0 - - - - True - False - 6 - - - - True - False - True - True - True - 0 - - True - * - False - - - 0 - False - False - - - - - - True - <i>Example: 172.16.0.0/16 10.11.12.0/24</i> - False - True - GTK_JUSTIFY_CENTER - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - - 0 - False - True - - - - - False - True - - - - - - True - Routing - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - tab - - - - - 0 - True - True - - - - - - - diff --git a/vpn-daemons/pptp/properties/nm-ppp-properties.c b/vpn-daemons/pptp/properties/nm-ppp-properties.c deleted file mode 100644 index 6564d9f679..0000000000 --- a/vpn-daemons/pptp/properties/nm-ppp-properties.c +++ /dev/null @@ -1,465 +0,0 @@ -/*************************************************************************** - * CVSID: $Id$ - * - * nm-pptp.c : GNOME UI dialogs for configuring PPTP connections - * - * Copyright (C) 2005 Antony Mee - * Based on work by Tim Niemueller - * and David Zeuthen, - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - **************************************************************************/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include - -#define NMVPNUI_PPTP_PROPERTIES_C - -#include "vpnui_impl.h" -#include "vpnui_opt.h" -#include "vpnui_expand.h" -#include "vpnui_validate.h" -#include "vpnui_variant.h" -#include "util_lists.h" - -#define BUILD_BLUETOOTH - -#define VPNUI_DISPLAY_NAME _("pppd tunnel (PPTP, BTGPRS, Dialup)") -#define VPNUI_SERVICE_NAME "org.freedesktop.NetworkManager.ppp_starter" -#define VPNUI_BASIC_DEFAULTS "connection-name='';" \ - "ppp-debug=no;" \ - "usepeerdns=yes;" \ - "usepeerdns-overtunnel=yes;" \ - "ppp-lock=yes;" \ - "ppp-auth-peer=no;" \ - "ppp-refuse-eap=no;" \ - "ppp-refuse-chap=no;" \ - "ppp-refuse-mschap=no;" \ - "lcp-echo-failure=10;" \ - "lcp-echo-interval=10;" \ - "use-routes=no;" \ - "routes=;" \ - "ppp-debug=no;" \ - "ppp-extra='';" -#define VPNUI_BTOOTH_DEFAULTS "bt-bdaddr=00:00:00:00:00:00;" \ - "bt-channel=1;" -#define VPNUI_GPRS_DEFAULTS "gprs-packet-type=IP;" \ - "gprs-context-num=1;" \ - "gprs-ip-address=0.0.0.0;" \ - "gprs-apn=internet;" \ - "ppp-crtscts=yes;" \ - "ppp-noipdefault=yes;" \ - "ppp-modem=yes;" \ - "usepeerdns=yes;" \ - "ppp-connect-delay=5000;" -#define VPNUI_BTGPRS_DEFAULTS "ppp-connection-type=btgprs;" \ - "encrypt-mppe=no;" \ - "encrypt-mppe-128=no;" \ - "encrypt-mppe-stateful=no;" \ - "compress-mppc=no;" \ - "compress-bsd=no;" \ - "compress-deflate=no;" \ - "mru=1000;" \ - "mtu=1000;" -#define VPNUI_PPTP_DEFAULTS "pptp-remote='';" \ - "ppp-connection-type=pptp;" \ - "encrypt-mppe=no;" \ - "encrypt-mppe-128=yes;" \ - "encrypt-mppe-stateful=yes;" \ - "compress-mppc=no;" \ - "compress-bsd=no;" \ - "compress-deflate=no;" \ - "mru=1416;" \ - "mtu=1416;" -#define VPNUI_DIALUP_DEFAULTS "phone-number=THIS DOESN'T DO ANYTHING;" \ - "ppp-crtscts=yes;" \ - "ppp-modem=yes;" \ - "ppp-connection-type=dialup;" \ - "encrypt-mppe=no;" \ - "encrypt-mppe-128=no;" \ - "encrypt-mppe-stateful=no;" \ - "compress-mppc=no;" \ - "compress-bsd=no;" \ - "compress-deflate=no;" \ - "mru=1000;" \ - "mtu=1000;" - -#ifdef NMVPNUI_PPTP_PROPERTIES_C -#endif - -void impl_setup (NetworkManagerVpnUIImpl *impl); -void impl_hide_and_show (NetworkManagerVpnUIImpl *impl); -void use_routes_toggled (GtkToggleButton *togglebutton, gpointer user_data); -void editable_changed (GtkEditable *editable, gpointer user_data); -void variant_changed (GtkComboBox *combo, gpointer user_data); - - -const char *GLADE_FILE="nm-ppp-dialog.glade"; -const char *GLADE_WIDGET="nm-ppp-widget"; - -void -impl_setup (NetworkManagerVpnUIImpl *impl) -{ - GSList *item; - VpnUIConfigOption *opt; - VpnUIVariant *variant; -// VpnUIExpander *expand; - g_return_if_fail(impl!=NULL); - - impl->display_name = VPNUI_DISPLAY_NAME; - impl->service_name = VPNUI_SERVICE_NAME; -// GLADE NAME TYPE -// GCONF_NAME EXPORT_NAME DESCRIPTION(for summary) -// VALIDATOR_Fn - opt = vpnui_opt_new( - "connection-name", VPN_UI_OPTTYPE_STRING, - NULL, "Description", _("Name"), - G_CALLBACK(&editable_changed), &vld_non_empty, impl ); - impl->connection_name_opt = opt; - - opt = vpnui_opt_new( - "ppp-connection-type", VPN_UI_OPTTYPE_COMBO, - "ppp-connection-type", "Connection-Type", NULL, - G_CALLBACK(&variant_changed), NULL, impl ); - impl->variant_combo = GTK_COMBO_BOX(opt->widget); - - opt = vpnui_opt_new( - "pptp-remote", VPN_UI_OPTTYPE_STRING, - "pptp-remote", "PPTP-Server", _("PPTP Server"), - G_CALLBACK(&editable_changed), &vld_non_empty, impl ); - - opt = vpnui_opt_new( - "phone-number", VPN_UI_OPTTYPE_STRING, - "phone-number", "Telephone-Number", _("Telephone Number"), - G_CALLBACK(&editable_changed), &vld_non_empty, impl ); - - opt = vpnui_opt_new( - "bt-bdaddr", VPN_UI_OPTTYPE_STRING, - "bt-bdaddr", "Bluetooth-Address", _("Bluetooth Address"), - G_CALLBACK(&editable_changed), &vld_non_empty, impl ); - - opt = vpnui_opt_new( - "bt-channel", VPN_UI_OPTTYPE_STRING, - "bt-channel", "Bluetooth-Channel", _("Bluetooth Channel"), - G_CALLBACK(&editable_changed), &vld_non_empty, impl ); - - opt = vpnui_opt_new( - "gprs-apn", VPN_UI_OPTTYPE_STRING, - "gprs-apn", "GPRS-Access-Point-Name", _("GPRS APN"), - G_CALLBACK(&editable_changed), &vld_non_empty, impl ); - - opt = vpnui_opt_new( - "gprs-ip-address", VPN_UI_OPTTYPE_STRING, - "gprs-ip-address", "GPRS-IP-Address", _("GPRS IP"), - G_CALLBACK(&editable_changed), &vld_non_empty, impl ); - - opt = vpnui_opt_new( - "gprs-context-num", VPN_UI_OPTTYPE_STRING, - "gprs-context-num", "GPRS-Context-Number", _("GPRS Context No."), - G_CALLBACK(&editable_changed), &vld_non_empty, impl ); - - opt = vpnui_opt_new( - "gprs-packet-type", VPN_UI_OPTTYPE_STRING, - "gprs-packet-type", "GPRS-Packet-Type", _("GPRS Packet Type"), - G_CALLBACK(&editable_changed), &vld_non_empty, impl ); - - opt = vpnui_opt_new( - "ppp-crtscts", VPN_UI_OPTTYPE_YESNO, - "ppp-crtscts", "PPP-Hardware-CTSRTS", _("Use CTS/RTS flow control"), - G_CALLBACK(&editable_changed), NULL, impl ); - - opt = vpnui_opt_new( - "ppp-modem", VPN_UI_OPTTYPE_YESNO, - "ppp-modem", "PPP-Modem", _("Connect via a modem"), - G_CALLBACK(&editable_changed), NULL, impl ); - - opt = vpnui_opt_new( - "ppp-noipdefault", VPN_UI_OPTTYPE_YESNO, - "ppp-noipdefault", "PPP-No-IP-Default", _("Require IP to be provided"), - G_CALLBACK(&editable_changed), NULL, impl ); - - opt = vpnui_opt_new( - "usepeerdns" , VPN_UI_OPTTYPE_YESNO , - "usepeerdns", "Use-Peer-DNS", _("Use Peer DNS"), - NULL, NULL, impl ); - - opt = vpnui_opt_new( - "encrypt-mppe" , VPN_UI_OPTTYPE_YESNO , - "encrypt-mppe", "Encrypt-MPPE", _("Use MPPE encryption"), - NULL, NULL, impl ); - - opt = vpnui_opt_new( - "encrypt-mppe-128" , VPN_UI_OPTTYPE_YESNO , - "encrypt-mppe-128", "Encrypt-MPPE-128", _("Use 128 bit MPPE encryption"), - NULL, NULL, impl ); - - opt = vpnui_opt_new( - "encrypt-mppe-stateful" , VPN_UI_OPTTYPE_YESNO , - "encrypt-mppe-stateful", "Encrypt-MPPE-Stateful", _("Enable stateful MPPE"), - NULL, NULL, impl ); - - opt = vpnui_opt_new( - "compress-mppc" , VPN_UI_OPTTYPE_YESNO , - "compress-mppc", "Compress-MPPC", _("Use MPPC compression"), - NULL, NULL, impl ); - - opt = vpnui_opt_new( - "compress-deflate" , VPN_UI_OPTTYPE_YESNO , - "compress-deflate", "Compress-Deflate", _("Do not use deflate compression"), - NULL, NULL, impl ); - - opt = vpnui_opt_new( - "compress-bsd" , VPN_UI_OPTTYPE_YESNO , - "compress-bsd", "Compress-BSD", _("Do not use BSD compression"), - NULL, NULL, impl ); - - opt = vpnui_opt_new( - "ppp-lock" , VPN_UI_OPTTYPE_YESNO , - "ppp-lock", "PPP-Lock", _("Exclusive device access by pppd"), - NULL, NULL, impl ); - - opt = vpnui_opt_new( - "ppp-auth-peer" , VPN_UI_OPTTYPE_YESNO , - "ppp-auth-peer", "Auth-Peer", _("Authenticate remote peer"), - NULL, NULL, impl ); - - opt = vpnui_opt_new( - "ppp-refuse-eap" , VPN_UI_OPTTYPE_YESNO , - "ppp-refuse-eap", "Refuse-EAP", _("Refuse EAP"), - NULL, NULL, impl ); - - opt = vpnui_opt_new( - "ppp-refuse-chap" , VPN_UI_OPTTYPE_YESNO , - "ppp-refuse-chap", "Refuse-CHAP", _("Refuse CHAP"), - NULL, NULL, impl ); - - opt = vpnui_opt_new( - "ppp-refuse-mschap" , VPN_UI_OPTTYPE_YESNO , - "ppp-refuse-mschap", "Refuse-MSCHAP", _("Refuse MSCHAP"), - NULL, NULL, impl ); - - opt = vpnui_opt_new( - "mtu" , VPN_UI_OPTTYPE_SPINNER , - "mtu", "MTU", _("Maximum transmit unit (in bytes)"), - NULL, NULL, impl ); - - opt = vpnui_opt_new( - "mru" , VPN_UI_OPTTYPE_SPINNER , - "mru", "MRU", _("Maximum receive unit (in bytes)"), - NULL, NULL, impl ); - - opt = vpnui_opt_new( - "lcp-echo-failure" , VPN_UI_OPTTYPE_SPINNER , - "lcp-echo-failure", "LCP-Echo-Failure", _("Number of failed LCP echos to cause disconnect"), - NULL, NULL, impl ); - - opt = vpnui_opt_new( - "lcp-echo-interval" , VPN_UI_OPTTYPE_SPINNER , - "lcp-echo-interval", "LCP-Echo-Interval", _("Interval (in seconds) at which to issue LCP echos"), - NULL, NULL, impl ); - - opt = vpnui_opt_new( - "ppp-connect-delay" , VPN_UI_OPTTYPE_SPINNER , - "ppp-connect-delay", "PPP-Connect-Delay", _("Interval (in milliseconds) to wait before connecting."), - NULL, NULL, impl ); - - opt = vpnui_opt_new( - "ppp-extra", VPN_UI_OPTTYPE_STRING, - "ppp-extra", "PPP-Custom-Options", _("Custom PPP options"), - G_CALLBACK(&editable_changed), NULL, impl ); - - opt = vpnui_opt_new( - "ppp-debug" , VPN_UI_OPTTYPE_YESNO , - "ppp-debug", NULL, NULL, - NULL, NULL, impl ); - - opt = vpnui_opt_new( - "usepeerdns-overtunnel" , VPN_UI_OPTTYPE_YESNO , - "usepeerdns-overtunnel", "Peer-DNS-Over-Tunnel", _("Use Peer DNS over the Tunnel"), - NULL, NULL, impl ); - - - opt = vpnui_opt_new( - "routes" , VPN_UI_OPTTYPE_STRING , - "routes", "X-NM-Routes", _("Specific networks available"), - G_CALLBACK(&editable_changed), &vld_routes_if_sens, impl ); - impl->routes_opt = opt; - - opt = vpnui_opt_new( - "use-routes" , VPN_UI_OPTTYPE_YESNO , - "use-routes", "Use-Routes", _("Limit to specific networks"), - G_CALLBACK(&use_routes_toggled), NULL, impl ); - impl->routes_toggle_opt = opt; - - variant = vpnui_variant_new( "pptp","Windows VPN (PPTP)", - VPNUI_BASIC_DEFAULTS VPNUI_PPTP_DEFAULTS, - impl); - -#ifdef BUILD_BLUETOOTH - variant = vpnui_variant_new( "btgprs", "GPRS over Bluetooth (via mobile phone)", - VPNUI_BASIC_DEFAULTS VPNUI_GPRS_DEFAULTS VPNUI_BTOOTH_DEFAULTS VPNUI_BTGPRS_DEFAULTS, - impl); -#endif - - variant = vpnui_variant_new( "dialup", "Dialup", - VPNUI_BASIC_DEFAULTS VPNUI_DIALUP_DEFAULTS, - impl); -// -// GLADE NAME IMPLEMENTATION_OBJ -// expand= vpnui_expand_new ("routing-expander",impl); -// expand= vpnui_expand_new ("dialup-expander",impl); -// expand= vpnui_expand_new ("pppd-expander",impl); -// expand= vpnui_expand_new ("pptp-expander",impl); -// expand= vpnui_expand_new ("bluetooth-expander",impl); -// expand= vpnui_expand_new ("serial-expander",impl); -// expand= vpnui_expand_new ("gprs-expander",impl); - -// Attach to press event of the Bluetooth "Find Device" button. -// will need libbtcl -// impl->w_import_button = GTK_BUTTON (glade_xml_get_widget (impl->xml, -// "import-button")); - -// Attach an import_button - impl->w_import_button = GTK_BUTTON (glade_xml_get_widget (impl->xml, - "import-config-button")); -} - -void -use_routes_toggled (GtkToggleButton *togglebutton, gpointer user_data) -{ - NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) user_data; - VpnUIConfigOption *opt = impl_opt_byglade(impl,"routes"); - - if (opt!=NULL) gtk_widget_set_sensitive (GTK_WIDGET (opt->widget), - gtk_toggle_button_get_active (togglebutton)); - - if (impl->callback != NULL) { - gboolean is_valid; - - is_valid = impl_is_valid (&(impl->parent)); - impl->callback (&(impl->parent), is_valid, impl->callback_user_data); - } -} - -void -editable_changed (GtkEditable *editable, gpointer user_data) -{ - NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) user_data; - - if (impl->callback != NULL) { - gboolean is_valid; - - is_valid = impl_is_valid (&(impl->parent)); - impl->callback (&(impl->parent), is_valid, impl->callback_user_data); - } -} - -void -variant_changed (GtkComboBox *combo, gpointer user_data) -{ - NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) user_data; - char *variant_name; - - - variant_name=gtk_combo_box_get_active_text(combo); - - vpnui_variant_select_byname(impl,variant_name); - - impl_hide_and_show(impl); - -// vpnui_expand_reset_all(impl); - - if (impl->callback != NULL) { - gboolean is_valid; - - is_valid = impl_is_valid (&(impl->parent)); - impl->callback (&(impl->parent), is_valid, impl->callback_user_data); - } -} - - -void -impl_hide_and_show (NetworkManagerVpnUIImpl *impl) -{ - GtkWidget *serial_options = NULL; - GtkWidget *gprs_options = NULL; - GtkWidget *auth_options = NULL; - GtkWidget *comp_enc_options = NULL; - GtkWidget *routing_options = NULL; - GtkWidget *ppp_options = NULL; - GtkWidget *bluetooth_front = NULL; - GtkWidget *pptp_front = NULL; - GtkWidget *dialup_front = NULL; - GtkComboBox *combo = NULL; - char *variant_name; - - if (impl==NULL) return; - if (impl->xml==NULL) return; - - combo = GTK_COMBO_BOX(glade_xml_get_widget(impl->xml, "ppp-connection-type")); - if (combo==NULL) return; - - ppp_options = glade_xml_get_widget(impl->xml, "ppp-options"); - auth_options = glade_xml_get_widget(impl->xml, "auth-options"); - comp_enc_options = glade_xml_get_widget(impl->xml, "comp-enc-options"); - routing_options = glade_xml_get_widget(impl->xml, "routing-options"); - gprs_options = glade_xml_get_widget(impl->xml, "gprs-options"); - serial_options = glade_xml_get_widget(impl->xml, "serial-options"); - bluetooth_front = glade_xml_get_widget(impl->xml, "bluetooth-front"); - dialup_front = glade_xml_get_widget(impl->xml, "dialup-front"); - pptp_front = glade_xml_get_widget(impl->xml, "pptp-front"); - - if (pptp_front) gtk_widget_hide(pptp_front); - if (bluetooth_front) gtk_widget_hide(bluetooth_front); - if (dialup_front) gtk_widget_hide(dialup_front); - if (gprs_options) gtk_widget_hide(gprs_options); - if (serial_options) gtk_widget_hide(serial_options); - if (ppp_options) gtk_widget_hide(ppp_options); - if (auth_options) gtk_widget_hide(auth_options); - if (comp_enc_options) gtk_widget_hide(comp_enc_options); - if (routing_options) gtk_widget_hide(routing_options); - - variant_name=gtk_combo_box_get_active_text(combo); - if (variant_name==NULL) return; - - if (strcmp(variant_name,"pptp")==0) { - if (pptp_front) gtk_widget_show(pptp_front); - if (ppp_options) gtk_widget_show(ppp_options); - if (auth_options) gtk_widget_show(auth_options); - if (comp_enc_options) gtk_widget_show(comp_enc_options); - if (routing_options) gtk_widget_show(routing_options); - } else if (strcmp(variant_name,"dialup")==0) { - if (dialup_front) gtk_widget_show(dialup_front); - if (serial_options) gtk_widget_show(serial_options); - if (ppp_options) gtk_widget_show(ppp_options); - if (auth_options) gtk_widget_show(auth_options); - if (comp_enc_options) gtk_widget_show(comp_enc_options); - if (routing_options) gtk_widget_show(routing_options); - } else if (strcmp(variant_name,"btgprs")==0) { - if (bluetooth_front) gtk_widget_show(bluetooth_front); - if (gprs_options) gtk_widget_show(gprs_options); - if (serial_options) gtk_widget_show(serial_options); - if (ppp_options) gtk_widget_show(ppp_options); - if (auth_options) gtk_widget_show(auth_options); - if (comp_enc_options) gtk_widget_show(comp_enc_options); - if (routing_options) gtk_widget_show(routing_options); - } -} diff --git a/vpn-daemons/pptp/properties/nm-ppp-properties.h b/vpn-daemons/pptp/properties/nm-ppp-properties.h deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/vpn-daemons/pptp/properties/nm-pptp-dialog.glade b/vpn-daemons/pptp/properties/nm-pptp-dialog.glade new file mode 100644 index 0000000000..5c746f3784 --- /dev/null +++ b/vpn-daemons/pptp/properties/nm-pptp-dialog.glade @@ -0,0 +1,538 @@ + + + + + + window1 + + + True + 12 + 16 + + + True + 6 + + + True + 0 + <b>General</b> + True + + + False + False + + + + + True + 12 + + + True + 1 + 2 + 6 + 6 + + + True + 0 + _Gateway: + True + gateway_entry + + + GTK_FILL + + + + + + True + True + + + 1 + 2 + + + + + + + + 1 + + + + + False + + + + + True + 6 + + + True + 0 + <b>Optional</b> + True + + + False + False + + + + + True + 12 + + + True + 2 + 2 + 6 + 6 + + + True + 0 + User name: + + + GTK_FILL + + + + + + True + True + + + 1 + 2 + + + + + + True + 0 + Domain: + + + 1 + 2 + GTK_FILL + + + + + + True + True + + + 1 + 2 + 1 + 2 + + + + + + + + 1 + + + + + False + False + 1 + + + + + True + 1 + 0 + + + True + True + True + 0 + + + True + 6 + + + True + gtk-preferences + + + False + False + + + + + True + Ad_vanced... + True + True + + + False + False + 1 + + + + + + + + + False + False + GTK_PACK_END + 2 + + + + + + + 5 + GTK_WIN_POS_CENTER_ON_PARENT + True + stock-preferences + GDK_WINDOW_TYPE_HINT_DIALOG + True + False + + + True + 2 + + + True + 12 + 16 + + + True + 6 + + + True + 0 + <b>Authentication</b> + True + + + False + False + + + + + True + 12 + + + True + 6 + + + True + 0 + Allow the following authentication methods: + + + + + True + True + GTK_POLICY_NEVER + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + + + True + True + False + + + + + 1 + + + + + + + False + 1 + + + + + False + + + + + True + 6 + + + True + 0 + <b>Security and Compression</b> + True + + + False + False + + + + + True + 12 + + + True + + + True + + + True + True + Use Point-to-Point Encryption (MPPE) + True + 0 + True + + + False + False + + + + + True + 12 + + + True + + + True + + + True + 0 + Security: + + + False + 6 + + + + + True + Default + + + 1 + + + + + + + True + True + Allow Stateful Encryption + True + 0 + True + + + False + False + 1 + + + + + + + 1 + + + + + False + False + + + + + True + True + Allow BSD data compression + True + 0 + True + + + False + False + 1 + + + + + True + True + Allow Deflate data compression + True + 0 + True + + + False + False + 2 + + + + + True + True + Use TCP header compression + True + 0 + True + + + False + False + 3 + + + + + + + False + 1 + + + + + False + 1 + + + + + True + 6 + + + True + 0 + <b>Echo</b> + True + + + False + False + + + + + True + 12 + + + True + True + Send PPP echo packets + True + 0 + True + + + + + 1 + + + + + False + 2 + + + + + 1 + + + + + True + GTK_BUTTONBOX_END + + + True + True + True + gtk-cancel + True + -6 + + + + + True + True + True + gtk-ok + True + -5 + + + 1 + + + + + False + GTK_PACK_END + + + + + + diff --git a/vpn-daemons/pptp/properties/nm-pptp.c b/vpn-daemons/pptp/properties/nm-pptp.c new file mode 100644 index 0000000000..756c249ced --- /dev/null +++ b/vpn-daemons/pptp/properties/nm-pptp.c @@ -0,0 +1,654 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/*************************************************************************** + * nm-pptp.c : GNOME UI dialogs for configuring PPTP VPN connections + * + * Copyright (C) 2008 Dan Williams, + * Based on work by David Zeuthen, + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + **************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#define NM_VPN_API_SUBJECT_TO_CHANGE + +#include +#include +#include +#include +#include + +#include "../src/nm-pptp-service.h" +#include "nm-pptp.h" +#include "import-export.h" +#include "advanced-dialog.h" + +#define PPTP_PLUGIN_NAME _("Point-to-Point Tunneling Protocol (PPTP)") +#define PPTP_PLUGIN_DESC _("Compatible with Microsoft and other PPTP VPN servers.") +#define PPTP_PLUGIN_SERVICE NM_DBUS_SERVICE_PPTP + + +/************** plugin class **************/ + +static void pptp_plugin_ui_interface_init (NMVpnPluginUiInterface *iface_class); + +G_DEFINE_TYPE_EXTENDED (PptpPluginUi, pptp_plugin_ui, G_TYPE_OBJECT, 0, + G_IMPLEMENT_INTERFACE (NM_TYPE_VPN_PLUGIN_UI_INTERFACE, + pptp_plugin_ui_interface_init)) + +/************** UI widget class **************/ + +static void pptp_plugin_ui_widget_interface_init (NMVpnPluginUiWidgetInterface *iface_class); + +G_DEFINE_TYPE_EXTENDED (PptpPluginUiWidget, pptp_plugin_ui_widget, G_TYPE_OBJECT, 0, + G_IMPLEMENT_INTERFACE (NM_TYPE_VPN_PLUGIN_UI_WIDGET_INTERFACE, + pptp_plugin_ui_widget_interface_init)) + +#define PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PPTP_TYPE_PLUGIN_UI_WIDGET, PptpPluginUiWidgetPrivate)) + +typedef struct { + GladeXML *xml; + GtkWidget *widget; + GtkSizeGroup *group; + GtkWindowGroup *window_group; + gboolean window_added; + GHashTable *advanced; +} PptpPluginUiWidgetPrivate; + + +GQuark +pptp_plugin_ui_error_quark (void) +{ + static GQuark error_quark = 0; + + if (G_UNLIKELY (error_quark == 0)) + error_quark = g_quark_from_static_string ("pptp-plugin-ui-error-quark"); + + return error_quark; +} + +/* This should really be standard. */ +#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC } + +GType +pptp_plugin_ui_error_get_type (void) +{ + static GType etype = 0; + + if (etype == 0) { + static const GEnumValue values[] = { + /* Unknown error. */ + ENUM_ENTRY (PPTP_PLUGIN_UI_ERROR_UNKNOWN, "UnknownError"), + /* The specified property was invalid. */ + ENUM_ENTRY (PPTP_PLUGIN_UI_ERROR_INVALID_PROPERTY, "InvalidProperty"), + /* The specified property was missing and is required. */ + ENUM_ENTRY (PPTP_PLUGIN_UI_ERROR_MISSING_PROPERTY, "MissingProperty"), + /* The file to import could not be read. */ + ENUM_ENTRY (PPTP_PLUGIN_UI_ERROR_FILE_NOT_READABLE, "FileNotReadable"), + /* The file to import could was not an PPTP client file. */ + ENUM_ENTRY (PPTP_PLUGIN_UI_ERROR_FILE_NOT_PPTP, "FileNotPPTP"), + { 0, 0, 0 } + }; + etype = g_enum_register_static ("PptpPluginUiError", values); + } + return etype; +} + +static gboolean +check_validity (PptpPluginUiWidget *self, GError **error) +{ + PptpPluginUiWidgetPrivate *priv = PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE (self); + GtkWidget *widget; + const char *str; + GtkTreeModel *model; + GtkTreeIter iter; + + widget = glade_xml_get_widget (priv->xml, "gateway_entry"); + str = gtk_entry_get_text (GTK_ENTRY (widget)); + if (!str || !strlen (str)) { + g_set_error (error, + PPTP_PLUGIN_UI_ERROR, + PPTP_PLUGIN_UI_ERROR_INVALID_PROPERTY, + NM_PPTP_KEY_GATEWAY); + return FALSE; + } + + return TRUE; +} + +static void +stuff_changed_cb (GtkWidget *widget, gpointer user_data) +{ + g_signal_emit_by_name (PPTP_PLUGIN_UI_WIDGET (user_data), "changed"); +} + +static void +advanced_dialog_close_cb (GtkWidget *dialog, gpointer user_data) +{ + PptpPluginUiWidget *self = PPTP_PLUGIN_UI_WIDGET (user_data); + + gtk_widget_hide (dialog); + /* gtk_widget_destroy() will remove the window from the window group */ + gtk_widget_destroy (dialog); +} + +static void +advanced_dialog_response_cb (GtkWidget *dialog, gint response, gpointer user_data) +{ + PptpPluginUiWidget *self = PPTP_PLUGIN_UI_WIDGET (user_data); + PptpPluginUiWidgetPrivate *priv = PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE (self); + GError *error = NULL; + + if (response != GTK_RESPONSE_OK) { + advanced_dialog_close_cb (dialog, self); + return; + } + + if (priv->advanced) + g_hash_table_destroy (priv->advanced); + priv->advanced = advanced_dialog_new_hash_from_dialog (dialog, &error); + if (!priv->advanced) { + g_message ("%s: error reading advanced settings: %s", __func__, error->message); + g_error_free (error); + } + advanced_dialog_close_cb (dialog, self); + + stuff_changed_cb (NULL, self); +} + +static void +advanced_button_clicked_cb (GtkWidget *button, gpointer user_data) +{ + PptpPluginUiWidget *self = PPTP_PLUGIN_UI_WIDGET (user_data); + PptpPluginUiWidgetPrivate *priv = PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE (self); + GtkWidget *dialog, *toplevel, *widget; + + toplevel = gtk_widget_get_toplevel (priv->widget); + g_return_if_fail (GTK_WIDGET_TOPLEVEL (toplevel)); + + dialog = advanced_dialog_new (priv->advanced); + if (!dialog) { + g_warning ("%s: failed to create the Advanced dialog!", __func__); + return; + } + + gtk_window_group_add_window (priv->window_group, GTK_WINDOW (dialog)); + if (!priv->window_added) { + gtk_window_group_add_window (priv->window_group, GTK_WINDOW (toplevel)); + priv->window_added = TRUE; + } + + gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (toplevel)); + g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (advanced_dialog_response_cb), self); + g_signal_connect (G_OBJECT (dialog), "close", G_CALLBACK (advanced_dialog_close_cb), self); + + gtk_widget_show_all (dialog); +} + +static gboolean +init_plugin_ui (PptpPluginUiWidget *self, NMConnection *connection, GError **error) +{ + PptpPluginUiWidgetPrivate *priv = PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE (self); + NMSettingVPNProperties *s_vpn_props; + GtkWidget *widget; + GtkListStore *store; + GtkTreeIter iter; + int active = -1; + GValue *value; + + s_vpn_props = (NMSettingVPNProperties *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN_PROPERTIES); + + priv->group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); + + widget = glade_xml_get_widget (priv->xml, "gateway_entry"); + if (!widget) + return FALSE; + gtk_size_group_add_widget (priv->group, widget); + if (s_vpn_props) { + value = g_hash_table_lookup (s_vpn_props->data, NM_PPTP_KEY_GATEWAY); + if (value && G_VALUE_HOLDS_STRING (value)) + gtk_entry_set_text (GTK_ENTRY (widget), g_value_get_string (value)); + } + g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (stuff_changed_cb), self); + + widget = glade_xml_get_widget (priv->xml, "user_entry"); + if (!widget) + return FALSE; + gtk_size_group_add_widget (priv->group, widget); + if (s_vpn_props) { + value = g_hash_table_lookup (s_vpn_props->data, NM_PPTP_KEY_USER); + if (value && G_VALUE_HOLDS_STRING (value)) + gtk_entry_set_text (GTK_ENTRY (widget), g_value_get_string (value)); + } + g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (stuff_changed_cb), self); + + widget = glade_xml_get_widget (priv->xml, "domain_entry"); + if (!widget) + return FALSE; + gtk_size_group_add_widget (priv->group, widget); + if (s_vpn_props) { + value = g_hash_table_lookup (s_vpn_props->data, NM_PPTP_KEY_DOMAIN); + if (value && G_VALUE_HOLDS_STRING (value)) + gtk_entry_set_text (GTK_ENTRY (widget), g_value_get_string (value)); + } + g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (stuff_changed_cb), self); + + widget = glade_xml_get_widget (priv->xml, "advanced_button"); + g_signal_connect (G_OBJECT (widget), "clicked", G_CALLBACK (advanced_button_clicked_cb), self); + + return TRUE; +} + +static GObject * +get_widget (NMVpnPluginUiWidgetInterface *iface) +{ + PptpPluginUiWidget *self = PPTP_PLUGIN_UI_WIDGET (iface); + PptpPluginUiWidgetPrivate *priv = PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE (self); + + return G_OBJECT (priv->widget); +} + +GValue * +str_to_gvalue (const char *str) +{ + GValue *value; + + value = g_slice_new0 (GValue); + g_value_init (value, G_TYPE_STRING); + g_value_set_string (value, str); + + return value; +} + +GValue * +bool_to_gvalue (gboolean b) +{ + GValue *value; + + value = g_slice_new0 (GValue); + g_value_init (value, G_TYPE_BOOLEAN); + g_value_set_boolean (value, b); + + return value; +} + +GValue * +int_to_gvalue (gint i) +{ + GValue *value; + + value = g_slice_new0 (GValue); + g_value_init (value, G_TYPE_INT); + g_value_set_int (value, i); + + return value; +} + +GValue * +uint_to_gvalue (guint32 u) +{ + GValue *value; + + value = g_slice_new0 (GValue); + g_value_init (value, G_TYPE_UINT); + g_value_set_uint (value, u); + + return value; +} + +static void +hash_copy_advanced (gpointer key, gpointer data, gpointer user_data) +{ + GHashTable *hash = (GHashTable *) user_data; + GValue *value = (GValue *) data; + + if (G_VALUE_HOLDS_STRING (value)) { + g_hash_table_insert (hash, + g_strdup ((const char *) key), + str_to_gvalue (g_value_get_string (value))); + } else if (G_VALUE_HOLDS_INT (value)) { + g_hash_table_insert (hash, + g_strdup ((const char *) key), + int_to_gvalue (g_value_get_int (value))); + } else if (G_VALUE_HOLDS_BOOLEAN (value)) { + g_hash_table_insert (hash, + g_strdup ((const char *) key), + bool_to_gvalue (g_value_get_boolean (value))); + } else { + g_warning ("%s: unhandled key '%s' of type '%s'", + __func__, (const char *) key, G_VALUE_TYPE_NAME (value)); + } +} + +static gboolean +update_connection (NMVpnPluginUiWidgetInterface *iface, + NMConnection *connection, + GError **error) +{ + PptpPluginUiWidget *self = PPTP_PLUGIN_UI_WIDGET (iface); + PptpPluginUiWidgetPrivate *priv = PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE (self); + NMSettingVPN *s_vpn; + NMSettingVPNProperties *s_vpn_props; + GtkWidget *widget; + char *str; + GtkTreeModel *model; + GtkTreeIter iter; + gboolean valid = FALSE; + + if (!check_validity (self, error)) + return FALSE; + + s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ()); + s_vpn->service_type = g_strdup (NM_DBUS_SERVICE_PPTP); + nm_connection_add_setting (connection, NM_SETTING (s_vpn)); + + s_vpn_props = NM_SETTING_VPN_PROPERTIES (nm_setting_vpn_properties_new ()); + + /* Gateway */ + widget = glade_xml_get_widget (priv->xml, "gateway_entry"); + str = (char *) gtk_entry_get_text (GTK_ENTRY (widget)); + if (str && strlen (str)) { + g_hash_table_insert (s_vpn_props->data, + g_strdup (NM_PPTP_KEY_GATEWAY), + str_to_gvalue (str)); + } + + /* Username */ + widget = glade_xml_get_widget (priv->xml, "user_entry"); + str = (char *) gtk_entry_get_text (GTK_ENTRY (widget)); + if (str && strlen (str)) { + g_hash_table_insert (s_vpn_props->data, + g_strdup (NM_PPTP_KEY_USER), + str_to_gvalue (str)); + } + + /* Domain */ + widget = glade_xml_get_widget (priv->xml, "domain_entry"); + str = (char *) gtk_entry_get_text (GTK_ENTRY (widget)); + if (str && strlen (str)) { + g_hash_table_insert (s_vpn_props->data, + g_strdup (NM_PPTP_KEY_DOMAIN), + str_to_gvalue (str)); + } + + if (priv->advanced) + g_hash_table_foreach (priv->advanced, hash_copy_advanced, s_vpn_props->data); + + nm_connection_add_setting (connection, NM_SETTING (s_vpn_props)); + valid = TRUE; + +done: + return valid; +} + +static NMVpnPluginUiWidgetInterface * +nm_vpn_plugin_ui_widget_interface_new (NMConnection *connection, GError **error) +{ + NMVpnPluginUiWidgetInterface *object; + PptpPluginUiWidgetPrivate *priv; + char *glade_file; + + if (error) + g_return_val_if_fail (*error == NULL, NULL); + + object = NM_VPN_PLUGIN_UI_WIDGET_INTERFACE (g_object_new (PPTP_TYPE_PLUGIN_UI_WIDGET, NULL)); + if (!object) { + g_set_error (error, PPTP_PLUGIN_UI_ERROR, 0, "could not create pptp object"); + return NULL; + } + + priv = PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE (object); + + glade_file = g_strdup_printf ("%s/%s", GLADEDIR, "nm-pptp-dialog.glade"); + priv->xml = glade_xml_new (glade_file, "pptp-vbox", GETTEXT_PACKAGE); + if (priv->xml == NULL) { + g_set_error (error, PPTP_PLUGIN_UI_ERROR, 0, + "could not load required resources at %s", glade_file); + g_free (glade_file); + g_object_unref (object); + return NULL; + } + g_free (glade_file); + + priv->widget = glade_xml_get_widget (priv->xml, "pptp-vbox"); + if (!priv->widget) { + g_set_error (error, PPTP_PLUGIN_UI_ERROR, 0, "could not load UI widget"); + g_object_unref (object); + return NULL; + } + g_object_ref_sink (priv->widget); + + priv->window_group = gtk_window_group_new (); + + if (!init_plugin_ui (PPTP_PLUGIN_UI_WIDGET (object), connection, error)) { + g_object_unref (object); + return NULL; + } + + priv->advanced = advanced_dialog_new_hash_from_connection (connection, error); + if (!priv->advanced) { + g_object_unref (object); + return NULL; + } + + return object; +} + +static void +dispose (GObject *object) +{ + PptpPluginUiWidget *plugin = PPTP_PLUGIN_UI_WIDGET (object); + PptpPluginUiWidgetPrivate *priv = PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE (plugin); + + if (priv->group) + g_object_unref (priv->group); + + if (priv->window_group) + g_object_unref (priv->window_group); + + if (priv->widget) + g_object_unref (priv->widget); + + if (priv->xml) + g_object_unref (priv->xml); + + if (priv->advanced) + g_hash_table_destroy (priv->advanced); + + G_OBJECT_CLASS (pptp_plugin_ui_widget_parent_class)->dispose (object); +} + +static void +pptp_plugin_ui_widget_class_init (PptpPluginUiWidgetClass *req_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (req_class); + + g_type_class_add_private (req_class, sizeof (PptpPluginUiWidgetPrivate)); + + object_class->dispose = dispose; +} + +static void +pptp_plugin_ui_widget_init (PptpPluginUiWidget *plugin) +{ +} + +static void +pptp_plugin_ui_widget_interface_init (NMVpnPluginUiWidgetInterface *iface_class) +{ + /* interface implementation */ + iface_class->get_widget = get_widget; + iface_class->update_connection = update_connection; +} + +static NMConnection * +import (NMVpnPluginUiInterface *iface, const char *path, GError **error) +{ + NMConnection *connection = NULL; + char *contents = NULL; + char **lines = NULL; + char *ext; + + ext = strrchr (path, '.'); + if (!ext) { + g_set_error (error, + PPTP_PLUGIN_UI_ERROR, + PPTP_PLUGIN_UI_ERROR_FILE_NOT_PPTP, + "unknown PPTP file extension"); + goto out; + } + + if (strcmp (ext, ".conf") && strcmp (ext, ".cnf")) { + g_set_error (error, + PPTP_PLUGIN_UI_ERROR, + PPTP_PLUGIN_UI_ERROR_FILE_NOT_PPTP, + "unknown PPTP file extension"); + goto out; + } + + if (!g_file_get_contents (path, &contents, NULL, error)) + return NULL; + + lines = g_strsplit_set (contents, "\r\n", 0); + if (g_strv_length (lines) <= 1) { + g_set_error (error, + PPTP_PLUGIN_UI_ERROR, + PPTP_PLUGIN_UI_ERROR_FILE_NOT_READABLE, + "not a valid PPTP configuration file"); + goto out; + } + + connection = do_import (path, lines, error); + +out: + if (lines) + g_strfreev (lines); + g_free (contents); + return connection; +} + +static gboolean +export (NMVpnPluginUiInterface *iface, + const char *path, + NMConnection *connection, + GError **error) +{ + return do_export (path, connection, error); +} + +static char * +get_suggested_name (NMVpnPluginUiInterface *iface, NMConnection *connection) +{ + NMSettingConnection *s_con; + + g_return_val_if_fail (connection != NULL, NULL); + + s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION)); + g_return_val_if_fail (s_con != NULL, NULL); + g_return_val_if_fail (s_con->id != NULL, NULL); + + return g_strdup_printf ("%s (pptp).conf", s_con->id); +} + +static guint32 +get_capabilities (NMVpnPluginUiInterface *iface) +{ + return (NM_VPN_PLUGIN_UI_CAPABILITY_IMPORT | NM_VPN_PLUGIN_UI_CAPABILITY_EXPORT); +} + +static NMVpnPluginUiWidgetInterface * +ui_factory (NMVpnPluginUiInterface *iface, NMConnection *connection, GError **error) +{ + return nm_vpn_plugin_ui_widget_interface_new (connection, error); +} + +static void +get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + switch (prop_id) { + case NM_VPN_PLUGIN_UI_INTERFACE_PROP_NAME: + g_value_set_string (value, PPTP_PLUGIN_NAME); + break; + case NM_VPN_PLUGIN_UI_INTERFACE_PROP_DESC: + g_value_set_string (value, PPTP_PLUGIN_DESC); + break; + case NM_VPN_PLUGIN_UI_INTERFACE_PROP_SERVICE: + g_value_set_string (value, PPTP_PLUGIN_SERVICE); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +pptp_plugin_ui_class_init (PptpPluginUiClass *req_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (req_class); + + object_class->get_property = get_property; + + g_object_class_override_property (object_class, + NM_VPN_PLUGIN_UI_INTERFACE_PROP_NAME, + NM_VPN_PLUGIN_UI_INTERFACE_NAME); + + g_object_class_override_property (object_class, + NM_VPN_PLUGIN_UI_INTERFACE_PROP_DESC, + NM_VPN_PLUGIN_UI_INTERFACE_DESC); + + g_object_class_override_property (object_class, + NM_VPN_PLUGIN_UI_INTERFACE_PROP_SERVICE, + NM_VPN_PLUGIN_UI_INTERFACE_SERVICE); +} + +static void +pptp_plugin_ui_init (PptpPluginUi *plugin) +{ +} + +static void +pptp_plugin_ui_interface_init (NMVpnPluginUiInterface *iface_class) +{ + /* interface implementation */ + iface_class->ui_factory = ui_factory; + iface_class->get_capabilities = get_capabilities; + iface_class->import = import; + iface_class->export = export; + iface_class->get_suggested_name = get_suggested_name; +} + + +G_MODULE_EXPORT NMVpnPluginUiInterface * +nm_vpn_plugin_ui_factory (GError **error) +{ + if (error) + g_return_val_if_fail (*error == NULL, NULL); + + return NM_VPN_PLUGIN_UI_INTERFACE (g_object_new (PPTP_TYPE_PLUGIN_UI, NULL)); +} + diff --git a/vpn-daemons/pptp/properties/nm-pptp.h b/vpn-daemons/pptp/properties/nm-pptp.h new file mode 100644 index 0000000000..9ff8b9fb04 --- /dev/null +++ b/vpn-daemons/pptp/properties/nm-pptp.h @@ -0,0 +1,94 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/*************************************************************************** + * nm-pptp.h : GNOME UI dialogs for configuring pptp VPN connections + * + * Copyright (C) 2008 Dan Williams, + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + **************************************************************************/ + +#ifndef _NM_PPTP_H_ +#define _NM_PPTP_H_ + +#include + +typedef enum +{ + PPTP_PLUGIN_UI_ERROR_UNKNOWN = 0, + PPTP_PLUGIN_UI_ERROR_INVALID_PROPERTY, + PPTP_PLUGIN_UI_ERROR_MISSING_PROPERTY, + PPTP_PLUGIN_UI_ERROR_FILE_NOT_READABLE, + PPTP_PLUGIN_UI_ERROR_FILE_NOT_PPTP +} PptpPluginUiError; + +#define PPTP_TYPE_PLUGIN_UI_ERROR (pptp_plugin_ui_error_get_type ()) +GType pptp_plugin_ui_error_get_type (void); + +#define PPTP_PLUGIN_UI_ERROR (pptp_plugin_ui_error_quark ()) +GQuark pptp_plugin_ui_error_quark (void); + + +#define PPTP_TYPE_PLUGIN_UI (pptp_plugin_ui_get_type ()) +#define PPTP_PLUGIN_UI(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PPTP_TYPE_PLUGIN_UI, PptpPluginUi)) +#define PPTP_PLUGIN_UI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PPTP_TYPE_PLUGIN_UI, PptpPluginUiClass)) +#define PPTP_IS_PLUGIN_UI(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PPTP_TYPE_PLUGIN_UI)) +#define PPTP_IS_PLUGIN_UI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), PPTP_TYPE_PLUGIN_UI)) +#define PPTP_PLUGIN_UI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PPTP_TYPE_PLUGIN_UI, PptpPluginUiClass)) + +typedef struct _PptpPluginUi PptpPluginUi; +typedef struct _PptpPluginUiClass PptpPluginUiClass; + +struct _PptpPluginUi { + GObject parent; +}; + +struct _PptpPluginUiClass { + GObjectClass parent; +}; + +GType pptp_plugin_ui_get_type (void); + + +#define PPTP_TYPE_PLUGIN_UI_WIDGET (pptp_plugin_ui_widget_get_type ()) +#define PPTP_PLUGIN_UI_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PPTP_TYPE_PLUGIN_UI_WIDGET, PptpPluginUiWidget)) +#define PPTP_PLUGIN_UI_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PPTP_TYPE_PLUGIN_UI_WIDGET, PptpPluginUiWidgetClass)) +#define PPTP_IS_PLUGIN_UI_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PPTP_TYPE_PLUGIN_UI_WIDGET)) +#define PPTP_IS_PLUGIN_UI_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), PPTP_TYPE_PLUGIN_UI_WIDGET)) +#define PPTP_PLUGIN_UI_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PPTP_TYPE_PLUGIN_UI_WIDGET, PptpPluginUiWidgetClass)) + +typedef struct _PptpPluginUiWidget PptpPluginUiWidget; +typedef struct _PptpPluginUiWidgetClass PptpPluginUiWidgetClass; + +struct _PptpPluginUiWidget { + GObject parent; +}; + +struct _PptpPluginUiWidgetClass { + GObjectClass parent; +}; + +GType pptp_plugin_ui_widget_get_type (void); + +GValue *int_to_gvalue (gint i); + +GValue *uint_to_gvalue (guint32 u); + +GValue *bool_to_gvalue (gboolean b); + +GValue *str_to_gvalue (const char *str); + +#endif /* _NM_PPTP_H_ */ + diff --git a/vpn-daemons/pptp/properties/util_lists.c b/vpn-daemons/pptp/properties/util_lists.c deleted file mode 100644 index 11bec86335..0000000000 --- a/vpn-daemons/pptp/properties/util_lists.c +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include - -#define NMVPNUI_UTIL_LISTS_C -#include "util_lists.h" - -GSList * -list_from_string (const char *string) -{ - char **entries; - char **parts; - char **entry; - char **part; - int i; - GSList *list=NULL; - - if (string==NULL) return list; - entries = g_strsplit(string,";",0); - - for (entry=entries; *entry; entry++) - { - parts = g_strsplit(*entry,"=",2); - part=parts; - if ((!(*part)) || (strlen(*part)==0)) { - g_strfreev(parts); - continue; - } - - list = g_slist_append (list,g_strdup(*part)); - *part++; - - if ((!(*part)) || (strlen(*part)==0) || (strcmp("''",*part)==0)) { - list = g_slist_append (list,g_strdup("")); - } else { - list = g_slist_append (list,g_strdup(*part)); - } - g_strfreev(parts); - } - g_strfreev(entries); - - return list; -} diff --git a/vpn-daemons/pptp/properties/util_lists.h b/vpn-daemons/pptp/properties/util_lists.h deleted file mode 100644 index 82d0e575a7..0000000000 --- a/vpn-daemons/pptp/properties/util_lists.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef NMVPNUI_UTIL_LISTS_H -#define NMVPNUI_UTIL_LISTS_H - -#define STORAGE_CLASS extern -#ifdef NMVPNUI_UTIL_LISTS_C -#undef STORAGE_CLASS -#define STORAGE_CLASS -#endif - -STORAGE_CLASS GSList *list_from_string (const char *string); - -#undef STORAGE_CLASS -#endif diff --git a/vpn-daemons/pptp/properties/vpnui_expand.c b/vpn-daemons/pptp/properties/vpnui_expand.c deleted file mode 100644 index e879fda5bb..0000000000 --- a/vpn-daemons/pptp/properties/vpnui_expand.c +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include - -#define NMVPNUI_EXPAND_C -#include "vpnui_opt.h" -#include "vpnui_expand.h" - -void vpnui_expand_free(VpnUIExpander *expand) -{ - g_return_if_fail(expand!=NULL); - - if (expand->glade_name !=NULL) g_free(expand->glade_name); - - g_free(expand); -} - -VpnUIExpander *vpnui_expand_new( char *glade_name, - NetworkManagerVpnUIImpl *impl ) -{ - VpnUIExpander *expand; - - g_return_val_if_fail(impl!=NULL,NULL); - - if (!(expand = (VpnUIExpander *) g_new0(VpnUIExpander,1))) - return NULL; - - expand->glade_name=g_strdup(glade_name); - - expand->impl=impl; - - expand->widget = GTK_WIDGET (glade_xml_get_widget(expand->impl->xml, expand->glade_name)); - impl->expanders = g_slist_append(impl->expanders, (gpointer) expand); - - return expand; -} - -void -vpnui_expand_reset_all (NetworkManagerVpnUIImpl *impl) -{ - GSList *item; - - for (item=impl->expanders; item != NULL; item = g_slist_next(item)) - { - vpnui_expand_reset((VpnUIExpander *)item->data); - } - - gtk_container_resize_children (GTK_CONTAINER (impl->widget)); -} - -void vpnui_expand_reset(VpnUIExpander *expand) -{ - GList *item; - - g_return_if_fail(expand!=NULL); - g_return_if_fail(expand->widget!=NULL); - - if (GTK_IS_CONTAINER(expand->widget)) { - if (vpnui_opt_has_active_children(GTK_CONTAINER(expand->widget),expand->impl)) { -// gtk_expander_set_expanded(GTK_EXPANDER(expand->widget),TRUE); - gtk_widget_show(GTK_WIDGET(expand->widget)); - } else { -// gtk_expander_set_expanded(GTK_EXPANDER(expand->widget),FALSE); - gtk_widget_hide(GTK_WIDGET(expand->widget)); - } - } - -// g_return_if_fail(expand!=NULL); -// gtk_expander_set_expanded (GTK_EXPANDER(expand->widget), TRUE); -} - - - diff --git a/vpn-daemons/pptp/properties/vpnui_expand.h b/vpn-daemons/pptp/properties/vpnui_expand.h deleted file mode 100644 index 304cc37968..0000000000 --- a/vpn-daemons/pptp/properties/vpnui_expand.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef NMVPNUI_EXPAND_H -#define NMVPNUI_EXPAND_H - -#ifdef HAVE_CONFIG_H -#include -#endif - - -#include -#include -#include - -#include - -typedef struct VpnUIExpander -{ - char *glade_name; - NetworkManagerVpnUIImpl *impl; - GtkWidget *widget; -} VpnUIExpander; - -#define STORAGE_CLASS extern -#ifdef NMVPNUI_EXPAND_C -#undef STORAGE_CLASS -#define STORAGE_CLASS -#endif - -STORAGE_CLASS void vpnui_expand_free(VpnUIExpander *expand); -STORAGE_CLASS VpnUIExpander *vpnui_expand_new( char *glade_name, - NetworkManagerVpnUIImpl *impl ); - -STORAGE_CLASS void vpnui_expand_reset(VpnUIExpander *expand); -STORAGE_CLASS void vpnui_expand_reset_all (NetworkManagerVpnUIImpl *impl); - -#undef STORAGE_CLASS -#endif diff --git a/vpn-daemons/pptp/properties/vpnui_impl.c b/vpn-daemons/pptp/properties/vpnui_impl.c deleted file mode 100644 index 9eebdc5769..0000000000 --- a/vpn-daemons/pptp/properties/vpnui_impl.c +++ /dev/null @@ -1,569 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include - -#define NM_VPN_API_SUBJECT_TO_CHANGE -#include - -#define NMVPNUI_IMPL_C -#include "vpnui_impl.h" -#include "vpnui_expand.h" -#include "vpnui_opt.h" - -/* Stuff to be provided by the specific instance */ -extern const char *GLADE_FILE; -extern const char *GLADE_WIDGET; -extern void impl_setup (NetworkManagerVpnUIImpl *impl); -extern void impl_hide_and_show (NetworkManagerVpnUIImpl *impl); - -static void -impl_set_validity_changed_callback (NetworkManagerVpnUI *self, - NetworkManagerVpnUIDialogValidityCallback callback, - gpointer user_data) -{ - NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data; - - impl->callback = callback; - impl->callback_user_data = user_data; -} - - -void -impl_clear_widget (NetworkManagerVpnUIImpl *impl) -{ - GSList *item; - - g_return_if_fail(impl!=NULL); - - if (impl->connection_name_opt!=NULL) vpnui_opt_set(impl->connection_name_opt,""); - if (impl->variant_combo!=NULL) gtk_combo_box_set_active(impl->variant_combo,-1); - if (impl->defaults!=NULL) - for (item=impl->config_options; item != NULL; item = g_slist_next(item)) - { - vpnui_opt_set_default((VpnUIConfigOption *)item->data, impl->defaults); - } - -// vpnui_expand_reset_all(impl); - impl_hide_and_show(impl); -} - -static const char * -impl_get_display_name (NetworkManagerVpnUI *self) -{ - NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data; - return impl->display_name; -} - -static const char * -impl_get_service_name (NetworkManagerVpnUI *self) -{ - NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data; - return impl->service_name; -} - -static GtkWidget * -impl_get_widget (NetworkManagerVpnUI *self, GSList *properties, GSList *routes, const char *connection_name) -{ - GSList *item; - VpnUIConfigOption *opt; - NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data; - - impl_clear_widget (impl); - - if (connection_name != NULL) { - if ((opt = impl->connection_name_opt) != NULL) { - vpnui_opt_set(opt,connection_name); - } - } - - for (item=properties; item != NULL; item = g_slist_next(g_slist_next(item))) - { - if (item->data==NULL) continue; - if ((g_slist_next(item))->data==NULL) continue; - opt = impl_opt_bygconf(impl,(char *)item->data); - if (opt==NULL) continue; - vpnui_opt_set(opt, (char *)(g_slist_next(item))->data); - } - - if (routes != NULL) { - GString *route_str; - char *str; - - route_str = g_string_new (""); - for (item = routes; item != NULL; item = g_slist_next (item)) { - if (item != routes) g_string_append_c(route_str, ' '); - g_string_append(route_str, (const char *) item->data); - } - str = g_string_free (route_str, FALSE); - - if(impl->routes_opt!=NULL) vpnui_opt_set(impl->routes_opt,str); - if(impl->routes_toggle_opt!=NULL) vpnui_opt_set(impl->routes_toggle_opt,"yes"); - g_free (str); - } - -// vpnui_expand_reset_all(impl); - impl_hide_and_show(impl); - - return impl->widget; -} - -static GSList * -impl_get_properties (NetworkManagerVpnUI *self) -{ - GSList *data; - GSList *item; - VpnUIConfigOption *opt; - NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data; - - data = NULL; - for (item=impl->config_options; item != NULL; item = g_slist_next(item)) - { - opt = (VpnUIConfigOption *)item->data; - if (opt==NULL) continue; - if (opt->gconf_name==NULL) continue; - if (!opt->active) continue; - - data = g_slist_append (data, g_strdup(opt->gconf_name)); - data = g_slist_append (data, g_strdup(vpnui_opt_get(opt))); - } - - return data; -} - -static GSList * -get_routes (NetworkManagerVpnUIImpl *impl) -{ - GSList *routes; - const char *routes_entry; - const char *use_routes; - char **substrs; - unsigned int i; - VpnUIConfigOption *opt; - - routes = NULL; - - opt = impl_opt_byglade(impl,"routes"); - g_return_val_if_fail(opt!=NULL,NULL); - if (!opt->active) return NULL; - routes_entry = vpnui_opt_get(opt); - - opt = impl_opt_byglade(impl,"use-routes"); - g_return_val_if_fail(opt!=NULL,NULL); - use_routes = vpnui_opt_get(impl_opt_byglade(impl,"use-routes")); - - if (strcmp("no",use_routes)==0) { - goto out; - } - - substrs = g_strsplit (routes_entry, " ", 0); - for (i = 0; substrs[i] != NULL; i++) { - char *route; - - if (strlen(substrs[i]) > 0) - routes = g_slist_append (routes, g_strdup (substrs[i])); - } - - g_strfreev (substrs); - - out: - return routes; -} - -static GSList * -impl_get_routes (NetworkManagerVpnUI *self) -{ - NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data; - - return get_routes (impl); -} - - -static char * -impl_get_connection_name (NetworkManagerVpnUI *self) -{ - NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data; - - return g_strdup( vpnui_opt_get(impl->connection_name_opt) ); -} - - -gboolean -impl_is_valid (NetworkManagerVpnUI *self) -{ - NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data; - GSList *item; - gboolean is_valid; - VpnUIConfigOption *opt; - - is_valid = TRUE; - for (item=impl->config_options; item != NULL; item = g_slist_next(item)) - { - opt = (VpnUIConfigOption *)item->data; - if (opt==NULL) continue; - if (!opt->active) continue; - is_valid &= vpnui_opt_validate(opt); - if (!is_valid) return is_valid; - } - - return is_valid; -} - - - -static void -impl_get_confirmation_details (NetworkManagerVpnUI *self, gchar **retval) -{ - GString *buf; - GSList *item; - const char *value; - VpnUIConfigOption *opt; - NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data; - - // This is risky, should be variable length depending on actual data! - buf = g_string_sized_new (1024); - - g_string_append_printf (buf, _("The following '%s' connection will be created:"), impl->display_name); - g_string_append (buf, "\n\n"); - for (item=impl->config_options; item != NULL; item = g_slist_next(item)) - { - opt = (VpnUIConfigOption *)item->data; - if (opt==NULL) continue; - if (opt->description==NULL) continue; - if (!opt->active) continue; - - value = vpnui_opt_get(opt); - if (value==NULL) continue; - if (strlen(value)==0) continue; - - g_string_append_printf (buf, _("\t%s: %s\n"), opt->description, value); - } - - g_string_append (buf, _("The connection details can be changed using the \"Back\" button.")); - g_string_append (buf, "\n"); - - *retval = g_string_free (buf, FALSE); -} - -static gboolean -import_from_file (NetworkManagerVpnUIImpl *impl, const char *path) -{ - char *basename; - GKeyFile *keyfile; - VpnUIConfigOption *opt; - GSList *item; - gboolean file_is_good; - - file_is_good = FALSE; - basename = g_path_get_basename (path); - - keyfile = g_key_file_new (); - if (g_key_file_load_from_file (keyfile, path, 0, NULL)) { - char *value = NULL; - - for (item=impl->config_options; item != NULL; item = g_slist_next(item)) - { - opt = (VpnUIConfigOption *)item->data; - if (opt==NULL) continue; - if (opt->export_name==NULL) continue; - - value = g_key_file_get_string (keyfile, "main", opt->export_name, NULL); - vpnui_opt_set(opt,value); - g_free (value); - } - g_key_file_free (keyfile); - } - - g_free (basename); - - impl_hide_and_show(impl); - - return file_is_good; - -// if (!file_is_good) { -// GtkWidget *dialog; -// -// dialog = gtk_message_dialog_new (NULL, -// GTK_DIALOG_DESTROY_WITH_PARENT, -// GTK_MESSAGE_WARNING, -// GTK_BUTTONS_CLOSE, -// _("Cannot import settings")); -// gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), -// _("The VPN settings file '%s' does not contain valid data."), basename); -// gtk_dialog_run (GTK_DIALOG (dialog)); -// gtk_widget_destroy (dialog); -// } -} - -static void -show_widget (GtkWidget *widget, gpointer user_data) -{ - g_warning("Widget show event"); - - impl_hide_and_show((NetworkManagerVpnUIImpl *) user_data); -} - - -static void -import_button_clicked (GtkButton *button, gpointer user_data) -{ - char *filename = NULL; - GtkWidget *dialog; - NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) user_data; - - dialog = gtk_file_chooser_dialog_new (_("Select file to import"), - NULL, - GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - NULL); - - if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { - - filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); - /*printf ("User selected '%s'\n", filename);*/ - - } - - gtk_widget_destroy (dialog); - - if (filename != NULL) { - import_from_file (impl, filename); - g_free (filename); - } -} - -static gboolean -impl_can_export (NetworkManagerVpnUI *self) -{ - return TRUE; -} - -static gboolean -impl_import_file (NetworkManagerVpnUI *self, const char *path) -{ - NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data; - - return import_from_file (impl, path); -} - -static void -export_to_file (NetworkManagerVpnUIImpl *impl, const char *path, - GSList *properties, GSList *routes, const char *connection_name) -{ - FILE *f; - GSList *item; - VpnUIConfigOption *opt; -// gboolean use_routes = FALSE; - const char *export = NULL; - const char *value = NULL; - char *routes_str = NULL; - - f = fopen (path, "w"); - if (f == NULL) return; - - /* Print the header */ - fprintf (f, "[main]\n"); - - /* Handle the connection-name */ - if (connection_name != NULL) { - opt = impl_opt_byglade(impl,"connection-name"); - if (opt != NULL ) { - export = opt->export_name; - value = connection_name; - if ((export != NULL ) && (value!=NULL) ) { - fprintf (f, "%s=%s\n",export,value); - } - } - } - - for (item=properties; item != NULL; item = g_slist_next(g_slist_next(item))) - { - if (item->data==NULL) continue; - if ((g_slist_next(item))->data==NULL) continue; - opt = impl_opt_bygconf(impl,(char *)item->data); - if (opt==NULL) continue; - vpnui_opt_set(opt, (char *)(g_slist_next(item))->data); - } - - if (routes != NULL) { - GString *route_str; - char *str; - - route_str = g_string_new (""); - for (item = routes; item != NULL; item = g_slist_next (item)) { - if (item != routes) g_string_append_c(route_str, ' '); - g_string_append(route_str, (const char *) item->data); - } - str = g_string_free (route_str, FALSE); - - if (impl->routes_opt!=NULL) vpnui_opt_set(impl->routes_opt,str); - if (impl->routes_toggle_opt!=NULL) vpnui_opt_set(impl->routes_toggle_opt,"yes"); - g_free (str); - } - - /* Loop over properties and print them out */ - for (item=properties; item != NULL; item = g_slist_next(g_slist_next(item))) - { - if (item->data==NULL) continue; - if ((g_slist_next(item))->data==NULL) continue; - -// if (strcmp("use_routes",item->data)==0) { -// if (strcmp("yes",(g_slist_next(item))->data)==0) use_routes=TRUE; -// } - - opt = impl_opt_bygconf(impl,(char *)item->data); - if (opt==NULL) continue; - if (opt->export_name==NULL) continue; - if (!opt->active) continue; - - export = opt->export_name; - value = (const char *)(g_slist_next(item))->data; - - if ((export != NULL ) && (value!=NULL) ) { - fprintf (f, "%s=%s\n",export,value); - } - } - - if (routes != NULL) { - GString *route_str; - char *str; - - route_str = g_string_new (""); - for (item = routes; item != NULL; item = g_slist_next (item)) { - if (item != routes) g_string_append_c(route_str, ' '); - g_string_append(route_str, (const char *) item->data); - } - value = ( str = g_string_free (route_str, FALSE) ); - value = str; - - opt = impl_opt_byglade(impl,"routes"); - g_free (str); - g_free (routes_str); - } - fclose (f); - -} - - -static gboolean -impl_export (NetworkManagerVpnUI *self, GSList *properties, GSList *routes, const char *connection_name) -{ - char *suggested_name; - char *path = NULL; - GtkWidget *dialog; - NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data; - - /*printf ("in impl_export\n");*/ - - dialog = gtk_file_chooser_dialog_new (_("Save as..."), - NULL, - GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, - NULL); - - suggested_name = g_strdup_printf ("%s.pcf", connection_name); - gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), suggested_name); - g_free (suggested_name); - - if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) - { - - path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); - - } - - gtk_widget_destroy (dialog); - - if (path != NULL) { - if (g_file_test (path, G_FILE_TEST_EXISTS)) { - int response; - GtkWidget *dialog; - - dialog = gtk_message_dialog_new (NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_CANCEL, - _("A file named \"%s\" already exists."), path); - gtk_dialog_add_buttons (GTK_DIALOG (dialog), "_Replace", GTK_RESPONSE_OK, NULL); - gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), - _("Do you want to replace it with the one you are saving?")); - response = gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - if (response == GTK_RESPONSE_OK) - export_to_file (impl, path, properties, routes, connection_name); - } else { - export_to_file (impl, path, properties, routes, connection_name); - } - } - - g_free (path); - - return TRUE; -} - -static NetworkManagerVpnUI* -impl_get_object (void) -{ - char *glade_file; - NetworkManagerVpnUIImpl *impl; - - impl = g_new0 (NetworkManagerVpnUIImpl, 1); - - glade_file = g_strdup_printf ("%s/%s", GLADEDIR, GLADE_FILE); - impl->xml = glade_xml_new (glade_file, NULL, GETTEXT_PACKAGE); - g_free( glade_file ); - if (impl->xml != NULL) { - - impl->widget = glade_xml_get_widget(impl->xml, GLADE_WIDGET); - - impl_setup(impl); - - impl->callback = NULL; - - if (impl->w_import_button!=NULL) { - g_signal_connect (GTK_OBJECT (impl->w_import_button), - "clicked", G_CALLBACK (import_button_clicked), impl); - } - - g_signal_connect (GTK_OBJECT (impl->widget), - "show", G_CALLBACK (show_widget), impl); - - /* make the widget reusable */ - g_signal_connect (GTK_OBJECT (impl->widget), "delete-event", - G_CALLBACK (gtk_widget_hide_on_delete), NULL); - - impl_clear_widget (impl); - - impl->parent.get_display_name = impl_get_display_name; - impl->parent.get_service_name = impl_get_service_name; - impl->parent.get_widget = impl_get_widget; - impl->parent.get_connection_name = impl_get_connection_name; - impl->parent.get_properties = impl_get_properties; - impl->parent.get_routes = impl_get_routes; - impl->parent.set_validity_changed_callback = impl_set_validity_changed_callback; - impl->parent.is_valid = impl_is_valid; - impl->parent.get_confirmation_details = impl_get_confirmation_details; - impl->parent.can_export = impl_can_export; - impl->parent.import_file = impl_import_file; - impl->parent.export = impl_export; - impl->parent.data = impl; - - return &(impl->parent); - } else { - g_free (impl); - return NULL; - } -} - -NetworkManagerVpnUI* -nm_vpn_properties_factory (void) -{ - return impl_get_object(); -} - - diff --git a/vpn-daemons/pptp/properties/vpnui_impl.h b/vpn-daemons/pptp/properties/vpnui_impl.h deleted file mode 100644 index 09007cb1d9..0000000000 --- a/vpn-daemons/pptp/properties/vpnui_impl.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef NMVPNUI_IMPL_H -#define NMVPNUI_IMPL_H - -#include - -#define NM_VPN_API_SUBJECT_TO_CHANGE -#include - - -struct impl_config -{ - const char *display_name; - const char *glade_widget; - const char *glade_file; - const char *glade_connection_name; - const char *glade_routes; - const char *glade_routes_toggle; - const char *glade_import_button; -}; - -#define HAVE_VpnUIConfigOption -typedef struct _VpnUIConfigOption VpnUIConfigOption; -typedef struct _NetworkManagerVpnUIImpl NetworkManagerVpnUIImpl; - -typedef void (*VpnUIHideShowCallback) (NetworkManagerVpnUIImpl *self); - -struct _NetworkManagerVpnUIImpl { - NetworkManagerVpnUI parent; - - NetworkManagerVpnUIDialogValidityCallback callback; - VpnUIHideShowCallback do_hide_and_show; - gpointer callback_user_data; - - GladeXML *xml; - - GtkWidget *widget; - - GSList *config_options; - GSList *variants; - -// GtkEntry *w_connection_name; -// GtkEntry *w_remote; -// GtkCheckButton *w_use_routes; -// GtkEntry *w_routes; -// GtkCheckButton *w_use_mppe; -// GtkCheckButton *w_use_mppc; -// GtkExpander *w_pppd_opt_info_expander; -// GtkExpander *w_routing_opt_info_expander; -// GtkExpander *w_pptp_opt_info_expander; - VpnUIConfigOption *connection_name_opt; - VpnUIConfigOption *routes_opt; - VpnUIConfigOption *routes_toggle_opt; - GtkComboBox *variant_combo; - GtkButton *w_import_button; - GSList *defaults; - GSList *expanders; - - const char *display_name; - const char *service_name; -}; - -#ifdef NMVPNUI_IMPL_C -#define STORAGE_CLASS static -#define STORAGE_CLASS2 -#else -#define STORAGE_CLASS extern -#define STORAGE_CLASS2 extern -#endif - -STORAGE_CLASS GSList *get_routes (NetworkManagerVpnUIImpl *impl); -STORAGE_CLASS2 gboolean impl_is_valid (NetworkManagerVpnUI *self); -STORAGE_CLASS void impl_set_validity_changed_callback (NetworkManagerVpnUI *self, - NetworkManagerVpnUIDialogValidityCallback callback, - gpointer user_data); - -#undef STORAGE_CLASS -#endif diff --git a/vpn-daemons/pptp/properties/vpnui_opt.c b/vpn-daemons/pptp/properties/vpnui_opt.c deleted file mode 100644 index 59b5e1a1ee..0000000000 --- a/vpn-daemons/pptp/properties/vpnui_opt.c +++ /dev/null @@ -1,350 +0,0 @@ -#include -#include -#include - -#define NMVPNUI_OPT_C -#include "vpnui_impl.h" -#include "util_lists.h" -#include "vpnui_opt.h" - -char get_opt_buffer[64]; - -extern void use_routes_toggled (GtkToggleButton *togglebutton, gpointer user_data); -extern void editable_changed (GtkEditable *editable, gpointer user_data); -extern void impl_set_validity_changed_callback (NetworkManagerVpnUI *self, - NetworkManagerVpnUIDialogValidityCallback callback, - gpointer user_data); - - -void vpnui_opt_free(VpnUIConfigOption *opt) -{ - g_return_if_fail(opt!=NULL); - - if (opt->glade_name !=NULL) g_free(opt->glade_name); - if (opt->gconf_name != NULL) g_free(opt->gconf_name); - if (opt->export_name != NULL) g_free(opt->export_name); - - g_free(opt); -} - -VpnUIConfigOption *vpnui_opt_new( char *glade_name, - int option_type, - char *gconf_name, - char *export_name, - char *description, - void (*change_handler)(void), - gboolean (*validator)(VpnUIConfigOption *opt), - NetworkManagerVpnUIImpl *impl ) -{ - VpnUIConfigOption *opt; - - g_return_val_if_fail(impl!=NULL,NULL); - - if (impl->config_options == NULL) impl->config_options = NULL; - - if (!(opt = (VpnUIConfigOption *) g_new0(VpnUIConfigOption,1))) - return NULL; - - opt->glade_name=g_strdup(glade_name); - opt->option_type=option_type; - if (gconf_name != NULL) opt->gconf_name=g_strdup(gconf_name); - if (export_name != NULL) opt->export_name=g_strdup(export_name); - if (description != NULL) opt->description=g_strdup(description); - - opt->change_handler=change_handler; - opt->validator=validator; - - opt->impl=impl; - impl->config_options = g_slist_append(impl->config_options, (gpointer) opt); - - vpnui_opt_get_widget(opt); - vpnui_opt_connect_signals(opt); - - return opt; -} - -void vpnui_opt_connect_signals(VpnUIConfigOption *opt) -{ - g_return_if_fail(opt!=NULL); - g_return_if_fail(opt->widget!=NULL); - g_return_if_fail(opt->impl!=NULL); - - if (opt->change_handler==NULL) return; - - switch (opt->option_type) - { - case VPN_UI_OPTTYPE_YESNO: - g_signal_connect (GTK_OBJECT (opt->widget), - "toggled", G_CALLBACK (opt->change_handler), opt->impl); - break; - case VPN_UI_OPTTYPE_STRING: - g_signal_connect (GTK_OBJECT (opt->widget), - "changed", G_CALLBACK (opt->change_handler), opt->impl); - break; - case VPN_UI_OPTTYPE_SPINNER: - g_signal_connect (GTK_OBJECT (opt->widget), - "changed", G_CALLBACK (opt->change_handler), opt->impl); - break; - case VPN_UI_OPTTYPE_COMBO: - g_signal_connect (GTK_OBJECT (opt->widget), - "changed", G_CALLBACK (opt->change_handler), opt->impl); - break; - } -} - -void vpnui_opt_get_widget(VpnUIConfigOption *opt) -{ - g_return_if_fail(opt!=NULL); - g_return_if_fail(opt->impl!=NULL); - - switch (opt->option_type) - { - case VPN_UI_OPTTYPE_YESNO: - case VPN_UI_OPTTYPE_STRING: - case VPN_UI_OPTTYPE_SPINNER: - case VPN_UI_OPTTYPE_COMBO: - opt->widget = GTK_WIDGET (glade_xml_get_widget(opt->impl->xml, opt->glade_name)); - break; - } -} - -const char * vpnui_opt_get(VpnUIConfigOption *opt) -{ - GtkTreeModel *combo_tree; - GtkTreeIter iter; - char *setting; - gdouble value; - g_return_val_if_fail(opt!=NULL,NULL); - - switch (opt->option_type) - { - case VPN_UI_OPTTYPE_YESNO: - if (gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON (opt->widget) )) { - return "yes"; - } - return "no"; - case VPN_UI_OPTTYPE_STRING: - return gtk_entry_get_text(GTK_ENTRY(opt->widget)); - case VPN_UI_OPTTYPE_SPINNER: - value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(opt->widget)); - sprintf(get_opt_buffer,"%.0f",value); - return get_opt_buffer; - case VPN_UI_OPTTYPE_COMBO: - combo_tree = gtk_combo_box_get_model(GTK_COMBO_BOX(opt->widget)); - if (combo_tree==NULL) return NULL; - if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(opt->widget), &iter)) - return NULL; - - gtk_tree_model_get (combo_tree, &iter, 0, &setting, -1); - return setting; - } - - return NULL; -} - -void vpnui_opt_set(VpnUIConfigOption *opt, const char *value) -{ - int num_value; - GtkTreeModel *combo_tree; - GtkTreeIter iter; - gboolean found; - - g_return_if_fail(opt!=NULL); - g_return_if_fail(value!=NULL); - - switch (opt->option_type) - { - case VPN_UI_OPTTYPE_YESNO: - if (strcmp("yes",value) == 0) { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (opt->widget), TRUE); - } else if (strcmp("no",value) == 0) { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (opt->widget), FALSE); - } else { - return; - } - break; - case VPN_UI_OPTTYPE_STRING: - gtk_entry_set_text ( GTK_ENTRY( opt->widget ), value ); - break; - case VPN_UI_OPTTYPE_SPINNER: - sscanf(value,"%d",&num_value); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(opt->widget),num_value); - break; - case VPN_UI_OPTTYPE_COMBO: - combo_tree = gtk_combo_box_get_model(GTK_COMBO_BOX(opt->widget)); - if (combo_tree==NULL) return; - for (found = gtk_tree_model_get_iter_first(combo_tree, &iter); - found == TRUE; - found = gtk_tree_model_iter_next(combo_tree, &iter)) { - char *setting; - gtk_tree_model_get (combo_tree, &iter, 0, &setting, -1); - if (strcmp(setting,value)==0) { - gtk_combo_box_set_active_iter(GTK_COMBO_BOX(opt->widget),&iter); - return; - } - } - gtk_combo_box_set_active(GTK_COMBO_BOX(opt->widget),-1); - - break; - } -} - -gboolean vpnui_opt_set_default(VpnUIConfigOption *opt, GSList *defaults) -{ - GSList *item; - - g_return_val_if_fail(opt!=NULL,FALSE); - g_return_val_if_fail(defaults!=NULL,FALSE); - - -// if (defaults == NULL) { -// vpnui_opt_set_inactive(opt); -// return FALSE; -// } - if (opt==opt->impl->connection_name_opt) { - if (strlen(vpnui_opt_get(opt))>0) - return TRUE; - } - - for (item=defaults; item != NULL; item = g_slist_next(g_slist_next(item))) - { - if (strcmp((char *)item->data,opt->glade_name)!=0) continue; - if ((g_slist_next(item))->data == NULL) continue; - vpnui_opt_set(opt,(char *)(g_slist_next(item))->data); - vpnui_opt_set_active(opt); - return TRUE; - } - - vpnui_opt_set_inactive(opt); - return FALSE; -} - -gboolean vpnui_opt_query_default(VpnUIConfigOption *opt, GSList *defaults) -{ - GSList *item; - const char *value; - - g_return_val_if_fail(opt!=NULL,TRUE); - - if (defaults == NULL) return TRUE; - - for (item=defaults; item != NULL; item = g_slist_next(g_slist_next(item))) - { - if (strcmp(item->data,opt->glade_name)!=0) continue; - value = vpnui_opt_get(opt); - if (strcmp((g_slist_next(item))->data,value)==0) { - return TRUE; - } else { - return FALSE; - } - } - - return TRUE; -} - -void vpnui_opt_set_active(VpnUIConfigOption *opt) -{ - g_return_if_fail(opt!=NULL); - - gtk_widget_set_sensitive(GTK_WIDGET(opt->widget),TRUE); - opt->active = TRUE; -} - -void vpnui_opt_set_inactive(VpnUIConfigOption *opt) -{ - g_return_if_fail(opt!=NULL); - - if (GTK_WIDGET(opt->widget)==GTK_WIDGET(opt->impl->variant_combo)) return; - if (opt==opt->impl->connection_name_opt) return; - - gtk_widget_set_sensitive(GTK_WIDGET(opt->widget),FALSE); - opt->active = FALSE; -} - -gboolean vpnui_opt_validate(VpnUIConfigOption *opt) -{ - g_return_val_if_fail(opt!=NULL,TRUE); - - if (opt->validator==NULL) return TRUE; - return (opt->validator)(opt); -} - -VpnUIConfigOption * -impl_opt_bygconf (NetworkManagerVpnUIImpl *impl, const char *name) -{ - GSList *item; - VpnUIConfigOption *opt; - - for (item=impl->config_options; item != NULL; item = g_slist_next(item)) - { - opt = (VpnUIConfigOption *)item->data; - if (opt == NULL) continue; - if (opt->gconf_name == NULL) continue; - if (strcmp(opt->gconf_name,name)==0) return opt; - } - - return NULL; -} - -VpnUIConfigOption * -impl_opt_byglade (NetworkManagerVpnUIImpl *impl, const char *name) -{ - GSList *item; - VpnUIConfigOption *opt; - - for (item=impl->config_options; item != NULL; item = g_slist_next(item)) - { - opt = (VpnUIConfigOption *)item->data; - if (opt == NULL) continue; - if (opt->glade_name == NULL) continue; - if (strcmp(opt->glade_name,name)==0) return opt; - } - - return NULL; -} - -gboolean vpnui_opt_has_active_children(GtkContainer *container, NetworkManagerVpnUIImpl *impl) -{ - VpnUIConfigOption *opt; - GList *item; - - g_return_val_if_fail(GTK_IS_CONTAINER(container) ,FALSE); - - for (item=gtk_container_get_children(container); - item != NULL; item=g_list_next(item)) { - if (item->data==NULL) continue; -// g_warning("%s has child %s",gtk_widget_get_name(GTK_WIDGET(container)), -// gtk_widget_get_name(GTK_WIDGET(item->data))); - opt = impl_opt_byglade(impl,gtk_widget_get_name(GTK_WIDGET(item->data))); - if (opt!=NULL && opt->active) return TRUE; - - if (GTK_IS_CONTAINER(item->data) - && vpnui_opt_has_active_children(GTK_CONTAINER(item->data),impl)) { - return TRUE; - } - } - - return FALSE; -} - - -//const char * vpnui_opt_get(VpnUIConfigOption *opt) -//{ -// g_return_if_fail(opt!=NULL); -// -// switch (opt->option_type) -// { -// case VPN_UI_OPTTYPE_YESNO: -// if (gtk_toggle_button_get_active ( GTK_CHECK_BUTTON (opt->widget) )) { -// return "yes"; -// } else { -// return "no"; -// } -// break; -// case VPN_UI_OPTTYPE_STRING: -// return gtk_entry_get_text(GTK_ENTRY(opt->widget)); -// break; -// } -// -// return NULL; -//} diff --git a/vpn-daemons/pptp/properties/vpnui_opt.h b/vpn-daemons/pptp/properties/vpnui_opt.h deleted file mode 100644 index c955a16bb0..0000000000 --- a/vpn-daemons/pptp/properties/vpnui_opt.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef NMVPNUI_OPT_H -#define NMVPNUI_OPT_H - - -#include -#include - -//##include -#include "vpnui_impl.h" - -#define VPN_UI_OPTTYPE_YESNO 1 -#define VPN_UI_OPTTYPE_STRING 2 -#define VPN_UI_OPTTYPE_SPINNER 3 -#define VPN_UI_OPTTYPE_COMBO 4 - -#ifndef HAVE_VpnUIConfigOption - typedef struct _VpnUIConfigOption VpnUIConfigOption; -#endif - -struct _VpnUIConfigOption -{ - char *glade_name; - int option_type; - char *gconf_name; - char *export_name; - char *description; - gboolean active; - GCallback change_handler; - gboolean (*validator)(VpnUIConfigOption *opt); - GtkWidget *widget; - NetworkManagerVpnUIImpl *impl; -}; - -#define STORAGE_CLASS extern -#ifdef NMVPNUI_OPT_C -#undef STORAGE_CLASS -#define STORAGE_CLASS -#endif - -STORAGE_CLASS void vpnui_opt_free(VpnUIConfigOption *opt); -STORAGE_CLASS VpnUIConfigOption *vpnui_opt_new( char *glade_name, - int option_type, - char *gconf_name, - char *export_name, - char *description, - void (*change_handler)(void), - gboolean (*validator)(VpnUIConfigOption *opt), - NetworkManagerVpnUIImpl *impl ); -STORAGE_CLASS void vpnui_opt_set_active(VpnUIConfigOption *opt); -STORAGE_CLASS void vpnui_opt_set_inactive(VpnUIConfigOption *opt); -STORAGE_CLASS void vpnui_opt_get_widget(VpnUIConfigOption *opt); -//static char * vpnui_opt_get(VpnUIConfigOption *opt); -STORAGE_CLASS void vpnui_opt_set(VpnUIConfigOption *opt, const char *value); -STORAGE_CLASS gboolean vpnui_opt_query_default(VpnUIConfigOption *opt, GSList *defaults); -STORAGE_CLASS gboolean vpnui_opt_set_default(VpnUIConfigOption *opt, GSList *defaults); -STORAGE_CLASS gboolean vpnui_opt_validate(VpnUIConfigOption *opt); -STORAGE_CLASS const char * vpnui_opt_get(VpnUIConfigOption *opt); -STORAGE_CLASS void vpnui_opt_connect_signals(VpnUIConfigOption *opt); -STORAGE_CLASS VpnUIConfigOption *impl_opt_bygconf (NetworkManagerVpnUIImpl *impl, const char *name); -STORAGE_CLASS VpnUIConfigOption *impl_opt_byglade (NetworkManagerVpnUIImpl *impl, const char *name); -STORAGE_CLASS gboolean vpnui_opt_has_active_children(GtkContainer *container, NetworkManagerVpnUIImpl *impl); -#undef STORAGE_CLASS -#endif diff --git a/vpn-daemons/pptp/properties/vpnui_validate.c b/vpn-daemons/pptp/properties/vpnui_validate.c deleted file mode 100644 index 874eb2dcf2..0000000000 --- a/vpn-daemons/pptp/properties/vpnui_validate.c +++ /dev/null @@ -1,98 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include - -#define NMVPNUI_VALIDATE_C -#include "vpnui_impl.h" -#include "vpnui_opt.h" -#include "vpnui_validate.h" - -gboolean vld_non_empty (VpnUIConfigOption *opt) -{ - const char *value = vpnui_opt_get(opt); - if ((value == NULL) || (strlen (value) == 0)) { - return FALSE; - } - return TRUE; -} - -gboolean vld_non_empty_no_ws (VpnUIConfigOption *opt) -{ - const char *value = vpnui_opt_get(opt); - if ((value == NULL) || - (strlen (value) == 0) || - (strstr(value, " ") != NULL) || - (strstr(value, "\t") != NULL) ) { - return FALSE; - } - return TRUE; -} - -gboolean vld_routes_if_sens (VpnUIConfigOption *opt) -{ - GSList *item; - GSList *routes = NULL; - VpnUIConfigOption *opt2; - const char *value; - const char *use_routes; - char **substrs; - int i; - gboolean sens, is_valid; - - sens = GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(opt->widget)); - if (!sens) return TRUE; - -// routes = get_routes (opt->impl); - g_return_val_if_fail(opt!=NULL,TRUE); - value = vpnui_opt_get(opt); - - opt2 = impl_opt_byglade(opt->impl,"use-routes"); - g_return_val_if_fail(opt2!=NULL,TRUE); - use_routes = vpnui_opt_get(opt2); - - if (strcmp("yes",use_routes)==0) { - substrs = g_strsplit (value, " ", 0); - for (i = 0; substrs[i] != NULL; i++) { - char *route; - - if (strlen(substrs[i]) > 0) - routes = g_slist_append (routes, g_strdup (substrs[i])); - } - - g_strfreev (substrs); - } - - is_valid=TRUE; - for (item = routes; item != NULL; item = g_slist_next (item)) { - int d1, d2, d3, d4, mask; - - const char *route = (const char *) item->data; - //printf ("route = '%s'\n", route); - - if (sscanf (route, "%d.%d.%d.%d/%d", &d1, &d2, &d3, &d4, &mask) != 5) { - is_valid = FALSE; - break; - } - - /* TODO: this can be improved a bit */ - if (d1 < 0 || d1 > 255 || - d2 < 0 || d2 > 255 || - d3 < 0 || d3 > 255 || - d4 < 0 || d4 > 255 || - mask < 0 || mask > 32) { - is_valid = FALSE; - break; - } - - } - - if (routes != NULL) { - g_slist_foreach (routes, (GFunc)g_free, NULL); - g_slist_free (routes); - } - - return is_valid; -} diff --git a/vpn-daemons/pptp/properties/vpnui_validate.h b/vpn-daemons/pptp/properties/vpnui_validate.h deleted file mode 100644 index f85eaa714d..0000000000 --- a/vpn-daemons/pptp/properties/vpnui_validate.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef NMVPNUI_VALIDATE_H -#define NMVPNUI_VALIDATE_H - -#define STORAGE_CLASS extern -#ifdef NMVPNUI_VALIDATE_C -#undef STORAGE_CLASS -#define STORAGE_CLASS -#endif - -STORAGE_CLASS gboolean vld_non_empty (VpnUIConfigOption *value); -STORAGE_CLASS gboolean vld_non_empty_no_ws (VpnUIConfigOption *value); -STORAGE_CLASS gboolean vld_routes_if_sens (VpnUIConfigOption *value); - -#undef STORAGE_CLASS -#endif diff --git a/vpn-daemons/pptp/properties/vpnui_variant.c b/vpn-daemons/pptp/properties/vpnui_variant.c deleted file mode 100644 index 95a16ba79b..0000000000 --- a/vpn-daemons/pptp/properties/vpnui_variant.c +++ /dev/null @@ -1,123 +0,0 @@ -#include -#include - -#define NMVPNUI_EXPAND_C -#include "util_lists.h" -#include "vpnui_opt.h" -#include "vpnui_variant.h" - - -void vpnui_variant_free( VpnUIVariant *variant ) -{ - g_return_if_fail(variant != NULL); - - g_free(variant->name); - g_free(variant->defaults); - g_free(variant); -} - -VpnUIVariant *vpnui_variant_new( const char *name, const char *description, - const char *defaults, - NetworkManagerVpnUIImpl *impl - ) -{ - VpnUIVariant *variant; - GtkListStore *store; - GtkTreeIter iter; - GtkCellRenderer *renderer; - gboolean first_variant=FALSE; - - g_return_val_if_fail(name != NULL,NULL); - g_return_val_if_fail(defaults != NULL,NULL); - g_return_val_if_fail(impl != NULL,NULL); - g_return_val_if_fail(impl->variant_combo != NULL,NULL); - - if (!(variant = (VpnUIVariant *) g_new0(VpnUIVariant,1))) - return NULL; - - variant->name = g_strdup(name); - variant->description = g_strdup(description); - variant->defaults = list_from_string(defaults); - variant->impl = impl; - - first_variant=(impl->variants == NULL); - - if (first_variant) { - store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING); - } else { - store = - (GtkListStore *)gtk_combo_box_get_model(GTK_COMBO_BOX(impl->variant_combo)); - } - - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, variant->name, 1, variant->description, -1); - - gtk_combo_box_set_model(impl->variant_combo,GTK_TREE_MODEL(store)); - if (first_variant) { - gtk_cell_layout_clear (GTK_CELL_LAYOUT (impl->variant_combo)); -// renderer = gtk_cell_renderer_text_new (); -// gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (impl->variant_combo), renderer, FALSE); -// gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (impl->variant_combo), renderer, -// "text", 0, "visible", FALSE, -// NULL); - renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (impl->variant_combo), renderer, TRUE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (impl->variant_combo), renderer, - "text", 1, - NULL); - } - -// gtk_combo_box_append_text(GTK_COMBO_BOX(impl->variant_combo), variant->name); - g_object_unref (store); - - impl->variants = g_slist_append(impl->variants, (gpointer) variant); - return variant; -} - -VpnUIVariant * -vpnui_variant_byname (NetworkManagerVpnUIImpl *impl, const char *name) -{ - GSList *item; - VpnUIVariant *variant; - - if (name==NULL) return NULL; - - for (item=impl->variants; item != NULL; item = g_slist_next(item)) - { - variant = (VpnUIVariant *)item->data; - if (variant == NULL) continue; - if (variant->name == NULL) continue; - if (strcmp(variant->name,name)==0) return variant; - } - - return NULL; -} - -void -vpnui_variant_select (VpnUIVariant *variant) -{ - NetworkManagerVpnUIImpl *impl; - GSList *item; - - g_return_if_fail(variant != NULL); - impl=variant->impl; - - impl->defaults=variant->defaults; - for (item=impl->config_options; item != NULL; item = g_slist_next(item)) { - vpnui_opt_set_default((VpnUIConfigOption *)item->data, impl->defaults); - } -} - - -void -vpnui_variant_select_byname (NetworkManagerVpnUIImpl *impl, const char *name) -{ - VpnUIVariant *variant; - - g_return_if_fail(impl != NULL); - - variant = vpnui_variant_byname(impl,name); - if (variant == NULL) return; - vpnui_variant_select(variant); -} - diff --git a/vpn-daemons/pptp/properties/vpnui_variant.h b/vpn-daemons/pptp/properties/vpnui_variant.h deleted file mode 100644 index 281597fac1..0000000000 --- a/vpn-daemons/pptp/properties/vpnui_variant.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef NMVPNUI_VARIANT_H -#define NMVPNUI_VARIANT_H - -#ifdef HAVE_CONFIG_H -#include -#endif - - -#include -#include -#include - -#include "vpnui_impl.h" - -typedef struct VpnUIVariant -{ - char *name; - char *description; - GSList *defaults; - NetworkManagerVpnUIImpl *impl; -} VpnUIVariant; - -#define STORAGE_CLASS extern -#ifdef NMVPNUI_EXPAND_C -#undef STORAGE_CLASS -#define STORAGE_CLASS -#endif - -STORAGE_CLASS void vpnui_variant_free( VpnUIVariant *variant ); -STORAGE_CLASS VpnUIVariant *vpnui_variant_new( const char *name, - const char *description, - const char *defaults, - NetworkManagerVpnUIImpl *impl - ); -STORAGE_CLASS VpnUIVariant *vpnui_variant_byname (NetworkManagerVpnUIImpl *impl, const char *name); -STORAGE_CLASS void vpnui_variant_select (VpnUIVariant *variant); -STORAGE_CLASS void vpnui_variant_select_byname (NetworkManagerVpnUIImpl *impl, const char *name); -#undef STORAGE_CLASS -#endif diff --git a/vpn-daemons/pptp/src/Makefile.am b/vpn-daemons/pptp/src/Makefile.am index 951d559ecf..ed3d4044cd 100644 --- a/vpn-daemons/pptp/src/Makefile.am +++ b/vpn-daemons/pptp/src/Makefile.am @@ -1,13 +1,9 @@ -INCLUDES = -I${top_srcdir} \ - -I${top_srcdir}/utils \ - -I${top_srcdir}/vpn-daemons/pptp +INCLUDES = -I${top_srcdir} AM_CPPFLAGS = \ - $(DBUS_CFLAGS) \ + $(DBUS_GLIB_CFLAGS) \ $(GTHREAD_CFLAGS) \ - $(NETWORK_MANAGER_CFLAGS) \ - $(PPPD_CFLAGS) \ - $(NM_VPN_CFLAGS) \ + $(NM_UTILS_CFLAGS) \ -Wall \ -DDBUS_API_SUBJECT_TO_CHANGE \ -DG_DISABLE_DEPRECATED \ @@ -19,45 +15,42 @@ AM_CPPFLAGS = \ -DLIBEXECDIR=\""$(libexecdir)"\" \ -DLOCALSTATEDIR=\""$(localstatedir)"\" \ -DDATADIR=\"$(datadir)\" \ + -DPLUGINDIR=\"$(PPPD_PLUGIN_DIR)\" \ -fPIC -bin_PROGRAMS = nm-ppp-starter +bin_PROGRAMS = nm-pptp-service -pppdplugindir = $(libexecdir)/pppd/$(PPPD_VERSION) -pppdplugin_LTLIBRARIES = nm-pppd-plugin.la +nm_pptp_service_SOURCES = \ + nm-pptp-service.c \ + nm-pptp-service.h -nm_ppp_starter_SOURCES = \ - nm-ppp-starter.c \ - nm-ppp-starter.h \ - nm-utils.c \ - nm-utils.h \ - external/2.4.3/pppd/patchlevel.h \ - external/2.4.3/pppd/ipcp.h \ - external/2.4.3/pppd/pppd.h \ - external/2.4.3/pppd/fsm.h \ - external/2.4.4/pppd/patchlevel.h \ - external/2.4.4/pppd/ipcp.h \ - external/2.4.4/pppd/pppd.h \ - external/2.4.4/pppd/fsm.h \ - external/2.4.4b1/pppd/patchlevel.h \ - external/2.4.4b1/pppd/ipcp.h \ - external/2.4.4b1/pppd/pppd.h \ - external/2.4.4b1/pppd/fsm.h +nm-pptp-pppd-service-glue.h: $(top_srcdir)/src/nm-pptp-pppd-service.xml + dbus-binding-tool --prefix=nm_pptp_pppd_service --mode=glib-server --output=$@ $< -nm_ppp_starter_LDADD = \ - $(DBUS_LIBS) \ +nm_pptp_service_LDADD = \ + $(DBUS_GLIB_LIBS) \ $(GTHREAD_LIBS) \ - $(NETWORK_MANAGER_LIBS) + $(NM_UTILS_LIBS) -nm_pppd_plugin_la_SOURCES = \ - nm-pppd-plugin.c \ - nm-pppd-plugin.h \ - nm-ppp-starter.h +pppd_plugindir = $(PPPD_PLUGIN_DIR) +pppd_plugin_LTLIBRARIES = nm-pptp-pppd-plugin.la -nm_pppd_plugin_la_LDFLAGS = -module +nm_pptp_pppd_plugin_la_SOURCES = \ + nm-pptp-pppd-plugin.c \ + nm-ppp-status.h -nm_pppd_plugin_la_LIBADD = \ - $(DBUS_LIBS) \ - $(GTHREAD_LIBS) +nm_pptp_pppd_plugin_la_CPPFLAGS = \ + $(DBUS_GLIB_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(NM_UTILS_CFLAGS) -CLEANFILES = *~ +nm_pptp_pppd_plugin_la_LDFLAGS = -module -avoid-version + +nm_pptp_pppd_plugin_la_LIBADD = \ + $(DBUS_GLIB_LIBS) \ + $(GLIB_LIBS) \ + $(NM_UTILS_LIBS) + +BUILT_SOURCES = nm-pptp-pppd-service-glue.h + +CLEANFILES = $(BUILT_SOURCES) diff --git a/vpn-daemons/pptp/src/external/2.4.3/pppd/fsm.h b/vpn-daemons/pptp/src/external/2.4.3/pppd/fsm.h deleted file mode 100644 index f02473f2b0..0000000000 --- a/vpn-daemons/pptp/src/external/2.4.3/pppd/fsm.h +++ /dev/null @@ -1,168 +0,0 @@ -/* - * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions. - * - * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The name "Carnegie Mellon University" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For permission or any legal - * details, please contact - * Office of Technology Transfer - * Carnegie Mellon University - * 5000 Forbes Avenue - * Pittsburgh, PA 15213-3890 - * (412) 268-4387, fax: (412) 268-7395 - * tech-transfer@andrew.cmu.edu - * - * 4. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by Computing Services - * at Carnegie Mellon University (http://www.cmu.edu/computing/)." - * - * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE - * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN - * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * $Id$ - */ - -/* - * Packet header = Code, id, length. - */ -#define HEADERLEN 4 - - -/* - * CP (LCP, IPCP, etc.) codes. - */ -#define CONFREQ 1 /* Configuration Request */ -#define CONFACK 2 /* Configuration Ack */ -#define CONFNAK 3 /* Configuration Nak */ -#define CONFREJ 4 /* Configuration Reject */ -#define TERMREQ 5 /* Termination Request */ -#define TERMACK 6 /* Termination Ack */ -#define CODEREJ 7 /* Code Reject */ - - -/* - * Each FSM is described by an fsm structure and fsm callbacks. - */ -typedef struct fsm { - int unit; /* Interface unit number */ - int protocol; /* Data Link Layer Protocol field value */ - int state; /* State */ - int flags; /* Contains option bits */ - u_char id; /* Current id */ - u_char reqid; /* Current request id */ - u_char seen_ack; /* Have received valid Ack/Nak/Rej to Req */ - int timeouttime; /* Timeout time in milliseconds */ - int maxconfreqtransmits; /* Maximum Configure-Request transmissions */ - int retransmits; /* Number of retransmissions left */ - int maxtermtransmits; /* Maximum Terminate-Request transmissions */ - int nakloops; /* Number of nak loops since last ack */ - int rnakloops; /* Number of naks received */ - int maxnakloops; /* Maximum number of nak loops tolerated */ - struct fsm_callbacks *callbacks; /* Callback routines */ - char *term_reason; /* Reason for closing protocol */ - int term_reason_len; /* Length of term_reason */ -} fsm; - - -typedef struct fsm_callbacks { - void (*resetci) /* Reset our Configuration Information */ - __P((fsm *)); - int (*cilen) /* Length of our Configuration Information */ - __P((fsm *)); - void (*addci) /* Add our Configuration Information */ - __P((fsm *, u_char *, int *)); - int (*ackci) /* ACK our Configuration Information */ - __P((fsm *, u_char *, int)); - int (*nakci) /* NAK our Configuration Information */ - __P((fsm *, u_char *, int, int)); - int (*rejci) /* Reject our Configuration Information */ - __P((fsm *, u_char *, int)); - int (*reqci) /* Request peer's Configuration Information */ - __P((fsm *, u_char *, int *, int)); - void (*up) /* Called when fsm reaches OPENED state */ - __P((fsm *)); - void (*down) /* Called when fsm leaves OPENED state */ - __P((fsm *)); - void (*starting) /* Called when we want the lower layer */ - __P((fsm *)); - void (*finished) /* Called when we don't want the lower layer */ - __P((fsm *)); - void (*protreject) /* Called when Protocol-Reject received */ - __P((int)); - void (*retransmit) /* Retransmission is necessary */ - __P((fsm *)); - int (*extcode) /* Called when unknown code received */ - __P((fsm *, int, int, u_char *, int)); - char *proto_name; /* String name for protocol (for messages) */ -} fsm_callbacks; - - -/* - * Link states. - */ -#define INITIAL 0 /* Down, hasn't been opened */ -#define STARTING 1 /* Down, been opened */ -#define CLOSED 2 /* Up, hasn't been opened */ -#define STOPPED 3 /* Open, waiting for down event */ -#define CLOSING 4 /* Terminating the connection, not open */ -#define STOPPING 5 /* Terminating, but open */ -#define REQSENT 6 /* We've sent a Config Request */ -#define ACKRCVD 7 /* We've received a Config Ack */ -#define ACKSENT 8 /* We've sent a Config Ack */ -#define OPENED 9 /* Connection available */ - - -/* - * Flags - indicate options controlling FSM operation - */ -#define OPT_PASSIVE 1 /* Don't die if we don't get a response */ -#define OPT_RESTART 2 /* Treat 2nd OPEN as DOWN, UP */ -#define OPT_SILENT 4 /* Wait for peer to speak first */ - - -/* - * Timeouts. - */ -#define DEFTIMEOUT 3 /* Timeout time in seconds */ -#define DEFMAXTERMREQS 2 /* Maximum Terminate-Request transmissions */ -#define DEFMAXCONFREQS 10 /* Maximum Configure-Request transmissions */ -#define DEFMAXNAKLOOPS 5 /* Maximum number of nak loops */ - - -/* - * Prototypes - */ -void fsm_init __P((fsm *)); -void fsm_lowerup __P((fsm *)); -void fsm_lowerdown __P((fsm *)); -void fsm_open __P((fsm *)); -void fsm_close __P((fsm *, char *)); -void fsm_input __P((fsm *, u_char *, int)); -void fsm_protreject __P((fsm *)); -void fsm_sdata __P((fsm *, int, int, u_char *, int)); - - -/* - * Variables - */ -extern int peer_mru[]; /* currently negotiated peer MRU (per unit) */ diff --git a/vpn-daemons/pptp/src/external/2.4.3/pppd/ipcp.h b/vpn-daemons/pptp/src/external/2.4.3/pppd/ipcp.h deleted file mode 100644 index c0d3c85eb4..0000000000 --- a/vpn-daemons/pptp/src/external/2.4.3/pppd/ipcp.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * ipcp.h - IP Control Protocol definitions. - * - * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The name "Carnegie Mellon University" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For permission or any legal - * details, please contact - * Office of Technology Transfer - * Carnegie Mellon University - * 5000 Forbes Avenue - * Pittsburgh, PA 15213-3890 - * (412) 268-4387, fax: (412) 268-7395 - * tech-transfer@andrew.cmu.edu - * - * 4. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by Computing Services - * at Carnegie Mellon University (http://www.cmu.edu/computing/)." - * - * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE - * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN - * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * $Id$ - */ - -/* - * Options. - */ -#define CI_ADDRS 1 /* IP Addresses */ -#define CI_COMPRESSTYPE 2 /* Compression Type */ -#define CI_ADDR 3 - -#define CI_MS_DNS1 129 /* Primary DNS value */ -#define CI_MS_WINS1 130 /* Primary WINS value */ -#define CI_MS_DNS2 131 /* Secondary DNS value */ -#define CI_MS_WINS2 132 /* Secondary WINS value */ - -#define MAX_STATES 16 /* from slcompress.h */ - -#define IPCP_VJMODE_OLD 1 /* "old" mode (option # = 0x0037) */ -#define IPCP_VJMODE_RFC1172 2 /* "old-rfc"mode (option # = 0x002d) */ -#define IPCP_VJMODE_RFC1332 3 /* "new-rfc"mode (option # = 0x002d, */ - /* maxslot and slot number compression) */ - -#define IPCP_VJ_COMP 0x002d /* current value for VJ compression option*/ -#define IPCP_VJ_COMP_OLD 0x0037 /* "old" (i.e, broken) value for VJ */ - /* compression option*/ - -typedef struct ipcp_options { - bool neg_addr; /* Negotiate IP Address? */ - bool old_addrs; /* Use old (IP-Addresses) option? */ - bool req_addr; /* Ask peer to send IP address? */ - bool default_route; /* Assign default route through interface? */ - bool proxy_arp; /* Make proxy ARP entry for peer? */ - bool neg_vj; /* Van Jacobson Compression? */ - bool old_vj; /* use old (short) form of VJ option? */ - bool accept_local; /* accept peer's value for ouraddr */ - bool accept_remote; /* accept peer's value for hisaddr */ - bool req_dns1; /* Ask peer to send primary DNS address? */ - bool req_dns2; /* Ask peer to send secondary DNS address? */ - int vj_protocol; /* protocol value to use in VJ option */ - int maxslotindex; /* values for RFC1332 VJ compression neg. */ - bool cflag; - u_int32_t ouraddr, hisaddr; /* Addresses in NETWORK BYTE ORDER */ - u_int32_t dnsaddr[2]; /* Primary and secondary MS DNS entries */ - u_int32_t winsaddr[2]; /* Primary and secondary MS WINS entries */ -} ipcp_options; - -extern fsm ipcp_fsm[]; -extern ipcp_options ipcp_wantoptions[]; -extern ipcp_options ipcp_gotoptions[]; -extern ipcp_options ipcp_allowoptions[]; -extern ipcp_options ipcp_hisoptions[]; - -char *ip_ntoa __P((u_int32_t)); - -extern struct protent ipcp_protent; diff --git a/vpn-daemons/pptp/src/external/2.4.3/pppd/patchlevel.h b/vpn-daemons/pptp/src/external/2.4.3/pppd/patchlevel.h deleted file mode 100644 index f36d37f9cf..0000000000 --- a/vpn-daemons/pptp/src/external/2.4.3/pppd/patchlevel.h +++ /dev/null @@ -1,4 +0,0 @@ -/* $Id$ */ - -#define VERSION "2.4.3" -#define DATE "13 November 2004" diff --git a/vpn-daemons/pptp/src/external/2.4.3/pppd/pppd.h b/vpn-daemons/pptp/src/external/2.4.3/pppd/pppd.h deleted file mode 100644 index b0d40138d3..0000000000 --- a/vpn-daemons/pptp/src/external/2.4.3/pppd/pppd.h +++ /dev/null @@ -1,910 +0,0 @@ -/* - * pppd.h - PPP daemon global declarations. - * - * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The name "Carnegie Mellon University" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For permission or any legal - * details, please contact - * Office of Technology Transfer - * Carnegie Mellon University - * 5000 Forbes Avenue - * Pittsburgh, PA 15213-3890 - * (412) 268-4387, fax: (412) 268-7395 - * tech-transfer@andrew.cmu.edu - * - * 4. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by Computing Services - * at Carnegie Mellon University (http://www.cmu.edu/computing/)." - * - * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE - * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN - * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * $Id$ - */ - -/* - * TODO: - */ - -#ifndef __PPPD_H__ -#define __PPPD_H__ - -#include /* for FILE */ -#include /* for NGROUPS_MAX */ -#include /* for MAXPATHLEN and BSD4_4, if defined */ -#include /* for u_int32_t, if defined */ -#include /* for struct timeval */ -#include -#include "patchlevel.h" - -#if defined(__STDC__) -#include -#define __V(x) x -#else -#include -#define __V(x) (va_alist) va_dcl -#define const -#define volatile -#endif - -#ifdef INET6 -#include "eui64.h" -#endif - -/* - * Limits. - */ - -#define NUM_PPP 1 /* One PPP interface supported (per process) */ -#define MAXWORDLEN 1024 /* max length of word in file (incl null) */ -#define MAXARGS 1 /* max # args to a command */ -#define MAXNAMELEN 256 /* max length of hostname or name for auth */ -#define MAXSECRETLEN 256 /* max length of password or secret */ - -/* - * Option descriptor structure. - */ - -typedef unsigned char bool; - -enum opt_type { - o_special_noarg = 0, - o_special = 1, - o_bool, - o_int, - o_uint32, - o_string, - o_wild -}; - -typedef struct { - char *name; /* name of the option */ - enum opt_type type; - void *addr; - char *description; - unsigned int flags; - void *addr2; - int upper_limit; - int lower_limit; - const char *source; - short int priority; - short int winner; -} option_t; - -/* Values for flags */ -#define OPT_VALUE 0xff /* mask for presupplied value */ -#define OPT_HEX 0x100 /* int option is in hex */ -#define OPT_NOARG 0x200 /* option doesn't take argument */ -#define OPT_OR 0x400 /* OR in argument to value */ -#define OPT_INC 0x800 /* increment value */ -#define OPT_A2OR 0x800 /* for o_bool, OR arg to *(u_char *)addr2 */ -#define OPT_PRIV 0x1000 /* privileged option */ -#define OPT_STATIC 0x2000 /* string option goes into static array */ -#define OPT_LLIMIT 0x4000 /* check value against lower limit */ -#define OPT_ULIMIT 0x8000 /* check value against upper limit */ -#define OPT_LIMITS (OPT_LLIMIT|OPT_ULIMIT) -#define OPT_ZEROOK 0x10000 /* 0 value is OK even if not within limits */ -#define OPT_HIDE 0x10000 /* for o_string, print value as ?????? */ -#define OPT_A2LIST 0x10000 /* for o_special, keep list of values */ -#define OPT_A2CLRB 0x10000 /* o_bool, clr val bits in *(u_char *)addr2 */ -#define OPT_NOINCR 0x20000 /* value mustn't be increased */ -#define OPT_ZEROINF 0x40000 /* with OPT_NOINCR, 0 == infinity */ -#define OPT_PRIO 0x80000 /* process option priorities for this option */ -#define OPT_PRIOSUB 0x100000 /* subsidiary member of priority group */ -#define OPT_ALIAS 0x200000 /* option is alias for previous option */ -#define OPT_A2COPY 0x400000 /* addr2 -> second location to rcv value */ -#define OPT_ENABLE 0x800000 /* use *addr2 as enable for option */ -#define OPT_A2CLR 0x1000000 /* clear *(bool *)addr2 */ -#define OPT_PRIVFIX 0x2000000 /* user can't override if set by root */ -#define OPT_INITONLY 0x4000000 /* option can only be set in init phase */ -#define OPT_DEVEQUIV 0x8000000 /* equiv to device name */ -#define OPT_DEVNAM (OPT_INITONLY | OPT_DEVEQUIV) -#define OPT_A2PRINTER 0x10000000 /* *addr2 is a fn for printing option */ -#define OPT_A2STRVAL 0x20000000 /* *addr2 points to current string value */ -#define OPT_NOPRINT 0x40000000 /* don't print this option at all */ - -#define OPT_VAL(x) ((x) & OPT_VALUE) - -/* Values for priority */ -#define OPRIO_DEFAULT 0 /* a default value */ -#define OPRIO_CFGFILE 1 /* value from a configuration file */ -#define OPRIO_CMDLINE 2 /* value from the command line */ -#define OPRIO_SECFILE 3 /* value from options in a secrets file */ -#define OPRIO_ROOT 100 /* added to priority if OPT_PRIVFIX && root */ - -#ifndef GIDSET_TYPE -#define GIDSET_TYPE gid_t -#endif - -/* Structure representing a list of permitted IP addresses. */ -struct permitted_ip { - int permit; /* 1 = permit, 0 = forbid */ - u_int32_t base; /* match if (addr & mask) == base */ - u_int32_t mask; /* base and mask are in network byte order */ -}; - -/* - * Unfortunately, the linux kernel driver uses a different structure - * for statistics from the rest of the ports. - * This structure serves as a common representation for the bits - * pppd needs. - */ -struct pppd_stats { - unsigned int bytes_in; - unsigned int bytes_out; - unsigned int pkts_in; - unsigned int pkts_out; -}; - -/* Used for storing a sequence of words. Usually malloced. */ -struct wordlist { - struct wordlist *next; - char *word; -}; - -/* An endpoint discriminator, used with multilink. */ -#define MAX_ENDP_LEN 20 /* maximum length of discriminator value */ -struct epdisc { - unsigned char class; - unsigned char length; - unsigned char value[MAX_ENDP_LEN]; -}; - -/* values for epdisc.class */ -#define EPD_NULL 0 /* null discriminator, no data */ -#define EPD_LOCAL 1 -#define EPD_IP 2 -#define EPD_MAC 3 -#define EPD_MAGIC 4 -#define EPD_PHONENUM 5 - -typedef void (*notify_func) __P((void *, int)); - -struct notifier { - struct notifier *next; - notify_func func; - void *arg; -}; - -/* - * Global variables. - */ - -extern int hungup; /* Physical layer has disconnected */ -extern int ifunit; /* Interface unit number */ -extern char ifname[]; /* Interface name */ -extern char hostname[]; /* Our hostname */ -extern u_char outpacket_buf[]; /* Buffer for outgoing packets */ -extern int devfd; /* fd of underlying device */ -extern int fd_ppp; /* fd for talking PPP */ -extern int phase; /* Current state of link - see values below */ -extern int baud_rate; /* Current link speed in bits/sec */ -extern char *progname; /* Name of this program */ -extern int redirect_stderr;/* Connector's stderr should go to file */ -extern char peer_authname[];/* Authenticated name of peer */ -extern int auth_done[NUM_PPP]; /* Methods actually used for auth */ -extern int privileged; /* We were run by real-uid root */ -extern int need_holdoff; /* Need holdoff period after link terminates */ -extern char **script_env; /* Environment variables for scripts */ -extern int detached; /* Have detached from controlling tty */ -extern GIDSET_TYPE groups[NGROUPS_MAX]; /* groups the user is in */ -extern int ngroups; /* How many groups valid in groups */ -extern struct pppd_stats link_stats; /* byte/packet counts etc. for link */ -extern int link_stats_valid; /* set if link_stats is valid */ -extern unsigned link_connect_time; /* time the link was up for */ -extern int using_pty; /* using pty as device (notty or pty opt.) */ -extern int log_to_fd; /* logging to this fd as well as syslog */ -extern bool log_default; /* log_to_fd is default (stdout) */ -extern char *no_ppp_msg; /* message to print if ppp not in kernel */ -extern volatile int status; /* exit status for pppd */ -extern bool devnam_fixed; /* can no longer change devnam */ -extern int unsuccess; /* # unsuccessful connection attempts */ -extern int do_callback; /* set if we want to do callback next */ -extern int doing_callback; /* set if this is a callback */ -extern int error_count; /* # of times error() has been called */ -extern char ppp_devnam[MAXPATHLEN]; -extern char remote_number[MAXNAMELEN]; /* Remote telephone number, if avail. */ -extern int ppp_session_number; /* Session number (eg PPPoE session) */ -extern int fd_devnull; /* fd open to /dev/null */ - -extern int listen_time; /* time to listen first (ms) */ -extern bool doing_multilink; -extern bool multilink_master; -extern bool bundle_eof; -extern bool bundle_terminating; - -extern struct notifier *pidchange; /* for notifications of pid changing */ -extern struct notifier *phasechange; /* for notifications of phase changes */ -extern struct notifier *exitnotify; /* for notification that we're exiting */ -extern struct notifier *sigreceived; /* notification of received signal */ -extern struct notifier *ip_up_notifier; /* IPCP has come up */ -extern struct notifier *ip_down_notifier; /* IPCP has gone down */ -extern struct notifier *auth_up_notifier; /* peer has authenticated */ -extern struct notifier *link_down_notifier; /* link has gone down */ -extern struct notifier *fork_notifier; /* we are a new child process */ - -/* Values for do_callback and doing_callback */ -#define CALLBACK_DIALIN 1 /* we are expecting the call back */ -#define CALLBACK_DIALOUT 2 /* we are dialling out to call back */ - -/* - * Variables set by command-line options. - */ - -extern int debug; /* Debug flag */ -extern int kdebugflag; /* Tell kernel to print debug messages */ -extern int default_device; /* Using /dev/tty or equivalent */ -extern char devnam[MAXPATHLEN]; /* Device name */ -extern int crtscts; /* Use hardware flow control */ -extern bool modem; /* Use modem control lines */ -extern int inspeed; /* Input/Output speed requested */ -extern u_int32_t netmask; /* IP netmask to set on interface */ -extern bool lockflag; /* Create lock file to lock the serial dev */ -extern bool nodetach; /* Don't detach from controlling tty */ -extern bool updetach; /* Detach from controlling tty when link up */ -extern char *initializer; /* Script to initialize physical link */ -extern char *connect_script; /* Script to establish physical link */ -extern char *disconnect_script; /* Script to disestablish physical link */ -extern char *welcomer; /* Script to welcome client after connection */ -extern char *ptycommand; /* Command to run on other side of pty */ -extern int maxconnect; /* Maximum connect time (seconds) */ -extern char user[MAXNAMELEN];/* Our name for authenticating ourselves */ -extern char passwd[MAXSECRETLEN]; /* Password for PAP or CHAP */ -extern bool auth_required; /* Peer is required to authenticate */ -extern bool persist; /* Reopen link after it goes down */ -extern bool uselogin; /* Use /etc/passwd for checking PAP */ -extern char our_name[MAXNAMELEN];/* Our name for authentication purposes */ -extern char remote_name[MAXNAMELEN]; /* Peer's name for authentication */ -extern bool explicit_remote;/* remote_name specified with remotename opt */ -extern bool demand; /* Do dial-on-demand */ -extern bool killoldaddr; /* If our IP is reassigned on - reconnect, kill active TCP - connections using the old IP. */ -extern char *ipparam; /* Extra parameter for ip up/down scripts */ -extern bool cryptpap; /* Others' PAP passwords are encrypted */ -extern int idle_time_limit;/* Shut down link if idle for this long */ -extern int holdoff; /* Dead time before restarting */ -extern bool holdoff_specified; /* true if user gave a holdoff value */ -extern bool notty; /* Stdin/out is not a tty */ -extern char *pty_socket; /* Socket to connect to pty */ -extern char *record_file; /* File to record chars sent/received */ -extern bool sync_serial; /* Device is synchronous serial device */ -extern int maxfail; /* Max # of unsuccessful connection attempts */ -extern char linkname[MAXPATHLEN]; /* logical name for link */ -extern bool tune_kernel; /* May alter kernel settings as necessary */ -extern int connect_delay; /* Time to delay after connect script */ -extern int max_data_rate; /* max bytes/sec through charshunt */ -extern int req_unit; /* interface unit number to use */ -extern bool multilink; /* enable multilink operation */ -extern bool noendpoint; /* don't send or accept endpt. discrim. */ -extern char *bundle_name; /* bundle name for multilink */ -extern bool dump_options; /* print out option values */ -extern bool dryrun; /* check everything, print options, exit */ -extern int child_wait; /* # seconds to wait for children at end */ - -#ifdef MAXOCTETS -extern unsigned int maxoctets; /* Maximum octetes per session (in bytes) */ -extern int maxoctets_dir; /* Direction : - 0 - in+out (default) - 1 - in - 2 - out - 3 - max(in,out) */ -extern int maxoctets_timeout; /* Timeout for check of octets limit */ -#define PPP_OCTETS_DIRECTION_SUM 0 -#define PPP_OCTETS_DIRECTION_IN 1 -#define PPP_OCTETS_DIRECTION_OUT 2 -#define PPP_OCTETS_DIRECTION_MAXOVERAL 3 -/* same as previos, but little different on RADIUS side */ -#define PPP_OCTETS_DIRECTION_MAXSESSION 4 -#endif - -#ifdef PPP_FILTER -extern struct bpf_program pass_filter; /* Filter for pkts to pass */ -extern struct bpf_program active_filter; /* Filter for link-active pkts */ -#endif - -#ifdef MSLANMAN -extern bool ms_lanman; /* Use LanMan password instead of NT */ - /* Has meaning only with MS-CHAP challenges */ -#endif - -/* Values for auth_pending, auth_done */ -#define PAP_WITHPEER 0x1 -#define PAP_PEER 0x2 -#define CHAP_WITHPEER 0x4 -#define CHAP_PEER 0x8 -#define EAP_WITHPEER 0x10 -#define EAP_PEER 0x20 - -/* Values for auth_done only */ -#define CHAP_MD5_WITHPEER 0x40 -#define CHAP_MD5_PEER 0x80 -#define CHAP_MS_SHIFT 8 /* LSB position for MS auths */ -#define CHAP_MS_WITHPEER 0x100 -#define CHAP_MS_PEER 0x200 -#define CHAP_MS2_WITHPEER 0x400 -#define CHAP_MS2_PEER 0x800 - -extern char *current_option; /* the name of the option being parsed */ -extern int privileged_option; /* set iff the current option came from root */ -extern char *option_source; /* string saying where the option came from */ -extern int option_priority; /* priority of current options */ - -/* - * Values for phase. - */ -#define PHASE_DEAD 0 -#define PHASE_INITIALIZE 1 -#define PHASE_SERIALCONN 2 -#define PHASE_DORMANT 3 -#define PHASE_ESTABLISH 4 -#define PHASE_AUTHENTICATE 5 -#define PHASE_CALLBACK 6 -#define PHASE_NETWORK 7 -#define PHASE_RUNNING 8 -#define PHASE_TERMINATE 9 -#define PHASE_DISCONNECT 10 -#define PHASE_HOLDOFF 11 -#define PHASE_MASTER 12 - -/* - * The following struct gives the addresses of procedures to call - * for a particular protocol. - */ -struct protent { - u_short protocol; /* PPP protocol number */ - /* Initialization procedure */ - void (*init) __P((int unit)); - /* Process a received packet */ - void (*input) __P((int unit, u_char *pkt, int len)); - /* Process a received protocol-reject */ - void (*protrej) __P((int unit)); - /* Lower layer has come up */ - void (*lowerup) __P((int unit)); - /* Lower layer has gone down */ - void (*lowerdown) __P((int unit)); - /* Open the protocol */ - void (*open) __P((int unit)); - /* Close the protocol */ - void (*close) __P((int unit, char *reason)); - /* Print a packet in readable form */ - int (*printpkt) __P((u_char *pkt, int len, - void (*printer) __P((void *, char *, ...)), - void *arg)); - /* Process a received data packet */ - void (*datainput) __P((int unit, u_char *pkt, int len)); - bool enabled_flag; /* 0 iff protocol is disabled */ - char *name; /* Text name of protocol */ - char *data_name; /* Text name of corresponding data protocol */ - option_t *options; /* List of command-line options */ - /* Check requested options, assign defaults */ - void (*check_options) __P((void)); - /* Configure interface for demand-dial */ - int (*demand_conf) __P((int unit)); - /* Say whether to bring up link for this pkt */ - int (*active_pkt) __P((u_char *pkt, int len)); -}; - -/* Table of pointers to supported protocols */ -extern struct protent *protocols[]; - -/* - * This struct contains pointers to a set of procedures for - * doing operations on a "channel". A channel provides a way - * to send and receive PPP packets - the canonical example is - * a serial port device in PPP line discipline (or equivalently - * with PPP STREAMS modules pushed onto it). - */ -struct channel { - /* set of options for this channel */ - option_t *options; - /* find and process a per-channel options file */ - void (*process_extra_options) __P((void)); - /* check all the options that have been given */ - void (*check_options) __P((void)); - /* get the channel ready to do PPP, return a file descriptor */ - int (*connect) __P((void)); - /* we're finished with the channel */ - void (*disconnect) __P((void)); - /* put the channel into PPP `mode' */ - int (*establish_ppp) __P((int)); - /* take the channel out of PPP `mode', restore loopback if demand */ - void (*disestablish_ppp) __P((int)); - /* set the transmit-side PPP parameters of the channel */ - void (*send_config) __P((int, u_int32_t, int, int)); - /* set the receive-side PPP parameters of the channel */ - void (*recv_config) __P((int, u_int32_t, int, int)); - /* cleanup on error or normal exit */ - void (*cleanup) __P((void)); - /* close the device, called in children after fork */ - void (*close) __P((void)); -}; - -extern struct channel *the_channel; - -/* - * Prototypes. - */ - -/* Procedures exported from main.c. */ -void set_ifunit __P((int)); /* set stuff that depends on ifunit */ -void detach __P((void)); /* Detach from controlling tty */ -void die __P((int)); /* Cleanup and exit */ -void quit __P((void)); /* like die(1) */ -void novm __P((char *)); /* Say we ran out of memory, and die */ -void timeout __P((void (*func)(void *), void *arg, int s, int us)); - /* Call func(arg) after s.us seconds */ -void untimeout __P((void (*func)(void *), void *arg)); - /* Cancel call to func(arg) */ -void record_child __P((int, char *, void (*) (void *), void *)); -pid_t safe_fork __P((int, int, int)); /* Fork & close stuff in child */ -int device_script __P((char *cmd, int in, int out, int dont_wait)); - /* Run `cmd' with given stdin and stdout */ -pid_t run_program __P((char *prog, char **args, int must_exist, - void (*done)(void *), void *arg)); - /* Run program prog with args in child */ -void reopen_log __P((void)); /* (re)open the connection to syslog */ -void print_link_stats __P((void)); /* Print stats, if available */ -void reset_link_stats __P((int)); /* Reset (init) stats when link goes up */ -void update_link_stats __P((int)); /* Get stats at link termination */ -void script_setenv __P((char *, char *, int)); /* set script env var */ -void script_unsetenv __P((char *)); /* unset script env var */ -void new_phase __P((int)); /* signal start of new phase */ -void add_notifier __P((struct notifier **, notify_func, void *)); -void remove_notifier __P((struct notifier **, notify_func, void *)); -void notify __P((struct notifier *, int)); -int ppp_send_config __P((int, int, u_int32_t, int, int)); -int ppp_recv_config __P((int, int, u_int32_t, int, int)); -const char *protocol_name __P((int)); -void remove_pidfiles __P((void)); -void lock_db __P((void)); -void unlock_db __P((void)); - -/* Procedures exported from tty.c. */ -void tty_init __P((void)); - -/* Procedures exported from utils.c. */ -void log_packet __P((u_char *, int, char *, int)); - /* Format a packet and log it with syslog */ -void print_string __P((char *, int, void (*) (void *, char *, ...), - void *)); /* Format a string for output */ -int slprintf __P((char *, int, char *, ...)); /* sprintf++ */ -int vslprintf __P((char *, int, char *, va_list)); /* vsprintf++ */ -size_t strlcpy __P((char *, const char *, size_t)); /* safe strcpy */ -size_t strlcat __P((char *, const char *, size_t)); /* safe strncpy */ -void dbglog __P((char *, ...)); /* log a debug message */ -void info __P((char *, ...)); /* log an informational message */ -void notice __P((char *, ...)); /* log a notice-level message */ -void warn __P((char *, ...)); /* log a warning message */ -void error __P((char *, ...)); /* log an error message */ -void fatal __P((char *, ...)); /* log an error message and die(1) */ -void init_pr_log __P((char *, int)); /* initialize for using pr_log */ -void pr_log __P((void *, char *, ...)); /* printer fn, output to syslog */ -void end_pr_log __P((void)); /* finish up after using pr_log */ -void dump_packet __P((const char *, u_char *, int)); - /* dump packet to debug log if interesting */ -ssize_t complete_read __P((int, void *, size_t)); - /* read a complete buffer */ - -/* Procedures exported from auth.c */ -void link_required __P((int)); /* we are starting to use the link */ -void start_link __P((int)); /* bring the link up now */ -void link_terminated __P((int)); /* we are finished with the link */ -void link_down __P((int)); /* the LCP layer has left the Opened state */ -void upper_layers_down __P((int));/* take all NCPs down */ -void link_established __P((int)); /* the link is up; authenticate now */ -void start_networks __P((int)); /* start all the network control protos */ -void continue_networks __P((int)); /* start network [ip, etc] control protos */ -void np_up __P((int, int)); /* a network protocol has come up */ -void np_down __P((int, int)); /* a network protocol has gone down */ -void np_finished __P((int, int)); /* a network protocol no longer needs link */ -void auth_peer_fail __P((int, int)); - /* peer failed to authenticate itself */ -void auth_peer_success __P((int, int, int, char *, int)); - /* peer successfully authenticated itself */ -void auth_withpeer_fail __P((int, int)); - /* we failed to authenticate ourselves */ -void auth_withpeer_success __P((int, int, int)); - /* we successfully authenticated ourselves */ -void auth_check_options __P((void)); - /* check authentication options supplied */ -void auth_reset __P((int)); /* check what secrets we have */ -int check_passwd __P((int, char *, int, char *, int, char **)); - /* Check peer-supplied username/password */ -int get_secret __P((int, char *, char *, char *, int *, int)); - /* get "secret" for chap */ -int get_srp_secret __P((int unit, char *client, char *server, char *secret, - int am_server)); -int auth_ip_addr __P((int, u_int32_t)); - /* check if IP address is authorized */ -int auth_number __P((void)); /* check if remote number is authorized */ -int bad_ip_adrs __P((u_int32_t)); - /* check if IP address is unreasonable */ - -/* Procedures exported from demand.c */ -void demand_conf __P((void)); /* config interface(s) for demand-dial */ -void demand_block __P((void)); /* set all NPs to queue up packets */ -void demand_unblock __P((void)); /* set all NPs to pass packets */ -void demand_discard __P((void)); /* set all NPs to discard packets */ -void demand_rexmit __P((int)); /* retransmit saved frames for an NP */ -int loop_chars __P((unsigned char *, int)); /* process chars from loopback */ -int loop_frame __P((unsigned char *, int)); /* should we bring link up? */ - -/* Procedures exported from multilink.c */ -#ifdef HAVE_MULTILINK -void mp_check_options __P((void)); /* Check multilink-related options */ -int mp_join_bundle __P((void)); /* join our link to an appropriate bundle */ -void mp_exit_bundle __P((void)); /* have disconnected our link from bundle */ -void mp_bundle_terminated __P((void)); -char *epdisc_to_str __P((struct epdisc *)); /* string from endpoint discrim. */ -int str_to_epdisc __P((struct epdisc *, char *)); /* endpt disc. from str */ -#else -#define mp_bundle_terminated() /* nothing */ -#define mp_exit_bundle() /* nothing */ -#define doing_multilink 0 -#define multilink_master 0 -#endif - -/* Procedures exported from sys-*.c */ -void sys_init __P((void)); /* Do system-dependent initialization */ -void sys_cleanup __P((void)); /* Restore system state before exiting */ -int sys_check_options __P((void)); /* Check options specified */ -void sys_close __P((void)); /* Clean up in a child before execing */ -int ppp_available __P((void)); /* Test whether ppp kernel support exists */ -int get_pty __P((int *, int *, char *, int)); /* Get pty master/slave */ -int open_ppp_loopback __P((void)); /* Open loopback for demand-dialling */ -int tty_establish_ppp __P((int)); /* Turn serial port into a ppp interface */ -void tty_disestablish_ppp __P((int)); /* Restore port to normal operation */ -void generic_disestablish_ppp __P((int dev_fd)); /* Restore device setting */ -int generic_establish_ppp __P((int dev_fd)); /* Make a ppp interface */ -void make_new_bundle __P((int, int, int, int)); /* Create new bundle */ -int bundle_attach __P((int)); /* Attach link to existing bundle */ -void cfg_bundle __P((int, int, int, int)); /* Configure existing bundle */ -void destroy_bundle __P((void)); /* Tell driver to destroy bundle */ -void clean_check __P((void)); /* Check if line was 8-bit clean */ -void set_up_tty __P((int, int)); /* Set up port's speed, parameters, etc. */ -void restore_tty __P((int)); /* Restore port's original parameters */ -void setdtr __P((int, int)); /* Raise or lower port's DTR line */ -void output __P((int, u_char *, int)); /* Output a PPP packet */ -void wait_input __P((struct timeval *)); - /* Wait for input, with timeout */ -void add_fd __P((int)); /* Add fd to set to wait for */ -void remove_fd __P((int)); /* Remove fd from set to wait for */ -int read_packet __P((u_char *)); /* Read PPP packet */ -int get_loop_output __P((void)); /* Read pkts from loopback */ -void tty_send_config __P((int, u_int32_t, int, int)); - /* Configure i/f transmit parameters */ -void tty_set_xaccm __P((ext_accm)); - /* Set extended transmit ACCM */ -void tty_recv_config __P((int, u_int32_t, int, int)); - /* Configure i/f receive parameters */ -int ccp_test __P((int, u_char *, int, int)); - /* Test support for compression scheme */ -void ccp_flags_set __P((int, int, int)); - /* Set kernel CCP state */ -int ccp_fatal_error __P((int)); /* Test for fatal decomp error in kernel */ -int get_idle_time __P((int, struct ppp_idle *)); - /* Find out how long link has been idle */ -int get_ppp_stats __P((int, struct pppd_stats *)); - /* Return link statistics */ -void netif_set_mtu __P((int, int)); /* Set PPP interface MTU */ -int netif_get_mtu __P((int)); /* Get PPP interface MTU */ -int sifvjcomp __P((int, int, int, int)); - /* Configure VJ TCP header compression */ -int sifup __P((int)); /* Configure i/f up for one protocol */ -int sifnpmode __P((int u, int proto, enum NPmode mode)); - /* Set mode for handling packets for proto */ -int sifdown __P((int)); /* Configure i/f down for one protocol */ -int sifaddr __P((int, u_int32_t, u_int32_t, u_int32_t)); - /* Configure IPv4 addresses for i/f */ -int cifaddr __P((int, u_int32_t, u_int32_t)); - /* Reset i/f IP addresses */ -#ifdef INET6 -int sif6addr __P((int, eui64_t, eui64_t)); - /* Configure IPv6 addresses for i/f */ -int cif6addr __P((int, eui64_t, eui64_t)); - /* Remove an IPv6 address from i/f */ -#endif -int sifdefaultroute __P((int, u_int32_t, u_int32_t)); - /* Create default route through i/f */ -int cifdefaultroute __P((int, u_int32_t, u_int32_t)); - /* Delete default route through i/f */ -int sifproxyarp __P((int, u_int32_t)); - /* Add proxy ARP entry for peer */ -int cifproxyarp __P((int, u_int32_t)); - /* Delete proxy ARP entry for peer */ -u_int32_t GetMask __P((u_int32_t)); /* Get appropriate netmask for address */ -int lock __P((char *)); /* Create lock file for device */ -int relock __P((int)); /* Rewrite lock file with new pid */ -void unlock __P((void)); /* Delete previously-created lock file */ -void logwtmp __P((const char *, const char *, const char *)); - /* Write entry to wtmp file */ -int get_host_seed __P((void)); /* Get host-dependent random number seed */ -int have_route_to __P((u_int32_t)); /* Check if route to addr exists */ -#ifdef PPP_FILTER -int set_filters __P((struct bpf_program *pass, struct bpf_program *active)); - /* Set filter programs in kernel */ -#endif -#ifdef IPX_CHANGE -int sipxfaddr __P((int, unsigned long, unsigned char *)); -int cipxfaddr __P((int)); -#endif -int get_if_hwaddr __P((u_char *addr, char *name)); -char *get_first_ethernet __P((void)); - -/* Procedures exported from options.c */ -int setipaddr __P((char *, char **, int)); /* Set local/remote ip addresses */ -int parse_args __P((int argc, char **argv)); - /* Parse options from arguments given */ -int options_from_file __P((char *filename, int must_exist, int check_prot, - int privileged)); - /* Parse options from an options file */ -int options_from_user __P((void)); /* Parse options from user's .ppprc */ -int options_for_tty __P((void)); /* Parse options from /etc/ppp/options.tty */ -int options_from_list __P((struct wordlist *, int privileged)); - /* Parse options from a wordlist */ -int getword __P((FILE *f, char *word, int *newlinep, char *filename)); - /* Read a word from a file */ -void option_error __P((char *fmt, ...)); - /* Print an error message about an option */ -int int_option __P((char *, int *)); - /* Simplified number_option for decimal ints */ -void add_options __P((option_t *)); /* Add extra options */ -void check_options __P((void)); /* check values after all options parsed */ -int override_value __P((const char *, int, const char *)); - /* override value if permitted by priority */ -void print_options __P((void (*) __P((void *, char *, ...)), void *)); - /* print out values of all options */ - -int parse_dotted_ip __P((char *, u_int32_t *)); - -/* - * Hooks to enable plugins to change various things. - */ -extern int (*new_phase_hook) __P((int)); -extern int (*idle_time_hook) __P((struct ppp_idle *)); -extern int (*holdoff_hook) __P((void)); -extern int (*pap_check_hook) __P((void)); -extern int (*pap_auth_hook) __P((char *user, char *passwd, char **msgp, - struct wordlist **paddrs, - struct wordlist **popts)); -extern void (*pap_logout_hook) __P((void)); -extern int (*pap_passwd_hook) __P((char *user, char *passwd)); -extern int (*allowed_address_hook) __P((u_int32_t addr)); -extern void (*ip_up_hook) __P((void)); -extern void (*ip_down_hook) __P((void)); -extern void (*ip_choose_hook) __P((u_int32_t *)); - -extern int (*chap_check_hook) __P((void)); -extern int (*chap_passwd_hook) __P((char *user, char *passwd)); - -/* Let a plugin snoop sent and received packets. Useful for L2TP */ -extern void (*snoop_recv_hook) __P((unsigned char *p, int len)); -extern void (*snoop_send_hook) __P((unsigned char *p, int len)); - -/* - * Inline versions of get/put char/short/long. - * Pointer is advanced; we assume that both arguments - * are lvalues and will already be in registers. - * cp MUST be u_char *. - */ -#define GETCHAR(c, cp) { \ - (c) = *(cp)++; \ -} -#define PUTCHAR(c, cp) { \ - *(cp)++ = (u_char) (c); \ -} - - -#define GETSHORT(s, cp) { \ - (s) = *(cp)++ << 8; \ - (s) |= *(cp)++; \ -} -#define PUTSHORT(s, cp) { \ - *(cp)++ = (u_char) ((s) >> 8); \ - *(cp)++ = (u_char) (s); \ -} - -#define GETLONG(l, cp) { \ - (l) = *(cp)++ << 8; \ - (l) |= *(cp)++; (l) <<= 8; \ - (l) |= *(cp)++; (l) <<= 8; \ - (l) |= *(cp)++; \ -} -#define PUTLONG(l, cp) { \ - *(cp)++ = (u_char) ((l) >> 24); \ - *(cp)++ = (u_char) ((l) >> 16); \ - *(cp)++ = (u_char) ((l) >> 8); \ - *(cp)++ = (u_char) (l); \ -} - -#define INCPTR(n, cp) ((cp) += (n)) -#define DECPTR(n, cp) ((cp) -= (n)) - -/* - * System dependent definitions for user-level 4.3BSD UNIX implementation. - */ - -#define TIMEOUT(r, f, t) timeout((r), (f), (t), 0) -#define UNTIMEOUT(r, f) untimeout((r), (f)) - -#define BCOPY(s, d, l) memcpy(d, s, l) -#define BZERO(s, n) memset(s, 0, n) -#define BCMP(s1, s2, l) memcmp(s1, s2, l) - -#define PRINTMSG(m, l) { info("Remote message: %0.*v", l, m); } - -/* - * MAKEHEADER - Add Header fields to a packet. - */ -#define MAKEHEADER(p, t) { \ - PUTCHAR(PPP_ALLSTATIONS, p); \ - PUTCHAR(PPP_UI, p); \ - PUTSHORT(t, p); } - -/* - * Exit status values. - */ -#define EXIT_OK 0 -#define EXIT_FATAL_ERROR 1 -#define EXIT_OPTION_ERROR 2 -#define EXIT_NOT_ROOT 3 -#define EXIT_NO_KERNEL_SUPPORT 4 -#define EXIT_USER_REQUEST 5 -#define EXIT_LOCK_FAILED 6 -#define EXIT_OPEN_FAILED 7 -#define EXIT_CONNECT_FAILED 8 -#define EXIT_PTYCMD_FAILED 9 -#define EXIT_NEGOTIATION_FAILED 10 -#define EXIT_PEER_AUTH_FAILED 11 -#define EXIT_IDLE_TIMEOUT 12 -#define EXIT_CONNECT_TIME 13 -#define EXIT_CALLBACK 14 -#define EXIT_PEER_DEAD 15 -#define EXIT_HANGUP 16 -#define EXIT_LOOPBACK 17 -#define EXIT_INIT_FAILED 18 -#define EXIT_AUTH_TOPEER_FAILED 19 -#ifdef MAXOCTETS -#define EXIT_TRAFFIC_LIMIT 20 -#endif -#define EXIT_CNID_AUTH_FAILED 21 - -/* - * Debug macros. Slightly useful for finding bugs in pppd, not particularly - * useful for finding out why your connection isn't being established. - */ -#ifdef DEBUGALL -#define DEBUGMAIN 1 -#define DEBUGFSM 1 -#define DEBUGLCP 1 -#define DEBUGIPCP 1 -#define DEBUGIPV6CP 1 -#define DEBUGUPAP 1 -#define DEBUGCHAP 1 -#endif - -#ifndef LOG_PPP /* we use LOG_LOCAL2 for syslog by default */ -#if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUGSYS) \ - || defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) \ - || defined(DEBUGCHAP) || defined(DEBUG) || defined(DEBUGIPV6CP) -#define LOG_PPP LOG_LOCAL2 -#else -#define LOG_PPP LOG_DAEMON -#endif -#endif /* LOG_PPP */ - -#ifdef DEBUGMAIN -#define MAINDEBUG(x) if (debug) dbglog x -#else -#define MAINDEBUG(x) -#endif - -#ifdef DEBUGSYS -#define SYSDEBUG(x) if (debug) dbglog x -#else -#define SYSDEBUG(x) -#endif - -#ifdef DEBUGFSM -#define FSMDEBUG(x) if (debug) dbglog x -#else -#define FSMDEBUG(x) -#endif - -#ifdef DEBUGLCP -#define LCPDEBUG(x) if (debug) dbglog x -#else -#define LCPDEBUG(x) -#endif - -#ifdef DEBUGIPCP -#define IPCPDEBUG(x) if (debug) dbglog x -#else -#define IPCPDEBUG(x) -#endif - -#ifdef DEBUGIPV6CP -#define IPV6CPDEBUG(x) if (debug) dbglog x -#else -#define IPV6CPDEBUG(x) -#endif - -#ifdef DEBUGUPAP -#define UPAPDEBUG(x) if (debug) dbglog x -#else -#define UPAPDEBUG(x) -#endif - -#ifdef DEBUGCHAP -#define CHAPDEBUG(x) if (debug) dbglog x -#else -#define CHAPDEBUG(x) -#endif - -#ifdef DEBUGIPXCP -#define IPXCPDEBUG(x) if (debug) dbglog x -#else -#define IPXCPDEBUG(x) -#endif - -#ifndef SIGTYPE -#if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) -#define SIGTYPE void -#else -#define SIGTYPE int -#endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */ -#endif /* SIGTYPE */ - -#ifndef MIN -#define MIN(a, b) ((a) < (b)? (a): (b)) -#endif -#ifndef MAX -#define MAX(a, b) ((a) > (b)? (a): (b)) -#endif - -#ifndef offsetof -#define offsetof(type, member) ((size_t) &((type *)0)->member) -#endif - -#endif /* __PPP_H__ */ diff --git a/vpn-daemons/pptp/src/external/2.4.4/pppd/fsm.h b/vpn-daemons/pptp/src/external/2.4.4/pppd/fsm.h deleted file mode 100644 index f02473f2b0..0000000000 --- a/vpn-daemons/pptp/src/external/2.4.4/pppd/fsm.h +++ /dev/null @@ -1,168 +0,0 @@ -/* - * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions. - * - * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The name "Carnegie Mellon University" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For permission or any legal - * details, please contact - * Office of Technology Transfer - * Carnegie Mellon University - * 5000 Forbes Avenue - * Pittsburgh, PA 15213-3890 - * (412) 268-4387, fax: (412) 268-7395 - * tech-transfer@andrew.cmu.edu - * - * 4. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by Computing Services - * at Carnegie Mellon University (http://www.cmu.edu/computing/)." - * - * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE - * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN - * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * $Id$ - */ - -/* - * Packet header = Code, id, length. - */ -#define HEADERLEN 4 - - -/* - * CP (LCP, IPCP, etc.) codes. - */ -#define CONFREQ 1 /* Configuration Request */ -#define CONFACK 2 /* Configuration Ack */ -#define CONFNAK 3 /* Configuration Nak */ -#define CONFREJ 4 /* Configuration Reject */ -#define TERMREQ 5 /* Termination Request */ -#define TERMACK 6 /* Termination Ack */ -#define CODEREJ 7 /* Code Reject */ - - -/* - * Each FSM is described by an fsm structure and fsm callbacks. - */ -typedef struct fsm { - int unit; /* Interface unit number */ - int protocol; /* Data Link Layer Protocol field value */ - int state; /* State */ - int flags; /* Contains option bits */ - u_char id; /* Current id */ - u_char reqid; /* Current request id */ - u_char seen_ack; /* Have received valid Ack/Nak/Rej to Req */ - int timeouttime; /* Timeout time in milliseconds */ - int maxconfreqtransmits; /* Maximum Configure-Request transmissions */ - int retransmits; /* Number of retransmissions left */ - int maxtermtransmits; /* Maximum Terminate-Request transmissions */ - int nakloops; /* Number of nak loops since last ack */ - int rnakloops; /* Number of naks received */ - int maxnakloops; /* Maximum number of nak loops tolerated */ - struct fsm_callbacks *callbacks; /* Callback routines */ - char *term_reason; /* Reason for closing protocol */ - int term_reason_len; /* Length of term_reason */ -} fsm; - - -typedef struct fsm_callbacks { - void (*resetci) /* Reset our Configuration Information */ - __P((fsm *)); - int (*cilen) /* Length of our Configuration Information */ - __P((fsm *)); - void (*addci) /* Add our Configuration Information */ - __P((fsm *, u_char *, int *)); - int (*ackci) /* ACK our Configuration Information */ - __P((fsm *, u_char *, int)); - int (*nakci) /* NAK our Configuration Information */ - __P((fsm *, u_char *, int, int)); - int (*rejci) /* Reject our Configuration Information */ - __P((fsm *, u_char *, int)); - int (*reqci) /* Request peer's Configuration Information */ - __P((fsm *, u_char *, int *, int)); - void (*up) /* Called when fsm reaches OPENED state */ - __P((fsm *)); - void (*down) /* Called when fsm leaves OPENED state */ - __P((fsm *)); - void (*starting) /* Called when we want the lower layer */ - __P((fsm *)); - void (*finished) /* Called when we don't want the lower layer */ - __P((fsm *)); - void (*protreject) /* Called when Protocol-Reject received */ - __P((int)); - void (*retransmit) /* Retransmission is necessary */ - __P((fsm *)); - int (*extcode) /* Called when unknown code received */ - __P((fsm *, int, int, u_char *, int)); - char *proto_name; /* String name for protocol (for messages) */ -} fsm_callbacks; - - -/* - * Link states. - */ -#define INITIAL 0 /* Down, hasn't been opened */ -#define STARTING 1 /* Down, been opened */ -#define CLOSED 2 /* Up, hasn't been opened */ -#define STOPPED 3 /* Open, waiting for down event */ -#define CLOSING 4 /* Terminating the connection, not open */ -#define STOPPING 5 /* Terminating, but open */ -#define REQSENT 6 /* We've sent a Config Request */ -#define ACKRCVD 7 /* We've received a Config Ack */ -#define ACKSENT 8 /* We've sent a Config Ack */ -#define OPENED 9 /* Connection available */ - - -/* - * Flags - indicate options controlling FSM operation - */ -#define OPT_PASSIVE 1 /* Don't die if we don't get a response */ -#define OPT_RESTART 2 /* Treat 2nd OPEN as DOWN, UP */ -#define OPT_SILENT 4 /* Wait for peer to speak first */ - - -/* - * Timeouts. - */ -#define DEFTIMEOUT 3 /* Timeout time in seconds */ -#define DEFMAXTERMREQS 2 /* Maximum Terminate-Request transmissions */ -#define DEFMAXCONFREQS 10 /* Maximum Configure-Request transmissions */ -#define DEFMAXNAKLOOPS 5 /* Maximum number of nak loops */ - - -/* - * Prototypes - */ -void fsm_init __P((fsm *)); -void fsm_lowerup __P((fsm *)); -void fsm_lowerdown __P((fsm *)); -void fsm_open __P((fsm *)); -void fsm_close __P((fsm *, char *)); -void fsm_input __P((fsm *, u_char *, int)); -void fsm_protreject __P((fsm *)); -void fsm_sdata __P((fsm *, int, int, u_char *, int)); - - -/* - * Variables - */ -extern int peer_mru[]; /* currently negotiated peer MRU (per unit) */ diff --git a/vpn-daemons/pptp/src/external/2.4.4/pppd/ipcp.h b/vpn-daemons/pptp/src/external/2.4.4/pppd/ipcp.h deleted file mode 100644 index c0d3c85eb4..0000000000 --- a/vpn-daemons/pptp/src/external/2.4.4/pppd/ipcp.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * ipcp.h - IP Control Protocol definitions. - * - * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The name "Carnegie Mellon University" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For permission or any legal - * details, please contact - * Office of Technology Transfer - * Carnegie Mellon University - * 5000 Forbes Avenue - * Pittsburgh, PA 15213-3890 - * (412) 268-4387, fax: (412) 268-7395 - * tech-transfer@andrew.cmu.edu - * - * 4. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by Computing Services - * at Carnegie Mellon University (http://www.cmu.edu/computing/)." - * - * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE - * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN - * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * $Id$ - */ - -/* - * Options. - */ -#define CI_ADDRS 1 /* IP Addresses */ -#define CI_COMPRESSTYPE 2 /* Compression Type */ -#define CI_ADDR 3 - -#define CI_MS_DNS1 129 /* Primary DNS value */ -#define CI_MS_WINS1 130 /* Primary WINS value */ -#define CI_MS_DNS2 131 /* Secondary DNS value */ -#define CI_MS_WINS2 132 /* Secondary WINS value */ - -#define MAX_STATES 16 /* from slcompress.h */ - -#define IPCP_VJMODE_OLD 1 /* "old" mode (option # = 0x0037) */ -#define IPCP_VJMODE_RFC1172 2 /* "old-rfc"mode (option # = 0x002d) */ -#define IPCP_VJMODE_RFC1332 3 /* "new-rfc"mode (option # = 0x002d, */ - /* maxslot and slot number compression) */ - -#define IPCP_VJ_COMP 0x002d /* current value for VJ compression option*/ -#define IPCP_VJ_COMP_OLD 0x0037 /* "old" (i.e, broken) value for VJ */ - /* compression option*/ - -typedef struct ipcp_options { - bool neg_addr; /* Negotiate IP Address? */ - bool old_addrs; /* Use old (IP-Addresses) option? */ - bool req_addr; /* Ask peer to send IP address? */ - bool default_route; /* Assign default route through interface? */ - bool proxy_arp; /* Make proxy ARP entry for peer? */ - bool neg_vj; /* Van Jacobson Compression? */ - bool old_vj; /* use old (short) form of VJ option? */ - bool accept_local; /* accept peer's value for ouraddr */ - bool accept_remote; /* accept peer's value for hisaddr */ - bool req_dns1; /* Ask peer to send primary DNS address? */ - bool req_dns2; /* Ask peer to send secondary DNS address? */ - int vj_protocol; /* protocol value to use in VJ option */ - int maxslotindex; /* values for RFC1332 VJ compression neg. */ - bool cflag; - u_int32_t ouraddr, hisaddr; /* Addresses in NETWORK BYTE ORDER */ - u_int32_t dnsaddr[2]; /* Primary and secondary MS DNS entries */ - u_int32_t winsaddr[2]; /* Primary and secondary MS WINS entries */ -} ipcp_options; - -extern fsm ipcp_fsm[]; -extern ipcp_options ipcp_wantoptions[]; -extern ipcp_options ipcp_gotoptions[]; -extern ipcp_options ipcp_allowoptions[]; -extern ipcp_options ipcp_hisoptions[]; - -char *ip_ntoa __P((u_int32_t)); - -extern struct protent ipcp_protent; diff --git a/vpn-daemons/pptp/src/external/2.4.4/pppd/patchlevel.h b/vpn-daemons/pptp/src/external/2.4.4/pppd/patchlevel.h deleted file mode 100644 index a19202111d..0000000000 --- a/vpn-daemons/pptp/src/external/2.4.4/pppd/patchlevel.h +++ /dev/null @@ -1,4 +0,0 @@ -/* $Id$ */ - -#define VERSION "2.4.4" -#define DATE "28 June 2006" diff --git a/vpn-daemons/pptp/src/external/2.4.4/pppd/pppd.h b/vpn-daemons/pptp/src/external/2.4.4/pppd/pppd.h deleted file mode 100644 index 1168a26bb1..0000000000 --- a/vpn-daemons/pptp/src/external/2.4.4/pppd/pppd.h +++ /dev/null @@ -1,907 +0,0 @@ -/* - * pppd.h - PPP daemon global declarations. - * - * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The name "Carnegie Mellon University" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For permission or any legal - * details, please contact - * Office of Technology Transfer - * Carnegie Mellon University - * 5000 Forbes Avenue - * Pittsburgh, PA 15213-3890 - * (412) 268-4387, fax: (412) 268-7395 - * tech-transfer@andrew.cmu.edu - * - * 4. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by Computing Services - * at Carnegie Mellon University (http://www.cmu.edu/computing/)." - * - * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE - * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN - * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * $Id$ - */ - -/* - * TODO: - */ - -#ifndef __PPPD_H__ -#define __PPPD_H__ - -#include /* for FILE */ -#include /* for NGROUPS_MAX */ -#include /* for MAXPATHLEN and BSD4_4, if defined */ -#include /* for u_int32_t, if defined */ -#include /* for struct timeval */ -#include -#include "patchlevel.h" - -#if defined(__STDC__) -#include -#define __V(x) x -#else -#include -#define __V(x) (va_alist) va_dcl -#define const -#define volatile -#endif - -#ifdef INET6 -#include "eui64.h" -#endif - -/* - * Limits. - */ - -#define NUM_PPP 1 /* One PPP interface supported (per process) */ -#define MAXWORDLEN 1024 /* max length of word in file (incl null) */ -#define MAXARGS 1 /* max # args to a command */ -#define MAXNAMELEN 256 /* max length of hostname or name for auth */ -#define MAXSECRETLEN 256 /* max length of password or secret */ - -/* - * Option descriptor structure. - */ - -typedef unsigned char bool; - -enum opt_type { - o_special_noarg = 0, - o_special = 1, - o_bool, - o_int, - o_uint32, - o_string, - o_wild -}; - -typedef struct { - char *name; /* name of the option */ - enum opt_type type; - void *addr; - char *description; - unsigned int flags; - void *addr2; - int upper_limit; - int lower_limit; - const char *source; - short int priority; - short int winner; -} option_t; - -/* Values for flags */ -#define OPT_VALUE 0xff /* mask for presupplied value */ -#define OPT_HEX 0x100 /* int option is in hex */ -#define OPT_NOARG 0x200 /* option doesn't take argument */ -#define OPT_OR 0x400 /* OR in argument to value */ -#define OPT_INC 0x800 /* increment value */ -#define OPT_A2OR 0x800 /* for o_bool, OR arg to *(u_char *)addr2 */ -#define OPT_PRIV 0x1000 /* privileged option */ -#define OPT_STATIC 0x2000 /* string option goes into static array */ -#define OPT_LLIMIT 0x4000 /* check value against lower limit */ -#define OPT_ULIMIT 0x8000 /* check value against upper limit */ -#define OPT_LIMITS (OPT_LLIMIT|OPT_ULIMIT) -#define OPT_ZEROOK 0x10000 /* 0 value is OK even if not within limits */ -#define OPT_HIDE 0x10000 /* for o_string, print value as ?????? */ -#define OPT_A2LIST 0x10000 /* for o_special, keep list of values */ -#define OPT_A2CLRB 0x10000 /* o_bool, clr val bits in *(u_char *)addr2 */ -#define OPT_NOINCR 0x20000 /* value mustn't be increased */ -#define OPT_ZEROINF 0x40000 /* with OPT_NOINCR, 0 == infinity */ -#define OPT_PRIO 0x80000 /* process option priorities for this option */ -#define OPT_PRIOSUB 0x100000 /* subsidiary member of priority group */ -#define OPT_ALIAS 0x200000 /* option is alias for previous option */ -#define OPT_A2COPY 0x400000 /* addr2 -> second location to rcv value */ -#define OPT_ENABLE 0x800000 /* use *addr2 as enable for option */ -#define OPT_A2CLR 0x1000000 /* clear *(bool *)addr2 */ -#define OPT_PRIVFIX 0x2000000 /* user can't override if set by root */ -#define OPT_INITONLY 0x4000000 /* option can only be set in init phase */ -#define OPT_DEVEQUIV 0x8000000 /* equiv to device name */ -#define OPT_DEVNAM (OPT_INITONLY | OPT_DEVEQUIV) -#define OPT_A2PRINTER 0x10000000 /* *addr2 is a fn for printing option */ -#define OPT_A2STRVAL 0x20000000 /* *addr2 points to current string value */ -#define OPT_NOPRINT 0x40000000 /* don't print this option at all */ - -#define OPT_VAL(x) ((x) & OPT_VALUE) - -/* Values for priority */ -#define OPRIO_DEFAULT 0 /* a default value */ -#define OPRIO_CFGFILE 1 /* value from a configuration file */ -#define OPRIO_CMDLINE 2 /* value from the command line */ -#define OPRIO_SECFILE 3 /* value from options in a secrets file */ -#define OPRIO_ROOT 100 /* added to priority if OPT_PRIVFIX && root */ - -#ifndef GIDSET_TYPE -#define GIDSET_TYPE gid_t -#endif - -/* Structure representing a list of permitted IP addresses. */ -struct permitted_ip { - int permit; /* 1 = permit, 0 = forbid */ - u_int32_t base; /* match if (addr & mask) == base */ - u_int32_t mask; /* base and mask are in network byte order */ -}; - -/* - * Unfortunately, the linux kernel driver uses a different structure - * for statistics from the rest of the ports. - * This structure serves as a common representation for the bits - * pppd needs. - */ -struct pppd_stats { - unsigned int bytes_in; - unsigned int bytes_out; - unsigned int pkts_in; - unsigned int pkts_out; -}; - -/* Used for storing a sequence of words. Usually malloced. */ -struct wordlist { - struct wordlist *next; - char *word; -}; - -/* An endpoint discriminator, used with multilink. */ -#define MAX_ENDP_LEN 20 /* maximum length of discriminator value */ -struct epdisc { - unsigned char class; - unsigned char length; - unsigned char value[MAX_ENDP_LEN]; -}; - -/* values for epdisc.class */ -#define EPD_NULL 0 /* null discriminator, no data */ -#define EPD_LOCAL 1 -#define EPD_IP 2 -#define EPD_MAC 3 -#define EPD_MAGIC 4 -#define EPD_PHONENUM 5 - -typedef void (*notify_func) __P((void *, int)); - -struct notifier { - struct notifier *next; - notify_func func; - void *arg; -}; - -/* - * Global variables. - */ - -extern int hungup; /* Physical layer has disconnected */ -extern int ifunit; /* Interface unit number */ -extern char ifname[]; /* Interface name */ -extern char hostname[]; /* Our hostname */ -extern u_char outpacket_buf[]; /* Buffer for outgoing packets */ -extern int devfd; /* fd of underlying device */ -extern int fd_ppp; /* fd for talking PPP */ -extern int phase; /* Current state of link - see values below */ -extern int baud_rate; /* Current link speed in bits/sec */ -extern char *progname; /* Name of this program */ -extern int redirect_stderr;/* Connector's stderr should go to file */ -extern char peer_authname[];/* Authenticated name of peer */ -extern int auth_done[NUM_PPP]; /* Methods actually used for auth */ -extern int privileged; /* We were run by real-uid root */ -extern int need_holdoff; /* Need holdoff period after link terminates */ -extern char **script_env; /* Environment variables for scripts */ -extern int detached; /* Have detached from controlling tty */ -extern GIDSET_TYPE groups[NGROUPS_MAX]; /* groups the user is in */ -extern int ngroups; /* How many groups valid in groups */ -extern struct pppd_stats link_stats; /* byte/packet counts etc. for link */ -extern int link_stats_valid; /* set if link_stats is valid */ -extern unsigned link_connect_time; /* time the link was up for */ -extern int using_pty; /* using pty as device (notty or pty opt.) */ -extern int log_to_fd; /* logging to this fd as well as syslog */ -extern bool log_default; /* log_to_fd is default (stdout) */ -extern char *no_ppp_msg; /* message to print if ppp not in kernel */ -extern volatile int status; /* exit status for pppd */ -extern bool devnam_fixed; /* can no longer change devnam */ -extern int unsuccess; /* # unsuccessful connection attempts */ -extern int do_callback; /* set if we want to do callback next */ -extern int doing_callback; /* set if this is a callback */ -extern int error_count; /* # of times error() has been called */ -extern char ppp_devnam[MAXPATHLEN]; -extern char remote_number[MAXNAMELEN]; /* Remote telephone number, if avail. */ -extern int ppp_session_number; /* Session number (eg PPPoE session) */ -extern int fd_devnull; /* fd open to /dev/null */ - -extern int listen_time; /* time to listen first (ms) */ -extern bool doing_multilink; -extern bool multilink_master; -extern bool bundle_eof; -extern bool bundle_terminating; - -extern struct notifier *pidchange; /* for notifications of pid changing */ -extern struct notifier *phasechange; /* for notifications of phase changes */ -extern struct notifier *exitnotify; /* for notification that we're exiting */ -extern struct notifier *sigreceived; /* notification of received signal */ -extern struct notifier *ip_up_notifier; /* IPCP has come up */ -extern struct notifier *ip_down_notifier; /* IPCP has gone down */ -extern struct notifier *auth_up_notifier; /* peer has authenticated */ -extern struct notifier *link_down_notifier; /* link has gone down */ -extern struct notifier *fork_notifier; /* we are a new child process */ - -/* Values for do_callback and doing_callback */ -#define CALLBACK_DIALIN 1 /* we are expecting the call back */ -#define CALLBACK_DIALOUT 2 /* we are dialling out to call back */ - -/* - * Variables set by command-line options. - */ - -extern int debug; /* Debug flag */ -extern int kdebugflag; /* Tell kernel to print debug messages */ -extern int default_device; /* Using /dev/tty or equivalent */ -extern char devnam[MAXPATHLEN]; /* Device name */ -extern int crtscts; /* Use hardware flow control */ -extern bool modem; /* Use modem control lines */ -extern int inspeed; /* Input/Output speed requested */ -extern u_int32_t netmask; /* IP netmask to set on interface */ -extern bool lockflag; /* Create lock file to lock the serial dev */ -extern bool nodetach; /* Don't detach from controlling tty */ -extern bool updetach; /* Detach from controlling tty when link up */ -extern char *initializer; /* Script to initialize physical link */ -extern char *connect_script; /* Script to establish physical link */ -extern char *disconnect_script; /* Script to disestablish physical link */ -extern char *welcomer; /* Script to welcome client after connection */ -extern char *ptycommand; /* Command to run on other side of pty */ -extern int maxconnect; /* Maximum connect time (seconds) */ -extern char user[MAXNAMELEN];/* Our name for authenticating ourselves */ -extern char passwd[MAXSECRETLEN]; /* Password for PAP or CHAP */ -extern bool auth_required; /* Peer is required to authenticate */ -extern bool persist; /* Reopen link after it goes down */ -extern bool uselogin; /* Use /etc/passwd for checking PAP */ -extern char our_name[MAXNAMELEN];/* Our name for authentication purposes */ -extern char remote_name[MAXNAMELEN]; /* Peer's name for authentication */ -extern bool explicit_remote;/* remote_name specified with remotename opt */ -extern bool demand; /* Do dial-on-demand */ -extern char *ipparam; /* Extra parameter for ip up/down scripts */ -extern bool cryptpap; /* Others' PAP passwords are encrypted */ -extern int idle_time_limit;/* Shut down link if idle for this long */ -extern int holdoff; /* Dead time before restarting */ -extern bool holdoff_specified; /* true if user gave a holdoff value */ -extern bool notty; /* Stdin/out is not a tty */ -extern char *pty_socket; /* Socket to connect to pty */ -extern char *record_file; /* File to record chars sent/received */ -extern bool sync_serial; /* Device is synchronous serial device */ -extern int maxfail; /* Max # of unsuccessful connection attempts */ -extern char linkname[MAXPATHLEN]; /* logical name for link */ -extern bool tune_kernel; /* May alter kernel settings as necessary */ -extern int connect_delay; /* Time to delay after connect script */ -extern int max_data_rate; /* max bytes/sec through charshunt */ -extern int req_unit; /* interface unit number to use */ -extern bool multilink; /* enable multilink operation */ -extern bool noendpoint; /* don't send or accept endpt. discrim. */ -extern char *bundle_name; /* bundle name for multilink */ -extern bool dump_options; /* print out option values */ -extern bool dryrun; /* check everything, print options, exit */ -extern int child_wait; /* # seconds to wait for children at end */ - -#ifdef MAXOCTETS -extern unsigned int maxoctets; /* Maximum octetes per session (in bytes) */ -extern int maxoctets_dir; /* Direction : - 0 - in+out (default) - 1 - in - 2 - out - 3 - max(in,out) */ -extern int maxoctets_timeout; /* Timeout for check of octets limit */ -#define PPP_OCTETS_DIRECTION_SUM 0 -#define PPP_OCTETS_DIRECTION_IN 1 -#define PPP_OCTETS_DIRECTION_OUT 2 -#define PPP_OCTETS_DIRECTION_MAXOVERAL 3 -/* same as previos, but little different on RADIUS side */ -#define PPP_OCTETS_DIRECTION_MAXSESSION 4 -#endif - -#ifdef PPP_FILTER -extern struct bpf_program pass_filter; /* Filter for pkts to pass */ -extern struct bpf_program active_filter; /* Filter for link-active pkts */ -#endif - -#ifdef MSLANMAN -extern bool ms_lanman; /* Use LanMan password instead of NT */ - /* Has meaning only with MS-CHAP challenges */ -#endif - -/* Values for auth_pending, auth_done */ -#define PAP_WITHPEER 0x1 -#define PAP_PEER 0x2 -#define CHAP_WITHPEER 0x4 -#define CHAP_PEER 0x8 -#define EAP_WITHPEER 0x10 -#define EAP_PEER 0x20 - -/* Values for auth_done only */ -#define CHAP_MD5_WITHPEER 0x40 -#define CHAP_MD5_PEER 0x80 -#define CHAP_MS_SHIFT 8 /* LSB position for MS auths */ -#define CHAP_MS_WITHPEER 0x100 -#define CHAP_MS_PEER 0x200 -#define CHAP_MS2_WITHPEER 0x400 -#define CHAP_MS2_PEER 0x800 - -extern char *current_option; /* the name of the option being parsed */ -extern int privileged_option; /* set iff the current option came from root */ -extern char *option_source; /* string saying where the option came from */ -extern int option_priority; /* priority of current options */ - -/* - * Values for phase. - */ -#define PHASE_DEAD 0 -#define PHASE_INITIALIZE 1 -#define PHASE_SERIALCONN 2 -#define PHASE_DORMANT 3 -#define PHASE_ESTABLISH 4 -#define PHASE_AUTHENTICATE 5 -#define PHASE_CALLBACK 6 -#define PHASE_NETWORK 7 -#define PHASE_RUNNING 8 -#define PHASE_TERMINATE 9 -#define PHASE_DISCONNECT 10 -#define PHASE_HOLDOFF 11 -#define PHASE_MASTER 12 - -/* - * The following struct gives the addresses of procedures to call - * for a particular protocol. - */ -struct protent { - u_short protocol; /* PPP protocol number */ - /* Initialization procedure */ - void (*init) __P((int unit)); - /* Process a received packet */ - void (*input) __P((int unit, u_char *pkt, int len)); - /* Process a received protocol-reject */ - void (*protrej) __P((int unit)); - /* Lower layer has come up */ - void (*lowerup) __P((int unit)); - /* Lower layer has gone down */ - void (*lowerdown) __P((int unit)); - /* Open the protocol */ - void (*open) __P((int unit)); - /* Close the protocol */ - void (*close) __P((int unit, char *reason)); - /* Print a packet in readable form */ - int (*printpkt) __P((u_char *pkt, int len, - void (*printer) __P((void *, char *, ...)), - void *arg)); - /* Process a received data packet */ - void (*datainput) __P((int unit, u_char *pkt, int len)); - bool enabled_flag; /* 0 iff protocol is disabled */ - char *name; /* Text name of protocol */ - char *data_name; /* Text name of corresponding data protocol */ - option_t *options; /* List of command-line options */ - /* Check requested options, assign defaults */ - void (*check_options) __P((void)); - /* Configure interface for demand-dial */ - int (*demand_conf) __P((int unit)); - /* Say whether to bring up link for this pkt */ - int (*active_pkt) __P((u_char *pkt, int len)); -}; - -/* Table of pointers to supported protocols */ -extern struct protent *protocols[]; - -/* - * This struct contains pointers to a set of procedures for - * doing operations on a "channel". A channel provides a way - * to send and receive PPP packets - the canonical example is - * a serial port device in PPP line discipline (or equivalently - * with PPP STREAMS modules pushed onto it). - */ -struct channel { - /* set of options for this channel */ - option_t *options; - /* find and process a per-channel options file */ - void (*process_extra_options) __P((void)); - /* check all the options that have been given */ - void (*check_options) __P((void)); - /* get the channel ready to do PPP, return a file descriptor */ - int (*connect) __P((void)); - /* we're finished with the channel */ - void (*disconnect) __P((void)); - /* put the channel into PPP `mode' */ - int (*establish_ppp) __P((int)); - /* take the channel out of PPP `mode', restore loopback if demand */ - void (*disestablish_ppp) __P((int)); - /* set the transmit-side PPP parameters of the channel */ - void (*send_config) __P((int, u_int32_t, int, int)); - /* set the receive-side PPP parameters of the channel */ - void (*recv_config) __P((int, u_int32_t, int, int)); - /* cleanup on error or normal exit */ - void (*cleanup) __P((void)); - /* close the device, called in children after fork */ - void (*close) __P((void)); -}; - -extern struct channel *the_channel; - -/* - * Prototypes. - */ - -/* Procedures exported from main.c. */ -void set_ifunit __P((int)); /* set stuff that depends on ifunit */ -void detach __P((void)); /* Detach from controlling tty */ -void die __P((int)); /* Cleanup and exit */ -void quit __P((void)); /* like die(1) */ -void novm __P((char *)); /* Say we ran out of memory, and die */ -void timeout __P((void (*func)(void *), void *arg, int s, int us)); - /* Call func(arg) after s.us seconds */ -void untimeout __P((void (*func)(void *), void *arg)); - /* Cancel call to func(arg) */ -void record_child __P((int, char *, void (*) (void *), void *)); -pid_t safe_fork __P((int, int, int)); /* Fork & close stuff in child */ -int device_script __P((char *cmd, int in, int out, int dont_wait)); - /* Run `cmd' with given stdin and stdout */ -pid_t run_program __P((char *prog, char **args, int must_exist, - void (*done)(void *), void *arg, int wait)); - /* Run program prog with args in child */ -void reopen_log __P((void)); /* (re)open the connection to syslog */ -void print_link_stats __P((void)); /* Print stats, if available */ -void reset_link_stats __P((int)); /* Reset (init) stats when link goes up */ -void update_link_stats __P((int)); /* Get stats at link termination */ -void script_setenv __P((char *, char *, int)); /* set script env var */ -void script_unsetenv __P((char *)); /* unset script env var */ -void new_phase __P((int)); /* signal start of new phase */ -void add_notifier __P((struct notifier **, notify_func, void *)); -void remove_notifier __P((struct notifier **, notify_func, void *)); -void notify __P((struct notifier *, int)); -int ppp_send_config __P((int, int, u_int32_t, int, int)); -int ppp_recv_config __P((int, int, u_int32_t, int, int)); -const char *protocol_name __P((int)); -void remove_pidfiles __P((void)); -void lock_db __P((void)); -void unlock_db __P((void)); - -/* Procedures exported from tty.c. */ -void tty_init __P((void)); - -/* Procedures exported from utils.c. */ -void log_packet __P((u_char *, int, char *, int)); - /* Format a packet and log it with syslog */ -void print_string __P((char *, int, void (*) (void *, char *, ...), - void *)); /* Format a string for output */ -int slprintf __P((char *, int, char *, ...)); /* sprintf++ */ -int vslprintf __P((char *, int, char *, va_list)); /* vsprintf++ */ -size_t strlcpy __P((char *, const char *, size_t)); /* safe strcpy */ -size_t strlcat __P((char *, const char *, size_t)); /* safe strncpy */ -void dbglog __P((char *, ...)); /* log a debug message */ -void info __P((char *, ...)); /* log an informational message */ -void notice __P((char *, ...)); /* log a notice-level message */ -void warn __P((char *, ...)); /* log a warning message */ -void error __P((char *, ...)); /* log an error message */ -void fatal __P((char *, ...)); /* log an error message and die(1) */ -void init_pr_log __P((char *, int)); /* initialize for using pr_log */ -void pr_log __P((void *, char *, ...)); /* printer fn, output to syslog */ -void end_pr_log __P((void)); /* finish up after using pr_log */ -void dump_packet __P((const char *, u_char *, int)); - /* dump packet to debug log if interesting */ -ssize_t complete_read __P((int, void *, size_t)); - /* read a complete buffer */ - -/* Procedures exported from auth.c */ -void link_required __P((int)); /* we are starting to use the link */ -void start_link __P((int)); /* bring the link up now */ -void link_terminated __P((int)); /* we are finished with the link */ -void link_down __P((int)); /* the LCP layer has left the Opened state */ -void upper_layers_down __P((int));/* take all NCPs down */ -void link_established __P((int)); /* the link is up; authenticate now */ -void start_networks __P((int)); /* start all the network control protos */ -void continue_networks __P((int)); /* start network [ip, etc] control protos */ -void np_up __P((int, int)); /* a network protocol has come up */ -void np_down __P((int, int)); /* a network protocol has gone down */ -void np_finished __P((int, int)); /* a network protocol no longer needs link */ -void auth_peer_fail __P((int, int)); - /* peer failed to authenticate itself */ -void auth_peer_success __P((int, int, int, char *, int)); - /* peer successfully authenticated itself */ -void auth_withpeer_fail __P((int, int)); - /* we failed to authenticate ourselves */ -void auth_withpeer_success __P((int, int, int)); - /* we successfully authenticated ourselves */ -void auth_check_options __P((void)); - /* check authentication options supplied */ -void auth_reset __P((int)); /* check what secrets we have */ -int check_passwd __P((int, char *, int, char *, int, char **)); - /* Check peer-supplied username/password */ -int get_secret __P((int, char *, char *, char *, int *, int)); - /* get "secret" for chap */ -int get_srp_secret __P((int unit, char *client, char *server, char *secret, - int am_server)); -int auth_ip_addr __P((int, u_int32_t)); - /* check if IP address is authorized */ -int auth_number __P((void)); /* check if remote number is authorized */ -int bad_ip_adrs __P((u_int32_t)); - /* check if IP address is unreasonable */ - -/* Procedures exported from demand.c */ -void demand_conf __P((void)); /* config interface(s) for demand-dial */ -void demand_block __P((void)); /* set all NPs to queue up packets */ -void demand_unblock __P((void)); /* set all NPs to pass packets */ -void demand_discard __P((void)); /* set all NPs to discard packets */ -void demand_rexmit __P((int)); /* retransmit saved frames for an NP */ -int loop_chars __P((unsigned char *, int)); /* process chars from loopback */ -int loop_frame __P((unsigned char *, int)); /* should we bring link up? */ - -/* Procedures exported from multilink.c */ -#ifdef HAVE_MULTILINK -void mp_check_options __P((void)); /* Check multilink-related options */ -int mp_join_bundle __P((void)); /* join our link to an appropriate bundle */ -void mp_exit_bundle __P((void)); /* have disconnected our link from bundle */ -void mp_bundle_terminated __P((void)); -char *epdisc_to_str __P((struct epdisc *)); /* string from endpoint discrim. */ -int str_to_epdisc __P((struct epdisc *, char *)); /* endpt disc. from str */ -#else -#define mp_bundle_terminated() /* nothing */ -#define mp_exit_bundle() /* nothing */ -#define doing_multilink 0 -#define multilink_master 0 -#endif - -/* Procedures exported from sys-*.c */ -void sys_init __P((void)); /* Do system-dependent initialization */ -void sys_cleanup __P((void)); /* Restore system state before exiting */ -int sys_check_options __P((void)); /* Check options specified */ -void sys_close __P((void)); /* Clean up in a child before execing */ -int ppp_available __P((void)); /* Test whether ppp kernel support exists */ -int get_pty __P((int *, int *, char *, int)); /* Get pty master/slave */ -int open_ppp_loopback __P((void)); /* Open loopback for demand-dialling */ -int tty_establish_ppp __P((int)); /* Turn serial port into a ppp interface */ -void tty_disestablish_ppp __P((int)); /* Restore port to normal operation */ -void generic_disestablish_ppp __P((int dev_fd)); /* Restore device setting */ -int generic_establish_ppp __P((int dev_fd)); /* Make a ppp interface */ -void make_new_bundle __P((int, int, int, int)); /* Create new bundle */ -int bundle_attach __P((int)); /* Attach link to existing bundle */ -void cfg_bundle __P((int, int, int, int)); /* Configure existing bundle */ -void destroy_bundle __P((void)); /* Tell driver to destroy bundle */ -void clean_check __P((void)); /* Check if line was 8-bit clean */ -void set_up_tty __P((int, int)); /* Set up port's speed, parameters, etc. */ -void restore_tty __P((int)); /* Restore port's original parameters */ -void setdtr __P((int, int)); /* Raise or lower port's DTR line */ -void output __P((int, u_char *, int)); /* Output a PPP packet */ -void wait_input __P((struct timeval *)); - /* Wait for input, with timeout */ -void add_fd __P((int)); /* Add fd to set to wait for */ -void remove_fd __P((int)); /* Remove fd from set to wait for */ -int read_packet __P((u_char *)); /* Read PPP packet */ -int get_loop_output __P((void)); /* Read pkts from loopback */ -void tty_send_config __P((int, u_int32_t, int, int)); - /* Configure i/f transmit parameters */ -void tty_set_xaccm __P((ext_accm)); - /* Set extended transmit ACCM */ -void tty_recv_config __P((int, u_int32_t, int, int)); - /* Configure i/f receive parameters */ -int ccp_test __P((int, u_char *, int, int)); - /* Test support for compression scheme */ -void ccp_flags_set __P((int, int, int)); - /* Set kernel CCP state */ -int ccp_fatal_error __P((int)); /* Test for fatal decomp error in kernel */ -int get_idle_time __P((int, struct ppp_idle *)); - /* Find out how long link has been idle */ -int get_ppp_stats __P((int, struct pppd_stats *)); - /* Return link statistics */ -void netif_set_mtu __P((int, int)); /* Set PPP interface MTU */ -int netif_get_mtu __P((int)); /* Get PPP interface MTU */ -int sifvjcomp __P((int, int, int, int)); - /* Configure VJ TCP header compression */ -int sifup __P((int)); /* Configure i/f up for one protocol */ -int sifnpmode __P((int u, int proto, enum NPmode mode)); - /* Set mode for handling packets for proto */ -int sifdown __P((int)); /* Configure i/f down for one protocol */ -int sifaddr __P((int, u_int32_t, u_int32_t, u_int32_t)); - /* Configure IPv4 addresses for i/f */ -int cifaddr __P((int, u_int32_t, u_int32_t)); - /* Reset i/f IP addresses */ -#ifdef INET6 -int sif6addr __P((int, eui64_t, eui64_t)); - /* Configure IPv6 addresses for i/f */ -int cif6addr __P((int, eui64_t, eui64_t)); - /* Remove an IPv6 address from i/f */ -#endif -int sifdefaultroute __P((int, u_int32_t, u_int32_t)); - /* Create default route through i/f */ -int cifdefaultroute __P((int, u_int32_t, u_int32_t)); - /* Delete default route through i/f */ -int sifproxyarp __P((int, u_int32_t)); - /* Add proxy ARP entry for peer */ -int cifproxyarp __P((int, u_int32_t)); - /* Delete proxy ARP entry for peer */ -u_int32_t GetMask __P((u_int32_t)); /* Get appropriate netmask for address */ -int lock __P((char *)); /* Create lock file for device */ -int relock __P((int)); /* Rewrite lock file with new pid */ -void unlock __P((void)); /* Delete previously-created lock file */ -void logwtmp __P((const char *, const char *, const char *)); - /* Write entry to wtmp file */ -int get_host_seed __P((void)); /* Get host-dependent random number seed */ -int have_route_to __P((u_int32_t)); /* Check if route to addr exists */ -#ifdef PPP_FILTER -int set_filters __P((struct bpf_program *pass, struct bpf_program *active)); - /* Set filter programs in kernel */ -#endif -#ifdef IPX_CHANGE -int sipxfaddr __P((int, unsigned long, unsigned char *)); -int cipxfaddr __P((int)); -#endif -int get_if_hwaddr __P((u_char *addr, char *name)); -char *get_first_ethernet __P((void)); - -/* Procedures exported from options.c */ -int setipaddr __P((char *, char **, int)); /* Set local/remote ip addresses */ -int parse_args __P((int argc, char **argv)); - /* Parse options from arguments given */ -int options_from_file __P((char *filename, int must_exist, int check_prot, - int privileged)); - /* Parse options from an options file */ -int options_from_user __P((void)); /* Parse options from user's .ppprc */ -int options_for_tty __P((void)); /* Parse options from /etc/ppp/options.tty */ -int options_from_list __P((struct wordlist *, int privileged)); - /* Parse options from a wordlist */ -int getword __P((FILE *f, char *word, int *newlinep, char *filename)); - /* Read a word from a file */ -void option_error __P((char *fmt, ...)); - /* Print an error message about an option */ -int int_option __P((char *, int *)); - /* Simplified number_option for decimal ints */ -void add_options __P((option_t *)); /* Add extra options */ -void check_options __P((void)); /* check values after all options parsed */ -int override_value __P((const char *, int, const char *)); - /* override value if permitted by priority */ -void print_options __P((void (*) __P((void *, char *, ...)), void *)); - /* print out values of all options */ - -int parse_dotted_ip __P((char *, u_int32_t *)); - -/* - * Hooks to enable plugins to change various things. - */ -extern int (*new_phase_hook) __P((int)); -extern int (*idle_time_hook) __P((struct ppp_idle *)); -extern int (*holdoff_hook) __P((void)); -extern int (*pap_check_hook) __P((void)); -extern int (*pap_auth_hook) __P((char *user, char *passwd, char **msgp, - struct wordlist **paddrs, - struct wordlist **popts)); -extern void (*pap_logout_hook) __P((void)); -extern int (*pap_passwd_hook) __P((char *user, char *passwd)); -extern int (*allowed_address_hook) __P((u_int32_t addr)); -extern void (*ip_up_hook) __P((void)); -extern void (*ip_down_hook) __P((void)); -extern void (*ip_choose_hook) __P((u_int32_t *)); - -extern int (*chap_check_hook) __P((void)); -extern int (*chap_passwd_hook) __P((char *user, char *passwd)); - -/* Let a plugin snoop sent and received packets. Useful for L2TP */ -extern void (*snoop_recv_hook) __P((unsigned char *p, int len)); -extern void (*snoop_send_hook) __P((unsigned char *p, int len)); - -/* - * Inline versions of get/put char/short/long. - * Pointer is advanced; we assume that both arguments - * are lvalues and will already be in registers. - * cp MUST be u_char *. - */ -#define GETCHAR(c, cp) { \ - (c) = *(cp)++; \ -} -#define PUTCHAR(c, cp) { \ - *(cp)++ = (u_char) (c); \ -} - - -#define GETSHORT(s, cp) { \ - (s) = *(cp)++ << 8; \ - (s) |= *(cp)++; \ -} -#define PUTSHORT(s, cp) { \ - *(cp)++ = (u_char) ((s) >> 8); \ - *(cp)++ = (u_char) (s); \ -} - -#define GETLONG(l, cp) { \ - (l) = *(cp)++ << 8; \ - (l) |= *(cp)++; (l) <<= 8; \ - (l) |= *(cp)++; (l) <<= 8; \ - (l) |= *(cp)++; \ -} -#define PUTLONG(l, cp) { \ - *(cp)++ = (u_char) ((l) >> 24); \ - *(cp)++ = (u_char) ((l) >> 16); \ - *(cp)++ = (u_char) ((l) >> 8); \ - *(cp)++ = (u_char) (l); \ -} - -#define INCPTR(n, cp) ((cp) += (n)) -#define DECPTR(n, cp) ((cp) -= (n)) - -/* - * System dependent definitions for user-level 4.3BSD UNIX implementation. - */ - -#define TIMEOUT(r, f, t) timeout((r), (f), (t), 0) -#define UNTIMEOUT(r, f) untimeout((r), (f)) - -#define BCOPY(s, d, l) memcpy(d, s, l) -#define BZERO(s, n) memset(s, 0, n) -#define BCMP(s1, s2, l) memcmp(s1, s2, l) - -#define PRINTMSG(m, l) { info("Remote message: %0.*v", l, m); } - -/* - * MAKEHEADER - Add Header fields to a packet. - */ -#define MAKEHEADER(p, t) { \ - PUTCHAR(PPP_ALLSTATIONS, p); \ - PUTCHAR(PPP_UI, p); \ - PUTSHORT(t, p); } - -/* - * Exit status values. - */ -#define EXIT_OK 0 -#define EXIT_FATAL_ERROR 1 -#define EXIT_OPTION_ERROR 2 -#define EXIT_NOT_ROOT 3 -#define EXIT_NO_KERNEL_SUPPORT 4 -#define EXIT_USER_REQUEST 5 -#define EXIT_LOCK_FAILED 6 -#define EXIT_OPEN_FAILED 7 -#define EXIT_CONNECT_FAILED 8 -#define EXIT_PTYCMD_FAILED 9 -#define EXIT_NEGOTIATION_FAILED 10 -#define EXIT_PEER_AUTH_FAILED 11 -#define EXIT_IDLE_TIMEOUT 12 -#define EXIT_CONNECT_TIME 13 -#define EXIT_CALLBACK 14 -#define EXIT_PEER_DEAD 15 -#define EXIT_HANGUP 16 -#define EXIT_LOOPBACK 17 -#define EXIT_INIT_FAILED 18 -#define EXIT_AUTH_TOPEER_FAILED 19 -#ifdef MAXOCTETS -#define EXIT_TRAFFIC_LIMIT 20 -#endif -#define EXIT_CNID_AUTH_FAILED 21 - -/* - * Debug macros. Slightly useful for finding bugs in pppd, not particularly - * useful for finding out why your connection isn't being established. - */ -#ifdef DEBUGALL -#define DEBUGMAIN 1 -#define DEBUGFSM 1 -#define DEBUGLCP 1 -#define DEBUGIPCP 1 -#define DEBUGIPV6CP 1 -#define DEBUGUPAP 1 -#define DEBUGCHAP 1 -#endif - -#ifndef LOG_PPP /* we use LOG_LOCAL2 for syslog by default */ -#if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUGSYS) \ - || defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) \ - || defined(DEBUGCHAP) || defined(DEBUG) || defined(DEBUGIPV6CP) -#define LOG_PPP LOG_LOCAL2 -#else -#define LOG_PPP LOG_DAEMON -#endif -#endif /* LOG_PPP */ - -#ifdef DEBUGMAIN -#define MAINDEBUG(x) if (debug) dbglog x -#else -#define MAINDEBUG(x) -#endif - -#ifdef DEBUGSYS -#define SYSDEBUG(x) if (debug) dbglog x -#else -#define SYSDEBUG(x) -#endif - -#ifdef DEBUGFSM -#define FSMDEBUG(x) if (debug) dbglog x -#else -#define FSMDEBUG(x) -#endif - -#ifdef DEBUGLCP -#define LCPDEBUG(x) if (debug) dbglog x -#else -#define LCPDEBUG(x) -#endif - -#ifdef DEBUGIPCP -#define IPCPDEBUG(x) if (debug) dbglog x -#else -#define IPCPDEBUG(x) -#endif - -#ifdef DEBUGIPV6CP -#define IPV6CPDEBUG(x) if (debug) dbglog x -#else -#define IPV6CPDEBUG(x) -#endif - -#ifdef DEBUGUPAP -#define UPAPDEBUG(x) if (debug) dbglog x -#else -#define UPAPDEBUG(x) -#endif - -#ifdef DEBUGCHAP -#define CHAPDEBUG(x) if (debug) dbglog x -#else -#define CHAPDEBUG(x) -#endif - -#ifdef DEBUGIPXCP -#define IPXCPDEBUG(x) if (debug) dbglog x -#else -#define IPXCPDEBUG(x) -#endif - -#ifndef SIGTYPE -#if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) -#define SIGTYPE void -#else -#define SIGTYPE int -#endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */ -#endif /* SIGTYPE */ - -#ifndef MIN -#define MIN(a, b) ((a) < (b)? (a): (b)) -#endif -#ifndef MAX -#define MAX(a, b) ((a) > (b)? (a): (b)) -#endif - -#ifndef offsetof -#define offsetof(type, member) ((size_t) &((type *)0)->member) -#endif - -#endif /* __PPP_H__ */ diff --git a/vpn-daemons/pptp/src/external/2.4.4b1/pppd/fsm.h b/vpn-daemons/pptp/src/external/2.4.4b1/pppd/fsm.h deleted file mode 100644 index f02473f2b0..0000000000 --- a/vpn-daemons/pptp/src/external/2.4.4b1/pppd/fsm.h +++ /dev/null @@ -1,168 +0,0 @@ -/* - * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions. - * - * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The name "Carnegie Mellon University" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For permission or any legal - * details, please contact - * Office of Technology Transfer - * Carnegie Mellon University - * 5000 Forbes Avenue - * Pittsburgh, PA 15213-3890 - * (412) 268-4387, fax: (412) 268-7395 - * tech-transfer@andrew.cmu.edu - * - * 4. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by Computing Services - * at Carnegie Mellon University (http://www.cmu.edu/computing/)." - * - * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE - * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN - * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * $Id$ - */ - -/* - * Packet header = Code, id, length. - */ -#define HEADERLEN 4 - - -/* - * CP (LCP, IPCP, etc.) codes. - */ -#define CONFREQ 1 /* Configuration Request */ -#define CONFACK 2 /* Configuration Ack */ -#define CONFNAK 3 /* Configuration Nak */ -#define CONFREJ 4 /* Configuration Reject */ -#define TERMREQ 5 /* Termination Request */ -#define TERMACK 6 /* Termination Ack */ -#define CODEREJ 7 /* Code Reject */ - - -/* - * Each FSM is described by an fsm structure and fsm callbacks. - */ -typedef struct fsm { - int unit; /* Interface unit number */ - int protocol; /* Data Link Layer Protocol field value */ - int state; /* State */ - int flags; /* Contains option bits */ - u_char id; /* Current id */ - u_char reqid; /* Current request id */ - u_char seen_ack; /* Have received valid Ack/Nak/Rej to Req */ - int timeouttime; /* Timeout time in milliseconds */ - int maxconfreqtransmits; /* Maximum Configure-Request transmissions */ - int retransmits; /* Number of retransmissions left */ - int maxtermtransmits; /* Maximum Terminate-Request transmissions */ - int nakloops; /* Number of nak loops since last ack */ - int rnakloops; /* Number of naks received */ - int maxnakloops; /* Maximum number of nak loops tolerated */ - struct fsm_callbacks *callbacks; /* Callback routines */ - char *term_reason; /* Reason for closing protocol */ - int term_reason_len; /* Length of term_reason */ -} fsm; - - -typedef struct fsm_callbacks { - void (*resetci) /* Reset our Configuration Information */ - __P((fsm *)); - int (*cilen) /* Length of our Configuration Information */ - __P((fsm *)); - void (*addci) /* Add our Configuration Information */ - __P((fsm *, u_char *, int *)); - int (*ackci) /* ACK our Configuration Information */ - __P((fsm *, u_char *, int)); - int (*nakci) /* NAK our Configuration Information */ - __P((fsm *, u_char *, int, int)); - int (*rejci) /* Reject our Configuration Information */ - __P((fsm *, u_char *, int)); - int (*reqci) /* Request peer's Configuration Information */ - __P((fsm *, u_char *, int *, int)); - void (*up) /* Called when fsm reaches OPENED state */ - __P((fsm *)); - void (*down) /* Called when fsm leaves OPENED state */ - __P((fsm *)); - void (*starting) /* Called when we want the lower layer */ - __P((fsm *)); - void (*finished) /* Called when we don't want the lower layer */ - __P((fsm *)); - void (*protreject) /* Called when Protocol-Reject received */ - __P((int)); - void (*retransmit) /* Retransmission is necessary */ - __P((fsm *)); - int (*extcode) /* Called when unknown code received */ - __P((fsm *, int, int, u_char *, int)); - char *proto_name; /* String name for protocol (for messages) */ -} fsm_callbacks; - - -/* - * Link states. - */ -#define INITIAL 0 /* Down, hasn't been opened */ -#define STARTING 1 /* Down, been opened */ -#define CLOSED 2 /* Up, hasn't been opened */ -#define STOPPED 3 /* Open, waiting for down event */ -#define CLOSING 4 /* Terminating the connection, not open */ -#define STOPPING 5 /* Terminating, but open */ -#define REQSENT 6 /* We've sent a Config Request */ -#define ACKRCVD 7 /* We've received a Config Ack */ -#define ACKSENT 8 /* We've sent a Config Ack */ -#define OPENED 9 /* Connection available */ - - -/* - * Flags - indicate options controlling FSM operation - */ -#define OPT_PASSIVE 1 /* Don't die if we don't get a response */ -#define OPT_RESTART 2 /* Treat 2nd OPEN as DOWN, UP */ -#define OPT_SILENT 4 /* Wait for peer to speak first */ - - -/* - * Timeouts. - */ -#define DEFTIMEOUT 3 /* Timeout time in seconds */ -#define DEFMAXTERMREQS 2 /* Maximum Terminate-Request transmissions */ -#define DEFMAXCONFREQS 10 /* Maximum Configure-Request transmissions */ -#define DEFMAXNAKLOOPS 5 /* Maximum number of nak loops */ - - -/* - * Prototypes - */ -void fsm_init __P((fsm *)); -void fsm_lowerup __P((fsm *)); -void fsm_lowerdown __P((fsm *)); -void fsm_open __P((fsm *)); -void fsm_close __P((fsm *, char *)); -void fsm_input __P((fsm *, u_char *, int)); -void fsm_protreject __P((fsm *)); -void fsm_sdata __P((fsm *, int, int, u_char *, int)); - - -/* - * Variables - */ -extern int peer_mru[]; /* currently negotiated peer MRU (per unit) */ diff --git a/vpn-daemons/pptp/src/external/2.4.4b1/pppd/ipcp.h b/vpn-daemons/pptp/src/external/2.4.4b1/pppd/ipcp.h deleted file mode 100644 index c0d3c85eb4..0000000000 --- a/vpn-daemons/pptp/src/external/2.4.4b1/pppd/ipcp.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * ipcp.h - IP Control Protocol definitions. - * - * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The name "Carnegie Mellon University" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For permission or any legal - * details, please contact - * Office of Technology Transfer - * Carnegie Mellon University - * 5000 Forbes Avenue - * Pittsburgh, PA 15213-3890 - * (412) 268-4387, fax: (412) 268-7395 - * tech-transfer@andrew.cmu.edu - * - * 4. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by Computing Services - * at Carnegie Mellon University (http://www.cmu.edu/computing/)." - * - * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE - * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN - * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * $Id$ - */ - -/* - * Options. - */ -#define CI_ADDRS 1 /* IP Addresses */ -#define CI_COMPRESSTYPE 2 /* Compression Type */ -#define CI_ADDR 3 - -#define CI_MS_DNS1 129 /* Primary DNS value */ -#define CI_MS_WINS1 130 /* Primary WINS value */ -#define CI_MS_DNS2 131 /* Secondary DNS value */ -#define CI_MS_WINS2 132 /* Secondary WINS value */ - -#define MAX_STATES 16 /* from slcompress.h */ - -#define IPCP_VJMODE_OLD 1 /* "old" mode (option # = 0x0037) */ -#define IPCP_VJMODE_RFC1172 2 /* "old-rfc"mode (option # = 0x002d) */ -#define IPCP_VJMODE_RFC1332 3 /* "new-rfc"mode (option # = 0x002d, */ - /* maxslot and slot number compression) */ - -#define IPCP_VJ_COMP 0x002d /* current value for VJ compression option*/ -#define IPCP_VJ_COMP_OLD 0x0037 /* "old" (i.e, broken) value for VJ */ - /* compression option*/ - -typedef struct ipcp_options { - bool neg_addr; /* Negotiate IP Address? */ - bool old_addrs; /* Use old (IP-Addresses) option? */ - bool req_addr; /* Ask peer to send IP address? */ - bool default_route; /* Assign default route through interface? */ - bool proxy_arp; /* Make proxy ARP entry for peer? */ - bool neg_vj; /* Van Jacobson Compression? */ - bool old_vj; /* use old (short) form of VJ option? */ - bool accept_local; /* accept peer's value for ouraddr */ - bool accept_remote; /* accept peer's value for hisaddr */ - bool req_dns1; /* Ask peer to send primary DNS address? */ - bool req_dns2; /* Ask peer to send secondary DNS address? */ - int vj_protocol; /* protocol value to use in VJ option */ - int maxslotindex; /* values for RFC1332 VJ compression neg. */ - bool cflag; - u_int32_t ouraddr, hisaddr; /* Addresses in NETWORK BYTE ORDER */ - u_int32_t dnsaddr[2]; /* Primary and secondary MS DNS entries */ - u_int32_t winsaddr[2]; /* Primary and secondary MS WINS entries */ -} ipcp_options; - -extern fsm ipcp_fsm[]; -extern ipcp_options ipcp_wantoptions[]; -extern ipcp_options ipcp_gotoptions[]; -extern ipcp_options ipcp_allowoptions[]; -extern ipcp_options ipcp_hisoptions[]; - -char *ip_ntoa __P((u_int32_t)); - -extern struct protent ipcp_protent; diff --git a/vpn-daemons/pptp/src/external/2.4.4b1/pppd/patchlevel.h b/vpn-daemons/pptp/src/external/2.4.4b1/pppd/patchlevel.h deleted file mode 100644 index 2f9e9d6c0f..0000000000 --- a/vpn-daemons/pptp/src/external/2.4.4b1/pppd/patchlevel.h +++ /dev/null @@ -1,4 +0,0 @@ -/* $Id$ */ - -#define VERSION "2.4.4b1" -#define DATE "28 August 2005" diff --git a/vpn-daemons/pptp/src/external/2.4.4b1/pppd/pppd.h b/vpn-daemons/pptp/src/external/2.4.4b1/pppd/pppd.h deleted file mode 100644 index 1168a26bb1..0000000000 --- a/vpn-daemons/pptp/src/external/2.4.4b1/pppd/pppd.h +++ /dev/null @@ -1,907 +0,0 @@ -/* - * pppd.h - PPP daemon global declarations. - * - * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The name "Carnegie Mellon University" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For permission or any legal - * details, please contact - * Office of Technology Transfer - * Carnegie Mellon University - * 5000 Forbes Avenue - * Pittsburgh, PA 15213-3890 - * (412) 268-4387, fax: (412) 268-7395 - * tech-transfer@andrew.cmu.edu - * - * 4. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by Computing Services - * at Carnegie Mellon University (http://www.cmu.edu/computing/)." - * - * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE - * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN - * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * $Id$ - */ - -/* - * TODO: - */ - -#ifndef __PPPD_H__ -#define __PPPD_H__ - -#include /* for FILE */ -#include /* for NGROUPS_MAX */ -#include /* for MAXPATHLEN and BSD4_4, if defined */ -#include /* for u_int32_t, if defined */ -#include /* for struct timeval */ -#include -#include "patchlevel.h" - -#if defined(__STDC__) -#include -#define __V(x) x -#else -#include -#define __V(x) (va_alist) va_dcl -#define const -#define volatile -#endif - -#ifdef INET6 -#include "eui64.h" -#endif - -/* - * Limits. - */ - -#define NUM_PPP 1 /* One PPP interface supported (per process) */ -#define MAXWORDLEN 1024 /* max length of word in file (incl null) */ -#define MAXARGS 1 /* max # args to a command */ -#define MAXNAMELEN 256 /* max length of hostname or name for auth */ -#define MAXSECRETLEN 256 /* max length of password or secret */ - -/* - * Option descriptor structure. - */ - -typedef unsigned char bool; - -enum opt_type { - o_special_noarg = 0, - o_special = 1, - o_bool, - o_int, - o_uint32, - o_string, - o_wild -}; - -typedef struct { - char *name; /* name of the option */ - enum opt_type type; - void *addr; - char *description; - unsigned int flags; - void *addr2; - int upper_limit; - int lower_limit; - const char *source; - short int priority; - short int winner; -} option_t; - -/* Values for flags */ -#define OPT_VALUE 0xff /* mask for presupplied value */ -#define OPT_HEX 0x100 /* int option is in hex */ -#define OPT_NOARG 0x200 /* option doesn't take argument */ -#define OPT_OR 0x400 /* OR in argument to value */ -#define OPT_INC 0x800 /* increment value */ -#define OPT_A2OR 0x800 /* for o_bool, OR arg to *(u_char *)addr2 */ -#define OPT_PRIV 0x1000 /* privileged option */ -#define OPT_STATIC 0x2000 /* string option goes into static array */ -#define OPT_LLIMIT 0x4000 /* check value against lower limit */ -#define OPT_ULIMIT 0x8000 /* check value against upper limit */ -#define OPT_LIMITS (OPT_LLIMIT|OPT_ULIMIT) -#define OPT_ZEROOK 0x10000 /* 0 value is OK even if not within limits */ -#define OPT_HIDE 0x10000 /* for o_string, print value as ?????? */ -#define OPT_A2LIST 0x10000 /* for o_special, keep list of values */ -#define OPT_A2CLRB 0x10000 /* o_bool, clr val bits in *(u_char *)addr2 */ -#define OPT_NOINCR 0x20000 /* value mustn't be increased */ -#define OPT_ZEROINF 0x40000 /* with OPT_NOINCR, 0 == infinity */ -#define OPT_PRIO 0x80000 /* process option priorities for this option */ -#define OPT_PRIOSUB 0x100000 /* subsidiary member of priority group */ -#define OPT_ALIAS 0x200000 /* option is alias for previous option */ -#define OPT_A2COPY 0x400000 /* addr2 -> second location to rcv value */ -#define OPT_ENABLE 0x800000 /* use *addr2 as enable for option */ -#define OPT_A2CLR 0x1000000 /* clear *(bool *)addr2 */ -#define OPT_PRIVFIX 0x2000000 /* user can't override if set by root */ -#define OPT_INITONLY 0x4000000 /* option can only be set in init phase */ -#define OPT_DEVEQUIV 0x8000000 /* equiv to device name */ -#define OPT_DEVNAM (OPT_INITONLY | OPT_DEVEQUIV) -#define OPT_A2PRINTER 0x10000000 /* *addr2 is a fn for printing option */ -#define OPT_A2STRVAL 0x20000000 /* *addr2 points to current string value */ -#define OPT_NOPRINT 0x40000000 /* don't print this option at all */ - -#define OPT_VAL(x) ((x) & OPT_VALUE) - -/* Values for priority */ -#define OPRIO_DEFAULT 0 /* a default value */ -#define OPRIO_CFGFILE 1 /* value from a configuration file */ -#define OPRIO_CMDLINE 2 /* value from the command line */ -#define OPRIO_SECFILE 3 /* value from options in a secrets file */ -#define OPRIO_ROOT 100 /* added to priority if OPT_PRIVFIX && root */ - -#ifndef GIDSET_TYPE -#define GIDSET_TYPE gid_t -#endif - -/* Structure representing a list of permitted IP addresses. */ -struct permitted_ip { - int permit; /* 1 = permit, 0 = forbid */ - u_int32_t base; /* match if (addr & mask) == base */ - u_int32_t mask; /* base and mask are in network byte order */ -}; - -/* - * Unfortunately, the linux kernel driver uses a different structure - * for statistics from the rest of the ports. - * This structure serves as a common representation for the bits - * pppd needs. - */ -struct pppd_stats { - unsigned int bytes_in; - unsigned int bytes_out; - unsigned int pkts_in; - unsigned int pkts_out; -}; - -/* Used for storing a sequence of words. Usually malloced. */ -struct wordlist { - struct wordlist *next; - char *word; -}; - -/* An endpoint discriminator, used with multilink. */ -#define MAX_ENDP_LEN 20 /* maximum length of discriminator value */ -struct epdisc { - unsigned char class; - unsigned char length; - unsigned char value[MAX_ENDP_LEN]; -}; - -/* values for epdisc.class */ -#define EPD_NULL 0 /* null discriminator, no data */ -#define EPD_LOCAL 1 -#define EPD_IP 2 -#define EPD_MAC 3 -#define EPD_MAGIC 4 -#define EPD_PHONENUM 5 - -typedef void (*notify_func) __P((void *, int)); - -struct notifier { - struct notifier *next; - notify_func func; - void *arg; -}; - -/* - * Global variables. - */ - -extern int hungup; /* Physical layer has disconnected */ -extern int ifunit; /* Interface unit number */ -extern char ifname[]; /* Interface name */ -extern char hostname[]; /* Our hostname */ -extern u_char outpacket_buf[]; /* Buffer for outgoing packets */ -extern int devfd; /* fd of underlying device */ -extern int fd_ppp; /* fd for talking PPP */ -extern int phase; /* Current state of link - see values below */ -extern int baud_rate; /* Current link speed in bits/sec */ -extern char *progname; /* Name of this program */ -extern int redirect_stderr;/* Connector's stderr should go to file */ -extern char peer_authname[];/* Authenticated name of peer */ -extern int auth_done[NUM_PPP]; /* Methods actually used for auth */ -extern int privileged; /* We were run by real-uid root */ -extern int need_holdoff; /* Need holdoff period after link terminates */ -extern char **script_env; /* Environment variables for scripts */ -extern int detached; /* Have detached from controlling tty */ -extern GIDSET_TYPE groups[NGROUPS_MAX]; /* groups the user is in */ -extern int ngroups; /* How many groups valid in groups */ -extern struct pppd_stats link_stats; /* byte/packet counts etc. for link */ -extern int link_stats_valid; /* set if link_stats is valid */ -extern unsigned link_connect_time; /* time the link was up for */ -extern int using_pty; /* using pty as device (notty or pty opt.) */ -extern int log_to_fd; /* logging to this fd as well as syslog */ -extern bool log_default; /* log_to_fd is default (stdout) */ -extern char *no_ppp_msg; /* message to print if ppp not in kernel */ -extern volatile int status; /* exit status for pppd */ -extern bool devnam_fixed; /* can no longer change devnam */ -extern int unsuccess; /* # unsuccessful connection attempts */ -extern int do_callback; /* set if we want to do callback next */ -extern int doing_callback; /* set if this is a callback */ -extern int error_count; /* # of times error() has been called */ -extern char ppp_devnam[MAXPATHLEN]; -extern char remote_number[MAXNAMELEN]; /* Remote telephone number, if avail. */ -extern int ppp_session_number; /* Session number (eg PPPoE session) */ -extern int fd_devnull; /* fd open to /dev/null */ - -extern int listen_time; /* time to listen first (ms) */ -extern bool doing_multilink; -extern bool multilink_master; -extern bool bundle_eof; -extern bool bundle_terminating; - -extern struct notifier *pidchange; /* for notifications of pid changing */ -extern struct notifier *phasechange; /* for notifications of phase changes */ -extern struct notifier *exitnotify; /* for notification that we're exiting */ -extern struct notifier *sigreceived; /* notification of received signal */ -extern struct notifier *ip_up_notifier; /* IPCP has come up */ -extern struct notifier *ip_down_notifier; /* IPCP has gone down */ -extern struct notifier *auth_up_notifier; /* peer has authenticated */ -extern struct notifier *link_down_notifier; /* link has gone down */ -extern struct notifier *fork_notifier; /* we are a new child process */ - -/* Values for do_callback and doing_callback */ -#define CALLBACK_DIALIN 1 /* we are expecting the call back */ -#define CALLBACK_DIALOUT 2 /* we are dialling out to call back */ - -/* - * Variables set by command-line options. - */ - -extern int debug; /* Debug flag */ -extern int kdebugflag; /* Tell kernel to print debug messages */ -extern int default_device; /* Using /dev/tty or equivalent */ -extern char devnam[MAXPATHLEN]; /* Device name */ -extern int crtscts; /* Use hardware flow control */ -extern bool modem; /* Use modem control lines */ -extern int inspeed; /* Input/Output speed requested */ -extern u_int32_t netmask; /* IP netmask to set on interface */ -extern bool lockflag; /* Create lock file to lock the serial dev */ -extern bool nodetach; /* Don't detach from controlling tty */ -extern bool updetach; /* Detach from controlling tty when link up */ -extern char *initializer; /* Script to initialize physical link */ -extern char *connect_script; /* Script to establish physical link */ -extern char *disconnect_script; /* Script to disestablish physical link */ -extern char *welcomer; /* Script to welcome client after connection */ -extern char *ptycommand; /* Command to run on other side of pty */ -extern int maxconnect; /* Maximum connect time (seconds) */ -extern char user[MAXNAMELEN];/* Our name for authenticating ourselves */ -extern char passwd[MAXSECRETLEN]; /* Password for PAP or CHAP */ -extern bool auth_required; /* Peer is required to authenticate */ -extern bool persist; /* Reopen link after it goes down */ -extern bool uselogin; /* Use /etc/passwd for checking PAP */ -extern char our_name[MAXNAMELEN];/* Our name for authentication purposes */ -extern char remote_name[MAXNAMELEN]; /* Peer's name for authentication */ -extern bool explicit_remote;/* remote_name specified with remotename opt */ -extern bool demand; /* Do dial-on-demand */ -extern char *ipparam; /* Extra parameter for ip up/down scripts */ -extern bool cryptpap; /* Others' PAP passwords are encrypted */ -extern int idle_time_limit;/* Shut down link if idle for this long */ -extern int holdoff; /* Dead time before restarting */ -extern bool holdoff_specified; /* true if user gave a holdoff value */ -extern bool notty; /* Stdin/out is not a tty */ -extern char *pty_socket; /* Socket to connect to pty */ -extern char *record_file; /* File to record chars sent/received */ -extern bool sync_serial; /* Device is synchronous serial device */ -extern int maxfail; /* Max # of unsuccessful connection attempts */ -extern char linkname[MAXPATHLEN]; /* logical name for link */ -extern bool tune_kernel; /* May alter kernel settings as necessary */ -extern int connect_delay; /* Time to delay after connect script */ -extern int max_data_rate; /* max bytes/sec through charshunt */ -extern int req_unit; /* interface unit number to use */ -extern bool multilink; /* enable multilink operation */ -extern bool noendpoint; /* don't send or accept endpt. discrim. */ -extern char *bundle_name; /* bundle name for multilink */ -extern bool dump_options; /* print out option values */ -extern bool dryrun; /* check everything, print options, exit */ -extern int child_wait; /* # seconds to wait for children at end */ - -#ifdef MAXOCTETS -extern unsigned int maxoctets; /* Maximum octetes per session (in bytes) */ -extern int maxoctets_dir; /* Direction : - 0 - in+out (default) - 1 - in - 2 - out - 3 - max(in,out) */ -extern int maxoctets_timeout; /* Timeout for check of octets limit */ -#define PPP_OCTETS_DIRECTION_SUM 0 -#define PPP_OCTETS_DIRECTION_IN 1 -#define PPP_OCTETS_DIRECTION_OUT 2 -#define PPP_OCTETS_DIRECTION_MAXOVERAL 3 -/* same as previos, but little different on RADIUS side */ -#define PPP_OCTETS_DIRECTION_MAXSESSION 4 -#endif - -#ifdef PPP_FILTER -extern struct bpf_program pass_filter; /* Filter for pkts to pass */ -extern struct bpf_program active_filter; /* Filter for link-active pkts */ -#endif - -#ifdef MSLANMAN -extern bool ms_lanman; /* Use LanMan password instead of NT */ - /* Has meaning only with MS-CHAP challenges */ -#endif - -/* Values for auth_pending, auth_done */ -#define PAP_WITHPEER 0x1 -#define PAP_PEER 0x2 -#define CHAP_WITHPEER 0x4 -#define CHAP_PEER 0x8 -#define EAP_WITHPEER 0x10 -#define EAP_PEER 0x20 - -/* Values for auth_done only */ -#define CHAP_MD5_WITHPEER 0x40 -#define CHAP_MD5_PEER 0x80 -#define CHAP_MS_SHIFT 8 /* LSB position for MS auths */ -#define CHAP_MS_WITHPEER 0x100 -#define CHAP_MS_PEER 0x200 -#define CHAP_MS2_WITHPEER 0x400 -#define CHAP_MS2_PEER 0x800 - -extern char *current_option; /* the name of the option being parsed */ -extern int privileged_option; /* set iff the current option came from root */ -extern char *option_source; /* string saying where the option came from */ -extern int option_priority; /* priority of current options */ - -/* - * Values for phase. - */ -#define PHASE_DEAD 0 -#define PHASE_INITIALIZE 1 -#define PHASE_SERIALCONN 2 -#define PHASE_DORMANT 3 -#define PHASE_ESTABLISH 4 -#define PHASE_AUTHENTICATE 5 -#define PHASE_CALLBACK 6 -#define PHASE_NETWORK 7 -#define PHASE_RUNNING 8 -#define PHASE_TERMINATE 9 -#define PHASE_DISCONNECT 10 -#define PHASE_HOLDOFF 11 -#define PHASE_MASTER 12 - -/* - * The following struct gives the addresses of procedures to call - * for a particular protocol. - */ -struct protent { - u_short protocol; /* PPP protocol number */ - /* Initialization procedure */ - void (*init) __P((int unit)); - /* Process a received packet */ - void (*input) __P((int unit, u_char *pkt, int len)); - /* Process a received protocol-reject */ - void (*protrej) __P((int unit)); - /* Lower layer has come up */ - void (*lowerup) __P((int unit)); - /* Lower layer has gone down */ - void (*lowerdown) __P((int unit)); - /* Open the protocol */ - void (*open) __P((int unit)); - /* Close the protocol */ - void (*close) __P((int unit, char *reason)); - /* Print a packet in readable form */ - int (*printpkt) __P((u_char *pkt, int len, - void (*printer) __P((void *, char *, ...)), - void *arg)); - /* Process a received data packet */ - void (*datainput) __P((int unit, u_char *pkt, int len)); - bool enabled_flag; /* 0 iff protocol is disabled */ - char *name; /* Text name of protocol */ - char *data_name; /* Text name of corresponding data protocol */ - option_t *options; /* List of command-line options */ - /* Check requested options, assign defaults */ - void (*check_options) __P((void)); - /* Configure interface for demand-dial */ - int (*demand_conf) __P((int unit)); - /* Say whether to bring up link for this pkt */ - int (*active_pkt) __P((u_char *pkt, int len)); -}; - -/* Table of pointers to supported protocols */ -extern struct protent *protocols[]; - -/* - * This struct contains pointers to a set of procedures for - * doing operations on a "channel". A channel provides a way - * to send and receive PPP packets - the canonical example is - * a serial port device in PPP line discipline (or equivalently - * with PPP STREAMS modules pushed onto it). - */ -struct channel { - /* set of options for this channel */ - option_t *options; - /* find and process a per-channel options file */ - void (*process_extra_options) __P((void)); - /* check all the options that have been given */ - void (*check_options) __P((void)); - /* get the channel ready to do PPP, return a file descriptor */ - int (*connect) __P((void)); - /* we're finished with the channel */ - void (*disconnect) __P((void)); - /* put the channel into PPP `mode' */ - int (*establish_ppp) __P((int)); - /* take the channel out of PPP `mode', restore loopback if demand */ - void (*disestablish_ppp) __P((int)); - /* set the transmit-side PPP parameters of the channel */ - void (*send_config) __P((int, u_int32_t, int, int)); - /* set the receive-side PPP parameters of the channel */ - void (*recv_config) __P((int, u_int32_t, int, int)); - /* cleanup on error or normal exit */ - void (*cleanup) __P((void)); - /* close the device, called in children after fork */ - void (*close) __P((void)); -}; - -extern struct channel *the_channel; - -/* - * Prototypes. - */ - -/* Procedures exported from main.c. */ -void set_ifunit __P((int)); /* set stuff that depends on ifunit */ -void detach __P((void)); /* Detach from controlling tty */ -void die __P((int)); /* Cleanup and exit */ -void quit __P((void)); /* like die(1) */ -void novm __P((char *)); /* Say we ran out of memory, and die */ -void timeout __P((void (*func)(void *), void *arg, int s, int us)); - /* Call func(arg) after s.us seconds */ -void untimeout __P((void (*func)(void *), void *arg)); - /* Cancel call to func(arg) */ -void record_child __P((int, char *, void (*) (void *), void *)); -pid_t safe_fork __P((int, int, int)); /* Fork & close stuff in child */ -int device_script __P((char *cmd, int in, int out, int dont_wait)); - /* Run `cmd' with given stdin and stdout */ -pid_t run_program __P((char *prog, char **args, int must_exist, - void (*done)(void *), void *arg, int wait)); - /* Run program prog with args in child */ -void reopen_log __P((void)); /* (re)open the connection to syslog */ -void print_link_stats __P((void)); /* Print stats, if available */ -void reset_link_stats __P((int)); /* Reset (init) stats when link goes up */ -void update_link_stats __P((int)); /* Get stats at link termination */ -void script_setenv __P((char *, char *, int)); /* set script env var */ -void script_unsetenv __P((char *)); /* unset script env var */ -void new_phase __P((int)); /* signal start of new phase */ -void add_notifier __P((struct notifier **, notify_func, void *)); -void remove_notifier __P((struct notifier **, notify_func, void *)); -void notify __P((struct notifier *, int)); -int ppp_send_config __P((int, int, u_int32_t, int, int)); -int ppp_recv_config __P((int, int, u_int32_t, int, int)); -const char *protocol_name __P((int)); -void remove_pidfiles __P((void)); -void lock_db __P((void)); -void unlock_db __P((void)); - -/* Procedures exported from tty.c. */ -void tty_init __P((void)); - -/* Procedures exported from utils.c. */ -void log_packet __P((u_char *, int, char *, int)); - /* Format a packet and log it with syslog */ -void print_string __P((char *, int, void (*) (void *, char *, ...), - void *)); /* Format a string for output */ -int slprintf __P((char *, int, char *, ...)); /* sprintf++ */ -int vslprintf __P((char *, int, char *, va_list)); /* vsprintf++ */ -size_t strlcpy __P((char *, const char *, size_t)); /* safe strcpy */ -size_t strlcat __P((char *, const char *, size_t)); /* safe strncpy */ -void dbglog __P((char *, ...)); /* log a debug message */ -void info __P((char *, ...)); /* log an informational message */ -void notice __P((char *, ...)); /* log a notice-level message */ -void warn __P((char *, ...)); /* log a warning message */ -void error __P((char *, ...)); /* log an error message */ -void fatal __P((char *, ...)); /* log an error message and die(1) */ -void init_pr_log __P((char *, int)); /* initialize for using pr_log */ -void pr_log __P((void *, char *, ...)); /* printer fn, output to syslog */ -void end_pr_log __P((void)); /* finish up after using pr_log */ -void dump_packet __P((const char *, u_char *, int)); - /* dump packet to debug log if interesting */ -ssize_t complete_read __P((int, void *, size_t)); - /* read a complete buffer */ - -/* Procedures exported from auth.c */ -void link_required __P((int)); /* we are starting to use the link */ -void start_link __P((int)); /* bring the link up now */ -void link_terminated __P((int)); /* we are finished with the link */ -void link_down __P((int)); /* the LCP layer has left the Opened state */ -void upper_layers_down __P((int));/* take all NCPs down */ -void link_established __P((int)); /* the link is up; authenticate now */ -void start_networks __P((int)); /* start all the network control protos */ -void continue_networks __P((int)); /* start network [ip, etc] control protos */ -void np_up __P((int, int)); /* a network protocol has come up */ -void np_down __P((int, int)); /* a network protocol has gone down */ -void np_finished __P((int, int)); /* a network protocol no longer needs link */ -void auth_peer_fail __P((int, int)); - /* peer failed to authenticate itself */ -void auth_peer_success __P((int, int, int, char *, int)); - /* peer successfully authenticated itself */ -void auth_withpeer_fail __P((int, int)); - /* we failed to authenticate ourselves */ -void auth_withpeer_success __P((int, int, int)); - /* we successfully authenticated ourselves */ -void auth_check_options __P((void)); - /* check authentication options supplied */ -void auth_reset __P((int)); /* check what secrets we have */ -int check_passwd __P((int, char *, int, char *, int, char **)); - /* Check peer-supplied username/password */ -int get_secret __P((int, char *, char *, char *, int *, int)); - /* get "secret" for chap */ -int get_srp_secret __P((int unit, char *client, char *server, char *secret, - int am_server)); -int auth_ip_addr __P((int, u_int32_t)); - /* check if IP address is authorized */ -int auth_number __P((void)); /* check if remote number is authorized */ -int bad_ip_adrs __P((u_int32_t)); - /* check if IP address is unreasonable */ - -/* Procedures exported from demand.c */ -void demand_conf __P((void)); /* config interface(s) for demand-dial */ -void demand_block __P((void)); /* set all NPs to queue up packets */ -void demand_unblock __P((void)); /* set all NPs to pass packets */ -void demand_discard __P((void)); /* set all NPs to discard packets */ -void demand_rexmit __P((int)); /* retransmit saved frames for an NP */ -int loop_chars __P((unsigned char *, int)); /* process chars from loopback */ -int loop_frame __P((unsigned char *, int)); /* should we bring link up? */ - -/* Procedures exported from multilink.c */ -#ifdef HAVE_MULTILINK -void mp_check_options __P((void)); /* Check multilink-related options */ -int mp_join_bundle __P((void)); /* join our link to an appropriate bundle */ -void mp_exit_bundle __P((void)); /* have disconnected our link from bundle */ -void mp_bundle_terminated __P((void)); -char *epdisc_to_str __P((struct epdisc *)); /* string from endpoint discrim. */ -int str_to_epdisc __P((struct epdisc *, char *)); /* endpt disc. from str */ -#else -#define mp_bundle_terminated() /* nothing */ -#define mp_exit_bundle() /* nothing */ -#define doing_multilink 0 -#define multilink_master 0 -#endif - -/* Procedures exported from sys-*.c */ -void sys_init __P((void)); /* Do system-dependent initialization */ -void sys_cleanup __P((void)); /* Restore system state before exiting */ -int sys_check_options __P((void)); /* Check options specified */ -void sys_close __P((void)); /* Clean up in a child before execing */ -int ppp_available __P((void)); /* Test whether ppp kernel support exists */ -int get_pty __P((int *, int *, char *, int)); /* Get pty master/slave */ -int open_ppp_loopback __P((void)); /* Open loopback for demand-dialling */ -int tty_establish_ppp __P((int)); /* Turn serial port into a ppp interface */ -void tty_disestablish_ppp __P((int)); /* Restore port to normal operation */ -void generic_disestablish_ppp __P((int dev_fd)); /* Restore device setting */ -int generic_establish_ppp __P((int dev_fd)); /* Make a ppp interface */ -void make_new_bundle __P((int, int, int, int)); /* Create new bundle */ -int bundle_attach __P((int)); /* Attach link to existing bundle */ -void cfg_bundle __P((int, int, int, int)); /* Configure existing bundle */ -void destroy_bundle __P((void)); /* Tell driver to destroy bundle */ -void clean_check __P((void)); /* Check if line was 8-bit clean */ -void set_up_tty __P((int, int)); /* Set up port's speed, parameters, etc. */ -void restore_tty __P((int)); /* Restore port's original parameters */ -void setdtr __P((int, int)); /* Raise or lower port's DTR line */ -void output __P((int, u_char *, int)); /* Output a PPP packet */ -void wait_input __P((struct timeval *)); - /* Wait for input, with timeout */ -void add_fd __P((int)); /* Add fd to set to wait for */ -void remove_fd __P((int)); /* Remove fd from set to wait for */ -int read_packet __P((u_char *)); /* Read PPP packet */ -int get_loop_output __P((void)); /* Read pkts from loopback */ -void tty_send_config __P((int, u_int32_t, int, int)); - /* Configure i/f transmit parameters */ -void tty_set_xaccm __P((ext_accm)); - /* Set extended transmit ACCM */ -void tty_recv_config __P((int, u_int32_t, int, int)); - /* Configure i/f receive parameters */ -int ccp_test __P((int, u_char *, int, int)); - /* Test support for compression scheme */ -void ccp_flags_set __P((int, int, int)); - /* Set kernel CCP state */ -int ccp_fatal_error __P((int)); /* Test for fatal decomp error in kernel */ -int get_idle_time __P((int, struct ppp_idle *)); - /* Find out how long link has been idle */ -int get_ppp_stats __P((int, struct pppd_stats *)); - /* Return link statistics */ -void netif_set_mtu __P((int, int)); /* Set PPP interface MTU */ -int netif_get_mtu __P((int)); /* Get PPP interface MTU */ -int sifvjcomp __P((int, int, int, int)); - /* Configure VJ TCP header compression */ -int sifup __P((int)); /* Configure i/f up for one protocol */ -int sifnpmode __P((int u, int proto, enum NPmode mode)); - /* Set mode for handling packets for proto */ -int sifdown __P((int)); /* Configure i/f down for one protocol */ -int sifaddr __P((int, u_int32_t, u_int32_t, u_int32_t)); - /* Configure IPv4 addresses for i/f */ -int cifaddr __P((int, u_int32_t, u_int32_t)); - /* Reset i/f IP addresses */ -#ifdef INET6 -int sif6addr __P((int, eui64_t, eui64_t)); - /* Configure IPv6 addresses for i/f */ -int cif6addr __P((int, eui64_t, eui64_t)); - /* Remove an IPv6 address from i/f */ -#endif -int sifdefaultroute __P((int, u_int32_t, u_int32_t)); - /* Create default route through i/f */ -int cifdefaultroute __P((int, u_int32_t, u_int32_t)); - /* Delete default route through i/f */ -int sifproxyarp __P((int, u_int32_t)); - /* Add proxy ARP entry for peer */ -int cifproxyarp __P((int, u_int32_t)); - /* Delete proxy ARP entry for peer */ -u_int32_t GetMask __P((u_int32_t)); /* Get appropriate netmask for address */ -int lock __P((char *)); /* Create lock file for device */ -int relock __P((int)); /* Rewrite lock file with new pid */ -void unlock __P((void)); /* Delete previously-created lock file */ -void logwtmp __P((const char *, const char *, const char *)); - /* Write entry to wtmp file */ -int get_host_seed __P((void)); /* Get host-dependent random number seed */ -int have_route_to __P((u_int32_t)); /* Check if route to addr exists */ -#ifdef PPP_FILTER -int set_filters __P((struct bpf_program *pass, struct bpf_program *active)); - /* Set filter programs in kernel */ -#endif -#ifdef IPX_CHANGE -int sipxfaddr __P((int, unsigned long, unsigned char *)); -int cipxfaddr __P((int)); -#endif -int get_if_hwaddr __P((u_char *addr, char *name)); -char *get_first_ethernet __P((void)); - -/* Procedures exported from options.c */ -int setipaddr __P((char *, char **, int)); /* Set local/remote ip addresses */ -int parse_args __P((int argc, char **argv)); - /* Parse options from arguments given */ -int options_from_file __P((char *filename, int must_exist, int check_prot, - int privileged)); - /* Parse options from an options file */ -int options_from_user __P((void)); /* Parse options from user's .ppprc */ -int options_for_tty __P((void)); /* Parse options from /etc/ppp/options.tty */ -int options_from_list __P((struct wordlist *, int privileged)); - /* Parse options from a wordlist */ -int getword __P((FILE *f, char *word, int *newlinep, char *filename)); - /* Read a word from a file */ -void option_error __P((char *fmt, ...)); - /* Print an error message about an option */ -int int_option __P((char *, int *)); - /* Simplified number_option for decimal ints */ -void add_options __P((option_t *)); /* Add extra options */ -void check_options __P((void)); /* check values after all options parsed */ -int override_value __P((const char *, int, const char *)); - /* override value if permitted by priority */ -void print_options __P((void (*) __P((void *, char *, ...)), void *)); - /* print out values of all options */ - -int parse_dotted_ip __P((char *, u_int32_t *)); - -/* - * Hooks to enable plugins to change various things. - */ -extern int (*new_phase_hook) __P((int)); -extern int (*idle_time_hook) __P((struct ppp_idle *)); -extern int (*holdoff_hook) __P((void)); -extern int (*pap_check_hook) __P((void)); -extern int (*pap_auth_hook) __P((char *user, char *passwd, char **msgp, - struct wordlist **paddrs, - struct wordlist **popts)); -extern void (*pap_logout_hook) __P((void)); -extern int (*pap_passwd_hook) __P((char *user, char *passwd)); -extern int (*allowed_address_hook) __P((u_int32_t addr)); -extern void (*ip_up_hook) __P((void)); -extern void (*ip_down_hook) __P((void)); -extern void (*ip_choose_hook) __P((u_int32_t *)); - -extern int (*chap_check_hook) __P((void)); -extern int (*chap_passwd_hook) __P((char *user, char *passwd)); - -/* Let a plugin snoop sent and received packets. Useful for L2TP */ -extern void (*snoop_recv_hook) __P((unsigned char *p, int len)); -extern void (*snoop_send_hook) __P((unsigned char *p, int len)); - -/* - * Inline versions of get/put char/short/long. - * Pointer is advanced; we assume that both arguments - * are lvalues and will already be in registers. - * cp MUST be u_char *. - */ -#define GETCHAR(c, cp) { \ - (c) = *(cp)++; \ -} -#define PUTCHAR(c, cp) { \ - *(cp)++ = (u_char) (c); \ -} - - -#define GETSHORT(s, cp) { \ - (s) = *(cp)++ << 8; \ - (s) |= *(cp)++; \ -} -#define PUTSHORT(s, cp) { \ - *(cp)++ = (u_char) ((s) >> 8); \ - *(cp)++ = (u_char) (s); \ -} - -#define GETLONG(l, cp) { \ - (l) = *(cp)++ << 8; \ - (l) |= *(cp)++; (l) <<= 8; \ - (l) |= *(cp)++; (l) <<= 8; \ - (l) |= *(cp)++; \ -} -#define PUTLONG(l, cp) { \ - *(cp)++ = (u_char) ((l) >> 24); \ - *(cp)++ = (u_char) ((l) >> 16); \ - *(cp)++ = (u_char) ((l) >> 8); \ - *(cp)++ = (u_char) (l); \ -} - -#define INCPTR(n, cp) ((cp) += (n)) -#define DECPTR(n, cp) ((cp) -= (n)) - -/* - * System dependent definitions for user-level 4.3BSD UNIX implementation. - */ - -#define TIMEOUT(r, f, t) timeout((r), (f), (t), 0) -#define UNTIMEOUT(r, f) untimeout((r), (f)) - -#define BCOPY(s, d, l) memcpy(d, s, l) -#define BZERO(s, n) memset(s, 0, n) -#define BCMP(s1, s2, l) memcmp(s1, s2, l) - -#define PRINTMSG(m, l) { info("Remote message: %0.*v", l, m); } - -/* - * MAKEHEADER - Add Header fields to a packet. - */ -#define MAKEHEADER(p, t) { \ - PUTCHAR(PPP_ALLSTATIONS, p); \ - PUTCHAR(PPP_UI, p); \ - PUTSHORT(t, p); } - -/* - * Exit status values. - */ -#define EXIT_OK 0 -#define EXIT_FATAL_ERROR 1 -#define EXIT_OPTION_ERROR 2 -#define EXIT_NOT_ROOT 3 -#define EXIT_NO_KERNEL_SUPPORT 4 -#define EXIT_USER_REQUEST 5 -#define EXIT_LOCK_FAILED 6 -#define EXIT_OPEN_FAILED 7 -#define EXIT_CONNECT_FAILED 8 -#define EXIT_PTYCMD_FAILED 9 -#define EXIT_NEGOTIATION_FAILED 10 -#define EXIT_PEER_AUTH_FAILED 11 -#define EXIT_IDLE_TIMEOUT 12 -#define EXIT_CONNECT_TIME 13 -#define EXIT_CALLBACK 14 -#define EXIT_PEER_DEAD 15 -#define EXIT_HANGUP 16 -#define EXIT_LOOPBACK 17 -#define EXIT_INIT_FAILED 18 -#define EXIT_AUTH_TOPEER_FAILED 19 -#ifdef MAXOCTETS -#define EXIT_TRAFFIC_LIMIT 20 -#endif -#define EXIT_CNID_AUTH_FAILED 21 - -/* - * Debug macros. Slightly useful for finding bugs in pppd, not particularly - * useful for finding out why your connection isn't being established. - */ -#ifdef DEBUGALL -#define DEBUGMAIN 1 -#define DEBUGFSM 1 -#define DEBUGLCP 1 -#define DEBUGIPCP 1 -#define DEBUGIPV6CP 1 -#define DEBUGUPAP 1 -#define DEBUGCHAP 1 -#endif - -#ifndef LOG_PPP /* we use LOG_LOCAL2 for syslog by default */ -#if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUGSYS) \ - || defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) \ - || defined(DEBUGCHAP) || defined(DEBUG) || defined(DEBUGIPV6CP) -#define LOG_PPP LOG_LOCAL2 -#else -#define LOG_PPP LOG_DAEMON -#endif -#endif /* LOG_PPP */ - -#ifdef DEBUGMAIN -#define MAINDEBUG(x) if (debug) dbglog x -#else -#define MAINDEBUG(x) -#endif - -#ifdef DEBUGSYS -#define SYSDEBUG(x) if (debug) dbglog x -#else -#define SYSDEBUG(x) -#endif - -#ifdef DEBUGFSM -#define FSMDEBUG(x) if (debug) dbglog x -#else -#define FSMDEBUG(x) -#endif - -#ifdef DEBUGLCP -#define LCPDEBUG(x) if (debug) dbglog x -#else -#define LCPDEBUG(x) -#endif - -#ifdef DEBUGIPCP -#define IPCPDEBUG(x) if (debug) dbglog x -#else -#define IPCPDEBUG(x) -#endif - -#ifdef DEBUGIPV6CP -#define IPV6CPDEBUG(x) if (debug) dbglog x -#else -#define IPV6CPDEBUG(x) -#endif - -#ifdef DEBUGUPAP -#define UPAPDEBUG(x) if (debug) dbglog x -#else -#define UPAPDEBUG(x) -#endif - -#ifdef DEBUGCHAP -#define CHAPDEBUG(x) if (debug) dbglog x -#else -#define CHAPDEBUG(x) -#endif - -#ifdef DEBUGIPXCP -#define IPXCPDEBUG(x) if (debug) dbglog x -#else -#define IPXCPDEBUG(x) -#endif - -#ifndef SIGTYPE -#if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) -#define SIGTYPE void -#else -#define SIGTYPE int -#endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */ -#endif /* SIGTYPE */ - -#ifndef MIN -#define MIN(a, b) ((a) < (b)? (a): (b)) -#endif -#ifndef MAX -#define MAX(a, b) ((a) > (b)? (a): (b)) -#endif - -#ifndef offsetof -#define offsetof(type, member) ((size_t) &((type *)0)->member) -#endif - -#endif /* __PPP_H__ */ diff --git a/vpn-daemons/pptp/src/nm-ppp-starter.c b/vpn-daemons/pptp/src/nm-ppp-starter.c deleted file mode 100644 index a699d2b8f4..0000000000 --- a/vpn-daemons/pptp/src/nm-ppp-starter.c +++ /dev/null @@ -1,1829 +0,0 @@ -/* nm-ppp-starter - pptp (and other ppp) integration with NetworkManager - * - * Antony J Mee - * Based on openvpn work by Tim Niemueller - * and Dan Williams - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "nm-ppp-starter.h" -#include "nm-utils.h" - -static const char *pptp_binary_paths[] = -{ - "/usr/sbin/pptp", - "/sbin/pptp", - NULL -}; - -static const char *chat_binary_paths[] = -{ - "/usr/sbin/chat", - "/sbin/chat", - NULL -}; - -static const char *pppd_binary_paths[] = -{ - "/usr/sbin/pppd", - "/sbin/pppd", - NULL -}; - -#define NM_PPP_HELPER_PATH "nm-pppd-plugin.so" - -typedef struct NmPPPData -{ - GMainLoop *loop; - DBusConnection *con; - NMVPNServiceState state; - GPid pid; - guint quit_timer; - guint helper_timer; - guint32 mtu; - char *str_ip4_vpn_gateway; - char *connection_type; - struct in_addr ip4_vpn_gateway; - char **auth_items; - int num_auth_items; - gboolean debug; -} NmPPPData; - - -static gboolean nm_ppp_dbus_handle_stop_vpn (NmPPPData *data); -static gboolean nm_ppp_store_auth_info (NmPPPData *data, - char **auth_items, int num_auth_items); - - -/* - * 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 VPN operation failed. - * - */ -static void nm_ppp_dbus_signal_failure (NmPPPData *data, const char *signal, const char *error_msg) -{ - DBusMessage *message; - const char *send_error_msg = NULL; - - g_return_if_fail (data != NULL); - g_return_if_fail (signal != NULL); - - // No sophisticated error message for now - if((send_error_msg=error_msg)==NULL) { - send_error_msg = _("VPN Connection failed"); - if (!send_error_msg) - return; - } - - if (!(message = dbus_message_new_signal (NM_DBUS_PATH_PPP_STARTER, NM_DBUS_INTERFACE_PPP_STARTER, signal))) - { - nm_warning ("Not enough memory for new dbus message!"); - return; - } - - dbus_message_append_args (message, DBUS_TYPE_STRING, &send_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, NMVPNServiceState old_state) -{ - DBusMessage *message; - - g_return_if_fail (data != NULL); - - if (!(message = dbus_message_new_signal (NM_DBUS_PATH_PPP_STARTER, NM_DBUS_INTERFACE_PPP_STARTER, NM_DBUS_VPN_SIGNAL_STATE_CHANGE))) - { - nm_warning ("nm_ppp_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); - - 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, NMVPNServiceState new_state) -{ - NMVPNServiceState old_state; - - g_return_if_fail (data != NULL); - - old_state = data->state; - - nm_info("PPP State change: %d -> %d",old_state,new_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-starter 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 pppd - * - */ -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_VPN_SIGNAL_CONNECT_FAILED, NULL); - nm_ppp_dbus_handle_stop_vpn (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 pppd - * - */ -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 (10000, (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); -} - -/* - * pppd_start_watch_cb - * - * Watch our child ppp process and get notified of events from it. - * - */ -static void pppd_start_watch_cb (GPid pid, gint status, gpointer user_data) -{ - guint error = -1; - - NmPPPData *data = (NmPPPData *)user_data; - nm_warning ("pppd_start_watch_cb: entered"); - - if (WIFEXITED (status)) - { - error = WEXITSTATUS (status); - if (error != 0) - nm_warning ("pppd exited with error code %d", error); - } - else if (WIFSTOPPED (status)) - nm_warning ("pppd stopped unexpectedly with signal %d", WSTOPSIG (status)); - else if (WIFSIGNALED (status)) - nm_warning ("pppd died with signal %d", WTERMSIG (status)); - else - nm_warning ("pppd 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 */ - switch (error) - { - case 0: /* No error... Let it keep going! */ - return; - case 2: /* Couldn't log in due to bad user/pass */ - nm_ppp_dbus_signal_failure (data, NM_DBUS_VPN_SIGNAL_LOGIN_FAILED,"Bad Username or Password"); - break; - - case 1: /* Other error (couldn't bind to address, etc) */ - nm_ppp_dbus_signal_failure (data, NM_DBUS_VPN_SIGNAL_CONNECT_FAILED,NULL); - break; - - default: /* Other error */ - nm_warning ("pppd exited with error code %d", error); - nm_ppp_dbus_signal_failure (data, NM_DBUS_VPN_SIGNAL_CONNECT_FAILED,"pppd dies with an unknown error code"); - break; - } - - nm_ppp_set_state (data, NM_VPN_SERVICE_STATE_STOPPED); - nm_ppp_schedule_quit_timer (data, 10000); -} - - -/* - * pppd_forked_watch_cb - * - * Watch our child ppp process and get notified of events from it. - * - */ -static void pppd_forked_watch_cb (GPid pid, gint status, gpointer user_data) -{ - guint error = -1; - - NmPPPData *data = (NmPPPData *)user_data; - nm_warning ("ppp_forked_watch_cb: entered"); - - 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 */ - switch (error) - { - case 2: /* Couldn't log in due to bad user/pass */ - nm_ppp_dbus_signal_failure (data, NM_DBUS_VPN_SIGNAL_LOGIN_FAILED,NULL); - break; - - case 1: /* Other error (couldn't bind to address, etc) */ - nm_ppp_dbus_signal_failure (data, NM_DBUS_VPN_SIGNAL_CONNECT_FAILED,NULL); - break; - - default: - break; - } - - switch (error) - { - case 0: /* No error... Let it keep going! */ - break; - case 2: /* Couldn't log in due to bad user/pass */ - nm_ppp_dbus_signal_failure (data, NM_DBUS_VPN_SIGNAL_LOGIN_FAILED,"Bad Username or Password"); - break; - - case 1: /* Other error (couldn't bind to address, etc) */ - nm_ppp_dbus_signal_failure (data, NM_DBUS_VPN_SIGNAL_CONNECT_FAILED,NULL); - break; - - default: /* Other error */ - nm_warning ("pppd exited with error code %d", error); - nm_ppp_dbus_signal_failure (data, NM_DBUS_VPN_SIGNAL_CONNECT_FAILED,"pppd dies with an unknown error code"); - break; - } - - - nm_ppp_set_state (data, NM_VPN_SERVICE_STATE_STOPPED); - nm_ppp_schedule_quit_timer (data, 10000); -} - -/* - * nm_ppp_get_cmdline_pptp - * - * Process and add to the pppd command line appropriately. - * - */ -static gint nm_ppp_get_cmdline_pptp (NmPPPData *data, char **data_items, const int num_items, GPtrArray *ppp_argv, GPtrArray *free_later) -{ - const char ** pptp_binary = NULL; - int i = 0; - struct hostent *hostinfo = NULL; - char * pppd_pty = NULL; - char buf[INET_ADDRSTRLEN+1]; - - memset (&buf, '\0', sizeof (buf)); - - /* Find pptp */ - pptp_binary = pptp_binary_paths; - while (*pptp_binary != NULL) { - if (g_file_test (*pptp_binary, G_FILE_TEST_EXISTS)) - break; - pptp_binary++; - } - - if (!*pptp_binary) { - nm_info ("Could not find pptp binary."); - return -1; - } - - // First ppp parameter is the PPTP server - for (i = 0; i < num_items; ++i) { - if ( strcmp( data_items[i], "pptp-remote" ) == 0) { - hostinfo = gethostbyname(data_items[++i]); - if (!hostinfo) { - nm_info ("Could not resolve IP address of VPN server."); - return -1; - } - data -> ip4_vpn_gateway = *(struct in_addr*)(hostinfo->h_addr_list[0]); - - if ( !inet_ntop (AF_INET, &data -> ip4_vpn_gateway, buf, INET_ADDRSTRLEN)) - data -> str_ip4_vpn_gateway = NULL; - data -> str_ip4_vpn_gateway = g_strdup( buf ); - - pppd_pty = g_strdup_printf ("%s %s --nolaunchpppd", (*pptp_binary), data->str_ip4_vpn_gateway); - - g_ptr_array_add (ppp_argv, (gpointer) "pty"); - g_ptr_array_add (ppp_argv, (gpointer) pppd_pty); - g_ptr_array_add (free_later, (gpointer) pppd_pty); - } - } -/* TODO: this pppd_pty should get freed somewhere */ -// g_free(pppd_pty); - - /* Process other pptp options */ - for (i = 0; i < num_items; ++i) { - if ( strcmp( data_items[i], "pptp-remote" ) == 0) { - g_ptr_array_add (ppp_argv, (gpointer) "remotename"); - g_ptr_array_add (ppp_argv, (gpointer) data_items[++i]); - } /* else if ( (strcmp( data_items[i], "ppp-lock" ) == 0) && - (strcmp( data_items[++i], "yes" ) == 0) ) { - g_ptr_array_add (ppp_argv, (gpointer) "lock"); - } */ - } - - return 0; -} - -/* - * nm_ppp_get_cmdline_dialup - * - * Process and add to the pppd command line appropriately. - * - */ -static gint nm_ppp_get_cmdline_dialup (NmPPPData *data, char **data_items, const int num_items, GPtrArray * ppp_argv, GPtrArray *free_later) -{ -// int i = 0; -// // First ppp parameter is the PPTP server -// for (i = 0; i < num_items; ++i) { -// if ( strcmp( data_items[i], "pptp-remote" ) == 0) { -// hostinfo = gethostbyname(data_items[++i]); -// if (!hostinfo) { -// nm_info ("Could not resolve IP address of VPN server."); -// return -1; -// } -// data -> ip4_vpn_gateway = *(struct in_addr*)(hostinfo->h_addr_list[0]); -// -// if ( !inet_ntop (AF_INET, &data -> ip4_vpn_gateway, buf, INET_ADDRSTRLEN)) -// data -> str_ip4_gateway = NULL; -// data -> str_ip4_vpn_gateway = g_strdup( buf ); -// -// pppd_pty = g_strdup_printf ("%s %s --nolaunchpppd", (*pptp_binary), data->str_ip4_vpn_gateway); -// -// g_ptr_array_add (ppp_argv, (gpointer) "pty"); -// g_ptr_array_add (ppp_argv, (gpointer) pppd_pty); -// } -// } -// -// /* Process other pptp options */ -// for (i = 0; i < num_items; ++i) { -// if ( strcmp( data_items[i], "pptp-remote" ) == 0) { -// g_ptr_array_add (ppp_argv, (gpointer) "remotename"); -// g_ptr_array_add (ppp_argv, (gpointer) data_items[++i]); -// } /* else if ( (strcmp( data_items[i], "ppp-lock" ) == 0) && -// (strcmp( data_items[++i], "yes" ) == 0) ) { -// g_ptr_array_add (ppp_argv, (gpointer) "lock"); -// } */ -// } - - return 0; -} - -/* - * nm_ppp_get_cmdline_btserial - * - * Process and add to the pppd command line appropriately. - * for a bluetooth serial connection - * - */ -static gint nm_ppp_get_cmdline_btserial (NmPPPData *data, char **data_items, const int num_items, GPtrArray *ppp_argv, GPtrArray *free_later) -{ - int i = 0; - char *bdaddr = NULL; - char *bdchannel=NULL; - - /* Based on BT GPRS instreuctions - * from http://www.linuxjournal.com/article/7525 */ - - /* Gather options */ - for (i = 0; i < num_items; ++i) { - if ( strcmp( data_items[i], "bt-bdaddr" ) == 0) { - bdaddr = data_items[++i]; - } else if ( strcmp( data_items[i], "bt-channel" ) == 0) { - bdchannel = data_items[++i]; - } - } - - /* TODO:Use BLueZ stack to open an RFCOMM channel - * see http://people.csail.mit.edu/albert/bluez-intro/x499.html - * and http://www.andybotting.com/mediawiki/index.php/Connecting_the_T610_to_Linux,_and_other_bluetooth_adventures */ - g_ptr_array_add (ppp_argv, (gpointer) "/dev/ttyGPRS"); -// g_ptr_array_add (ppp_argv, (gpointer) "115200"); - g_ptr_array_add (ppp_argv, (gpointer) "57600"); - - return 0; -} - -/* - * nm_ppp_get_cmdline_gprs - * - * Process and add to the pppd command line appropriately. - * - */ -static gint nm_ppp_get_cmdline_gprs (NmPPPData *data, char **data_items, const int num_items, GPtrArray * ppp_argv, GPtrArray *free_later) -{ - int i = 0; - const char *gprs_ip=NULL; - const char *gprs_apn=NULL; - const char *gprs_packet_type=NULL; - const char *gprs_context_num=NULL; - const char *connect_script=NULL; - const char ** chat_binary = NULL; - - /* Find chat */ - chat_binary = chat_binary_paths; - while (*chat_binary != NULL) { - if (g_file_test (*chat_binary, G_FILE_TEST_EXISTS)) - break; - chat_binary++; - } - - if (!*chat_binary) { - nm_info ("Could not find chat binary."); - return -1; - } - - /* Gather options */ - for (i = 0; i < num_items; ++i) { - if ( strcmp( data_items[i], "gprs-apn" ) == 0) { - gprs_apn = data_items[++i]; - } else if ( strcmp( data_items[i], "gprs-ip-address" ) == 0) { - gprs_ip = data_items[++i]; - } else if ( strcmp( data_items[i], "gprs-packet-type" ) == 0) { - gprs_packet_type = data_items[++i]; - } else if ( strcmp( data_items[i], "gprs-context-num" ) == 0) { - gprs_context_num = data_items[++i]; - } - } - - /* Build connect script */ -// connect_script = g_strdup_printf ( -// "%s -s -v \"\" AT+CGDCONT=%s,\"%s\",\"%s\",\"%s\",0,0 OK AT+CGDATA=\"PPP\",1", -// (*chat_binary), gprs_context_num, gprs_packet_type, gprs_apn, gprs_ip); - connect_script = g_strdup_printf ( - "%s -s -v " - "TIMEOUT 5 " - "ECHO ON " - "ABORT '\\nBUSY\\r' " - "ABORT '\\nERROR\\r' " - "ABORT '\\nNO ANSWER\\r' " - "ABORT '\\nNO CARRIER\\r' " - "ABORT '\\nNO DIALTONE\\r' " - "ABORT '\\nRINGING\\r\\n\\r\\nRINGING\\r' " - "'' \\rAT " - "TIMEOUT 12 " - "OK ATE1 " - "TIMEOUT 12 " - "TIMEOUT 12 " - "OK AT+cdgcont=%s,\"%s\",\"%s\" " - "OK ATD*99***1#" - "CONNECT", - (*chat_binary), gprs_context_num, gprs_packet_type, gprs_apn); - - /* TODO: Need to free connect_string somehow */ - g_ptr_array_add (ppp_argv, (gpointer) "connect"); - g_ptr_array_add (ppp_argv, (gpointer) connect_script); - g_ptr_array_add (free_later, (gpointer) connect_script); - - return 0; -} - -/* - * nm_ppp_get_cmdline_ppp - * - * Process and add to the pppd command line appropriately. - * - */ -static gint nm_ppp_get_cmdline_ppp (NmPPPData *data, char **data_items, const int num_items, GPtrArray * ppp_argv, GPtrArray *free_later) -{ - int i = 0; - char **extra_opts; - char **opt; - // Announce ourselves as NetworkManager to the ip-up/down scripts - g_ptr_array_add (ppp_argv, (gpointer) "ipparam"); - g_ptr_array_add (ppp_argv, (gpointer) "NetworkManager"); - - for (i = 0; i < num_items; ++i) { - if ( (strcmp( data_items[i], "ppp-lock" ) == 0) && - (strcmp( data_items[++i], "yes" ) == 0) ) { - g_ptr_array_add (ppp_argv, (gpointer) "lock"); - - } else if ( (strcmp( data_items[i], "ppp-auth-peer" ) == 0) && - (strcmp( data_items[++i], "no" ) == 0) ) { - g_ptr_array_add (ppp_argv, (gpointer) "noauth"); - - } else if ( (strcmp( data_items[i], "ppp-refuse-eap" ) == 0) && - (strcmp( data_items[++i], "yes" ) == 0) ) { - g_ptr_array_add (ppp_argv, (gpointer) "refuse-eap"); - - } else if ( (strcmp( data_items[i], "ppp-refuse-chap" ) == 0) && - (strcmp( data_items[++i], "yes" ) == 0) ) { - g_ptr_array_add (ppp_argv, (gpointer) "refuse-chap"); - - } else if ( (strcmp( data_items[i], "ppp-refuse-mschap" ) == 0) && - (strcmp( data_items[++i], "yes" ) == 0) ) { - g_ptr_array_add (ppp_argv, (gpointer) "refuse-mschap"); - - } else if ( (strcmp( data_items[i], "compress-bsd" ) == 0) && - (strcmp( data_items[++i], "no" ) == 0) ) { - g_ptr_array_add (ppp_argv, (gpointer) "nobsdcomp"); - - } else if ( (strcmp( data_items[i], "compress-deflate" ) == 0) && - (strcmp( data_items[++i], "no" ) == 0) ) { - g_ptr_array_add (ppp_argv, (gpointer) "nodeflate"); - - } else if ( (strcmp( data_items[i], "mru" ) == 0) && - (strlen( data_items[++i] ) > 0) ) { - g_ptr_array_add (ppp_argv, (gpointer) "mru"); - g_ptr_array_add (ppp_argv, (gpointer) data_items[i]); - - } else if ( (strcmp( data_items[i], "mtu" ) == 0) && - (strlen( data_items[++i] ) > 0) ) { - g_ptr_array_add (ppp_argv, (gpointer) "mtu"); - g_ptr_array_add (ppp_argv, (gpointer) data_items[i]); -// Set the mtu value for return to NM. -// (Subtract 4 for PPP header) - data->mtu=atoi(data_items[i])-4; - - } else if ( (strcmp( data_items[i], "lcp-echo-failure" ) == 0) && - (strlen( data_items[++i] ) > 0) ) { - g_ptr_array_add (ppp_argv, (gpointer) "lcp-echo-failure"); - g_ptr_array_add (ppp_argv, (gpointer) data_items[i]); - - } else if ( (strcmp( data_items[i], "lcp-echo-interval" ) == 0) && - (strlen( data_items[++i] ) > 0) ) { - g_ptr_array_add (ppp_argv, (gpointer) "lcp-echo-interval"); - g_ptr_array_add (ppp_argv, (gpointer) data_items[i]); - - } else if ( (strcmp( data_items[i], "encrypt-mppe" ) == 0) && - (strcmp( data_items[++i], "yes" ) == 0) ) { - g_ptr_array_add (ppp_argv, (gpointer) "require-mppe"); - - } else if ( (strcmp( data_items[i], "encrypt-mppe-128" ) == 0) && - (strcmp( data_items[++i], "yes" ) == 0) ) { - g_ptr_array_add (ppp_argv, (gpointer) "require-mppe-128"); - - } else if ( (strcmp( data_items[i], "encrypt-mppe-stateful" ) == 0) && - (strcmp( data_items[++i], "yes" ) == 0) ) { - g_ptr_array_add (ppp_argv, (gpointer) "mppe-stateful"); - - } else if ( (strcmp( data_items[i], "compress-mppc" ) == 0) && - (strcmp( data_items[++i], "yes" ) == 0) ) { - g_ptr_array_add (ppp_argv, (gpointer) "require-mppc"); - - } else if ( (strcmp( data_items[i], "ppp-modem" ) == 0) && - (strcmp( data_items[++i], "yes" ) == 0) ) { - g_ptr_array_add (ppp_argv, (gpointer) "modem"); - - } else if ( (strcmp( data_items[i], "ppp-crtscts" ) == 0) && - (strcmp( data_items[++i], "yes" ) == 0) ) { - g_ptr_array_add (ppp_argv, (gpointer) "crtscts"); - - } else if ( (strcmp( data_items[i], "ppp-connect" ) == 0) && - (strcmp( data_items[++i], "yes" ) == 0) ) { - g_ptr_array_add (ppp_argv, (gpointer) "crtscts"); - - } else if ( (strcmp( data_items[i], "usepeerdns" ) == 0) && - (strcmp( data_items[++i], "yes" ) == 0) ) { - g_ptr_array_add (ppp_argv, (gpointer) "usepeerdns"); -// -// } else if ( (strcmp( data_items[i], "usepeerdns-overtunnel" ) == 0) && -// (strcmp( data_items[++i], "yes" ) != 0) ) { -// g_ptr_array_add (ppp_argv, (gpointer) "usepeeddns-overtunnel"); - - } else if ( strcmp( data_items[i], "ppp-extra" ) == 0 ) { - extra_opts=g_strsplit(data_items[++i]," ",-1); - for (opt=extra_opts; *opt !=NULL; opt++) { - char *opt_copy = g_strdup(*opt); - g_ptr_array_add (ppp_argv, (gpointer) opt_copy); - g_ptr_array_add (free_later, (gpointer) opt_copy); - } - g_strfreev(extra_opts); -// } else if ( (strcmp( data_items[i], "usepeerdns-overtunnel" ) == 0) && -// (strcmp( data_items[++i], "yes" ) != 0) ) { -// g_ptr_array_add (ppp_argv, (gpointer) "usepeeddns-overtunnel"); - - } else if ( (strcmp( data_items[i], "ppp-debug" ) == 0) && - (strcmp( data_items[++i], "yes" ) == 0) ) { - data->debug=TRUE; - } - } - - /* Add this here in case debug has been flagged by other means */ - if (data->debug) g_ptr_array_add (ppp_argv, (gpointer) "debug"); - - g_ptr_array_add (ppp_argv, (gpointer) "plugin"); - g_ptr_array_add (ppp_argv, (gpointer) NM_PPP_HELPER_PATH); - - return 0; -} - -/* - * nm_pptp_child_setup - * - * Set the process group ID of the newly forked process - * - */ -void nm_pptp_child_setup (gpointer user_data G_GNUC_UNUSED) -{ - /* We are in the child process at this point */ - pid_t pid = getpid (); - setpgid (pid, pid); -} - -/* - * nm_ppp_start_vpn_binary - * - * Start the ppp binary with a set of arguments and a config file. - * - */ -static gint nm_ppp_start_ppp_binary (NmPPPData *data, char **data_items, const int num_items) -{ - GPid pid; - const char ** pppd_binary = NULL; - GPtrArray * ppp_argv; - GPtrArray * free_later; - GError * error = NULL; - gint stdin_fd = -1; - GSource * pppd_watch; - char * cmdline = NULL; - - g_return_val_if_fail (data != NULL, -1); - - data->pid = 0; - - if ( (num_items == 0) || (data_items == NULL) ) { - return -1; - } - - /* Find pppd */ - pppd_binary = pppd_binary_paths; - while (*pppd_binary != NULL) { - if (g_file_test (*pppd_binary, G_FILE_TEST_EXISTS)) - break; - pppd_binary++; - } - - if (!*pppd_binary) { - nm_info ("Could not find pppd binary."); - return -1; - } - - free_later = g_ptr_array_new (); - ppp_argv = g_ptr_array_new (); - g_ptr_array_add (ppp_argv, (gpointer) (*pppd_binary)); - - if (strcmp("pptp",data->connection_type)==0) { - nm_ppp_get_cmdline_pptp(data,data_items,num_items,ppp_argv,free_later); - } else if (strcmp("dialup",data->connection_type)==0) { - nm_ppp_get_cmdline_dialup(data,data_items,num_items,ppp_argv,free_later); - } else if (strcmp("btgprs",data->connection_type)==0) { - nm_ppp_get_cmdline_btserial(data,data_items,num_items,ppp_argv,free_later); - nm_ppp_get_cmdline_gprs(data,data_items,num_items,ppp_argv,free_later); - } else { - nm_warning("nm-ppp-starter: ppp-connection-type '%s' unknown",data->connection_type); - } - - nm_ppp_get_cmdline_ppp(data,data_items,num_items,ppp_argv,free_later); - - g_ptr_array_add (ppp_argv, NULL); - - if (data->debug) - { - cmdline=g_strjoinv(" ",(char **) ppp_argv->pdata); - nm_info("Running pppd with commandline:\n '%s'",cmdline); - g_free(cmdline); - } - - if (!g_spawn_async_with_pipes (NULL, (char **) ppp_argv->pdata, NULL, - G_SPAWN_DO_NOT_REAP_CHILD, &nm_pptp_child_setup, NULL, &pid, &stdin_fd, - NULL, NULL, &error)) - { - g_ptr_array_foreach(free_later,(GFunc)g_free,NULL); - g_ptr_array_free (free_later, TRUE); - g_ptr_array_free (ppp_argv, TRUE); - nm_warning ("pppd failed to start. error: '%s'", error->message); - g_error_free(error); - return -1; - } - g_ptr_array_foreach(free_later,(GFunc)g_free,NULL); - g_ptr_array_free (free_later, TRUE); - g_ptr_array_free (ppp_argv, TRUE); - - pppd_watch = g_child_watch_source_new (pid); - g_source_set_callback (pppd_watch, (GSourceFunc) pppd_start_watch_cb, data, NULL); - g_source_attach (pppd_watch, NULL); - g_source_unref (pppd_watch); - - return stdin_fd; -} - - -typedef enum OptType -{ - OPT_TYPE_UNKNOWN = 0, - OPT_TYPE_ADDRESS, - OPT_TYPE_ASCII, - OPT_TYPE_PPP_EXTRA, - OPT_TYPE_NONE -} OptType; - -typedef struct Option -{ - const char *name; - OptType type; -} Option; - -typedef struct PPPOption -{ - const char *name; - unsigned int nparams; -} PPPOption; - -/* - * nm_ppp_config_options_validate - * - * Make sure the config options are sane - * - */ -static gboolean nm_ppp_config_options_validate (NmPPPData *data, char **data_items, int num_items) -{ - Option allowed_opts[] = { - { "ppp-connection-type", OPT_TYPE_ASCII }, - { "pptp-remote", OPT_TYPE_ADDRESS }, - { "phone-number", OPT_TYPE_ADDRESS }, - { "usepeerdns", OPT_TYPE_ASCII }, - { "usepeerdns-overtunnel", OPT_TYPE_ASCII }, - { "compress-mppc", OPT_TYPE_ASCII }, - { "compress-bsd", OPT_TYPE_ASCII }, - { "compress-deflate", OPT_TYPE_ASCII }, - { "encrypt-mppe", OPT_TYPE_ASCII }, - { "encrypt-mppe-128", OPT_TYPE_ASCII }, - { "encrypt-mppe-stateful", OPT_TYPE_ASCII }, - { "ppp-auth-peer", OPT_TYPE_ASCII }, - { "ppp-refuse-eap", OPT_TYPE_ASCII }, - { "ppp-refuse-chap", OPT_TYPE_ASCII }, - { "ppp-refuse-mschap", OPT_TYPE_ASCII }, - { "ppp-lock", OPT_TYPE_ASCII }, - { "mtu", OPT_TYPE_ASCII }, - { "mru", OPT_TYPE_ASCII }, - { "lcp-echo-failure", OPT_TYPE_ASCII }, - { "lcp-echo-interval", OPT_TYPE_ASCII }, - { "ppp-debug", OPT_TYPE_ASCII }, - { "use-routes", OPT_TYPE_ASCII }, - { "routes", OPT_TYPE_ASCII }, - { "ppp-crtscts", OPT_TYPE_ASCII }, - { "ppp-noipdefault", OPT_TYPE_ASCII }, - { "ppp-connect-delay", OPT_TYPE_ASCII }, - { "ppp-modem", OPT_TYPE_ASCII }, - { "ppp-extra", OPT_TYPE_PPP_EXTRA }, - { "bt-bdaddr", OPT_TYPE_ASCII }, - { "bt-channel", OPT_TYPE_ASCII }, - { "gprs-packet-type", OPT_TYPE_ASCII }, - { "gprs-apn", OPT_TYPE_ASCII }, - { "gprs-ip-address", OPT_TYPE_ASCII }, - { "gprs-context-num", OPT_TYPE_ASCII }, - { NULL, OPT_TYPE_UNKNOWN } }; - - PPPOption allowed_extra_ppp_opts[] = { - { "mppe-stateful", 0 }, - { "require-mppe-128", 0 }, - { "refuse-eap", 0 }, - { "refuse-chap", 0 }, - { "refuse-mschap", 0 }, - { NULL, 0 } }; - - 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 VPN config options was not even."); - return FALSE; - } - - if (data->connection_type!=NULL) g_free(data->connection_type); - for (i = 0; i < num_items; ++i) { - if ( strcmp( data_items[i], "ppp-connection-type" ) == 0) { - data->connection_type=g_strdup(data_items[++i]); - break; - } - } - if (data->connection_type==NULL) return FALSE; - - /* TODO: Need to add some different sections based on the connection_type */ - - for (i = 0; i < num_items; i += 2) - { - Option *opt = NULL; - unsigned int t, len; - char *opt_value; - char **extra_opts = NULL; - PPPOption *allowed = NULL; - char **extra_opt = NULL; - - 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])==0)) - break; - } - if (!opt->name) /* not found */ - { - nm_warning ("VPN 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 VPN 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_PPP_EXTRA: - - /* Can be any a string containing any of the options in the allowed list */ - extra_opts=g_strsplit(opt_value," ",-1); - /* Loop over the extra options */ - for (extra_opt=extra_opts; *extra_opt != NULL; extra_opt++) { - unsigned int j; - for (j = 0; j < sizeof (allowed_extra_ppp_opts) / sizeof (PPPOption); j++) - { - allowed = &allowed_extra_ppp_opts[j]; - if (allowed->name && (strcmp(*extra_opt,allowed->name)==0)) { - extra_opt+=allowed->nparams; - break; - } - } - if (!allowed->name) { - nm_warning ("The extra ppp option '%s' is not in the allowed list.", *extra_opt); - g_strfreev(extra_opts); - return FALSE; - } - } - g_strfreev(extra_opts); - break; - - default: - return FALSE; - break; - } - } - - return TRUE; -} - -/* - * nm_ppp_store_auth_info - * - * Decode and temporarily store the authentication info provided. - * - */ -static gboolean nm_ppp_store_auth_info (NmPPPData *data, - char **auth_items, int num_auth_items) -{ - int i; -// nm_warning("nm_ppp_store_auth_info: enter"); - g_return_val_if_fail (data != NULL, FALSE); - g_return_val_if_fail (auth_items != NULL, FALSE); - g_return_val_if_fail (num_auth_items >= 1, FALSE); - - data->auth_items = (char **)g_new0(char *, num_auth_items+1); - g_return_val_if_fail (data->auth_items != NULL, FALSE); - - for (i=0;iauth_items[i]=g_strdup(auth_items[i]); - if ((data->auth_items=g_strdupv(auth_items))==NULL) { - for (--i;i>=0;i--) { - g_free(data->auth_items[i]); - } - g_free(data->auth_items); - data->num_auth_items=-1; - return FALSE; - } - } - data->num_auth_items=num_auth_items; - - return TRUE; -} - -/* - * nm_ppp_dbus_handle_start_vpn - * - * Parse message arguments and start the VPN connection. - * - */ -static gboolean nm_ppp_dbus_handle_start_vpn (DBusMessage *message, NmPPPData *data) -{ - char ** data_items = NULL; - int num_items = -1; - char ** auth_items = NULL; - int num_auth_items = -1; - char ** user_routes = NULL; - int user_routes_count = -1; - const char * name = NULL; - const char * user_name = NULL; - DBusError error; - gboolean success = FALSE; - gint pppd_fd = -1; - - g_return_val_if_fail (message != NULL, FALSE); - g_return_val_if_fail (data != NULL, FALSE); - - nm_ppp_set_state (data, NM_VPN_SERVICE_STATE_STARTING); - - dbus_error_init (&error); - if (!dbus_message_get_args (message, &error, - DBUS_TYPE_STRING, &name, - DBUS_TYPE_STRING, &user_name, - 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)) - { - 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_VPN_SIGNAL_VPN_CONFIG_BAD,"NM made an invalid DBUS request"); - dbus_error_free (&error); - goto out; - } - - if (!nm_ppp_config_options_validate (data, data_items, num_items)) - { - nm_ppp_dbus_signal_failure (data, NM_DBUS_VPN_SIGNAL_VPN_CONFIG_BAD, - "Validating options failed"); - goto out; - } - - if (!nm_ppp_store_auth_info (data, auth_items, num_auth_items)) - { - nm_ppp_dbus_signal_failure (data, NM_DBUS_VPN_SIGNAL_LOGIN_FAILED, - "Could not store authentication information correctly"); - goto out; - } - - /* Now we can finally try to activate the VPN */ - if ( (pppd_fd=nm_ppp_start_ppp_binary (data, data_items, num_items)) >= 0) - { - success = TRUE; - } - -out: - dbus_free_string_array (data_items); - dbus_free_string_array (auth_items); - dbus_free_string_array (user_routes); - if (!success) - nm_ppp_set_state (data, NM_VPN_SERVICE_STATE_STOPPED); - return success; -} - - -/* - * nm_ppp_dbus_handle_stop_vpn - * - * Stop the running pppd dameon. - * - */ -static gboolean nm_ppp_dbus_handle_stop_vpn (NmPPPData *data) -{ - g_return_val_if_fail (data != NULL, FALSE); - - if (data->pid > 0) - { - nm_ppp_set_state (data, NM_VPN_SERVICE_STATE_STOPPING); - - kill (data->pid, SIGTERM); - nm_info ("Terminated pppd with PID %d.", data->pid); - data->pid = 0; - - nm_ppp_set_state (data, NM_VPN_SERVICE_STATE_STOPPED); - nm_ppp_schedule_quit_timer (data, 10000); - } - - return TRUE; -} - -/* - * nm_ppp_dbus_handle_chap_check - * - * Stop the running pppd dameon. - * - */ -/* static gboolean nm_ppp_dbus_handle_chap_check (NmPPPData *data) -{ - g_return_val_if_fail (data != NULL, FALSE); - - if (data->pid > 0) - { - nm_ppp_set_state (data, NM_VPN_SERVICE_STATE_STOPPING); - - kill (data->pid, SIGTERM); - nm_info ("Terminated pppd with PID %d.", data->pid); - data->pid = 0; - - nm_ppp_set_state (data, NM_VPN_SERVICE_STATE_STOPPED); - nm_ppp_schedule_quit_timer (data, 10000); - } - - return TRUE; -} */ - - -/* - * nm_ppp_dbus_start_vpn - * - * Begin a VPN connection. - * - */ -static DBusMessage *nm_ppp_dbus_start_vpn (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_VPN_SERVICE_STATE_STARTING: - reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE_PPP_STARTER, NM_DBUS_VPN_STARTING_IN_PROGRESS, - "Could not process the request because the VPN connection is already being started."); - break; - - case NM_VPN_SERVICE_STATE_STARTED: - reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE_PPP_STARTER, NM_DBUS_VPN_ALREADY_STARTED, - "Could not process the request because a VPN connection was already active."); - break; - - case NM_VPN_SERVICE_STATE_STOPPING: - reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE_PPP_STARTER, NM_DBUS_VPN_STOPPING_IN_PROGRESS, - "Could not process the request because the VPN connection is being stopped."); - break; - - case NM_VPN_SERVICE_STATE_STOPPED: - nm_ppp_cancel_quit_timer (data); - nm_ppp_dbus_handle_start_vpn (message, data); - reply = dbus_message_new_method_return (message); - break; - - default: - g_assert_not_reached(); - break; - } - - return reply; -} - - -/* - * nm_ppp_dbus_stop_vpn - * - * Terminate a VPN connection. - * - */ -static DBusMessage *nm_ppp_dbus_stop_vpn (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_VPN_SERVICE_STATE_STOPPING: - reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE_PPP_STARTER, NM_DBUS_VPN_STOPPING_IN_PROGRESS, - "Could not process the request because the VPN connection is already being stopped."); - break; - - case NM_VPN_SERVICE_STATE_STOPPED: - reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE_PPP_STARTER, NM_DBUS_VPN_ALREADY_STOPPED, - "Could not process the request because no VPN connection was active."); - break; - - case NM_VPN_SERVICE_STATE_STARTING: - case NM_VPN_SERVICE_STATE_STARTED: - nm_ppp_dbus_handle_stop_vpn (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_notify_pid - * - * Receive the pid of the PPPD process from the PPPD plugin. - * - */ -static void nm_ppp_dbus_notify_pid (DBusConnection *con, DBusMessage *message, NmPPPData *data) -{ - GSource * pppd_watch; - - g_return_if_fail (data != NULL); - g_return_if_fail (con != NULL); - g_return_if_fail (message != NULL); - - if(!dbus_message_get_args (message, NULL, - DBUS_TYPE_UINT32, &(data->pid), - DBUS_TYPE_INVALID)) { - nm_warning ("PPPD plugin did not send a valid process ID"); - return; - } - - nm_info ("nm-ppp-starter: pppd spawned pid %d", data->pid); - - pppd_watch = g_child_watch_source_new (data->pid); - g_source_set_callback (pppd_watch, (GSourceFunc) pppd_forked_watch_cb, data, NULL); - g_source_attach (pppd_watch, NULL); - g_source_unref (pppd_watch); - - nm_ppp_schedule_helper_timer (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->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); - - 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 "); - - 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_VPN_SERVICE_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 pppd. It is missing '%s'.", error_item); - nm_ppp_dbus_signal_failure (data, NM_DBUS_VPN_SIGNAL_IP_CONFIG_BAD, NULL); - } - - nm_ppp_cancel_helper_timer (data); - nm_ppp_dbus_handle_stop_vpn (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) -{ - guint32 ip4_vpn_gateway; - char * tundev; - guint32 ip4_address; - guint32 ip4_ptp_address; - guint32 ip4_netmask; - guint32 * ip4_dns = NULL; - guint32 ip4_dns_len; - guint32 ip4_dns1; - guint32 ip4_dns2; - guint32 * ip4_nbns = NULL; - guint32 ip4_nbns_len; - guint32 ip4_nbns1; - guint32 ip4_nbns2; - guint32 mtu; - guint32 mss; - gboolean success = FALSE; - DBusMessageIter iter, iter_dict; - - - 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_VPN_SERVICE_STATE_STARTING) - return; - - /* If IP is up then we don't need to leave the auth info lying around */ - - if (data->auth_items) - g_strfreev (data->auth_items); - data->auth_items = NULL; - data->num_auth_items=-1; - - nm_ppp_cancel_helper_timer (data); - - if (dbus_message_get_args(message, NULL, - DBUS_TYPE_STRING, &tundev, - DBUS_TYPE_UINT32, &ip4_address, - DBUS_TYPE_UINT32, &ip4_ptp_address, - DBUS_TYPE_UINT32, &ip4_netmask, - DBUS_TYPE_UINT32, &ip4_dns1, - DBUS_TYPE_UINT32, &ip4_dns2, - DBUS_TYPE_UINT32, &ip4_dns_len, - DBUS_TYPE_UINT32, &ip4_nbns1, - DBUS_TYPE_UINT32, &ip4_nbns2, - DBUS_TYPE_UINT32, &ip4_nbns_len, -// 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)) - { - DBusMessage *signal; - - if (ip4_dns_len) { - ip4_dns = g_new0(guint32, ip4_dns_len); - ip4_dns[0]=ip4_dns1; - if (ip4_dns_len==2) ip4_dns[1]=ip4_dns2; - } - - if (ip4_nbns_len) { - ip4_nbns = g_new0(guint32, ip4_nbns_len); - ip4_nbns[0]=ip4_nbns1; - if (ip4_nbns_len==2) ip4_nbns[1]=ip4_nbns2; - } - - if (!(signal = dbus_message_new_signal (NM_DBUS_PATH_PPP_STARTER, NM_DBUS_INTERFACE_PPP_STARTER, NM_DBUS_VPN_SIGNAL_IP4_CONFIG))) - { - nm_warning ("Not enough memory for new dbus message!"); - goto out; - } - - /* PPP does not care about the MSS */ - mss = 0; - if (data->mtu <= 0) data->mtu=1500-4; - mtu = data->mtu; - - ip4_vpn_gateway=data->ip4_vpn_gateway.s_addr; - -#ifdef NM_VPN_USE_OLD_DBUS_INTERFACE - dbus_message_append_args (signal, - DBUS_TYPE_UINT32, &ip4_vpn_gateway, - DBUS_TYPE_STRING, &tundev, - DBUS_TYPE_UINT32, &ip4_address, - DBUS_TYPE_UINT32, &ip4_ptp_address, - 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_UINT32, &mss, - DBUS_TYPE_STRING, &empty, - DBUS_TYPE_STRING, &empty, - DBUS_TYPE_INVALID); -#else - dbus_message_iter_init_append (signal, &iter); - if (!nmu_dbus_dict_open_write (&iter, &iter_dict)) { - nm_warning ("dict open write failed!"); - goto out; - } - - if (!nmu_dbus_dict_append_uint32 (&iter_dict, "gateway", ip4_vpn_gateway)) { - nm_warning ("couldn't append gateway to dict"); - goto out; - } - - if (!nmu_dbus_dict_append_string (&iter_dict, "tundev", tundev)) { - nm_warning ("couldn't append tundev to dict"); - goto out; - } - - if (!nmu_dbus_dict_append_uint32 (&iter_dict, "local_addr", ip4_address)) { - nm_warning ("couldn't append local_address to dict"); - goto out; - } - - if (!nmu_dbus_dict_append_uint32 (&iter_dict, "ptp_addr", ip4_ptp_address)) { - nm_warning ("couldn't append ptp_address to dict"); - goto out; - } - - if (!nmu_dbus_dict_append_uint32_array (&iter_dict, "dns_server", ip4_dns, ip4_dns_len)) { - nm_warning ("couldn't append dns_servers to dict"); - goto out; - } - - if (!nmu_dbus_dict_append_uint32_array (&iter_dict, "nbns_server", ip4_nbns, ip4_nbns_len)) { - nm_warning ("couldn't append nbns_servers to dict"); - goto out; - } - - if (!nmu_dbus_dict_append_uint32 (&iter_dict, "mtu", mtu)) { - nm_warning ("couldn't append mtu to dict"); - goto out; - } - - if (!nmu_dbus_dict_close_write (&iter, &iter_dict)) { - nm_warning ("dict close write failed!"); - goto out; - } -#endif - - if (!dbus_connection_send (data->con, signal, NULL)) - { - nm_warning ("Could not raise the "NM_DBUS_VPN_SIGNAL_IP4_CONFIG" signal!"); - goto out; - } - - dbus_message_unref (signal); - nm_ppp_set_state (data, NM_VPN_SERVICE_STATE_STARTED); - success = TRUE; - } - -out: - if (ip4_nbns!=NULL) g_free(ip4_nbns); - if (ip4_dns!=NULL) g_free(ip4_dns); - - if (!success) - { - nm_warning ("Received invalid IP4 Config information from helper, terminating pppd."); - nm_ppp_dbus_handle_stop_vpn (data); - } -} - - -/* - * 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_VPN_SERVICE_STATE_INIT) || (data->state == NM_VPN_SERVICE_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_STARTER, 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_ppp_dbus_start_vpn (con, message, data); - else if (strcmp ("stopConnection", method) == 0) - reply = nm_ppp_dbus_stop_vpn (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 ("notifyPID", method) == 0) - nm_ppp_dbus_notify_pid (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_ppp_dbus_handle_stop_vpn (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 VPN is certainly not going to work. */ - nm_ppp_dbus_handle_stop_vpn (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. - * - */ -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_set_exit_on_disconnect (connection, FALSE); - dbus_connection_setup_with_g_main (connection, NULL); - - dbus_error_init (&error); - dbus_bus_request_name (connection, NM_DBUS_SERVICE_PPP_STARTER, 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_STARTER, &vtable, data)) - { - nm_warning ("Could not register a dbus handler for nm-ppp-starter. 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 *vpn_data = NULL; - -static void sigterm_handler (int signum) -{ - nm_info ("nm-ppp-starter caught SIGINT/SIGTERM"); - - g_main_loop_quit (vpn_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); - - vpn_data = g_malloc0 (sizeof (NmPPPData)); - - vpn_data->debug = FALSE; - vpn_data->state = NM_VPN_SERVICE_STATE_INIT; - - vpn_data->loop = g_main_loop_new (NULL, FALSE); - - if (!(vpn_data->con = nm_ppp_dbus_init (vpn_data))) - exit (1); - - 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 (vpn_data, NM_VPN_SERVICE_STATE_STOPPED); - g_main_loop_run (vpn_data->loop); - - nm_ppp_dbus_handle_stop_vpn (vpn_data); - - g_main_loop_unref (vpn_data->loop); - - if (vpn_data->auth_items) - g_strfreev (vpn_data->auth_items); - if (vpn_data->str_ip4_vpn_gateway) g_free (vpn_data->str_ip4_vpn_gateway); - if (vpn_data) g_free (vpn_data); - - exit (0); -} diff --git a/vpn-daemons/pptp/src/nm-ppp-status.h b/vpn-daemons/pptp/src/nm-ppp-status.h new file mode 100644 index 0000000000..9e46e542c7 --- /dev/null +++ b/vpn-daemons/pptp/src/nm-ppp-status.h @@ -0,0 +1,22 @@ +#ifndef NM_PPP_STATUS_H +#define NM_PPP_STATUS_H + +typedef enum { + NM_PPP_STATUS_UNKNOWN, + + NM_PPP_STATUS_DEAD, + NM_PPP_STATUS_INITIALIZE, + NM_PPP_STATUS_SERIALCONN, + NM_PPP_STATUS_DORMANT, + NM_PPP_STATUS_ESTABLISH, + NM_PPP_STATUS_AUTHENTICATE, + NM_PPP_STATUS_CALLBACK, + NM_PPP_STATUS_NETWORK, + NM_PPP_STATUS_RUNNING, + NM_PPP_STATUS_TERMINATE, + NM_PPP_STATUS_DISCONNECT, + NM_PPP_STATUS_HOLDOFF, + NM_PPP_STATUS_MASTER +} NMPPPStatus; + +#endif /* NM_PPP_STATUS_H */ diff --git a/vpn-daemons/pptp/src/nm-pppd-plugin.c b/vpn-daemons/pptp/src/nm-pppd-plugin.c deleted file mode 100644 index cd788de38f..0000000000 --- a/vpn-daemons/pptp/src/nm-pppd-plugin.c +++ /dev/null @@ -1,507 +0,0 @@ -/* nm-pptp-service - pptp (and other pppd) integration with NetworkManager - * - * Antony J Mee - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#include "pppd/pppd.h" - -#include "pppd/fsm.h" -#include "pppd/ipcp.h" -#ifndef PPPD_VERSION - #ifdef VERSION - #define PPPD_VERSION VERSION - #endif -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "nm-ppp-starter.h" -#include "nm-pppd-plugin.h" -#include "nm-utils.h" - -typedef struct NmPPPData -{ - DBusConnection *con; - gboolean got_auth_info; - char *auth_type; - char *username; - char *password; - int pppd_pid; -} NmPPPData; - -char pppd_version[] = PPPD_VERSION; - -NmPPPData plugin_data; - -int plugin_init(); - -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 *user, char *passwd); -int nm_chap_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 **auth_items, int num_auth_items); -gboolean nm_dbus_prepare_connection(NmPPPData *data); -void nm_dbus_kill_connection(NmPPPData *data); - -gboolean nm_dbus_prepare_connection(NmPPPData *data) -{ -// DBusMessage * message = NULL; - DBusError error; -// 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 (&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 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); -} - -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; - } - - if (strcmp("CHAP",plugin_data.auth_type)!=0) - { - info("nm-pppd-plugin: No CHAP authentication available!"); - return 0; - } - - - info("nm-pppd-plugin: CHAP check hook."); - return 1; -} - -int nm_chap_passwd_hook(char *user, char *passwd) -{ - info("nm-pppd-plugin: CHAP credentials requested."); - - if (user == NULL) - { - info("nm-pppd-plugin: pppd didn't provide username buffer"); - return -1; - } - - if (passwd == 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; - } - - strcpy(user, plugin_data.username); - user[MAXNAMELEN-1]='\0'; - strcpy(passwd, plugin_data.password); - passwd[MAXSECRETLEN-1]='\0'; -// info("nm-pppd-plugin: 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 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 * 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-pppd-plugin: didn't receive an Internal IP4 Address from ppp."); - send_config_error (con, "IP4 Address"); - return; - } - uint_ip4_address=ipcp_gotoptions[ifunit].ouraddr; - - if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE_PPP_STARTER, NM_DBUS_PATH_PPP_STARTER, NM_DBUS_INTERFACE_PPP_STARTER, "signalIP4Config"))) - { - nm_warning ("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-pppd-plugin: 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 ("nm_ip_up(): could not send dbus message"); - dbus_message_unref (message); - g_free(str_ifname); - return; - } - - g_free(str_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_STARTER, NM_DBUS_PATH_PPP_STARTER, NM_DBUS_INTERFACE_PPP_STARTER, "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); -} - - -/* - * 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_STARTER, NM_DBUS_PATH_PPP_STARTER, NM_DBUS_INTERFACE_PPP_STARTER, "notifyPID"))) - { - nm_warning ("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_ip_up(): could not send dbus message"); - dbus_message_unref (message); - return; - } - -// nm_warning("Sent notify message: %d",data->pppd_pid); - dbus_message_unref (message); -} -/* - * nm_get_auth_items - * - * Request credentials from PPP_STARTER service. - * - */ -gboolean nm_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 (!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_STARTER, NM_DBUS_PATH_PPP_STARTER, NM_DBUS_INTERFACE_PPP_STARTER, "getAuthInfo"))) - { - nm_warning("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, &(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 (!nm_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; -} - -/* - * nm_store_auth_info - * - * Decode and temporarily store the authentication info provided. - * - */ -gboolean nm_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 ("PPPD 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 ("PPPD 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 = nm_chap_check_hook; - chap_passwd_hook = nm_chap_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/vpn-daemons/pptp/src/nm-pptp-pppd-plugin.c b/vpn-daemons/pptp/src/nm-pptp-pppd-plugin.c new file mode 100644 index 0000000000..bfaae5ac16 --- /dev/null +++ b/vpn-daemons/pptp/src/nm-pptp-pppd-plugin.c @@ -0,0 +1,324 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* nm-pptp-service - pptp (and other pppd) integration with NetworkManager + * + * (C) 2007 - 2008 Novell, Inc. + * (C) 2008 Red Hat, Inc. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "nm-pptp-service.h" +#include "nm-ppp-status.h" + +#include + +int plugin_init (void); + +char pppd_version[] = VERSION; + +static DBusGProxy *proxy = NULL; + +static void +nm_phasechange (void *data, int arg) +{ + NMPPPStatus ppp_status = NM_PPP_STATUS_UNKNOWN; + char *ppp_phase; + + g_return_if_fail (DBUS_IS_G_PROXY (proxy)); + + switch (arg) { + case PHASE_DEAD: + ppp_status = NM_PPP_STATUS_DEAD; + ppp_phase = "dead"; + break; + case PHASE_INITIALIZE: + ppp_status = NM_PPP_STATUS_INITIALIZE; + ppp_phase = "initialize"; + break; + case PHASE_SERIALCONN: + ppp_status = NM_PPP_STATUS_SERIALCONN; + ppp_phase = "serial connection"; + break; + case PHASE_DORMANT: + ppp_status = NM_PPP_STATUS_DORMANT; + ppp_phase = "dormant"; + break; + case PHASE_ESTABLISH: + ppp_status = NM_PPP_STATUS_ESTABLISH; + ppp_phase = "establish"; + break; + case PHASE_AUTHENTICATE: + ppp_status = NM_PPP_STATUS_AUTHENTICATE; + ppp_phase = "authenticate"; + break; + case PHASE_CALLBACK: + ppp_status = NM_PPP_STATUS_CALLBACK; + ppp_phase = "callback"; + break; + case PHASE_NETWORK: + ppp_status = NM_PPP_STATUS_NETWORK; + ppp_phase = "network"; + break; + case PHASE_RUNNING: + ppp_status = NM_PPP_STATUS_RUNNING; + ppp_phase = "running"; + break; + case PHASE_TERMINATE: + ppp_status = NM_PPP_STATUS_TERMINATE; + ppp_phase = "terminate"; + break; + case PHASE_DISCONNECT: + ppp_status = NM_PPP_STATUS_DISCONNECT; + ppp_phase = "disconnect"; + break; + case PHASE_HOLDOFF: + ppp_status = NM_PPP_STATUS_HOLDOFF; + ppp_phase = "holdoff"; + break; + case PHASE_MASTER: + ppp_status = NM_PPP_STATUS_MASTER; + ppp_phase = "master"; + break; + + default: + ppp_phase = "unknown"; + break; + } + + if (ppp_status != NM_PPP_STATUS_UNKNOWN) { + dbus_g_proxy_call_no_reply (proxy, "SetState", + G_TYPE_UINT, ppp_status, + G_TYPE_INVALID, + G_TYPE_INVALID); + } +} + +static GValue * +str_to_gvalue (const char *str) +{ + GValue *val; + + val = g_slice_new0 (GValue); + g_value_init (val, G_TYPE_STRING); + g_value_set_string (val, str); + + return val; +} + +static GValue * +uint_to_gvalue (guint32 i) +{ + GValue *val; + + val = g_slice_new0 (GValue); + g_value_init (val, G_TYPE_UINT); + g_value_set_uint (val, i); + + return val; +} + +static void +value_destroy (gpointer data) +{ + GValue *val = (GValue *) data; + + g_value_unset (val); + g_slice_free (GValue, val); +} + +static void +nm_ip_up (void *data, int arg) +{ + ipcp_options opts = ipcp_gotoptions[ifunit]; + ipcp_options peer_opts = ipcp_hisoptions[ifunit]; + GHashTable *hash; + GArray *array; + GValue *val; + + g_return_if_fail (DBUS_IS_G_PROXY (proxy)); + + if (!opts.ouraddr) { + g_warning ("Didn't receive an internal IP from pppd"); + return; + } + + hash = g_hash_table_new_full (g_str_hash, g_str_equal, + NULL, value_destroy); + + g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_TUNDEV, + str_to_gvalue (ifname)); + + g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_ADDRESS, + uint_to_gvalue (opts.ouraddr)); + + g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_PREFIX, uint_to_gvalue (32)); + + if (opts.dnsaddr[0] || opts.dnsaddr[1]) { + array = g_array_new (FALSE, FALSE, sizeof (guint32)); + + if (opts.dnsaddr[0]) + g_array_append_val (array, opts.dnsaddr[0]); + if (opts.dnsaddr[1]) + g_array_append_val (array, opts.dnsaddr[1]); + + val = g_slice_new0 (GValue); + g_value_init (val, DBUS_TYPE_G_UINT_ARRAY); + g_value_set_boxed (val, array); + + g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_DNS, val); + } + +/* + if (opts.winsaddr[0] || opts.winsaddr[1]) { + array = g_array_new (FALSE, FALSE, sizeof (guint32)); + + if (opts.winsaddr[0]) + g_array_append_val (array, opts.winsaddr[0]); + if (opts.winsaddr[1]) + g_array_append_val (array, opts.winsaddr[1]); + + val = g_slice_new0 (GValue); + g_value_init (val, DBUS_TYPE_G_UINT_ARRAY); + g_value_set_boxed (val, array); + + g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_WINS, val); + } +*/ + + dbus_g_proxy_call_no_reply (proxy, "SetIp4Config", + DBUS_TYPE_G_MAP_OF_VARIANT, hash, G_TYPE_INVALID, + G_TYPE_INVALID); + + g_hash_table_destroy (hash); +} + +static int +get_chap_check() +{ + return 1; +} + +static int +get_pap_check() +{ + return 1; +} + +static int +get_credentials (char *username, char *password) +{ + char *my_username; + char *my_password; + size_t len; + GError *err = NULL; + + if (username && !password) { + /* pppd is checking pap support; return 1 for supported */ + return 1; + } + + g_return_val_if_fail (DBUS_IS_G_PROXY (proxy), -1); + + my_username = my_password = NULL; + dbus_g_proxy_call (proxy, "NeedSecrets", &err, + G_TYPE_INVALID, + G_TYPE_STRING, &my_username, + G_TYPE_STRING, &my_password, + G_TYPE_INVALID); + + if (err) { + g_warning ("Could not get secrets: %s", err->message); + g_error_free (err); + return -1; + } + + if (my_username) { + len = strlen (my_username) + 1; + len = len < MAXNAMELEN ? len : MAXNAMELEN; + + strncpy (username, my_username, len); + username[len - 1] = '\0'; + + g_free (my_username); + } + + if (my_password) { + len = strlen (my_password) + 1; + len = len < MAXSECRETLEN ? len : MAXSECRETLEN; + + strncpy (password, my_password, len); + password[len - 1] = '\0'; + + g_free (my_password); + } + + return 1; +} + +static void +nm_exit_notify (void *data, int arg) +{ + g_return_if_fail (DBUS_IS_G_PROXY (proxy)); + + g_object_unref (proxy); + proxy = NULL; +} + +int +plugin_init (void) +{ + DBusGConnection *bus; + GError *err = NULL; + + g_type_init (); + + bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err); + if (!bus) { + g_warning ("Couldn't connect to system bus: %s", err->message); + g_error_free (err); + return -1; + } + + proxy = dbus_g_proxy_new_for_name (bus, + NM_DBUS_SERVICE_PPTP_PPP, + NM_DBUS_PATH_PPTP_PPP, + NM_DBUS_INTERFACE_PPTP_PPP); + + dbus_g_connection_unref (bus); + + chap_passwd_hook = get_credentials; + chap_check_hook = get_chap_check; + pap_passwd_hook = get_credentials; + pap_check_hook = get_pap_check; + + add_notifier (&phasechange, nm_phasechange, NULL); + add_notifier (&ip_up_notifier, nm_ip_up, NULL); + add_notifier (&exitnotify, nm_exit_notify, proxy); + + return 0; +} diff --git a/vpn-daemons/pptp/src/nm-pptp-pppd-service.xml b/vpn-daemons/pptp/src/nm-pptp-pppd-service.xml new file mode 100644 index 0000000000..cc4bfaaf78 --- /dev/null +++ b/vpn-daemons/pptp/src/nm-pptp-pppd-service.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/vpn-daemons/pptp/src/nm-pptp-service.c b/vpn-daemons/pptp/src/nm-pptp-service.c new file mode 100644 index 0000000000..9fab9bd315 --- /dev/null +++ b/vpn-daemons/pptp/src/nm-pptp-service.c @@ -0,0 +1,1031 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* nm-pptp-service - PPTP VPN integration with NetworkManager + * + * Dan Williams + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (C) Copyright 2008 Red Hat, Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include +#ifndef aligned_u64 +#define aligned_u64 unsigned long long __attribute__((aligned(8))) +#endif +#include + +#include +#include +#include + +#include "nm-pptp-service.h" +#include "nm-ppp-status.h" + +/********************************************************/ +/* ppp plugin <-> pptp-service object */ +/********************************************************/ + +/* Have to have a separate objec to handle ppp plugin requests since + * dbus-glib doesn't allow multiple interfaces registed on one GObject. + */ + +#define NM_TYPE_PPTP_PPP_SERVICE (nm_pptp_ppp_service_get_type ()) +#define NM_PPTP_PPP_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_PPTP_PPP_SERVICE, NMPptpPppService)) +#define NM_PPTP_PPP_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_PPTP_PPP_SERVICE, NMPptpPppServiceClass)) +#define NM_IS_PPTP_PPP_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_PPTP_PPP_SERVICE)) +#define NM_IS_PPTP_PPP_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_PPTP_PPP_SERVICE)) +#define NM_PPTP_PPP_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_PPTP_PPP_SERVICE, NMPptpPppServiceClass)) + +typedef struct { + GObject parent; +} NMPptpPppService; + +typedef struct { + GObjectClass parent; + + /* Signals */ + void (*plugin_alive) (NMPptpPppService *self); + void (*ppp_state) (NMPptpPppService *self, guint32 state); + void (*ip4_config) (NMPptpPppService *self, GHashTable *config_hash); +} NMPptpPppServiceClass; + +GType nm_pptp_ppp_service_get_type (void); + +G_DEFINE_TYPE (NMPptpPppService, nm_pptp_ppp_service, G_TYPE_OBJECT) + +static gboolean impl_pptp_service_need_secrets (NMPptpPppService *self, + char **out_username, + char **out_password, + GError **err); + +static gboolean impl_pptp_service_set_state (NMPptpPppService *self, + guint32 state, + GError **err); + +static gboolean impl_pptp_service_set_ip4_config (NMPptpPppService *self, + GHashTable *config, + GError **err); + +#include "nm-pptp-pppd-service-glue.h" + + +#define NM_PPTP_PPP_SERVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_PPTP_PPP_SERVICE, NMPptpPppServicePrivate)) + +typedef struct { + char username[100]; + char password[100]; +} NMPptpPppServicePrivate; + +enum { + PLUGIN_ALIVE, + PPP_STATE, + IP4_CONFIG, + + LAST_SIGNAL +}; +static guint signals[LAST_SIGNAL] = { 0 }; + +NMPptpPppService * +nm_pptp_ppp_service_new (void) +{ + DBusGConnection *connection; + DBusGProxy *proxy; + GError *error = NULL; + gboolean success = FALSE; + guint request_name_result; + GObject *object; + + object = g_object_new (NM_TYPE_PPTP_PPP_SERVICE, NULL); + + dbus_connection_set_change_sigpipe (TRUE); + + connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); + if (!connection) { + nm_warning ("Could not get the system bus. Make sure " + "the message bus daemon is running! Message: %s", + error->message); + g_error_free (error); + g_object_unref (object); + return NULL; + } + + proxy = dbus_g_proxy_new_for_name (connection, + "org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus"); + + if (dbus_g_proxy_call (proxy, "RequestName", &error, + G_TYPE_STRING, NM_DBUS_SERVICE_PPTP_PPP, + G_TYPE_UINT, 0, + G_TYPE_INVALID, + G_TYPE_UINT, &request_name_result, + G_TYPE_INVALID)) { + dbus_g_connection_register_g_object (connection, NM_DBUS_PATH_PPTP_PPP, object); + success = TRUE; + } else { + nm_warning ("Could not register D-Bus service name. Message: %s", error->message); + g_error_free (error); + g_object_unref (object); + object = NULL; + } + + g_object_unref (proxy); + return (NMPptpPppService *) object; +} + +static void +nm_pptp_ppp_service_init (NMPptpPppService *self) +{ +} + +static void +finalize (GObject *object) +{ + NMPptpPppServicePrivate *priv = NM_PPTP_PPP_SERVICE_GET_PRIVATE (object); + + /* Get rid of the cached username and password */ + memset (priv->username, 0, sizeof (priv->username)); + memset (priv->password, 0, sizeof (priv->password)); +} + +static void +nm_pptp_ppp_service_class_init (NMPptpPppServiceClass *service_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (service_class); + + g_type_class_add_private (service_class, sizeof (NMPptpPppServicePrivate)); + + /* virtual methods */ + object_class->finalize = finalize; + + /* Signals */ + signals[PLUGIN_ALIVE] = + g_signal_new ("plugin-alive", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMPptpPppServiceClass, plugin_alive), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + signals[PPP_STATE] = + g_signal_new ("ppp-state", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMPptpPppServiceClass, ppp_state), + NULL, NULL, + g_cclosure_marshal_VOID__UINT, + G_TYPE_NONE, 1, G_TYPE_UINT); + + signals[IP4_CONFIG] = + g_signal_new ("ip4-config", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMPptpPppServiceClass, ip4_config), + NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, G_TYPE_POINTER); + + dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (service_class), + &dbus_glib_nm_pptp_pppd_service_object_info); +} + +static gboolean +nm_pptp_ppp_service_cache_credentials (NMPptpPppService *self, + NMConnection *connection, + GError **error) +{ + NMPptpPppServicePrivate *priv = NM_PPTP_PPP_SERVICE_GET_PRIVATE (self); + NMSettingVPN *s_vpn; + NMSettingVPNProperties *s_vpn_props; + GValue *value; + const char *username, *password; + + g_return_val_if_fail (self != NULL, FALSE); + g_return_val_if_fail (connection != NULL, FALSE); + + memset (priv->username, 0, sizeof (priv->username)); + memset (priv->password, 0, sizeof (priv->password)); + + s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN); + if (!s_vpn) { + g_set_error (error, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID, + "%s", + "Could not find secrets (connection invalid, no vpn setting)."); + return FALSE; + } + + s_vpn_props = (NMSettingVPNProperties *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN_PROPERTIES); + if (!s_vpn_props || !s_vpn_props->data) { + g_set_error (error, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID, + "%s", + "Could not find secrets (connection invalid, no vpn-properties setting)."); + return FALSE; + } + + /* Username; try PPTP specific username first, then generic username */ + value = g_hash_table_lookup (s_vpn_props->data, NM_PPTP_KEY_USER); + if (value && G_VALUE_HOLDS_STRING (value)) { + username = g_value_get_string (value); + if (!username || !strlen (username)) { + g_set_error (error, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID, + "%s", + "Invalid VPN username."); + return FALSE; + } + } else { + username = s_vpn->user_name; + if (!username || !strlen (username)) { + g_set_error (error, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID, + "%s", + "Missing VPN username."); + return FALSE; + } + } + + value = g_hash_table_lookup (s_vpn_props->data, NM_PPTP_KEY_PASSWORD); + if (!value || !G_VALUE_HOLDS_STRING (value)) { + g_set_error (error, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID, + "%s", + "Missing VPN password."); + return FALSE; + } + + password = g_value_get_string (value); + if (!password || !strlen (password)) { + g_set_error (error, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID, + "%s", + "Invalid VPN password."); + return FALSE; + } + + memcpy (priv->username, username, strlen (username)); + memcpy (priv->password, password, strlen (password)); + return TRUE; +} + +static gboolean +impl_pptp_service_need_secrets (NMPptpPppService *self, + char **out_username, + char **out_password, + GError **error) +{ + NMPptpPppServicePrivate *priv = NM_PPTP_PPP_SERVICE_GET_PRIVATE (self); + + g_signal_emit (G_OBJECT (self), signals[PLUGIN_ALIVE], 0); + + if (!strlen (priv->username) || !strlen (priv->password)) { + g_set_error (error, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID, + "%s", + "No cached credentials."); + goto error; + } + + /* Success */ + *out_username = g_strdup (priv->username); + *out_password = g_strdup (priv->password); + return TRUE; + +error: + return FALSE; +} + +static gboolean +impl_pptp_service_set_state (NMPptpPppService *self, + guint32 pppd_state, + GError **err) +{ + g_signal_emit (G_OBJECT (self), signals[PLUGIN_ALIVE], 0); + g_signal_emit (G_OBJECT (self), signals[PPP_STATE], 0, pppd_state); + return TRUE; +} + +static gboolean +impl_pptp_service_set_ip4_config (NMPptpPppService *self, + GHashTable *config_hash, + GError **err) +{ + nm_info ("PPTP service (IP Config Get) reply received."); + g_signal_emit (G_OBJECT (self), signals[PLUGIN_ALIVE], 0); + + /* Just forward the pppd plugin config up to our superclass; no need to modify it */ + g_signal_emit (G_OBJECT (self), signals[IP4_CONFIG], 0, config_hash); + + return TRUE; +} + + +/********************************************************/ +/* The VPN plugin service */ +/********************************************************/ + +G_DEFINE_TYPE (NMPptpPlugin, nm_pptp_plugin, NM_TYPE_VPN_PLUGIN) + +typedef struct { + GPid pid; + guint32 ppp_timeout_handler; + NMPptpPppService *service; +} NMPptpPluginPrivate; + +#define NM_PPTP_PLUGIN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_PPTP_PLUGIN, NMPptpPluginPrivate)) + +#define NM_PPTP_PPPD_PLUGIN PLUGINDIR "/nm-pptp-pppd-plugin.so" +#define NM_PPTP_WAIT_PPPD 10000 /* 10 seconds */ +#define PPTP_SERVICE_SECRET_TRIES "pptp-service-secret-tries" + +typedef struct { + const char *name; + GType type; + gboolean required; +} ValidProperty; + +static ValidProperty valid_properties[] = { + { NM_PPTP_KEY_GATEWAY, G_TYPE_STRING, TRUE }, + { NM_PPTP_KEY_USER, G_TYPE_STRING, FALSE }, + { NM_PPTP_KEY_PASSWORD, G_TYPE_STRING, FALSE }, + { NM_PPTP_KEY_DOMAIN, G_TYPE_STRING, FALSE }, + { NM_PPTP_KEY_REFUSE_EAP, G_TYPE_BOOLEAN, FALSE }, + { NM_PPTP_KEY_REFUSE_PAP, G_TYPE_BOOLEAN, FALSE }, + { NM_PPTP_KEY_REFUSE_CHAP, G_TYPE_BOOLEAN, FALSE }, + { NM_PPTP_KEY_REFUSE_MSCHAP, G_TYPE_BOOLEAN, FALSE }, + { NM_PPTP_KEY_REFUSE_MSCHAPV2, G_TYPE_BOOLEAN, FALSE }, + { NM_PPTP_KEY_REQUIRE_MPPE, G_TYPE_BOOLEAN, FALSE }, + { NM_PPTP_KEY_REQUIRE_MPPE_40, G_TYPE_BOOLEAN, FALSE }, + { NM_PPTP_KEY_REQUIRE_MPPE_128, G_TYPE_BOOLEAN, FALSE }, + { NM_PPTP_KEY_MPPE_STATEFUL, G_TYPE_BOOLEAN, FALSE }, + { NM_PPTP_KEY_NOBSDCOMP, G_TYPE_BOOLEAN, FALSE }, + { NM_PPTP_KEY_NODEFLATE, G_TYPE_BOOLEAN, FALSE }, + { NM_PPTP_KEY_NO_VJ_COMP, G_TYPE_BOOLEAN, FALSE }, + { NM_PPTP_KEY_LCP_ECHO_FAILURE, G_TYPE_UINT, FALSE }, + { NM_PPTP_KEY_LCP_ECHO_INTERVAL, G_TYPE_UINT, FALSE }, + { NULL, G_TYPE_NONE, FALSE } +}; + +static gboolean +validate_gateway (GValue *value) +{ + const char *gateway = g_value_get_string (value); + const char *p = gateway; + + if (!gateway || !strlen (gateway)) + return FALSE; + + /* Ensure it's a valid DNS name or IP address */ + p = gateway; + while (*p) { + if (!isalnum (*p) && (*p != '-') && (*p != '.')) + return FALSE; + p++; + } + return TRUE; +} + +static void +validate_one_property (gpointer key, gpointer val, gpointer user_data) +{ + gboolean *failed = (gboolean *) user_data; + int i; + + if (*failed) + return; + + /* 'name' is the setting name; always allowed but unused */ + if (!strcmp ((char *) key, NM_SETTING_NAME)) + return; + + for (i = 0; valid_properties[i].name; i++) { + ValidProperty prop = valid_properties[i]; + + if (!strcmp (prop.name, (char *) key) && prop.type == G_VALUE_TYPE ((GValue *) val)) { + if (!strcmp (prop.name, NM_PPTP_KEY_GATEWAY)) { + if (!validate_gateway ((GValue *) val)) + goto failed; + } + /* Property is ok */ + return; + } + } + +failed: + /* Did not find the property from valid_properties or the type did not match */ + g_warning ("VPN property '%s' failed validation.", (char *) key); + *failed = TRUE; +} + +static gboolean +nm_pptp_properties_validate (GHashTable *properties) +{ + gboolean failed = FALSE; + int i; + + if (g_hash_table_size (properties) < 1) + return failed; + + g_hash_table_foreach (properties, validate_one_property, &failed); + if (failed) + return FALSE; + + /* Ensure required properties exist */ + for (i = 0; valid_properties[i].name; i++) { + ValidProperty prop = valid_properties[i]; + GValue *value; + + if (!prop.required) + continue; + + value = g_hash_table_lookup (properties, prop.name); + if (!value || (G_VALUE_TYPE (value) != prop.type)) + return FALSE; + } + + return TRUE; +} + +static void +pppd_watch_cb (GPid pid, gint status, gpointer user_data) +{ + NMPptpPlugin *plugin = NM_PPTP_PLUGIN (user_data); + NMPptpPluginPrivate *priv = NM_PPTP_PLUGIN_GET_PRIVATE (plugin); + guint error = 0; + + if (WIFEXITED (status)) { + error = WEXITSTATUS (status); + if (error != 0) + nm_warning ("pppd exited with error code %d", error); + } + else if (WIFSTOPPED (status)) + nm_warning ("pppd stopped unexpectedly with signal %d", WSTOPSIG (status)); + else if (WIFSIGNALED (status)) + nm_warning ("pppd died with signal %d", WTERMSIG (status)); + else + nm_warning ("pppd died from an unknown cause"); + + /* Reap child if needed. */ + waitpid (priv->pid, NULL, WNOHANG); + priv->pid = 0; + + /* Must be after data->state is set since signals use data->state */ + switch (error) { + case 16: + /* hangup */ + // FIXME: better failure reason + nm_vpn_plugin_failure (NM_VPN_PLUGIN (plugin), NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED); + break; + case 2: + /* Couldn't log in due to bad user/pass */ + nm_vpn_plugin_failure (NM_VPN_PLUGIN (plugin), NM_VPN_PLUGIN_FAILURE_LOGIN_FAILED); + break; + case 1: + /* Other error (couldn't bind to address, etc) */ + nm_vpn_plugin_failure (NM_VPN_PLUGIN (plugin), NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED); + break; + default: + break; + } + + nm_vpn_plugin_set_state (NM_VPN_PLUGIN (plugin), NM_VPN_SERVICE_STATE_STOPPED); +} + +static inline const char * +nm_find_pppd (void) +{ + static const char *pppd_binary_paths[] = + { + "/sbin/pppd", + "/usr/sbin/pppd", + "/usr/local/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_pptp (void) +{ + static const char *pptp_binary_paths[] = + { + "/sbin/pptp", + "/usr/sbin/pptp", + "/usr/local/sbin/pptp", + NULL + }; + + const char **pptp_binary = pptp_binary_paths; + + while (*pptp_binary != NULL) { + if (g_file_test (*pptp_binary, G_FILE_TEST_EXISTS)) + break; + pptp_binary++; + } + + return *pptp_binary; +} + +static gboolean +pppd_timed_out (gpointer user_data) +{ + NMPptpPlugin *plugin = NM_PPTP_PLUGIN (user_data); + + nm_warning ("Looks like pppd didn't initialize our dbus module"); + nm_vpn_plugin_failure (NM_VPN_PLUGIN (plugin), NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT); + + return FALSE; +} + +static void +free_pppd_args (GPtrArray *args) +{ + int i; + + if (!args) + return; + + for (i = 0; i < args->len; i++) + g_free (g_ptr_array_index (args, i)); + g_ptr_array_free (args, TRUE); +} + +static GPtrArray * +construct_pppd_args (NMPptpPlugin *plugin, + NMSettingVPN *s_vpn, + NMSettingVPNProperties *s_vpn_props, + const char *pppd, + GError **error) +{ + GPtrArray *args = NULL; + GValue *value; + const char *pptp_binary; + char *ipparam, *tmp; + + pptp_binary = nm_find_pptp (); + if (!pptp_binary) { + g_set_error (error, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_LAUNCH_FAILED, + "%s", + "Could not find pptp client binary."); + return FALSE; + } + + args = g_ptr_array_new (); + g_ptr_array_add (args, (gpointer) g_strdup (pppd)); + + /* PPTP options */ + value = g_hash_table_lookup (s_vpn_props->data, NM_PPTP_KEY_GATEWAY); + if (!value || !G_VALUE_HOLDS_STRING (value)) { + g_set_error (error, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID, + "%s", + "Missing VPN gateway."); + goto error; + } + + ipparam = g_strdup_printf ("nm-pptp-service-%d", getpid ()); + + g_ptr_array_add (args, (gpointer) g_strdup ("pty")); + tmp = g_strdup_printf ("%s %s --nolaunchpppd --logstring %s", + pptp_binary, g_value_get_string (value), ipparam); + g_ptr_array_add (args, (gpointer) tmp); + + /* PPP options */ + g_ptr_array_add (args, (gpointer) g_strdup ("ipparam")); + g_ptr_array_add (args, (gpointer) ipparam); + + g_ptr_array_add (args, (gpointer) g_strdup ("nodetach")); + g_ptr_array_add (args, (gpointer) g_strdup ("lock")); + g_ptr_array_add (args, (gpointer) g_strdup ("usepeerdns")); + + value = g_hash_table_lookup (s_vpn_props->data, NM_PPTP_KEY_REFUSE_EAP); + if (value && G_VALUE_HOLDS_BOOLEAN (value) && g_value_get_boolean (value)) + g_ptr_array_add (args, (gpointer) g_strdup ("refuse-eap")); + + value = g_hash_table_lookup (s_vpn_props->data, NM_PPTP_KEY_REFUSE_PAP); + if (value && G_VALUE_HOLDS_BOOLEAN (value) && g_value_get_boolean (value)) + g_ptr_array_add (args, (gpointer) g_strdup ("refuse-pap")); + + value = g_hash_table_lookup (s_vpn_props->data, NM_PPTP_KEY_REFUSE_CHAP); + if (value && G_VALUE_HOLDS_BOOLEAN (value) && g_value_get_boolean (value)) + g_ptr_array_add (args, (gpointer) g_strdup ("refuse-chap")); + + value = g_hash_table_lookup (s_vpn_props->data, NM_PPTP_KEY_REFUSE_MSCHAP); + if (value && G_VALUE_HOLDS_BOOLEAN (value) && g_value_get_boolean (value)) + g_ptr_array_add (args, (gpointer) g_strdup ("refuse-mschap")); + + value = g_hash_table_lookup (s_vpn_props->data, NM_PPTP_KEY_REFUSE_MSCHAPV2); + if (value && G_VALUE_HOLDS_BOOLEAN (value) && g_value_get_boolean (value)) + g_ptr_array_add (args, (gpointer) g_strdup ("refuse-mschap-v2")); + + value = g_hash_table_lookup (s_vpn_props->data, NM_PPTP_KEY_REQUIRE_MPPE); + if (value && G_VALUE_HOLDS_BOOLEAN (value) && g_value_get_boolean (value)) + g_ptr_array_add (args, (gpointer) g_strdup ("require-mppe")); + + value = g_hash_table_lookup (s_vpn_props->data, NM_PPTP_KEY_REQUIRE_MPPE_40); + if (value && G_VALUE_HOLDS_BOOLEAN (value) && g_value_get_boolean (value)) + g_ptr_array_add (args, (gpointer) g_strdup ("require-mppe-40")); + + value = g_hash_table_lookup (s_vpn_props->data, NM_PPTP_KEY_REQUIRE_MPPE_128); + if (value && G_VALUE_HOLDS_BOOLEAN (value) && g_value_get_boolean (value)) + g_ptr_array_add (args, (gpointer) g_strdup ("require-mppe-128")); + + value = g_hash_table_lookup (s_vpn_props->data, NM_PPTP_KEY_MPPE_STATEFUL); + if (value && G_VALUE_HOLDS_BOOLEAN (value) && g_value_get_boolean (value)) + g_ptr_array_add (args, (gpointer) g_strdup ("mppe-stateful")); + + value = g_hash_table_lookup (s_vpn_props->data, NM_PPTP_KEY_NOBSDCOMP); + if (value && G_VALUE_HOLDS_BOOLEAN (value) && g_value_get_boolean (value)) + g_ptr_array_add (args, (gpointer) g_strdup ("nobsdcomp")); + + value = g_hash_table_lookup (s_vpn_props->data, NM_PPTP_KEY_NODEFLATE); + if (value && G_VALUE_HOLDS_BOOLEAN (value) && g_value_get_boolean (value)) + g_ptr_array_add (args, (gpointer) g_strdup ("nodeflate")); + + value = g_hash_table_lookup (s_vpn_props->data, NM_PPTP_KEY_NO_VJ_COMP); + if (value && G_VALUE_HOLDS_BOOLEAN (value) && g_value_get_boolean (value)) + g_ptr_array_add (args, (gpointer) g_strdup ("novjcomp")); + + value = g_hash_table_lookup (s_vpn_props->data, NM_PPTP_KEY_LCP_ECHO_FAILURE); + if (value && G_VALUE_HOLDS_UINT (value) && g_value_get_uint (value)) { + g_ptr_array_add (args, (gpointer) g_strdup ("lcp-echo-failure")); + tmp = g_strdup_printf ("%d", g_value_get_uint (value)); + g_ptr_array_add (args, (gpointer) tmp); + } + + value = g_hash_table_lookup (s_vpn_props->data, NM_PPTP_KEY_LCP_ECHO_INTERVAL); + if (value && G_VALUE_HOLDS_UINT (value) && g_value_get_uint (value)) { + g_ptr_array_add (args, (gpointer) g_strdup ("lcp-echo-interval")); + tmp = g_strdup_printf ("%d", g_value_get_uint (value)); + g_ptr_array_add (args, (gpointer) tmp); + } + + g_ptr_array_add (args, (gpointer) g_strdup ("plugin")); + g_ptr_array_add (args, (gpointer) g_strdup (NM_PPTP_PPPD_PLUGIN)); + + g_ptr_array_add (args, NULL); + + return args; + +error: + free_pppd_args (args); + return FALSE; +} + +static gboolean +nm_pptp_start_pppd_binary (NMPptpPlugin *plugin, + NMSettingVPN *s_vpn, + NMSettingVPNProperties *s_vpn_props) +{ + NMPptpPluginPrivate *priv = NM_PPTP_PLUGIN_GET_PRIVATE (plugin); + GPid pid; + const char *pppd_binary; + GPtrArray *pppd_argv; + GError *err = NULL; + + pppd_binary = nm_find_pppd (); + if (!pppd_binary) { + nm_info ("Could not find pppd binary."); + return FALSE; + } + + pppd_argv = construct_pppd_args (plugin, s_vpn, s_vpn_props, pppd_binary, &err); + if (!pppd_argv) + return FALSE; + + if (!g_spawn_async (NULL, (char **) pppd_argv->pdata, NULL, + G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, &err)) { + g_ptr_array_free (pppd_argv, TRUE); + nm_warning ("pppd failed to start. error: '%s'", err->message); + g_error_free (err); + return FALSE; + } + free_pppd_args (pppd_argv); + + nm_info ("pppd started with pid %d", pid); + + NM_PPTP_PLUGIN_GET_PRIVATE (plugin)->pid = pid; + g_child_watch_add (pid, pppd_watch_cb, plugin); + + priv->ppp_timeout_handler = g_timeout_add (NM_PPTP_WAIT_PPPD, pppd_timed_out, plugin); + + return TRUE; +} + +static void +remove_timeout_handler (NMPptpPlugin *plugin) +{ + NMPptpPluginPrivate *priv = NM_PPTP_PLUGIN_GET_PRIVATE (plugin); + + if (priv->ppp_timeout_handler) { + g_source_remove (priv->ppp_timeout_handler); + priv->ppp_timeout_handler = 0; + } +} + +static void +service_plugin_alive_cb (NMPptpPppService *service, + NMPptpPlugin *plugin) +{ + remove_timeout_handler (plugin); +} + +static void +service_ppp_state_cb (NMPptpPppService *service, + guint32 ppp_state, + NMPptpPlugin *plugin) +{ + NMVPNServiceState plugin_state = nm_vpn_plugin_get_state (NM_VPN_PLUGIN (plugin)); + + switch (ppp_state) { + case NM_PPP_STATUS_DEAD: + case NM_PPP_STATUS_DISCONNECT: + if (plugin_state == NM_VPN_SERVICE_STATE_STARTED) + nm_vpn_plugin_disconnect (NM_VPN_PLUGIN (plugin), NULL); + else if (plugin_state == NM_VPN_SERVICE_STATE_STARTING) + nm_vpn_plugin_failure (NM_VPN_PLUGIN (plugin), NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED); + break; + default: + break; + } +} + +static void +service_ip4_config_cb (NMPptpPppService *service, + GHashTable *config_hash, + NMPptpPlugin *plugin) +{ + nm_vpn_plugin_set_ip4_config (NM_VPN_PLUGIN (plugin), config_hash); +} + +static gboolean +real_connect (NMVPNPlugin *plugin, + NMConnection *connection, + GError **err) +{ + NMPptpPluginPrivate *priv = NM_PPTP_PLUGIN_GET_PRIVATE (plugin); + NMSettingVPN *s_vpn; + NMSettingVPNProperties *s_vpn_props; + + s_vpn_props = NM_SETTING_VPN_PROPERTIES (nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN_PROPERTIES)); + if (!s_vpn_props || !nm_pptp_properties_validate (s_vpn_props->data)) { + g_set_error (err, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, + "%s", + "Invalid arguments."); + return FALSE; + } + + s_vpn = NM_SETTING_VPN (nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN)); + g_assert (s_vpn); + + /* Start our pppd plugin helper service */ + if (priv->service) + g_object_unref (priv->service); + + priv->service = nm_pptp_ppp_service_new (); + if (!priv->service) { + g_set_error (err, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_LAUNCH_FAILED, + "%s", + "Could not start pppd plugin helper service."); + return FALSE; + } + g_signal_connect (G_OBJECT (priv->service), "plugin-alive", G_CALLBACK (service_plugin_alive_cb), plugin); + g_signal_connect (G_OBJECT (priv->service), "ppp-state", G_CALLBACK (service_ppp_state_cb), plugin); + g_signal_connect (G_OBJECT (priv->service), "ip4-config", G_CALLBACK (service_ip4_config_cb), plugin); + + /* Cache the username and password so we can relay the secrets to the pppd + * plugin when it asks for them. + */ + if (!nm_pptp_ppp_service_cache_credentials (priv->service, connection, err)) + return FALSE; + + if (!nm_pptp_start_pppd_binary (NM_PPTP_PLUGIN (plugin), s_vpn, s_vpn_props)) { + g_set_error (err, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_LAUNCH_FAILED, + "%s", + "Could not start pppd binary."); + return FALSE; + } + + return TRUE; +} + +static gboolean +real_need_secrets (NMVPNPlugin *plugin, + NMConnection *connection, + char **setting_name, + GError **error) +{ + NMSettingVPNProperties *s_vpn_props; + + g_return_val_if_fail (NM_IS_VPN_PLUGIN (plugin), FALSE); + g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); + + s_vpn_props = NM_SETTING_VPN_PROPERTIES (nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN_PROPERTIES)); + if (!s_vpn_props) { + g_set_error (error, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID, + "%s", + "Could not process the request because the VPN connection settings were invalid."); + return FALSE; + } + + if (!g_hash_table_lookup (s_vpn_props->data, NM_PPTP_KEY_PASSWORD)) { + *setting_name = NM_SETTING_VPN_PROPERTIES_SETTING_NAME; + return TRUE; + } + + return FALSE; +} + +static gboolean +ensure_killed (gpointer data) +{ + int pid = GPOINTER_TO_INT (data); + + if (kill (pid, 0) == 0) + kill (pid, SIGKILL); + + return FALSE; +} + +static gboolean +real_disconnect (NMVPNPlugin *plugin, + GError **err) +{ + NMPptpPluginPrivate *priv = NM_PPTP_PLUGIN_GET_PRIVATE (plugin); + + if (priv->pid) { + if (kill (priv->pid, SIGTERM) == 0) + g_timeout_add (2000, ensure_killed, GINT_TO_POINTER (priv->pid)); + else + kill (priv->pid, SIGKILL); + + nm_info ("Terminated ppp daemon with PID %d.", priv->pid); + priv->pid = 0; + } + + if (priv->service) { + g_object_unref (priv->service); + priv->service = NULL; + } + + return TRUE; +} + +static void +state_changed_cb (GObject *object, NMVPNServiceState state, gpointer user_data) +{ + NMPptpPluginPrivate *priv = NM_PPTP_PLUGIN_GET_PRIVATE (object); + + switch (state) { + case NM_VPN_SERVICE_STATE_UNKNOWN: + case NM_VPN_SERVICE_STATE_INIT: + case NM_VPN_SERVICE_STATE_SHUTDOWN: + case NM_VPN_SERVICE_STATE_STARTED: + case NM_VPN_SERVICE_STATE_STOPPING: + case NM_VPN_SERVICE_STATE_STOPPED: + if (priv->service) { + g_object_unref (priv->service); + priv->service = NULL; + } + break; + default: + break; + } +} + +static void +dispose (GObject *object) +{ + NMPptpPluginPrivate *priv = NM_PPTP_PLUGIN_GET_PRIVATE (object); + + if (priv->service) + g_object_unref (priv->service); + + G_OBJECT_CLASS (nm_pptp_plugin_parent_class)->dispose (object); +} + +static void +nm_pptp_plugin_init (NMPptpPlugin *plugin) +{ +} + +static void +nm_pptp_plugin_class_init (NMPptpPluginClass *pptp_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (pptp_class); + NMVPNPluginClass *parent_class = NM_VPN_PLUGIN_CLASS (pptp_class); + + g_type_class_add_private (object_class, sizeof (NMPptpPluginPrivate)); + + /* virtual methods */ + object_class->dispose = dispose; + parent_class->connect = real_connect; + parent_class->need_secrets = real_need_secrets; + parent_class->disconnect = real_disconnect; +} + +NMPptpPlugin * +nm_pptp_plugin_new (void) +{ + NMPptpPlugin *plugin; + + plugin = g_object_new (NM_TYPE_PPTP_PLUGIN, + NM_VPN_PLUGIN_DBUS_SERVICE_NAME, + NM_DBUS_SERVICE_PPTP, + NULL); + if (plugin) + g_signal_connect (G_OBJECT (plugin), "state-changed", G_CALLBACK (state_changed_cb), NULL); + return plugin; +} + +static void +quit_mainloop (NMPptpPlugin *plugin, gpointer user_data) +{ + g_main_loop_quit ((GMainLoop *) user_data); +} + +int +main (int argc, char *argv[]) +{ + NMPptpPlugin *plugin; + GMainLoop *main_loop; + + g_type_init (); + + plugin = nm_pptp_plugin_new (); + if (!plugin) + exit (EXIT_FAILURE); + + main_loop = g_main_loop_new (NULL, FALSE); + + g_signal_connect (plugin, "quit", + G_CALLBACK (quit_mainloop), + main_loop); + + g_main_loop_run (main_loop); + + g_main_loop_unref (main_loop); + g_object_unref (plugin); + + exit (EXIT_SUCCESS); +} diff --git a/vpn-daemons/pptp/src/nm-pptp-service.h b/vpn-daemons/pptp/src/nm-pptp-service.h new file mode 100644 index 0000000000..dc1880caa4 --- /dev/null +++ b/vpn-daemons/pptp/src/nm-pptp-service.h @@ -0,0 +1,82 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* nm-pptp-service - PPTP VPN integration with NetworkManager + * + * Dan Williams + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (C) Copyright 2008 Red Hat, Inc. + */ + +#ifndef NM_PPTP_PLUGIN_H +#define NM_PPTP_PLUGIN_H + +#include +#include +#include + +#define NM_TYPE_PPTP_PLUGIN (nm_pptp_plugin_get_type ()) +#define NM_PPTP_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_PPTP_PLUGIN, NMPptpPlugin)) +#define NM_PPTP_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_PPTP_PLUGIN, NMPptpPluginClass)) +#define NM_IS_PPTP_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_PPTP_PLUGIN)) +#define NM_IS_PPTP_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_PPTP_PLUGIN)) +#define NM_PPTP_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_PPTP_PLUGIN, NMPptpPluginClass)) + +/* For the pppd plugin <-> VPN plugin service */ +#define DBUS_TYPE_G_MAP_OF_VARIANT (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE)) + +#define NM_DBUS_SERVICE_PPTP_PPP "org.freedesktop.NetworkManager.pptp-ppp" +#define NM_DBUS_PATH_PPTP_PPP "/org/freedesktop/NetworkManager/pptp/ppp" +#define NM_DBUS_INTERFACE_PPTP_PPP "org.freedesktop.NetworkManager.pptp.ppp" + + +/* For the NM <-> VPN plugin service */ +#define NM_DBUS_SERVICE_PPTP "org.freedesktop.NetworkManager.pptp" +#define NM_DBUS_INTERFACE_PPTP "org.freedesktop.NetworkManager.pptp" +#define NM_DBUS_PATH_PPTP "/org/freedesktop/NetworkManager/pptp" + +#define NM_PPTP_KEY_GATEWAY "gateway" +#define NM_PPTP_KEY_USER "user" +#define NM_PPTP_KEY_PASSWORD "password" +#define NM_PPTP_KEY_DOMAIN "domain" +#define NM_PPTP_KEY_REFUSE_EAP "refuse-eap" +#define NM_PPTP_KEY_REFUSE_PAP "refuse-pap" +#define NM_PPTP_KEY_REFUSE_CHAP "refuse-chap" +#define NM_PPTP_KEY_REFUSE_MSCHAP "refuse-mschap" +#define NM_PPTP_KEY_REFUSE_MSCHAPV2 "refuse-mschapv2" +#define NM_PPTP_KEY_REQUIRE_MPPE "require-mppe" +#define NM_PPTP_KEY_REQUIRE_MPPE_40 "require-mppe-40" +#define NM_PPTP_KEY_REQUIRE_MPPE_128 "require-mppe-128" +#define NM_PPTP_KEY_MPPE_STATEFUL "mppe-stateful" +#define NM_PPTP_KEY_NOBSDCOMP "nobsdcomp" +#define NM_PPTP_KEY_NODEFLATE "nodeflate" +#define NM_PPTP_KEY_NO_VJ_COMP "no-vj-comp" +#define NM_PPTP_KEY_LCP_ECHO_FAILURE "lcp-echo-failure" +#define NM_PPTP_KEY_LCP_ECHO_INTERVAL "lcp-echo-interval" + + +typedef struct { + NMVPNPlugin parent; +} NMPptpPlugin; + +typedef struct { + NMVPNPluginClass parent; +} NMPptpPluginClass; + +GType nm_pptp_plugin_get_type (void); + +NMPptpPlugin *nm_pptp_plugin_new (void); + +#endif /* NM_PPTP_PLUGIN_H */ diff --git a/vpn-daemons/pptp/src/nm-utils.c b/vpn-daemons/pptp/src/nm-utils.c deleted file mode 100644 index d3b90d6143..0000000000 --- a/vpn-daemons/pptp/src/nm-utils.c +++ /dev/null @@ -1,606 +0,0 @@ -/* NetworkManager -- Network link manager - * - * Ray Strode - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * (C) Copyright 2005 Red Hat, Inc. - */ - -#include -#include -#include - -#include -#include -#include "nm-utils.h" - -gchar *nm_dbus_escape_object_path (const gchar *utf8_string) -{ - const gchar *p; - gchar *object_path; - GString *string; - - g_return_val_if_fail (utf8_string != NULL, NULL); - g_return_val_if_fail (g_utf8_validate (utf8_string, -1, NULL), NULL); - - string = g_string_sized_new ((strlen (utf8_string) + 1) * 6); - - for (p = utf8_string; *p != '\0'; p = g_utf8_next_char (p)) - { - gunichar character; - - character = g_utf8_get_char (p); - - if (((character >= ((gunichar) 'a')) && - (character <= ((gunichar) 'z'))) || - ((character >= ((gunichar) 'A')) && - (character <= ((gunichar) 'Z'))) || - ((character >= ((gunichar) '0')) && - (character <= ((gunichar) '9'))) || - (character == ((gunichar) '/'))) - { - g_string_append_c (string, (gchar) character); - continue; - } - - g_string_append_printf (string, "_%x_", character); - } - - object_path = string->str; - - g_string_free (string, FALSE); - - return object_path; -} - -gchar *nm_dbus_unescape_object_path (const gchar *object_path) -{ - const gchar *p; - gchar *utf8_string; - GString *string; - - g_return_val_if_fail (object_path != NULL, NULL); - - string = g_string_sized_new (strlen (object_path) + 1); - - for (p = object_path; *p != '\0'; p++) - { - const gchar *q; - gchar *hex_digits, *end, utf8_character[6] = { '\0' }; - gint utf8_character_size; - gunichar character; - gulong hex_value; - - if (*p != '_') - { - g_string_append_c (string, *p); - continue; - } - - q = strchr (p + 1, '_'); - - if ((q == NULL) || (q == p + 1)) - { - g_string_free (string, TRUE); - return NULL; - } - - hex_digits = g_strndup (p + 1, (q - 1) - p); - - hex_value = strtoul (hex_digits, &end, 16); - - character = (gunichar) hex_value; - - if (((hex_value == G_MAXLONG) && (errno == ERANGE)) || - (hex_value > G_MAXUINT32) || - (*end != '\0') || - (!g_unichar_validate (character))) - { - g_free (hex_digits); - g_string_free (string, TRUE); - return NULL; - } - - utf8_character_size = - g_unichar_to_utf8 (character, utf8_character); - - g_assert (utf8_character_size > 0); - - g_string_append_len (string, utf8_character, - utf8_character_size); - - p = q; - } - - utf8_string = string->str; - - g_string_free (string, FALSE); - - return utf8_string; -} - - -/** - * Start a dict in a dbus message. Should be paired with a call to - * {@link nmu_dbus_dict_close_write}. - * - * @param iter A valid dbus message iterator - * @param iter_dict (out) A dict iterator to pass to further dict functions - * @return TRUE on success, FALSE on failure - * - */ -dbus_bool_t -nmu_dbus_dict_open_write (DBusMessageIter *iter, DBusMessageIter *iter_dict) -{ - if (!iter || !iter_dict) - return FALSE; - - return dbus_message_iter_open_container (iter, - DBUS_TYPE_ARRAY, - DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING - DBUS_TYPE_STRING_AS_STRING - DBUS_TYPE_VARIANT_AS_STRING - DBUS_DICT_ENTRY_END_CHAR_AS_STRING, - iter_dict); -} - -/** - * End a dict element in a dbus message. Should be paired with - * a call to {@link nmu_dbus_dict_open_write}. - * - * @param iter valid dbus message iterator, same as passed to - * nmu_dbus_dict_open_write() - * @param iter_dict a dbus dict iterator returned from {@link nmu_dbus_dict_open_write} - * @return TRUE on success, FALSE on failure - * - */ -dbus_bool_t -nmu_dbus_dict_close_write (DBusMessageIter *iter, DBusMessageIter *iter_dict) -{ - if (!iter || !iter_dict) - return FALSE; - - return dbus_message_iter_close_container (iter, iter_dict); -} - - -static const char * -_nmu_get_type_as_string_from_type (const int type) -{ - switch (type) - { - case DBUS_TYPE_BYTE: - return DBUS_TYPE_BYTE_AS_STRING; - case DBUS_TYPE_BOOLEAN: - return DBUS_TYPE_BOOLEAN_AS_STRING; - case DBUS_TYPE_INT16: - return DBUS_TYPE_INT16_AS_STRING; - case DBUS_TYPE_UINT16: - return DBUS_TYPE_UINT16_AS_STRING; - case DBUS_TYPE_INT32: - return DBUS_TYPE_INT32_AS_STRING; - case DBUS_TYPE_UINT32: - return DBUS_TYPE_UINT32_AS_STRING; - case DBUS_TYPE_INT64: - return DBUS_TYPE_INT64_AS_STRING; - case DBUS_TYPE_UINT64: - return DBUS_TYPE_UINT64_AS_STRING; - case DBUS_TYPE_DOUBLE: - return DBUS_TYPE_DOUBLE_AS_STRING; - case DBUS_TYPE_STRING: - return DBUS_TYPE_STRING_AS_STRING; - case DBUS_TYPE_OBJECT_PATH: - return DBUS_TYPE_OBJECT_PATH_AS_STRING; - case DBUS_TYPE_ARRAY: - return DBUS_TYPE_ARRAY_AS_STRING; - default: - return NULL; - } - return NULL; -} - - -static dbus_bool_t -_nmu_dbus_add_dict_entry_start (DBusMessageIter *iter_dict, - DBusMessageIter *iter_dict_entry, - const char *key, - const int value_type) -{ - if (!dbus_message_iter_open_container (iter_dict, - DBUS_TYPE_DICT_ENTRY, - NULL, - iter_dict_entry)) - return FALSE; - - if (!dbus_message_iter_append_basic (iter_dict_entry, DBUS_TYPE_STRING, &key)) - return FALSE; - - return TRUE; -} - - -static dbus_bool_t -_nmu_dbus_add_dict_entry_end (DBusMessageIter *iter_dict, - DBusMessageIter *iter_dict_entry, - DBusMessageIter *iter_dict_val) -{ - if (!dbus_message_iter_close_container (iter_dict_entry, iter_dict_val)) - return FALSE; - if (!dbus_message_iter_close_container (iter_dict, iter_dict_entry)) - return FALSE; - - return TRUE; -} - - -static dbus_bool_t -_nmu_dbus_add_dict_entry_basic (DBusMessageIter *iter_dict, - const char *key, - const int value_type, - const void *value) -{ - DBusMessageIter iter_dict_entry, iter_dict_val; - const char * type_as_string = NULL; - - type_as_string = _nmu_get_type_as_string_from_type (value_type); - if (!type_as_string) - return FALSE; - - if (!_nmu_dbus_add_dict_entry_start (iter_dict, &iter_dict_entry, - key, value_type)) - return FALSE; - - if (!dbus_message_iter_open_container (&iter_dict_entry, - DBUS_TYPE_VARIANT, - type_as_string, - &iter_dict_val)) - return FALSE; - - if (!dbus_message_iter_append_basic (&iter_dict_val, value_type, value)) - return FALSE; - - if (!_nmu_dbus_add_dict_entry_end (iter_dict, &iter_dict_entry, - &iter_dict_val)) - return FALSE; - - return TRUE; -} - - -static dbus_bool_t -_nmu_dbus_add_dict_entry_byte_array (DBusMessageIter *iter_dict, - const char *key, - const char *value, - const dbus_uint32_t value_len) -{ - DBusMessageIter iter_dict_entry, iter_dict_val, iter_array; - dbus_uint32_t i; - - if (!_nmu_dbus_add_dict_entry_start (iter_dict, &iter_dict_entry, - key, DBUS_TYPE_ARRAY)) - return FALSE; - - if (!dbus_message_iter_open_container (&iter_dict_entry, - DBUS_TYPE_VARIANT, - DBUS_TYPE_ARRAY_AS_STRING - DBUS_TYPE_BYTE_AS_STRING, - &iter_dict_val)) - return FALSE; - - if (!dbus_message_iter_open_container (&iter_dict_val, DBUS_TYPE_ARRAY, - DBUS_TYPE_BYTE_AS_STRING, &iter_array)) - return FALSE; - - for (i = 0; i < value_len; i++) - { - if (!dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_BYTE, - &(value[i]))) - return FALSE; - } - - if (!dbus_message_iter_close_container (&iter_dict_val, &iter_array)) - return FALSE; - - if (!_nmu_dbus_add_dict_entry_end (iter_dict, &iter_dict_entry, - &iter_dict_val)) - return FALSE; - - return TRUE; -} - - -static dbus_bool_t -_nmu_dbus_add_dict_entry_string_array (DBusMessageIter *iter_dict, - const char *key, - const char **items, - const dbus_uint32_t num_items) -{ - DBusMessageIter iter_dict_entry, iter_dict_val, iter_array; - dbus_uint32_t i; - - if (!_nmu_dbus_add_dict_entry_start (iter_dict, &iter_dict_entry, - key, DBUS_TYPE_ARRAY)) - return FALSE; - - if (!dbus_message_iter_open_container (&iter_dict_entry, - DBUS_TYPE_VARIANT, - DBUS_TYPE_ARRAY_AS_STRING - DBUS_TYPE_STRING_AS_STRING, - &iter_dict_val)) - return FALSE; - - if (!dbus_message_iter_open_container (&iter_dict_val, DBUS_TYPE_ARRAY, - DBUS_TYPE_BYTE_AS_STRING, &iter_array)) - return FALSE; - - for (i = 0; i < num_items; i++) - { - if (!dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_STRING, - &(items[i]))) - return FALSE; - } - - if (!dbus_message_iter_close_container (&iter_dict_val, &iter_array)) - return FALSE; - - if (!_nmu_dbus_add_dict_entry_end (iter_dict, &iter_dict_entry, - &iter_dict_val)) - return FALSE; - - return TRUE; -} - -/** - * Add a string entry to the dict. - * - * @param iter_dict A valid DBusMessageIter returned from {@link nmu_dbus_dict_open_write} - * @param key The key of the dict item - * @param value The string value - * @return TRUE on success, FALSE on failure - * - */ -dbus_bool_t -nmu_dbus_dict_append_string (DBusMessageIter *iter_dict, - const char * key, - const char * value) -{ - if (!key || !value) return FALSE; - return _nmu_dbus_add_dict_entry_basic (iter_dict, key, DBUS_TYPE_STRING, &value); -} - -/** - * Add a byte entry to the dict. - * - * @param iter_dict A valid DBusMessageIter returned from {@link nmu_dbus_dict_open_write} - * @param key The key of the dict item - * @param value The byte value - * @return TRUE on success, FALSE on failure - * - */ -dbus_bool_t -nmu_dbus_dict_append_byte (DBusMessageIter *iter_dict, - const char * key, - const char value) -{ - if (!key) return FALSE; - return _nmu_dbus_add_dict_entry_basic (iter_dict, key, DBUS_TYPE_BYTE, &value); -} - -/** - * Add a boolean entry to the dict. - * - * @param iter_dict A valid DBusMessageIter returned from {@link nmu_dbus_dict_open_write} - * @param key The key of the dict item - * @param value The boolean value - * @return TRUE on success, FALSE on failure - * - */ -dbus_bool_t -nmu_dbus_dict_append_bool (DBusMessageIter *iter_dict, - const char * key, - const dbus_bool_t value) -{ - if (!key) return FALSE; - return _nmu_dbus_add_dict_entry_basic (iter_dict, key, DBUS_TYPE_BOOLEAN, &value); -} - -/** - * Add a 16-bit signed integer entry to the dict. - * - * @param iter_dict A valid DBusMessageIter returned from {@link nmu_dbus_dict_open_write} - * @param key The key of the dict item - * @param value The 16-bit signed integer value - * @return TRUE on success, FALSE on failure - * - */ -dbus_bool_t -nmu_dbus_dict_append_int16 (DBusMessageIter *iter_dict, - const char * key, - const dbus_int16_t value) -{ - if (!key) return FALSE; - return _nmu_dbus_add_dict_entry_basic (iter_dict, key, DBUS_TYPE_INT16, &value); -} - -/** - * Add a 16-bit unsigned integer entry to the dict. - * - * @param iter_dict A valid DBusMessageIter returned from {@link nmu_dbus_dict_open_write} - * @param key The key of the dict item - * @param value The 16-bit unsigned integer value - * @return TRUE on success, FALSE on failure - * - */ -dbus_bool_t -nmu_dbus_dict_append_uint16 (DBusMessageIter *iter_dict, - const char * key, - const dbus_uint16_t value) -{ - if (!key) return FALSE; - return _nmu_dbus_add_dict_entry_basic (iter_dict, key, DBUS_TYPE_UINT16, &value); -} - -/** - * Add a 32-bit signed integer to the dict. - * - * @param iter_dict A valid DBusMessageIter returned from {@link nmu_dbus_dict_open_write} - * @param key The key of the dict item - * @param value The 32-bit signed integer value - * @return TRUE on success, FALSE on failure - * - */ -dbus_bool_t -nmu_dbus_dict_append_int32 (DBusMessageIter *iter_dict, - const char * key, - const dbus_int32_t value) -{ - if (!key) return FALSE; - return _nmu_dbus_add_dict_entry_basic (iter_dict, key, DBUS_TYPE_INT32, &value); -} - -/** - * Add a 32-bit unsigned integer entry to the dict. - * - * @param iter_dict A valid DBusMessageIter returned from {@link nmu_dbus_dict_open_write} - * @param key The key of the dict item - * @param value The 32-bit unsigned integer value - * @return TRUE on success, FALSE on failure - * - */ -dbus_bool_t -nmu_dbus_dict_append_uint32 (DBusMessageIter *iter_dict, - const char * key, - const dbus_uint32_t value) -{ - if (!key) return FALSE; - return _nmu_dbus_add_dict_entry_basic (iter_dict, key, DBUS_TYPE_UINT32, &value); -} - -/** - * Add a 64-bit integer entry to the dict. - * - * @param iter_dict A valid DBusMessageIter returned from {@link nmu_dbus_dict_open_write} - * @param key The key of the dict item - * @param value The 64-bit integer value - * @return TRUE on success, FALSE on failure - * - */ -dbus_bool_t -nmu_dbus_dict_append_int64 (DBusMessageIter *iter_dict, - const char * key, - const dbus_int64_t value) -{ - if (!key) return FALSE; - return _nmu_dbus_add_dict_entry_basic (iter_dict, key, DBUS_TYPE_INT64, &value); -} - -/** - * Add a 64-bit unsigned integer entry to the dict. - * - * @param iter_dict A valid DBusMessageIter returned from {@link nmu_dbus_dict_open_write} - * @param key The key of the dict item - * @param value The 64-bit unsigned integer value - * @return TRUE on success, FALSE on failure - * - */ -dbus_bool_t -nmu_dbus_dict_append_uint64 (DBusMessageIter *iter_dict, - const char * key, - const dbus_uint64_t value) -{ - if (!key) return FALSE; - return _nmu_dbus_add_dict_entry_basic (iter_dict, key, DBUS_TYPE_UINT64, &value); -} - -/** - * Add a double-precision floating point entry to the dict. - * - * @param iter_dict A valid DBusMessageIter returned from {@link nmu_dbus_dict_open_write} - * @param key The key of the dict item - * @param value The double-precision floating point value - * @return TRUE on success, FALSE on failure - * - */ -dbus_bool_t -nmu_dbus_dict_append_double (DBusMessageIter *iter_dict, - const char * key, - const double value) -{ - if (!key) return FALSE; - return _nmu_dbus_add_dict_entry_basic (iter_dict, key, DBUS_TYPE_DOUBLE, &value); -} - -/** - * Add a DBus object path entry to the dict. - * - * @param iter_dict A valid DBusMessageIter returned from {@link nmu_dbus_dict_open_write} - * @param key The key of the dict item - * @param value The DBus object path value - * @return TRUE on success, FALSE on failure - * - */ -dbus_bool_t -nmu_dbus_dict_append_object_path (DBusMessageIter *iter_dict, - const char * key, - const char * value) -{ - if (!key || !value) return FALSE; - return _nmu_dbus_add_dict_entry_basic (iter_dict, key, DBUS_TYPE_OBJECT_PATH, &value); -} - -/** - * Add a byte array entry to the dict. - * - * @param iter_dict A valid DBusMessageIter returned from {@link nmu_dbus_dict_open_write} - * @param key The key of the dict item - * @param value The byte array - * @param value_len The length of the byte array, in bytes - * @return TRUE on success, FALSE on failure - * - */ -dbus_bool_t -nmu_dbus_dict_append_byte_array (DBusMessageIter *iter_dict, - const char * key, - const char * value, - const dbus_uint32_t value_len) -{ - if (!key) return FALSE; - if (!value && (value_len != 0)) return FALSE; - return _nmu_dbus_add_dict_entry_byte_array (iter_dict, key, value, value_len); -} - - -/** - * Add a string array entry to the dict. - * - * @param iter_dict A valid DBusMessageIter returned from {@link nmu_dbus_dict_open_write} - * @param key The key of the dict item - * @param items The array of strings - * @param num_items The number of strings in the array - * @return TRUE on success, FALSE on failure - * - */ -dbus_bool_t -nmu_dbus_dict_append_string_array (DBusMessageIter *iter_dict, - const char * key, - const char ** items, - const dbus_uint32_t num_items) -{ - if (!key) return FALSE; - if (!items && (num_items != 0)) return FALSE; - return _nmu_dbus_add_dict_entry_string_array (iter_dict, key, items, num_items); -} - diff --git a/vpn-daemons/pptp/src/nm-utils.h b/vpn-daemons/pptp/src/nm-utils.h deleted file mode 100644 index 8eb3de105a..0000000000 --- a/vpn-daemons/pptp/src/nm-utils.h +++ /dev/null @@ -1,210 +0,0 @@ -/* NetworkManager -- Network link manager - * - * Ray Strode - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * (C) Copyright 2005 Red Hat, Inc. - */ - -#ifndef NM_UTILS_H -#define NM_UTILS_H - -#include -#include - -#define nm_print_backtrace() \ -G_STMT_START \ -{ \ - void *_call_stack[512]; \ - int _call_stack_size; \ - char **_symbols; \ - _call_stack_size = backtrace (_call_stack, \ - G_N_ELEMENTS (_call_stack)); \ - _symbols = backtrace_symbols (_call_stack, _call_stack_size); \ - if (_symbols != NULL) \ - { \ - int _i; \ - _i = 0; \ - g_critical ("traceback:\n"); \ - while (_i < _call_stack_size) \ - { \ - g_critical ("\t%s\n", _symbols[_i]); \ - _i++; \ - } \ - free (_symbols); \ - } \ -} \ -G_STMT_END - -#define nm_get_timestamp(timestamp) \ -G_STMT_START \ -{ \ - GTimeVal _tv; \ - g_get_current_time (&_tv); \ - *timestamp = (_tv.tv_sec * (1.0 * G_USEC_PER_SEC) + \ - _tv.tv_usec) / G_USEC_PER_SEC; \ -} \ -G_STMT_END - -#define nm_info(fmt, args...) \ -G_STMT_START \ -{ \ - g_message ("\t" fmt "\n", ##args); \ -} G_STMT_END - -#define nm_info_str(fmt_str, args...) \ -G_STMT_START \ -{ \ - g_message ("\t%s\n", fmt_str, ##args); \ -} G_STMT_END - -#define nm_debug(fmt, args...) \ -G_STMT_START \ -{ \ - gdouble _timestamp; \ - nm_get_timestamp (&_timestamp); \ - g_debug ("\t[%f] %s (): " fmt "\n", _timestamp, \ - G_STRFUNC, ##args); \ -} G_STMT_END - -#define nm_debug_str(fmt_str, args...) \ -G_STMT_START \ -{ \ - gdouble _timestamp; \ - nm_get_timestamp (&_timestamp); \ - g_debug ("\t[%f] %s (): %s\n", _timestamp, \ - G_STRFUNC, fmt_str, ##args); \ -} G_STMT_END - -#define nm_warning(fmt, args...) \ -G_STMT_START \ -{ \ - g_warning ("\t %s (): " fmt "\n", \ - G_STRFUNC, ##args); \ -} G_STMT_END - -#define nm_warning_str(fmt_str, args...) \ -G_STMT_START \ -{ \ - g_warning ("\t %s (): %s\n", \ - G_STRFUNC, fmt_str, ##args); \ -} G_STMT_END - -#define nm_error(fmt, args...) \ -G_STMT_START \ -{ \ - gdouble _timestamp; \ - nm_get_timestamp (&_timestamp); \ - g_critical ("\t[%f] %s (): " fmt "\n", _timestamp, \ - G_STRFUNC, ##args); \ - nm_print_backtrace (); \ - G_BREAKPOINT (); \ -} G_STMT_END - -#define nm_error_str(fmt_str, args...) \ -G_STMT_START \ -{ \ - gdouble _timestamp; \ - nm_get_timestamp (&_timestamp); \ - g_critical ("\t[%f] %s (): %s\n", _timestamp, \ - G_STRFUNC, fmt_str, ##args); \ - nm_print_backtrace (); \ - G_BREAKPOINT (); \ -} G_STMT_END - -gchar *nm_dbus_escape_object_path (const gchar *utf8_string); -gchar *nm_dbus_unescape_object_path (const gchar *object_path); - -/* - * Adding a dict to a DBusMessage - */ - -dbus_bool_t -nmu_dbus_dict_open_write (DBusMessageIter *iter, - DBusMessageIter *iter_dict); - -dbus_bool_t -nmu_dbus_dict_close_write (DBusMessageIter *iter, - DBusMessageIter *iter_dict); - -dbus_bool_t -nmu_dbus_dict_append_string (DBusMessageIter *iter_dict, - const char * key, - const char * value); - -dbus_bool_t -nmu_dbus_dict_append_byte (DBusMessageIter *iter_dict, - const char * key, - const char value); - -dbus_bool_t -nmu_dbus_dict_append_bool (DBusMessageIter *iter_dict, - const char * key, - const dbus_bool_t value); - -dbus_bool_t -nmu_dbus_dict_append_int16 (DBusMessageIter *iter_dict, - const char * key, - const dbus_int16_t value); - -dbus_bool_t -nmu_dbus_dict_append_uint16 (DBusMessageIter *iter_dict, - const char * key, - const dbus_uint16_t value); - -dbus_bool_t -nmu_dbus_dict_append_int32 (DBusMessageIter *iter_dict, - const char * key, - const dbus_int32_t value); - -dbus_bool_t -nmu_dbus_dict_append_uint32 (DBusMessageIter *iter_dict, - const char * key, - const dbus_uint32_t value); - -dbus_bool_t -nmu_dbus_dict_append_int64 (DBusMessageIter *iter_dict, - const char * key, - const dbus_int64_t value); - -dbus_bool_t -nmu_dbus_dict_append_uint64 (DBusMessageIter *iter_dict, - const char * key, - const dbus_uint64_t value); - -dbus_bool_t -nmu_dbus_dict_append_double (DBusMessageIter *iter_dict, - const char * key, - const double value); - -dbus_bool_t -nmu_dbus_dict_append_object_path (DBusMessageIter *iter_dict, - const char * key, - const char * value); - -dbus_bool_t -nmu_dbus_dict_append_byte_array (DBusMessageIter *iter_dict, - const char * key, - const char * value, - const dbus_uint32_t value_len); - -dbus_bool_t -nmu_dbus_dict_append_string_array (DBusMessageIter *iter_dict, - const char * key, - const char ** items, - const dbus_uint32_t num_items); - -#endif /* NM_UTILS_H */