чување 3359a3f4b2bdaadce336e8024e3e019b66d40ab8
родитељ 375d5b5a5798cce4f622eddf6da48f3ac71d69f5
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Sun, 17 Jul 2022 22:25:25 +0200
Add umountall, remountroot (shell scripts can't be setuid)
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 8, додавања: 86(+), брисања: 10(-)
diff --git a/.gitignore b/.gitignore
@@ -9,3 +9,5 @@
*.rej
*.swp
*.session
+src/remountroot
+src/umountall
diff --git a/02-chroot.sh b/02-chroot.sh
@@ -117,6 +117,10 @@ cp_or_fail ${WD}/lib/perms.tsv ${GR}/lib/perms.tsv
cp_or_fail ${WD}/lib/rmfiles ${GR}/lib/rmfiles
cp_or_fail ${WD}/lib/rmlist.tsv ${GR}/lib/rmlist.tsv
+check_dir ${G_SRC}/galeb-utils-20220717
+cp_or_fail ${WD}/src/remountroot.c ${G_SRC}/galeb-utils-20220717/remountroot.c
+cp_or_fail ${WD}/src/umountall.c ${G_SRC}/galeb-utils-20220717/umountall.c
+
cp_or_fail ${WD}/${FLD}/rc.d/profile ${GR}/etc/profile.final
cp_or_fail ${WD}/${FLD}/rc.d/mkshrc ${GR}/etc/mkshrc
cp_or_fail ${WD}/${FLD}/rc.d/rc.conf ${GR}/etc/rc.conf
diff --git a/03-packages.sh b/03-packages.sh
@@ -4050,6 +4050,22 @@ mkpk_install()
fi
end_substep
+begin_substep galeb-utils-20220717
+if [ ! -x /bin/umountall ]; then
+ (
+ cd_or_fail ${G_SRC}/${pkg}
+
+ cc -Os -pipe -static --static -fcommon -o remountroot \
+ remountroot.c || exit 1
+ cc -Os -pipe -static --static -fcommon -o umountall \
+ umountall.c || exit 1
+
+ cp_or_fail remountroot /bin/remountroot
+ cp_or_fail umountall /bin/umountall
+ ) || exit 1
+fi
+end_substep
+
begin_substep linux-5.17.13
extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.gz
remove_file ${G_SRC}/linux
diff --git a/TODO b/TODO
@@ -9,20 +9,24 @@ TODO
[ ] https://git.2f30.org/
[ ] https://git.suckless.org/
[x] hwclock on shutdown
- [ ] shutdown as regular user (remount / ro)
+ [x] shutdown as regular user (remount / ro)
[~] Add packages
- [x] Add git
- [x] Add dhcp
- [ ] Add curl (needed for git?)
- [x] Add snarf
- [x] Add svc
- [x] Add table, text-utils
+ [ ] Add curl (needed for git?) - needed
[ ] git://git.suckless.org/utmp
[ ] git://r-36.net/nldev
[ ] git://r-36.net/nlmon
[ ] git://r-36.net/rfkilld
[ ] fsck.vfat
+ [ ] Add ssh(d)
+ [ ] Add sup
+ [~] Add git
+ [~] Add table, text-utils
+ [x] Add sdhcp
+ [x] Test sdhcp
+ [/] ~Add snarf~ - doesn't support HTTPS
+ [/] Replace with axel if not installing curl
+ [x] Add svc
[ ] Add -h to free
diff --git a/fil/rc.d/rc.shutdown b/fil/rc.d/rc.shutdown
@@ -57,10 +57,10 @@ msg info "whoami="
whoami
msg info "Remounting / as read-only"
-mount -o ro,remount /
+remountroot
msg info "Unmounting filesystems"
-umount -a >/dev/null 2>&1
+umountall
sync; sync; sync
sleep 3
wait
diff --git a/lib/perms.tsv b/lib/perms.tsv
@@ -4,10 +4,13 @@ Path Mode Owner Group
/bin/su 4555 root root
/bin/crond 4700 root root
/bin/crontab 4750 root cron
+/bin/halt 4550 root wheel
/var/spool/cron 0755 root root
/var/spool/cron/cronstamps 0755 root root
/var/spool/cron/crontabs 0755 root root
/var/run/utmp 664 root utmp
/bin/rc.init 555 root root
-/bin/rc.shutdown 4555 root root
+/bin/rc.shutdown 4555 root wheel
/bin/rc.svc 555 root root
+/bin/remountroot 4755 root wheel
+/bin/umountall 4755 root wheel
diff --git a/src/remountroot.c b/src/remountroot.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <sys/mount.h>
+
+static const char roottype[] = "ext4";
+
+int
+main()
+{
+ if (mount(NULL, "/", roottype, MS_REMOUNT | MS_RDONLY, NULL))
+ {
+ perror("remountroot");
+ return 1;
+ }
+ return 0;
+}
diff --git a/src/umountall.c b/src/umountall.c
@@ -0,0 +1,32 @@
+#include <stdio.h>
+#include <string.h>
+#include <sys/mount.h>
+
+#define MAXBUF 4096
+
+int
+main()
+{
+ FILE* mounts = NULL;
+ char line[MAXBUF];
+ char* eol = NULL;
+
+ if (!(mounts = fopen("/proc/self/mounts", "r")))
+ {
+ perror("umountall");
+ return 1;
+ }
+
+ while (fgets(line, MAXBUF, mounts))
+ {
+ eol = strchr(line, '\n');
+ if (eol)
+ *eol = 0;
+ strtok(line, " ");
+ if (umount(strtok(NULL, " ")))
+ perror("umountall");
+ }
+
+ fclose(mounts);
+ return 0;
+}