nightly: remove unused BINARCHIVE
[unleashed.git] / share / man / man3c / getutxent.3c
blob2a2e55c2e4fb4cb1c9c96b1c0790b49a7ae5983e
1 '\" te
2 .\" Copyright 1989 AT&T.  Copyright (c) 2004 Sun Microsystems, Inc.  All Rights Reserved.
3 .\" 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.
4 .\" 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.
5 .\" 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]
6 .TH GETUTXENT 3C "Nov 21, 2014"
7 .SH NAME
8 getutxent, getutxid, getutxline, pututxline, setutxent, endutxent, utmpxname,
9 getutmp, getutmpx, updwtmp, updwtmpx \- user accounting database functions
10 .SH SYNOPSIS
11 .LP
12 .nf
13 #include <utmpx.h>
15 \fBstruct utmpx *\fR\fBgetutxent\fR(\fBvoid\fR);
16 .fi
18 .LP
19 .nf
20 \fBstruct utmpx *\fR\fBgetutxid\fR(\fBconst struct utmpx *\fR\fIid\fR);
21 .fi
23 .LP
24 .nf
25 \fBstruct utmpx *\fR\fBgetutxline\fR(\fBconst struct utmpx *\fR\fIline\fR);
26 .fi
28 .LP
29 .nf
30 \fBstruct utmpx *\fR\fBpututxline\fR(\fBconst struct utmpx *\fR\fIutmpx\fR);
31 .fi
33 .LP
34 .nf
35 \fBvoid\fR \fBsetutxent\fR(\fBvoid\fR);
36 .fi
38 .LP
39 .nf
40 \fBvoid\fR \fBendutxent\fR(\fBvoid\fR);
41 .fi
43 .LP
44 .nf
45 \fBint\fR \fButmpxname\fR(\fBconst char *\fR\fIfile\fR);
46 .fi
48 .LP
49 .nf
50 \fBvoid\fR \fBgetutmp\fR(\fBstruct utmpx *\fR\fIutmpx\fR, \fBstruct utmp *\fR\fIutmp\fR);
51 .fi
53 .LP
54 .nf
55 \fBvoid\fR \fBgetutmpx\fR(\fBstruct utmp *\fR\fIutmp\fR, \fBstruct utmpx *\fR\fIutmpx\fR);
56 .fi
58 .LP
59 .nf
60 \fBvoid\fR \fBupdwtmp\fR(\fBchar *\fR\fIwfile\fR, \fBstruct utmp *\fR\fIutmp\fR);
61 .fi
63 .LP
64 .nf
65 \fBvoid\fR \fBupdwtmpx\fR(\fBchar *\fR\fIwfilex\fR, \fBstruct utmpx *\fR\fIutmpx\fR);
66 .fi
68 .SH DESCRIPTION
69 .LP
70 These functions provide access to the user accounting database, \fButmpx\fR
71 (see \fButmpx\fR(4)). Entries in the database are described by the definitions
72 and data structures in \fB<utmpx.h>\fR\&.
73 .sp
74 .LP
75 The \fButmpx\fR structure contains the following members:
76 .sp
77 .in +2
78 .nf
79 char                 ut_user[32];   /* user login name */
80 char                 ut_id[4];      /* /etc/inittab id */
81                                     /* (usually line #) */
82 char                 ut_line[32];   /* device name */
83                                     /* (console, lnxx) */
84 pid_t                ut_pid;        /* process id */
85 short                ut_type;       /* type of entry */
86 struct exit_status   ut_exit;       /* exit status of a process */
87                                     /* marked as DEAD_PROCESS */
88 struct timeval       ut_tv;         /* time entry was made */
89 int                  ut_session;    /* session ID, used for */
90                                     /* windowing */
91 short                ut_syslen;     /* significant length of */
92                                     /* ut_host */
93                                     /* including terminating null */
94 char                 ut_host[257];  /* host name, if remote */
95 .fi
96 .in -2
98 .sp
99 .LP
100 The \fBexit_status\fR structure includes the following members:
102 .in +2
104 short   e_termination;   /* termination status */
105 short   e_exit;          /* exit status */
107 .in -2
109 .SS "\fBgetutxent()\fR"
111 The \fBgetutxent()\fR function reads in the next entry from a \fButmpx\fR
112 database. If the database is not already open, it opens it. If it reaches the
113 end of the database, it fails.
114 .SS "\fBgetutxid()\fR"
116 The \fBgetutxid()\fR function searches forward from the current point in the
117 \fButmpx\fR database until it finds an entry with a \fBut_type\fR matching
118 \fIid\fR->\fBut_type\fR, if the type specified is \fBRUN_LVL\fR,
119 \fBBOOT_TIME\fR, \fBDOWN_TIME\fR, \fBOLD_TIME\fR, or \fBNEW_TIME\fR. If the
120 type specified in \fIid\fR is \fBINIT_PROCESS\fR, \fBLOGIN_PROCESS\fR,
121 \fBUSER_PROCESS\fR, or \fBDEAD_PROCESS\fR, then \fBgetutxid()\fR will return a
122 pointer to the first entry whose type is one of these four and whose
123 \fBut_id\fR member matches \fIid\fR->\fBut_id\fR. If the end of database is
124 reached without a match, it fails.
125 .SS "\fBgetutxline()\fR"
127 The \fBgetutxline()\fR function searches forward from the current point in the
128 \fButmpx\fR database until it finds an entry of the type \fBLOGIN_PROCESS\fR or
129 \fBUSER_PROCESS\fR which also has a \fIut_line\fR string matching the
130 \fIline\fR->\fBut_line\fR string.  If the end of the database is reached
131 without a match, it fails.
132 .SS "\fBpututxline()\fR"
134 The \fBpututxline()\fR function writes the supplied \fButmpx\fR structure into
135 the \fButmpx\fR database.  It uses \fBgetutxid()\fR to search forward for the
136 proper place if it finds that it is not already at the proper place.  It is
137 expected that normally the user of \fBpututxline()\fR will have searched for
138 the proper entry using one of the \fBgetutx()\fR routines.  If so,
139 \fBpututxline()\fR will not search.  If \fBpututxline()\fR does not find a
140 matching slot for the new entry, it will add a new entry to the end of the
141 database.  It returns a pointer to the  \fButmpx\fR structure. When called by a
142 non-root user, \fBpututxline()\fR invokes a \fBsetuid()\fR root program to
143 verify and write the entry, since the \fButmpx\fR database is normally writable
144 only by root.  In this event, the \fBut_name\fR member must correspond to the
145 actual user name associated with the process; the  \fBut_type\fR member must be
146 either \fBUSER_PROCESS\fR or \fBDEAD_PROCESS\fR; and the \fBut_line\fR member
147 must be a device special file and be writable by the user.
148 .SS "\fBsetutxent()\fR"
150 The \fBsetutxent()\fR function resets the input stream to the beginning. This
151 should be done before each search for a new entry if it is desired that the
152 entire database be examined.
153 .SS "\fBendutxent()\fR"
155 The \fBendutxent()\fR function closes the currently open database.
156 .SS "\fButmpxname()\fR"
158 The \fButmpxname()\fR function allows the user to change the name of the
159 database file examined from \fB/var/adm/utmpx\fR to any other file, most often
160 \fB/var/adm/wtmpx\fR. If the file does not exist, this will not be apparent
161 until the first attempt to reference the file is made.  The \fButmpxname()\fR
162 function does not open the file, but closes the old file if it is currently
163 open and saves the new file name. The new file name must end with the "x"
164 character to allow the name of the corresponding \fButmp\fR file to be easily
165 obtainable.; otherwise, an error value of \fB0\fR is returned. The function
166 returns \fB1\fR on success.
167 .SS "\fBgetutmp()\fR"
169 The \fBgetutmp()\fR function copies the information stored in the members of
170 the \fButmpx\fR structure to the corresponding members of the \fButmp\fR
171 structure. If the information in any member of  \fButmpx\fR does not fit in the
172 corresponding \fButmp\fR member, the data is silently truncated. (See
173 \fBgetutent\fR(3C) for  \fButmp\fR structure)
174 .SS "\fBgetutmpx()\fR"
176 The \fBgetutmpx()\fR function copies the information stored in the members of
177 the \fButmp\fR structure to the corresponding members of the \fButmpx\fR
178 structure. (See \fBgetutent\fR(3C) for  \fButmp\fR structure)
179 .SS "\fBupdwtmp()\fR"
181 The \fBupdwtmp()\fR function can be used in two ways.
184 If \fIwfile\fR is \fB/var/adm/wtmp\fR, the \fButmp\fR format record supplied by
185 the caller is converted to a \fButmpx \fRformat record and the
186 \fB/var/adm/wtmpx\fR file is updated (because the \fB/var/adm/wtmp\fR file no
187 longer exists, operations on \fBwtmp\fR are converted to operations on
188 \fBwtmpx\fR by the library functions.
191 If \fIwfile\fR is a file other than \fB/var/adm/wtmp\fR, it is assumed to be an
192 old file in \fButmp\fR format and is updated directly with the \fButmp\fR
193 format record supplied by the caller.
194 .SS "\fBupdwtmpx()\fR"
196 The \fBupdwtmpx()\fR function writes the contents of the \fButmpx\fR structure
197 pointed to by \fIutmpx\fR to the database.
198 .SS "\fButmpx\fR structure"
200 The values of the \fBe_termination\fR and \fBe_exit\fR members of the
201 \fBut_exit\fR structure are valid only for records of type \fBDEAD_PROCESS\fR.
202 For \fButmpx\fR entries created by \fBinit\fR(8),  these values are set
203 according to the result of the \fBwait()\fR call that \fBinit\fR performs on
204 the process when the process exits. See the \fBwait\fR(3C), manual page for the
205 values \fBinit\fR uses. Applications creating \fButmpx\fR entries can set
206 \fBut_exit\fR values using the following code example:
208 .in +2
210 u->ut_exit.e_termination = WTERMSIG(process->p_exit)
211 u->ut_exit.e_exit = WEXITSTATUS(process->p_exit)
213 .in -2
217 See \fBwait.h\fR(3HEAD) for descriptions of the \fBWTERMSIG\fR and
218 \fBWEXITSTATUS\fR macros.
221 The \fBut_session\fR member is not acted upon by the operating system. It is
222 used by applications interested in creating \fButmpx\fR entries.
225 For records of type \fBUSER_PROCESS\fR, the \fBnonuserx()\fR macro uses
226 value of the \fBut_exit.e_exit\fR member to mark \fButmpx\fR entries as real
227 logins (as opposed to multiple xterms started by the same user on a window
228 system). This allows the system utilities that display users to obtain an
229 accurate indication of the number of actual users, while still permitting each
230 \fBpty\fR to have a \fButmpx\fR record (as most applications expect). The
231 \fBNONROOT_USRX\fR macro defines the value that \fBlogin\fR places in the
232 \fBut_exit.e_exit\fR member.
233 .SH RETURN VALUES
235 Upon successful completion, \fBgetutxent()\fR, \fBgetutxid()\fR, and
236 \fBgetutxline()\fR each return a pointer to a \fButmpx\fR structure containing
237 a copy of the requested entry in the user accounting database.  Otherwise a
238 null pointer is returned.
241 The return value may point to a static area which is overwritten by a
242 subsequent call to \fBgetutxid ()\fR or \fBgetutxline()\fR.
245 Upon successful completion, \fBpututxline()\fR returns a pointer to a
246 \fButmpx\fR structure containing a copy of the entry added to the user
247 accounting database.  Otherwise a null pointer is returned.
250 The \fBendutxent()\fR and \fBsetutxent()\fR functions return no value.
253 A null pointer is returned upon failure to read, whether for permissions or
254 having reached the end of file, or upon failure to write.
255 .SH USAGE
257 These functions use buffered standard I/O for input, but \fBpututxline()\fR
258 uses an unbuffered write to avoid race conditions between processes trying to
259 modify the \fButmpx\fR and \fBwtmpx\fR files.
262 Applications should not access the \fButmpx\fR and \fBwtmpx\fR databases
263 directly, but should use these functions to ensure that these databases are
264 maintained consistently.
265 .SH FILES
266 .ne 2
268 \fB\fB/var/adm/utmpx\fR\fR
270 .RS 18n
271 user access and accounting information
275 .ne 2
277 \fB\fB/var/adm/wtmpx\fR\fR
279 .RS 18n
280 history of user access and accounting information
283 .SH ATTRIBUTES
285 See \fBattributes\fR(5) for descriptions of the following attributes:
290 box;
291 c | c
292 l | l .
293 ATTRIBUTE TYPE  ATTRIBUTE VALUE
295 Interface Stability     See below.
297 MT-Level        Unsafe
302 The \fBendutxent()\fR, \fBgetutxent()\fR, \fBgetutxid()\fR, \fBgetutxline()\fR,
303 \fBpututxline()\fR, and \fBsetutxent()\fR functions are Standard.
304 .SH SEE ALSO
306 \fBgetutent\fR(3C), \fBttyslot\fR(3C), \fBwait\fR(3C), \fBwait.h\fR(3HEAD),
307 \fButmpx\fR(4), \fBattributes\fR(5), \fBstandards\fR(5)
308 .SH NOTES
310 The most current entry is saved in a static structure.  Multiple accesses
311 require that it be copied before further accesses are made. On each call to
312 either \fBgetutxid()\fR or \fBgetutxline()\fR, the routine examines the static
313 structure before performing more I/O. If the contents of the static structure
314 match what it is searching for, it looks no further. For this reason, to use
315 \fBgetutxline()\fR to search for multiple occurrences it would be necessary to
316 zero out the static after each success, or \fBgetutxline()\fR would just return
317 the same structure over and over again. There is one exception to the rule
318 about emptying the structure before further reads are done.  The implicit read
319 done by \fBpututxline()\fR (if it finds that it is not already at the correct
320 place in the file) will not hurt the contents of the static structure returned
321 by the \fBgetutxent()\fR, \fBgetutxid()\fR, or \fBgetutxline()\fR routines, if
322 the user has just modified those contents and passed the pointer back to
323 \fBpututxline()\fR.