Re: Re: Could connect GVFS session bus from a root privilege program?



Hi Edwin,

not sure that this is still valid, it seems that the email was sent before two months, but I received it today for some reason...

Just a note that it is discouraged to run graphical applications under the root and it is not even possible under Wayland for example!

The problem is that you need session bus for GVfs. So, you have to be sure that DBUS_SESSION_BUS_ADDRESS environment variable is correctly set and also that the EUID of the process is set to the same user as for dbus session (you can achieve this using setuid()).

See also:
https://lists.freedesktop.org/archives/dbus/2010-May/012766.html

Regards

Ondrej



2017-08-18 23:40 GMT+02:00 Edwin De La Cruz <edwinspire gmail com>:
Best regards.
I have a problem with GVFS when trying as root user.
Searching the net on hundreds of pages I have not found a clue to solve it.

Between the pages I found in this mailing list that that problem comes
from years ago.

 Https://mail.gnome.org/archives/gvfs-list/2010-May/msg00000.html

Someone can help me or know how to solve that problem. Thank you all.

##################################################
Hi All,

I have a problem that I need get the information from GVFS(I thought
it is), but the program run as root users.

I use g_volume_monitor_get() to get a monitor for the removable
devices and do something while removable devices connect or
disconnect, it works normally while run as  a plain user but failed
when run as the root user.

How could I do?   Hope for someone give me any clue, and thanks in advance.

Below is my test program.

#include <gio/gio.h>
#include <gtk/gtk.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>

static void print_drive_info(GDrive *drive)
{
    gchar *name;
    name = g_drive_get_name(drive);
    g_print("\tname: %s\n",
        name ? name : "(null)");
    g_free(name);
}

static void on_drive_changed(GVolumeMonitor *volume_monitor, GDrive *drive)
{
    g_print("Drive changed:\n");
    print_drive_info(drive);
}

static void on_drive_connected(GVolumeMonitor *volume_monitor, GDrive *drive)
{
    g_print("Drive connected:\n");
    print_drive_info(drive);
}

static void on_drive_disconnected(GVolumeMonitor *volume_monitor, GDrive *drive)
{
    g_print("Drive disconnected:\n");
    print_drive_info(drive);
}


int main(int argc, char *argv[])
{
    GVolumeMonitor *monitor;
    gtk_init(&argc, &argv);
    #if 0
    /*the following is my test by setting euid */
    int old_uid = getuid();
    int old_euid = geteuid();
    printf("uid is %d \n euid is %d \n",getuid(), geteuid() );
    //if (setuid(500) == -1)
    if (seteuid(500) == -1)
    {
    printf ("seteuid : %s \n", strerror(errno));
    return -1;
    }
    printf("uid is %d \n euid is %d \n",getuid(), geteuid() );
    #endif
    monitor = g_volume_monitor_get();
    g_signal_connect(monitor, "drive-changed",
G_CALLBACK(on_drive_changed), NULL);
    g_signal_connect(monitor, "drive-connected",
G_CALLBACK(on_drive_connected), NULL);
    g_signal_connect(monitor, "drive-disconnected",
G_CALLBACK(on_drive_disconnected), NULL);

    gtk_main();
    return 0;
}


--
 Best Regards,






Mis proyectos de software libre en:
Github - edwinspire
_______________________________________________
gvfs-list mailing list
gvfs-list gnome org
https://mail.gnome.org/mailman/listinfo/gvfs-list



--
Ondrej Holy
Software Engineer, Core Desktop Development
Red Hat Czech s.r.o


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]