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
|
/*
* ptyint_update_wtmp: Update wtmp.
*
* Copyright 1995, 2001 by the Massachusetts Institute of Technology.
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby
* granted, provided that the above copyright notice appear in all
* copies and that both that copyright notice and this permission
* notice appear in supporting documentation, and that the name of
* M.I.T. not be used in advertising or publicity pertaining to
* distribution of the software without specific, written prior
* permission. Furthermore if you modify this software you must label
* your software as modified software and not distribute it in such a
* fashion that it might be confused with the original M.I.T. software.
* M.I.T. makes no representations about the suitability
* of this software for any purpose. It is provided "as is" without
* express or implied warranty.
*
*/
#include <com_err.h>
#include "libpty.h"
#include "pty-int.h"
#if !defined(WTMP_FILE) && defined(_PATH_WTMP)
#define WTMP_FILE _PATH_WTMP
#endif
#if !defined(WTMPX_FILE) && defined(_PATH_WTMPX)
#define WTMPX_FILE _PATH_WTMPX
#endif
/* if it is *still* missing, assume SunOS */
#ifndef WTMP_FILE
#define WTMP_FILE "/usr/adm/wtmp"
#endif
#ifdef HAVE_SETUTXENT
/*
* Welcome to conditional salad.
*
* This really wants to take a (const struct utmpx *) but updutmpx()
* on Solaris at least doesn't take a const argument. *sigh*
*/
long
ptyint_update_wtmpx(struct utmpx *ent)
{
#if !(defined(HAVE_UPDWTMPX) && defined(WTMPX_FILE))
struct utmp ut;
#endif
#if defined(HAVE_UPDWTMPX) && defined(WTMPX_FILE)
updwtmpx(WTMPX_FILE, ent);
return 0;
#else
#ifdef HAVE_GETUTMP
getutmp(ent, &ut);
#else /* Emulate getutmp(). Yuck. */
memset(&ut, 0, sizeof(ut));
strncpy(ut.ut_name, ent->ut_user, sizeof(ut.ut_name));
strncpy(ut.ut_line, ent->ut_line, sizeof(ut.ut_line));
ut.ut_time = ent->ut_tv.tv_sec;
#ifdef HAVE_STRUCT_UTMP_UT_HOST
strncpy(ut.ut_host, ent->ut_host, sizeof(ut.ut_host));
ut.ut_host[sizeof(ut.ut_host) - 1] = '\0';
#ifdef HAVE_STRUCT_UTMP_UT_SYSLEN
ut.ut_syslen = strlen(ut.ut_host) + 1;
#endif
#endif
#ifdef HAVE_STRUCT_UTMP_UT_ID
strncpy(ut.ut_id, ent->ut_id, sizeof(ut.ut_id));
#endif
#ifdef HAVE_STRUCT_UTMP_UT_PID
ut.ut_pid = ent->ut_pid;
#endif
#ifdef HAVE_STRUCT_UTMP_UT_TYPE
ut.ut_type = ent->ut_type;
#endif
#if defined(PTY_UTMP_E_EXIT) && defined(PTY_UTMPX_E_EXIT)
ut.ut_exit.PTY_UTMP_E_EXIT = ent->ut_exit.PTY_UTMPX_E_EXIT;
ut.ut_exit.PTY_UTMP_E_TERMINATION =
ent->ut_exit.PTY_UTMPX_E_TERMINATION
#endif
#endif /* !HAVE_GETUTMP */
return ptyint_update_wtmp(&ut);
#endif /* !(defined(WTMPX_FILE) && defined(HAVE_UPDWTMPX)) */
}
#else /* !HAVE_SETUTXENT */
long
ptyint_update_wtmp(struct utmp *ent)
{
#ifndef HAVE_UPDWTMP
int fd;
struct stat statb;
#endif
#ifdef HAVE_UPDWTMP
updwtmp(WTMP_FILE, ent);
#else
fd = open(WTMP_FILE, O_WRONLY | O_APPEND, 0);
if (fd != -1 && !fstat(fd, &statb)) {
if (write(fd, (char *)ent, sizeof(struct utmp))
!= sizeof(struct utmp))
(void)ftruncate(fd, statb.st_size);
(void)close(fd);
}
#endif
/*
* no current failure cases; file not found is not failure!
*/
return 0;
}
#endif
|