From b2162c8751a6cf75c963677b838ef36c5e4d96f4 Mon Sep 17 00:00:00 2001 From: espie Date: Tue, 28 Oct 2008 14:32:08 +0000 Subject: [PATCH] do a much better job at handling owners and groups --- infrastructure/install/FS.pm | 25 +++++++-- infrastructure/install/make-plist | 84 ++++++++++++++++++++++++++----- 2 files changed, 92 insertions(+), 17 deletions(-) diff --git a/infrastructure/install/FS.pm b/infrastructure/install/FS.pm index 7438e4e36ad..1b20b8664d3 100644 --- a/infrastructure/install/FS.pm +++ b/infrastructure/install/FS.pm @@ -1,4 +1,4 @@ -# $OpenBSD: FS.pm,v 1.2 2008/10/27 11:12:01 espie Exp $ +# $OpenBSD: FS.pm,v 1.3 2008/10/28 14:32:08 espie Exp $ # Copyright (c) 2008 Marc Espie # # Permission to use, copy, modify, and distribute this software for any @@ -19,8 +19,9 @@ use warnings; package FS::File; sub new { - my ($class, $filename, $type) = @_; - bless {path =>$filename, type => $type}, $class + my ($class, $filename, $type, $owner, $group) = @_; + bless {path =>$filename, type => $type, owner => $owner, + group => $group}, $class } sub type @@ -33,6 +34,16 @@ sub path shift->{path}; } +sub owner +{ + shift->{owner}; +} + +sub group +{ + shift->{group}; +} + package FS; my $destdir; @@ -40,6 +51,7 @@ use OpenBSD::Mtree; use File::Find; use File::Spec; use File::Basename; +use OpenBSD::IdCache; # existing files are classified according to the following routine sub get_type @@ -249,6 +261,8 @@ sub scan_destdir my $archname = $Config{'archname'}; my $installprivlib = $Config{'installprivlib'}; my $installarchlib = $Config{'installarchlib'}; + my $uid_lookup = OpenBSD::UnameCache->new; + my $gid_lookup = OpenBSD::GnameCache->new; find( sub { @@ -265,8 +279,11 @@ sub scan_destdir } return if $File::Find::name =~ m/pear\/lib\/\.(?:filemap|lock)$/; my $path = undest($File::Find::name); + my ($uid, $gid) = (stat $_)[4,5]; $path =~ s,^/etc/X11/app-defaults\b,/usr/local/lib/X11/app-defaults,; - $files{$path} = FS::File->new($path, $type); + $files{$path} = FS::File->new($path, $type, + $uid_lookup->lookup($uid), + $gid_lookup->lookup($gid)); }, $destdir); zap_dirs(\%files, $destdir.'/etc/X11/app-defaults'); return \%files; diff --git a/infrastructure/install/make-plist b/infrastructure/install/make-plist index 15cfae5b8a9..8111d36d9f2 100755 --- a/infrastructure/install/make-plist +++ b/infrastructure/install/make-plist @@ -1,5 +1,5 @@ #! /usr/bin/perl -# $OpenBSD: make-plist,v 1.117 2008/10/28 13:29:01 espie Exp $ +# $OpenBSD: make-plist,v 1.118 2008/10/28 14:32:08 espie Exp $ # Copyright (c) 2004-2008 Marc Espie # # Permission to use, copy, modify, and distribute this software for any @@ -283,7 +283,7 @@ sub clone_tags my $n = $t->clone; if ($n->isa("OpenBSD::PackingElement::Sample") || $n->isa("OpenBSD::PackingElement::SampleDir")) { - main::handle_modes($plist, $n, $t); + main::handle_modes($plist, $n, $t, undef, undef); } $n->add_object($plist); $plist->{nonempty} = 1; @@ -395,15 +395,28 @@ sub stringize return '!%%'.shift->{name}.'%%'; } +package OpenBSD::PackingElement::Owner; +sub register2 +{ + my ($self, $plist, $haystack) = @_; + + $self->SUPER::register2($plist, $haystack); + push(@{$haystack->{$main::subst->do($self->{name})}}, $self); +} + +package OpenBSD::PackingElement::Group; +sub register2 +{ + &OpenBSD::PackingElement::Owner::register2; +} + package OpenBSD::PackingElement::FileObject; sub register2 { my ($self, $plist, $haystack) = @_; $self->SUPER::register2($plist, $haystack); - my $fullname = $self->fullname; - my $n = $main::subst->do($fullname); - push(@{$haystack->{$n}}, $self); + push(@{$haystack->{$main::subst->do($self->fullname)}}, $self); } package OpenBSD::PackingElement::FileBase; @@ -658,10 +671,11 @@ sub create_object # for now, we copy over stuff from old items. sub handle_modes { - my ($plist, $item, $o) = @_; + my ($plist, $item, $o, $file, $haystack) = @_; my ($mode, $owner, $group) = ('', '', ''); my ($oldmode, $oldowner, $oldgroup) = ($plist->{state}->{mode}, $plist->{state}->{owner}, $plist->{state}->{group}); $oldmode = '' unless defined $oldmode; + $oldowner = '' unless defined $oldowner; $oldgroup = '' unless defined $oldgroup; @@ -682,6 +696,42 @@ sub handle_modes $group = $item->{group}; } } + if (defined $file) { + if (defined $haystack->{$file->owner}) { + for my $o (@{$haystack->{$file->owner}}) { + if ($o->isa("OpenBSD::PackingElement::Owner")) { + if ($owner ne '') { + if ($main::subst->do($owner) eq $file->owner) { + last; + } else { + print "File owner does not match for ", + $file->path, " ($owner vs. ", + $file->owner, ")\n"; + } + } else { + $owner = $o->{name}; + } + } + } + } + if (defined $haystack->{$file->group}) { + for my $g (@{$haystack->{$file->group}}) { + if ($g->isa("OpenBSD::PackingElement::Group")) { + if ($group ne '') { + if ($main::subst->do($group) eq $file->group) { + last; + } else { + print "File group does not match for ", + $file->path, " ($group vs. ", + $file->group, ")\n"; + } + } else { + $group = $g->{name}; + } + } + } + } + } if ($mode ne $oldmode) { OpenBSD::PackingElement::Mode->add($plist, $mode); } @@ -714,7 +764,7 @@ sub short_name # If the resulting name is arch-dependent, we warn. # We don't fix it automatically, as this may need special handling. if ($short =~ m/i386|m68k|sparc/) { - print STDERR "make-plist: generated plist $plist->{filename} contains arch-dependent\n"; + print STDERR "make-plist: $plist->{filename} contains arch-dependent\n"; print STDERR "\t$short\n"; } return $short; @@ -725,15 +775,15 @@ sub bad_files my ($short, $plist) = @_; if ($short =~ /\.orig$/) { - print STDERR "make-plist: generated plist $plist->{filename} may contain patched file\n"; + print STDERR "make-plist: $plist->{filename} may contain patched file\n"; print STDERR "\t$short\n"; } if ($short =~ /\/\.[^\/]*\.swp$/) { - print STDERR "make-plist: generated plist $plist->{filename} may contain vim swap file\n"; + print STDERR "make-plist: $plist->{filename} may contain vim swap file\n"; print STDERR "\t$short\n"; } if ($short =~ /\~$/) { - print STDERR "make-plist: generated plist $plist->{filename} may contain emacs temp file\n"; + print STDERR "make-plist: $plist->{filename} may contain emacs temp file\n"; print STDERR "\t$short\n"; } } @@ -748,6 +798,7 @@ sub handle_file my $default = $allplists->[0]; if (defined $haystack->{$file->path}) { for my $item (@{$haystack->{$file->path}}) { + next if $item->isa("OpenBSD::PackingElement::State"); my $p = $item->{plist}->{replacement}; if ($file->type eq 'directory' && $p->{mtree}->{$file->path}) { @@ -761,7 +812,7 @@ sub handle_file } $foundit = $item; if ($o->can("compute_modes")) { - handle_modes($p, $item, $o); + handle_modes($p, $item, $o, $file, $haystack); } $o->add_object($p); $item->{accounted_for} = $o; @@ -785,8 +836,15 @@ sub handle_file if (!defined $o) { next; } + bad_files($short, $p); + if (($file->type eq 'library' || $file->type eq 'plugin') && !$shared_only) { + if (defined $p->{shared}) { + $p->{wantshared} = 1; + $p = $p->{shared}; + } + } if ($o->can("compute_modes")) { - handle_modes($p, undef, $o); + handle_modes($p, undef, $o, $file, $haystack); } $o->add_object($p); $p->{nonempty} = 1; @@ -834,7 +892,7 @@ sub handle_file $p->{wantshared} = 1; $p = $p->{shared}; } - handle_modes($p, undef, $o); + handle_modes($p, undef, $o, $file, $haystack); $o->add_object($p); $p->{nonempty} = 1; }