From: Michael Tremer <michael.tremer@ipfire.org>
To: development@lists.ipfire.org
Subject: Re: Guidelines for creating a C Program launched by a WebGUI page.
Date: Thu, 16 Jan 2025 21:18:47 +0000 [thread overview]
Message-ID: <78FC350D-EED0-4255-BC5C-1E4E31142003@ipfire.org> (raw)
In-Reply-To: <EDB740E3-EC57-48D6-8DE7-B29D8C16D82C@ipfire.org>
[-- 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
>
parent reply other threads:[~2025-01-16 21:18 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <EDB740E3-EC57-48D6-8DE7-B29D8C16D82C@ipfire.org>]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=78FC350D-EED0-4255-BC5C-1E4E31142003@ipfire.org \
--to=michael.tremer@ipfire.org \
--cc=development@lists.ipfire.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox