Debian Codegraph @

upstream/mageia-cauldron/man3pm/User::pwent.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (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 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "User::pwent 3pm"
61 .TH User::pwent 3pm 2023-12-22 "perl v5.42.0" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 User::pwent \- by\-name interface to Perl\*(Aqs built\-in getpw*() functions
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 5
71 \& use User::pwent;
72 \& my $pw = getpwnam(\*(Aqdaemon\*(Aq) || die "No daemon user";
73 \& if ( $pw\->uid == 1 && $pw\->dir =~ m#^/(bin|tmp)?\ez#s ) {
74 \& print "gid 1 on root dir";
75 \& }
76 \&
77 \& my $real_shell = $pw\->shell || \*(Aq/bin/sh\*(Aq;
78 \&
79 \& for (my ($fullname, $office, $workphone, $homephone) =
80 \& split /\es*,\es*/, $pw\->gecos)
81 \& {
82 \& s/&/ucfirst(lc($pw\->name))/ge;
83 \& }
84 \&
85 \& use User::pwent qw(:FIELDS);
86 \& getpwnam(\*(Aqdaemon\*(Aq) || die "No daemon user";
87 \& if ( $pw_uid == 1 && $pw_dir =~ m#^/(bin|tmp)?\ez#s ) {
88 \& print "gid 1 on root dir";
89 \& }
90 \&
91 \& my $pw = getpw($whoever);
92 \&
93 \& use User::pwent qw/:DEFAULT pw_has/;
94 \& if (pw_has(qw[gecos expire quota])) { .... }
95 \& if (pw_has("name uid gid passwd")) { .... }
96 \& print "Your struct pwd has: ", scalar pw_has(), "\en";
97 .Ve
98 .SH DESCRIPTION
99 .IX Header "DESCRIPTION"
100 This module\*(Aqs default exports override the core \fBgetpwent()\fR, \fBgetpwuid()\fR,
101 and \fBgetpwnam()\fR functions, replacing them with versions that return
102 \&\f(CW\*(C`User::pwent\*(C'\fR objects. This object has methods that return the
103 similarly named structure field name from the C\*(Aqs passwd structure
104 from \fIpwd.h\fR, stripped of their leading "pw_" parts, namely \f(CW\*(C`name\*(C'\fR,
105 \&\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,
106 \&\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,
107 \&\f(CW\*(C`gecos\*(C'\fR, and \f(CW\*(C`shell\*(C'\fR fields are tainted when running in taint mode.
108 .PP
109 You may also import all the structure fields directly into your
110 namespace as regular variables using the :FIELDS import tag. (Note
111 that this still overrides your core functions.) Access these fields
112 as variables named with a preceding \f(CW\*(C`pw_\*(C'\fR in front their method
113 names. Thus, \f(CW\*(C`$passwd_obj\->shell\*(C'\fR corresponds to \f(CW$pw_shell\fR
114 if you import the fields.
115 .PP
116 The \fBgetpw()\fR function is a simple front\-end that forwards
117 a numeric argument to \fBgetpwuid()\fR and the rest to \fBgetpwnam()\fR.
118 .PP
119 To access this functionality without the core overrides, pass the
120 \&\f(CW\*(C`use\*(C'\fR an empty import list, and then access function functions
121 with their full qualified names. The built\-ins are always still
122 available via the \f(CW\*(C`CORE::\*(C'\fR pseudo\-package.
123 .SS "System Specifics"
124 .IX Subsection "System Specifics"
125 Perl believes that no machine ever has more than one of \f(CW\*(C`change\*(C'\fR,
126 \&\f(CW\*(C`age\*(C'\fR, or \f(CW\*(C`quota\*(C'\fR implemented, nor more than one of either
127 \&\f(CW\*(C`comment\*(C'\fR or \f(CW\*(C`class\*(C'\fR. Some machines do not support \f(CW\*(C`expire\*(C'\fR,
128 \&\f(CW\*(C`gecos\*(C'\fR, or allegedly, \f(CW\*(C`passwd\*(C'\fR. You may call these methods
129 no matter what machine you\*(Aqre on, but they return \f(CW\*(C`undef\*(C'\fR if
130 unimplemented.
131 .PP
132 You may ask whether one of these was implemented on the system Perl
133 was built on by asking the importable \f(CW\*(C`pw_has\*(C'\fR function about them.
134 This function returns true if all parameters are supported fields
135 on the build platform, false if one or more were not, and raises
136 an exception if you asked about a field that Perl never knows how
137 to provide. Parameters may be in a space\-separated string, or as
138 separate arguments. If you pass no parameters, the function returns
139 the list of \f(CW\*(C`struct pwd\*(C'\fR fields supported by your build platform\*(Aqs
140 C library, as a list in list context, or a space\-separated string
141 in scalar context. Note that just because your C library had
142 a field doesn\*(Aqt necessarily mean that it\*(Aqs fully implemented on
143 that system.
144 .PP
145 Interpretation of the \f(CW\*(C`gecos\*(C'\fR field varies between systems, but
146 traditionally holds 4 comma\-separated fields containing the user\*(Aqs
147 full name, office location, work phone number, and home phone number.
148 An \f(CW\*(C`&\*(C'\fR in the gecos field should be replaced by the user\*(Aqs properly
149 capitalized login \f(CW\*(C`name\*(C'\fR. The \f(CW\*(C`shell\*(C'\fR field, if blank, must be
150 assumed to be \fI/bin/sh\fR. Perl does not do this for you. The
151 \&\f(CW\*(C`passwd\*(C'\fR is one\-way hashed garble, not clear text, and may not be
152 unhashed save by brute\-force guessing. Secure systems use more a
153 more secure hashing than DES. On systems supporting shadow password
154 systems, Perl automatically returns the shadow password entry when
155 called by a suitably empowered user, even if your underlying
156 vendor\-provided C library was too short\-sighted to realize it should
157 do this.
158 .PP
159 See \fBpasswd\fR\|(5) and \fBgetpwent\fR\|(3) for details.
160 .SH NOTE
161 .IX Header "NOTE"
162 While this class is currently implemented using the Class::Struct
163 module to build a struct\-like class, you shouldn\*(Aqt rely upon this.
164 .SH AUTHOR
165 .IX Header "AUTHOR"
166 Tom Christiansen
167 .SH HISTORY
168 .IX Header "HISTORY"
169 .IP "March 18th, 2000" 4
170 .IX Item "March 18th, 2000"
171 Reworked internals to support better interface to dodgey fields
172 than normal Perl function provides. Added \fBpw_has()\fR field. Improved
173 documentation.