This email list is read-only. Emails sent to this list will be discarded
----------------------------------
ChangeLog | 9 +++++++
mconf/Makefile.am | 8 +++---
mconf/mconf-dbus.c | 60 +++++++++++++++++++++++++++++++++++++++++++++-------
mconf/mconf-dbus.h | 1 +
mconf/mconf-tool.c | 2 +-
mconf/mconfd.c | 48 +++++++++++++++++++++++++++++++++++++++-
scripts/mconf.spec | 4 +-
7 files changed, 115 insertions(+), 17 deletions(-)
New commits:
commit aab1c7e76e632025d8e9625dc85fe88fdddb03fc
Author: Todd Brandt <[EMAIL PROTECTED]>
Date: Thu Sep 18 07:06:20 2008 -0700
application name extraction added
Diff in this email is a maximum of 400 lines.
diff --git a/ChangeLog b/ChangeLog
index 5de1e2d..8c2cda7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+mconf (1.2)
+
+ * Added PolicyKit control to the interface
+ * Added code which established the application executable name
+ from the DBusMesssage contents
+ * Added the .mconf folder to the user's home directory
+
+ -- Todd Brandt <[EMAIL PROTECTED]> Thu Sep 18 07:04:55 PDT 2008
+
mconf (1.1)
* Added function stubs for the new interface
diff --git a/mconf/Makefile.am b/mconf/Makefile.am
index fecd137..bcbe5fa 100644
--- a/mconf/Makefile.am
+++ b/mconf/Makefile.am
@@ -2,19 +2,19 @@ SUBDIRS =
DIST_SUBDIRS =
bin_PROGRAMS=mconf-tool
-sbin_PROGRAMS=mconf
+sbin_PROGRAMS=mconfd
INCLUDES= $(MCONF_CFLAGS)
mconf_tool_SOURCES = mconf-tool.c
mconf_tool_LDADD = $(MCONF_LIBS)
-mconf_SOURCES = \
+mconfd_SOURCES = \
mconfd.c \
keymanager.c keymanager.h \
mconf-dbus.c mconf-dbus.h
-mconf_LDADD = \
+mconfd_LDADD = \
$(MCONF_LIBS)
BUILT_SOURCES=mconf-server.h \
@@ -22,7 +22,7 @@ BUILT_SOURCES=mconf-server.h \
mconf-marshal.h \
mconf-marshal.c
-mconf_SOURCES+=$(BUILT_SOURCES)
+mconfd_SOURCES+=$(BUILT_SOURCES)
Dbusapidir = $(includedir)/moblin-2.0/mconf
Dbusapi_DATA = mconf-client.h
diff --git a/mconf/mconf-dbus.c b/mconf/mconf-dbus.c
index 98c6737..615f042 100644
--- a/mconf/mconf-dbus.c
+++ b/mconf/mconf-dbus.c
@@ -24,6 +24,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <errno.h>
#include <ctype.h>
#include "mconf-dbus.h"
#include "mconf-marshal.h"
@@ -70,6 +71,22 @@ mconf_server_class_init (MconfServerClass * klass)
object_class->constructor = mconf_server_constructor;
}
+static DBusHandlerResult dbus_filter_callback(DBusConnection*, DBusMessage*,
void*);
+
+static gboolean
+init_security_filter(MconfServer * server)
+{
+ DBusConnection *connection;
+
+ if(server->connection == NULL) return FALSE;
+ connection =
+ dbus_g_connection_get_connection(server->connection);
+ dbus_connection_setup_with_g_main(connection, NULL);
+ dbus_connection_add_filter(connection,
+ dbus_filter_callback, server, NULL);
+ return TRUE;
+}
+
static gboolean
init_polkit(MconfServer * server)
{
@@ -117,7 +134,7 @@ init_dbus(void *svr)
if(server->connection != NULL) return TRUE;
/* Init the DBus connection, per-server */
- server->connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ server->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (server->connection == NULL) {
PRINTF("Unable to connect to dbus: %s\n",
error->message);
@@ -126,6 +143,7 @@ init_dbus(void *svr)
}
if(!init_polkit(server)) return FALSE;
+ if(!init_security_filter(server)) return FALSE;
/* &dbus_glib__object_info is provided in the server-bindings.h file */
dbus_g_object_type_install_info (MCONF_TYPE_SERVER,
@@ -133,7 +151,7 @@ init_dbus(void *svr)
/* Register DBUS path */
dbus_g_connection_register_g_object (server->connection,
- "/org/moblin/SystemDaemon",
+ "/org/moblin/mconf",
G_OBJECT (server));
/* Register the service name, the constant here are defined in
dbus-glib-bindings.h */
@@ -142,15 +160,16 @@ init_dbus(void *svr)
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
+ server->proxy = driver_proxy;
+
if (!org_freedesktop_DBus_request_name
- (driver_proxy, "org.moblin.SystemDaemon", 0, &request_ret,
+ (driver_proxy, "org.moblin.mconf", 0, &request_ret,
&error)) {
PRINTF("Unable to register service: %s\n", error->message);
g_error_free (error);
return FALSE;
}
- g_object_unref (driver_proxy);
return TRUE;
}
@@ -164,7 +183,30 @@ mconf_server_init (MconfServer * server)
}
}
-#if 0
+gboolean
+get_app_name(MconfServer *server, const gchar *sender)
+{
+unsigned int pid;
+int sz;
+GError *error = NULL;
+char pfname[100], link[1000];
+
+ if(!org_freedesktop_DBus_get_connection_unix_process_id(server->proxy,
+ sender, &pid, &error))
+ {
+ g_error_free(error);
+ return FALSE;
+ }
+ sprintf(pfname, "/proc/%u/exe", pid);
+ if((sz = readlink(pfname, link, 1000)) < 0) {
+ PRINTF("%s read failure: %s\n", pfname, strerror(errno));
+ return FALSE;
+ }
+ link[sz] = '\0';
+ PRINTF("application is %s\n", link);
+ return TRUE;
+}
+
static void
create_action(char *action, const char *iface, const char *member)
{
@@ -207,7 +249,7 @@ char action[512];
#endif
return DBUS_HANDLER_RESULT_HANDLED;
} else
if((dbus_message_get_type(message)==DBUS_MESSAGE_TYPE_METHOD_CALL)&&
- dbus_message_has_interface(message, "org.moblin.SystemDaemon"))
+ dbus_message_has_interface(message, "org.moblin.mconf"))
{
dbus_error_init(&error);
sender = dbus_message_get_sender(message);
@@ -221,6 +263,9 @@ char action[512];
if((sender == NULL)||(iface == NULL)||(member == NULL)) {
PRINTF("Unidentified message received, permission denied\n");
pk_result = POLKIT_RESULT_NO;
+ } else if(!get_app_name(server, sender)) {
+ PRINTF("Could not identify the application, permission
denied\n");
+ pk_result = POLKIT_RESULT_NO;
} else if((pk_action = polkit_action_new()) == NULL) {
PRINTF("polkit_action_new failed, memory issues...\n");
pk_result = POLKIT_RESULT_NO;
@@ -254,7 +299,7 @@ char action[512];
PRINTF("CALL DENIED: iface=%s mem=%s snd=%s uid=%d\n",
iface, member, sender, uid);
reply = dbus_message_new_error(message,
- "org.moblin.SystemDaemon.PermissionDenied",
+ "org.moblin.mconf.PermissionDenied",
"You do not have permission to call this method");
if(reply == NULL)
{
@@ -273,4 +318,3 @@ char action[512];
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-#endif
diff --git a/mconf/mconf-dbus.h b/mconf/mconf-dbus.h
index 622e71b..b4cdf52 100644
--- a/mconf/mconf-dbus.h
+++ b/mconf/mconf-dbus.h
@@ -56,6 +56,7 @@ struct MconfServer {
DBusGConnection *connection;
PolKitContext *pk_context;
PolKitTracker *pk_tracker;
+ DBusGProxy *proxy;
};
struct MconfServerClass {
diff --git a/mconf/mconf-tool.c b/mconf/mconf-tool.c
index 1916ddc..0083ece 100644
--- a/mconf/mconf-tool.c
+++ b/mconf/mconf-tool.c
@@ -18,7 +18,7 @@ activate_mconf (void)
{
GError *error = NULL;
- connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (connection == NULL)
{
g_warning("Failed to get dbus connection\n");
diff --git a/mconf/mconfd.c b/mconf/mconfd.c
index a4303fa..048b4e8 100644
--- a/mconf/mconfd.c
+++ b/mconf/mconfd.c
@@ -4,6 +4,7 @@
#include <stdio.h>
#include <errno.h>
+#include <dirent.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
@@ -16,11 +17,11 @@
#include "mconfd.h"
#ifdef LOGDEBUG
-#define LOGFILE "/var/log/mconfd"
FILE *logfp = NULL;
#endif
GQuark error_quark = 0;
+char *mconf_dir_name = NULL;
static void
sig_handler(int num)
@@ -34,6 +35,41 @@ main(int argc, char *argv[])
{
GMainLoop *loop = NULL;
MconfServer *dbusserver = NULL;
+char *val;
+DIR *dir;
+
+ /* ensure the mconf data folder is available */
+
+ if((val = getenv("HOME")) == NULL)
+ {
+ fprintf(stderr, "%s cannot be run as this user\n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ if((mconf_dir_name = (char *)malloc(strlen(val)+strlen("/.mconf"))) ==
NULL)
+ {
+ fprintf(stderr, "malloc failed: %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ sprintf(mconf_dir_name, "%s/.mconf", val);
+ if((dir = opendir(mconf_dir_name)) == NULL)
+ {
+ if(errno != ENOENT) {
+ fprintf(stderr, "couldn't access %s: %s\n",
+ mconf_dir_name, strerror(errno));
+ exit(EXIT_FAILURE);
+ } else if(mkdir(mconf_dir_name, S_IRWXU)) {
+ fprintf(stderr, "couldn't create %s: %s\n",
+ mconf_dir_name, strerror(errno));
+ exit(EXIT_FAILURE);
+ } else if((dir = opendir(mconf_dir_name)) == NULL) {
+ fprintf(stderr, "couldn't access %s: %s\n",
+ mconf_dir_name, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ }
+ closedir(dir);
+
+ /* daemonize the process */
switch(fork()) {
case -1:
@@ -57,12 +93,20 @@ MconfServer *dbusserver = NULL;
loop = g_main_loop_new(NULL,FALSE);
#ifdef LOGDEBUG
- if((logfp = fopen(LOGFILE, "w")) == NULL)
+ if((val = (char *)malloc(strlen(mconf_dir_name)+strlen("/mconfd.log")))
== NULL)
+ {
+ fprintf(stderr, "malloc failed: %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ sprintf(val, "%s/mconfd.log", mconf_dir_name);
+ if((logfp = fopen(val, "w")) == NULL)
{
fprintf(stderr, "Failed to open the log file\n");
exit(EXIT_FAILURE);
}
setbuf(logfp, NULL);
+ free(val);
+ val = NULL;
#endif
dbusserver = (MconfServer*)g_object_new (mconf_server_get_type (),
NULL);
if(dbusserver == NULL)
diff --git a/scripts/mconf.spec b/scripts/mconf.spec
index 3ffc41f..1fc7957 100644
--- a/scripts/mconf.spec
+++ b/scripts/mconf.spec
@@ -1,6 +1,6 @@
Summary: Moblin System Settings
Name: mconf
-Version: 1.1
+Version: 1.2
Release: 1%{?dist}
URL: http://moblin.org
Source0: http://moblin.org/repos/releases/%{name}-%{version}.tar.gz
@@ -98,7 +98,7 @@ fi
%dir %{_datadir}/dbus-1
%dir %{_datadir}/dbus-1/system-services
-%{_datadir}/dbus-1/system-services/org.moblin.SystemDaemon.service
+%{_datadir}/dbus-1/system-services/org.moblin.mconf.service
%{_sbindir}/mconf
%{_bindir}/moblin-system-tool
%{_mandir}/man1/*
_______________________________________________
Commits mailing list
[email protected]
https://www.moblin.org/mailman/listinfo/commits