'\" 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 "27 Oct 1998" "SunOS 5.11" "Standard C Library Functions" .SH NAME getutent, getutid, getutline, pututline, setutent, endutent, utmpname \- user accounting database functions .SH SYNOPSIS .LP .nf #include \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 .sp .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\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" .sp .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" .sp .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" .sp .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" .sp .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 the 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" .sp .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" .sp .LP The \fBendutent()\fR function closes the currently open database. .SS "\fButmpname()\fR" .sp .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 .sp .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 .sp .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 .sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPEATTRIBUTE VALUE _ MT-LevelUnsafe .TE .SH SEE ALSO .sp .LP \fBgetutxent\fR(3C), \fBttyslot\fR(3C), \fButmpx\fR(4), \fBattributes\fR(5) .SH NOTES .sp .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.