aboutsummaryrefslogtreecommitdiff
path: root/korean/han/files/patch-ag
blob: 66ac5d73c41c9e5c67a86f9616461fa33680ec43 (plain) (blame)
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
--- src/utmp.c.orig	Fri Jan 24 09:37:28 1997
+++ src/utmp.c	Sat Apr 26 21:50:30 1997
@@ -41,20 +41,32 @@
 #include	<utmp.h>
 #include	<grp.h>
 #include	<sys/stat.h>
+#if defined(__FreeBSD__)
+#include	<ttyent.h>
+#endif
 
+#if !defined(__FreeBSD__)
 static int ttyGid;
+#else
+static gid_t ttyGid;
+static int ts;
+#endif
 
 void	SetUtmp(char *tty)
 {
-#ifdef linux
 	struct utmp	utmp;
 	struct passwd	*pw;
 	struct group	*ttygrp;
 	char	*tn;
+#if defined(__FreeBSD__)
+	struct ttyent	*ttyp;
+	int fd, i;
+#endif
 
 	pw = getpwuid(getuid());
 	tn = rindex(tty, '/') + 1;
 	memset((char *)&utmp, 0, sizeof(utmp));
+#if !defined(__FreeBSD__)
 	strncpy(utmp.ut_id, tn + 3, sizeof(utmp.ut_id));
 	utmp.ut_type = DEAD_PROCESS;
 	setutent();
@@ -66,21 +78,43 @@
 	time(&(utmp.ut_time));
 	pututline(&utmp);
 	endutent();
+#else
+	time(&(utmp.ut_time));
+	strncpy(utmp.ut_name, pw->pw_name, sizeof(utmp.ut_name));
+	strncpy(utmp.ut_line, tn, sizeof(utmp.ut_line));
+	setttyent();
+	ts = 0;
+	for (i = 1; (ttyp = getttyent()); ++i)
+	    if (!strcmp(ttyp->ty_name,tn)) {
+		ts = i;
+		break;
+	    }
+	endttyent();
+	if (ts > 0 && (fd = open(_PATH_UTMP, O_WRONLY|O_CREAT, 0644)) >= 0) {
+	    lseek(fd, (ts*sizeof(struct utmp)), L_SET);
+	    write(fd, &utmp, sizeof(struct utmp));
+	    close(fd);
+	}
+#endif
 	if ((ttygrp = getgrnam("tty")) != NULL)
 		ttyGid = ttygrp->gr_gid;
 	else
 		ttyGid = -1;
 	chmod(tty, 0622);
 	chown(tty, getuid(), ttyGid);
-#endif
 }
 
 void	ResetUtmp(char *tty)
 {
-#ifdef linux
+#if !defined(__FreeBSD__)
 	struct utmp	utmp, *utp;
 	char	*tn;
+#else
+	struct utmp	utmp;
+	int fd;
+#endif
 
+#if !defined(__FreeBSD__)
 	tn = rindex(tty, '/') + 4;
 	memset((char *)&utmp, 0, sizeof(utmp));
 	strncpy(utmp.ut_id, tn, sizeof(utmp.ut_id));
@@ -93,7 +127,19 @@
 	time(&(utp->ut_time));
 	pututline(utp);
 	endutent();
+#else
+	if (ts > 0 && (fd = open(_PATH_UTMP, O_RDWR, 0)) >= 0) {
+	    lseek(fd, (ts*sizeof(struct utmp)), L_SET);
+	    if (read(fd, &utmp, sizeof(struct utmp)) == sizeof(struct utmp)) {
+		bzero(utmp.ut_name, sizeof(utmp.ut_name));
+		bzero(utmp.ut_host, sizeof(utmp.ut_host));
+		time(&utmp.ut_time);
+		lseek(fd, (ts*sizeof(struct utmp)), L_SET);
+		write(fd, &utmp, sizeof(struct utmp));
+	    }
+	    close(fd);
+	}
+#endif
 	chmod(tty, 0600);
 	chown(tty, 0, ttyGid);
-#endif
 }