diff options
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackingElement.pm | 90 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackingList.pm | 6 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_add | 65 |
3 files changed, 155 insertions, 6 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm index 268a09d8363..c430c149e56 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PackingElement.pm,v 1.28 2004/09/20 10:36:39 espie Exp $ +# $OpenBSD: PackingElement.pm,v 1.29 2004/09/21 22:17:49 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -626,6 +626,94 @@ sub stringize($) ':'.$self->{pattern}.':'.$self->{def}; } +package OpenBSD::PackingElement::NewUser; +our @ISA=qw(OpenBSD::PackingElement); +__PACKAGE__->setKeyword("newuser"); + +sub category() { "users" } +sub keyword() { "newuser" } + +sub new +{ + my ($class, $args) = @_; + my ($name, $uid, $group, $loginclass, $comment, $home, $shell) = + split /\:/, $args; + bless { name => $name, uid => $uid, group => $group, + class => $loginclass, + comment => $comment, home => $home, shell => $shell }, $class; +} + +sub check +{ + my $self = shift; + my ($name, $passwd, $uid, $gid, $quota, $class, $gcos, $dir, $shell, + $expire) = getpwnam($self->{name}); + return undef unless defined $name; + if ($self->{uid} =~ m/^\!/) { + return 0 unless $uid == $'; + } + if ($self->{group} =~ m/^\!/) { + my $g = $'; + unless ($g =~ m/^\d+/) { + $g = getgrnam($g); + return 0 unless defined $g; + } + return 0 unless $gid eq $g; + } + if ($self->{class} =~ m/^\!/) { + return 0 unless $class eq $'; + } + if ($self->{comment} =~ m/^\!/) { + return 0 unless $gcos eq $'; + } + if ($self->{home} =~ m/^\!/) { + return 0 unless $dir eq $'; + } + if ($self->{shell} =~ m/^\!/) { + return 0 unless $shell eq $'; + } + return 1; +} + +sub stringize($) +{ + my $self = $_[0]; + return $self->{name}.':'.$self->{uid}.':'.$self->{group}.':'. + $self->{class}.':'.$self->{comment}.':'.$self->{home}.':'. + $self->{shell}; +} + +package OpenBSD::PackingElement::NewGroup; +our @ISA=qw(OpenBSD::PackingElement); +__PACKAGE__->setKeyword("newgroup"); + +sub category() { "groups" } +sub keyword() { "newgroup" } + +sub new +{ + my ($class, $args) = @_; + my ($name, $gid) = split /\:/, $args; + bless { name => $name, gid => $gid }, $class; +} + +sub check +{ + my $self = shift; + my ($name, $passwd, $gid, $members) = getgrnam($self->{name}); + return undef unless defined $name; + if ($self->{gid} =~ m/^\!/) { + return 0 unless $gid == $'; + } + return 1; +} + +sub stringize($) +{ + my $self = $_[0]; + return $self->{name}.':'.$self->{gid}; +} + package OpenBSD::PackingElement::LibDepend; our @ISA=qw(OpenBSD::PackingElement); diff --git a/usr.sbin/pkg_add/OpenBSD/PackingList.pm b/usr.sbin/pkg_add/OpenBSD/PackingList.pm index b9c5b4c88ac..15c2110a9aa 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.24 2004/09/18 08:14:40 espie Exp $ +# $OpenBSD: PackingList.pm,v 1.25 2004/09/21 22:17:49 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -134,7 +134,7 @@ sub write for my $unique_item (qw(name no-default-conflict manual-installation extrainfo arch)) { $self->{$unique_item}->write($fh) if defined $self->{$unique_item}; } - for my $listname (qw(modules pkgcfl conflict pkgdep newdepend libdepend items)) { + for my $listname (qw(modules pkgcfl conflict pkgdep newdepend libdepend groups users items)) { if (defined $self->{$listname}) { for my $item (@{$self->{$listname}}) { $item->write($fh); @@ -163,7 +163,7 @@ sub visit for my $unique_item (qw(name no-default-conflict manual-installation extrainfo arch)) { $self->{$unique_item}->$method(@l) if defined $self->{$unique_item}; } - for my $listname (qw(modules pkgcfl conflict pkgdep newdepend libdepend items)) { + for my $listname (qw(modules pkgcfl conflict pkgdep newdepend libdepend groups users items)) { if (defined $self->{$listname}) { for my $item (@{$self->{$listname}}) { $item->$method(@l); diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add index 41aab657a83..9ab2965371d 100644 --- a/usr.sbin/pkg_add/pkg_add +++ b/usr.sbin/pkg_add/pkg_add @@ -1,7 +1,7 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: pkg_add,v 1.59 2004/09/20 10:36:39 espie Exp $ +# $OpenBSD: pkg_add,v 1.60 2004/09/21 22:17:49 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -42,6 +42,18 @@ sub ensure_ldconfig undef $OpenBSD::PackingElement::Lib::todo; } +# used by newuser/newgroup to deal with options. +sub add_entry +{ + my ($l, $f, $v) = @_; + return if !defined $v or $v eq ''; + if ($v =~ m/^\!/) { + push(@$l, $f, $'); + } else { + push(@$l, $f, $v); + } +} + package OpenBSD::PackingElement; use OpenBSD::Error; @@ -81,6 +93,55 @@ sub set_modes } } +package OpenBSD::PackingElement::NewUser; +use OpenBSD::Error; + +sub install +{ + my ($self, $archive, $destdir, $verbose, $not) = @_; + my $user = $self->{name}; + print "adding user $user\n" if $verbose; + return if $not; + my $ok = $self->check(); + if (defined $ok) { + if ($ok == 0) { + die "user $user does not match\n"; + } + } else { + my $l=[]; + push(@$l, "-v") if $verbose; + main::add_entry($l, '-u', $self->{uid}); + main::add_entry($l, '-g', $self->{group}); + main::add_entry($l, '-L', $self->{class}); + main::add_entry($l, '-c', $self->{comment}); + main::add_entry($l, '-d', $self->{home}); + main::add_entry($l, '-s', $self->{shell}); + VSystem($verbose, '/usr/sbin/useradd', @$l, $user); + } +} + +package OpenBSD::PackingElement::NewGroup; +use OpenBSD::Error; + +sub install +{ + my ($self, $archive, $destdir, $verbose, $not) = @_; + my $group = $self->{name}; + print "adding group $group\n" if $verbose; + return if $not; + my $ok = $self->check(); + if (defined $ok) { + if ($ok == 0) { + die "group $group does not match\n"; + } + } else { + my $l=[]; + push(@$l, "-v") if $verbose; + main::add_entry($l, '-g', $self->{gid}); + VSystem($verbose, '/usr/sbin/groupadd', @$l, $group); + } +} + package OpenBSD::PackingElement::FileBase; use File::Basename; use File::Path; @@ -659,7 +720,7 @@ sub really_add($$) $plist->{done} = []; - for my $item (@{$plist->{items}}) { + for my $item (@{$plist->{groups}}, @{$plist->{users}}, @{$plist->{items}}) { eval { $item->install($handle, $destdir, $opt_v, $opt_n); }; if ($@) { print STDERR "$@"; |