This repository was archived by the owner on Feb 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathptylogs.c
More file actions
127 lines (113 loc) · 2.16 KB
/
ptylogs.c
File metadata and controls
127 lines (113 loc) · 2.16 KB
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
#include <sys/types.h>
#include <sys/file.h>
#include <utmp.h>
#include "fmt.h"
#include "config/utmpfile.h"
#include "config/wtmpfile.h"
#include "config/sysv.h" /*XXX*/
#include "ptymisc.h"
#include "ptylogs.h"
extern int flagxutmp; /*XXX*/
extern int flagxwtmp; /*XXX*/
/* utmp and wtmp make about as much sense as /etc/passwd: not much. */
int utmp_on(ext,name,host,date)
char *ext;
char *name;
char *host;
long date;
{
struct utmp ut;
struct utmp xt;
int fd;
int i;
char *t;
if (!flagxutmp)
return 0;
/* XXXX: This uses sequential allocation. See utmpinit. */
t = ut.ut_line;
t += fmt_strncpy(t,"tty",0);
*t++ = ext[0];
*t++ = ext[1];
*t = 0;
strncpy(ut.ut_name,name,sizeof(ut.ut_name));
#ifndef SYSV
strncpy(ut.ut_host,host,sizeof(ut.ut_host));
#endif
ut.ut_time = date;
if ((fd = open(UTMP_FILE,O_RDWR)) == -1)
return -1;
i = 0;
while (bread(fd,(char *) &xt,sizeof(xt)) == sizeof(xt)) /* XXX: should buffer */
{
if (!strncmp(xt.ut_line,ut.ut_line,sizeof(ut.ut_line)))
{
if (lseek(fd,i * (long) sizeof(xt),L_SET) == -1)
{
close(fd);
return -1;
}
i = -1;
break;
}
++i;
}
if (i != -1)
{
/* We have to reopen to avoid a race with other end-of-utmp entries. */
close(fd);
if ((fd = open(UTMP_FILE,O_RDWR | O_APPEND)) == -1)
return -1;
}
if (bwrite(fd,(char *) &ut,sizeof(ut)) < sizeof(ut))
{
close(fd);
return -1;
}
close(fd);
return 0;
}
int utmp_off(ext,host,date)
char *ext;
char *host;
long date;
{
utmp_on(ext,"",host,date);
}
int wtmp_on(ext,name,host,date)
char *ext;
char *name;
char *host;
long date;
{
struct utmp wt;
int fd;
char *t;
if (!flagxwtmp)
return 0;
t = wt.ut_line;
t += fmt_strncpy(t,"tty",0);
*t++ = ext[0];
*t++ = ext[1];
*t = 0;
strncpy(wt.ut_name,name,sizeof(wt.ut_name));
#ifndef SYSV
strncpy(wt.ut_host,host,sizeof(wt.ut_host));
#endif
wt.ut_time = date;
if ((fd = open(WTMP_FILE,O_WRONLY | O_APPEND)) == -1)
return -1;
if (bwrite(fd,(char *) &wt,sizeof(wt)) < sizeof(wt))
{
close(fd);
return -1;
}
close(fd);
return 0;
}
int wtmp_off(ext,host,date)
char *ext;
char *host;
long date;
{
wtmp_on(ext,"",host,date);
}