* Boston, MA 02111-1307, USA.
*/
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include <gio/gio.h>
#include "ibusbus.h"
#include "ibusinternal.h"
static void
ibus_bus_init (IBusBus *bus)
{
- gchar *path;
+ struct stat buf;
+ const gchar *path;
GFile *file;
+
IBusBusPrivate *priv;
priv = IBUS_BUS_GET_PRIVATE (bus);
priv->connection = NULL;
priv->watch_dbus_signal = FALSE;
- ibus_bus_connect (bus);
-
path = ibus_get_socket_folder ();
- mkdir (path, 0700);
- chmod (path, 0700);
+
+ if (stat (path, &buf) == 0) {
+ if (buf.st_uid != ibus_get_daemon_uid ()) {
+ g_debug ("%ld %ld", buf.st_uid, ibus_get_daemon_uid ());
+ g_warning ("The owner of %s is not %s!", path, ibus_get_user_name ());
+ return;
+ }
+ }
+ else {
+ if (getuid () == ibus_get_daemon_uid ()) {
+ mkdir (path, 0700);
+ chmod (path, 0700);
+ }
+ }
+
+ ibus_bus_connect (bus);
file = g_file_new_for_path (path);
dbus_error_init (&error);
dbus_connection = dbus_connection_open (address, &error);
if (dbus_connection == NULL) {
- g_warning ("Connect to %s failed. %s.", address, error.message);
+ g_warning ("Connect to %s failed: %s.", address, error.message);
dbus_error_free (&error);
return NULL;
}
return username;
}
+glong
+ibus_get_daemon_uid (void)
+{
+ struct passwd *pwd;
+ uid_t uid;
+ const gchar *username;
+
+ uid = getuid ();
+
+ if (uid != 0)
+ return uid;
+
+ username = ibus_get_user_name ();
+ if (username == NULL)
+ return 0;
+
+ pwd = getpwnam (username);
+ if (pwd == NULL)
+ return 0;
+
+ return pwd->pw_uid;
+}
+
const gchar *
ibus_get_session_id (void)
{
void ibus_set_display (const gchar *display);
const gchar *ibus_get_address (void);
const gchar *ibus_get_user_name (void);
+glong ibus_get_daemon_uid (void);
const gchar *ibus_get_socket_path (void);
const gchar *ibus_get_socket_folder (void);