summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackingList.pm4
-rw-r--r--usr.sbin/pkg_add/pkg_delete102
2 files changed, 84 insertions, 22 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackingList.pm b/usr.sbin/pkg_add/OpenBSD/PackingList.pm
index 15c2110a9aa..152a0874c0a 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackingList.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackingList.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackingList.pm,v 1.25 2004/09/21 22:17:49 espie Exp $
+# $OpenBSD: PackingList.pm,v 1.26 2004/09/24 08:49:27 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -65,7 +65,7 @@ sub DirrmOnly
my ($fh, $cont) = @_;
local $_;
while (<$fh>) {
- next unless m/^\@(?:cwd|dirrm|dir|fontdir|mandir|name)\b/ || m/^\@(?:sample|extra)\b.*\/$/ || m/^[^\@].*\/$/;
+ next unless m/^\@(?:cwd|dirrm|dir|fontdir|mandir|newuser|newgroup|name)\b/ || m/^\@(?:sample|extra)\b.*\/$/ || m/^[^\@].*\/$/;
&$cont($_);
}
}
diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/pkg_delete
index 99bac83dd12..81da1d12e5b 100644
--- a/usr.sbin/pkg_add/pkg_delete
+++ b/usr.sbin/pkg_add/pkg_delete
@@ -1,6 +1,6 @@
#!/usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg_delete,v 1.46 2004/09/21 09:44:09 espie Exp $
+# $OpenBSD: pkg_delete,v 1.47 2004/09/24 08:49:27 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -41,11 +41,11 @@ sub ensure_ldconfig
sub record_all_shared_items
{
- my $db = {};
+ my $db = {dirs=>{}, users=>{}, groups=>{}};
my @list = installed_packages();
for my $e (@list) {
my $plist = OpenBSD::PackingList->fromfile(installed_info($e).CONTENTS, \&OpenBSD::PackingList::DirrmOnly) or next;
- for my $item (@{$plist->{items}}) {
+ for my $item (@{$plist->{users}}, @{$plist->{groups}}, @{$plist->{items}}) {
$item->record_shared_item($e, $db);
}
}
@@ -57,25 +57,40 @@ sub cleanup_shared_items
my $state = shift;
my $h = $state->{dirs_to_rm};
- return unless defined $h;
-
+ my $u = $state->{users_to_rm};
+ my $g = $state->{groups_to_rm};
+ return unless defined $h or defined $u or defined $g;
my $remaining = record_all_shared_items();
- for my $d (sort {$b cmp $a} keys %$h) {
- my $realname = $state->{destdir}.$d;
- if ($remaining->{$realname}) {
- for my $i (@{$h->{$d}}) {
- $i->reload($state);
- }
- } else {
- for my $i (@{$h->{$d}}) {
- $i->cleanup($state);
- }
- if (!rmdir $realname) {
- print "Error deleting directory $realname: $!\n";
+ if (defined $h) {
+ for my $d (sort {$b cmp $a} keys %$h) {
+ my $realname = $state->{destdir}.$d;
+ if ($remaining->{dirs}->{$realname}) {
+ for my $i (@{$h->{$d}}) {
+ $i->reload($state);
+ }
+ } else {
+ for my $i (@{$h->{$d}}) {
+ $i->cleanup($state);
+ }
+ if (!rmdir $realname) {
+ print "Error deleting directory $realname: $!\n";
+ }
}
}
}
+ if (defined $u) {
+ for my $user (keys %$u) {
+ next if $remaining->{users}->{$user};
+ System("/usr/sbin/userdel", $user);
+ }
+ }
+ if (defined $g) {
+ for my $group (keys %$g) {
+ next if $remaining->{groups}->{$group};
+ System("/usr/sbin/groupdel", $group);
+ }
+ }
}
@@ -106,13 +121,60 @@ sub log_pkgname
}
}
+package OpenBSD::PackingElement::NewUser;
+sub record_shared_item
+{
+ my ($self, $pkgname, $db) = @_;
+ my $k = $self->{name};
+ $db->{users}->{$k} = 1;
+}
+
+sub delete
+{
+ my ($self, $state) = @_;
+
+ my $name = $self->{name};
+
+ if ($state->{verbose} or $state->{not}) {
+ print "rmuser: $name\n";
+ }
+
+ $state->{users_to_rm} = {} unless defined $state->{users_to_rm};
+
+ my $h = $state->{users_to_rm};
+ $h->{$name} = 1;
+}
+
+package OpenBSD::PackingElement::NewGroup;
+sub record_shared_item
+{
+ my ($self, $pkgname, $db) = @_;
+ my $k = $self->{name};
+ $db->{groups}->{$k} = 1;
+}
+
+sub delete
+{
+ my ($self, $state) = @_;
+
+ my $name = $self->{name};
+
+ if ($state->{verbose} or $state->{not}) {
+ print "rmgroup: $name\n";
+ }
+
+ $state->{groups_to_rm} = {} unless defined $state->{groups_to_rm};
+
+ my $h = $state->{groups_to_rm};
+ $h->{$name} = 1;
+}
package OpenBSD::PackingElement::DirBase;
sub record_shared_item
{
my ($self, $pkgname, $db) = @_;
my $k = $self->fullname();
- $db->{$k} = 1;
+ $db->{dirs}->{$k} = 1;
}
sub delete
@@ -488,7 +550,7 @@ sub delete_package
$plist->get(DEINSTALL)->delete($state);
}
manpages_unindex($plist, $state->{destdir});
- for my $item (@{$plist->{items}}) {
+ for my $item (@{$plist->{groups}}, @{$plist->{users}}, @{$plist->{items}}) {
$item->delete($state);
}
# guard against duplicate pkgdep
@@ -649,7 +711,7 @@ eval {
my $dielater = $@;
ensure_ldconfig($opt_v) unless $opt_n;
-# delayed directory removal
+# delayed directory/user/group removal
cleanup_shared_items($state);
OpenBSD::PackingElement::Fontdir::finish_fontdirs();