summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/IdCache.pm38
-rw-r--r--usr.sbin/pkg_add/pod/OpenBSD::IdCache.pod20
2 files changed, 49 insertions, 9 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/IdCache.pm b/usr.sbin/pkg_add/OpenBSD/IdCache.pm
index 2c08f718c5c..be7cfcb5ea3 100644
--- a/usr.sbin/pkg_add/OpenBSD/IdCache.pm
+++ b/usr.sbin/pkg_add/OpenBSD/IdCache.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: IdCache.pm,v 1.1 2004/09/14 22:37:39 espie Exp $
+# $OpenBSD: IdCache.pm,v 1.2 2005/06/13 11:33:07 espie Exp $
#
# Copyright (c) 2002-2004 Marc Espie <espie@openbsd.org>
#
@@ -17,8 +17,8 @@
use strict;
use warnings;
-package OpenBSD::IdCache;
+package OpenBSD::SimpleIdCache;
sub new
{
my $class = shift;
@@ -30,9 +30,6 @@ sub lookup
my ($self, $name, $default) = @_;
my $r;
- if ($name =~ m/^\d+$/) {
- return $name;
- }
if (defined $self->{$name}) {
$r = $self->{$name};
} else {
@@ -45,6 +42,21 @@ sub lookup
return $r;
}
+
+package OpenBSD::IdCache;
+our @ISA=qw(OpenBSD::SimpleIdCache);
+
+sub lookup
+{
+ my ($self, $name, $default) = @_;
+
+ if ($name =~ m/^\d+$/) {
+ return $name;
+ } else {
+ return $self->SUPER::lookup($name, $default);
+ }
+}
+
package OpenBSD::UidCache;
our @ISA=qw(OpenBSD::IdCache);
@@ -63,4 +75,20 @@ sub convert
return @entry == 0 ? undef : $entry[2];
}
+package OpenBSD::UnameCache;
+our @ISA=qw(OpenBSD::SimpleIdCache);
+
+sub convert
+{
+ return getpwuid($_[1]);
+}
+
+package OpenBSD::GnameCache;
+our @ISA=qw(OpenBSD::SimpleIdCache);
+
+sub convert
+{
+ return getgrgid($_[1]);
+}
+
1;
diff --git a/usr.sbin/pkg_add/pod/OpenBSD::IdCache.pod b/usr.sbin/pkg_add/pod/OpenBSD::IdCache.pod
index 5a2727fc813..80b94fb0aaa 100644
--- a/usr.sbin/pkg_add/pod/OpenBSD::IdCache.pod
+++ b/usr.sbin/pkg_add/pod/OpenBSD::IdCache.pod
@@ -1,8 +1,8 @@
-$OpenBSD: OpenBSD::IdCache.pod,v 1.1 2005/02/28 13:08:41 espie Exp $
+$OpenBSD: OpenBSD::IdCache.pod,v 1.2 2005/06/13 11:33:07 espie Exp $
=head1 NAME
-OpenBSD::IdCache - cache for uid and gid look-ups
+OpenBSD::IdCache - cache for user and group look-ups
=head1 SYNOPSIS
@@ -14,10 +14,17 @@ OpenBSD::IdCache - cache for uid and gid look-ups
my $gcache = new OpenBSD::GidCache;
my $gid = $gcache->lookup("wheel", 0);
+ my $unamecache = new OpenBSD::UnameCache;
+ my $name = $unamecache->lookup($uid);
+
+ my $gnamecache = new OpenBSD::GnameCache;
+ my $grname = $gnamecache->lookup($gid);
+
=head1 DESCRIPTION
-C<OpenBSD::IdCache> provides two classes: C<OpenBSD::UidCache>, for UIDs,
-and C<OpenBSD::GidCache> for GIDs.
+C<OpenBSD::IdCache> provides four classes: C<OpenBSD::UidCache> for UIDs,
+C<OpenBSD::GidCache> for GIDs, C<OpenBSD::UnameCache> for user names, and
+C<OpenBSD::GnameCache> for group names.
C<UidCache::new> creates a UID cache, which can be used to look up user
names by using the C<lookup> method. Looking up a numeric user name
@@ -25,3 +32,8 @@ is a no-op. Non-existing IDs return a default value, which is normally
C<undef> but can be provided as an extra argument to C<lookup>.
C<GidCache::new> provides the same service for GIDs.
+
+C<UnameCache::new> creates a user name cache, which can be used to look up
+UIDs.
+
+C<GnameCache::new> provides the same service for group names.