summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCameron Katri <me@cameronkatri.com>2021-03-20 01:47:16 -0400
committerCameron Katri <me@cameronkatri.com>2021-03-20 01:47:16 -0400
commita477b5619a23ec06af401df48724cc6ec49d9f76 (patch)
treea85a80e1f71b3ddb3b216163244dbbf057228359
parentff633087671584f9a0627d2525d07f603f9994cc (diff)
downloadpw-darwin-a477b5619a23ec06af401df48724cc6ec49d9f76.tar.gz
pw-darwin-a477b5619a23ec06af401df48724cc6ec49d9f76.tar.zst
pw-darwin-a477b5619a23ec06af401df48724cc6ec49d9f76.zip
pw(8): Fix userdel -r
Fix userdel -r: Remove check to see if uid is used by second user, which is failing after single user is removed Improve Makefile Disallow removing of apple's system users
-rw-r--r--pw/.gitignore1
-rw-r--r--pw/Makefile13
-rw-r--r--pw/pw_user.c10
3 files changed, 14 insertions, 10 deletions
diff --git a/pw/.gitignore b/pw/.gitignore
index 2a81d98..d0cde54 100644
--- a/pw/.gitignore
+++ b/pw/.gitignore
@@ -1 +1,2 @@
pw
+*.o
diff --git a/pw/Makefile b/pw/Makefile
index b6279ef..59ee1bb 100644
--- a/pw/Makefile
+++ b/pw/Makefile
@@ -40,10 +40,13 @@ all: pw
install: install-pw
-pw: $(SRC) $(LIBUTILSRC) $(SBUFSRC) ent.xml
- $(CC) $(CFLAGS) -o pw -I. -Isbuf -Ilibutil $(SRC) $(LIBUTILSRC) $(SBUFSRC) $(LDFLAGS) -lcrypt
- $(STRIP) pw
- $(LDID) -Sent.xml pw
+pw: $(SRC:%.c=%.o) $(LIBUTILSRC:%.c=%.o) $(SBUFSRC:%.c=%.o) ent.xml
+ $(CC) $(LDFLAGS) -o $@ -lcrypt $(SRC:%.c=%.o) $(LIBUTILSRC:%.c=%.o) $(SBUFSRC:%.c=%.o)
+ $(STRIP) $@
+ $(LDID) -Sent.xml $@
+
+%.o: %.c
+ $(CC) $(CFLAGS) -c -o $@ $< -I. -Isbuf -Ilibutil
install-pw: pw pw.8 pw.conf.5
$(GINSTALL) -Dm755 pw $(DESTDIR)/$(PREFIX)/sbin/pw
@@ -52,6 +55,6 @@ install-pw: pw pw.8 pw.conf.5
mkdir -p $(DESTDIR)/$(PREFIX)/share/skel
clean:
- rm -f pw
+ rm -f pw $(SRC:%.c=%.o) $(LIBUTILSRC:%.c=%.o) $(SBUFSRC:%.c=%.o)
.PHONY: all install install-pw clean
diff --git a/pw/pw_user.c b/pw/pw_user.c
index 826388d..fa1ee36 100644
--- a/pw/pw_user.c
+++ b/pw/pw_user.c
@@ -224,7 +224,6 @@ static struct passwd fakeuser = {
"User &",
"/nonexistent",
"/bin/sh",
- 0,
0
};
@@ -1077,9 +1076,11 @@ pw_user_del(int argc, char **argv, char *arg1)
if (name == NULL)
name = pwd->pw_name;
- if (strcmp(pwd->pw_name, "root") == 0)
- errx(EX_DATAERR, "cannot remove user 'root'");
-
+ char *system_users[30] = {"nobody", "root", "mobile", "daemon", "_ftp", "_networkd", "_wireless", "_installd", "_neagent", "_ifccd", "_securityd", "_mdnsresponder", "_sshd", "_unknown", "_distnote", "_astris", "_ondemand", "_findmydevice", "_datadetectors", "_captiveagent", "_analyticsd", "_timed", "_gpsd", "_reportmemoryexception", "_diskimagesiod", "_logd", "_iconservices", "_fud", "_knowledgegraphd", "_coreml"};
+ for (int i = 0; i < 30; i++) {
+ if (strcmp(pwd->pw_name, system_users[i]) == 0)
+ errx(EX_DATAERR, "cannot remove user '%s'", system_users[i]);
+ }
/* Remove opie record from /etc/opiekeys */
if (PWALTDIR() != PWF_ALT)
rmopie(pwd->pw_name);
@@ -1158,7 +1159,6 @@ pw_user_del(int argc, char **argv, char *arg1)
/* Remove home directory and contents */
if (PWALTDIR() != PWF_ALT && deletehome && *home == '/' &&
- GETPWUID(id) == NULL &&
fstatat(conf.rootfd, home + 1, &st, 0) != -1) {
rm_r(conf.rootfd, home, id);
pw_log(cnf, M_DELETE, W_USER, "%s(%ju) home '%s' %s"