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`?
Are there guidelines for `xyz-ctrl.c` programs?
I am guessing "touch, chown, chmod" do not require a C program but I don’t know "why".
``` [root@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@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@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@ipfire tmp] # ```
Is it because these are already compiled programs?
So my ask is: what determines the items required in a `rpzctrl.c` type program?
Best regards, Jon
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@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@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@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@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@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
Michael,
Comments below. . .
On Jan 16, 2025, at 3:18 PM, Michael Tremer michael.tremer@ipfire.org wrote:
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.
This makes sense!
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.
I think this is true for the RPZ items.
On 16 Jan 2025, at 18:07, jon jon.murphy@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.
There are two non-Action items. One is a RPZ-NAME and one is the RPZ-URL. Like this: `&General::system('/usr/sbin/rpz-config', 'add', $name, $url, '--no-reload')`
Otherwise they are all predetermined actions.
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.
Yes, the touch file and the directory are owned by "nobody"
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.
Any created or updated files are owned by "nobody"
[root@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@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@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@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.
Thank you! I think I understand the above but to make sure here are the various files below:
1) So the WebGUI - owned by root
[root@ipfire ~] # lso /srv/web/ipfire/cgi-bin/rpz.cgi 755 -rwxr-xr-x 1 root root 26980 Jan 15 11:13 /srv/web/ipfire/cgi-bin/rpz.cgi
2) gets items from Allowlist/Blocklist and updates the two config files. - owned by nobody
[root@ipfire ~] # lso /var/ipfire/dns/rpz 644 -rw-r--r-- 1 nobody nobody 899 Jan 10 11:43 allowlist 644 -rw-r--r-- 1 nobody nobody 68 Jan 10 11:43 blocklist 644 -rw-r--r-- 1 nobody nobody 979 Jan 10 11:43 customlists.conf 644 -rw-r--r-- 1 nobody nobody 1414 Jan 15 14:24 zonefiles.conf
3) and then the WebGUI calls the various RPZ scripts: - owned by root
[root@ipfire ~] # lso /usr/sbin/rpz* 755 -rwxr-xr-x 1 root root 4916 Jan 15 12:32 /usr/sbin/rpz-config 755 -rwxr-xr-x 1 root root 3273 Jan 15 12:32 /usr/sbin/rpz-functions 755 -rwxr-xr-x 1 root root 7216 Jan 15 12:32 /usr/sbin/rpz-make 755 -rwxr-xr-x 1 root root 6105 Jan 15 12:32 /usr/sbin/rpz-metrics 755 -rwxr-xr-x 1 root root 2315 Jan 15 12:32 /usr/sbin/rpz-sleep
4) and those RPZ scripts create these config files: - owned by nobody
[root@ipfire ~] # lso /etc/unbound/local.d/* 644 -rw-r--r-- 1 nobody nobody 294 Jan 10 21:51 /etc/unbound/local.d/00-rpz.conf 644 -rw-r--r-- 1 nobody nobody 371 Jan 5 15:05 /etc/unbound/local.d/AmazonTrkrHZ.rpz.conf . . . 644 -rw-r--r-- 1 nobody nobody 312 Jan 15 15:43 /etc/unbound/local.d/urlhaus.rpz.conf 644 -rw-r--r-- 1 nobody nobody 365 Jan 5 15:06 /etc/unbound/local.d/WinTrkrHZ.rpz.conf
5) and those config files launch the Unbound RPZ code and Unbound RPZ downloads these RPZ files. - owned by nobody
[root@ipfire ~] # lso /etc/unbound/zonefiles/* 644 -rw-r--r-- 1 nobody nobody 1263 Jan 10 21:51 /etc/unbound/zonefiles/allow.rpz 644 -rw-r--r-- 1 nobody nobody 25355 Jan 16 15:44 /etc/unbound/zonefiles/AmazonTrkrHZ.rpz . . . 644 -rw-r--r-- 1 nobody nobody 42911 Jan 16 19:21 /etc/unbound/zonefiles/urlhaus.rpz 644 -rw-r--r-- 1 nobody nobody 28297 Jan 16 15:44 /etc/unbound/zonefiles/WinTrkrHZ.rpz
So I think we are OK with no rpzctrl.c file. Does this seem right??
Hope this helps.
Yes, big time!
-Michael
Best regards, Jon
Jon