Debian Codegraph @

upstream/debian-unstable/man3/User::pwent.3perl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "User::pwent 3perl"
58 .TH User::pwent 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide"
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 User::pwent \- by\-name interface to Perl's built\-in getpw*() functions
65 .SH SYNOPSIS
66 .IX Header "SYNOPSIS"
67 .Vb 5
68 \& use User::pwent;
69 \& my $pw = getpwnam(\*(Aqdaemon\*(Aq) || die "No daemon user";
70 \& if ( $pw\->uid == 1 && $pw\->dir =~ m#^/(bin|tmp)?\ez#s ) {
71 \& print "gid 1 on root dir";
72 \& }
73 \&
74 \& my $real_shell = $pw\->shell || \*(Aq/bin/sh\*(Aq;
75 \&
76 \& for (my ($fullname, $office, $workphone, $homephone) =
77 \& split /\es*,\es*/, $pw\->gecos)
78 \& {
79 \& s/&/ucfirst(lc($pw\->name))/ge;
80 \& }
81 \&
82 \& use User::pwent qw(:FIELDS);
83 \& getpwnam(\*(Aqdaemon\*(Aq) || die "No daemon user";
84 \& if ( $pw_uid == 1 && $pw_dir =~ m#^/(bin|tmp)?\ez#s ) {
85 \& print "gid 1 on root dir";
86 \& }
87 \&
88 \& my $pw = getpw($whoever);
89 \&
90 \& use User::pwent qw/:DEFAULT pw_has/;
91 \& if (pw_has(qw[gecos expire quota])) { .... }
92 \& if (pw_has("name uid gid passwd")) { .... }
93 \& print "Your struct pwd has: ", scalar pw_has(), "\en";
94 .Ve
95 .SH DESCRIPTION
96 .IX Header "DESCRIPTION"
97 This module's default exports override the core \fBgetpwent()\fR, \fBgetpwuid()\fR,
98 and \fBgetpwnam()\fR functions, replacing them with versions that return
99 \&\f(CW\*(C`User::pwent\*(C'\fR objects. This object has methods that return the
100 similarly named structure field name from the C's passwd structure
101 from \fIpwd.h\fR, stripped of their leading "pw_" parts, namely \f(CW\*(C`name\*(C'\fR,
102 \&\f(CW\*(C`passwd\*(C'\fR, \f(CW\*(C`uid\*(C'\fR, \f(CW\*(C`gid\*(C'\fR, \f(CW\*(C`change\*(C'\fR, \f(CW\*(C`age\*(C'\fR, \f(CW\*(C`quota\*(C'\fR, \f(CW\*(C`comment\*(C'\fR,
103 \&\f(CW\*(C`class\*(C'\fR, \f(CW\*(C`gecos\*(C'\fR, \f(CW\*(C`dir\*(C'\fR, \f(CW\*(C`shell\*(C'\fR, and \f(CW\*(C`expire\*(C'\fR. The \f(CW\*(C`passwd\*(C'\fR,
104 \&\f(CW\*(C`gecos\*(C'\fR, and \f(CW\*(C`shell\*(C'\fR fields are tainted when running in taint mode.
105 .PP
106 You may also import all the structure fields directly into your
107 namespace as regular variables using the :FIELDS import tag. (Note
108 that this still overrides your core functions.) Access these fields
109 as variables named with a preceding \f(CW\*(C`pw_\*(C'\fR in front their method
110 names. Thus, \f(CW\*(C`$passwd_obj\->shell\*(C'\fR corresponds to \f(CW$pw_shell\fR
111 if you import the fields.
112 .PP
113 The \fBgetpw()\fR function is a simple front-end that forwards
114 a numeric argument to \fBgetpwuid()\fR and the rest to \fBgetpwnam()\fR.
115 .PP
116 To access this functionality without the core overrides, pass the
117 \&\f(CW\*(C`use\*(C'\fR an empty import list, and then access function functions
118 with their full qualified names. The built-ins are always still
119 available via the \f(CW\*(C`CORE::\*(C'\fR pseudo-package.
120 .SS "System Specifics"
121 .IX Subsection "System Specifics"
122 Perl believes that no machine ever has more than one of \f(CW\*(C`change\*(C'\fR,
123 \&\f(CW\*(C`age\*(C'\fR, or \f(CW\*(C`quota\*(C'\fR implemented, nor more than one of either
124 \&\f(CW\*(C`comment\*(C'\fR or \f(CW\*(C`class\*(C'\fR. Some machines do not support \f(CW\*(C`expire\*(C'\fR,
125 \&\f(CW\*(C`gecos\*(C'\fR, or allegedly, \f(CW\*(C`passwd\*(C'\fR. You may call these methods
126 no matter what machine you're on, but they return \f(CW\*(C`undef\*(C'\fR if
127 unimplemented.
128 .PP
129 You may ask whether one of these was implemented on the system Perl
130 was built on by asking the importable \f(CW\*(C`pw_has\*(C'\fR function about them.
131 This function returns true if all parameters are supported fields
132 on the build platform, false if one or more were not, and raises
133 an exception if you asked about a field that Perl never knows how
134 to provide. Parameters may be in a space-separated string, or as
135 separate arguments. If you pass no parameters, the function returns
136 the list of \f(CW\*(C`struct pwd\*(C'\fR fields supported by your build platform's
137 C library, as a list in list context, or a space-separated string
138 in scalar context. Note that just because your C library had
139 a field doesn't necessarily mean that it's fully implemented on
140 that system.
141 .PP
142 Interpretation of the \f(CW\*(C`gecos\*(C'\fR field varies between systems, but
143 traditionally holds 4 comma-separated fields containing the user's
144 full name, office location, work phone number, and home phone number.
145 An \f(CW\*(C`&\*(C'\fR in the gecos field should be replaced by the user's properly
146 capitalized login \f(CW\*(C`name\*(C'\fR. The \f(CW\*(C`shell\*(C'\fR field, if blank, must be
147 assumed to be \fI/bin/sh\fR. Perl does not do this for you. The
148 \&\f(CW\*(C`passwd\*(C'\fR is one-way hashed garble, not clear text, and may not be
149 unhashed save by brute-force guessing. Secure systems use more a
150 more secure hashing than DES. On systems supporting shadow password
151 systems, Perl automatically returns the shadow password entry when
152 called by a suitably empowered user, even if your underlying
153 vendor-provided C library was too short-sighted to realize it should
154 do this.
155 .PP
156 See \fBpasswd\fR\|(5) and \fBgetpwent\fR\|(3) for details.
157 .SH NOTE
158 .IX Header "NOTE"
159 While this class is currently implemented using the Class::Struct
160 module to build a struct-like class, you shouldn't rely upon this.
161 .SH AUTHOR
162 .IX Header "AUTHOR"
163 Tom Christiansen
164 .SH HISTORY
165 .IX Header "HISTORY"
166 .IP "March 18th, 2000" 4
167 .IX Item "March 18th, 2000"
168 Reworked internals to support better interface to dodgey fields
169 than normal Perl function provides. Added \fBpw_has()\fR field. Improved
170 documentation.