1User::pwent(3pm)       Perl Programmers Reference Guide       User::pwent(3pm)
2
3
4

NAME

6       User::pwent - by-name interface to Perl's built-in getpw*() functions
7

SYNOPSIS

9        use User::pwent;
10        $pw = getpwnam('daemon')       ⎪⎪ die "No daemon user";
11        if ( $pw->uid == 1 && $pw->dir =~ m#^/(bin⎪tmp)?\z#s ) {
12            print "gid 1 on root dir";
13        }
14
15        $real_shell = $pw->shell ⎪⎪ '/bin/sh';
16
17        for (($fullname, $office, $workphone, $homephone) =
18               split /\s*,\s*/, $pw->gecos)
19        {
20           s/&/ucfirst(lc($pw->name))/ge;
21        }
22
23        use User::pwent qw(:FIELDS);
24        getpwnam('daemon')             ⎪⎪ die "No daemon user";
25        if ( $pw_uid == 1 && $pw_dir =~ m#^/(bin⎪tmp)?\z#s ) {
26            print "gid 1 on root dir";
27        }
28
29        $pw = getpw($whoever);
30
31        use User::pwent qw/:DEFAULT pw_has/;
32        if (pw_has(qw[gecos expire quota])) { .... }
33        if (pw_has("name uid gid passwd"))  { .... }
34        print "Your struct pwd has: ", scalar pw_has(), "\n";
35

DESCRIPTION

37       This module's default exports override the core getpwent(), getpwuid(),
38       and getpwnam() functions, replacing them with versions that return
39       "User::pwent" objects.  This object has methods that return the simi‐
40       larly named structure field name from the C's passwd structure from
41       pwd.h, stripped of their leading "pw_" parts, namely "name", "passwd",
42       "uid", "gid", "change", "age", "quota", "comment", "class", "gecos",
43       "dir", "shell", and "expire".  The "passwd", "gecos", and "shell"
44       fields are tainted when running in taint mode.
45
46       You may also import all the structure fields directly into your names‐
47       pace as regular variables using the :FIELDS import tag.  (Note that
48       this still overrides your core functions.)  Access these fields as
49       variables named with a preceding "pw_" in front their method names.
50       Thus, "$passwd_obj->shell" corresponds to $pw_shell if you import the
51       fields.
52
53       The getpw() function is a simple front-end that forwards a numeric
54       argument to getpwuid() and the rest to getpwnam().
55
56       To access this functionality without the core overrides, pass the "use"
57       an empty import list, and then access function functions with their
58       full qualified names.  The built-ins are always still available via the
59       "CORE::" pseudo-package.
60
61       System Specifics
62
63       Perl believes that no machine ever has more than one of "change",
64       "age", or "quota" implemented, nor more than one of either "comment" or
65       "class".  Some machines do not support "expire", "gecos", or allegedly,
66       "passwd".  You may call these methods no matter what machine you're on,
67       but they return "undef" if unimplemented.
68
69       You may ask whether one of these was implemented on the system Perl was
70       built on by asking the importable "pw_has" function about them.  This
71       function returns true if all parameters are supported fields on the
72       build platform, false if one or more were not, and raises an exception
73       if you asked about a field that Perl never knows how to provide.
74       Parameters may be in a space-separated string, or as separate argu‐
75       ments.  If you pass no parameters, the function returns the list of
76       "struct pwd" fields supported by your build platform's C library, as a
77       list in list context, or a space-separated string in scalar context.
78       Note that just because your C library had a field doesn't necessarily
79       mean that it's fully implemented on that system.
80
81       Interpretation of the "gecos" field varies between systems, but tradi‐
82       tionally holds 4 comma-separated fields containing the user's full
83       name, office location, work phone number, and home phone number.  An
84       "&" in the gecos field should be replaced by the user's properly capi‐
85       talized login "name".  The "shell" field, if blank, must be assumed to
86       be /bin/sh.  Perl does not do this for you.  The "passwd" is one-way
87       hashed garble, not clear text, and may not be unhashed save by brute-
88       force guessing.  Secure systems use more a more secure hashing than
89       DES.  On systems supporting shadow password systems, Perl automatically
90       returns the shadow password entry when called by a suitably empowered
91       user, even if your underlying vendor-provided C library was too short-
92       sighted to realize it should do this.
93
94       See passwd(5) and getpwent(3) for details.
95

NOTE

97       While this class is currently implemented using the Class::Struct mod‐
98       ule to build a struct-like class, you shouldn't rely upon this.
99

AUTHOR

101       Tom Christiansen
102

HISTORY

104       March 18th, 2000
105           Reworked internals to support better interface to dodgey fields
106           than normal Perl function provides.  Added pw_has() field.
107           Improved documentation.
108
109
110
111perl v5.8.8                       2001-09-21                  User::pwent(3pm)
Impressum