Subject: | Net::DBus dbus_strict_exports [patch] |
Hi Daniel,
Net::DBus doesn't support to only allow access to exported methods via
dbus_method.
The attached patch introduces a new method dbus_strict_exports() which
will force Net::DBus to only allow a client to access methods which were
exported through dbus_method.
Thanks.
Greetings.
Subject: | dbus_strict_exports.patch |
diff -uraN libnet-dbus-perl-0.33.6.orig/lib/Net/DBus/Binding/Introspector.pm libnet-dbus-perl-0.33.6/lib/Net/DBus/Binding/Introspector.pm
--- libnet-dbus-perl-0.33.6.orig/lib/Net/DBus/Binding/Introspector.pm 2008-02-21 01:26:44.000000000 +0100
+++ libnet-dbus-perl-0.33.6/lib/Net/DBus/Binding/Introspector.pm 2009-04-14 19:42:02.112396715 +0200
@@ -209,14 +209,20 @@
my $self = shift;
my $name = shift;
- my @interfaces;
- foreach my $interface (keys %{$self->{interfaces}}) {
- if (exists $self->{interfaces}->{$interface}->{methods}->{$name}) {
- push @interfaces, $interface;
+ if (@_) {
+ my $interface = shift;
+ return () unless exists $self->{interfaces}->{$interface};
+ return () unless exists $self->{interfaces}->{$interface}->{methods}->{$name};
+ return ($interface);
+ } else {
+ my @interfaces;
+ foreach my $interface (keys %{$self->{interfaces}}) {
+ if (exists $self->{interfaces}->{$interface}->{methods}->{$name}) {
+ push @interfaces, $interface;
+ }
}
+ return @interfaces;
}
-
- return @interfaces;
}
=item my @interfaces = $ins->has_signal($name)
diff -uraN libnet-dbus-perl-0.33.6.orig/lib/Net/DBus/Exporter.pm libnet-dbus-perl-0.33.6/lib/Net/DBus/Exporter.pm
--- libnet-dbus-perl-0.33.6.orig/lib/Net/DBus/Exporter.pm 2008-02-21 01:26:44.000000000 +0100
+++ libnet-dbus-perl-0.33.6/lib/Net/DBus/Exporter.pm 2009-04-14 19:41:18.452156966 +0200
@@ -240,7 +240,7 @@
package Net::DBus::Exporter;
-use vars qw(@ISA @EXPORT %dbus_exports %dbus_introspectors);
+use vars qw(@ISA @EXPORT %dbus_exports %dbus_introspectors $dbus_strict_exports);
use Net::DBus::Binding::Introspector;
@@ -250,7 +250,7 @@
use Exporter;
@ISA = qw(Exporter);
-@EXPORT = qw(dbus_method dbus_signal dbus_property);
+@EXPORT = qw(dbus_method dbus_signal dbus_property dbus_strict_exports);
sub import {
@@ -400,6 +400,22 @@
$dbus_exports{$caller}->{methods}->{$name} = [$params, $returns, $interface, \%attributes, $param_names, $return_names];
}
+=item dbus_strict_exports();
+
+Restricts calls to only methods already exported through C<dbus_method>.
+When not using this method, by default any method call will be allowed.
+
+Method calls will be also restricted according to the used interface.
+
+=cut
+
+sub dbus_strict_exports {
+ $dbus_strict_exports = 1;
+}
+
+sub _has_dbus_strict_exports {
+ return $dbus_strict_exports;
+}
=item dbus_property($name, $type, $access, [\%attributes]);
diff -uraN libnet-dbus-perl-0.33.6.orig/lib/Net/DBus/Object.pm libnet-dbus-perl-0.33.6/lib/Net/DBus/Object.pm
--- libnet-dbus-perl-0.33.6.orig/lib/Net/DBus/Object.pm 2008-02-21 01:26:44.000000000 +0100
+++ libnet-dbus-perl-0.33.6/lib/Net/DBus/Object.pm 2009-04-14 19:42:37.060397087 +0200
@@ -488,7 +488,7 @@
} elsif ($method_name eq "Set") {
$reply = $self->_dispatch_prop_write($connection, $message);
}
- } elsif ($self->can($method_name)) {
+ } elsif (Net::DBus::Exporter::_has_dbus_strict_exports() ? $self->_introspector->has_method($method_name, $interface) : $self->can($method_name)) {
my $ins = $self->_introspector;
my @ret = eval {
my @args;