From 25e0af63e8141c74650eb0ef1b3b78087aef7636 Mon Sep 17 00:00:00 2001 From: Antony Mee Date: Wed, 21 Dec 2005 21:50:07 +0000 Subject: [PATCH] Initial check in on NetworkManager PPTP VPN plugin (used pppd) git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1220 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- vpn-daemons/pptp/AUTHORS | 5 + vpn-daemons/pptp/ChangeLog | 4 + vpn-daemons/pptp/Makefile.am | 28 + vpn-daemons/pptp/NEWS | 0 vpn-daemons/pptp/README | 15 + vpn-daemons/pptp/TODO | 105 ++ vpn-daemons/pptp/acinclude.m4 | 45 + vpn-daemons/pptp/auth-dialog/.cvsignore | 3 + vpn-daemons/pptp/auth-dialog/Makefile.am | 33 + .../auth-dialog/gnome-two-password-dialog.c | 745 +++++++++ .../auth-dialog/gnome-two-password-dialog.h | 116 ++ vpn-daemons/pptp/auth-dialog/main.c | 290 ++++ vpn-daemons/pptp/autogen.sh | 23 + vpn-daemons/pptp/configure.in | 131 ++ .../example-pptp-system-wide-connection.sh | 25 + ...gnome-mime-application-x-pptp-settings.png | Bin 0 -> 2595 bytes vpn-daemons/pptp/intltool-extract.in | 839 ++++++++++ vpn-daemons/pptp/intltool-merge.in | 1356 +++++++++++++++++ vpn-daemons/pptp/intltool-update.in | 1065 +++++++++++++ vpn-daemons/pptp/nm-pptp-service.conf | 16 + vpn-daemons/pptp/nm-pptp-service.name.in | 8 + vpn-daemons/pptp/nm-pptp.desktop.in | 12 + vpn-daemons/pptp/po/.cvsignore | 7 + vpn-daemons/pptp/po/ChangeLog | 10 + vpn-daemons/pptp/po/POTFILES.in | 10 + vpn-daemons/pptp/po/da.po | 233 +++ vpn-daemons/pptp/po/sv.po | 246 +++ vpn-daemons/pptp/properties/.cvsignore | 2 + vpn-daemons/pptp/properties/Makefile.am | 33 + .../pptp/properties/nm-pptp-dialog.glade | 778 ++++++++++ vpn-daemons/pptp/properties/nm-pptp.c | 749 +++++++++ vpn-daemons/pptp/src/.cvsignore | 4 + vpn-daemons/pptp/src/Makefile.am | 42 + .../pptp/src/nm-pptp-service-pppd-plugin.c | 243 +++ vpn-daemons/pptp/src/nm-pptp-service.c | 1136 ++++++++++++++ vpn-daemons/pptp/src/nm-pptp-service.h | 30 + vpn-daemons/pptp/src/nm-utils.c | 132 ++ vpn-daemons/pptp/src/nm-utils.h | 131 ++ vpn-daemons/pptp/src/pppd/fsm.h | 168 ++ vpn-daemons/pptp/src/pppd/ipcp.h | 96 ++ vpn-daemons/pptp/src/pppd/patchlevel.h | 4 + vpn-daemons/pptp/src/pppd/pppd.h | 910 +++++++++++ 42 files changed, 9828 insertions(+) create mode 100644 vpn-daemons/pptp/AUTHORS create mode 100644 vpn-daemons/pptp/ChangeLog create mode 100644 vpn-daemons/pptp/Makefile.am create mode 100644 vpn-daemons/pptp/NEWS create mode 100644 vpn-daemons/pptp/README create mode 100644 vpn-daemons/pptp/TODO create mode 100644 vpn-daemons/pptp/acinclude.m4 create mode 100644 vpn-daemons/pptp/auth-dialog/.cvsignore create mode 100644 vpn-daemons/pptp/auth-dialog/Makefile.am create mode 100644 vpn-daemons/pptp/auth-dialog/gnome-two-password-dialog.c create mode 100644 vpn-daemons/pptp/auth-dialog/gnome-two-password-dialog.h create mode 100644 vpn-daemons/pptp/auth-dialog/main.c create mode 100755 vpn-daemons/pptp/autogen.sh create mode 100644 vpn-daemons/pptp/configure.in create mode 100755 vpn-daemons/pptp/doc/example-pptp-system-wide-connection.sh create mode 100644 vpn-daemons/pptp/gnome-mime-application-x-pptp-settings.png create mode 100755 vpn-daemons/pptp/intltool-extract.in create mode 100755 vpn-daemons/pptp/intltool-merge.in create mode 100755 vpn-daemons/pptp/intltool-update.in create mode 100644 vpn-daemons/pptp/nm-pptp-service.conf create mode 100644 vpn-daemons/pptp/nm-pptp-service.name.in create mode 100644 vpn-daemons/pptp/nm-pptp.desktop.in create mode 100644 vpn-daemons/pptp/po/.cvsignore create mode 100644 vpn-daemons/pptp/po/ChangeLog create mode 100644 vpn-daemons/pptp/po/POTFILES.in create mode 100644 vpn-daemons/pptp/po/da.po create mode 100644 vpn-daemons/pptp/po/sv.po create mode 100644 vpn-daemons/pptp/properties/.cvsignore create mode 100644 vpn-daemons/pptp/properties/Makefile.am create mode 100644 vpn-daemons/pptp/properties/nm-pptp-dialog.glade create mode 100644 vpn-daemons/pptp/properties/nm-pptp.c create mode 100644 vpn-daemons/pptp/src/.cvsignore create mode 100644 vpn-daemons/pptp/src/Makefile.am create mode 100644 vpn-daemons/pptp/src/nm-pptp-service-pppd-plugin.c create mode 100644 vpn-daemons/pptp/src/nm-pptp-service.c create mode 100644 vpn-daemons/pptp/src/nm-pptp-service.h create mode 100644 vpn-daemons/pptp/src/nm-utils.c create mode 100644 vpn-daemons/pptp/src/nm-utils.h create mode 100644 vpn-daemons/pptp/src/pppd/fsm.h create mode 100644 vpn-daemons/pptp/src/pppd/ipcp.h create mode 100644 vpn-daemons/pptp/src/pppd/patchlevel.h create mode 100644 vpn-daemons/pptp/src/pppd/pppd.h diff --git a/vpn-daemons/pptp/AUTHORS b/vpn-daemons/pptp/AUTHORS new file mode 100644 index 0000000000..8a757faa86 --- /dev/null +++ b/vpn-daemons/pptp/AUTHORS @@ -0,0 +1,5 @@ +Antony Mee +Tim Niemueller +Dan Williams +David Zeuthen + diff --git a/vpn-daemons/pptp/ChangeLog b/vpn-daemons/pptp/ChangeLog new file mode 100644 index 0000000000..fdfe536752 --- /dev/null +++ b/vpn-daemons/pptp/ChangeLog @@ -0,0 +1,4 @@ +2005-11-17 Antony Mee + + * started work based on openvpn work + diff --git a/vpn-daemons/pptp/Makefile.am b/vpn-daemons/pptp/Makefile.am new file mode 100644 index 0000000000..cfd71261b5 --- /dev/null +++ b/vpn-daemons/pptp/Makefile.am @@ -0,0 +1,28 @@ +AUTOMAKE_OPTIONS = foreign + +SUBDIRS = src auth-dialog properties po + +dbusservicedir = $(sysconfdir)/dbus-1/system.d +dbusservice_DATA = nm-pptp-service.conf + +nmvpnservicedir = $(sysconfdir)/NetworkManager/VPN +nmvpnservice_DATA = nm-pptp-service.name + +desktopdir = $(datadir)/applications +desktop_in_files = nm-pptp.desktop.in +desktop_DATA = $(desktop_in_files:.desktop.in=.desktop) +@INTLTOOL_DESKTOP_RULE@ + +icondir = $(datadir)/icons/hicolor/48x48/apps +icon_DATA = gnome-mime-application-x-pptp-settings.png + +EXTRA_DIST = $(nmvpnservice_DATA) \ + $(dbusservice_DATA) \ + $(desktop_in_files) \ + $(icon_DATA) \ + intltool-extract.in \ + intltool-merge.in \ + intltool-update.in + +CLEANFILES = $(desktop_DATA) *~ +DISTCLEANFILES = intltool-extract intltool-merge intltool-update diff --git a/vpn-daemons/pptp/NEWS b/vpn-daemons/pptp/NEWS new file mode 100644 index 0000000000..e69de29bb2 diff --git a/vpn-daemons/pptp/README b/vpn-daemons/pptp/README new file mode 100644 index 0000000000..39c577d633 --- /dev/null +++ b/vpn-daemons/pptp/README @@ -0,0 +1,15 @@ +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 + +Code released under the GPL. See COPYING file in the NetworkManager +directory. + +Aachen, 2005/11/12 + diff --git a/vpn-daemons/pptp/TODO b/vpn-daemons/pptp/TODO new file mode 100644 index 0000000000..8df2055bca --- /dev/null +++ b/vpn-daemons/pptp/TODO @@ -0,0 +1,105 @@ + + + +Hi Nikolaus, + +Yes, I've did quite a bit of work on it. Infact I totally revamped it to use a pppd plugin as it's helper. (Thus is can do the DNS + routing without modifications to your local /etc/ppp files) + +Actually there is one exception... Many distros have an ip-up script which implements usepeerdns functionality thus replacing resolve.conf... This conflicts with NetworkManager's actions so may need to be removed. Sadly there appears to be no way to tell pppd NOT to execute /etc/ppp/ip-up if it exists! + +Uses a pppd plugin to handle CHAP authentication (not sure of the V2 implications...) and ip-up functionality... It explicitly resolves the IP of the vpn server before starting pppd. And starts pppd with the pty option rather than letting pptp start pppd (as recomented by the pptp maintainer). + +Sadly, I haven't quite figured out how I'm gonna get the username and password from the vpn-daemon to the pppd helper plugin infact I've just got my credentials hard coded in the plugin for testing! +The reason I haven't fixed that is that there is another strange behaviour where by the pptp vpn daemon (sometimes!) takes NM down when it exits!! It seems to seg fault but I can't find the cause. I've been really busy but would love somone to take a look at this. I can upload it in it's present state with instructions for where to insert your credentials if you/anyone else would be willing to try it and perhaps assist me. + +tOnY + + +Nikolaus Filus wrote: + +> Hi, +> +> I just managed to get your pptp plugin "working" for my university setup. It was a hard piece of work, since I'm not familiar with NM or pptp details. There are several issues to be fixed and I hope this report will be usefull for you. I don't attach patches as my modifications are just hacks :) +> +> 1. nm-pptp-service-pptp-helper +> The while-loop doesn't work, as I wasn't able to find a place, where +> foreign_option_%i shall be defined. It seems to me as if this code is incomplete and you wanted to scan through the whole environment and +> analyse the options. I had to manually add parsing of DNS, DNS1 and DNS2 which are set in my environment, or my resolv.conf is empty after connecting to the vpn. +> +> 2. nm-pptp-service +> encrypt-mppe was never attached to my pppd options and I had to add +> +> g_ptr_array_add (pptp_argv, (gpointer) "require-mschap-v2"); +> g_ptr_array_add (pptp_argv, (gpointer) "mppe"); +> g_ptr_array_add (pptp_argv, (gpointer) "required,stateless"); +> +> outside the for-loop. As you can see, I also need the "require-mschap-v2" option. For this to work I need to specify a special remotename, which is NOT the hostname, as used in your code. This also requires a second line +> in chap-secrets. +> +> 3. configuration +> By default a new default route to ppp0 is specified, deleting the old one. I need to preserve it (by setting vpn-routes to 0.0.0.0/0) and add +> +> route add -host vpn-gw dev eth1 +> route add default dev ppp0 +> +> manually. +> +> +> With this modifications, I was able to connect the vpn at my university "using" networkmanager. +> +> +> Are you working on the pppd plugin as announced on the mailinglist? I would be glad to test it :) +> +> +> Thanks for your work +> +> Nikolaus Filus +> +> +> + + + + + +Dan Williams wrote: + +> But in your case, the pppd-vpn-service daemon could just do whatever it +> does to start the connection, but provide a dbus service that when +> called, returns the password and username. The pppd plugin would then +> call this dbus service and request the pass & user. +> +> +> +That is precisely what I intend and started implementing it. I just wanted to fix the strange and 'intermittent' segfault before +adding anymore complexity. + +I only hesitated when naming the dbus service. + +> There are some things to think hard about here though, namely the +> security of it. If you have a daemon providing a dbus service, unless +> you lock it down anyone can call its methods. So you'd have to make +> sure that you lock down the dbus policy for the service-daemon pretty +> tight. If you restrict it to just 'root'/uid 0, any root app could ask +> for the user and password. But then again, any 'root' app can do +> horrible things to your system anyway. So this might be an acceptable +> course of action. +> +> +I imagined that root access would be sufficient in this case too. I suppose +the only other way is for the vpn-daemon to pass some secret cookie to the +pppd on start up that the plugin then uses when asking for the user/pass later +but that too would open all kinds of security holes I suppose. + +Anyway... A root process could overwrite the pppd plugin in /usr/lib with +something malicious so I can't see any possible gain. Just as a root process could +overwrite the vpnc binary with a script which 'tee' s the standard input to a file :-) + +> Ideally this could be solved upstream in pppd. But at some point you +> simply do best-effort to hide the username & password from view, keep +> investigating how to do it better, and fix it a bit later. +> +> +Exactly. "Just works" not "Will at some future time just work" right :-) + +tOnY diff --git a/vpn-daemons/pptp/acinclude.m4 b/vpn-daemons/pptp/acinclude.m4 new file mode 100644 index 0000000000..571b4fc57f --- /dev/null +++ b/vpn-daemons/pptp/acinclude.m4 @@ -0,0 +1,45 @@ + +dnl as-ac-expand.m4 0.1.0 +dnl autostars m4 macro for expanding directories using configure's prefix +dnl thomas@apestaart.org + +dnl AS_AC_EXPAND(VAR, CONFIGURE_VAR) +dnl +dnl example +dnl AS_AC_EXPAND(SYSCONFDIR, $sysconfdir) +dnl will set SYSCONFDIR to /usr/local/etc if prefix=/usr/local + +AC_DEFUN(AS_AC_EXPAND, +[ + EXP_VAR=[$1] + FROM_VAR=[$2] + + dnl first expand prefix and exec_prefix if necessary + prefix_save=$prefix + exec_prefix_save=$exec_prefix + + dnl if no prefix given, then use /usr/local, the default prefix + if test "x$prefix" = "xNONE"; then + prefix=$ac_default_prefix + fi + dnl if no exec_prefix given, then use prefix + if test "x$exec_prefix" = "xNONE"; then + exec_prefix=$prefix + fi + + full_var="$FROM_VAR" + dnl loop until it doesn't change anymore + while true; do + new_full_var="`eval echo $full_var`" + if test "x$new_full_var"="x$full_var"; then break; fi + full_var=$new_full_var + done + + dnl clean up + full_var=$new_full_var + AC_SUBST([$1], "$full_var") + + dnl restore prefix and exec_prefix + prefix=$prefix_save + exec_prefix=$exec_prefix_save +]) diff --git a/vpn-daemons/pptp/auth-dialog/.cvsignore b/vpn-daemons/pptp/auth-dialog/.cvsignore new file mode 100644 index 0000000000..60aac6c80f --- /dev/null +++ b/vpn-daemons/pptp/auth-dialog/.cvsignore @@ -0,0 +1,3 @@ +Makefile.in +Makefile +nm-pptp-auth-dialog diff --git a/vpn-daemons/pptp/auth-dialog/Makefile.am b/vpn-daemons/pptp/auth-dialog/Makefile.am new file mode 100644 index 0000000000..bf405bfad0 --- /dev/null +++ b/vpn-daemons/pptp/auth-dialog/Makefile.am @@ -0,0 +1,33 @@ +INCLUDES = -I${top_srcdir} -I${top_srcdir}/utils + +libexec_PROGRAMS = nm-pptp-auth-dialog + +nm_pptp_auth_dialog_CPPFLAGS = \ + $(GTHREAD_CFLAGS) \ + $(GTK_CFLAGS) \ + $(LIBGNOMEUI_CFLAGS) \ + $(GNOMEKEYRING_CFLAGS) \ + -DICONDIR=\""$(datadir)/pixmaps"\" \ + -DGLADEDIR=\""$(gladedir)"\" \ + -DBINDIR=\""$(bindir)"\" \ + -DDBUS_API_SUBJECT_TO_CHANGE \ + -DG_DISABLE_DEPRECATED \ + -DGDK_DISABLE_DEPRECATED \ + -DGNOME_DISABLE_DEPRECATED \ + -DGNOMELOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \ + -DVERSION=\"$(VERSION)\" \ + $(NULL) + +nm_pptp_auth_dialog_SOURCES = \ + main.c \ + gnome-two-password-dialog.c \ + gnome-two-password-dialog.h \ + $(NULL) + +nm_pptp_auth_dialog_LDADD = \ + $(GTK_LIBS) \ + $(LIBGNOMEUI_LIBS) \ + $(GNOMEKEYRING_LIBS) \ + $(NULL) + +CLEANFILES = *~ diff --git a/vpn-daemons/pptp/auth-dialog/gnome-two-password-dialog.c b/vpn-daemons/pptp/auth-dialog/gnome-two-password-dialog.c new file mode 100644 index 0000000000..94d1faa23d --- /dev/null +++ b/vpn-daemons/pptp/auth-dialog/gnome-two-password-dialog.c @@ -0,0 +1,745 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* gnome-password-dialog.c - A use password prompting dialog widget. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library 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 ree Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library 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: Ramiro Estrugo +*/ + +#include +//#include "gnome-i18nP.h" +#include "gnome-two-password-dialog.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + + +struct GnomeTwoPasswordDialogDetails +{ + /* Attributes */ + gboolean readonly_username; + gboolean readonly_domain; + + gboolean show_username; + gboolean show_domain; + gboolean show_password; + gboolean show_password_secondary; + + /* TODO: */ + gboolean remember; + char *remember_label_text; + + /* Internal widgetry and flags */ + GtkWidget *username_entry; + GtkWidget *password_entry; + GtkWidget *password_entry_secondary; + GtkWidget *domain_entry; + + GtkWidget *table; + + GtkWidget *remember_session_button; + GtkWidget *remember_forever_button; + + GtkWidget *radio_vbox; + GtkWidget *connect_with_no_userpass_button; + GtkWidget *connect_with_userpass_button; + + gboolean anon_support_on; + + char *secondary_password_label; +}; + +/* Caption table rows indices */ +static const guint CAPTION_TABLE_USERNAME_ROW = 0; +static const guint CAPTION_TABLE_PASSWORD_ROW = 1; + +/* Layout constants */ +static const guint DIALOG_BORDER_WIDTH = 6; +static const guint CAPTION_TABLE_BORDER_WIDTH = 4; + +/* GnomeTwoPasswordDialogClass methods */ +static void gnome_two_password_dialog_class_init (GnomeTwoPasswordDialogClass *password_dialog_class); +static void gnome_two_password_dialog_init (GnomeTwoPasswordDialog *password_dialog); + +/* GObjectClass methods */ +static void gnome_two_password_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; + +GtkType +gnome_two_password_dialog_get_type (void) +{ + static GType type = 0; + + if (!type) { + static const GTypeInfo info = { + sizeof (GnomeTwoPasswordDialogClass), + NULL, NULL, + (GClassInitFunc) gnome_two_password_dialog_class_init, + NULL, NULL, + sizeof (GnomeTwoPasswordDialog), 0, + (GInstanceInitFunc) gnome_two_password_dialog_init, + NULL + }; + + type = g_type_register_static (gtk_dialog_get_type(), + "GnomeTwoPasswordDialog", + &info, 0); + + parent_class = g_type_class_ref (gtk_dialog_get_type()); + } + + return type; +} + + +static void +gnome_two_password_dialog_class_init (GnomeTwoPasswordDialogClass * klass) +{ + G_OBJECT_CLASS (klass)->finalize = gnome_two_password_dialog_finalize; +} + +static void +gnome_two_password_dialog_init (GnomeTwoPasswordDialog *password_dialog) +{ + password_dialog->details = g_new0 (GnomeTwoPasswordDialogDetails, 1); + password_dialog->details->show_username = TRUE; + password_dialog->details->show_password = TRUE; + password_dialog->details->show_password_secondary = TRUE; + password_dialog->details->anon_support_on = FALSE; + + password_dialog->details->secondary_password_label = g_strdup ( _("_Secondary Password:") ); +} + +/* GObjectClass methods */ +static void +gnome_two_password_dialog_finalize (GObject *object) +{ + GnomeTwoPasswordDialog *password_dialog; + + password_dialog = GNOME_TWO_PASSWORD_DIALOG (object); + + g_object_unref (password_dialog->details->username_entry); + g_object_unref (password_dialog->details->domain_entry); + g_object_unref (password_dialog->details->password_entry); + g_object_unref (password_dialog->details->password_entry_secondary); + + g_free (password_dialog->details->remember_label_text); + g_free (password_dialog->details); + + g_free (password_dialog->details->secondary_password_label); + + if (G_OBJECT_CLASS (parent_class)->finalize != NULL) + (* G_OBJECT_CLASS (parent_class)->finalize) (object); +} + +/* GtkDialog callbacks */ +static void +dialog_show_callback (GtkWidget *widget, gpointer callback_data) +{ + GnomeTwoPasswordDialog *password_dialog; + + password_dialog = GNOME_TWO_PASSWORD_DIALOG (callback_data); + + if (GTK_WIDGET_VISIBLE (password_dialog->details->username_entry) && + !password_dialog->details->readonly_username) { + gtk_widget_grab_focus (password_dialog->details->username_entry); + } else if (GTK_WIDGET_VISIBLE (password_dialog->details->domain_entry) && + !password_dialog->details->readonly_domain) { + gtk_widget_grab_focus (password_dialog->details->domain_entry); + } else if (GTK_WIDGET_VISIBLE (password_dialog->details->password_entry)) { + gtk_widget_grab_focus (password_dialog->details->password_entry); + } else if (GTK_WIDGET_VISIBLE (password_dialog->details->password_entry_secondary)) { + gtk_widget_grab_focus (password_dialog->details->password_entry_secondary); + } +} + +static void +dialog_close_callback (GtkWidget *widget, gpointer callback_data) +{ + gtk_widget_hide (widget); +} + +static void +userpass_radio_button_clicked (GtkWidget *widget, gpointer callback_data) +{ + GnomeTwoPasswordDialog *password_dialog; + + password_dialog = GNOME_TWO_PASSWORD_DIALOG (callback_data); + + if (widget == password_dialog->details->connect_with_no_userpass_button) { + gtk_widget_set_sensitive ( + password_dialog->details->table, FALSE); + } + else { /* the other button */ + gtk_widget_set_sensitive ( + password_dialog->details->table, TRUE); + } +} + +static void +add_row (GtkWidget *table, int row, const char *label_text, GtkWidget *entry, int offset) +{ + GtkWidget *label; + + label = gtk_label_new_with_mnemonic (label_text); + gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); + + gtk_table_attach (GTK_TABLE (table), label, + 0, 1, + row, row + 1, + GTK_FILL, + (GTK_FILL|GTK_EXPAND), + offset, 0); + + gtk_table_attach (GTK_TABLE (table), entry, + 1, 2, + row, row + 1, + (GTK_FILL|GTK_EXPAND), + (GTK_FILL|GTK_EXPAND), + 0, 0); + + gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry); +} + +static void +remove_child (GtkWidget *child, GtkWidget *table) +{ + gtk_container_remove (GTK_CONTAINER (table), child); +} + +static void +add_table_rows (GnomeTwoPasswordDialog *password_dialog) +{ + int row; + GtkWidget *table; + int offset; + + if (password_dialog->details->anon_support_on) { + offset = 20; + } + else { + offset = 0; + } + + table = password_dialog->details->table; + /* This will not kill the entries, since they are ref:ed */ + gtk_container_foreach (GTK_CONTAINER (table), + (GtkCallback)remove_child, table); + + row = 0; + if (password_dialog->details->show_username) + add_row (table, row++, _("_Username:"), password_dialog->details->username_entry, offset); + if (password_dialog->details->show_domain) + add_row (table, row++, _("_Domain:"), password_dialog->details->domain_entry, offset); + if (password_dialog->details->show_password) + add_row (table, row++, _("_Password:"), password_dialog->details->password_entry, offset); + if (password_dialog->details->show_password_secondary) + add_row (table, row++, password_dialog->details->secondary_password_label, + password_dialog->details->password_entry_secondary, offset); + + gtk_widget_show_all (table); +} + +static void +username_entry_activate (GtkWidget *widget, GtkWidget *dialog) +{ + GnomeTwoPasswordDialog *password_dialog; + + password_dialog = GNOME_TWO_PASSWORD_DIALOG (dialog); + + if (GTK_WIDGET_VISIBLE (password_dialog->details->domain_entry) && + GTK_WIDGET_SENSITIVE (password_dialog->details->domain_entry)) + gtk_widget_grab_focus (password_dialog->details->domain_entry); + else if (GTK_WIDGET_VISIBLE (password_dialog->details->password_entry) && + GTK_WIDGET_SENSITIVE (password_dialog->details->password_entry)) + gtk_widget_grab_focus (password_dialog->details->password_entry); + else if (GTK_WIDGET_VISIBLE (password_dialog->details->password_entry_secondary) && + GTK_WIDGET_SENSITIVE (password_dialog->details->password_entry_secondary)) + gtk_widget_grab_focus (password_dialog->details->password_entry_secondary); +} + +static void +domain_entry_activate (GtkWidget *widget, GtkWidget *dialog) +{ + GnomeTwoPasswordDialog *password_dialog; + + password_dialog = GNOME_TWO_PASSWORD_DIALOG (dialog); + + if (GTK_WIDGET_VISIBLE (password_dialog->details->password_entry) && + GTK_WIDGET_SENSITIVE (password_dialog->details->password_entry)) + gtk_widget_grab_focus (password_dialog->details->password_entry); + else if (GTK_WIDGET_VISIBLE (password_dialog->details->password_entry_secondary) && + GTK_WIDGET_SENSITIVE (password_dialog->details->password_entry_secondary)) + gtk_widget_grab_focus (password_dialog->details->password_entry_secondary); +} + + +/* Public GnomeTwoPasswordDialog methods */ +GtkWidget * +gnome_two_password_dialog_new (const char *dialog_title, + const char *message, + const char *username, + const char *password, + gboolean readonly_username) +{ + GnomeTwoPasswordDialog *password_dialog; + GtkWidget *table; + GtkLabel *message_label; + GtkWidget *hbox; + GtkWidget *vbox; + GtkWidget *dialog_icon; + GSList *group; + + password_dialog = GNOME_TWO_PASSWORD_DIALOG (gtk_widget_new (gnome_two_password_dialog_get_type (), NULL)); + + gtk_window_set_title (GTK_WINDOW (password_dialog), dialog_title); + gtk_dialog_add_buttons (GTK_DIALOG (password_dialog), + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_OK, + NULL); + + /* Setup the dialog */ + gtk_dialog_set_has_separator (GTK_DIALOG (password_dialog), FALSE); + + gtk_window_set_position (GTK_WINDOW (password_dialog), GTK_WIN_POS_CENTER); + gtk_window_set_modal (GTK_WINDOW (password_dialog), TRUE); + + gtk_container_set_border_width (GTK_CONTAINER (password_dialog), DIALOG_BORDER_WIDTH); + + gtk_dialog_set_default_response (GTK_DIALOG (password_dialog), GTK_RESPONSE_OK); + + g_signal_connect (password_dialog, "show", + G_CALLBACK (dialog_show_callback), password_dialog); + g_signal_connect (password_dialog, "close", + G_CALLBACK (dialog_close_callback), password_dialog); + + /* the radio buttons for anonymous login */ + password_dialog->details->connect_with_no_userpass_button = + gtk_radio_button_new_with_mnemonic (NULL, _("Connect _anonymously")); + group = gtk_radio_button_get_group ( + GTK_RADIO_BUTTON (password_dialog->details->connect_with_no_userpass_button)); + password_dialog->details->connect_with_userpass_button = + gtk_radio_button_new_with_mnemonic ( + group, _("Connect as _user:")); + + if (username != NULL && *username != 0) { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (password_dialog->details->connect_with_userpass_button), TRUE); + } else { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (password_dialog->details->connect_with_no_userpass_button), TRUE); + } + + + password_dialog->details->radio_vbox = gtk_vbox_new (FALSE, 0); + gtk_box_pack_start (GTK_BOX (password_dialog->details->radio_vbox), + password_dialog->details->connect_with_no_userpass_button, + FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (password_dialog->details->radio_vbox), + password_dialog->details->connect_with_userpass_button, + FALSE, FALSE, 0); + g_signal_connect (password_dialog->details->connect_with_no_userpass_button, "clicked", + G_CALLBACK (userpass_radio_button_clicked), password_dialog); + g_signal_connect (password_dialog->details->connect_with_userpass_button, "clicked", + G_CALLBACK (userpass_radio_button_clicked), password_dialog); + + /* The table that holds the captions */ + password_dialog->details->table = table = gtk_table_new (3, 2, FALSE); + gtk_table_set_col_spacings (GTK_TABLE (table), 12); + gtk_table_set_row_spacings (GTK_TABLE (table), 6); + + password_dialog->details->username_entry = gtk_entry_new (); + password_dialog->details->domain_entry = gtk_entry_new (); + password_dialog->details->password_entry = gtk_entry_new (); + password_dialog->details->password_entry_secondary = gtk_entry_new (); + + /* We want to hold on to these during the table rearrangement */ + g_object_ref (password_dialog->details->username_entry); + gtk_object_sink (GTK_OBJECT (password_dialog->details->username_entry)); + g_object_ref (password_dialog->details->domain_entry); + gtk_object_sink (GTK_OBJECT (password_dialog->details->domain_entry)); + g_object_ref (password_dialog->details->password_entry); + gtk_object_sink (GTK_OBJECT (password_dialog->details->password_entry)); + g_object_ref (password_dialog->details->password_entry_secondary); + gtk_object_sink (GTK_OBJECT (password_dialog->details->password_entry_secondary)); + + gtk_entry_set_visibility (GTK_ENTRY (password_dialog->details->password_entry), FALSE); + gtk_entry_set_visibility (GTK_ENTRY (password_dialog->details->password_entry_secondary), FALSE); + + g_signal_connect (password_dialog->details->username_entry, + "activate", + G_CALLBACK (username_entry_activate), + password_dialog); + g_signal_connect (password_dialog->details->domain_entry, + "activate", + G_CALLBACK (domain_entry_activate), + password_dialog); + g_signal_connect_swapped (password_dialog->details->password_entry, + "activate", + G_CALLBACK (gtk_window_activate_default), + password_dialog); + g_signal_connect_swapped (password_dialog->details->password_entry_secondary, + "activate", + G_CALLBACK (gtk_window_activate_default), + password_dialog); + add_table_rows (password_dialog); + + /* 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 (password_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 */ + } + gtk_box_pack_start (GTK_BOX (vbox), password_dialog->details->radio_vbox, + TRUE, TRUE, 5); + gtk_box_pack_start (GTK_BOX (vbox), table, + TRUE, TRUE, 5); + + /* Configure the table */ + gtk_container_set_border_width (GTK_CONTAINER (table), + CAPTION_TABLE_BORDER_WIDTH); + + gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 5); + + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (password_dialog)->vbox), + hbox, + TRUE, /* expand */ + TRUE, /* fill */ + 0); /* padding */ + + 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")); + password_dialog->details->remember_forever_button = + gtk_check_button_new_with_mnemonic (_("_Save password in keyring")); + + gtk_box_pack_start (GTK_BOX (vbox), password_dialog->details->remember_session_button, + TRUE, TRUE, 6); + gtk_box_pack_start (GTK_BOX (vbox), password_dialog->details->remember_forever_button, + TRUE, TRUE, 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); + + return GTK_WIDGET (password_dialog); +} + +gboolean +gnome_two_password_dialog_run_and_block (GnomeTwoPasswordDialog *password_dialog) +{ + gint button_clicked; + + g_return_val_if_fail (password_dialog != NULL, FALSE); + g_return_val_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog), FALSE); + + button_clicked = gtk_dialog_run (GTK_DIALOG (password_dialog)); + gtk_widget_hide (GTK_WIDGET (password_dialog)); + + return button_clicked == GTK_RESPONSE_OK; +} + +void +gnome_two_password_dialog_set_username (GnomeTwoPasswordDialog *password_dialog, + const char *username) +{ + g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog)); + g_return_if_fail (password_dialog->details->username_entry != NULL); + + gtk_entry_set_text (GTK_ENTRY (password_dialog->details->username_entry), + username?username:""); +} + +void +gnome_two_password_dialog_set_password (GnomeTwoPasswordDialog *password_dialog, + const char *password) +{ + g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog)); + + gtk_entry_set_text (GTK_ENTRY (password_dialog->details->password_entry), + password ? password : ""); +} + +void +gnome_two_password_dialog_set_password_secondary (GnomeTwoPasswordDialog *password_dialog, + const char *password_secondary) +{ + g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog)); + + gtk_entry_set_text (GTK_ENTRY (password_dialog->details->password_entry_secondary), + password_secondary ? password_secondary : ""); +} + +void +gnome_two_password_dialog_set_domain (GnomeTwoPasswordDialog *password_dialog, + const char *domain) +{ + g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog)); + g_return_if_fail (password_dialog->details->domain_entry != NULL); + + gtk_entry_set_text (GTK_ENTRY (password_dialog->details->domain_entry), + domain ? domain : ""); +} + + +void +gnome_two_password_dialog_set_show_username (GnomeTwoPasswordDialog *password_dialog, + gboolean show) +{ + g_return_if_fail (password_dialog != NULL); + g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog)); + + show = !!show; + if (password_dialog->details->show_username != show) { + password_dialog->details->show_username = show; + add_table_rows (password_dialog); + } +} + +void +gnome_two_password_dialog_set_show_domain (GnomeTwoPasswordDialog *password_dialog, + gboolean show) +{ + g_return_if_fail (password_dialog != NULL); + g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog)); + + show = !!show; + if (password_dialog->details->show_domain != show) { + password_dialog->details->show_domain = show; + add_table_rows (password_dialog); + } +} + +void +gnome_two_password_dialog_set_show_password (GnomeTwoPasswordDialog *password_dialog, + gboolean show) +{ + g_return_if_fail (password_dialog != NULL); + g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog)); + + show = !!show; + if (password_dialog->details->show_password != show) { + password_dialog->details->show_password = show; + add_table_rows (password_dialog); + } +} + +void +gnome_two_password_dialog_set_show_password_secondary (GnomeTwoPasswordDialog *password_dialog, + gboolean show) +{ + g_return_if_fail (password_dialog != NULL); + g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog)); + + show = !!show; + if (password_dialog->details->show_password_secondary != show) { + password_dialog->details->show_password_secondary = show; + add_table_rows (password_dialog); + } +} + +void +gnome_two_password_dialog_set_readonly_username (GnomeTwoPasswordDialog *password_dialog, + gboolean readonly) +{ + g_return_if_fail (password_dialog != NULL); + g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog)); + + password_dialog->details->readonly_username = readonly; + + gtk_widget_set_sensitive (password_dialog->details->username_entry, + !readonly); +} + +void +gnome_two_password_dialog_set_readonly_domain (GnomeTwoPasswordDialog *password_dialog, + gboolean readonly) +{ + g_return_if_fail (password_dialog != NULL); + g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog)); + + password_dialog->details->readonly_domain = readonly; + + gtk_widget_set_sensitive (password_dialog->details->domain_entry, + !readonly); +} + +char * +gnome_two_password_dialog_get_username (GnomeTwoPasswordDialog *password_dialog) +{ + g_return_val_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog), NULL); + + return g_strdup (gtk_entry_get_text (GTK_ENTRY (password_dialog->details->username_entry))); +} + +char * +gnome_two_password_dialog_get_domain (GnomeTwoPasswordDialog *password_dialog) +{ + g_return_val_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog), NULL); + + return g_strdup (gtk_entry_get_text (GTK_ENTRY (password_dialog->details->domain_entry))); +} + +char * +gnome_two_password_dialog_get_password (GnomeTwoPasswordDialog *password_dialog) +{ + g_return_val_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog), NULL); + + return g_strdup (gtk_entry_get_text (GTK_ENTRY (password_dialog->details->password_entry))); +} + +char * +gnome_two_password_dialog_get_password_secondary (GnomeTwoPasswordDialog *password_dialog) +{ + g_return_val_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog), NULL); + + return g_strdup (gtk_entry_get_text (GTK_ENTRY (password_dialog->details->password_entry_secondary))); +} + +void +gnome_two_password_dialog_set_show_userpass_buttons (GnomeTwoPasswordDialog *password_dialog, + gboolean show_userpass_buttons) +{ + if (show_userpass_buttons) { + password_dialog->details->anon_support_on = TRUE; + gtk_widget_show (password_dialog->details->radio_vbox); + if (gtk_toggle_button_get_active ( + GTK_TOGGLE_BUTTON (password_dialog->details->connect_with_no_userpass_button))) { + gtk_widget_set_sensitive (password_dialog->details->table, FALSE); + } + else { + gtk_widget_set_sensitive (password_dialog->details->table, TRUE); + } + } else { + password_dialog->details->anon_support_on = FALSE; + gtk_widget_hide (password_dialog->details->radio_vbox); + gtk_widget_set_sensitive (password_dialog->details->table, TRUE); + } + + add_table_rows (password_dialog); +} + +gboolean +gnome_two_password_dialog_anon_selected (GnomeTwoPasswordDialog *password_dialog) +{ + return password_dialog->details->anon_support_on && + gtk_toggle_button_get_active ( + GTK_TOGGLE_BUTTON ( + password_dialog->details->connect_with_no_userpass_button)); +} + +void +gnome_two_password_dialog_set_show_remember (GnomeTwoPasswordDialog *password_dialog, + gboolean show_remember) +{ + if (show_remember) { + gtk_widget_show (password_dialog->details->remember_session_button); + gtk_widget_show (password_dialog->details->remember_forever_button); + } else { + gtk_widget_hide (password_dialog->details->remember_session_button); + gtk_widget_hide (password_dialog->details->remember_forever_button); + } +} + +void +gnome_two_password_dialog_set_remember (GnomeTwoPasswordDialog *password_dialog, + GnomeTwoPasswordDialogRemember remember) +{ + gboolean session, forever; + + session = FALSE; + forever = FALSE; + if (remember == GNOME_TWO_PASSWORD_DIALOG_REMEMBER_SESSION) { + session = TRUE; + } else if (remember == GNOME_TWO_PASSWORD_DIALOG_REMEMBER_FOREVER){ + forever = TRUE; + } + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (password_dialog->details->remember_session_button), + session); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (password_dialog->details->remember_forever_button), + forever); +} + +GnomeTwoPasswordDialogRemember +gnome_two_password_dialog_get_remember (GnomeTwoPasswordDialog *password_dialog) +{ + gboolean session, forever; + + session = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (password_dialog->details->remember_session_button)); + forever = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (password_dialog->details->remember_forever_button)); + if (forever) { + return GNOME_TWO_PASSWORD_DIALOG_REMEMBER_FOREVER; + } else if (session) { + return GNOME_TWO_PASSWORD_DIALOG_REMEMBER_SESSION; + } + return GNOME_TWO_PASSWORD_DIALOG_REMEMBER_NOTHING; +} + +void gnome_two_password_dialog_set_password_secondary_label (GnomeTwoPasswordDialog *password_dialog, + const char *password_secondary_label) +{ + g_return_if_fail (password_dialog != NULL); + g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog)); + + g_free (password_dialog->details->secondary_password_label); + password_dialog->details->secondary_password_label = g_strdup (password_secondary_label); + + if (password_dialog->details->show_password_secondary) { + add_table_rows (password_dialog); + } +} diff --git a/vpn-daemons/pptp/auth-dialog/gnome-two-password-dialog.h b/vpn-daemons/pptp/auth-dialog/gnome-two-password-dialog.h new file mode 100644 index 0000000000..ecd6c2aa9d --- /dev/null +++ b/vpn-daemons/pptp/auth-dialog/gnome-two-password-dialog.h @@ -0,0 +1,116 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* gnome-two-password-dialog.h - A use password prompting dialog widget + asking for two passwords. Based of + gnome-password-dialog.[ch] from libgnomeui + + Copyright (C) 1999, 2000 Eazel, Inc. + Copyright (C) 2005, Red Hat, Inc. + + The Gnome Library 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. + + The Gnome Library 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: Ramiro Estrugo +*/ + +#ifndef GNOME_TWO_PASSWORD_DIALOG_H +#define GNOME_TWO_PASSWORD_DIALOG_H + +#include + +G_BEGIN_DECLS + +#define GNOME_TYPE_TWO_PASSWORD_DIALOG (gnome_two_password_dialog_get_type ()) +#define GNOME_TWO_PASSWORD_DIALOG(obj) (GTK_CHECK_CAST ((obj), GNOME_TYPE_TWO_PASSWORD_DIALOG, GnomeTwoPasswordDialog)) +#define GNOME_TWO_PASSWORD_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GNOME_TYPE_TWO_PASSWORD_DIALOG, GnomeTwoPasswordDialogClass)) +#define GNOME_IS_TWO_PASSWORD_DIALOG(obj) (GTK_CHECK_TYPE ((obj), GNOME_TYPE_TWO_PASSWORD_DIALOG)) +#define GNOME_IS_TWO_PASSWORD_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_TWO_PASSWORD_DIALOG)) + +typedef struct GnomeTwoPasswordDialog GnomeTwoPasswordDialog; +typedef struct GnomeTwoPasswordDialogClass GnomeTwoPasswordDialogClass; +typedef struct GnomeTwoPasswordDialogDetails GnomeTwoPasswordDialogDetails; + +struct GnomeTwoPasswordDialog +{ + GtkDialog gtk_dialog; + + GnomeTwoPasswordDialogDetails *details; +}; + +struct GnomeTwoPasswordDialogClass +{ + GtkDialogClass parent_class; +}; + +typedef enum { + GNOME_TWO_PASSWORD_DIALOG_REMEMBER_NOTHING, + GNOME_TWO_PASSWORD_DIALOG_REMEMBER_SESSION, + GNOME_TWO_PASSWORD_DIALOG_REMEMBER_FOREVER +} GnomeTwoPasswordDialogRemember; + + +GtkType gnome_two_password_dialog_get_type (void); +GtkWidget* gnome_two_password_dialog_new (const char *dialog_title, + const char *message, + const char *username, + const char *password, + gboolean readonly_username); + +gboolean gnome_two_password_dialog_run_and_block (GnomeTwoPasswordDialog *password_dialog); + +/* Attribute mutators */ +void gnome_two_password_dialog_set_show_username (GnomeTwoPasswordDialog *password_dialog, + gboolean show); +void gnome_two_password_dialog_set_show_domain (GnomeTwoPasswordDialog *password_dialog, + gboolean show); +void gnome_two_password_dialog_set_show_password (GnomeTwoPasswordDialog *password_dialog, + gboolean show); +void gnome_two_password_dialog_set_show_password_secondary (GnomeTwoPasswordDialog *password_dialog, + gboolean show); +void gnome_two_password_dialog_set_username (GnomeTwoPasswordDialog *password_dialog, + const char *username); +void gnome_two_password_dialog_set_domain (GnomeTwoPasswordDialog *password_dialog, + const char *domain); +void gnome_two_password_dialog_set_password (GnomeTwoPasswordDialog *password_dialog, + const char *password); +void gnome_two_password_dialog_set_password_secondary (GnomeTwoPasswordDialog *password_dialog, + const char *password_secondary); +void gnome_two_password_dialog_set_readonly_username (GnomeTwoPasswordDialog *password_dialog, + gboolean readonly); +void gnome_two_password_dialog_set_readonly_domain (GnomeTwoPasswordDialog *password_dialog, + gboolean readonly); + +void gnome_two_password_dialog_set_password_secondary_label (GnomeTwoPasswordDialog *password_dialog, + const char *password_secondary_description); + +void gnome_two_password_dialog_set_show_remember (GnomeTwoPasswordDialog *password_dialog, + gboolean show_remember); +void gnome_two_password_dialog_set_remember (GnomeTwoPasswordDialog *password_dialog, + GnomeTwoPasswordDialogRemember remember); +GnomeTwoPasswordDialogRemember gnome_two_password_dialog_get_remember (GnomeTwoPasswordDialog *password_dialog); +void gnome_two_password_dialog_set_show_userpass_buttons (GnomeTwoPasswordDialog *password_dialog, + gboolean show_userpass_buttons); + +/* Attribute accessors */ +char * gnome_two_password_dialog_get_username (GnomeTwoPasswordDialog *password_dialog); +char * gnome_two_password_dialog_get_domain (GnomeTwoPasswordDialog *password_dialog); +char * gnome_two_password_dialog_get_password (GnomeTwoPasswordDialog *password_dialog); +char * gnome_two_password_dialog_get_password_secondary (GnomeTwoPasswordDialog *password_dialog); + +gboolean gnome_two_password_dialog_anon_selected (GnomeTwoPasswordDialog *password_dialog); + +G_END_DECLS + +#endif /* GNOME_TWO_PASSWORD_DIALOG_H */ diff --git a/vpn-daemons/pptp/auth-dialog/main.c b/vpn-daemons/pptp/auth-dialog/main.c new file mode 100644 index 0000000000..9e67ffe1ed --- /dev/null +++ b/vpn-daemons/pptp/auth-dialog/main.c @@ -0,0 +1,290 @@ +/* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * (C) Copyright 2004 Red Hat, Inc. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "gnome-two-password-dialog.h" + +#define VPN_SERVICE "org.freedesktop.NetworkManager.pptp" + +static GSList * +lookup_pass (const char *vpn_name, const char *vpn_service, gboolean *is_session) +{ + GSList *passwords; + GList *keyring_result; + + passwords = NULL; + + if (gnome_keyring_find_network_password_sync (g_get_user_name (), /* user */ + NULL, /* domain */ + vpn_name, /* server */ + NULL, /* object */ + vpn_service, /* protocol */ + NULL, /* authtype */ + 0, /* port */ + &keyring_result) != GNOME_KEYRING_RESULT_OK) + return FALSE; + + if (keyring_result != NULL && g_list_length (keyring_result) == 2) { + char *username; + char *password; + GnomeKeyringNetworkPasswordData *data1 = keyring_result->data; + GnomeKeyringNetworkPasswordData *data2 = (g_list_next (keyring_result))->data; + + username = NULL; + password = NULL; + + if (strcmp (data1->object, "username") == 0) { + username = data1->password; + } else if (strcmp (data1->object, "password") == 0) { + password = data1->password; + } + + if (strcmp (data2->object, "username") == 0) { + username = data2->password; + } else if (strcmp (data2->object, "password") == 0) { + password = data2->password; + } + + if (password != NULL && username != NULL) { + passwords = g_slist_append (passwords, g_strdup (username)); + passwords = g_slist_append (passwords, g_strdup (password)); + if (strcmp (data1->keyring, "session") == 0) + *is_session = TRUE; + else + *is_session = FALSE; + } + + gnome_keyring_network_password_list_free (keyring_result); + } + + return passwords; +} + +static void save_vpn_password (const char *vpn_name, const char *vpn_service, const char *keyring, + const char *username, const char *password) +{ + guint32 item_id; + GnomeKeyringResult keyring_result; + + keyring_result = gnome_keyring_set_network_password_sync (keyring, + g_get_user_name (), + NULL, + vpn_name, + "password", + vpn_service, + NULL, + 0, + password, + &item_id); + if (keyring_result != GNOME_KEYRING_RESULT_OK) + { + g_warning ("Couldn't store password in keyring, code %d", (int) keyring_result); + } + + keyring_result = gnome_keyring_set_network_password_sync (keyring, + g_get_user_name (), + NULL, + vpn_name, + "password", + vpn_service, + NULL, + 0, + password, + &item_id); + + if (keyring_result != GNOME_KEYRING_RESULT_OK) + { + g_warning ("Couldn't store password in keyring, code %d", (int) keyring_result); + } +} + +static GSList * +get_passwords (const char *vpn_name, const char *vpn_service, gboolean retry) +{ + GSList *result; + char *prompt; + GtkWidget *dialog; + char *keyring_username; + char *keyring_password; + gboolean keyring_is_session; + GSList *keyring_result; + GnomeTwoPasswordDialogRemember remember; + + result = NULL; + keyring_password = NULL; + keyring_username = NULL; + keyring_result = 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, &keyring_is_session)) != NULL) { + return result; + } + } else { + if ((keyring_result = lookup_pass (vpn_name, vpn_service, &keyring_is_session)) != NULL) { + keyring_username = g_strdup ((char *) keyring_result->data); + 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 the Virtual Private Network '%s'."), vpn_name); + dialog = gnome_two_password_dialog_new (_("Authenticate PPTP VPN"), prompt, NULL, NULL, FALSE); + g_free (prompt); + + 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) { + if (keyring_is_session) + remember = GNOME_TWO_PASSWORD_DIALOG_REMEMBER_SESSION; + else + remember = GNOME_TWO_PASSWORD_DIALOG_REMEMBER_FOREVER; + } + 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); + } + + gtk_widget_show (dialog); + + if (gnome_two_password_dialog_run_and_block (GNOME_TWO_PASSWORD_DIALOG (dialog))) + { + char *username; + char *password; + + username = gnome_two_password_dialog_get_username (GNOME_TWO_PASSWORD_DIALOG (dialog)); + password = gnome_two_password_dialog_get_password (GNOME_TWO_PASSWORD_DIALOG (dialog)); + result = g_slist_append (result, username); + 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", username, password); + break; + case GNOME_TWO_PASSWORD_DIALOG_REMEMBER_FOREVER: + save_vpn_password (vpn_name, vpn_service, NULL, username, password); + break; + default: + break; + } + + } + + g_free (keyring_username); + g_free (keyring_password); + + gtk_widget_destroy (dialog); + + return result; +} + +int +main (int argc, char *argv[]) +{ + GSList *i; + GSList *passwords; + static gboolean retry = FALSE; + static gchar *vpn_name = NULL; + static gchar *vpn_service = NULL; + GError *error = NULL; + GOptionContext *context; + static GOptionEntry entries[] = + { + { "reprompt", 'r', 0, G_OPTION_ARG_NONE, &retry, "Reprompt for passwords", 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"); + textdomain (GETTEXT_PACKAGE); + + passwords = NULL; + + context = g_option_context_new ("- pptp auth dialog"); + g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); + g_option_context_add_group (context, gtk_get_option_group (TRUE)); + g_option_context_parse (context, &argc, &argv, &error); + + if (vpn_name == NULL || vpn_service == NULL) { + fprintf (stderr, "Have to supply both 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); + goto out; + } + + gnome_program_init ("nm-pptp-auth-dialog", VERSION, LIBGNOMEUI_MODULE, + argc, argv, + GNOME_PARAM_NONE); + + passwords = get_passwords (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 ("\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_option_context_free (context); + + return passwords != NULL ? 0 : 1; +} diff --git a/vpn-daemons/pptp/autogen.sh b/vpn-daemons/pptp/autogen.sh new file mode 100755 index 0000000000..53d12d1192 --- /dev/null +++ b/vpn-daemons/pptp/autogen.sh @@ -0,0 +1,23 @@ +#!/bin/sh +# Run this to generate all the initial makefiles, etc. + +srcdir=`dirname $0` +test -z "$srcdir" && srcdir=. +REQUIRED_AUTOMAKE_VERSION=1.7 +PKG_NAME=NetworkManager-pptp + +(test -f $srcdir/configure.in \ + && test -f $srcdir/auth-dialog/main.c) || { + echo -n "**Error**: Directory "\`$srcdir\'" does not look like the" + echo " top-level $PKG_NAME directory" + exit 1 +} + + +which gnome-autogen.sh || { + echo "You need to install gnome-common from the GNOME CVS" + exit 1 +} +USE_GNOME2_MACROS=1 . gnome-autogen.sh + + diff --git a/vpn-daemons/pptp/configure.in b/vpn-daemons/pptp/configure.in new file mode 100644 index 0000000000..201e53f7f1 --- /dev/null +++ b/vpn-daemons/pptp/configure.in @@ -0,0 +1,131 @@ +AC_PREREQ(2.52) + +AC_INIT(NetworkManager-pptp, 0.1.0, A.J.Mee@ncl.ac.uk, NetworkManager-pptp) +AM_INIT_AUTOMAKE([subdir-objects]) +AM_MAINTAINER_MODE + +AM_CONFIG_HEADER(config.h) + +dnl +dnl Require programs +dnl +AC_PROG_CC +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) + +dnl +dnl Checks for typedefs, structures, and compiler characteristics. +dnl +AC_TYPE_MODE_T +AC_TYPE_PID_T +AC_HEADER_TIME + +dnl +dnl Checks for library functions. +dnl +AC_PROG_GCC_TRADITIONAL +AC_FUNC_MEMCMP +AC_CHECK_FUNCS(select socket uname) + +ALL_LINGUAS="da sv" +AC_SUBST(ALL_LINGUAS) + +GETTEXT_PACKAGE=NetworkManager-pptp +AC_SUBST(GETTEXT_PACKAGE) +AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package]) + +AC_PROG_INTLTOOL([0.27.2]) +AM_GLIB_GNU_GETTEXT + +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(NETWORK_MANAGER, NetworkManager >= 0.4.1) +AC_SUBST(NETWORK_MANAGER_CFLAGS) +AC_SUBST(NETWORK_MANAGER_LIBS) + +PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.6) +AC_SUBST(GTK_CFLAGS) +AC_SUBST(GTK_LIBS) + +PKG_CHECK_MODULES(GDK_PIXBUF, gdk-pixbuf-2.0) +AC_SUBST(GDK_PIXBUF_CFLAGS) +AC_SUBST(GDK_PIXBUF_LIBS) + +PKG_CHECK_MODULES(GLADE, libglade-2.0) +AC_SUBST(GLADE_CFLAGS) +AC_SUBST(GLADE_LIBS) + +PKG_CHECK_MODULES(LIBGNOMEUI, libgnomeui-2.0) +AC_SUBST(LIBGNOMEUI_CFLAGS) +AC_SUBST(LIBGNOMEUI_LIBS) + +PKG_CHECK_MODULES(GCONF, gconf-2.0) +AC_SUBST(GCONF_CFLAGS) +AC_SUBST(GCONF_LIBS) + +PKG_CHECK_MODULES(GNOMEKEYRING, gnome-keyring-1) +AC_SUBST(GNOMEKEYRING_CFLAGS) +AC_SUBST(GNOMEKEYRING_LIBS) + +AS_AC_EXPAND(LOCALSTATEDIR, $localstatedir) +AS_AC_EXPAND(SYSCONFDIR, $sysconfdir) +AS_AC_EXPAND(DATADIR, $datadir) +AS_AC_EXPAND(BINDIR, $bindir) +AS_AC_EXPAND(SBINDIR, $sbindir) +AS_AC_EXPAND(LIBDIR, $libdir) +AS_AC_EXPAND(LIBEXECDIR, $libexecdir) + +AC_ARG_ENABLE(more-warnings, +AC_HELP_STRING([--enable-more-warnings], [Maximum compiler warnings]), +set_more_warnings="$enableval",[ +if test -d "$srcdir/{arch}" || test -d "$srcdir/CVS"; then + set_more_warnings=yes +else + set_more_warnings=no +fi +]) +AC_MSG_CHECKING(for more warnings, including -Werror) +if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then + AC_MSG_RESULT(yes) + CFLAGS="-Wall -Werror -std=gnu89 $CFLAGS" + + for option in -Wno-unused -Wno-strict-aliasing -Wno-sign-compare -Wdeclaration-after-statement -Wno-pointer-sign ; do + SAVE_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $option" + AC_MSG_CHECKING([whether gcc understands $option]) + AC_TRY_COMPILE([], [], + has_option=yes, + has_option=no,) + if test $has_option = no; then + CFLAGS="$SAVE_CFLAGS" + fi + AC_MSG_RESULT($has_option) + unset has_option + unset SAVE_CFLAGS + done + unset option +else + AC_MSG_RESULT(no) +fi + +AC_OUTPUT([ +Makefile +src/Makefile +auth-dialog/Makefile +properties/Makefile +po/Makefile.in +nm-pptp-service.name +]) diff --git a/vpn-daemons/pptp/doc/example-pptp-system-wide-connection.sh b/vpn-daemons/pptp/doc/example-pptp-system-wide-connection.sh new file mode 100755 index 0000000000..e74dd01074 --- /dev/null +++ b/vpn-daemons/pptp/doc/example-pptp-system-wide-connection.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +# This is an example of how to install a system-wide connection that +# cannot be edited by unprivileged users using nm-vpn-properties. This +# script needs to be run as root and you may need to restart any +# gconfd daemons after the script has run (logging in and out will +# suffice) + +NAME="pptp-system-wide" +ESCAPED_NAME="pptp-system-wide" +REMOTE="1.2.3.4" +# must be either yes or no +USEMPPE="no" + +IPSEC_ROUTES="[172.16.0.0/16,192.168.4.0/24]" + +GCONF_PATH="/system/networking/vpn_connections/$ESCAPED_NAME" + +GCONFTOOL2_OPTS="--direct --config-source xml:readwrite:/etc/gconf/gconf.xml.mandatory" + +gconftool-2 $GCONFTOOL2_OPTS --type string --set $GCONF_PATH/name "$NAME" +gconftool-2 $GCONFTOOL2_OPTS --type string --set $GCONF_PATH/service_name "org.freedesktop.NetworkManager.pptp" +gconftool-2 $GCONFTOOL2_OPTS --type list --list-type=string --set $GCONF_PATH/vpn_data ["remote","$REMOTE","require-mppe",$USEMPPE] +gconftool-2 $GCONFTOOL2_OPTS --type list --list-type=string --set $GCONF_PATH/routes $IPSEC_ROUTES + diff --git a/vpn-daemons/pptp/gnome-mime-application-x-pptp-settings.png b/vpn-daemons/pptp/gnome-mime-application-x-pptp-settings.png new file mode 100644 index 0000000000000000000000000000000000000000..d8354ff65551b1db41091b57532368acf26271d4 GIT binary patch literal 2595 zcmV+;3f%RHP)g+^_g)%r(wSEz|A?gQf{XydxAW?5aE zE+*PEtr~}}iP_dBbd9vhh829k)<;>9hZ00U@WpG8;V}cu?Dsn}-*BY^3=g|&vL}A| z?!DZ(_x#TJoyYfGRd&0bo@PRwjWIKM6q74#3~v-+tr94cBim1BhanMgY3@zXTvPEiJA1 z`0?Y90T}r#3FhL(ix^V^q}17a8a!%9PEKZJ-6<}QSFBjU!+9PkK)iu*;lhO}0h$gE zoGmIUG9)G@x>bBEP|6uV6k|+4(@G)mzpk!s(u$9E4}hFMe_qZ?Kt`c+*K`3$O;1lR z&d<-EkaC{{He{-{f^^-Y8!cLEozN#FV3wk-@S6FFOKT}TIsrfaBz?Y1_qd? zcDs$>U<+UY`txXYhR3dZG$1+q2SOE z_4oIaMx!-bEergjqZcUkQBID4!!v9)280 zxOf5e4-Q|mTCILvU0tNr+9)_Um|p?~F{?o-wR+SXZnp_A!aH64Lv*vgk(!#k$=BDH zX3m_+!yT2}S${$?0Od{n$}3vZ=)7l!K?=t-)n9$Hr^78T;l|CK;P-$lNSp;R8nwo^gh?*Pg>EpaV zu|j(P0D9xCpV6}9RQk5`JRSOAFMWHlgn##J;`8*8@e9iTsMGPj5>Gj++hIo=g;To zmz0!DF8~-6fts=^jo!}uCAGIcq}rNF>M?f<*N3oWm6iwRm%a28M;b*26UxG4e6Dib zqtoel$c(1^{Zu>9;w5;Fso$7{D>aODL=H_I9OFn=?}l4i0hVsjpYNXd|hkOrgR9rqMdou>fq;>-7hh zC(I2DpEH}HqoX;En!92tY3Yw$$`4qrOqJZcPwAV#f5D1FUVe2oJrkcGVq`G~uF|4N zjb7vk*s!oLwz{N_s4sjT85ub)eZ~T?F+M)tc>45d`nsxz-EFa0M79{Bi0Fm1?cKe6 zjvS8{_VxAAGqG_Lx8prm6_%EMckc&0Tf}`_7sRt%Ers}}6CgrDLU=d}q>E}!>rWU! zCAD1{5(_frl+E0TBl` zdu?dIkw&cpq5I41AhI3;b{> z(_`)-bB~#i0Y(O>9ziNCEJk>+FAv;@_hFVYp7loq5QSc(y}g|u(Dk6fNDuy8==@t& ze9Eusg$0f(36Kb2w96y2hdgF5B0xbC3~P7iFc?7_z25h+G^&)z0$`p35 zAvQLa3JMAcUFe!MYiQM~RSW`PWhGUnL#1NMAeCSm8yj8Jae&dgV!=}Y?qc9FYHF&huaVZ4iYb+I*XtvjfjamNj-#TY zT%K^pe@_mo8mO$BrF)Ofd;aDmRv; z-3hF}a^=bbarov~0NkxQj73F7F6ALemk z(%IQbnVFfK0Dh;QG%odHb-L{(K4?_y8Y0|(2>%0~4B zXoP`a=H4C+nxGSu2A47K+_{s}?s)NlXUMstqJqwxIRgVWc)CM9T031L9`bLYbkax= zNQF=yc^rU{fglebK4j`(Al1Ty%a$$UlsTHj*TGQ!$dMzkK3w+IbO5*}C}3E>e!W`| zNUh*M0$M3(H;`(Tzi}rhV)ga)tUTgp-@bj|{z37l%n2>dJ=k7<9x);M9>b|qr(7FN z$oFXMz((&{xpSrzd>goa z{W>cyXkilV0hB9nW)v)L_dJo0#>(M=z!P>s6?<-Ou01_H-Hz5nwBPvgSux&o((Z|V z=yvHl2>=Yjx%FQzMxGe2|B(N^K&h|l|NmR%zbyX|U;rP9vz1Q6+}8jA002ovPDHLk FV1mA;+W7zg literal 0 HcmV?d00001 diff --git a/vpn-daemons/pptp/intltool-extract.in b/vpn-daemons/pptp/intltool-extract.in new file mode 100755 index 0000000000..adfa97134d --- /dev/null +++ b/vpn-daemons/pptp/intltool-extract.in @@ -0,0 +1,839 @@ +#!@INTLTOOL_PERL@ -w +# -*- Mode: perl; indent-tabs-mode: nil; c-basic-offset: 4 -*- + +# +# The Intltool Message Extractor +# +# Copyright (C) 2000-2001, 2003 Free Software Foundation. +# +# Intltool 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. +# +# Intltool 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. +# +# Authors: Kenneth Christiansen +# Darin Adler +# + +## Release information +my $PROGRAM = "intltool-extract"; +my $PACKAGE = "intltool"; +my $VERSION = "0.34.1"; + +## Loaded modules +use strict; +use File::Basename; +use Getopt::Long; + +## Scalars used by the option stuff +my $TYPE_ARG = "0"; +my $LOCAL_ARG = "0"; +my $HELP_ARG = "0"; +my $VERSION_ARG = "0"; +my $UPDATE_ARG = "0"; +my $QUIET_ARG = "0"; +my $SRCDIR_ARG = "."; + +my $FILE; +my $OUTFILE; + +my $gettext_type = ""; +my $input; +my %messages = (); +my %loc = (); +my %count = (); +my %comments = (); +my $strcount = 0; + +my $XMLCOMMENT = ""; + +## Use this instead of \w for XML files to handle more possible characters. +my $w = "[-A-Za-z0-9._:]"; + +## Always print first +$| = 1; + +## Handle options +GetOptions ( + "type=s" => \$TYPE_ARG, + "local|l" => \$LOCAL_ARG, + "help|h" => \$HELP_ARG, + "version|v" => \$VERSION_ARG, + "update" => \$UPDATE_ARG, + "quiet|q" => \$QUIET_ARG, + "srcdir=s" => \$SRCDIR_ARG, + ) or &error; + +&split_on_argument; + + +## Check for options. +## This section will check for the different options. + +sub split_on_argument { + + if ($VERSION_ARG) { + &version; + + } elsif ($HELP_ARG) { + &help; + + } elsif ($LOCAL_ARG) { + &place_local; + &extract; + + } elsif ($UPDATE_ARG) { + &place_normal; + &extract; + + } elsif (@ARGV > 0) { + &place_normal; + &message; + &extract; + + } else { + &help; + + } +} + +sub place_normal { + $FILE = $ARGV[0]; + $OUTFILE = "$FILE.h"; +} + +sub place_local { + $FILE = $ARGV[0]; + $OUTFILE = fileparse($FILE, ()); + if (!-e "tmp/") { + system("mkdir tmp/"); + } + $OUTFILE = "./tmp/$OUTFILE.h" +} + +sub determine_type { + if ($TYPE_ARG =~ /^gettext\/(.*)/) { + $gettext_type=$1 + } +} + +## Sub for printing release information +sub version{ + print <<_EOF_; +${PROGRAM} (${PACKAGE}) $VERSION +Copyright (C) 2000, 2003 Free Software Foundation, Inc. +Written by Kenneth Christiansen, 2000. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +_EOF_ + exit; +} + +## Sub for printing usage information +sub help { + print <<_EOF_; +Usage: ${PROGRAM} [OPTION]... [FILENAME] +Generates a header file from an XML source file. + +It grabs all strings between <_translatable_node> and its end tag in +XML files. Read manpage (man ${PROGRAM}) for more info. + + --type=TYPE Specify the file type of FILENAME. Currently supports: + "gettext/glade", "gettext/ini", "gettext/keys" + "gettext/rfc822deb", "gettext/schemas", + "gettext/scheme", "gettext/xml" + -l, --local Writes output into current working directory + (conflicts with --update) + --update Writes output into the same directory the source file + reside (conflicts with --local) + --srcdir Root of the source tree + -v, --version Output version information and exit + -h, --help Display this help and exit + -q, --quiet Quiet mode + +Report bugs to http://bugzilla.gnome.org/ (product name "$PACKAGE") +or send email to . +_EOF_ + exit; +} + +## Sub for printing error messages +sub error{ + print STDERR "Try `${PROGRAM} --help' for more information.\n"; + exit; +} + +sub message { + print "Generating C format header file for translation.\n" unless $QUIET_ARG; +} + +sub extract { + &determine_type; + + &convert; + + open OUT, ">$OUTFILE"; + binmode (OUT) if $^O eq 'MSWin32'; + &msg_write; + close OUT; + + print "Wrote $OUTFILE\n" unless $QUIET_ARG; +} + +sub convert { + + ## Reading the file + { + local (*IN); + local $/; #slurp mode + open (IN, "<$SRCDIR_ARG/$FILE") || die "can't open $SRCDIR_ARG/$FILE: $!"; + $input = ; + } + + &type_ini if $gettext_type eq "ini"; + &type_keys if $gettext_type eq "keys"; + &type_xml if $gettext_type eq "xml"; + &type_glade if $gettext_type eq "glade"; + &type_scheme if $gettext_type eq "scheme"; + &type_schemas if $gettext_type eq "schemas"; + &type_rfc822deb if $gettext_type eq "rfc822deb"; +} + +sub entity_decode_minimal +{ + local ($_) = @_; + + s/'/'/g; # ' + s/"/"/g; # " + s/&/&/g; + + return $_; +} + +sub entity_decode +{ + local ($_) = @_; + + s/'/'/g; # ' + s/"/"/g; # " + s/&/&/g; + s/<//g; + + return $_; +} + +sub escape_char +{ + return '\"' if $_ eq '"'; + return '\n' if $_ eq "\n"; + return '\\' if $_ eq '\\'; + + return $_; +} + +sub escape +{ + my ($string) = @_; + return join "", map &escape_char, split //, $string; +} + +sub type_ini { + ### For generic translatable desktop files ### + while ($input =~ /^_.*=(.*)$/mg) { + $messages{$1} = []; + } +} + +sub type_keys { + ### For generic translatable mime/keys files ### + while ($input =~ /^\s*_\w+=(.*)$/mg) { + $messages{$1} = []; + } +} + +sub type_xml { + ### For generic translatable XML files ### + my $tree = readXml($input); + parseTree(0, $tree); +} + +sub print_var { + my $var = shift; + my $vartype = ref $var; + + if ($vartype =~ /ARRAY/) { + my @arr = @{$var}; + print "[ "; + foreach my $el (@arr) { + print_var($el); + print ", "; + } + print "] "; + } elsif ($vartype =~ /HASH/) { + my %hash = %{$var}; + print "{ "; + foreach my $key (keys %hash) { + print "$key => "; + print_var($hash{$key}); + print ", "; + } + print "} "; + } else { + print $var; + } +} + +# Same syntax as getAttributeString in intltool-merge.in.in, similar logic (look for ## differences comment) +sub getAttributeString +{ + my $sub = shift; + my $do_translate = shift || 1; + my $language = shift || ""; + my $translate = shift; + my $result = ""; + foreach my $e (reverse(sort(keys %{ $sub }))) { + my $key = $e; + my $string = $sub->{$e}; + my $quote = '"'; + + $string =~ s/^[\s]+//; + $string =~ s/[\s]+$//; + + if ($string =~ /^'.*'$/) + { + $quote = "'"; + } + $string =~ s/^['"]//g; + $string =~ s/['"]$//g; + + ## differences from intltool-merge.in.in + if ($key =~ /^_/) { + $comments{entity_decode($string)} = $XMLCOMMENT if $XMLCOMMENT; + $messages{entity_decode($string)} = []; + $$translate = 2; + } + ## differences end here from intltool-merge.in.in + $result .= " $key=$quote$string$quote"; + } + return $result; +} + +# Verbatim copy from intltool-merge.in.in +sub getXMLstring +{ + my $ref = shift; + my $spacepreserve = shift || 0; + my @list = @{ $ref }; + my $result = ""; + + my $count = scalar(@list); + my $attrs = $list[0]; + my $index = 1; + + $spacepreserve = 1 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?preserve["']?$/)); + $spacepreserve = 0 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?default["']?$/)); + + while ($index < $count) { + my $type = $list[$index]; + my $content = $list[$index+1]; + if (! $type ) { + # We've got CDATA + if ($content) { + # lets strip the whitespace here, and *ONLY* here + $content =~ s/\s+/ /gs if (!$spacepreserve); + $result .= $content; + } + } elsif ( "$type" ne "1" ) { + # We've got another element + $result .= "<$type"; + $result .= getAttributeString(@{$content}[0], 0); # no nested translatable elements + if ($content) { + my $subresult = getXMLstring($content, $spacepreserve); + if ($subresult) { + $result .= ">".$subresult . ""; + } else { + $result .= "/>"; + } + } else { + $result .= "/>"; + } + } + $index += 2; + } + return $result; +} + +# Verbatim copy from intltool-merge.in.in, except for MULTIPLE_OUTPUT handling removed +# Translate list of nodes if necessary +sub translate_subnodes +{ + my $fh = shift; + my $content = shift; + my $language = shift || ""; + my $singlelang = shift || 0; + my $spacepreserve = shift || 0; + + my @nodes = @{ $content }; + + my $count = scalar(@nodes); + my $index = 0; + while ($index < $count) { + my $type = $nodes[$index]; + my $rest = $nodes[$index+1]; + traverse($fh, $type, $rest, $language, $spacepreserve); + $index += 2; + } +} + +# Based on traverse() in intltool-merge.in.in +sub traverse +{ + my $fh = shift; # unused, to allow us to sync code between -merge and -extract + my $nodename = shift; + my $content = shift; + my $language = shift || ""; + my $spacepreserve = shift || 0; + + if ($nodename && "$nodename" eq "1") { + $XMLCOMMENT = $content; + } elsif ($nodename) { + # element + my @all = @{ $content }; + my $attrs = shift @all; + my $translate = 0; + my $outattr = getAttributeString($attrs, 1, $language, \$translate); + + if ($nodename =~ /^_/) { + $translate = 1; + $nodename =~ s/^_//; + } + my $lookup = ''; + + $spacepreserve = 0 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?default["']?$/)); + $spacepreserve = 1 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?preserve["']?$/)); + + if ($translate) { + $lookup = getXMLstring($content, $spacepreserve); + if (!$spacepreserve) { + $lookup =~ s/^\s+//s; + $lookup =~ s/\s+$//s; + } + + if ($lookup && $translate != 2) { + $comments{$lookup} = $XMLCOMMENT if $XMLCOMMENT; + $messages{$lookup} = []; + } elsif ($translate == 2) { + translate_subnodes($fh, \@all, $language, 1, $spacepreserve); + } + } else { + $XMLCOMMENT = ""; + my $count = scalar(@all); + if ($count > 0) { + my $index = 0; + while ($index < $count) { + my $type = $all[$index]; + my $rest = $all[$index+1]; + traverse($fh, $type, $rest, $language, $spacepreserve); + $index += 2; + } + } + } + $XMLCOMMENT = ""; + } +} + + +# Verbatim copy from intltool-merge.in.in, $fh for compatibility +sub parseTree +{ + my $fh = shift; + my $ref = shift; + my $language = shift || ""; + + my $name = shift @{ $ref }; + my $cont = shift @{ $ref }; + + while (!$name || "$name" eq "1") { + $name = shift @{ $ref }; + $cont = shift @{ $ref }; + } + + my $spacepreserve = 0; + my $attrs = @{$cont}[0]; + $spacepreserve = 1 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?preserve["']?$/)); + + traverse($fh, $name, $cont, $language, $spacepreserve); +} + +# Verbatim copy from intltool-merge.in.in +sub intltool_tree_comment +{ + my $expat = shift; + my $data = shift; + my $clist = $expat->{Curlist}; + my $pos = $#$clist; + + push @$clist, 1 => $data; +} + +# Verbatim copy from intltool-merge.in.in +sub intltool_tree_cdatastart +{ + my $expat = shift; + my $clist = $expat->{Curlist}; + my $pos = $#$clist; + + push @$clist, 0 => $expat->original_string(); +} + +# Verbatim copy from intltool-merge.in.in +sub intltool_tree_cdataend +{ + my $expat = shift; + my $clist = $expat->{Curlist}; + my $pos = $#$clist; + + $clist->[$pos] .= $expat->original_string(); +} + +# Verbatim copy from intltool-merge.in.in +sub intltool_tree_char +{ + my $expat = shift; + my $text = shift; + my $clist = $expat->{Curlist}; + my $pos = $#$clist; + + # Use original_string so that we retain escaped entities + # in CDATA sections. + # + if ($pos > 0 and $clist->[$pos - 1] eq '0') { + $clist->[$pos] .= $expat->original_string(); + } else { + push @$clist, 0 => $expat->original_string(); + } +} + +# Verbatim copy from intltool-merge.in.in +sub intltool_tree_start +{ + my $expat = shift; + my $tag = shift; + my @origlist = (); + + # Use original_string so that we retain escaped entities + # in attribute values. We must convert the string to an + # @origlist array to conform to the structure of the Tree + # Style. + # + my @original_array = split /\x/, $expat->original_string(); + my $source = $expat->original_string(); + + # Remove leading tag. + # + $source =~ s|^\s*<\s*(\S+)||s; + + # Grab attribute key/value pairs and push onto @origlist array. + # + while ($source) + { + if ($source =~ /^\s*([\w:-]+)\s*[=]\s*["]/) + { + $source =~ s|^\s*([\w:-]+)\s*[=]\s*["]([^"]*)["]||s; + push @origlist, $1; + push @origlist, '"' . $2 . '"'; + } + elsif ($source =~ /^\s*([\w:-]+)\s*[=]\s*[']/) + { + $source =~ s|^\s*([\w:-]+)\s*[=]\s*[']([^']*)[']||s; + push @origlist, $1; + push @origlist, "'" . $2 . "'"; + } + else + { + last; + } + } + + my $ol = [ { @origlist } ]; + + push @{ $expat->{Lists} }, $expat->{Curlist}; + push @{ $expat->{Curlist} }, $tag => $ol; + $expat->{Curlist} = $ol; +} + +# Copied from intltool-merge.in.in and added comment handler. +sub readXml +{ + my $xmldoc = shift || return; + my $ret = eval 'require XML::Parser'; + if(!$ret) { + die "You must have XML::Parser installed to run $0\n\n"; + } + my $xp = new XML::Parser(Style => 'Tree'); + $xp->setHandlers(Char => \&intltool_tree_char); + $xp->setHandlers(Start => \&intltool_tree_start); + $xp->setHandlers(CdataStart => \&intltool_tree_cdatastart); + $xp->setHandlers(CdataEnd => \&intltool_tree_cdataend); + + ## differences from intltool-merge.in.in + $xp->setHandlers(Comment => \&intltool_tree_comment); + ## differences end here from intltool-merge.in.in + + my $tree = $xp->parse($xmldoc); + #print_var($tree); + +# Hello thereHowdydo +# would be: +# [foo, [{}, 1, "comment", head, [{id => "a"}, 0, "Hello ", em, [{}, 0, "there"]], bar, +# [{}, 0, "Howdy", ref, [{}]], 0, "do" ] ] + + return $tree; +} + +sub type_schemas { + ### For schemas XML files ### + + # FIXME: We should handle escaped < (less than) + while ($input =~ / + \s* + (\s*(?:\s*)?(.*?)\s*<\/default>\s*)? + (\s*(?:\s*)?(.*?)\s*<\/short>\s*)? + (\s*(?:\s*)?(.*?)\s*<\/long>\s*)? + <\/locale> + /sgx) { + my @totranslate = ($3,$6,$9); + my @eachcomment = ($2,$5,$8); + foreach (@totranslate) { + my $currentcomment = shift @eachcomment; + next if !$_; + s/\s+/ /g; + $messages{entity_decode_minimal($_)} = []; + $comments{entity_decode_minimal($_)} = $currentcomment if (defined($currentcomment)); + } + } +} + +sub type_rfc822deb { + ### For rfc822-style Debian configuration files ### + + my $lineno = 1; + my $type = ''; + while ($input =~ /\G(.*?)(^|\n)(_+)([^:]+):[ \t]*(.*?)(?=\n\S|$)/sg) + { + my ($pre, $newline, $underscore, $tag, $text) = ($1, $2, $3, $4, $5); + while ($pre =~ m/\n/g) + { + $lineno ++; + } + $lineno += length($newline); + my @str_list = rfc822deb_split(length($underscore), $text); + for my $str (@str_list) + { + $strcount++; + $messages{$str} = []; + $loc{$str} = $lineno; + $count{$str} = $strcount; + my $usercomment = ''; + while($pre =~ s/(^|\n)#([^\n]*)$//s) + { + $usercomment = "\n" . $2 . $usercomment; + } + $comments{$str} = $tag . $usercomment; + } + $lineno += ($text =~ s/\n//g); + } +} + +sub rfc822deb_split { + # Debian defines a special way to deal with rfc822-style files: + # when a value contain newlines, it consists of + # 1. a short form (first line) + # 2. a long description, all lines begin with a space, + # and paragraphs are separated by a single dot on a line + # This routine returns an array of all paragraphs, and reformat + # them. + # When first argument is 2, the string is a comma separated list of + # values. + my $type = shift; + my $text = shift; + $text =~ s/^[ \t]//mg; + return (split(/, */, $text, 0)) if $type ne 1; + return ($text) if $text !~ /\n/; + + $text =~ s/([^\n]*)\n//; + my @list = ($1); + my $str = ''; + for my $line (split (/\n/, $text)) + { + chomp $line; + if ($line =~ /^\.\s*$/) + { + # New paragraph + $str =~ s/\s*$//; + push(@list, $str); + $str = ''; + } + elsif ($line =~ /^\s/) + { + # Line which must not be reformatted + $str .= "\n" if length ($str) && $str !~ /\n$/; + $line =~ s/\s+$//; + $str .= $line."\n"; + } + else + { + # Continuation line, remove newline + $str .= " " if length ($str) && $str !~ /\n$/; + $str .= $line; + } + } + $str =~ s/\s*$//; + push(@list, $str) if length ($str); + return @list; +} + +sub type_glade { + ### For translatable Glade XML files ### + + my $tags = "label|title|text|format|copyright|comments|preview_text|tooltip|message"; + + while ($input =~ /<($tags)>([^<]+)<\/($tags)>/sg) { + # Glade sometimes uses tags that normally mark translatable things for + # little bits of non-translatable content. We work around this by not + # translating strings that only includes something like label4 or window1. + $messages{entity_decode($2)} = [] unless $2 =~ /^(window|label|dialog)[0-9]+$/; + } + + while ($input =~ /(..[^<]*)<\/items>/sg) { + for my $item (split (/\n/, $1)) { + $messages{entity_decode($item)} = []; + } + } + + ## handle new glade files + while ($input =~ /<(property|atkproperty)\s+[^>]*translatable\s*=\s*"yes"(?:\s+[^>]*comments\s*=\s*"([^"]*)")?[^>]*>([^<]+)<\/\1>/sg) { + $messages{entity_decode($3)} = [] unless $3 =~ /^(window|label)[0-9]+$/; + if (defined($2) and !($3 =~ /^(window|label)[0-9]+$/)) { + $comments{entity_decode($3)} = entity_decode($2) ; + } + } + while ($input =~ /]*)"\s+description="([^>]+)"\/>/sg) { + $messages{entity_decode_minimal($2)} = []; + } +} + +sub type_scheme { + my ($line, $i, $state, $str, $trcomment, $char); + for $line (split(/\n/, $input)) { + $i = 0; + $state = 0; # 0 - nothing, 1 - string, 2 - translatable string + while ($i < length($line)) { + if (substr($line,$i,1) eq "\"") { + if ($state == 2) { + $comments{$str} = $trcomment if ($trcomment); + $messages{$str} = []; + $str = ''; + $state = 0; $trcomment = ""; + } elsif ($state == 1) { + $str = ''; + $state = 0; $trcomment = ""; + } else { + $state = 1; + $str = ''; + if ($i>0 && substr($line,$i-1,1) eq '_') { + $state = 2; + } + } + } elsif (!$state) { + if (substr($line,$i,1) eq ";") { + $trcomment = substr($line,$i+1); + $trcomment =~ s/^;*\s*//; + $i = length($line); + } elsif ($trcomment && substr($line,$i,1) !~ /\s|\(|\)|_/) { + $trcomment = ""; + } + } else { + if (substr($line,$i,1) eq "\\") { + $char = substr($line,$i+1,1); + if ($char ne "\"" && $char ne "\\") { + $str = $str . "\\"; + } + $i++; + } + $str = $str . substr($line,$i,1); + } + $i++; + } + } +} + +sub msg_write { + my @msgids; + if (%count) + { + @msgids = sort { $count{$a} <=> $count{$b} } keys %count; + } + else + { + @msgids = sort keys %messages; + } + for my $message (@msgids) + { + my $offsetlines = 1; + $offsetlines++ if $message =~ /%/; + if (defined ($comments{$message})) + { + while ($comments{$message} =~ m/\n/g) + { + $offsetlines++; + } + } + print OUT "# ".($loc{$message} - $offsetlines). " \"$FILE\"\n" + if defined $loc{$message}; + print OUT "/* ".$comments{$message}." */\n" + if defined $comments{$message}; + print OUT "/* xgettext:no-c-format */\n" if $message =~ /%/; + + my @lines = split (/\n/, $message, -1); + for (my $n = 0; $n < @lines; $n++) + { + if ($n == 0) + { + print OUT "char *s = N_(\""; + } + else + { + print OUT " \""; + } + + print OUT escape($lines[$n]); + + if ($n < @lines - 1) + { + print OUT "\\n\"\n"; + } + else + { + print OUT "\");\n"; + } + } + } +} + diff --git a/vpn-daemons/pptp/intltool-merge.in b/vpn-daemons/pptp/intltool-merge.in new file mode 100755 index 0000000000..9b3a539d8b --- /dev/null +++ b/vpn-daemons/pptp/intltool-merge.in @@ -0,0 +1,1356 @@ +#!@INTLTOOL_PERL@ -w +# -*- Mode: perl; indent-tabs-mode: nil; c-basic-offset: 4 -*- + +# +# The Intltool Message Merger +# +# Copyright (C) 2000, 2003 Free Software Foundation. +# Copyright (C) 2000, 2001 Eazel, Inc +# +# Intltool is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# version 2 published by the Free Software Foundation. +# +# Intltool 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. +# +# Authors: Maciej Stachowiak +# Kenneth Christiansen +# Darin Adler +# +# Proper XML UTF-8'ification written by Cyrille Chepelov +# + +## Release information +my $PROGRAM = "intltool-merge"; +my $PACKAGE = "intltool"; +my $VERSION = "0.34.1"; + +## Loaded modules +use strict; +use Getopt::Long; +use Text::Wrap; +use File::Basename; + +my $must_end_tag = -1; +my $last_depth = -1; +my $translation_depth = -1; +my @tag_stack = (); +my @entered_tag = (); +my @translation_strings = (); +my $leading_space = ""; + +## Scalars used by the option stuff +my $HELP_ARG = 0; +my $VERSION_ARG = 0; +my $BA_STYLE_ARG = 0; +my $XML_STYLE_ARG = 0; +my $KEYS_STYLE_ARG = 0; +my $DESKTOP_STYLE_ARG = 0; +my $SCHEMAS_STYLE_ARG = 0; +my $RFC822DEB_STYLE_ARG = 0; +my $QUIET_ARG = 0; +my $PASS_THROUGH_ARG = 0; +my $UTF8_ARG = 0; +my $MULTIPLE_OUTPUT = 0; +my $cache_file; + +## Handle options +GetOptions +( + "help" => \$HELP_ARG, + "version" => \$VERSION_ARG, + "quiet|q" => \$QUIET_ARG, + "oaf-style|o" => \$BA_STYLE_ARG, ## for compatibility + "ba-style|b" => \$BA_STYLE_ARG, + "xml-style|x" => \$XML_STYLE_ARG, + "keys-style|k" => \$KEYS_STYLE_ARG, + "desktop-style|d" => \$DESKTOP_STYLE_ARG, + "schemas-style|s" => \$SCHEMAS_STYLE_ARG, + "rfc822deb-style|r" => \$RFC822DEB_STYLE_ARG, + "pass-through|p" => \$PASS_THROUGH_ARG, + "utf8|u" => \$UTF8_ARG, + "multiple-output|m" => \$MULTIPLE_OUTPUT, + "cache|c=s" => \$cache_file + ) or &error; + +my $PO_DIR; +my $FILE; +my $OUTFILE; + +my %po_files_by_lang = (); +my %translations = (); +my $iconv = $ENV{"ICONV"} || $ENV{"INTLTOOL_ICONV"} || "/usr/bin/iconv"; +my $devnull = ($^O eq 'MSWin32' ? 'NUL:' : '/dev/null'); + +# Use this instead of \w for XML files to handle more possible characters. +my $w = "[-A-Za-z0-9._:]"; + +# XML quoted string contents +my $q = "[^\\\"]*"; + +## Check for options. + +if ($VERSION_ARG) +{ + &print_version; +} +elsif ($HELP_ARG) +{ + &print_help; +} +elsif ($BA_STYLE_ARG && @ARGV > 2) +{ + &utf8_sanity_check; + &preparation; + &print_message; + &ba_merge_translations; + &finalize; +} +elsif ($XML_STYLE_ARG && @ARGV > 2) +{ + &utf8_sanity_check; + &preparation; + &print_message; + &xml_merge_output; + &finalize; +} +elsif ($KEYS_STYLE_ARG && @ARGV > 2) +{ + &utf8_sanity_check; + &preparation; + &print_message; + &keys_merge_translations; + &finalize; +} +elsif ($DESKTOP_STYLE_ARG && @ARGV > 2) +{ + &utf8_sanity_check; + &preparation; + &print_message; + &desktop_merge_translations; + &finalize; +} +elsif ($SCHEMAS_STYLE_ARG && @ARGV > 2) +{ + &utf8_sanity_check; + &preparation; + &print_message; + &schemas_merge_translations; + &finalize; +} +elsif ($RFC822DEB_STYLE_ARG && @ARGV > 2) +{ + &preparation; + &print_message; + &rfc822deb_merge_translations; + &finalize; +} +else +{ + &print_help; +} + +exit; + +## Sub for printing release information +sub print_version +{ + print <<_EOF_; +${PROGRAM} (${PACKAGE}) ${VERSION} +Written by Maciej Stachowiak, Darin Adler and Kenneth Christiansen. + +Copyright (C) 2000-2003 Free Software Foundation, Inc. +Copyright (C) 2000-2001 Eazel, Inc. +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +_EOF_ + exit; +} + +## Sub for printing usage information +sub print_help +{ + print <<_EOF_; +Usage: ${PROGRAM} [OPTION]... PO_DIRECTORY FILENAME OUTPUT_FILE +Generates an output file that includes some localized attributes from an +untranslated source file. + +Mandatory options: (exactly one must be specified) + -b, --ba-style includes translations in the bonobo-activation style + -d, --desktop-style includes translations in the desktop style + -k, --keys-style includes translations in the keys style + -s, --schemas-style includes translations in the schemas style + -r, --rfc822deb-style includes translations in the RFC822 style + -x, --xml-style includes translations in the standard xml style + +Other options: + -u, --utf8 convert all strings to UTF-8 before merging + (default for everything except RFC822 style) + -p, --pass-through deprecated, does nothing and issues a warning + -m, --multiple-output output one localized file per locale, instead of + a single file containing all localized elements + -c, --cache=FILE specify cache file name + (usually \$top_builddir/po/.intltool-merge-cache) + -q, --quiet suppress most messages + --help display this help and exit + --version output version information and exit + +Report bugs to http://bugzilla.gnome.org/ (product name "$PACKAGE") +or send email to . +_EOF_ + exit; +} + + +## Sub for printing error messages +sub print_error +{ + print STDERR "Try `${PROGRAM} --help' for more information.\n"; + exit; +} + + +sub print_message +{ + print "Merging translations into $OUTFILE.\n" unless $QUIET_ARG; +} + + +sub preparation +{ + $PO_DIR = $ARGV[0]; + $FILE = $ARGV[1]; + $OUTFILE = $ARGV[2]; + + &gather_po_files; + &get_translation_database; +} + +# General-purpose code for looking up translations in .po files + +sub po_file2lang +{ + my ($tmp) = @_; + $tmp =~ s/^.*\/(.*)\.po$/$1/; + return $tmp; +} + +sub gather_po_files +{ + for my $po_file (glob "$PO_DIR/*.po") { + $po_files_by_lang{po_file2lang($po_file)} = $po_file; + } +} + +sub get_local_charset +{ + my ($encoding) = @_; + my $alias_file = $ENV{"G_CHARSET_ALIAS"} || "/usr/lib/charset.alias"; + + # seek character encoding aliases in charset.alias (glib) + + if (open CHARSET_ALIAS, $alias_file) + { + while () + { + next if /^\#/; + return $1 if (/^\s*([-._a-zA-Z0-9]+)\s+$encoding\b/i) + } + + close CHARSET_ALIAS; + } + + # if not found, return input string + + return $encoding; +} + +sub get_po_encoding +{ + my ($in_po_file) = @_; + my $encoding = ""; + + open IN_PO_FILE, $in_po_file or die; + while () + { + ## example: "Content-Type: text/plain; charset=ISO-8859-1\n" + if (/Content-Type\:.*charset=([-a-zA-Z0-9]+)\\n/) + { + $encoding = $1; + last; + } + } + close IN_PO_FILE; + + if (!$encoding) + { + print STDERR "Warning: no encoding found in $in_po_file. Assuming ISO-8859-1\n" unless $QUIET_ARG; + $encoding = "ISO-8859-1"; + } + + system ("$iconv -f $encoding -t UTF-8 <$devnull 2>$devnull"); + if ($?) { + $encoding = get_local_charset($encoding); + } + + return $encoding +} + +sub utf8_sanity_check +{ + print STDERR "Warning: option --pass-through has been removed.\n" if $PASS_THROUGH_ARG; + $UTF8_ARG = 1; +} + +sub get_translation_database +{ + if ($cache_file) { + &get_cached_translation_database; + } else { + &create_translation_database; + } +} + +sub get_newest_po_age +{ + my $newest_age; + + foreach my $file (values %po_files_by_lang) + { + my $file_age = -M $file; + $newest_age = $file_age if !$newest_age || $file_age < $newest_age; + } + + $newest_age = 0 if !$newest_age; + + return $newest_age; +} + +sub create_cache +{ + print "Generating and caching the translation database\n" unless $QUIET_ARG; + + &create_translation_database; + + open CACHE, ">$cache_file" || die; + print CACHE join "\x01", %translations; + close CACHE; +} + +sub load_cache +{ + print "Found cached translation database\n" unless $QUIET_ARG; + + my $contents; + open CACHE, "<$cache_file" || die; + { + local $/; + $contents = ; + } + close CACHE; + %translations = split "\x01", $contents; +} + +sub get_cached_translation_database +{ + my $cache_file_age = -M $cache_file; + if (defined $cache_file_age) + { + if ($cache_file_age <= &get_newest_po_age) + { + &load_cache; + return; + } + print "Found too-old cached translation database\n" unless $QUIET_ARG; + } + + &create_cache; +} + +sub create_translation_database +{ + for my $lang (keys %po_files_by_lang) + { + my $po_file = $po_files_by_lang{$lang}; + + if ($UTF8_ARG) + { + my $encoding = get_po_encoding ($po_file); + + if (lc $encoding eq "utf-8") + { + open PO_FILE, "<$po_file"; + } + else + { + print STDERR "WARNING: $po_file is not in UTF-8 but $encoding, converting...\n" unless $QUIET_ARG;; + + open PO_FILE, "$iconv -f $encoding -t UTF-8 $po_file|"; + } + } + else + { + open PO_FILE, "<$po_file"; + } + + my $nextfuzzy = 0; + my $inmsgid = 0; + my $inmsgstr = 0; + my $msgid = ""; + my $msgstr = ""; + + while () + { + $nextfuzzy = 1 if /^#, fuzzy/; + + if (/^msgid "((\\.|[^\\])*)"/ ) + { + $translations{$lang, $msgid} = $msgstr if $inmsgstr && $msgid && $msgstr; + $msgid = ""; + $msgstr = ""; + + if ($nextfuzzy) { + $inmsgid = 0; + } else { + $msgid = unescape_po_string($1); + $inmsgid = 1; + } + $inmsgstr = 0; + $nextfuzzy = 0; + } + + if (/^msgstr "((\\.|[^\\])*)"/) + { + $msgstr = unescape_po_string($1); + $inmsgstr = 1; + $inmsgid = 0; + } + + if (/^"((\\.|[^\\])*)"/) + { + $msgid .= unescape_po_string($1) if $inmsgid; + $msgstr .= unescape_po_string($1) if $inmsgstr; + } + } + $translations{$lang, $msgid} = $msgstr if $inmsgstr && $msgid && $msgstr; + } +} + +sub finalize +{ +} + +sub unescape_one_sequence +{ + my ($sequence) = @_; + + return "\\" if $sequence eq "\\\\"; + return "\"" if $sequence eq "\\\""; + return "\n" if $sequence eq "\\n"; + return "\r" if $sequence eq "\\r"; + return "\t" if $sequence eq "\\t"; + return "\b" if $sequence eq "\\b"; + return "\f" if $sequence eq "\\f"; + return "\a" if $sequence eq "\\a"; + return chr(11) if $sequence eq "\\v"; # vertical tab, see ascii(7) + + return chr(hex($1)) if ($sequence =~ /\\x([0-9a-fA-F]{2})/); + return chr(oct($1)) if ($sequence =~ /\\([0-7]{3})/); + + # FIXME: Is \0 supported as well? Kenneth and Rodney don't want it, see bug #48489 + + return $sequence; +} + +sub unescape_po_string +{ + my ($string) = @_; + + $string =~ s/(\\x[0-9a-fA-F]{2}|\\[0-7]{3}|\\.)/unescape_one_sequence($1)/eg; + + return $string; +} + +## NOTE: deal with < - < but not > - > because it seems its ok to have +## > in the entity. For further info please look at #84738. +sub entity_decode +{ + local ($_) = @_; + + s/'/'/g; # ' + s/"/"/g; # " + s/&/&/g; + s/</; + close INPUT; + } + + open OUTPUT, ">$OUTFILE" or die "can't open $OUTFILE: $!"; + # Binmode so that selftest works ok if using a native Win32 Perl... + binmode (OUTPUT) if $^O eq 'MSWin32'; + + while ($source =~ s|^(.*?)([ \t]*<\s*$w+\s+($w+\s*=\s*"$q"\s*)+/?>)([ \t]*\n)?||s) + { + print OUTPUT $1; + + my $node = $2 . "\n"; + + my @strings = (); + $_ = $node; + while (s/(\s)_($w+\s*=\s*"($q)")/$1$2/s) { + push @strings, entity_decode($3); + } + print OUTPUT; + + my %langs; + for my $string (@strings) + { + for my $lang (keys %po_files_by_lang) + { + $langs{$lang} = 1 if $translations{$lang, $string}; + } + } + + for my $lang (sort keys %langs) + { + $_ = $node; + s/(\sname\s*=\s*)"($q)"/$1"$2-$lang"/s; + s/(\s)_($w+\s*=\s*")($q)"/$1 . $2 . entity_encoded_translation($lang, $3) . '"'/seg; + print OUTPUT; + } + } + + print OUTPUT $source; + + close OUTPUT; +} + + +## XML (non-bonobo-activation) merge code + + +# Process tag attributes +# Only parameter is a HASH containing attributes -> values mapping +sub getAttributeString +{ + my $sub = shift; + my $do_translate = shift || 0; + my $language = shift || ""; + my $result = ""; + my $translate = shift; + foreach my $e (reverse(sort(keys %{ $sub }))) { + my $key = $e; + my $string = $sub->{$e}; + my $quote = '"'; + + $string =~ s/^[\s]+//; + $string =~ s/[\s]+$//; + + if ($string =~ /^'.*'$/) + { + $quote = "'"; + } + $string =~ s/^['"]//g; + $string =~ s/['"]$//g; + + if ($do_translate && $key =~ /^_/) { + $key =~ s|^_||g; + if ($language) { + # Handle translation + my $decode_string = entity_decode($string); + my $translation = $translations{$language, $decode_string}; + if ($translation) { + $translation = entity_encode($translation); + $string = $translation; + } + $$translate = 2; + } else { + $$translate = 2 if ($translate && (!$$translate)); # watch not to "overwrite" $translate + } + } + + $result .= " $key=$quote$string$quote"; + } + return $result; +} + +# Returns a translatable string from XML node, it works on contents of every node in XML::Parser tree +sub getXMLstring +{ + my $ref = shift; + my $spacepreserve = shift || 0; + my @list = @{ $ref }; + my $result = ""; + + my $count = scalar(@list); + my $attrs = $list[0]; + my $index = 1; + + $spacepreserve = 1 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?preserve["']?$/)); + $spacepreserve = 0 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?default["']?$/)); + + while ($index < $count) { + my $type = $list[$index]; + my $content = $list[$index+1]; + if (! $type ) { + # We've got CDATA + if ($content) { + # lets strip the whitespace here, and *ONLY* here + $content =~ s/\s+/ /gs if (!$spacepreserve); + $result .= $content; + } + } elsif ( "$type" ne "1" ) { + # We've got another element + $result .= "<$type"; + $result .= getAttributeString(@{$content}[0], 0); # no nested translatable elements + if ($content) { + my $subresult = getXMLstring($content, $spacepreserve); + if ($subresult) { + $result .= ">".$subresult . ""; + } else { + $result .= "/>"; + } + } else { + $result .= "/>"; + } + } + $index += 2; + } + return $result; +} + +# Translate list of nodes if necessary +sub translate_subnodes +{ + my $fh = shift; + my $content = shift; + my $language = shift || ""; + my $singlelang = shift || 0; + my $spacepreserve = shift || 0; + + my @nodes = @{ $content }; + + my $count = scalar(@nodes); + my $index = 0; + while ($index < $count) { + my $type = $nodes[$index]; + my $rest = $nodes[$index+1]; + if ($singlelang) { + my $oldMO = $MULTIPLE_OUTPUT; + $MULTIPLE_OUTPUT = 1; + traverse($fh, $type, $rest, $language, $spacepreserve); + $MULTIPLE_OUTPUT = $oldMO; + } else { + traverse($fh, $type, $rest, $language, $spacepreserve); + } + $index += 2; + } +} + +sub isWellFormedXmlFragment +{ + my $ret = eval 'require XML::Parser'; + if(!$ret) { + die "You must have XML::Parser installed to run $0\n\n"; + } + + my $fragment = shift; + return 0 if (!$fragment); + + $fragment = "$fragment"; + my $xp = new XML::Parser(Style => 'Tree'); + my $tree = 0; + eval { $tree = $xp->parse($fragment); }; + return $tree; +} + +sub traverse +{ + my $fh = shift; + my $nodename = shift; + my $content = shift; + my $language = shift || ""; + my $spacepreserve = shift || 0; + + if (!$nodename) { + if ($content =~ /^[\s]*$/) { + $leading_space .= $content; + } + print $fh $content; + } else { + # element + my @all = @{ $content }; + my $attrs = shift @all; + my $translate = 0; + my $outattr = getAttributeString($attrs, 1, $language, \$translate); + + if ($nodename =~ /^_/) { + $translate = 1; + $nodename =~ s/^_//; + } + my $lookup = ''; + + $spacepreserve = 0 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?default["']?$/)); + $spacepreserve = 1 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?preserve["']?$/)); + + print $fh "<$nodename", $outattr; + if ($translate) { + $lookup = getXMLstring($content, $spacepreserve); + if (!$spacepreserve) { + $lookup =~ s/^\s+//s; + $lookup =~ s/\s+$//s; + } + + if ($lookup || $translate == 2) { + my $translation = $translations{$language, $lookup} if isWellFormedXmlFragment($translations{$language, $lookup}); + if ($MULTIPLE_OUTPUT && ($translation || $translate == 2)) { + $translation = $lookup if (!$translation); + print $fh " xml:lang=\"", $language, "\"" if $language; + print $fh ">"; + if ($translate == 2) { + translate_subnodes($fh, \@all, $language, 1, $spacepreserve); + } else { + print $fh $translation; + } + print $fh ""; + + return; # this means there will be no same translation with xml:lang="$language"... + # if we want them both, just remove this "return" + } else { + print $fh ">"; + if ($translate == 2) { + translate_subnodes($fh, \@all, $language, 1, $spacepreserve); + } else { + print $fh $lookup; + } + print $fh ""; + } + } else { + print $fh "/>"; + } + + for my $lang (sort keys %po_files_by_lang) { + if ($MULTIPLE_OUTPUT && $lang ne "$language") { + next; + } + if ($lang) { + # Handle translation + # + my $translate = 0; + my $localattrs = getAttributeString($attrs, 1, $lang, \$translate); + my $translation = $translations{$lang, $lookup} if isWellFormedXmlFragment($translations{$lang, $lookup}); + if ($translate && !$translation) { + $translation = $lookup; + } + + if ($translation || $translate) { + print $fh "\n"; + $leading_space =~ s/.*\n//g; + print $fh $leading_space; + print $fh "<", $nodename, " xml:lang=\"", $lang, "\"", $localattrs, ">"; + if ($translate == 2) { + translate_subnodes($fh, \@all, $lang, 1, $spacepreserve); + } else { + print $fh $translation; + } + print $fh ""; + } + } + } + + } else { + my $count = scalar(@all); + if ($count > 0) { + print $fh ">"; + my $index = 0; + while ($index < $count) { + my $type = $all[$index]; + my $rest = $all[$index+1]; + traverse($fh, $type, $rest, $language, $spacepreserve); + $index += 2; + } + print $fh ""; + } else { + print $fh "/>"; + } + } + } +} + +sub intltool_tree_comment +{ + my $expat = shift; + my $data = shift; + my $clist = $expat->{Curlist}; + my $pos = $#$clist; + + push @$clist, 1 => $data; +} + +sub intltool_tree_cdatastart +{ + my $expat = shift; + my $clist = $expat->{Curlist}; + my $pos = $#$clist; + + push @$clist, 0 => $expat->original_string(); +} + +sub intltool_tree_cdataend +{ + my $expat = shift; + my $clist = $expat->{Curlist}; + my $pos = $#$clist; + + $clist->[$pos] .= $expat->original_string(); +} + +sub intltool_tree_char +{ + my $expat = shift; + my $text = shift; + my $clist = $expat->{Curlist}; + my $pos = $#$clist; + + # Use original_string so that we retain escaped entities + # in CDATA sections. + # + if ($pos > 0 and $clist->[$pos - 1] eq '0') { + $clist->[$pos] .= $expat->original_string(); + } else { + push @$clist, 0 => $expat->original_string(); + } +} + +sub intltool_tree_start +{ + my $expat = shift; + my $tag = shift; + my @origlist = (); + + # Use original_string so that we retain escaped entities + # in attribute values. We must convert the string to an + # @origlist array to conform to the structure of the Tree + # Style. + # + my @original_array = split /\x/, $expat->original_string(); + my $source = $expat->original_string(); + + # Remove leading tag. + # + $source =~ s|^\s*<\s*(\S+)||s; + + # Grab attribute key/value pairs and push onto @origlist array. + # + while ($source) + { + if ($source =~ /^\s*([\w:-]+)\s*[=]\s*["]/) + { + $source =~ s|^\s*([\w:-]+)\s*[=]\s*["]([^"]*)["]||s; + push @origlist, $1; + push @origlist, '"' . $2 . '"'; + } + elsif ($source =~ /^\s*([\w:-]+)\s*[=]\s*[']/) + { + $source =~ s|^\s*([\w:-]+)\s*[=]\s*[']([^']*)[']||s; + push @origlist, $1; + push @origlist, "'" . $2 . "'"; + } + else + { + last; + } + } + + my $ol = [ { @origlist } ]; + + push @{ $expat->{Lists} }, $expat->{Curlist}; + push @{ $expat->{Curlist} }, $tag => $ol; + $expat->{Curlist} = $ol; +} + +sub readXml +{ + my $filename = shift || return; + if(!-f $filename) { + die "ERROR Cannot find filename: $filename\n"; + } + + my $ret = eval 'require XML::Parser'; + if(!$ret) { + die "You must have XML::Parser installed to run $0\n\n"; + } + my $xp = new XML::Parser(Style => 'Tree'); + $xp->setHandlers(Char => \&intltool_tree_char); + $xp->setHandlers(Start => \&intltool_tree_start); + $xp->setHandlers(CdataStart => \&intltool_tree_cdatastart); + $xp->setHandlers(CdataEnd => \&intltool_tree_cdataend); + my $tree = $xp->parsefile($filename); + +# Hello thereHowdydo +# would be: +# [foo, [{}, head, [{id => "a"}, 0, "Hello ", em, [{}, 0, "there"]], bar, [{}, +# 0, "Howdy", ref, [{}]], 0, "do" ] ] + + return $tree; +} + +sub print_header +{ + my $infile = shift; + my $fh = shift; + my $source; + + if(!-f $infile) { + die "ERROR Cannot find filename: $infile\n"; + } + + print $fh qq{\n}; + { + local $/; + open DOCINPUT, "<${FILE}" or die; + $source = ; + close DOCINPUT; + } + if ($source =~ /()/s) + { + print $fh "$1\n"; + } + elsif ($source =~ /(]*>)/s) + { + print $fh "$1\n"; + } +} + +sub parseTree +{ + my $fh = shift; + my $ref = shift; + my $language = shift || ""; + + my $name = shift @{ $ref }; + my $cont = shift @{ $ref }; + + while (!$name || "$name" eq "1") { + $name = shift @{ $ref }; + $cont = shift @{ $ref }; + } + + my $spacepreserve = 0; + my $attrs = @{$cont}[0]; + $spacepreserve = 1 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?preserve["']?$/)); + + traverse($fh, $name, $cont, $language, $spacepreserve); +} + +sub xml_merge_output +{ + my $source; + + if ($MULTIPLE_OUTPUT) { + for my $lang (sort keys %po_files_by_lang) { + if ( ! -e $lang ) { + mkdir $lang or die "Cannot create subdirectory $lang: $!\n"; + } + open OUTPUT, ">$lang/$OUTFILE" or die "Cannot open $lang/$OUTFILE: $!\n"; + binmode (OUTPUT) if $^O eq 'MSWin32'; + my $tree = readXml($FILE); + print_header($FILE, \*OUTPUT); + parseTree(\*OUTPUT, $tree, $lang); + close OUTPUT; + print "CREATED $lang/$OUTFILE\n" unless $QUIET_ARG; + } + } + open OUTPUT, ">$OUTFILE" or die "Cannot open $OUTFILE: $!\n"; + binmode (OUTPUT) if $^O eq 'MSWin32'; + my $tree = readXml($FILE); + print_header($FILE, \*OUTPUT); + parseTree(\*OUTPUT, $tree); + close OUTPUT; + print "CREATED $OUTFILE\n" unless $QUIET_ARG; +} + +sub keys_merge_translations +{ + open INPUT, "<${FILE}" or die; + open OUTPUT, ">${OUTFILE}" or die; + binmode (OUTPUT) if $^O eq 'MSWin32'; + + while () + { + if (s/^(\s*)_(\w+=(.*))/$1$2/) + { + my $string = $3; + + print OUTPUT; + + my $non_translated_line = $_; + + for my $lang (sort keys %po_files_by_lang) + { + my $translation = $translations{$lang, $string}; + next if !$translation; + + $_ = $non_translated_line; + s/(\w+)=.*/[$lang]$1=$translation/; + print OUTPUT; + } + } + else + { + print OUTPUT; + } + } + + close OUTPUT; + close INPUT; +} + +sub desktop_merge_translations +{ + open INPUT, "<${FILE}" or die; + open OUTPUT, ">${OUTFILE}" or die; + binmode (OUTPUT) if $^O eq 'MSWin32'; + + while () + { + if (s/^(\s*)_(\w+=(.*))/$1$2/) + { + my $string = $3; + + print OUTPUT; + + my $non_translated_line = $_; + + for my $lang (sort keys %po_files_by_lang) + { + my $translation = $translations{$lang, $string}; + next if !$translation; + + $_ = $non_translated_line; + s/(\w+)=.*/${1}[$lang]=$translation/; + print OUTPUT; + } + } + else + { + print OUTPUT; + } + } + + close OUTPUT; + close INPUT; +} + +sub schemas_merge_translations +{ + my $source; + + { + local $/; # slurp mode + open INPUT, "<$FILE" or die "can't open $FILE: $!"; + $source = ; + close INPUT; + } + + open OUTPUT, ">$OUTFILE" or die; + binmode (OUTPUT) if $^O eq 'MSWin32'; + + # FIXME: support attribute translations + + # Empty nodes never need translation, so unmark all of them. + # For example, <_foo/> is just replaced by . + $source =~ s|<\s*_($w+)\s*/>|<$1/>|g; + + while ($source =~ s/ + (.*?) + (\s+)((\s*) + (\s*(?:\s*)?(.*?)\s*<\/default>)?(\s*) + (\s*(?:\s*)?(.*?)\s*<\/short>)?(\s*) + (\s*(?:\s*)?(.*?)\s*<\/long>)?(\s*) + <\/locale>) + //sx) + { + print OUTPUT $1; + + my $locale_start_spaces = $2 ? $2 : ''; + my $default_spaces = $4 ? $4 : ''; + my $short_spaces = $7 ? $7 : ''; + my $long_spaces = $10 ? $10 : ''; + my $locale_end_spaces = $13 ? $13 : ''; + my $c_default_block = $3 ? $3 : ''; + my $default_string = $6 ? $6 : ''; + my $short_string = $9 ? $9 : ''; + my $long_string = $12 ? $12 : ''; + + print OUTPUT "$locale_start_spaces$c_default_block"; + + $default_string =~ s/\s+/ /g; + $default_string = entity_decode($default_string); + $short_string =~ s/\s+/ /g; + $short_string = entity_decode($short_string); + $long_string =~ s/\s+/ /g; + $long_string = entity_decode($long_string); + + for my $lang (sort keys %po_files_by_lang) + { + my $default_translation = $translations{$lang, $default_string}; + my $short_translation = $translations{$lang, $short_string}; + my $long_translation = $translations{$lang, $long_string}; + + next if (!$default_translation && !$short_translation && + !$long_translation); + + print OUTPUT "\n$locale_start_spaces"; + + print OUTPUT "$default_spaces"; + + if ($default_translation) + { + $default_translation = entity_encode($default_translation); + print OUTPUT "$default_translation"; + } + + print OUTPUT "$short_spaces"; + + if ($short_translation) + { + $short_translation = entity_encode($short_translation); + print OUTPUT "$short_translation"; + } + + print OUTPUT "$long_spaces"; + + if ($long_translation) + { + $long_translation = entity_encode($long_translation); + print OUTPUT "$long_translation"; + } + + print OUTPUT "$locale_end_spaces"; + } + } + + print OUTPUT $source; + + close OUTPUT; +} + +sub rfc822deb_merge_translations +{ + my %encodings = (); + for my $lang (keys %po_files_by_lang) { + $encodings{$lang} = ($UTF8_ARG ? 'UTF-8' : get_po_encoding($po_files_by_lang{$lang})); + } + + my $source; + + $Text::Wrap::huge = 'overflow'; + $Text::Wrap::break = qr/\n|\s(?=\S)/; + + { + local $/; # slurp mode + open INPUT, "<$FILE" or die "can't open $FILE: $!"; + $source = ; + close INPUT; + } + + open OUTPUT, ">${OUTFILE}" or die; + binmode (OUTPUT) if $^O eq 'MSWin32'; + + while ($source =~ /(^|\n+)(_*)([^:\s]+)(:[ \t]*)(.*?)(?=\n[\S\n]|$)/sg) + { + my $sep = $1; + my $non_translated_line = $3.$4; + my $string = $5; + my $underscore = length($2); + next if $underscore eq 0 && $non_translated_line =~ /^#/; + # Remove [] dummy strings + my $stripped = $string; + $stripped =~ s/\[\s[^\[\]]*\],/,/g if $underscore eq 2; + $stripped =~ s/\[\s[^\[\]]*\]$//; + $non_translated_line .= $stripped; + + print OUTPUT $sep.$non_translated_line; + + if ($underscore) + { + my @str_list = rfc822deb_split($underscore, $string); + + for my $lang (sort keys %po_files_by_lang) + { + my $is_translated = 1; + my $str_translated = ''; + my $first = 1; + + for my $str (@str_list) + { + my $translation = $translations{$lang, $str}; + + if (!$translation) + { + $is_translated = 0; + last; + } + + # $translation may also contain [] dummy + # strings, mostly to indicate an empty string + $translation =~ s/\[\s[^\[\]]*\]$//; + + if ($first) + { + if ($underscore eq 2) + { + $str_translated .= $translation; + } + else + { + $str_translated .= + Text::Tabs::expand($translation) . + "\n"; + } + } + else + { + if ($underscore eq 2) + { + $str_translated .= ', ' . $translation; + } + else + { + $str_translated .= Text::Tabs::expand( + Text::Wrap::wrap(' ', ' ', $translation)) . + "\n .\n"; + } + } + $first = 0; + + # To fix some problems with Text::Wrap::wrap + $str_translated =~ s/(\n )+\n/\n .\n/g; + } + next unless $is_translated; + + $str_translated =~ s/\n \.\n$//; + $str_translated =~ s/\s+$//; + + $_ = $non_translated_line; + s/^(\w+):\s*.*/$sep${1}-$lang.$encodings{$lang}: $str_translated/s; + print OUTPUT; + } + } + } + print OUTPUT "\n"; + + close OUTPUT; + close INPUT; +} + +sub rfc822deb_split +{ + # Debian defines a special way to deal with rfc822-style files: + # when a value contain newlines, it consists of + # 1. a short form (first line) + # 2. a long description, all lines begin with a space, + # and paragraphs are separated by a single dot on a line + # This routine returns an array of all paragraphs, and reformat + # them. + # When first argument is 2, the string is a comma separated list of + # values. + my $type = shift; + my $text = shift; + $text =~ s/^[ \t]//mg; + return (split(/, */, $text, 0)) if $type ne 1; + return ($text) if $text !~ /\n/; + + $text =~ s/([^\n]*)\n//; + my @list = ($1); + my $str = ''; + + for my $line (split (/\n/, $text)) + { + chomp $line; + if ($line =~ /^\.\s*$/) + { + # New paragraph + $str =~ s/\s*$//; + push(@list, $str); + $str = ''; + } + elsif ($line =~ /^\s/) + { + # Line which must not be reformatted + $str .= "\n" if length ($str) && $str !~ /\n$/; + $line =~ s/\s+$//; + $str .= $line."\n"; + } + else + { + # Continuation line, remove newline + $str .= " " if length ($str) && $str !~ /\n$/; + $str .= $line; + } + } + + $str =~ s/\s*$//; + push(@list, $str) if length ($str); + + return @list; +} + diff --git a/vpn-daemons/pptp/intltool-update.in b/vpn-daemons/pptp/intltool-update.in new file mode 100755 index 0000000000..f251956ca0 --- /dev/null +++ b/vpn-daemons/pptp/intltool-update.in @@ -0,0 +1,1065 @@ +#!@INTLTOOL_PERL@ -w +# -*- Mode: perl; indent-tabs-mode: nil; c-basic-offset: 4 -*- + +# +# The Intltool Message Updater +# +# Copyright (C) 2000-2003 Free Software Foundation. +# +# Intltool is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# version 2 published by the Free Software Foundation. +# +# Intltool 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. +# +# Authors: Kenneth Christiansen +# Maciej Stachowiak +# Darin Adler + +## Release information +my $PROGRAM = "intltool-update"; +my $VERSION = "0.34.1"; +my $PACKAGE = "intltool"; + +## Loaded modules +use strict; +use Getopt::Long; +use Cwd; +use File::Copy; +use File::Find; + +## Scalars used by the option stuff +my $HELP_ARG = 0; +my $VERSION_ARG = 0; +my $DIST_ARG = 0; +my $POT_ARG = 0; +my $HEADERS_ARG = 0; +my $MAINTAIN_ARG = 0; +my $REPORT_ARG = 0; +my $VERBOSE = 0; +my $GETTEXT_PACKAGE = ""; +my $OUTPUT_FILE = ""; + +my @languages; +my %varhash = (); +my %po_files_by_lang = (); + +# Regular expressions to categorize file types. +# FIXME: Please check if the following is correct + +my $xml_support = +"xml(?:\\.in)*|". # http://www.w3.org/XML/ (Note: .in is not required) +"ui|". # Bonobo specific - User Interface desc. files +"lang|". # ? +"glade2?(?:\\.in)*|". # Glade specific - User Interface desc. files (Note: .in is not required) +"scm(?:\\.in)*|". # ? (Note: .in is not required) +"oaf(?:\\.in)+|". # DEPRECATED: Replaces by Bonobo .server files +"etspec|". # ? +"server(?:\\.in)+|". # Bonobo specific +"sheet(?:\\.in)+|". # ? +"schemas(?:\\.in)+|". # GConf specific +"pong(?:\\.in)+|". # DEPRECATED: PONG is not used [by GNOME] any longer. +"kbd(?:\\.in)+"; # GOK specific. + +my $ini_support = +"icon(?:\\.in)+|". # http://www.freedesktop.org/Standards/icon-theme-spec +"desktop(?:\\.in)+|". # http://www.freedesktop.org/Standards/menu-spec +"caves(?:\\.in)+|". # GNOME Games specific +"directory(?:\\.in)+|". # http://www.freedesktop.org/Standards/menu-spec +"soundlist(?:\\.in)+|". # GNOME specific +"keys(?:\\.in)+|". # GNOME Mime database specific +"theme(?:\\.in)+"; # http://www.freedesktop.org/Standards/icon-theme-spec + +my $buildin_gettext_support = +"c|y|cs|cc|cpp|c\\+\\+|h|hh|gob|py"; + +## Always flush buffer when printing +$| = 1; + +## Sometimes the source tree will be rooted somewhere else. +my $SRCDIR = "."; +my $POTFILES_in; + +$SRCDIR = $ENV{"srcdir"} if $ENV{"srcdir"}; +$POTFILES_in = "<$SRCDIR/POTFILES.in"; + +my $devnull = ($^O eq 'MSWin32' ? 'NUL:' : '/dev/null'); + +## Handle options +GetOptions +( + "help" => \$HELP_ARG, + "version" => \$VERSION_ARG, + "dist|d" => \$DIST_ARG, + "pot|p" => \$POT_ARG, + "headers|s" => \$HEADERS_ARG, + "maintain|m" => \$MAINTAIN_ARG, + "report|r" => \$REPORT_ARG, + "verbose|x" => \$VERBOSE, + "gettext-package|g=s" => \$GETTEXT_PACKAGE, + "output-file|o=s" => \$OUTPUT_FILE, + ) or &Console_WriteError_InvalidOption; + +&Console_Write_IntltoolHelp if $HELP_ARG; +&Console_Write_IntltoolVersion if $VERSION_ARG; + +my $arg_count = ($DIST_ARG > 0) + + ($POT_ARG > 0) + + ($HEADERS_ARG > 0) + + ($MAINTAIN_ARG > 0) + + ($REPORT_ARG > 0); + +&Console_Write_IntltoolHelp if $arg_count > 1; + +# --version and --help don't require a module name +my $MODULE = $GETTEXT_PACKAGE || &FindPackageName; + +if ($POT_ARG) +{ + &GenerateHeaders; + &GeneratePOTemplate; +} +elsif ($HEADERS_ARG) +{ + &GenerateHeaders; +} +elsif ($MAINTAIN_ARG) +{ + &FindLeftoutFiles; +} +elsif ($REPORT_ARG) +{ + &GenerateHeaders; + &GeneratePOTemplate; + &Console_Write_CoverageReport; +} +elsif ((defined $ARGV[0]) && $ARGV[0] =~ /^[a-z]/) +{ + my $lang = $ARGV[0]; + + ## Report error if the language file supplied + ## to the command line is non-existent + &Console_WriteError_NotExisting("$SRCDIR/$lang.po") + if ! -s "$SRCDIR/$lang.po"; + + if (!$DIST_ARG) + { + print "Working, please wait..." if $VERBOSE; + &GenerateHeaders; + &GeneratePOTemplate; + } + &POFile_Update ($lang, $OUTPUT_FILE); + &Console_Write_TranslationStatus ($lang, $OUTPUT_FILE); +} +else +{ + &Console_Write_IntltoolHelp; +} + +exit; + +######### + +sub Console_Write_IntltoolVersion +{ + print <<_EOF_; +${PROGRAM} (${PACKAGE}) $VERSION +Written by Kenneth Christiansen, Maciej Stachowiak, and Darin Adler. + +Copyright (C) 2000-2003 Free Software Foundation, Inc. +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +_EOF_ + exit; +} + +sub Console_Write_IntltoolHelp +{ + print <<_EOF_; +Usage: ${PROGRAM} [OPTION]... LANGCODE +Updates PO template files and merge them with the translations. + +Mode of operation (only one is allowed): + -p, --pot generate the PO template only + -s, --headers generate the header files in POTFILES.in + -m, --maintain search for left out files from POTFILES.in + -r, --report display a status report for the module + -d, --dist merge LANGCODE.po with existing PO template + +Extra options: + -g, --gettext-package=NAME override PO template name, useful with --pot + -o, --output-file=FILE write merged translation to FILE + -x, --verbose display lots of feedback + --help display this help and exit + --version output version information and exit + +Examples of use: +${PROGRAM} --pot just create a new PO template +${PROGRAM} xy create new PO template and merge xy.po with it + +Report bugs to http://bugzilla.gnome.org/ (product name "$PACKAGE") +or send email to . +_EOF_ + exit; +} + +sub echo_n +{ + my $str = shift; + my $ret = `echo "$str"`; + + $ret =~ s/\n$//; # do we need the "s" flag? + + return $ret; +} + +sub POFile_DetermineType ($) +{ + my $type = $_; + my $gettext_type; + + my $xml_regex = "(?:" . $xml_support . ")"; + my $ini_regex = "(?:" . $ini_support . ")"; + my $buildin_regex = "(?:" . $buildin_gettext_support . ")"; + + if ($type =~ /\[type: gettext\/([^\]].*)]/) + { + $gettext_type=$1; + } + elsif ($type =~ /schemas(\.in)+$/) + { + $gettext_type="schemas"; + } + elsif ($type =~ /glade2?(\.in)*$/) + { + $gettext_type="glade"; + } + elsif ($type =~ /scm(\.in)*$/) + { + $gettext_type="scheme"; + } + elsif ($type =~ /keys(\.in)+$/) + { + $gettext_type="keys"; + } + + # bucket types + + elsif ($type =~ /$xml_regex$/) + { + $gettext_type="xml"; + } + elsif ($type =~ /$ini_regex$/) + { + $gettext_type="ini"; + } + elsif ($type =~ /$buildin_regex$/) + { + $gettext_type="buildin"; + } + else + { + $gettext_type="unknown"; + } + + return "gettext\/$gettext_type"; +} + +sub TextFile_DetermineEncoding ($) +{ + my $gettext_code="ASCII"; # All files are ASCII by default + my $filetype=`file $_ | cut -d ' ' -f 2`; + + if ($? eq "0") + { + if ($filetype =~ /^(ISO|UTF)/) + { + chomp ($gettext_code = $filetype); + } + elsif ($filetype =~ /^XML/) + { + $gettext_code="UTF-8"; # We asume that .glade and other .xml files are UTF-8 + } + } + + return $gettext_code; +} + +sub isNotValidMissing +{ + my ($file) = @_; + + return if $file =~ /^\{arch\}\/.*$/; + return if $file =~ /^$varhash{"PACKAGE"}-$varhash{"VERSION"}\/.*$/; +} + +sub FindLeftoutFiles +{ + my (@buf_i18n_plain, + @buf_i18n_xml, + @buf_i18n_xml_unmarked, + @buf_i18n_ini, + @buf_potfiles, + @buf_potfiles_ignore, + @buf_allfiles, + @buf_allfiles_sorted, + @buf_potfiles_sorted + ); + + ## Search and find all translatable files + find sub { + push @buf_i18n_plain, "$File::Find::name" if /\.($buildin_gettext_support)$/; + push @buf_i18n_xml, "$File::Find::name" if /\.($xml_support)$/; + push @buf_i18n_ini, "$File::Find::name" if /\.($ini_support)$/; + push @buf_i18n_xml_unmarked, "$File::Find::name" if /\.(schemas(\.in)+)$/; + }, ".."; + + + open POTFILES, $POTFILES_in or die "$PROGRAM: there's no POTFILES.in!\n"; + @buf_potfiles = grep !/^(#|\s*$)/, ; + close POTFILES; + + foreach (@buf_potfiles) { + s/^\[.*]\s*//; + } + + print "Searching for missing translatable files...\n" if $VERBOSE; + + ## Check if we should ignore some found files, when + ## comparing with POTFILES.in + foreach my $ignore ("POTFILES.skip", "POTFILES.ignore") + { + (-s $ignore) or next; + + if ("$ignore" eq "POTFILES.ignore") + { + print "The usage of POTFILES.ignore is deprecated. Please consider moving the\n". + "content of this file to POTFILES.skip.\n"; + } + + print "Found $ignore: Ignoring files...\n" if $VERBOSE; + open FILE, "<$ignore" or die "ERROR: Failed to open $ignore!\n"; + + while () + { + push @buf_potfiles_ignore, $_ unless /^(#|\s*$)/; + } + close FILE; + + @buf_potfiles = (@buf_potfiles_ignore, @buf_potfiles); + } + + foreach my $file (@buf_i18n_plain) + { + my $in_comment = 0; + my $in_macro = 0; + + open FILE, "<$file"; + while () + { + # Handle continued multi-line comment. + if ($in_comment) + { + next unless s-.*\*/--; + $in_comment = 0; + } + + # Handle continued macro. + if ($in_macro) + { + $in_macro = 0 unless /\\$/; + next; + } + + # Handle start of macro (or any preprocessor directive). + if (/^\s*\#/) + { + $in_macro = 1 if /^([^\\]|\\.)*\\$/; + next; + } + + # Handle comments and quoted text. + while (m-(/\*|//|\'|\")-) # \' and \" keep emacs perl mode happy + { + my $match = $1; + if ($match eq "/*") + { + if (!s-/\*.*?\*/--) + { + s-/\*.*--; + $in_comment = 1; + } + } + elsif ($match eq "//") + { + s-//.*--; + } + else # ' or " + { + if (!s-$match([^\\]|\\.)*?$match-QUOTEDTEXT-) + { + warn "mismatched quotes at line $. in $file\n"; + s-$match.*--; + } + } + } + + if (/\.GetString ?\(QUOTEDTEXT/) + { + if (defined isNotValidMissing (unpack("x3 A*", $file))) { + ## Remove the first 3 chars and add newline + push @buf_allfiles, unpack("x3 A*", $file) . "\n"; + } + last; + } + + if (/_\(QUOTEDTEXT/) + { + if (defined isNotValidMissing (unpack("x3 A*", $file))) { + ## Remove the first 3 chars and add newline + push @buf_allfiles, unpack("x3 A*", $file) . "\n"; + } + last; + } + } + close FILE; + } + + foreach my $file (@buf_i18n_xml) + { + open FILE, "<$file"; + + while () + { + # FIXME: share the pattern matching code with intltool-extract + if (/\s_[-A-Za-z0-9._:]+\s*=\s*\"([^"]+)\"/ || /<_[^>]+>/ || /translatable=\"yes\"/) + { + if (defined isNotValidMissing (unpack("x3 A*", $file))) { + push @buf_allfiles, unpack("x3 A*", $file) . "\n"; + } + last; + } + } + close FILE; + } + + foreach my $file (@buf_i18n_ini) + { + open FILE, "<$file"; + while () + { + if (/_(.*)=/) + { + if (defined isNotValidMissing (unpack("x3 A*", $file))) { + push @buf_allfiles, unpack("x3 A*", $file) . "\n"; + } + last; + } + } + close FILE; + } + + foreach my $file (@buf_i18n_xml_unmarked) + { + if (defined isNotValidMissing (unpack("x3 A*", $file))) { + push @buf_allfiles, unpack("x3 A*", $file) . "\n"; + } + } + + + @buf_allfiles_sorted = sort (@buf_allfiles); + @buf_potfiles_sorted = sort (@buf_potfiles); + + my %in2; + foreach (@buf_potfiles_sorted) + { + $in2{$_} = 1; + } + + my @result; + + foreach (@buf_allfiles_sorted) + { + if (!exists($in2{$_})) + { + push @result, $_ + } + } + + my @buf_potfiles_notexist; + + foreach (@buf_potfiles_sorted) + { + chomp (my $dummy = $_); + if ("$dummy" ne "" and ! -f "../$dummy") + { + push @buf_potfiles_notexist, $_; + } + } + + ## Save file with information about the files missing + ## if any, and give information about this procedure. + if (@result + @buf_potfiles_notexist > 0) + { + if (@result) + { + print "\n" if $VERBOSE; + unlink "missing"; + open OUT, ">missing"; + print OUT @result; + close OUT; + warn "\e[1mThe following files contain translations and are currently not in use. Please\e[0m\n". + "\e[1mconsider adding these to the POTFILES.in file, located in the po/ directory.\e[0m\n\n"; + print STDERR @result, "\n"; + warn "If some of these files are left out on purpose then please add them to\n". + "POTFILES.skip instead of POTFILES.in. A file \e[1m'missing'\e[0m containing this list\n". + "of left out files has been written in the current directory.\n"; + } + if (@buf_potfiles_notexist) + { + unlink "notexist"; + open OUT, ">notexist"; + print OUT @buf_potfiles_notexist; + close OUT; + warn "\n" if ($VERBOSE or @result); + warn "\e[1mThe following files do not exist anymore:\e[0m\n\n"; + warn @buf_potfiles_notexist, "\n"; + warn "Please remove them from POTFILES.in or POTFILES.skip. A file \e[1m'notexist'\e[0m\n". + "containing this list of absent files has been written in the current directory.\n"; + } + } + + ## If there is nothing to complain about, notify the user + else { + print "\nAll files containing translations are present in POTFILES.in.\n" if $VERBOSE; + } +} + +sub Console_WriteError_InvalidOption +{ + ## Handle invalid arguments + print STDERR "Try `${PROGRAM} --help' for more information.\n"; + exit 1; +} + +sub GenerateHeaders +{ + my $EXTRACT = "@INTLTOOL_EXTRACT@"; + chomp $EXTRACT; + + $EXTRACT = $ENV{"INTLTOOL_EXTRACT"} if $ENV{"INTLTOOL_EXTRACT"}; + + ## Generate the .h header files, so we can allow glade and + ## xml translation support + if (! -x "$EXTRACT") + { + print STDERR "\n *** The intltool-extract script wasn't found!" + ."\n *** Without it, intltool-update can not generate files.\n"; + exit; + } + else + { + open (FILE, $POTFILES_in) or die "$PROGRAM: POTFILES.in not found.\n"; + + while () + { + chomp; + next if /^\[\s*encoding/; + + ## Find xml files in POTFILES.in and generate the + ## files with help from the extract script + + my $gettext_type= &POFile_DetermineType ($1); + + if (/\.($xml_support|$ini_support)$/ || /^\[/) + { + s/^\[[^\[].*]\s*//; + + my $filename = "../$_"; + + if ($VERBOSE) + { + system ($EXTRACT, "--update", "--srcdir=$SRCDIR", + "--type=$gettext_type", $filename); + } + else + { + system ($EXTRACT, "--update", "--type=$gettext_type", + "--srcdir=$SRCDIR", "--quiet", $filename); + } + } + } + close FILE; + } +} + +# +# Generate .pot file from POTFILES.in +# +sub GeneratePOTemplate +{ + my $XGETTEXT = $ENV{"XGETTEXT"} || "/usr/bin/xgettext"; + my $XGETTEXT_ARGS = $ENV{"XGETTEXT_ARGS"} || ''; + chomp $XGETTEXT; + + if (! -x $XGETTEXT) + { + print STDERR " *** xgettext is not found on this system!\n". + " *** Without it, intltool-update can not extract strings.\n"; + exit; + } + + print "Building $MODULE.pot...\n" if $VERBOSE; + + open INFILE, $POTFILES_in; + unlink "POTFILES.in.temp"; + open OUTFILE, ">POTFILES.in.temp" or die("Cannot open POTFILES.in.temp for writing"); + + my $gettext_support_nonascii = 0; + + # checks for GNU gettext >= 0.12 + my $dummy = `$XGETTEXT --version --from-code=UTF-8 >$devnull 2>$devnull`; + if ($? == 0) + { + $gettext_support_nonascii = 1; + } + else + { + # urge everybody to upgrade gettext + print STDERR "WARNING: This version of gettext does not support extracting non-ASCII\n". + " strings. That means you should install a version of gettext\n". + " that supports non-ASCII strings (such as GNU gettext >= 0.12),\n". + " or have to let non-ASCII strings untranslated. (If there is any)\n"; + } + + my $encoding = "ASCII"; + my $forced_gettext_code; + my @temp_headers; + my $encoding_problem_is_reported = 0; + + while () + { + next if (/^#/ or /^\s*$/); + + chomp; + + my $gettext_code; + + if (/^\[\s*encoding:\s*(.*)\s*\]/) + { + $forced_gettext_code=$1; + } + elsif (/\.($xml_support|$ini_support)$/ || /^\[/) + { + s/^\[.*]\s*//; + print OUTFILE "../$_.h\n"; + push @temp_headers, "../$_.h"; + $gettext_code = &TextFile_DetermineEncoding ("../$_.h") if ($gettext_support_nonascii and not defined $forced_gettext_code); + } + else + { + if ($SRCDIR eq ".") { + print OUTFILE "../$_\n"; + } else { + print OUTFILE "$SRCDIR/../$_\n"; + } + $gettext_code = &TextFile_DetermineEncoding ("../$_") if ($gettext_support_nonascii and not defined $forced_gettext_code); + } + + next if (! $gettext_support_nonascii); + + if (defined $forced_gettext_code) + { + $encoding=$forced_gettext_code; + } + elsif (defined $gettext_code and "$encoding" ne "$gettext_code") + { + if ($encoding eq "ASCII") + { + $encoding=$gettext_code; + } + elsif ($gettext_code ne "ASCII") + { + # Only report once because the message is quite long + if (! $encoding_problem_is_reported) + { + print STDERR "WARNING: You should use the same file encoding for all your project files,\n". + " but $PROGRAM thinks that most of the source files are in\n". + " $encoding encoding, while \"$_\" is (likely) in\n". + " $gettext_code encoding. If you are sure that all translatable strings\n". + " are in same encoding (say UTF-8), please \e[1m*prepend*\e[0m the following\n". + " line to POTFILES.in:\n\n". + " [encoding: UTF-8]\n\n". + " and make sure that configure.in/ac checks for $PACKAGE >= 0.27 .\n". + "(such warning message will only be reported once.)\n"; + $encoding_problem_is_reported = 1; + } + } + } + } + + close OUTFILE; + close INFILE; + + unlink "$MODULE.pot"; + my @xgettext_argument=("$XGETTEXT", + "--add-comments", + "--directory\=\.", + "--output\=$MODULE\.pot", + "--files-from\=\.\/POTFILES\.in\.temp"); + my $XGETTEXT_KEYWORDS = &FindPOTKeywords; + push @xgettext_argument, $XGETTEXT_KEYWORDS; + push @xgettext_argument, "--from-code\=$encoding" if ($gettext_support_nonascii); + push @xgettext_argument, $XGETTEXT_ARGS if $XGETTEXT_ARGS; + my $xgettext_command = join ' ', @xgettext_argument; + + # intercept xgettext error message + print "Running $xgettext_command\n" if $VERBOSE; + my $xgettext_error_msg = `$xgettext_command 2>\&1`; + my $command_failed = $?; + + unlink "POTFILES.in.temp"; + + print "Removing generated header (.h) files..." if $VERBOSE; + unlink foreach (@temp_headers); + print "done.\n" if $VERBOSE; + + if (! $command_failed) + { + if (! -e "$MODULE.pot") + { + print "None of the files in POTFILES.in contain strings marked for translation.\n" if $VERBOSE; + } + else + { + print "Wrote $MODULE.pot\n" if $VERBOSE; + } + } + else + { + if ($xgettext_error_msg =~ /--from-code/) + { + # replace non-ASCII error message with a more useful one. + print STDERR "ERROR: xgettext failed to generate PO template file because there is non-ASCII\n". + " string marked for translation. Please make sure that all strings marked\n". + " for translation are in uniform encoding (say UTF-8), then \e[1m*prepend*\e[0m the\n". + " following line to POTFILES.in and rerun $PROGRAM:\n\n". + " [encoding: UTF-8]\n\n"; + } + else + { + print STDERR "$xgettext_error_msg"; + if (-e "$MODULE.pot") + { + # is this possible? + print STDERR "ERROR: xgettext failed but still managed to generate PO template file.\n". + " Please consult error message above if there is any.\n"; + } + else + { + print STDERR "ERROR: xgettext failed to generate PO template file. Please consult\n". + " error message above if there is any.\n"; + } + } + exit (1); + } +} + +sub POFile_Update +{ + -f "$MODULE.pot" or die "$PROGRAM: $MODULE.pot does not exist.\n"; + + my $MSGMERGE = $ENV{"MSGMERGE"} || "/usr/bin/msgmerge"; + my ($lang, $outfile) = @_; + + print "Merging $SRCDIR/$lang.po with $MODULE.pot..." if $VERBOSE; + + my $infile = "$SRCDIR/$lang.po"; + $outfile = "$SRCDIR/$lang.po" if ($outfile eq ""); + + # I think msgmerge won't overwrite old file if merge is not successful + system ("$MSGMERGE", "-o", $outfile, $infile, "$MODULE.pot"); +} + +sub Console_WriteError_NotExisting +{ + my ($file) = @_; + + ## Report error if supplied language file is non-existing + print STDERR "$PROGRAM: $file does not exist!\n"; + print STDERR "Try '$PROGRAM --help' for more information.\n"; + exit; +} + +sub GatherPOFiles +{ + my @po_files = glob ("./*.po"); + + @languages = map (&POFile_GetLanguage, @po_files); + + foreach my $lang (@languages) + { + $po_files_by_lang{$lang} = shift (@po_files); + } +} + +sub POFile_GetLanguage ($) +{ + s/^(.*\/)?(.+)\.po$/$2/; + return $_; +} + +sub Console_Write_TranslationStatus +{ + my ($lang, $output_file) = @_; + my $MSGFMT = $ENV{"MSGFMT"} || "/usr/bin/msgfmt"; + + $output_file = "$SRCDIR/$lang.po" if ($output_file eq ""); + + system ("$MSGFMT", "-o", "$devnull", "--verbose", $output_file); +} + +sub Console_Write_CoverageReport +{ + my $MSGFMT = $ENV{"MSGFMT"} || "/usr/bin/msgfmt"; + + &GatherPOFiles; + + foreach my $lang (@languages) + { + print "$lang: "; + &POFile_Update ($lang, ""); + } + + print "\n\n * Current translation support in $MODULE \n\n"; + + foreach my $lang (@languages) + { + print "$lang: "; + system ("$MSGFMT", "-o", "$devnull", "--verbose", "$SRCDIR/$lang.po"); + } +} + +sub SubstituteVariable +{ + my ($str) = @_; + + # always need to rewind file whenever it has been accessed + seek (CONF, 0, 0); + + # cache each variable. varhash is global to we can add + # variables elsewhere. + while () + { + if (/^(\w+)=(.*)$/) + { + ($varhash{$1} = $2) =~ s/^["'](.*)["']$/$1/; + } + } + + if ($str =~ /^(.*)\${?([A-Z_]+)}?(.*)$/) + { + my $rest = $3; + my $untouched = $1; + my $sub = $varhash{$2}; + + return SubstituteVariable ("$untouched$sub$rest"); + } + + # We're using Perl backticks ` and "echo -n" here in order to + # expand any shell escapes (such as backticks themselves) in every variable + return echo_n ($str); +} + +sub CONF_Handle_Open +{ + my $base_dirname = getcwd(); + $base_dirname =~ s@.*/@@; + + my ($conf_in, $src_dir); + + if ($base_dirname =~ /^po(-.+)?$/) + { + if (-f "Makevars") + { + my $makefile_source; + + local (*IN); + open (IN, ") + { + if (/^top_builddir[ \t]*=/) + { + $src_dir = $_; + $src_dir =~ s/^top_builddir[ \t]*=[ \t]*([^ \t\n\r]*)/$1/; + + chomp $src_dir; + if (-f "$src_dir" . "/configure.ac") { + $conf_in = "$src_dir" . "/configure.ac" . "\n"; + } else { + $conf_in = "$src_dir" . "/configure.in" . "\n"; + } + last; + } + } + close IN; + + $conf_in || die "Cannot find top_builddir in Makevars."; + } + elsif (-f "../configure.ac") + { + $conf_in = "../configure.ac"; + } + elsif (-f "../configure.in") + { + $conf_in = "../configure.in"; + } + else + { + my $makefile_source; + + local (*IN); + open (IN, ") + { + if (/^top_srcdir[ \t]*=/) + { + $src_dir = $_; + $src_dir =~ s/^top_srcdir[ \t]*=[ \t]*([^ \t\n\r]*)/$1/; + + chomp $src_dir; + $conf_in = "$src_dir" . "/configure.in" . "\n"; + + last; + } + } + close IN; + + $conf_in || die "Cannot find top_srcdir in Makefile."; + } + + open (CONF, "<$conf_in"); + } + else + { + print STDERR "$PROGRAM: Unable to proceed.\n" . + "Make sure to run this script inside the po directory.\n"; + exit; + } +} + +sub FindPackageName +{ + my $version; + my $domain = &FindMakevarsDomain; + my $name = $domain || "untitled"; + + &CONF_Handle_Open; + + my $conf_source; { + local (*IN); + open (IN, "<&CONF") || return $name; + seek (IN, 0, 0); + local $/; # slurp mode + $conf_source = ; + close IN; + } + + # priority for getting package name: + # 1. GETTEXT_PACKAGE + # 2. first argument of AC_INIT (with >= 2 arguments) + # 3. first argument of AM_INIT_AUTOMAKE (with >= 2 argument) + + # /^AM_INIT_AUTOMAKE\([\s\[]*([^,\)\s\]]+)/m + # the \s makes this not work, why? + if ($conf_source =~ /^AM_INIT_AUTOMAKE\(([^,\)]+),([^,\)]+)/m) + { + ($name, $version) = ($1, $2); + $name =~ s/[\[\]\s]//g; + $version =~ s/[\[\]\s]//g; + $varhash{"AC_PACKAGE_NAME"} = $name; + $varhash{"PACKAGE"} = $name; + $varhash{"AC_PACKAGE_VERSION"} = $version; + $varhash{"VERSION"} = $version; + } + + if ($conf_source =~ /^AC_INIT\(([^,\)]+),([^,\)]+)/m) + { + ($name, $version) = ($1, $2); + $name =~ s/[\[\]\s]//g; + $version =~ s/[\[\]\s]//g; + $varhash{"AC_PACKAGE_NAME"} = $name; + $varhash{"PACKAGE"} = $name; + $varhash{"AC_PACKAGE_VERSION"} = $version; + $varhash{"VERSION"} = $version; + } + + # \s makes this not work, why? + $name = $1 if $conf_source =~ /^GETTEXT_PACKAGE=\[?([^\n\]]+)/m; + + # prepend '$' to auto* internal variables, usually they are + # used in configure.in/ac without the '$' + $name =~ s/AC_/\$AC_/g; + $name =~ s/\$\$/\$/g; + + $name = $domain if $domain; + + $name = SubstituteVariable ($name); + $name =~ s/^["'](.*)["']$/$1/; + + return $name if $name; +} + + +sub FindPOTKeywords +{ + + my $keywords = "--keyword\=\_ --keyword\=N\_ --keyword\=U\_ --keyword\=Q\_"; + my $varname = "XGETTEXT_OPTIONS"; + my $make_source; { + local (*IN); + open (IN, "; + close IN; + } + + $keywords = $1 if $make_source =~ /^$varname[ ]*=\[?([^\n\]]+)/m; + + return $keywords; +} + +sub FindMakevarsDomain +{ + + my $domain = ""; + my $makevars_source; { + local (*IN); + open (IN, "; + close IN; + } + + $domain = $1 if $makevars_source =~ /^DOMAIN[ ]*=\[?([^\n\]\$]+)/m; + $domain =~ s/^\s+//; + $domain =~ s/\s+$//; + + return $domain; +} diff --git a/vpn-daemons/pptp/nm-pptp-service.conf b/vpn-daemons/pptp/nm-pptp-service.conf new file mode 100644 index 0000000000..7bc31614c2 --- /dev/null +++ b/vpn-daemons/pptp/nm-pptp-service.conf @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + 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..a7f23c6489 --- /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=@LIBEXECDIR@/nm-pptp-auth-dialog +properties=@LIBDIR@/libnm-pptp-properties diff --git a/vpn-daemons/pptp/nm-pptp.desktop.in b/vpn-daemons/pptp/nm-pptp.desktop.in new file mode 100644 index 0000000000..1f83ec1b9e --- /dev/null +++ b/vpn-daemons/pptp/nm-pptp.desktop.in @@ -0,0 +1,12 @@ +[Desktop Entry] +Encoding=UTF-8 +_Name=VPN Connection Manager (PPTP) +_GenericName=VPN Connection Manager (PPTP) +_Comment=Add, Remove, and Edit VPN Connections +Exec=nm-vpn-properties --import-service org.freedesktop.NetworkManager.pptp --import-file %f +Icon=gnome-mime-application-x-pptp-settings +Terminal=false +Type=Application +DocPath= +Categories=GNOME;Application;Network; +MimeType=application/x-pptp-settings diff --git a/vpn-daemons/pptp/po/.cvsignore b/vpn-daemons/pptp/po/.cvsignore new file mode 100644 index 0000000000..68336a4624 --- /dev/null +++ b/vpn-daemons/pptp/po/.cvsignore @@ -0,0 +1,7 @@ +Makefile.in.in +Makefile +Makefile.in +POTFILES +da.gmo +sv.gmo +*.pot diff --git a/vpn-daemons/pptp/po/ChangeLog b/vpn-daemons/pptp/po/ChangeLog new file mode 100644 index 0000000000..c6e033d229 --- /dev/null +++ b/vpn-daemons/pptp/po/ChangeLog @@ -0,0 +1,10 @@ +2005-06-17 David Zeuthen + + * POTFILES.in: Added nm-vpnc.desktop.in + + * da.po: Updated danish translations + +2005-06-16 David Zeuthen + + * da.po: Updated danish translations + diff --git a/vpn-daemons/pptp/po/POTFILES.in b/vpn-daemons/pptp/po/POTFILES.in new file mode 100644 index 0000000000..dc380519da --- /dev/null +++ b/vpn-daemons/pptp/po/POTFILES.in @@ -0,0 +1,10 @@ +# List of source files containing translatable strings. +# Please keep this file sorted alphabetically. +auth-dialog/gnome-two-password-dialog.c +auth-dialog/main.c +nm-pptp.desktop.in +properties/nm-pptp.c +properties/nm-pptp-dialog.glade +src/nm-pptp-service.c +src/nm-pptp-service-pptp-helper.c + diff --git a/vpn-daemons/pptp/po/da.po b/vpn-daemons/pptp/po/da.po new file mode 100644 index 0000000000..a176218cd3 --- /dev/null +++ b/vpn-daemons/pptp/po/da.po @@ -0,0 +1,233 @@ +# Danish translation of NetworkManager-vpnc. +# Copyright (C) 2005 Dan Williams , David Zeuthen +# This file is distributed under the same license as the NetworkManager-vpnc package. +# David Zeuthen , 2005 +# +msgid "" +msgstr "" +"Project-Id-Version: NetworkManager-vpnc\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2005-06-16 23:50-0400\n" +"PO-Revision-Date: 2005-06-11 23:21-0400\n" +"Last-Translator: David Zeuthen \n" +"Language-Team: Danish \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: ../auth-dialog/gnome-two-password-dialog.c:147 +msgid "_Secondary Password:" +msgstr "_Sekundær Nøgle:" + +#: ../auth-dialog/gnome-two-password-dialog.c:268 +msgid "_Username:" +msgstr "_Brugernavn:" + +#: ../auth-dialog/gnome-two-password-dialog.c:270 +msgid "_Domain:" +msgstr "_Domæne:" + +#: ../auth-dialog/gnome-two-password-dialog.c:272 +msgid "_Password:" +msgstr "_Nøgle:" + +#: ../auth-dialog/gnome-two-password-dialog.c:355 +msgid "Connect _anonymously" +msgstr "Tilslut _anonymt" + +#: ../auth-dialog/gnome-two-password-dialog.c:360 +msgid "Connect as _user:" +msgstr "Tilslut som _bruger:" + +#: ../auth-dialog/gnome-two-password-dialog.c:466 +msgid "Remember password for this session" +msgstr "Husk adgangskode for denne session" + +#: ../auth-dialog/gnome-two-password-dialog.c:468 +msgid "Save password in keyring" +msgstr "Gem adgangskode i nøglering" + +#: ../auth-dialog/main.c:161 +#, c-format +msgid "You need to authenticate to access the Virtual Private Network '%s'." +msgstr "" +"Brugerverifikation er påkrævet for at tilslutte til det private netværk '%s'." + +#: ../auth-dialog/main.c:162 +msgid "Authenticate VPN" +msgstr "Brugerverifikation til privat netværk" + +#: ../auth-dialog/main.c:169 +msgid "_Group Password:" +msgstr "_Gruppe nøgle:" + +# +#: ../nm-vpnc.desktop.in.h:1 +msgid "VPN Connection Manager (vpnc)" +msgstr "VPN forbindelser (vpnc)" + +#: ../properties/nm-vpnc.c:83 +msgid "Compatible Cisco VPN client (vpnc)" +msgstr "Kompatibel Cisco VPN klient (vpnc)" + +#: ../properties/nm-vpnc.c:448 +#, c-format +msgid "\tUsername: %s\n" +msgstr "\tBrugernavn: %s\n" + +#: ../properties/nm-vpnc.c:449 +#, c-format +msgid "\tRoutes: %s\n" +msgstr "\tRuter: %s\n" + +#: ../properties/nm-vpnc.c:450 +#, c-format +msgid "\tDomain: %s\n" +msgstr "\tDomæne: %s\n" + +#: ../properties/nm-vpnc.c:453 +#, c-format +msgid "" +"The following vpnc VPN connection will be created:\n" +"\n" +"\tName: %s\n" +"\n" +"\tGateway: %s\n" +"\tGroup Name: %s\n" +"%s%s%s\n" +"The connection details can be changed using the \"Edit\" button.\n" +msgstr "" +"Flg. private netværks forbindelse via vpnc vil blive oprettet:\n" +"\n" +"\tNavn: %s\n" +"\n" +"\tKnudepunkt: %s\n" +"\tGruppe navn: %s\n" +"%s%s%s\n" +"Detaljer for forbindelsen kan senere redigeres vha. \"Redigér\" knappen\n" + +#: ../properties/nm-vpnc.c:545 +msgid "TCP tunneling not supported" +msgstr "" + +#: ../properties/nm-vpnc.c:547 +#, c-format +msgid "" +"The VPN settings file '%s' specifies that VPN traffic should be tunneled " +"through TCP which is currently not supported in the vpnc software.\n" +"\n" +"The connection can still be created, with TCP tunneling disabled, however it " +"may not work as expected." +msgstr "" + +#: ../properties/nm-vpnc.c:571 +msgid "Cannot import settings" +msgstr "" + +#: ../properties/nm-vpnc.c:573 +#, c-format +msgid "The VPN settings file '%s' does not contain valid data." +msgstr "" + +#: ../properties/nm-vpnc.c:590 +msgid "Select file to import" +msgstr "Vælg fil der skal importeres" + +#: ../properties/nm-vpnc.c:745 +msgid "Save as..." +msgstr "" + +#: ../properties/nm-vpnc.c:775 +#, c-format +msgid "A file named \"%s\" already exists." +msgstr "" + +#: ../properties/nm-vpnc.c:778 +msgid "Do you want to replace it with the one you are saving?" +msgstr "" + +#: ../properties/nm-vpnc-dialog.glade.h:1 +msgid "Connection Name" +msgstr "Navn på forbindelse" + +#: ../properties/nm-vpnc-dialog.glade.h:2 +msgid "Optional Information" +msgstr "Andre oplysninger" + +#: ../properties/nm-vpnc-dialog.glade.h:3 +msgid "Required Information" +msgstr "Påkrævede oplysninger" + +#: ../properties/nm-vpnc-dialog.glade.h:4 +msgid "example: 172.16.0.0/16 10.11.12.0/24" +msgstr "eksempel: 172.16.0.0/16 10.11.12.0/24" + +#: ../properties/nm-vpnc-dialog.glade.h:5 +msgid "Gateway:" +msgstr "Adgangspunkt:" + +#: ../properties/nm-vpnc-dialog.glade.h:6 +msgid "Group Name:" +msgstr "Gruppe navn:" + +#: ../properties/nm-vpnc-dialog.glade.h:7 +msgid "" +"Name used to identify the connection to the private network, e.g. \"Campus " +"VPN\" or \"Corporate Network\"" +msgstr "" +"Navn brugt til at identificere forbindelsen til det private netværk, f.eks. " +"\"Universitets Privat Netværk\" eller \"Arbejds Privat Netværk\"" + +#: ../properties/nm-vpnc-dialog.glade.h:8 +msgid "Only use VPN connection for these addresses" +msgstr "Brug kun det private netværk til flg. adresser" + +#: ../properties/nm-vpnc-dialog.glade.h:9 +msgid "Override user name" +msgstr "Overskriv brugernavn" + +#: ../properties/nm-vpnc-dialog.glade.h:10 +msgid "" +"Please enter the information provided by your system administrator below. Do " +"not enter your password here as you will be prompted when connecting." +msgstr "" +"Indtast oplysninger fra din systemadministrator nedenfor. Du skal ikke " +"indtaste din nøgle her da du bliver spurgt om den ved forbindelse." + +#: ../properties/nm-vpnc-dialog.glade.h:11 +msgid "Use domain for authentication" +msgstr "Brug domæne til brugerverifikation" + +#: ../properties/nm-vpnc-dialog.glade.h:12 +msgid "_Import..." +msgstr "_Importér..." + +#: ../src/nm-vpnc-service.c:115 +msgid "" +"The VPN login failed because the user name and password were not accepted." +msgstr "VPN-tjenesten fejlede fordi brugernavn og nøgle blev afvist." + +#: ../src/nm-vpnc-service.c:117 +msgid "The VPN login failed because the VPN program could not be started." +msgstr "VPN-tjenesten fejlede fordi VPN programmet ikke kunne starte." + +#: ../src/nm-vpnc-service.c:119 +msgid "" +"The VPN login failed because the VPN program could not connect to the VPN " +"server." +msgstr "" +"VPN-tjenesten fejlede fordi VPN programmet ikke kunne forbinde tilVPN " +"knudepunktet" + +#: ../src/nm-vpnc-service.c:121 +msgid "" +"The VPN login failed because the VPN configuration options were invalid." +msgstr "VPN-tjenesten fejlede fordi VPN indstillingerne var ugyldige." + +#: ../src/nm-vpnc-service.c:123 +msgid "" +"The VPN login failed because the VPN program received an invalid " +"configuration from the VPN server." +msgstr "" +"VPN-tjenesten fejlede fordi VPN programmet modtog ugyldige indstillingen fra " +"VPN værts-maskinen" diff --git a/vpn-daemons/pptp/po/sv.po b/vpn-daemons/pptp/po/sv.po new file mode 100644 index 0000000000..5720b3819b --- /dev/null +++ b/vpn-daemons/pptp/po/sv.po @@ -0,0 +1,246 @@ +# Swedish messages for NetworkManager. +# Copyright (C) 2004, 2005 Free Software Foundation, Inc. +# Christian Rose , 2004, 2005. +# +# $Id: sv.po,v 1.1 2005/12/21 21:50:06 ajmee Exp $ +# +msgid "" +msgstr "" +"Project-Id-Version: NetworkManager-vpnc\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2005-06-26 01:20+0200\n" +"PO-Revision-Date: 2005-06-26 01:20+0200\n" +"Last-Translator: Christian Rose \n" +"Language-Team: Swedish \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: vpn-daemons/vpnc/auth-dialog/gnome-two-password-dialog.c:147 +msgid "_Secondary Password:" +msgstr "_Andrahandslösenord:" + +#: vpn-daemons/vpnc/auth-dialog/gnome-two-password-dialog.c:268 +msgid "_Username:" +msgstr "_Användarnamn:" + +#: vpn-daemons/vpnc/auth-dialog/gnome-two-password-dialog.c:270 +msgid "_Domain:" +msgstr "_Domän:" + +#: vpn-daemons/vpnc/auth-dialog/gnome-two-password-dialog.c:272 +msgid "_Password:" +msgstr "_Lösenord:" + +#: vpn-daemons/vpnc/auth-dialog/gnome-two-password-dialog.c:355 +msgid "Connect _anonymously" +msgstr "Anslut anon_ymt" + +#: vpn-daemons/vpnc/auth-dialog/gnome-two-password-dialog.c:360 +msgid "Connect as _user:" +msgstr "Anslut som _användare:" + +#: vpn-daemons/vpnc/auth-dialog/gnome-two-password-dialog.c:466 +msgid "Remember password for this session" +msgstr "Kom ihåg lösenordet för denna session" + +#: vpn-daemons/vpnc/auth-dialog/gnome-two-password-dialog.c:468 +msgid "Save password in keyring" +msgstr "Spara lösenordet i nyckelring" + +#: vpn-daemons/vpnc/auth-dialog/main.c:161 +#, c-format +msgid "You need to authenticate to access the Virtual Private Network '%s'." +msgstr "Du måsta autentisera för att komma åt VPN-nätverket \"%s\"." + +#: vpn-daemons/vpnc/auth-dialog/main.c:162 +msgid "Authenticate VPN" +msgstr "Autentisera VPN" + +#: vpn-daemons/vpnc/auth-dialog/main.c:169 +msgid "_Group Password:" +msgstr "_Grupplösenord:" + +#: vpn-daemons/vpnc/nm-vpnc.desktop.in.h:1 +msgid "VPN Connection Manager (vpnc)" +msgstr "VPN-anslutningshanterare (vpnc)" + +#: vpn-daemons/vpnc/properties/nm-vpnc-dialog.glade.h:1 +msgid "Connection Name" +msgstr "Anslutningsnamn" + +#: vpn-daemons/vpnc/properties/nm-vpnc-dialog.glade.h:2 +msgid "Optional Information" +msgstr "Valfri information" + +#: vpn-daemons/vpnc/properties/nm-vpnc-dialog.glade.h:3 +msgid "Required Information" +msgstr "Nödvändig information" + +#: vpn-daemons/vpnc/properties/nm-vpnc-dialog.glade.h:4 +msgid "example: 172.16.0.0/16 10.11.12.0/24" +msgstr "exempel: 172.16.0.0/16 10.11.12.0/24" + +#: vpn-daemons/vpnc/properties/nm-vpnc-dialog.glade.h:5 +msgid "Gateway:" +msgstr "Gateway:" + +#: vpn-daemons/vpnc/properties/nm-vpnc-dialog.glade.h:6 +msgid "Group Name:" +msgstr "Gruppnamn:" + +#: vpn-daemons/vpnc/properties/nm-vpnc-dialog.glade.h:7 +msgid "" +"Name used to identify the connection to the private network, e.g. \"Campus " +"VPN\" or \"Corporate Network\"" +msgstr "" +"Namn som används för att identifiera anslutningen till det privata " +"nätverket, exempelvis \"Campus-VPN\" eller \"Företagsnätverket\"" + +#: vpn-daemons/vpnc/properties/nm-vpnc-dialog.glade.h:8 +msgid "Only use VPN connection for these addresses" +msgstr "Använd endast VPN-anslutning för dessa adresser" + +#: vpn-daemons/vpnc/properties/nm-vpnc-dialog.glade.h:9 +msgid "Override user name" +msgstr "Åsidosätt användarnamn" + +#: vpn-daemons/vpnc/properties/nm-vpnc-dialog.glade.h:10 +msgid "" +"Please enter the information provided by your system administrator below. Do " +"not enter your password here as you will be prompted when connecting." +msgstr "" +"Ange den information som har tillhandahållits av din systemadministratör " +"nedan. Ange inte lösenordet här eftersom du kommer att efterfrågas det när " +"du ansluter." + +#: vpn-daemons/vpnc/properties/nm-vpnc-dialog.glade.h:11 +msgid "Use domain for authentication" +msgstr "Använd domän för autentisering" + +#: vpn-daemons/vpnc/properties/nm-vpnc-dialog.glade.h:12 +msgid "_Import..." +msgstr "_Importera..." + +#: vpn-daemons/vpnc/properties/nm-vpnc.c:83 +msgid "Compatible Cisco VPN client (vpnc)" +msgstr "Kompatibel Cisco VPN-klient (vpnc)" + +#: vpn-daemons/vpnc/properties/nm-vpnc.c:448 +#, c-format +msgid "\tUsername: %s\n" +msgstr "\tAnvändarnamn: %s\n" + +#: vpn-daemons/vpnc/properties/nm-vpnc.c:449 +#, c-format +msgid "\tRoutes: %s\n" +msgstr "\tVägar: %s\n" + +#: vpn-daemons/vpnc/properties/nm-vpnc.c:450 +#, c-format +msgid "\tDomain: %s\n" +msgstr "\tDomän: %s\n" + +#: vpn-daemons/vpnc/properties/nm-vpnc.c:453 +#, c-format +msgid "" +"The following vpnc VPN connection will be created:\n" +"\n" +"\tName: %s\n" +"\n" +"\tGateway: %s\n" +"\tGroup Name: %s\n" +"%s%s%s\n" +"The connection details can be changed using the \"Edit\" button.\n" +msgstr "" +"Följande vpnc-VPN-anslutning kommer att skapas:\n" +"\n" +"\tNamn: %s\n" +"\n" +"\tGateway: %s\n" +"\tGruppnamn: %s\n" +"%s%s%s\n" +"Anslutningsdetaljerna kan ändras genom att använda knappen \"Redigera\".\n" + +#: vpn-daemons/vpnc/properties/nm-vpnc.c:544 +msgid "TCP tunneling not supported" +msgstr "TCP-tunnling stöds inte" + +#: vpn-daemons/vpnc/properties/nm-vpnc.c:546 +#, c-format +msgid "" +"The VPN settings file '%s' specifies that VPN traffic should be tunneled " +"through TCP which is currently not supported in the vpnc software.\n" +"\n" +"The connection can still be created, with TCP tunneling disabled, however it " +"may not work as expected." +msgstr "" +"VPN-inställningsfilen \"%s\" anger att VPN-trafiken ska tunnlas genom TCP " +"vilket för tillfället inte stöds i vpnc-programvaran.\n" +"\n" +"Anslutningen kan fortfarande skapas, med inaktiverad TCP-tunnling, men det " +"kanske inte fungerar som väntat." + +#: vpn-daemons/vpnc/properties/nm-vpnc.c:570 +msgid "Cannot import settings" +msgstr "Kan inte importera inställningar" + +#: vpn-daemons/vpnc/properties/nm-vpnc.c:572 +#, c-format +msgid "The VPN settings file '%s' does not contain valid data." +msgstr "VPN-inställningsfilen \"%s\" innehåller inte giltiga data." + +#: vpn-daemons/vpnc/properties/nm-vpnc.c:589 +msgid "Select file to import" +msgstr "Välj fil att importera" + +#. printf ("in impl_export\n"); +#: vpn-daemons/vpnc/properties/nm-vpnc.c:744 +msgid "Save as..." +msgstr "Spara som..." + +#: vpn-daemons/vpnc/properties/nm-vpnc.c:774 +#, c-format +msgid "A file named \"%s\" already exists." +msgstr "En fil med namnet \"%s\" finns redan." + +#: vpn-daemons/vpnc/properties/nm-vpnc.c:777 +msgid "Do you want to replace it with the one you are saving?" +msgstr "Vill du ersätta den med den du håller på att spara?" + +#: vpn-daemons/vpnc/src/nm-vpnc-service.c:115 +msgid "" +"The VPN login failed because the user name and password were not accepted." +msgstr "" +"VPN-inloggningen misslyckades eftersom användarnamnet och lösenordet inte " +"accepterades." + +#: vpn-daemons/vpnc/src/nm-vpnc-service.c:117 +msgid "The VPN login failed because the VPN program could not be started." +msgstr "" +"VPN-inloggningen misslyckades eftersom VPN-programmet inte kunde startas." + +#: vpn-daemons/vpnc/src/nm-vpnc-service.c:119 +msgid "" +"The VPN login failed because the VPN program could not connect to the VPN " +"server." +msgstr "" +"VPN-inloggningen misslyckades eftersom VPN-programmet inte kunde ansluta " +"till VPN-servern." + +#: vpn-daemons/vpnc/src/nm-vpnc-service.c:121 +msgid "" +"The VPN login failed because the VPN configuration options were invalid." +msgstr "" +"VPN-inloggningen misslyckades eftersom VPN-konfigurationsalternativen var " +"ogiltiga." + +#: vpn-daemons/vpnc/src/nm-vpnc-service.c:123 +msgid "" +"The VPN login failed because the VPN program received an invalid " +"configuration from the VPN server." +msgstr "" +"VPN-inloggningen misslyckades eftersom VPN-programmet mottog en ogiltig " +"konfiguration från VPN-servern." + diff --git a/vpn-daemons/pptp/properties/.cvsignore b/vpn-daemons/pptp/properties/.cvsignore new file mode 100644 index 0000000000..3dda72986f --- /dev/null +++ b/vpn-daemons/pptp/properties/.cvsignore @@ -0,0 +1,2 @@ +Makefile.in +Makefile diff --git a/vpn-daemons/pptp/properties/Makefile.am b/vpn-daemons/pptp/properties/Makefile.am new file mode 100644 index 0000000000..b7b08c268e --- /dev/null +++ b/vpn-daemons/pptp/properties/Makefile.am @@ -0,0 +1,33 @@ + + +lib_LTLIBRARIES = libnm-pptp-properties.la + +libnm_pptp_properties_la_SOURCES = \ + nm-pptp.c + +gladedir = $(datadir)/gnome-vpn-properties/pptp +glade_DATA = nm-pptp-dialog.glade + +libnm_pptp_properties_la_CFLAGS = \ + $(GLADE_CFLAGS) \ + $(GTK_CFLAGS) \ + $(GCONF_CFLAGS) \ + $(LIBGNOMEUI_CFLAGS) \ + -DICONDIR=\""$(datadir)/pixmaps"\" \ + -DGLADEDIR=\""$(gladedir)"\" \ + -DG_DISABLE_DEPRECATED \ + -DGDK_DISABLE_DEPRECATED \ + -DGNOME_DISABLE_DEPRECATED \ + -DGNOMELOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \ + -DVERSION=\"$(VERSION)\" + +libnm_pptp_properties_la_LIBADD = \ + $(GLADE_LIBS) \ + $(GTK_LIBS) \ + $(GCONF_LIBS) \ + $(LIBGNOMEUI_LIBS) + +CLEANFILES = *.bak *.gladep *~ + +EXTRA_DIST = \ + $(glade_DATA) 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..2da3be538a --- /dev/null +++ b/vpn-daemons/pptp/properties/nm-pptp-dialog.glade @@ -0,0 +1,778 @@ + + + + + + + + + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + + + + 12 + True + False + 12 + + + + True + Please enter the information provided by your system administrator below. Do not enter your password here as you will be prompted when connecting. + False + False + GTK_JUSTIFY_LEFT + True + False + 0 + 0.5 + 0 + 0 + + + 0 + False + True + + + + + + True + False + 6 + + + + True + <b>Connection Name</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + False + True + + + + + + True + False + 0 + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 12 + 0 + + + 0 + False + True + + + + + + True + False + 6 + + + + True + _Name used to identify the connection to the private network, e.g. "Campus VPN" or "Corporate Network" + True + False + GTK_JUSTIFY_LEFT + True + False + 0 + 0.5 + 0 + 0 + + + 0 + False + True + + + + + + True + False + 0 + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 12 + 0 + + + 0 + False + True + + + + + + True + True + True + True + 0 + + True + * + False + + + 0 + True + True + + + + + 0 + True + True + + + + + 0 + True + True + + + + + 0 + True + True + + + + + 0 + True + True + + + + + + True + False + 0 + + + + True + <b>Required Information</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + 12 + True + False + 6 + + + + True + False + 0 + + + + True + _Gateway: + True + False + GTK_JUSTIFY_LEFT + False + False + 1 + 0.5 + 0 + 0 + pptp-remote + + + 0 + False + False + + + + + + True + True + True + True + 0 + + True + * + False + + + 0 + True + True + + + + + 0 + True + True + + + + + 0 + True + True + + + + + + 12 + True + True + True + True + GTK_POS_TOP + False + False + + + + True + False + 6 + + + + True + False + 0 + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 12 + 0 + + + 0 + False + True + + + + + + True + 1 + 2 + False + 12 + 6 + + + + True + Username: + False + False + GTK_JUSTIFY_LEFT + False + False + 1 + 0.5 + 0 + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 0 + 1 + + + + + + 0 + True + True + + + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 12 + 0 + + + 0 + False + False + + + + + 0 + True + True + + + + + + True + Your password must be defined +in /etc/ppp/chap-secrets + False + False + GTK_JUSTIFY_CENTER + True + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + False + True + + + + + + True + MS CHAP-v1/v2 + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + tab + + + + + 0 + True + True + + + + + 0 + True + True + + + + + + True + True + True + 6 + + + + True + False + 0 + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 12 + 0 + + + 0 + False + True + + + + + + True + False + 6 + + + + True + True + _Only use VPN connection for these addresses + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 0 + False + False + + + + + + True + False + 0 + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 12 + 0 + + + 0 + False + True + + + + + + True + False + 6 + + + + True + <i>example: 172.16.0.0/16 10.11.12.0/24</i> + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + False + True + + + + + + True + True + True + True + 0 + + True + * + False + + + 0 + True + True + + + + + 0 + True + True + + + + + 0 + True + True + + + + + + True + True + Use MPPC compression + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 0 + False + False + + + + + + True + True + Require MPPE encryption + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 0 + False + False + + + + + 0 + True + True + + + + + + + 0 + True + 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 + + + 0 + False + False + + + + + + + + + + + 0 + True + True + + + + + + + diff --git a/vpn-daemons/pptp/properties/nm-pptp.c b/vpn-daemons/pptp/properties/nm-pptp.c new file mode 100644 index 0000000000..8fd2655915 --- /dev/null +++ b/vpn-daemons/pptp/properties/nm-pptp.c @@ -0,0 +1,749 @@ +/*************************************************************************** + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + **************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#define NM_VPN_API_SUBJECT_TO_CHANGE + +#include + +typedef struct _NetworkManagerVpnUIImpl NetworkManagerVpnUIImpl; + + +struct _NetworkManagerVpnUIImpl { + NetworkManagerVpnUI parent; + + NetworkManagerVpnUIDialogValidityCallback callback; + gpointer callback_user_data; + + GladeXML *xml; + + GtkWidget *widget; + + GtkEntry *w_connection_name; + GtkEntry *w_remote; + GtkEntry *w_username; + GtkCheckButton *w_use_routes; + GtkEntry *w_routes; + GtkCheckButton *w_use_mppe; + GtkCheckButton *w_use_mppc; + GtkExpander *w_opt_info_expander; + GtkButton *w_import_button; +}; + +static void +pptp_clear_widget (NetworkManagerVpnUIImpl *impl) +{ + gtk_entry_set_text (impl->w_connection_name, ""); + gtk_entry_set_text (impl->w_remote, ""); + gtk_entry_set_text (impl->w_username, ""); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_routes), FALSE); + gtk_entry_set_text (impl->w_routes, ""); + gtk_widget_set_sensitive (GTK_WIDGET (impl->w_routes), FALSE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_mppe), TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_mppc), TRUE); + gtk_expander_set_expanded (impl->w_opt_info_expander, FALSE); +} + +static const char * +impl_get_display_name (NetworkManagerVpnUI *self) +{ + return _("PPTP Client"); +} + +static const char * +impl_get_service_name (NetworkManagerVpnUI *self) +{ + return "org.freedesktop.NetworkManager.pptp"; +} + +static GtkWidget * +impl_get_widget (NetworkManagerVpnUI *self, GSList *properties, GSList *routes, const char *connection_name) +{ + GSList *i; + NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data; + gboolean should_expand; + + pptp_clear_widget (impl); + + should_expand = FALSE; + + if (connection_name != NULL) + gtk_entry_set_text (impl->w_connection_name, connection_name); + + for (i = properties; i != NULL && g_slist_next (i) != NULL; i = g_slist_next (g_slist_next (i))) { + const char *key; + const char *value; + + key = i->data; + value = (g_slist_next (i))->data; + + if (strcmp (key, "remote") == 0) { + gtk_entry_set_text (impl->w_remote, value); + } else if (strcmp (key, "username") == 0) { + gtk_entry_set_text (impl->w_username, value); + } else if ( (strcmp (key, "comp-mppc") == 0) && + (strcmp (value, "yes")) ) { + //gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_mppc), TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_routes), TRUE); + should_expand = TRUE; + } else if ( (strcmp (key, "comp-mppe") == 0) && + (strcmp (value, "yes")) ) { + //gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_mppe), TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_routes), TRUE); + should_expand = TRUE; + } + } + + if (routes != NULL) { + GString *route_str; + char *str; + + route_str = g_string_new (""); + for (i = routes; i != NULL; i = g_slist_next (i)) { + const char *route; + + if (i != routes) + g_string_append_c(route_str, ' '); + + route = (const char *) i->data; + g_string_append(route_str, route); + } + + str = g_string_free (route_str, FALSE); + gtk_entry_set_text (impl->w_routes, str); + g_free (str); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_routes), TRUE); + gtk_widget_set_sensitive (GTK_WIDGET (impl->w_routes), TRUE); + + should_expand = TRUE; + } + + gtk_expander_set_expanded (impl->w_opt_info_expander, should_expand); + gtk_container_resize_children (GTK_CONTAINER (impl->widget)); + + return impl->widget; +} + +static GSList * +impl_get_properties (NetworkManagerVpnUI *self) +{ + GSList *data; + NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data; + const char *connectionname; + const char *remote; + const char *username; + gboolean use_mppc; + gboolean use_mppe; + + connectionname = gtk_entry_get_text (impl->w_connection_name); + remote = gtk_entry_get_text (impl->w_remote); + username = gtk_entry_get_text (impl->w_username); + use_mppc = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (impl->w_use_mppc)); + use_mppe = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (impl->w_use_mppe)); + + data = NULL; + data = g_slist_append (data, g_strdup ("remote")); + data = g_slist_append (data, g_strdup (remote)); + data = g_slist_append (data, g_strdup ("username")); + data = g_slist_append (data, g_strdup (username)); + data = g_slist_append (data, g_strdup ("comp-mppc")); + data = g_slist_append (data, use_mppc ? g_strdup ("yes") : g_strdup("no")); + data = g_slist_append (data, g_strdup ("encrypt-mppe")); + data = g_slist_append (data, use_mppe ? g_strdup ("yes") : g_strdup("no")); + + return data; +} + +static GSList * +get_routes (NetworkManagerVpnUIImpl *impl) +{ + GSList *routes; + const char *routes_entry; + gboolean use_routes; + char **substrs; + unsigned int i; + + routes = NULL; + + routes_entry = gtk_entry_get_text (impl->w_routes); + use_routes = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (impl->w_use_routes)); + + if (!use_routes) + goto out; + + substrs = g_strsplit (routes_entry, " ", 0); + for (i = 0; substrs[i] != NULL; i++) { + char *route; + + route = substrs[i]; + if (strlen (route) > 0) + routes = g_slist_append (routes, g_strdup (route)); + } + + 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) +{ + const char *name; + NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data; + + name = gtk_entry_get_text (impl->w_connection_name); + if (name != NULL) + return g_strdup (name); + else + return NULL; +} + +static gboolean +impl_is_valid (NetworkManagerVpnUI *self) +{ + NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data; + gboolean is_valid; + const char *connectionname; + const char *remote; + const char *username; + gboolean use_routes; + const char *routes_entry; + + + is_valid = FALSE; + + connectionname = gtk_entry_get_text (impl->w_connection_name); + remote = gtk_entry_get_text (impl->w_remote); + username = gtk_entry_get_text (impl->w_username); + use_routes = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (impl->w_use_routes)); + routes_entry = gtk_entry_get_text (impl->w_routes); + + /* initial sanity checking */ + if (strlen (connectionname) > 0 && + strlen (remote) > 0 && + strlen (username) > 0 && + ((!use_routes) || (use_routes && strlen (routes_entry) > 0)) ) { + is_valid = TRUE; + } + + /* validate gateway: can be a hostname or an IP; do not allow spaces or tabs */ + if (is_valid && + ( (strstr (remote, " ") != NULL) || + (strstr (remote, "\t") != NULL) || + (strstr (username, " ") != NULL) || + (strstr (username, "\t") != NULL) ) + ) { + is_valid = FALSE; + } + + /* validate routes: each entry must be of the form 'a.b.c.d/mask' */ + if (is_valid) { + GSList *i; + GSList *routes; + + routes = get_routes (impl); + + for (i = routes; i != NULL; i = g_slist_next (i)) { + int d1, d2, d3, d4, mask; + + const char *route = (const char *) i->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) + // printf ("\n"); + + if (routes != NULL) { + g_slist_foreach (routes, (GFunc)g_free, NULL); + g_slist_free (routes); + } + } + + return is_valid; +} + + +static void +use_routes_toggled (GtkToggleButton *togglebutton, gpointer user_data) +{ + NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) user_data; + + gtk_widget_set_sensitive (GTK_WIDGET (impl->w_routes), + 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); + } +} + + +static 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); + } +} + + +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; +} + +static void +impl_get_confirmation_details (NetworkManagerVpnUI *self, gchar **retval) +{ + GString *buf; + NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data; + const char *connectionname; + const char *remote; + const char *username; + gboolean use_routes; + const char *routes; + gboolean use_mppe; + gboolean use_mppc; + + connectionname = gtk_entry_get_text (impl->w_connection_name); + remote = gtk_entry_get_text (impl->w_remote); + username = gtk_entry_get_text (impl->w_username); + use_routes = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (impl->w_use_routes)); + routes = gtk_entry_get_text (impl->w_routes); + use_mppe = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (impl->w_use_mppe)); + use_mppc = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (impl->w_use_mppc)); + + + // This is risky, should be variable length depending on actual data! + buf = g_string_sized_new (512); + + g_string_append (buf, _("The following PPTP connection will be created:")); + g_string_append (buf, "\n\n\t"); + g_string_append_printf (buf, _("Name: %s"), connectionname); + g_string_append (buf, "\n\n\t"); + + g_string_append_printf (buf, _("Remote: %s"), remote); + g_string_append (buf, "\n\t"); + + g_string_append_printf (buf, _("Username: %s"), username); + + if (use_routes) { + g_string_append (buf, "\n\t"); + g_string_append_printf (buf, _("Routes: %s"), routes); + } + + g_string_append (buf, "\n\t"); + g_string_append_printf( buf, _("Use MPPC Compression: %s"), ((use_mppc) ? _("Yes") : _("No"))); + g_string_append (buf, "\n\t"); + g_string_append_printf( buf, _("Use MPPE Encryption: %s"), ((use_mppe) ? _("Yes") : _("No"))); + + g_string_append (buf, "\n\n"); + g_string_append (buf, _("The connection details can be changed using the \"Edit\" 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; + 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 *connectionname = NULL; + char *remote = NULL; + char *username = NULL; + char *routes = NULL; + char *mppc = NULL; + char *mppe = NULL; + gboolean should_expand; + + connectionname = g_key_file_get_string (keyfile, "main", "Description", NULL); + remote = g_key_file_get_string (keyfile, "main", "Remote", NULL); + username = g_key_file_get_string (keyfile, "main", "Username", NULL); + mppc = g_key_file_get_string (keyfile, "main", "Comp-MPPC", NULL); + mppe = g_key_file_get_string (keyfile, "main", "Encrypt-MPPE", NULL); + + /* may not exist */ + if ((routes = g_key_file_get_string (keyfile, "main", "X-NM-Routes", NULL)) == NULL) + routes = g_strdup (""); + + /* sanity check data */ + if ( ( connectionname != NULL) && + ( remote != NULL ) && + ( username != NULL ) && + (strlen(connectionname) > 0) && + (strlen(username) > 0) && + (strlen(remote) > 0) ) { + + gtk_entry_set_text (impl->w_connection_name, connectionname); + gtk_entry_set_text (impl->w_remote, remote); + gtk_entry_set_text (impl->w_username, username); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_mppc), ((mppc != NULL) && (strcmp(mppc, "yes") == 0))); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_mppe), ((mppe != NULL) && (strcmp(mppe, "yes") == 0))); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_routes), strlen (routes) > 0); + gtk_entry_set_text (impl->w_routes, routes); + gtk_widget_set_sensitive (GTK_WIDGET (impl->w_routes), strlen (routes) > 0); + + should_expand = (strlen (routes) > 0) || + ((mppc != NULL) && (strcmp(mppc, "yes") == 0)) || + ((mppe != NULL) && (strcmp(mppe, "yes") == 0)); + gtk_expander_set_expanded (impl->w_opt_info_expander, should_expand); + + } else { + g_free (connectionname); + g_free (remote); + g_free (username); + g_free (mppe); + g_free (mppc); + } + g_key_file_free (keyfile); + + 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); + } + } + + g_free (basename); + + return file_is_good; +} + +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 *i; + const char *remote = NULL; + const char *username = NULL; + const char *mppc = NULL; + const char *mppe = NULL; + char *routes_str = NULL; + + /*printf ("in export_to_file; path='%s'\n", path);*/ + + for (i = properties; i != NULL && g_slist_next (i) != NULL; i = g_slist_next (g_slist_next (i))) { + const char *key; + const char *value; + + key = i->data; + value = (g_slist_next (i))->data; + + if (strcmp (key, "remote") == 0) { + remote = value; + } else if (strcmp (key, "username") == 0) { + username = value; + } else if (strcmp (key, "comp-mppc") == 0) { + mppc = value; + } else if (strcmp (key, "encrypt-mppe") == 0) { + mppe = value; + } + } + + + if (routes != NULL) { + GString *str; + + str = g_string_new ("X-NM-Routes="); + for (i = routes; i != NULL; i = g_slist_next (i)) { + const char *route; + + if (i != routes) + g_string_append_c (str, ' '); + + route = (const char *) i->data; + g_string_append (str, route); + } + + g_string_append_c (str, '\n'); + + routes_str = g_string_free (str, FALSE); + } + + f = fopen (path, "w"); + if (f != NULL) { + + fprintf (f, + "[main]\n" + "Description=%s\n" + "Remote=%s\n" + "Username=%s\n" + "Comp-MPPC=%s\n" + "Encrypt-MPPE=%s\n" + "%s", + /* Description */ connection_name, + /* Host */ remote, + /* Username */ username, + /* Comp-MPPC */ mppc, + /* Comp-MPPE */ mppe, + /* X-NM-Routes */ routes_str != NULL ? routes_str : ""); + + fclose (f); + } + g_free (routes_str); +} + + +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)); + /*printf ("User selected '%s'\n", path);*/ + + } + + 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); + } + } + + 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, "nm-pptp-dialog.glade"); + 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, "nm-pptp-widget"); + + impl->w_connection_name = GTK_ENTRY (glade_xml_get_widget (impl->xml, "pptp-connection-name")); + impl->w_remote = GTK_ENTRY (glade_xml_get_widget (impl->xml, "pptp-remote")); + impl->w_use_routes = GTK_CHECK_BUTTON (glade_xml_get_widget (impl->xml, "pptp-use-routes")); + impl->w_routes = GTK_ENTRY (glade_xml_get_widget (impl->xml, "pptp-routes")); + impl->w_opt_info_expander = GTK_EXPANDER (glade_xml_get_widget (impl->xml, + "pptp-optional-information-expander")); + impl->w_import_button = GTK_BUTTON (glade_xml_get_widget (impl->xml, + "pptp-import-button")); + + impl->w_username = GTK_ENTRY( glade_xml_get_widget( impl->xml, "pptp-username" ) ); + + impl->w_use_mppc = GTK_CHECK_BUTTON (glade_xml_get_widget (impl->xml, "pptp-use-mppc")); + impl->w_use_mppe = GTK_CHECK_BUTTON (glade_xml_get_widget (impl->xml, "pptp-use-mppe")); + + impl->callback = NULL; + + gtk_signal_connect (GTK_OBJECT (impl->w_use_routes), + "toggled", GTK_SIGNAL_FUNC (use_routes_toggled), impl); + + gtk_signal_connect (GTK_OBJECT (impl->w_connection_name), + "changed", GTK_SIGNAL_FUNC (editable_changed), impl); + gtk_signal_connect (GTK_OBJECT (impl->w_remote), + "changed", GTK_SIGNAL_FUNC (editable_changed), impl); + gtk_signal_connect (GTK_OBJECT (impl->w_routes), + "changed", GTK_SIGNAL_FUNC (editable_changed), impl); + gtk_signal_connect (GTK_OBJECT (impl->w_username), + "changed", GTK_SIGNAL_FUNC (editable_changed), impl); + + gtk_signal_connect (GTK_OBJECT (impl->w_import_button), + "clicked", GTK_SIGNAL_FUNC (import_button_clicked), impl); + + /* make the widget reusable */ + gtk_signal_connect (GTK_OBJECT (impl->widget), "delete-event", + GTK_SIGNAL_FUNC (gtk_widget_hide_on_delete), NULL); + + pptp_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/src/.cvsignore b/vpn-daemons/pptp/src/.cvsignore new file mode 100644 index 0000000000..7cb5018284 --- /dev/null +++ b/vpn-daemons/pptp/src/.cvsignore @@ -0,0 +1,4 @@ +Makefile.in +Makefile +nm-pptp-service +nm-pptp-service-pptp-helper diff --git a/vpn-daemons/pptp/src/Makefile.am b/vpn-daemons/pptp/src/Makefile.am new file mode 100644 index 0000000000..44a1153f0c --- /dev/null +++ b/vpn-daemons/pptp/src/Makefile.am @@ -0,0 +1,42 @@ +INCLUDES = -I${top_srcdir} -I${top_srcdir}/utils -I${top_srcdir}/vpn-daemons/pptp + +AM_CPPFLAGS = \ + $(DBUS_CFLAGS) \ + $(GTHREAD_CFLAGS) \ + -Wall \ + -DDBUS_API_SUBJECT_TO_CHANGE \ + -DG_DISABLE_DEPRECATED \ + -DBINDIR=\"$(bindir)\" \ + -DPREFIX=\""$(prefix)"\" \ + -DSYSCONFDIR=\""$(sysconfdir)"\" \ + -DVERSION="\"$(VERSION)\"" \ + -DLIBDIR=\""$(libdir)"\" \ + -DLIBEXECDIR=\""$(libexecdir)"\" \ + -DLOCALSTATEDIR=\""$(localstatedir)"\" \ + -DDATADIR=\"$(datadir)\" + +bin_PROGRAMS = nm-pptp-service nm-pptp-service-pppd-plugin.so + +nm_pptp_service_SOURCES = \ + nm-pptp-service.c \ + nm-pptp-service.h \ + nm-utils.c \ + nm-utils.h + + +nm_pptp_service_LDADD = \ + $(DBUS_LIBS) \ + $(GTHREAD_LIBS) + + +nm_pptp_service_pppd_plugin_so_SOURCES = \ + nm-pptp-service-pppd-plugin.c + +nm_pptp_service_pppd_plugin_so_LDFLAGS = \ + -shared + +nm_pptp_service_pppd_plugin_so_LDADD = \ + $(DBUS_LIBS) \ + $(GTHREAD_LIBS) + +CLEANFILES = *~ diff --git a/vpn-daemons/pptp/src/nm-pptp-service-pppd-plugin.c b/vpn-daemons/pptp/src/nm-pptp-service-pppd-plugin.c new file mode 100644 index 0000000000..97ad392cd2 --- /dev/null +++ b/vpn-daemons/pptp/src/nm-pptp-service-pppd-plugin.c @@ -0,0 +1,243 @@ +/* nm-pptp-service - pptp 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * (C) Copyright 2005 Red Hat, Inc. + */ + +#include "pppd/pppd.h" +#include "pppd/fsm.h" +#include "pppd/ipcp.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "nm-pptp-service.h" +#include "nm-utils.h" + +char pppd_version[] = VERSION; + +static void pptp_ip_up(void *opaque, int arg); +static void pptp_ip_down(void *opaque, int arg); +int pptp_chap_passwd(char *user, char *passwd); +static void send_config_error (DBusConnection *con, const char *item); + +/* nm_warning ("nm-pptp-service-pptp-helper didn't receive a Tunnel Device from pptp, or the tunnel device was not valid UTF-8."); + send_config_error (con, "Tunnel Device"); + nm_warning ("nm-pptp-service-pptp-helper didn't receive an Internal IP4 Address from pptp."); + send_config_error (con, "IP4 Address"); +*/ + +int plugin_init() +{ + DBusConnection * con; + 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)) + { + nm_warning ("Could not get the system bus. Make sure the message bus daemon is running?"); + return -1; + } + dbus_connection_set_exit_on_disconnect (con, FALSE); + +// add_options(ldap_options); + chap_passwd_hook = pptp_chap_passwd; + +// add_notifier(&ip_down_notifier, pptp_ip_down, (void *) con); + add_notifier(&ip_up_notifier, pptp_ip_up, (void *) con); + + info("nm-pptp: plugin initialized."); + + return 0; +} + +int pptp_chap_passwd(char *user, char *passwd) +{ + memcpy(passwd, "YOUR PASSWORD IN HERE!!",MAXSECRETLEN); + passwd[MAXSECRETLEN-1]='\0'; + return 0; +} + +static void pptp_ip_down(void *opaque, int arg) +{ +} + +static void pptp_ip_up(void *opaque, int arg) +{ + DBusConnection *con = (DBusConnection *)opaque; + DBusMessage *message; + char * str_ifname = NULL; +// guint32 * uint_ip4_dns = NULL; + guint32 uint_ip4_dns1 = 0; + guint32 uint_ip4_dns2 = 0; + guint32 uint_ip4_dns_len = 0; +// guint32 * uint_ip4_wins = NULL; + guint32 uint_ip4_wins1 = 0; + guint32 uint_ip4_wins2 = 0; + guint32 uint_ip4_wins_len = 0; + guint32 uint_ip4_address = 0; + guint32 uint_ip4_netmask = 0xFFFFFFFF; /* Default mask of 255.255.255.255 */ + guint32 i=0; + + g_return_if_fail (con != NULL); + if (ipcp_gotoptions[ifunit].ouraddr==0) { + nm_warning ("nm-pptp-service-pptp-helper didn't receive an Internal IP4 Address from pptp."); + send_config_error (con, "IP4 Address"); + return; + } + uint_ip4_address=ipcp_gotoptions[ifunit].ouraddr; + + if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE_PPTP, NM_DBUS_PATH_PPTP, NM_DBUS_INTERFACE_PPTP, "signalIP4Config"))) + { + 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 (uint_ip4_dns_len > 0) +// { +// uint_ip4_dns = g_new0(guint32,uint_ip4_dns_len); +// for (i = 0; i < uint_ip4_dns_len; ++i) +// uint_ip4_dns[i] = ipcp_gotoptions[ifunit].dnsaddr[i]; +// } + } + + if (ipcp_gotoptions[ifunit].winsaddr) { + if (ipcp_gotoptions[ifunit].winsaddr[0]!=0) { + uint_ip4_wins_len++; + uint_ip4_wins1=ipcp_gotoptions[ifunit].winsaddr[0]; + if (ipcp_gotoptions[ifunit].winsaddr[1]!=0) { + uint_ip4_wins_len++; + uint_ip4_wins2=ipcp_gotoptions[ifunit].winsaddr[1]; + } + } +// if (uint_ip4_wins_len > 0) +// { +// uint_ip4_wins = g_new0(guint32,uint_ip4_wins_len); +// for (i = 0; i < uint_ip4_wins_len; ++i) +// uint_ip4_wins[i] = ipcp_gotoptions[ifunit].winsaddr[i]; +// } + } + + if (ifname==NULL) { + nm_warning ("nm-pptp-service-pptp-helper didn't receive a tunnel device name."); + send_config_error (con, "IP4 Address"); + } + str_ifname = g_strdup(ifname); + +/* Print out some debug info. + nm_warning("Sending config IFNAME: %s",str_ifname); + nm_warning("Sending config IPLOCAL: %s", ip_ntoa(uint_ip4_address)); + nm_warning("Sending config NETMASK: %s", ip_ntoa(uint_ip4_netmask)); + nm_warning("Sending config DNS1: %s", ip_ntoa(uint_ip4_dns1)); + nm_warning("Sending config DNS2: %s", ip_ntoa(uint_ip4_dns2)); + nm_warning("Sending config NDNS: %d", uint_ip4_dns_len); + nm_warning("Sending config WINS1: %s", ip_ntoa(uint_ip4_wins1)); + nm_warning("Sending config WINS2: %s", ip_ntoa(uint_ip4_wins2)); + nm_warning("Sending config NWINS: %d", uint_ip4_wins_len); */ + + dbus_message_append_args (message, + DBUS_TYPE_STRING, &str_ifname, + DBUS_TYPE_UINT32, &uint_ip4_address, + DBUS_TYPE_UINT32, &uint_ip4_netmask, +// Array workaround + DBUS_TYPE_UINT32, &uint_ip4_dns1, + DBUS_TYPE_UINT32, &uint_ip4_dns2, + DBUS_TYPE_UINT32, &uint_ip4_dns_len, + DBUS_TYPE_UINT32, &uint_ip4_wins1, + DBUS_TYPE_UINT32, &uint_ip4_wins2, + DBUS_TYPE_UINT32, &uint_ip4_wins_len, +// +// For some reason DBUS_TYPE_ARRAYs don't seem to like working inside the pppd plugin +// +// testing with: +// pppd pty "/usr/sbin/pptp SOME.SERVER.IP --nolaunchpppd" nodetach remotename SOME.SERVER user MYUSER usepeerdns plugin nm-pptp-service-pppd-plugin.so +// +// Fails with (given pointers and allocated arrays with g_new0() ): +// 13646: assertion failed "value != NULL" file "dbus-string.c" line 235 function _dbus_string_init_const_len +// Fatal signal 6 +// +// Or if fixed [2] arrays are used: +// Fatal signal 11 +// +// DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &uint_ip4_dns, uint_ip4_dns_len, +// DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &uint_ip4_wins, uint_ip4_wins_len, + DBUS_TYPE_INVALID); + if (!dbus_connection_send (con, message, NULL)) { + nm_warning ("pptp_ip_up(): could not send dbus message"); + dbus_message_unref (message); + return; + } + + dbus_message_unref (message); + + return; +} + + +/* + * send_config_error + * + * Notify nm-pptp-service of a config error from 'pptp'. + * +*/ +static void send_config_error (DBusConnection *con, const char *item) +{ + DBusMessage *message; + + g_return_if_fail (con != NULL); + g_return_if_fail (item != NULL); + + if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE_PPTP, NM_DBUS_PATH_PPTP, NM_DBUS_INTERFACE_PPTP, "signalConfigError"))) + { + nm_warning ("send_config_error(): Couldn't allocate the dbus message"); + return; + } + + dbus_message_append_args (message, DBUS_TYPE_STRING, &item, DBUS_TYPE_INVALID); + if (!dbus_connection_send (con, message, NULL)) + nm_warning ("send_config_error(): could not send dbus message"); + + dbus_message_unref (message); +} + + 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..8dbc0c944a --- /dev/null +++ b/vpn-daemons/pptp/src/nm-pptp-service.c @@ -0,0 +1,1136 @@ +/* nm-pptp-service - pptp integration with NetworkManager + * + * Antony Mee + * Based on 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 "nm-pptp-service.h" +#include "nm-utils.h" + + +static const char *pptp_binary_paths[] = +{ + "/usr/sbin/pptp", + "/sbin/pptp", + NULL +}; + +static const char *pppd_binary_paths[] = +{ + "/usr/sbin/pppd", + "/sbin/pppd", + NULL +}; + +#define NM_PPTP_HELPER_PATH "nm-pptp-service-pppd-plugin.so" + +typedef struct NmPPTPData +{ + GMainLoop * loop; + DBusConnection *con; + NMVPNState state; + GPid pid; + guint quit_timer; + guint helper_timer; + char *str_ip4_vpn_gateway; + struct in_addr ip4_vpn_gateway; +} NmPPTPData; + + +static gboolean nm_pptp_dbus_handle_stop_vpn (NmPPTPData *data); + + +/* + * 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_pptp_dbus_signal_failure + * + * Signal the bus that some VPN operation failed. + * + */ +static void nm_pptp_dbus_signal_failure (NmPPTPData *data, const char *signal) +{ + DBusMessage *message; + const char *error_msg = NULL; + + g_return_if_fail (data != NULL); + g_return_if_fail (signal != NULL); + + // No sophisticated error message for now + error_msg = _("VPN Connection failed"); + if (!error_msg) + return; + + if (!(message = dbus_message_new_signal (NM_DBUS_PATH_PPTP, NM_DBUS_INTERFACE_PPTP, signal))) + { + nm_warning ("Not enough memory for new dbus message!"); + return; + } + + dbus_message_append_args (message, DBUS_TYPE_STRING, &error_msg, DBUS_TYPE_INVALID); + if (!dbus_connection_send (data->con, message, NULL)) + nm_warning ("Could not raise the signal!"); + + dbus_message_unref (message); +} + + +/* + * nm_pptp_dbus_signal_state_change + * + * Signal the bus that our state changed. + * + */ +static void nm_pptp_dbus_signal_state_change (NmPPTPData *data, NMVPNState old_state) +{ + DBusMessage *message; + + g_return_if_fail (data != NULL); + + if (!(message = dbus_message_new_signal (NM_DBUS_PATH_PPTP, NM_DBUS_INTERFACE_PPTP, NM_DBUS_VPN_SIGNAL_STATE_CHANGE))) + { + nm_warning ("nm_pptp_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_pptp_dbus_signal_state_change(): Could not raise the signal!"); + + dbus_message_unref (message); +} + + +/* + * nm_pptp_set_state + * + * Set our state and make sure to signal the bus. + * + */ +static void nm_pptp_set_state (NmPPTPData *data, NMVPNState new_state) +{ + NMVPNState old_state; + + g_return_if_fail (data != NULL); + + old_state = data->state; + + nm_info("PPTP State change: %d -> %d",old_state,new_state); + + if (old_state != new_state) + { + data->state = new_state; + nm_pptp_dbus_signal_state_change (data, old_state); + } +} + + +/* + * nm_pptp_quit_timer_cb + * + * Callback to quit nm-pptp-service after a certain period of time. + * + */ +static gboolean nm_pptp_quit_timer_cb (NmPPTPData *data) +{ + data->quit_timer = 0; + + g_return_val_if_fail (data != NULL, FALSE); + + g_main_loop_quit (data->loop); + + return FALSE; +} + + +/* + * nm_pptp_schedule_quit_timer + * + * If pptp 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_pptp_schedule_quit_timer (NmPPTPData *data, guint interval) +{ + g_return_if_fail (data != NULL); + + if (data->quit_timer == 0) + data->quit_timer = g_timeout_add (interval, (GSourceFunc) nm_pptp_quit_timer_cb, data); +} + + +/* + * nm_pptp_cancel_quit_timer + * + * Cancel a quit timer that we've scheduled before. + * + */ +static void nm_pptp_cancel_quit_timer (NmPPTPData *data) +{ + g_return_if_fail (data != NULL); + + if (data->quit_timer > 0) + g_source_remove (data->quit_timer); +} + + +/* + * nm_pptp_helper_timer_cb + * + * If we haven't received the IP4 config info from the helper before the timeout + * occurs, we kill pptp + * + */ +static gboolean nm_pptp_helper_timer_cb (NmPPTPData *data) +{ + data->helper_timer = 0; + + g_return_val_if_fail (data != NULL, FALSE); + + nm_pptp_dbus_signal_failure (data, NM_DBUS_VPN_SIGNAL_CONNECT_FAILED); + nm_pptp_dbus_handle_stop_vpn (data); + + return FALSE; +} + + +/* + * nm_pptp_schedule_helper_timer + * + * Once pptp 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 pptp + * + */ +static void nm_pptp_schedule_helper_timer (NmPPTPData *data) +{ + g_return_if_fail (data != NULL); + + if (data->helper_timer == 0) + data->helper_timer = g_timeout_add (10000, (GSourceFunc) nm_pptp_helper_timer_cb, data); +} + + +/* + * nm_pptp_cancel_helper_timer + * + * Cancel a helper timer that we've scheduled before. + * + */ +static void nm_pptp_cancel_helper_timer (NmPPTPData *data) +{ + g_return_if_fail (data != NULL); + + if (data->helper_timer > 0) + g_source_remove (data->helper_timer); +} + + +/* + * pptp_watch_cb + * + * Watch our child pptp process and get notified of events from it. + * + */ +static void pptp_watch_cb (GPid pid, gint status, gpointer user_data) +{ + guint error = -1; + + NmPPTPData *data = (NmPPTPData *)user_data; + + if (WIFEXITED (status)) + { + error = WEXITSTATUS (status); + if (error != 0) + nm_warning ("pptp exited with error code %d", error); + } + else if (WIFSTOPPED (status)) + nm_warning ("pptp stopped unexpectedly with signal %d", WSTOPSIG (status)); + else if (WIFSIGNALED (status)) + nm_warning ("pptp died with signal %d", WTERMSIG (status)); + else + nm_warning ("pptp 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_pptp_dbus_signal_failure (data, NM_DBUS_VPN_SIGNAL_LOGIN_FAILED); + break; + + case 1: /* Other error (couldn't bind to address, etc) */ + nm_pptp_dbus_signal_failure (data, NM_DBUS_VPN_SIGNAL_CONNECT_FAILED); + break; + + default: + break; + } + + nm_pptp_set_state (data, NM_VPN_STATE_STOPPED); + nm_pptp_schedule_quit_timer (data, 10000); +} + + +/* + * nm_pptp_start_vpn_binary + * + * Start the pptp binary with a set of arguments and a config file. + * + */ +static gint nm_pptp_start_pptp_binary (NmPPTPData *data, char **data_items, const int num_items) +{ + GPid pid; + const char ** pptp_binary = NULL; + const char ** pppd_binary = NULL; + struct hostent *hostinfo = NULL; + GPtrArray * pptp_argv; + GError * error = NULL; + GSource * pptp_watch; + gint stdin_fd = -1; + int i = 0; + char * pppd_pty = NULL; + + g_return_val_if_fail (data != NULL, -1); + + data->pid = 0; + + if ( (num_items == 0) || (data_items == NULL) ) { + return -1; + } + + /* 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; + } + + /* 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; + } + + pptp_argv = g_ptr_array_new (); + g_ptr_array_add (pptp_argv, (gpointer) (*pppd_binary)); + + // First pptp parameter is the PPTP server + for (i = 0; i < num_items; ++i) { + if ( strcmp( data_items[i], "remote" ) == 0) { + hostinfo = gethostbyname(data_items[++i]); + if (!hostinfo) { + nm_info ("Could not resolve VPN servers IP."); + return -1; + } + data -> ip4_vpn_gateway = *(struct in_addr*)(hostinfo->h_addr_list[0]); + data -> str_ip4_vpn_gateway = g_strdup( inet_ntoa( data -> ip4_vpn_gateway ) ); +// nm_info ("Lookup VPN server IP = '%s'",data->str_ip4_vpn_gateway); + + pppd_pty = g_strdup_printf ("%s %s --nolaunchpppd", (*pptp_binary), data->str_ip4_vpn_gateway); +// nm_info ("Starting pppd with pty %s",pppd_pty); + + g_ptr_array_add (pptp_argv, (gpointer) "pty"); + g_ptr_array_add (pptp_argv, (gpointer) pppd_pty); + + } + } + + g_ptr_array_add (pptp_argv, (gpointer) "nodetach"); + g_ptr_array_add (pptp_argv, (gpointer) "lock"); + g_ptr_array_add (pptp_argv, (gpointer) "noauth"); + g_ptr_array_add (pptp_argv, (gpointer) "nobsdcomp"); + g_ptr_array_add (pptp_argv, (gpointer) "nodeflate"); +// g_ptr_array_add (pptp_argv, (gpointer) "ipparam"); +// g_ptr_array_add (pptp_argv, (gpointer) "nm-pptp-service"); + g_ptr_array_add (pptp_argv, (gpointer) "mtu"); + g_ptr_array_add (pptp_argv, (gpointer) "1000"); + g_ptr_array_add (pptp_argv, (gpointer) "mru"); + g_ptr_array_add (pptp_argv, (gpointer) "1000"); + g_ptr_array_add (pptp_argv, (gpointer) "lcp-echo-failure"); + g_ptr_array_add (pptp_argv, (gpointer) "10"); + g_ptr_array_add (pptp_argv, (gpointer) "lcp-echo-interval"); + g_ptr_array_add (pptp_argv, (gpointer) "10"); + // Set the username... + for (i = 0; i < num_items; ++i) { + if ( strcmp( data_items[i], "username" ) == 0) { + g_ptr_array_add (pptp_argv, (gpointer) "user"); + g_ptr_array_add (pptp_argv, (gpointer) data_items[++i]); + } else if ( strcmp( data_items[i], "remote" ) == 0) { + g_ptr_array_add (pptp_argv, (gpointer) "remotename"); + g_ptr_array_add (pptp_argv, (gpointer) data_items[++i]); + } else if ( (strcmp( data_items[i], "encrypt-mppe" ) == 0) && + (strcmp( data_items[i], "yes" ) == 0) ) { +// g_ptr_array_add (pptp_argv, (gpointer) "mppe required"); + } else if ( (strcmp( data_items[i], "comp-mppc" ) == 0) && + (strcmp( data_items[i], "yes" ) == 0) ) { +// g_ptr_array_add (pptp_argv, (gpointer) "mppc required"); + } + } + + g_ptr_array_add (pptp_argv, (gpointer) "usepeerdns"); + + g_ptr_array_add (pptp_argv, (gpointer) "plugin"); + g_ptr_array_add (pptp_argv, (gpointer) NM_PPTP_HELPER_PATH); + + g_ptr_array_add (pptp_argv, NULL); + + if (!g_spawn_async_with_pipes (NULL, (char **) pptp_argv->pdata, NULL, + G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, &stdin_fd, + NULL, NULL, &error)) + { + g_ptr_array_free (pptp_argv, TRUE); + g_free(pppd_pty); + nm_warning ("pptp failed to start. error: '%s'", error->message); + g_error_free(error); + return -1; + } + g_ptr_array_free (pptp_argv, TRUE); + g_free(pppd_pty); + + nm_info ("pptp started with pid %d", pid); + + data->pid = pid; + pptp_watch = g_child_watch_source_new (pid); + g_source_set_callback (pptp_watch, (GSourceFunc) pptp_watch_cb, data, NULL); + g_source_attach (pptp_watch, NULL); + g_source_unref (pptp_watch); + + nm_pptp_schedule_helper_timer (data); + + return stdin_fd; +} + + +typedef enum OptType +{ + OPT_TYPE_UNKNOWN = 0, + OPT_TYPE_ADDRESS, + OPT_TYPE_ASCII, + OPT_TYPE_NONE +} OptType; + +typedef struct Option +{ + const char *name; + OptType type; +} Option; + +/* + * nm_pptp_config_options_validate + * + * Make sure the config options are sane + * + */ +static gboolean nm_pptp_config_options_validate (char **data_items, int num_items) +{ + Option allowed_opts[] = { + { "remote", OPT_TYPE_ADDRESS }, + { "username", OPT_TYPE_ASCII }, + { "comp-mppc", OPT_TYPE_ASCII }, + { "encrypt-mppe", OPT_TYPE_ASCII }, + { NULL, OPT_TYPE_UNKNOWN } }; + + unsigned int i; + + g_return_val_if_fail (data_items != NULL, FALSE); + g_return_val_if_fail (num_items >= 2, FALSE); + + /* Must be an even numbers of config options */ + if ((num_items % 2) != 0) + { + nm_warning ("The number of VPN config options was not even."); + return FALSE; + } + + for (i = 0; i < num_items; i += 2) + { + Option *opt = NULL; + unsigned int t, len; + char *opt_value; + + if (!data_items[i] || !data_items[i+1]) + return FALSE; + opt_value = data_items[i+1]; + + /* Find the option in the allowed list */ + for (t = 0; t < sizeof (allowed_opts) / sizeof (Option); t++) + { + opt = &allowed_opts[t]; + if (opt->name && !strcmp (opt->name, data_items[i])) + break; + } + if (!opt->name) /* not found */ + { + nm_warning ("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; + + default: + return FALSE; + break; + } + } + + return TRUE; +} + +/* + * nm_pptp_dbus_handle_start_vpn + * + * Parse message arguments and start the VPN connection. + * + */ +static gboolean nm_pptp_dbus_handle_start_vpn (DBusMessage *message, NmPPTPData *data) +{ + char ** data_items = NULL; + int num_items = -1; + char ** password_items = NULL; + int num_passwords = -1; + const char * name = NULL; + const char * user_name = NULL; + DBusError error; + gboolean success = FALSE; + gint pptp_fd = -1; + + g_return_val_if_fail (message != NULL, FALSE); + g_return_val_if_fail (data != NULL, FALSE); + + nm_pptp_set_state (data, NM_VPN_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, &password_items, &num_passwords, + DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &data_items, &num_items, + DBUS_TYPE_INVALID)) + { + nm_warning ("Could not process the request because its arguments were invalid. dbus said: '%s'", error.message); + nm_pptp_dbus_signal_failure (data, NM_DBUS_VPN_SIGNAL_VPN_CONFIG_BAD); + dbus_error_free (&error); + goto out; + } + + if (!nm_pptp_config_options_validate (data_items, num_items)) + { + nm_pptp_dbus_signal_failure (data, NM_DBUS_VPN_SIGNAL_VPN_CONFIG_BAD); + goto out; + } + + /* Now we can finally try to activate the VPN */ + if ((pptp_fd = nm_pptp_start_pptp_binary (data, data_items, num_items)) >= 0) + { + success = TRUE; + } + +out: + dbus_free_string_array (data_items); + if (!success) + nm_pptp_set_state (data, NM_VPN_STATE_STOPPED); + return success; +} + + +/* + * nm_pptp_dbus_handle_stop_vpn + * + * Stop the running pppd dameon. + * + */ +static gboolean nm_pptp_dbus_handle_stop_vpn (NmPPTPData *data) +{ + g_return_val_if_fail (data != NULL, FALSE); + + if (data->pid > 0) + { + nm_pptp_set_state (data, NM_VPN_STATE_STOPPING); + + kill (data->pid, SIGTERM); + nm_info ("Terminated pppd with PID %d.", data->pid); + data->pid = 0; + + nm_pptp_set_state (data, NM_VPN_STATE_STOPPED); + nm_pptp_schedule_quit_timer (data, 10000); + } + + return TRUE; +} + + +/* + * nm_pptp_dbus_start_vpn + * + * Begin a VPN connection. + * + */ +static DBusMessage *nm_pptp_dbus_start_vpn (DBusConnection *con, DBusMessage *message, NmPPTPData *data) +{ + DBusMessage *reply = NULL; + + g_return_val_if_fail (data != NULL, NULL); + g_return_val_if_fail (con != NULL, NULL); + g_return_val_if_fail (message != NULL, NULL); + + switch (data->state) + { + case NM_VPN_STATE_STARTING: + reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE_PPTP, NM_DBUS_VPN_STARTING_IN_PROGRESS, + "Could not process the request because the VPN connection is already being started."); + break; + + case NM_VPN_STATE_STARTED: + reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE_PPTP, NM_DBUS_VPN_ALREADY_STARTED, + "Could not process the request because a VPN connection was already active."); + break; + + case NM_VPN_STATE_STOPPING: + reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE_PPTP, NM_DBUS_VPN_STOPPING_IN_PROGRESS, + "Could not process the request because the VPN connection is being stopped."); + break; + + case NM_VPN_STATE_STOPPED: + nm_pptp_cancel_quit_timer (data); + nm_pptp_dbus_handle_start_vpn (message, data); + reply = dbus_message_new_method_return (message); + break; + + default: + g_assert_not_reached(); + break; + } + + return reply; +} + + +/* + * nm_pptp_dbus_stop_vpn + * + * Terminate a VPN connection. + * + */ +static DBusMessage *nm_pptp_dbus_stop_vpn (DBusConnection *con, DBusMessage *message, NmPPTPData *data) +{ + DBusMessage *reply = NULL; + + g_return_val_if_fail (data != NULL, NULL); + g_return_val_if_fail (con != NULL, NULL); + g_return_val_if_fail (message != NULL, NULL); + + switch (data->state) + { + case NM_VPN_STATE_STOPPING: + reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE_PPTP, NM_DBUS_VPN_STOPPING_IN_PROGRESS, + "Could not process the request because the VPN connection is already being stopped."); + break; + + case NM_VPN_STATE_STOPPED: + reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE_PPTP, NM_DBUS_VPN_ALREADY_STOPPED, + "Could not process the request because no VPN connection was active."); + break; + + case NM_VPN_STATE_STARTING: + case NM_VPN_STATE_STARTED: + nm_pptp_dbus_handle_stop_vpn (data); + reply = dbus_message_new_method_return (message); + break; + + default: + g_assert_not_reached(); + break; + } + + return reply; +} + + +/* + * nm_pptp_dbus_get_state + * + * Return some state information to NetworkManager. + * + */ +static DBusMessage *nm_pptp_dbus_get_state (DBusConnection *con, DBusMessage *message, NmPPTPData *data) +{ + DBusMessage *reply = NULL; + + g_return_val_if_fail (data != NULL, NULL); + g_return_val_if_fail (con != NULL, NULL); + g_return_val_if_fail (message != NULL, NULL); + + if ((reply = dbus_message_new_method_return (message))) + dbus_message_append_args (reply, DBUS_TYPE_UINT32, &(data->state), DBUS_TYPE_INVALID); + + return reply; +} + + +/* + * nm_pptp_dbus_process_helper_config_error + * + * Signal the bus that the helper could not get all the configuration information + * it needed. + * + */ +static void nm_pptp_dbus_process_helper_config_error (DBusConnection *con, DBusMessage *message, NmPPTPData *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_STATE_STARTING) + return; + + if (dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &error_item, DBUS_TYPE_INVALID)) + { + nm_warning ("pptp helper did not receive adequate configuration information from pppd. It is missing '%s'.", error_item); + nm_pptp_dbus_signal_failure (data, NM_DBUS_VPN_SIGNAL_IP_CONFIG_BAD); + } + + nm_pptp_cancel_helper_timer (data); + nm_pptp_dbus_handle_stop_vpn (data); +} + + +/* + * nm_pptp_dbus_process_helper_ip4_config + * + * Signal the bus + * + */ +static void nm_pptp_dbus_process_helper_ip4_config (DBusConnection *con, DBusMessage *message, NmPPTPData *data) +{ + guint32 ip4_vpn_gateway; + char * tundev; + guint32 ip4_address; + guint32 ip4_netmask; + guint32 * ip4_dns; + guint32 ip4_dns_len; + guint32 ip4_dns1; + guint32 ip4_dns2; + guint32 * ip4_nbns; + guint32 ip4_nbns_len; + guint32 ip4_nbns1; + guint32 ip4_nbns2; + gboolean success = FALSE; + char * empty = ""; + + 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_STATE_STARTING) + return; + + nm_pptp_cancel_helper_timer (data); + + if (dbus_message_get_args(message, NULL, + DBUS_TYPE_STRING, &tundev, + DBUS_TYPE_UINT32, &ip4_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_PPTP, NM_DBUS_INTERFACE_PPTP, NM_DBUS_VPN_SIGNAL_IP4_CONFIG))) + { + nm_warning ("Not enough memory for new dbus message!"); + goto out; + } + + ip4_vpn_gateway=data->ip4_vpn_gateway.s_addr; + dbus_message_append_args (signal, + DBUS_TYPE_UINT32, &ip4_vpn_gateway, + DBUS_TYPE_STRING, &tundev, + DBUS_TYPE_UINT32, &ip4_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_STRING, &empty, + DBUS_TYPE_STRING, &empty, + DBUS_TYPE_INVALID); + + 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_pptp_set_state (data, NM_VPN_STATE_STARTED); + success = TRUE; + } + +out: + if (ip4_nbns) g_free(ip4_nbns); + if (ip4_dns) g_free(ip4_dns); + + if (!success) + { + nm_warning ("Received invalid IP4 Config information from helper, terminating pptp."); + nm_pptp_dbus_handle_stop_vpn (data); + } +} + + +/* + * nm_pptp_dbus_message_handler + * + * Handle requests for our services. + * + */ +static DBusHandlerResult nm_pptp_dbus_message_handler (DBusConnection *con, DBusMessage *message, void *user_data) +{ + NmPPTPData *data = (NmPPTPData *)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_pptp_dbus_message_handler() got method '%s' for path '%s'.", method, path); */ + + /* If we aren't ready to accept dbus messages, don't */ + if ((data->state == NM_VPN_STATE_INIT) || (data->state == NM_VPN_STATE_SHUTDOWN)) + { + nm_warning ("Received dbus messages but couldn't handle them due to INIT or SHUTDOWN states."); + reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE_PPTP, NM_DBUS_VPN_WRONG_STATE, + "Could not process the request due to current state of STATE_INIT or STATE_SHUTDOWN."); + goto reply; + } + + if (strcmp ("startConnection", method) == 0) + reply = nm_pptp_dbus_start_vpn (con, message, data); + else if (strcmp ("stopConnection", method) == 0) + reply = nm_pptp_dbus_stop_vpn (con, message, data); + else if (strcmp ("getState", method) == 0) + reply = nm_pptp_dbus_get_state (con, message, data); + else if (strcmp ("signalConfigError", method) == 0) + nm_pptp_dbus_process_helper_config_error (con, message, data); + else if (strcmp ("signalIP4Config", method) == 0) + nm_pptp_dbus_process_helper_ip4_config (con, message, data); + else + 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_pptp_dbus_filter + * + * Handle signals from the bus, like NetworkManager network state + * signals. + * + */ +static DBusHandlerResult nm_pptp_dbus_filter (DBusConnection *con, DBusMessage *message, void *user_data) +{ + NmPPTPData *data = (NmPPTPData *)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_pptp_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_pptp_dbus_handle_stop_vpn (data); + } + + return (handled ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED); +} + + +/* + * nm_pptp_dbus_init + * + * Grab our connection to the system bus, return NULL if anything goes wrong. + * + */ +DBusConnection *nm_pptp_dbus_init (NmPPTPData *data) +{ + DBusConnection *connection = NULL; + DBusError error; + DBusObjectPathVTable vtable = { NULL, &nm_pptp_dbus_message_handler, NULL, NULL, NULL, NULL }; + + g_return_val_if_fail (data != NULL, NULL); + + dbus_error_init (&error); + if (!(connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error))) + { + nm_warning ("Error connecting to system bus: '%s'", error.message); + goto out; + } + + dbus_connection_setup_with_g_main (connection, NULL); + + dbus_error_init (&error); + dbus_bus_request_name (connection, NM_DBUS_SERVICE_PPTP, 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_PPTP, &vtable, data)) + { + nm_warning ("Could not register a dbus handler for nm-pptp-service. Not enough memory?"); + return NULL; + } + + if (!dbus_connection_add_filter (connection, nm_pptp_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; +} + +NmPPTPData *vpn_data = NULL; + +static void sigterm_handler (int signum) +{ + nm_info ("nm-pptp-service 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 (NmPPTPData)); + + vpn_data->state = NM_VPN_STATE_INIT; + + vpn_data->loop = g_main_loop_new (NULL, FALSE); + + if (!(vpn_data->con = nm_pptp_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_pptp_set_state (vpn_data, NM_VPN_STATE_STOPPED); + g_main_loop_run (vpn_data->loop); + + nm_pptp_dbus_handle_stop_vpn (vpn_data); + + g_main_loop_unref (vpn_data->loop); + + if (vpn_data->str_ip4_vpn_gateway != NULL) g_free( vpn_data->str_ip4_vpn_gateway ); + g_free (vpn_data); + + exit (0); +} 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..96b5f7f67a --- /dev/null +++ b/vpn-daemons/pptp/src/nm-pptp-service.h @@ -0,0 +1,30 @@ +/* nm-pptp-service - pptp integration with NetworkManager + * + * Antony Mee + * Based on 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef NM_PPTP_SERVICE_H +#define NM_PPTP_SERVICE_H + +#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" + +#endif diff --git a/vpn-daemons/pptp/src/nm-utils.c b/vpn-daemons/pptp/src/nm-utils.c new file mode 100644 index 0000000000..fbcabe912d --- /dev/null +++ b/vpn-daemons/pptp/src/nm-utils.c @@ -0,0 +1,132 @@ +/* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * (C) Copyright 2005 Red Hat, Inc. + */ + +#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; +} diff --git a/vpn-daemons/pptp/src/nm-utils.h b/vpn-daemons/pptp/src/nm-utils.h new file mode 100644 index 0000000000..5c548ac186 --- /dev/null +++ b/vpn-daemons/pptp/src/nm-utils.h @@ -0,0 +1,131 @@ +/* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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_GNUC_PRETTY_FUNCTION, ##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_GNUC_PRETTY_FUNCTION, fmt_str, ##args); \ +} G_STMT_END + +#define nm_warning(fmt, args...) \ +G_STMT_START \ +{ \ + g_warning ("\t %s (): " fmt "\n", \ + G_GNUC_PRETTY_FUNCTION, ##args); \ +} G_STMT_END + +#define nm_warning_str(fmt_str, args...) \ +G_STMT_START \ +{ \ + g_warning ("\t %s (): %s\n", \ + G_GNUC_PRETTY_FUNCTION, 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_GNUC_PRETTY_FUNCTION, ##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_GNUC_PRETTY_FUNCTION, 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); + +#endif /* NM_UTILS_H */ diff --git a/vpn-daemons/pptp/src/pppd/fsm.h b/vpn-daemons/pptp/src/pppd/fsm.h new file mode 100644 index 0000000000..f02473f2b0 --- /dev/null +++ b/vpn-daemons/pptp/src/pppd/fsm.h @@ -0,0 +1,168 @@ +/* + * 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/pppd/ipcp.h b/vpn-daemons/pptp/src/pppd/ipcp.h new file mode 100644 index 0000000000..c0d3c85eb4 --- /dev/null +++ b/vpn-daemons/pptp/src/pppd/ipcp.h @@ -0,0 +1,96 @@ +/* + * 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/pppd/patchlevel.h b/vpn-daemons/pptp/src/pppd/patchlevel.h new file mode 100644 index 0000000000..f36d37f9cf --- /dev/null +++ b/vpn-daemons/pptp/src/pppd/patchlevel.h @@ -0,0 +1,4 @@ +/* $Id$ */ + +#define VERSION "2.4.3" +#define DATE "13 November 2004" diff --git a/vpn-daemons/pptp/src/pppd/pppd.h b/vpn-daemons/pptp/src/pppd/pppd.h new file mode 100644 index 0000000000..b0d40138d3 --- /dev/null +++ b/vpn-daemons/pptp/src/pppd/pppd.h @@ -0,0 +1,910 @@ +/* + * 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__ */