4

I need to launch gphoto2 from a Qt program. I do this:

QString gphotoProgram = "/usr/bin/gphoto2";
QStringList gphotoArguments;
gphotoArguments << "--capture-image";
QProcess *gphotoProcess = new QProcess(this);
gphotoProcess->start(gphotoProgram, gphotoArguments);

but it never enters the Running state this way, as gphoto2 usually needs admin rights to be launched on command line.

How can I start this QProcess with proper rights to make gphoto2 working?

Edit: I precise that I would prefer the user to not have to enter a password, which means gksudo, kdesudo or any other graphical solution is not a valid option for me.

Stéphane Péchard
  • 2,013
  • 3
  • 22
  • 35

4 Answers4

2

I would strongly recommend finding a way to allow gphoto2 to be run with the logged in user's permissions. Perhaps this article has some helpful info.

Arnold Spence
  • 21,942
  • 7
  • 74
  • 67
  • This page was helpful indeed, thanks a lot! For the posterity, here is the needed command line to do to enable any user of the group plugdev: /usr/lib/libgphoto2/print-camera-list udev-rules version 0.98 group plugdev mode 0660 > /etc/udev/rules.d/90-libgphoto2.rules – Stéphane Péchard Apr 14 '11 at 18:34
1

If you have a distribution with sudo enabled, try to add "gksudo" to the command line of your process:

QString gphotoProgram = "gksudo /usr/bin/gphoto2"

If the user account is authorized as a sudo-er, it will ask the user password so that the program can run with root rights.

Gabriel Cuvillier
  • 3,617
  • 1
  • 28
  • 35
  • I forgot to precise that I would prefer not to use a graphical interface to enter a password, as the user may not know it. I edited the question accordingly. – Stéphane Péchard Apr 11 '11 at 19:35
  • If the security mechanism demands a password (and most often it does), you won't be able to bypass that. – Frank Osterfeld Apr 11 '11 at 20:26
  • If you want to bypass the password authentication, the only way to do it is to set up a background process with root privileges (daemon, server, etc.) wrapping your gphoto2 needs. Your application just have to communicate with the server with a socket. But I think it is a bad idea, as it is an open gate to security problems... Maybe you should try to understand why admin rigths are needed, and if there is some alternatives to that. – Gabriel Cuvillier Apr 11 '11 at 20:38
  • ... as a side note, I think that if gphoto needs admin rights, it is because it is using USB devices directly, and access rights must be set correctly for them. Have a look at the following page: http://www.gphoto.org/doc/manual/permissions-usb.html , and see if you can configure things so that no root privilege is needed for USB cameras – Gabriel Cuvillier Apr 11 '11 at 20:44
1

You can also use PolicyKit to start QProcess with sudo rights.

pkexec command

QString gphotoProgram = "pkexec /usr/bin/gphoto2";

smitrp
  • 1,292
  • 1
  • 12
  • 28
0

Don't GNOME and KDE still have their own graphical sudo wrappers? (I'm a Windows guy myself.) You could use QProcess to launch "sudo" and let it take care of the elevation and subsequent gphoto launch.

ChrisV
  • 3,363
  • 16
  • 19
  • I forgot to precise that I would prefer not to use a graphical interface to enter a password, as the user may not know it. I edited the question accordingly. – Stéphane Péchard Apr 11 '11 at 19:36