diff options
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | SelfConfig.pm | 72 | ||||
-rw-r--r-- | Users/Users.pm | 35 | ||||
-rw-r--r-- | dispatcher/dispatcher.c | 71 | ||||
-rw-r--r-- | org.freedesktop.SystemToolsBackends.conf | 3 |
5 files changed, 123 insertions, 61 deletions
diff --git a/Makefile.am b/Makefile.am index 70835a0..c2e52f6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -17,7 +17,8 @@ modules_DATA = \ SMBConfig.pm \ TimeConfig.pm \ UserConfig.pm \ - UsersConfig.pm + UsersConfig.pm \ + SelfConfig.pm scripts = \ SystemToolsBackends.pl diff --git a/SelfConfig.pm b/SelfConfig.pm new file mode 100644 index 0000000..4ca751b --- /dev/null +++ b/SelfConfig.pm @@ -0,0 +1,72 @@ +#-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + +# DBus object for self user configuration +# +# Copyright (C) 2009 Milan Bouchet-Valat +# +# Authors: Milan Bouchet-Valat <nalimilan@club.fr>. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Library General Public License as published +# by the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This 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 Library General Public License for more details. +# +# You should have received a copy of the GNU Library 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. + +package SelfConfig; + +use base qw(StbObject); +use Net::DBus::Exporter ($Utils::Backend::DBUS_PREFIX); +use Users::Users; + +my $OBJECT_NAME = "SelfConfig2"; +my $OBJECT_PATH = "$Utils::Backend::DBUS_PATH/$OBJECT_NAME"; + +# user is only allowed to change his own GECOS fields, locale, location +my $format = [ [ "struct", "uint32", [ "array", "string" ], "string", "string" ] ]; + +sub new +{ + my $class = shift; + my $self = $class->SUPER::new ($OBJECT_PATH, $OBJECT_NAME); + + bless $self, $class; + + return $self; +} + +# UID is filled by dispatcher +dbus_method ("get", "uint32", $format); +dbus_method ("set", $format, []); + +sub get +{ + my ($self, $uid) = @_; + + return Users::Users::get_self ($uid); +} + +sub set +{ + my ($self, @config) = @_; + + Users::Users::set_self (@config); +} + +sub getFiles +{ + my ($self) = @_; + + return Users::Users::get_files (); +} + +my $config = SelfConfig->new (); + +1; diff --git a/Users/Users.pm b/Users/Users.pm index 80f982d..8034ce8 100644 --- a/Users/Users.pm +++ b/Users/Users.pm @@ -779,6 +779,20 @@ sub set_logindefs } } +sub get_self +{ + my ($uid) = @_; + my ($users) = &get (); + + foreach $user (@$users) + { + next if ($uid != $$user[$UID]); + return ($$user[$COMMENT], $$user[$LOCALE]); + } + + return ([""], ""); +} + sub get_user { my ($login) = @_; @@ -812,6 +826,27 @@ sub set_user } } +sub set_self +{ + my ($uid, $old_passwd, $new_passwd, @comments) = @_; + my ($users) = &get (); + + # Make backups manually, otherwise they don't get backed up. + &Utils::File::do_backup ($_) foreach (@passwd_names); + &Utils::File::do_backup ($_) foreach (@shadow_names); + + foreach $user (@$users) + { + if ($uid == $$user[$UID]) + { + &change_user_chfn ($$user[$LOGIN], $$user[$COMMENT], @comments); + return; + } + } + # TODO: change password +} + + sub get_files { my ($arr); diff --git a/dispatcher/dispatcher.c b/dispatcher/dispatcher.c index e230d66..62ba9b6 100644 --- a/dispatcher/dispatcher.c +++ b/dispatcher/dispatcher.c @@ -42,7 +42,6 @@ #define DBUS_ADDRESS_ENVVAR "DBUS_SESSION_BUS_ADDRESS" #define DBUS_INTERFACE_STB "org.freedesktop.SystemToolsBackends" #define DBUS_INTERFACE_STB_PLATFORM "org.freedesktop.SystemToolsBackends.Platform" -#define DBUS_PATH_USER_CONFIG "/org/freedesktop/SystemToolsBackends/UserConfig2" #define DBUS_PATH_SELF_CONFIG "/org/freedesktop/SystemToolsBackends/SelfConfig2" #define STB_DISPATCHER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), STB_TYPE_DISPATCHER, StbDispatcherPrivate)) @@ -501,14 +500,12 @@ dispatch_platform_message (StbDispatcher *dispatcher, } static void -dispatch_user_config (StbDispatcher *dispatcher, +dispatch_self_config (StbDispatcher *dispatcher, DBusMessage *message) { StbDispatcherPrivate *priv; - DBusMessageIter iter; - DBusMessage *user_message = NULL; const gchar *sender; - gulong uid; + uid_t uid, message_uid; priv = dispatcher->_priv; sender = dbus_message_get_sender (message); @@ -516,63 +513,17 @@ dispatch_user_config (StbDispatcher *dispatcher, g_return_if_fail (uid != -1); - if (dbus_message_has_member (message, "get")) - { - /* compose the call to UserConfig with the uid of the caller */ - user_message = dbus_message_new_method_call (DBUS_INTERFACE_STB ".UserConfig2", - DBUS_PATH_USER_CONFIG, - DBUS_INTERFACE_STB, - "get"); - dbus_message_iter_init_append (user_message, &iter); - dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &uid); - } - else if (dbus_message_has_member (message, "set")) - { - DBusMessageIter array_iter; - const gchar *passwd; - gchar **gecos; - gint gecos_elements, i; - uid_t message_uid; - - if (dbus_message_get_args (message, NULL, - DBUS_TYPE_UINT32, &message_uid, - DBUS_TYPE_STRING, &passwd, - DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &gecos, &gecos_elements, - DBUS_TYPE_INVALID)) - { - user_message = dbus_message_new_method_call (DBUS_INTERFACE_STB ".UserConfig2", - DBUS_PATH_USER_CONFIG, - DBUS_INTERFACE_STB, - "set"); - - dbus_message_iter_init_append (user_message, &iter); - dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &uid); - dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &passwd); - - /* append gecos array */ - dbus_message_iter_open_container (&iter, - DBUS_TYPE_ARRAY, - DBUS_TYPE_STRING_AS_STRING, - &array_iter); - - for (i = 0; gecos[i]; i++) - dbus_message_iter_append_basic (&array_iter, DBUS_TYPE_STRING, &gecos[i]); - - dbus_message_iter_close_container (&iter, &array_iter); - dbus_free_string_array (gecos); - } - } - else - g_warning ("unsupported method on SelfConfig"); - - if (user_message) + if (dbus_message_get_args (message, NULL, + DBUS_TYPE_UINT32, &message_uid, + DBUS_TYPE_INVALID) + && message_uid == uid) { - dbus_message_set_sender (user_message, sender); - dispatch_stb_message (dispatcher, user_message, dbus_message_get_serial (message)); - dbus_message_unref (user_message); + dbus_message_set_sender (message, sender); + dispatch_stb_message (dispatcher, message, dbus_message_get_serial (message)); + dbus_message_unref (message); } else - return_error (dispatcher, message, DBUS_ERROR_UNKNOWN_METHOD); + return_error (dispatcher, message, DBUS_ERROR_ACCESS_DENIED); } static DBusHandlerResult @@ -597,7 +548,7 @@ dispatcher_filter_func (DBusConnection *connection, else if (dbus_message_has_path (message, DBUS_PATH_SELF_CONFIG)) { if (can_caller_do_action (dispatcher, message, "self")) - dispatch_user_config (dispatcher, message); + dispatch_self_config (dispatcher, message); else return_error (dispatcher, message, DBUS_ERROR_ACCESS_DENIED); } diff --git a/org.freedesktop.SystemToolsBackends.conf b/org.freedesktop.SystemToolsBackends.conf index 52dcc51..319ea51 100644 --- a/org.freedesktop.SystemToolsBackends.conf +++ b/org.freedesktop.SystemToolsBackends.conf @@ -18,6 +18,7 @@ <allow own="org.freedesktop.SystemToolsBackends.TimeConfig"/> <allow own="org.freedesktop.SystemToolsBackends.UserConfig2"/> <allow own="org.freedesktop.SystemToolsBackends.UsersConfig2"/> + <allow own="org.freedesktop.SystemToolsBackends.SelfConfig2"/> <allow own="org.freedesktop.SystemToolsBackends.Platform"/> <allow send_interface="org.freedesktop.SystemToolsBackends.Platform" send_member="getPlatform"/> --> @@ -41,6 +42,7 @@ <allow own="org.freedesktop.SystemToolsBackends.TimeConfig"/> <allow own="org.freedesktop.SystemToolsBackends.UserConfig2"/> <allow own="org.freedesktop.SystemToolsBackends.UsersConfig2"/> + <allow own="org.freedesktop.SystemToolsBackends.SelfConfig2"/> <allow own="org.freedesktop.SystemToolsBackends.Platform"/> <!-- be able to speak to configuration modules, @@ -59,5 +61,6 @@ <allow send_destination="org.freedesktop.SystemToolsBackends.TimeConfig"/> <allow send_destination="org.freedesktop.SystemToolsBackends.UserConfig2"/> <allow send_destination="org.freedesktop.SystemToolsBackends.UsersConfig2"/> + <allow send_destination="org.freedesktop.SystemToolsBackends.SelfConfig2"/> </policy> </busconfig> |