public inbox for development@lists.ipfire.org
 help / color / mirror / Atom feed
* Re: Guidelines for creating a C Program launched by a WebGUI page.
       [not found] <EDB740E3-EC57-48D6-8DE7-B29D8C16D82C@ipfire.org>
@ 2025-01-16 21:18 ` Michael Tremer
  0 siblings, 0 replies; only message in thread
From: Michael Tremer @ 2025-01-16 21:18 UTC (permalink / raw)
  To: development

[-- Attachment #1: Type: text/plain, Size: 3086 bytes --]

Hello Jon,

The reason why we are using the C helper programs is to elevate privileges to the root user.

The web UI itself is running as an unprivileged user, but certain actions can only be executed as root; for example launching a service.

Ideally as many actions as possible will be executed as a non-privileged user. In your case, downloading the lists comes to mind as well as modifying the configuration files. For those actions, you don’t need root privileges and therefore not a helper binary.

> On 16 Jan 2025, at 18:07, jon <jon.murphy(a)ipfire.org> wrote:
> 
> Hello,
> 
> I am creating a C program for use with the RPZ project and I need your help.
> 
> Right now there is a rpz.cgi WebGUI.  And it calls the following commands:
> 
> ```
> &General::system('touch', "$CUSTOMLISTS_CONF"); }
> &General::system_output('/usr/sbin/rpz-config', 'list');
> &General::system('/usr/sbin/rpz-config', 'remove', $action_key, '--no-reload');
> &General::system('/usr/sbin/rpz-config', 'add', $name, $url, '--no-reload');
> &General::system('/usr/sbin/rpz-make', 'allowblock', '--no-reload');
> &General::system('/usr/sbin/rpz-config', 'reload');
> &General::system('/usr/local/bin/unboundctrl', 'restart');
> ```
> 
> What determines which of these require a `rpzctrl.c`?  

See above. I hope I could describe it well.

> Are there guidelines for `xyz-ctrl.c` programs?

There is lots. Because they can be launched by nobody and will run as root, they cannot do much. They cannot freely accept command line arguments and interpret those, but they can accept predetermined actions like “start”, “stop”, “restart”. The simpler, the better.

> I am guessing "touch, chown, chmod" do not require a C program but I don’t know "why".  

That depends. If you are are touching files that are in a directory that nobody can write to, then there is no problem.

If you want to create files in a directory that is not owned by nobody you will need to be root. Chmod and chown are also operations that require root permissions - usually.

> 
> ```
> [root(a)ipfire tmp] # file /usr/bin/touch
> /usr/bin/touch: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 5.4.0, stripped
> 
> [root(a)ipfire tmp] # file /bin/chown
> /bin/chown: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 5.4.0, stripped
> 
> [root(a)ipfire tmp] # file /bin/chmod
> /bin/chmod: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 5.4.0, stripped
> [root(a)ipfire tmp] # 
> ```

To run any of these operations, you don’t need to run a shell command. You can do this in Perl.

> Is it because these are already compiled programs?
> 
> So my ask is: what determines the items required in a `rpzctrl.c` type program?

If you need to become root.

Hope this helps.

-Michael

> Best regards,
> Jon
> 


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-01-16 21:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <EDB740E3-EC57-48D6-8DE7-B29D8C16D82C@ipfire.org>
2025-01-16 21:18 ` Guidelines for creating a C Program launched by a WebGUI page Michael Tremer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox