1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License, Version 1.0 only
   6  * (the "License").  You may not use this file except in compliance
   7  * with the License.
   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
  24  *
  25  * Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
  26  * Use is subject to license terms.
  27  */
  28 
  29 /*      Copyright (c) 1983,1984,1985,1986,1987,1988,1989 AT&T       */
  30 /*        All Rights Reserved   */
  31 
  32 /*
  33  * Portions of this source code were derived from Berkeley 4.3 BSD
  34  * under license from the Regents of the University of California.
  35  */
  36 
  37 #ifndef _UTMPX_H
  38 #define _UTMPX_H
  39 
  40 #include <sys/feature_tests.h>
  41 #include <sys/types.h>
  42 #include <sys/time.h>
  43 #include <utmp.h>
  44 
  45 #ifdef  __cplusplus
  46 extern "C" {
  47 #endif
  48 
  49 #define _UTMPX_FILE     "/var/adm/utmpx"
  50 #define _WTMPX_FILE     "/var/adm/wtmpx"
  51 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
  52 #define UTMPX_FILE      _UTMPX_FILE
  53 #define WTMPX_FILE      _WTMPX_FILE
  54 #endif
  55 
  56 #define ut_name ut_user
  57 #define ut_xtime ut_tv.tv_sec
  58 
  59 /*
  60  * This data structure describes the utmpx entries returned by
  61  * the getutxent(3c) family of APIs.  It does not (necessarily)
  62  * correspond to the contents of the utmpx or wtmpx files.
  63  *
  64  * Applications should only interact with this subsystem via
  65  * the getutxent(3c) family of APIs.
  66  */
  67 struct utmpx {
  68         char    ut_user[32];            /* user login name */
  69         char    ut_id[4];               /* inittab id */
  70         char    ut_line[32];            /* device name (console, lnxx) */
  71         pid_t   ut_pid;                 /* process id */
  72         short   ut_type;                /* type of entry */
  73 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
  74         struct exit_status ut_exit;     /* process termination/exit status */
  75 #else
  76         struct ut_exit_status ut_exit;  /* process termination/exit status */
  77 #endif
  78         struct timeval ut_tv;           /* time entry was made */
  79         int     ut_session;             /* session ID, used for windowing */
  80 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
  81         int     pad[5];                 /* reserved for future use */
  82 #else
  83         int     __pad[5];               /* reserved for future use */
  84 #endif
  85         short   ut_syslen;              /* significant length of ut_host */
  86                                         /*   including terminating null */
  87         char    ut_host[257];           /* remote host name */
  88 };
  89 
  90 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
  91 
  92 #include <sys/types32.h>
  93 #include <inttypes.h>
  94 
  95 /*
  96  * This data structure describes the utmp *file* contents using
  97  * fixed-width data types.  It should only be used by the implementation.
  98  *
  99  * Applications should use the getutxent(3c) family of routines to interact
 100  * with this database.
 101  */
 102 
 103 struct futmpx {
 104         char    ut_user[32];            /* user login name */
 105         char    ut_id[4];               /* inittab id */
 106         char    ut_line[32];            /* device name (console, lnxx) */
 107         pid32_t ut_pid;                 /* process id */
 108         int16_t ut_type;                /* type of entry */
 109         struct {
 110                 int16_t e_termination;  /* process termination status */
 111                 int16_t e_exit;         /* process exit status */
 112         } ut_exit;                      /* exit status of a process */
 113         struct timeval32 ut_tv;         /* time entry was made */
 114         int32_t ut_session;             /* session ID, user for windowing */
 115         int32_t pad[5];                 /* reserved for future use */
 116         int16_t ut_syslen;              /* significant length of ut_host */
 117         char    ut_host[257];           /* remote host name */
 118 };
 119 
 120 #define MOD_WIN         10
 121 
 122 /*      Define and macro for determing if a normal user wrote the entry */
 123 /*      and marking the utmpx entry as a normal user */
 124 #define NONROOT_USRX    2
 125 #define nonuserx(utx)   ((utx).ut_exit.e_exit == NONROOT_USRX ? 1 : 0)
 126 #define setuserx(utx)   ((utx).ut_exit.e_exit = NONROOT_USRX)
 127 
 128 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
 129 
 130 extern void endutxent(void);
 131 extern struct utmpx *getutxent(void);
 132 extern struct utmpx *getutxid(const struct utmpx *);
 133 extern struct utmpx *getutxline(const struct utmpx *);
 134 extern struct utmpx *pututxline(const struct utmpx *);
 135 extern void setutxent(void);
 136 
 137 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
 138 extern int utmpxname(const char *);
 139 extern struct utmpx *makeutx(const struct utmpx *);
 140 extern struct utmpx *modutx(const struct utmpx *);
 141 extern void getutmp(const struct utmpx *, struct utmp *);
 142 extern void getutmpx(const struct utmp *, struct utmpx *);
 143 extern void updwtmp(const char *, struct utmp *);
 144 extern void updwtmpx(const char *, struct utmpx *);
 145 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
 146 
 147 #ifdef  __cplusplus
 148 }
 149 #endif
 150 
 151 #endif  /* _UTMPX_H */