1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
'\" te
.\" Copyright 1989 AT&T Copyright (c) 1998, Sun Microsystems, Inc. All Rights Reserved
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH GETUTENT 3C "April 9, 2016"
.SH NAME
getutent, getutid, getutline, pututline, setutent, endutent, utmpname \- user
accounting database functions
.SH SYNOPSIS
.LP
.nf
#include <utmp.h>
\fBstruct utmp *\fR\fBgetutent\fR(\fBvoid\fR);
.fi
.LP
.nf
\fBstruct utmp *\fR\fBgetutid\fR(\fBconst struct utmp *\fR\fIid\fR);
.fi
.LP
.nf
\fBstruct utmp *\fR\fBgetutline\fR(\fBconst struct utmp *\fR\fIline\fR);
.fi
.LP
.nf
\fBstruct utmp *\fR\fBpututline\fR(\fBconst struct utmp *\fR\fIutmp\fR);
.fi
.LP
.nf
\fBvoid\fR \fBsetutent\fR(\fBvoid\fR);
.fi
.LP
.nf
\fBvoid\fR \fBendutent\fR(\fBvoid\fR);
.fi
.LP
.nf
\fBint\fR \fButmpname\fR(\fBconst char *\fR\fIfile\fR);
.fi
.SH DESCRIPTION
.LP
These functions provide access to the user accounting database, \fButmp\fR.
Entries in the database are described by the definitions and data structures in
\fB<utmp.h>\fR\&.
.sp
.LP
The \fButmp\fR structure contains the following members:
.sp
.in +2
.nf
char ut_user[8]; /* user login name */
char ut_id[4]; /* /sbin/inittab id */
/* (usually line #) */
char ut_line[12]; /* device name (console, lnxx) */
short ut_pid; /* process id */
short ut_type; /* type of entry */
struct exit_status ut_exit; /* exit status of a process */
/* marked as DEAD_PROCESS */
time_t ut_time; /* time entry was made */
.fi
.in -2
.sp
.LP
The structure \fBexit_status\fR includes the following members:
.sp
.in +2
.nf
short e_termination; /* termination status */
short e_exit; /* exit status */
.fi
.in -2
.SS "\fBgetutent()\fR"
.LP
The \fBgetutent()\fR function reads in the next entry from a \fButmp\fR
database. If the database is not already open, it opens it. If it reaches the
end of the database, it fails.
.SS "\fBgetutid()\fR"
.LP
The \fBgetutid()\fR function searches forward from the current point in the
\fButmp\fR database until it finds an entry with a \fBut_type\fR matching
\fIid\fR->\fBut_type\fR if the type specified is \fBRUN_LVL\fR,
\fBBOOT_TIME\fR, \fBDOWN_TIME\fR, \fBOLD_TIME\fR, or \fBNEW_TIME\fR. If the
type specified in \fIid\fR is \fBINIT_PROCESS\fR, \fBLOGIN_PROCESS\fR,
\fBUSER_PROCESS\fR, or \fBDEAD_PROCESS\fR, then \fBgetutid()\fR will return a
pointer to the first entry whose type is one of these four and whose
\fBut_id\fR member matches \fIid\fR->\fBut_id\fR. If the end of database is
reached without a match, it fails.
.SS "\fBgetutline()\fR"
.LP
The \fBgetutline()\fR function searches forward from the current point in the
\fButmp\fR database until it finds an entry of the type \fBLOGIN_PROCESS\fR or
\fBut_line\fR string matching the \fIline\fR->\fBut_line\fR string. If the end
of database is reached without a match, it fails.
.SS "\fBpututline()\fR"
.LP
The \fBpututline()\fR function writes the supplied \fButmp\fR structure into
the \fButmp\fR database. It uses \fBgetutid()\fR to search forward for the
proper place if it finds that it is not already at the proper place. It is
expected that normally the user of \fBpututline()\fR will have searched for the
proper entry using one of these functions. If so, \fBpututline()\fR will
not search. If \fBpututline()\fR does not find a matching slot for the new
entry, it will add a new entry to the end of the database. It returns a
pointer to the \fButmp\fR structure. When called by a non-root user,
\fBpututline()\fR invokes a \fBsetuid()\fR root program to verify and write the
entry, since the \fButmp\fR database is normally writable only by root. In
this event, the \fBut_name\fR member must correspond to the actual user name
associated with the process; the \fBut_type\fR member must be either
\fBUSER_PROCESS\fR or \fBDEAD_PROCESS\fR; and the \fBut_line\fR member must be
a device special file and be writable by the user.
.SS "\fBsetutent()\fR"
.LP
The \fBsetutent()\fR function resets the input stream to the beginning. This
reset should be done before each search for a new entry if it is desired that
the entire database be examined.
.SS "\fBendutent()\fR"
.LP
The \fBendutent()\fR function closes the currently open database.
.SS "\fButmpname()\fR"
.LP
The \fButmpname()\fR function allows the user to change the name of the
database file examined to another file. If the file does not exist, this will
not be apparent until the first attempt to reference the file is made. The
\fButmpname()\fR function does not open the file but closes the old file if it
is currently open and saves the new file name.
.SH RETURN VALUES
.LP
A null pointer is returned upon failure to read, whether for permissions or
having reached the end of file, or upon failure to write. If the file name
given is longer than 79 characters, \fButmpname()\fR returns \fB0\fR.
Otherwise, it returns \fB1\fR.
.SH USAGE
.LP
These functions use buffered standard I/O for input, but \fBpututline()\fR uses
an unbuffered non-standard write to avoid race conditions between processes
trying to modify the \fButmp\fR and \fBwtmp\fR databases.
.sp
.LP
Applications should not access the \fButmp\fR and \fBwtmp\fR databases
directly, but should use these functions to ensure that these databases are
maintained consistently. Using these functions, however, may cause applications
to fail if user accounting data cannot be represented properly in the
\fButmp\fR structure (for example, on a system where PIDs can exceed 32767).
Use the functions described on the \fBgetutxent\fR(3C) manual page instead.
.SH ATTRIBUTES
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp
.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE ATTRIBUTE VALUE
_
MT-Level Unsafe
.TE
.SH SEE ALSO
.LP
\fBgetutxent\fR(3C), \fBttyslot\fR(3C), \fButmpx\fR(4), \fBattributes\fR(5)
.SH NOTES
.LP
The most current entry is saved in a static structure. Multiple accesses
require that it be copied before further accesses are made. On each call to
either \fBgetutid()\fR or \fBgetutline()\fR, the function examines the static
structure before performing more I/O. If the contents of the static structure
match what it is searching for, it looks no further. For this reason, to use
\fBgetutline()\fR to search for multiple occurrences, it would be necessary to
zero out the static area after each success, or \fBgetutline()\fR would just
return the same structure over and over again. There is one exception to the
rule about emptying the structure before further reads are done. The implicit
read done by \fBpututline()\fR (if it finds that it is not already at the
correct place in the file) will not hurt the contents of the static structure
returned by the \fBgetutent()\fR, \fBgetutid()\fR or \fBgetutline()\fR
functions, if the user has just modified those contents and passed the pointer
back to \fBpututline()\fR.
|