Skip to content

Commit

Permalink
chpst: remove dependency on prot.h
Browse files Browse the repository at this point in the history
prot.c provides two functions: prot_gid and prot_uid.

prot_gid is fully unused, and depends on {chk,try}shsgr, both of which must be
run at build-time and require that the user has additional groups. They are not
needed by anything else and their removal gets rid of cross-compilation jank.

prot_uid is used (once) by chpst, but since it is a no-op wrapper around
setuid(), its use can be replaced by a normal call to setuid().

Solves the big questions from void-linux#11
  • Loading branch information
0x5c committed Mar 27, 2023
1 parent 2b8000f commit 66ec476
Show file tree
Hide file tree
Showing 10 changed files with 4 additions and 100 deletions.
22 changes: 3 additions & 19 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,6 @@ byte_diff.o: byte.h byte_diff.c compile
byte_rchr.o: byte.h byte_rchr.c compile
./compile byte_rchr.c

chkshsgr: chkshsgr.o load
./load chkshsgr

chkshsgr.o: chkshsgr.c compile
./compile chkshsgr.c

choose: choose.sh warn-auto.sh
rm -f choose
cat warn-auto.sh choose.sh \
Expand Down Expand Up @@ -232,11 +226,6 @@ hassgact.h: choose compile hassgact.h1 hassgact.h2 load trysgact.c
hassgprm.h: choose compile hassgprm.h1 hassgprm.h2 load trysgprm.c
./choose cl trysgprm hassgprm.h1 hassgprm.h2 > hassgprm.h

hasshsgr.h: chkshsgr choose compile hasshsgr.h1 hasshsgr.h2 load \
tryshsgr.c warn-shsgr
./chkshsgr || ( cat warn-shsgr; exit 1 )
./choose clr tryshsgr hasshsgr.h1 hasshsgr.h2 > hasshsgr.h

haswaitp.h: choose compile haswaitp.h1 haswaitp.h2 load trywaitp.c
./choose cl trywaitp haswaitp.h1 haswaitp.h2 > haswaitp.h

Expand Down Expand Up @@ -292,9 +281,6 @@ pathexec_run.o: compile env.h error.h gen_alloc.h pathexec.h \
pathexec_run.c str.h stralloc.h
./compile pathexec_run.c

prot.o: compile hasshsgr.h prot.c prot.h
./compile prot.c

readclose.o: compile error.h gen_alloc.h readclose.c readclose.h \
stralloc.h
./compile readclose.c
Expand Down Expand Up @@ -372,7 +358,7 @@ subgetopt.o: compile subgetopt.c subgetopt.h
./compile subgetopt.c

sysdeps: compile direntry.h hasflock.h hasmkffo.h hassgact.h \
hassgprm.h hasshsgr.h haswaitp.h iopause.h load select.h systype \
hassgprm.h haswaitp.h iopause.h load select.h systype \
uint64.h reboot_system.h uw_tmp.h socket.lib
rm -f sysdeps
cat systype compile load socket.lib >>sysdeps
Expand All @@ -385,7 +371,6 @@ uint64.h reboot_system.h uw_tmp.h socket.lib
grep sysdep iopause.h >>sysdeps
grep sysdep hasmkffo.h >>sysdeps
grep sysdep hasflock.h >>sysdeps
grep sysdep hasshsgr.h >>sysdeps
grep sysdep reboot_system.h >>sysdeps
grep sysdep uw_tmp.h >>sysdeps
cat sysdeps
Expand Down Expand Up @@ -444,7 +429,7 @@ buffer_get.o buffer_put.o buffer_read.o buffer_write.o coe.o env.o \
error.o error_str.o fd_copy.o fd_move.o fifo.o lock_ex.o lock_exnb.o \
makelib ndelay_off.o ndelay_on.o open_append.o open_read.o \
open_trunc.o open_write.o openreadclose.o pathexec_env.o \
pathexec_run.o prot.o readclose.o seek_set.o sgetopt.o sig.o \
pathexec_run.o readclose.o seek_set.o sgetopt.o sig.o \
sig_block.o sig_catch.o sig_pause.o stralloc_cat.o stralloc_catb.o \
stralloc_cats.o stralloc_eady.o stralloc_opyb.o stralloc_opys.o \
stralloc_pend.o strerr_die.o strerr_sys.o subgetopt.o wait_nohang.o \
Expand All @@ -454,7 +439,7 @@ wait_pid.o
coe.o env.o error.o error_str.o fd_copy.o fd_move.o fifo.o lock_ex.o \
lock_exnb.o ndelay_off.o ndelay_on.o open_append.o open_read.o \
open_trunc.o open_write.o openreadclose.o pathexec_env.o \
pathexec_run.o prot.o readclose.o seek_set.o sgetopt.o sig.o \
pathexec_run.o readclose.o seek_set.o sgetopt.o sig.o \
sig_block.o sig_catch.o sig_pause.o stralloc_cat.o stralloc_catb.o \
stralloc_cats.o stralloc_eady.o stralloc_opyb.o stralloc_opys.o \
stralloc_pend.o strerr_die.o strerr_sys.o subgetopt.o wait_nohang.o \
Expand All @@ -465,4 +450,3 @@ wait_nohang.o: compile haswaitp.h wait_nohang.c

wait_pid.o: compile error.h haswaitp.h wait_pid.c
./compile wait_pid.c

4 changes: 0 additions & 4 deletions src/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ byte_copy.o
byte_cr.o
byte_diff.o
byte_rchr.o
chkshsgr
chkshsgr.o
choose
coe.o
compile
Expand All @@ -68,7 +66,6 @@ hasflock.h
hasmkffo.h
hassgact.h
hassgprm.h
hasshsgr.h
haswaitp.h
iopause.h
iopause.o
Expand All @@ -85,7 +82,6 @@ open_write.o
openreadclose.o
pathexec_env.o
pathexec_run.o
prot.o
readclose.o
scan_ulong.o
seek_set.o
Expand Down
13 changes: 0 additions & 13 deletions src/chkshsgr.c

This file was deleted.

3 changes: 1 addition & 2 deletions src/chpst.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "strerr.h"
#include "str.h"
#include "uidgid.h"
#include "prot.h"
#include "strerr.h"
#include "scan.h"
#include "fmt.h"
Expand Down Expand Up @@ -80,7 +79,7 @@ void suidgid(char *user, unsigned int ext) {
}
if (setgroups(ugid.gids, ugid.gid) == -1) fatal("unable to setgroups");
if (setgid(*ugid.gid) == -1) fatal("unable to setgid");
if (prot_uid(ugid.uid) == -1) fatal("unable to setuid");
if (setuid(ugid.uid) == -1) fatal("unable to setuid");
}

void euidgid(char *user, unsigned int ext) {
Expand Down
3 changes: 0 additions & 3 deletions src/hasshsgr.h1

This file was deleted.

4 changes: 0 additions & 4 deletions src/hasshsgr.h2

This file was deleted.

25 changes: 0 additions & 25 deletions src/prot.c

This file was deleted.

11 changes: 0 additions & 11 deletions src/prot.h

This file was deleted.

16 changes: 0 additions & 16 deletions src/tryshsgr.c

This file was deleted.

3 changes: 0 additions & 3 deletions src/warn-shsgr

This file was deleted.

0 comments on commit 66ec476

Please sign in to comment.