Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-02

run program in ide with sudo for debug purpose

26 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

ik

Hello,

I'm trying to debug a program that I'm writing with Lazarus, and it require root privileges, but I do not want Lazarus to run as root, only the program itself for debug.

How can I do that ?

Thanks,
Ido

Reply by email

Martin
to ik
ik wrote 8 lines
Hello, I'm trying to debug a program that I'm writing with Lazarus, and it require root privileges, but I do not want Lazarus to run as root, only the program itself for debug. How can I do that ?

I have not tried it, but maybe if you replace "/usr/bin/gdb" (in the IDE opions dialog) with "sudo /usr/bin/gdb" ?

Of course that affects all projects.

But afaik you can't use a starter app , because then gdb will attempt to debug the starter app....

Reply by email

zeljko
to Martin
Martin wrote 13 lines
On 26/02/2012 12:38, ik wrote: > Hello, > > I'm trying to debug a program that I'm writing with Lazarus, and it > require root privileges, but I do not want Lazarus to run as root, > only the program itself for debug. > > How can I do that ? I have not tried it, but maybe if you replace "/usr/bin/gdb" (in the IDE opions dialog) with "sudo /usr/bin/gdb" ? Of course that affects all projects.

Yes, but sudo can ask for password ,so he'll be stucked there I think.

zeljko
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120226/d4d58a59/attachment.html>

Reply by email

ik
to zeljko
zeljko wrote 30 lines
On Sunday 26 of February 2012 13:49:08 Martin wrote: > On 26/02/2012 12:38, ik wrote: > > Hello, > > > > I'm trying to debug a program that I'm writing with Lazarus, and it > > require root privileges, but I do not want Lazarus to run as root, > > only the program itself for debug. > > > > How can I do that ? > > I have not tried it, but maybe if you replace "/usr/bin/gdb" (in the IDE > opions dialog) with "sudo /usr/bin/gdb" ? > > Of course that affects all projects. Yes, but sudo can ask for password ,so he'll be stucked there I think.

Treid to use kdesu but got the following:

The debugger "/usr/bin/kdesu /usr/bin/gdb"
does not exist or is not executable.

See Tools -> Options -> Debugger options

Show quoted text 11 lines
zeljko -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Mark Morgan Lloyd
to Martin: I have not tried it, but maybe if you replace "/usr/bin/gdb" (in the IDE opions dialog)…
Martin wrote 17 lines
On 26/02/2012 12:38, ik wrote: > Hello, > > I'm trying to debug a program that I'm writing with Lazarus, and it > require root privileges, but I do not want Lazarus to run as root, > only the program itself for debug. > > How can I do that ? > I have not tried it, but maybe if you replace "/usr/bin/gdb" (in the IDE opions dialog) with "sudo /usr/bin/gdb" ? Of course that affects all projects. But afaik you can't use a starter app , because then gdb will attempt to debug the starter app....

I've had this sort of requirement in the past, specifically when using libusb (i.e. the program needed sufficient privilege to grab the device).

I wonder whether setting either Lazarus or gdb setuid root would help?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

ik
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 26 lines
Martin wrote: > > On 26/02/2012 12:38, ik wrote: >> >> Hello, >> >> I'm trying to debug a program that I'm writing with Lazarus, and it >> require root privileges, but I do not want Lazarus to run as root, >> only the program itself for debug. >> >> How can I do that ? >> > > I have not tried it, but maybe if you replace "/usr/bin/gdb" (in the IDE > opions dialog) with "sudo /usr/bin/gdb" ? > > Of course that affects all projects. > > But afaik you can't use a starter app , because then gdb will attempt to > debug the starter app.... I've had this sort of requirement in the past, specifically when using libusb (i.e. the program needed sufficient privilege to grab the device). I wonder whether setting either Lazarus or gdb setuid root would help?

That's scars me a lot. Because it means that every program that is using gdb can raise it's privileges to root.
I think that a better way, will be to set per project if the program should have different privileges for running inside Lazarus, and if so, then to use tools such as kdesu for example.

Show quoted text 13 lines
-- Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues] -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

zeljko
to ik
ik wrote 5 lines
That's scars me a lot. Because it means that every program that is using gdb can raise it's privileges to root. I think that a better way, will be to set per project if the program should have different privileges for running inside Lazarus, and if so, then to use tools such as kdesu for example.

workaround is to use gdb from console :)

zeljko

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120226/5db44869/attachment.html>

Reply by email

Martin
to ik: Treid to use kdesu but got the following: The debugger "/usr/bin/kdesu /usr/bin/gdb" does…
ik wrote 11 lines
On Sun, Feb 26, 2012 at 15:05, zeljko wrote: > On Sunday 26 of February 2012 13:49:08 Martin wrote: >> I have not tried it, but maybe if you replace "/usr/bin/gdb" (in the IDE >> opions dialog) with "sudo /usr/bin/gdb" ? Treid to use kdesu but got the following: The debugger "/usr/bin/kdesu /usr/bin/gdb" does not exist or is not executable. See Tools -> Options -> Debugger options

Maybe a script/ that contains that line? but it must forward the commandline param

Otherwise, I don't have an idea.

There is no build in solution for this

Reply by email

Henry Vermaak
to Mark Morgan Lloyd: I've had this sort of requirement in the past, specifically when using libusb (i.e. the…
Mark Morgan Lloyd wrote 21 lines
Martin wrote: > On 26/02/2012 12:38, ik wrote: >> Hello, >> >> I'm trying to debug a program that I'm writing with Lazarus, and it >> require root privileges, but I do not want Lazarus to run as root, >> only the program itself for debug. >> >> How can I do that ? >> > > I have not tried it, but maybe if you replace "/usr/bin/gdb" (in the > IDE opions dialog) with "sudo /usr/bin/gdb" ? > > Of course that affects all projects. > > But afaik you can't use a starter app , because then gdb will attempt > to debug the starter app.... I've had this sort of requirement in the past, specifically when using libusb (i.e. the program needed sufficient privilege to grab the device).

You need udev rules that set the user/group permissions for the devices that you use. You don't need to run as root.

Henry

Reply by email

Mark Morgan Lloyd
to Henry Vermaak
Henry Vermaak wrote 7 lines
On 26/02/12 13:29, Mark Morgan Lloyd wrote: > I've had this sort of requirement in the past, specifically when using > libusb (i.e. the program needed sufficient privilege to grab the device). You need udev rules that set the user/group permissions for the devices that you use. You don't need to run as root.

I'd be happy to be proven wrong, but my understanding is that you do since there is one specific kernel call (in effect, telling the kernel to release an unrecognised device to an unprivileged program) that won't work otherwise.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

ik
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 17 lines
Henry Vermaak wrote: > > On 26/02/12 13:29, Mark Morgan Lloyd wrote: >> I've had this sort of requirement in the past, specifically when using >> libusb (i.e. the program needed sufficient privilege to grab the device). > > > You need udev rules that set the user/group permissions for the devices > that you use. ?You don't need to run as root. I'd be happy to be proven wrong, but my understanding is that you do since there is one specific kernel call (in effect, telling the kernel to release an unrecognised device to an unprivileged program) that won't work otherwise.

Close, I'm using libraries that talk with kernel space, and require root access to work, and it's not a GUI application.

Show quoted text 13 lines
-- Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues] -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Sven Barth
to Mark Morgan Lloyd: I'd be happy to be proven wrong, but my understanding is that you do since there is one…
Mark Morgan Lloyd wrote 15 lines
Henry Vermaak wrote: > On 26/02/12 13:29, Mark Morgan Lloyd wrote: >> I've had this sort of requirement in the past, specifically when using >> libusb (i.e. the program needed sufficient privilege to grab the >> device). > > You need udev rules that set the user/group permissions for the > devices that you use. You don't need to run as root. I'd be happy to be proven wrong, but my understanding is that you do since there is one specific kernel call (in effect, telling the kernel to release an unrecognised device to an unprivileged program) that won't work otherwise.

I already managed the following some time ago for a scanner that was not supported by SANE:
* setup a Windows VM in QEMU
* tell QEMU to pass the scanner to the VM

If I now started the VM I became a "permission denied" error when it tried to open the corresponding dev node. Now I simply changed (at that time without udev rules, because they somehow didn't work as I wanted them to) the group of the corresponding device file (/dev/usb/{bus}/{device}) to a group my user is part of and Tada! it worked. So no, you don't need Root access for an unrecognized device.

Regards,
Sven

Reply by email

Henry Vermaak
to Mark Morgan Lloyd: I'd be happy to be proven wrong, but my understanding is that you do since there is one…
Mark Morgan Lloyd wrote 14 lines
Henry Vermaak wrote: > On 26/02/12 13:29, Mark Morgan Lloyd wrote: >> I've had this sort of requirement in the past, specifically when using >> libusb (i.e. the program needed sufficient privilege to grab the >> device). > > You need udev rules that set the user/group permissions for the > devices that you use. You don't need to run as root. I'd be happy to be proven wrong, but my understanding is that you do since there is one specific kernel call (in effect, telling the kernel to release an unrecognised device to an unprivileged program) that won't work otherwise.

You need root permissions because libusb accesses the file /dev/bus/usb/%d/%d. The default permissions to these files are restricted to root by default, so udev is used so that known devices can be used by less-privileged users. E.g. usb printers, which will set the group to "lp" on my system (Debian). This is what I use at work for development with a Cypress FX2 board:

hcv at technical09:~$ lsusb
...
Bus 001 Device 003: ID 04b4:8613 Cypress Semiconductor Corp. CY7C68013 EZ-USB FX2 USB 2.0 Development Kit
...

hcv at technical09:~$ ls -l /dev/bus/usb/001/
total 0
crw-rw-r-- 1 root root 189, 0 Feb 27 09:15 001
crw-rw-r-- 1 root plugdev 189, 2 Feb 27 10:26 003

hcv at technical09:~$ cat /etc/udev/rules.d/55-hcv.rules ATTRS{idVendor}=="04b4", ATTRS{idProduct}=="8613", MODE="0664", GROUP="plugdev"

I belong to the "plugdev" group, so I can use the device without running as root.

Henry

Reply by email

Mark Morgan Lloyd
to Sven Barth: I already managed the following some time ago for a scanner that was not supported by…
Sven Barth wrote 19 lines
Am 27.02.2012 11:07, schrieb Mark Morgan Lloyd: > I'd be happy to be proven wrong, but my understanding is that you do > since there is one specific kernel call (in effect, telling the kernel > to release an unrecognised device to an unprivileged program) that won't > work otherwise. > I already managed the following some time ago for a scanner that was not supported by SANE: * setup a Windows VM in QEMU * tell QEMU to pass the scanner to the VM If I now started the VM I became a "permission denied" error when it tried to open the corresponding dev node. Now I simply changed (at that time without udev rules, because they somehow didn't work as I wanted them to) the group of the corresponding device file (/dev/usb/{bus}/{device}) to a group my user is part of and Tada! it worked. So no, you don't need Root access for an unrecognized device.

The reason it didn't work as expected might have been because the insertion of otherwise-unrecognised devices in /dev/usb is a comparatively recent feature. Checking, it's not in 2.6.18 (Debian Etch) but is in 2.6.32 (Debian Lenny). Allow for a few kernel steppings for it to actually /work/ :-)

But to make those changes (and were they in the host or the guest?) you needed root access. So you've moved the problem rather than fixing it permanently.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Mark Morgan Lloyd
to Henry Vermaak: You need root permissions because libusb accesses the file /dev/bus/usb/%d/%d. The…
Henry Vermaak wrote 31 lines
On 27/02/12 10:07, Mark Morgan Lloyd wrote: > I'd be happy to be proven wrong, but my understanding is that you do > since there is one specific kernel call (in effect, telling the kernel > to release an unrecognised device to an unprivileged program) that won't > work otherwise. You need root permissions because libusb accesses the file /dev/bus/usb/%d/%d. The default permissions to these files are restricted to root by default, so udev is used so that known devices can be used by less-privileged users. E.g. usb printers, which will set the group to "lp" on my system (Debian). This is what I use at work for development with a Cypress FX2 board: hcv at technical09:~$ lsusb ... Bus 001 Device 003: ID 04b4:8613 Cypress Semiconductor Corp. CY7C68013 EZ-USB FX2 USB 2.0 Development Kit ... hcv at technical09:~$ ls -l /dev/bus/usb/001/ total 0 crw-rw-r-- 1 root root 189, 0 Feb 27 09:15 001 crw-rw-r-- 1 root plugdev 189, 2 Feb 27 10:26 003 hcv at technical09:~$ cat /etc/udev/rules.d/55-hcv.rules ATTRS{idVendor}=="04b4", ATTRS{idProduct}=="8613", MODE="0664", GROUP="plugdev" I belong to the "plugdev" group, so I can use the device without running as root.

Thanks for the example.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Henry Vermaak
to Mark Morgan Lloyd: The reason it didn't work as expected might have been because the insertion of…
Mark Morgan Lloyd wrote 5 lines
The reason it didn't work as expected might have been because the insertion of otherwise-unrecognised devices in /dev/usb is a comparatively recent feature. Checking, it's not in 2.6.18 (Debian Etch) but is in 2.6.32 (Debian Lenny). Allow for a few kernel steppings for it to actually /work/ :-)

The wiki page says it will work as far back as 2.6.13. Before then, "hotplug" was used, but don't ask me how that worked :)

Reply by email

Mark Morgan Lloyd
to Henry Vermaak
Henry Vermaak wrote 9 lines
On 27/02/12 11:13, Mark Morgan Lloyd wrote: > The reason it didn't work as expected might have been because the > insertion of otherwise-unrecognised devices in /dev/usb is a > comparatively recent feature. Checking, it's not in 2.6.18 (Debian Etch) > but is in 2.6.32 (Debian Lenny). Allow for a few kernel steppings for it > to actually /work/ :-) The wiki page says it will work as far back as 2.6.13. Before then, "hotplug" was used, but don't ask me how that worked :)

It might be in 2.6.13, but testing on a Debian SPARC Etch with 2.6.18 didn't so it might not have been enabled as standard until later.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Henry Vermaak
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 13 lines
Henry Vermaak wrote: > On 27/02/12 11:13, Mark Morgan Lloyd wrote: >> The reason it didn't work as expected might have been because the >> insertion of otherwise-unrecognised devices in /dev/usb is a >> comparatively recent feature. Checking, it's not in 2.6.18 (Debian Etch) >> but is in 2.6.32 (Debian Lenny). Allow for a few kernel steppings for it >> to actually /work/ :-) > > The wiki page says it will work as far back as 2.6.13. Before then, > "hotplug" was used, but don't ask me how that worked :) It might be in 2.6.13, but testing on a Debian SPARC Etch with 2.6.18 didn't so it might not have been enabled as standard until later.

That's probably the case. They are quite conservative with new features!

Henry

Reply by email

Mark Morgan Lloyd
to Henry Vermaak: That's probably the case. They are quite conservative with new features! Henry
Henry Vermaak wrote 18 lines
On 27/02/12 11:34, Mark Morgan Lloyd wrote: > Henry Vermaak wrote: >> On 27/02/12 11:13, Mark Morgan Lloyd wrote: >>> The reason it didn't work as expected might have been because the >>> insertion of otherwise-unrecognised devices in /dev/usb is a >>> comparatively recent feature. Checking, it's not in 2.6.18 (Debian >>> Etch) >>> but is in 2.6.32 (Debian Lenny). Allow for a few kernel steppings >>> for it >>> to actually /work/ :-) >> >> The wiki page says it will work as far back as 2.6.13. Before then, >> "hotplug" was used, but don't ask me how that worked :) > > It might be in 2.6.13, but testing on a Debian SPARC Etch with 2.6.18 > didn't so it might not have been enabled as standard until later. That's probably the case. They are quite conservative with new features!

:-) Testing on a SPARC Debian Lenny similarly didn't show /dev/usb etc, so it's probably architecture-specific. I've not checked an ARM system- I've got no spare real (i.e. as distinct from Qemu) ARM hardware at the moment.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Sven Barth
to Mark Morgan Lloyd: The reason it didn't work as expected might have been because the insertion of…
Mark Morgan Lloyd wrote 26 lines
Sven Barth wrote: > Am 27.02.2012 11:07, schrieb Mark Morgan Lloyd: >> I'd be happy to be proven wrong, but my understanding is that you do >> since there is one specific kernel call (in effect, telling the kernel >> to release an unrecognised device to an unprivileged program) that won't >> work otherwise. >> > > I already managed the following some time ago for a scanner that was > not supported by SANE: > * setup a Windows VM in QEMU > * tell QEMU to pass the scanner to the VM > > If I now started the VM I became a "permission denied" error when it > tried to open the corresponding dev node. Now I simply changed (at > that time without udev rules, because they somehow didn't work as I > wanted them to) the group of the corresponding device file > (/dev/usb/{bus}/{device}) to a group my user is part of and Tada! it > worked. So no, you don't need Root access for an unrecognized device. The reason it didn't work as expected might have been because the insertion of otherwise-unrecognised devices in /dev/usb is a comparatively recent feature. Checking, it's not in 2.6.18 (Debian Etch) but is in 2.6.32 (Debian Lenny). Allow for a few kernel steppings for it to actually /work/ :-)

At the time I tested this I run a 2.6.40 or so kernel (ArchLinux) so this was definitely not the problem ;) Nevertheless: though the udev rules failed the manual changing of the ownership on the host computer worked.

But to make those changes (and were they in the host or the guest?) you needed root access. So you've moved the problem rather than fixing it permanently.

These changes were on the host and the ownership only needs to be changed once after the scanner was plugged in (udev would have done that automatically, but as I didn't need the scanner that often the manual route was sufficient) otherwise QEMU will complain that it can't open the USB device file.

Note: I did never look why my udev rule didn't work. Today this is no longer important as I now have a scanner that works with SANE.

Also I don't see what you want to imply with "moved the problem". The solution for accessing hardware devices without root access is to change their permissions one way or the other. You can do that either by udev rules, manually or in a startup script which is always run (and is run as root - like /etc/rc.local on ArchLinux) though in the last case the device needs ot be plugged ,
Sven

Reply by email

Mark Morgan Lloyd
to ik: Working with gdbserver can solve this. I'll investigate this issue on the weekend and…
ik wrote 11 lines
On Sun, Feb 26, 2012 at 14:38, ik wrote: > Hello, > > I'm trying to debug a program that I'm writing with Lazarus, and it > require root privileges, but I do not want Lazarus to run as root, > only the program itself for debug. > > How can I do that ? Working with gdbserver can solve this. I'll investigate this issue on the weekend and might send a patch to lazarus to support it

If that would work then would accessing gdb via ssh be an alternative?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

ik
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 18 lines
ik wrote: > > On Sun, Feb 26, 2012 at 14:38, ik wrote: >> >> Hello, >> >> I'm trying to debug a program that I'm writing with Lazarus, and it >> require root privileges, but I do not want Lazarus to run as root, >> only the program itself for debug. >> >> How can I do that ? > > > Working with gdbserver can solve this. I'll investigate this issue on > the weekend and might send a patch to lazarus to support it If that would work then would accessing gdb via ssh be an alternative?

I don't think it's the same. But I guess it is :)

Show quoted text 13 lines
-- Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues] -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

waldo kitty
to Sven Barth: I already managed the following some time ago for a scanner that was not supported by…
Sven Barth wrote 16 lines
> I'd be happy to be proven wrong, but my understanding is that you do > since there is one specific kernel call (in effect, telling the kernel > to release an unrecognised device to an unprivileged program) that won't > work otherwise. I already managed the following some time ago for a scanner that was not supported by SANE: * setup a Windows VM in QEMU * tell QEMU to pass the scanner to the VM If I now started the VM I became a "permission denied" error when it tried to open the corresponding dev node. Now I simply changed (at that time without udev rules, because they somehow didn't work as I wanted them to) the group of the corresponding device file (/dev/usb/{bus}/{device}) to a group my user is part of and Tada! it worked. So no, you don't need Root access for an unrecognized device.

why not just add your user(s) to that group the device was in? this would/should give the same access capabilities... or am i missing something else?

Reply by email

Sven Barth
to waldo kitty
waldo kitty wrote 26 lines
On 2/27/2012 05:11, Sven Barth wrote: >> I'd be happy to be proven wrong, but my understanding is that you do >> since there is one specific kernel call (in effect, telling the kernel >> to release an unrecognised device to an unprivileged program) that won't >> work otherwise. > > I already managed the following some time ago for a scanner that was not > supported by SANE: > * setup a Windows VM in QEMU > * tell QEMU to pass the scanner to the VM > > If I now started the VM I became a "permission denied" error when it > tried to > open the corresponding dev node. Now I simply changed (at that time > without udev > rules, because they somehow didn't work as I wanted them to) the group > of the > corresponding device file (/dev/usb/{bus}/{device}) to a group my user > is part > of and Tada! it worked. So no, you don't need Root access for an > unrecognized > device. why not just add your user(s) to that group the device was in? this would/should give the same access capabilities... or am i missing something else?

The USB device files are by default created with root:root. I changed the one of my scanner to root:plugdev by hand (and yes, my user belongs to plugdev ;) )

Regards,
Sven

Reply by email

waldo kitty
to Sven Barth
Sven Barth wrote 7 lines
Am 27.02.2012 16:06, schrieb waldo kitty: > why not just add your user(s) to that group the device was in? this > would/should give the same access capabilities... or am i missing > something else? The USB device files are by default created with root:root. I changed the one of my scanner to root:plugdev by hand (and yes, my user belongs to plugdev ;) )

ahhh! yes, i remember similar messes i dug into a while back... i should have remembered before writing...

Reply by email