Sign in Join

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

Mailing lists / fpc-pascal / 2010-10

Help getting Lazarus app in Ubuntu to elevate to root and back again

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Andrew Brunner

I'm needing help to take my Lazarus app, elevate process to root (using GUI prompt like GKSU) and I want to drop back down to the user's level after port binding and listening.

Ubuntu has port restrictions for low port numbers. I'm developing a platform that happens to use ports for HTTP, XMPP, etc. Unfortunately I find myself running Lazarus as root and that is messing up my units as they are saved.

I need Lazarus to run my app with debugger, and have the desktop system ask me for my password, attach that elevated id by way of that security mechanism to my debugged app, so I can execute my Bind and Listen socket calls, then detach/remove that elevated status to normal.

Anyone with code to do this very thing?  I this to be cross-platform
so ppl with KDE instead of Gnome need to be considered.
Example Code:
procedure DebugServices;
begin
   ElevateToRootStatus; // << Gets Ubuntu to prompt for Desktop system
to elevate CurrentProcess
   StartServices;
   DropRootStatus;
end;

Under normal circumstances I could just launch gksu in front of my app. But I'm under Lazarus with debugger so I need this badly.

Developing ElevateToRootStatus and DropRootStatus is totally unknown how to do this.

Any help would be greatly appreciated.

Reply by email

Sven Barth
to Andrew Brunner
Andrew Brunner wrote 33 lines
I'm needing help to take my Lazarus app, elevate process to root (using GUI prompt like GKSU) and I want to drop back down to the user's level after port binding and listening. Ubuntu has port restrictions for low port numbers. I'm developing a platform that happens to use ports for HTTP, XMPP, etc. Unfortunately I find myself running Lazarus as root and that is messing up my units as they are saved. I need Lazarus to run my app with debugger, and have the desktop system ask me for my password, attach that elevated id by way of that security mechanism to my debugged app, so I can execute my Bind and Listen socket calls, then detach/remove that elevated status to normal. Anyone with code to do this very thing? I this to be cross-platform so ppl with KDE instead of Gnome need to be considered. Example Code: procedure DebugServices; begin ElevateToRootStatus; //<< Gets Ubuntu to prompt for Desktop system to elevate CurrentProcess StartServices; DropRootStatus; end; Under normal circumstances I could just launch gksu in front of my app. But I'm under Lazarus with debugger so I need this badly. Developing ElevateToRootStatus and DropRootStatus is totally unknown how to do this. Any help would be greatly appreciated.

You might want to try PolicyKit.

Overview: http://www.freedesktop.org/wiki/Software/PolicyKit Reference: http://hal.freedesktop.org/docs/PolicyKit/

I can't help you with it though, because I didn't have the need to do
something like that yet.

Regards,
Sven

Reply by email

Mark Morgan Lloyd
to Andrew Brunner: I'm needing help to take my Lazarus app, elevate process to root (using GUI prompt like…
Andrew Brunner wrote 8 lines
I'm needing help to take my Lazarus app, elevate process to root (using GUI prompt like GKSU) and I want to drop back down to the user's level after port binding and listening. Ubuntu has port restrictions for low port numbers. I'm developing a platform that happens to use ports for HTTP, XMPP, etc. Unfortunately I find myself running Lazarus as root and that is messing up my units as they are saved.

Could you suid it to root or to an appropriate group? I've not tried this for a Pascal/Lazarus program and don't know what the precise rules are for port usage (i.e. whether the user has to be root or using the root group is sufficient), but for a C program accessing a video capture device I use

chown root:video v4lgrab
chmod g+s v4lgrab

That then allows the program to be run as part of an unprivileged CGI script.

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

Andrew Brunner
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 10 lines
Could you suid it to root or to an appropriate group? I've not tried this for a Pascal/Lazarus program and don't know what the precise rules are for port usage (i.e. whether the user has to be root or using the root group is sufficient), but for a C program accessing a video capture device I use  chown root:video v4lgrab  chmod g+s v4lgrab That then allows the program to be run as part of an unprivileged CGI script.

I'm presently using gksu ./startlazarus. Though it would be nice if I could use gksu -u myusername ./startlazarus and then have the fpSetUID(0) not fail on me. I made the assumption that gksu would startup lazarus under myusername and not fail any attempts for me to use the setgid or uid to root (because I did use gksu to launch the app). This would have been an ideal solution. But there needs to be one library out there that solves this.

Presently I am just using root :-( Which means it's working but I'm forced to use the root account for my Lazarus instance.

Reply by email