]> git.pld-linux.org Git - packages/AfterStep-APPS.git/blame - aterm-utmp.patch
- massive attack s/pld.org.pl/pld-linux.org/
[packages/AfterStep-APPS.git] / aterm-utmp.patch
CommitLineData
f605c4c0
JR
1--- aterm-0.3.4/src/utmp.c.ewt Wed Mar 24 22:28:48 1999
2+++ aterm-0.3.4/src/utmp.c Wed Mar 24 22:42:32 1999
3@@ -42,203 +42,17 @@
4 static const char rcsid[] = "$Id$";
5 #endif
6
7-#include "rxvt.h" /* NECESSARY */
8-
9-/*
10- * HAVE_SETUTENT corresponds to SYSV-style utmp support.
11- * Without it corresponds to using BSD utmp support.
12- * SYSV-style utmp support is further divided in normal utmp support
13- * and utmpx support (Solaris 2.x) by HAVE_UTMPX_H
14- */
15-
16-/*
17- * update wtmp entries - only for SYSV style UTMP systems
18- */
19-#ifdef UTMP_SUPPORT
20-static char ut_id[5]; /* remember if entry to utmp made */
21-# ifndef USE_SYSV_UTMP
22-static int utmp_pos; /* BSD position of utmp-stamp */
23-# endif
24-#endif
25-
26-/* ------------------------------------------------------------------------- */
27-#ifndef HAVE_UTMPX_H /* supposedly we have updwtmpx ? */
28-#ifdef WTMP_SUPPORT
29-/* PROTO */
30-void
31-rxvt_update_wtmp(char *fname, struct utmp *putmp)
32-{
33- int fd, retry = 10; /* 10 attempts at locking */
34- struct flock lck; /* fcntl locking scheme */
35-
36- if ((fd = open(fname, O_WRONLY | O_APPEND, 0)) < 0)
37- return;
38-
39- lck.l_whence = SEEK_END; /* start lock at current eof */
40- lck.l_len = 0; /* end at ``largest possible eof'' */
41- lck.l_start = 0;
42- lck.l_type = F_WRLCK; /* we want a write lock */
43-
44- while (retry--)
45- /* attempt lock with F_SETLK - F_SETLKW would cause a deadlock! */
46- if ((fcntl(fd, F_SETLK, &lck) < 0) && errno != EACCESS) {
47- close(fd);
48- return; /* failed for unknown reason: give up */
49- }
50- write(fd, putmp, sizeof(struct utmp));
51-
52-/* unlocking the file */
53- lck.l_type = F_UNLCK;
54- fcntl(fd, F_SETLK, &lck);
55-
56- close(fd);
57-}
58-#endif /* WTMP_SUPPORT */
59-#endif /* !HAVE_UTMPX_H */
60-/* ------------------------------------------------------------------------- */
61-#ifdef UTMP_SUPPORT
62 /*
63 * make a utmp entry
64 */
65 /* PROTO */
66 void
67-makeutent(const char *pty, const char *hostname)
68+makeutent(const char *pty, const char *hostname, int fd)
69 {
70-
71- struct passwd *pwent = getpwuid(getuid());
72- UTMP utmp;
73-
74-#ifndef USE_SYSV_UTMP
75-/*
76- * BSD style utmp entry
77- * ut_line, ut_name, ut_host, ut_time
78- */
79- int i;
80- FILE *fd0, *fd1;
81- char buf[256], name[256];
82-
83-#else
84-/*
85- * SYSV style utmp entry
86- * ut_user, ut_id, ut_line, ut_pid, ut_type, ut_exit, ut_time
87- */
88- char *colon;
89-
90-#endif /* !USE_SYSV_UTMP */
91-
92-/* BSD naming is of the form /dev/tty?? or /dev/pty?? */
93-
94- MEMSET(&utmp, 0, sizeof(UTMP));
95- if (!strncmp(pty, "/dev/", 5))
96- pty += 5; /* skip /dev/ prefix */
97- if (!strncmp(pty, "pty", 3) || !strncmp(pty, "tty", 3))
98- STRNCPY(ut_id, (pty + 3), sizeof(ut_id));
99- else
100-#ifndef USE_SYSV_UTMP
101- {
102- print_error("can't parse tty name \"%s\"", pty);
103- ut_id[0] = '\0'; /* entry not made */
104- return;
105- }
106-
107- STRNCPY(utmp.ut_line, pty, sizeof(utmp.ut_line));
108- STRNCPY(utmp.ut_name, (pwent && pwent->pw_name) ? pwent->pw_name : "?",
109- sizeof(utmp.ut_name));
110- STRNCPY(utmp.ut_host, hostname, sizeof(utmp.ut_host));
111- utmp.ut_time = time(NULL);
112-
113- if ((fd0 = fopen(UTMP_FILENAME, "r+")) == NULL)
114- ut_id[0] = '\0'; /* entry not made */
115- else {
116- utmp_pos = -1;
117- if ((fd1 = fopen(TTYTAB_FILENAME, "r")) != NULL) {
118- for (i = 1; (fgets(buf, sizeof(buf), fd1) != NULL); i++) {
119- if (*buf == '#' || sscanf(buf, "%s", name) != 1)
120- continue;
121- if (!strcmp(utmp.ut_line, name)) {
122- fclose(fd1);
123- utmp_pos = i * sizeof(struct utmp);
124-
125- break;
126- }
127- }
128- fclose(fd1);
129- }
130- if (utmp_pos < 0)
131- ut_id[0] = '\0'; /* entry not made */
132- else {
133- fseek(fd0, utmp_pos, 0);
134- fwrite(&utmp, sizeof(UTMP), 1, fd0);
135- }
136- fclose(fd0);
137- }
138-
139-#else /* USE_SYSV_UTMP */
140- {
141- int n;
142-
143- if (sscanf(pty, "pts/%d", &n) == 1)
144- sprintf(ut_id, "vt%02x", (n % 256)); /* sysv naming */
145- else {
146- print_error("can't parse tty name \"%s\"", pty);
147- ut_id[0] = '\0'; /* entry not made */
148- return;
149- }
150- }
151-
152- utmpname(UTMP_FILENAME);
153-
154- setutent(); /* XXX: should be unnecessaray */
155-
156- STRNCPY(utmp.ut_id, ut_id, sizeof(utmp.ut_id));
157- utmp.ut_type = DEAD_PROCESS;
158- (void)getutid(&utmp); /* position to entry in utmp file */
159-
160-/* set up the new entry */
161- utmp.ut_type = USER_PROCESS;
162-#ifndef linux
163- utmp.ut_exit.e_exit = 2;
164-#endif
165- STRNCPY(utmp.ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?",
166- sizeof(utmp.ut_user));
167- STRNCPY(utmp.ut_id, ut_id, sizeof(utmp.ut_id));
168- STRNCPY(utmp.ut_line, pty, sizeof(utmp.ut_line));
169-
170-#ifdef HAVE_UTMP_HOST
171- STRNCPY(utmp.ut_host, hostname, sizeof(utmp.ut_host));
172-#ifndef linux
173- if ((colon = strrchr(utmp.ut_host, ':')) != NULL)
174- *colon = '\0';
175-#endif
176-#endif /* HAVE_UTMP_HOST */
177-
178-/* ut_name is normally the same as ut_user, but .... */
179- STRNCPY(utmp.ut_name, (pwent && pwent->pw_name) ? pwent->pw_name : "?",
180- sizeof(utmp.ut_name));
181-
182- utmp.ut_pid = getpid();
183-
184-#ifdef HAVE_UTMPX_H
185- utmp.ut_session = getsid(0);
186- utmp.ut_tv.tv_sec = time(NULL);
187- utmp.ut_tv.tv_usec = 0;
188-#else
189- utmp.ut_time = time(NULL);
190-#endif /* HAVE_UTMPX_H */
191-
192- pututline(&utmp);
193-
194-#ifdef WTMP_SUPPORT
195- update_wtmp(WTMP_FILENAME, &utmp);
196-#endif
197-
198- endutent(); /* close the file */
199-#endif /* !USE_SYSV_UTMP */
200+ addToUtmp(pty, hostname, fd);
201 }
202-#endif /* UTMP_SUPPORT */
203
204 /* ------------------------------------------------------------------------- */
205-#ifdef UTMP_SUPPORT
206 /*
207 * remove a utmp entry
208 */
209@@ -246,52 +60,5 @@
210 void
211 cleanutent(void)
212 {
213- UTMP utmp;
214-
215-#ifndef USE_SYSV_UTMP
216- FILE *fd;
217-
218- if (ut_id[0] && ((fd = fopen(UTMP_FILENAME, "r+")) != NULL)) {
219- MEMSET(&utmp, 0, sizeof(struct utmp));
220-
221- fseek(fd, utmp_pos, 0);
222- fwrite(&utmp, sizeof(struct utmp), 1, fd);
223-
224- fclose(fd);
225- }
226-#else /* USE_SYSV_UTMP */
227- UTMP *putmp;
228-
229- if (!ut_id[0])
230- return; /* entry not made */
231-
232- utmpname(UTMP_FILENAME);
233- MEMSET(&utmp, 0, sizeof(UTMP));
234- STRNCPY(utmp.ut_id, ut_id, sizeof(utmp.ut_id));
235- utmp.ut_type = USER_PROCESS;
236-
237- setutent(); /* XXX: should be unnecessaray */
238-
239- putmp = getutid(&utmp);
240- if (!putmp || putmp->ut_pid != getpid())
241- return;
242-
243- putmp->ut_type = DEAD_PROCESS;
244-
245-#ifdef HAVE_UTMPX_H
246- putmp->ut_session = getsid(0);
247- putmp->ut_tv.tv_sec = time(NULL);
248- putmp->ut_tv.tv_usec = 0;
249-#else /* HAVE_UTMPX_H */
250- putmp->ut_time = time(NULL);
251-#endif /* HAVE_UTMPX_H */
252- pututline(putmp);
253-
254-#ifdef WTMP_SUPPORT
255- update_wtmp(WTMP_FILENAME, putmp);
256-#endif
257-
258- endutent();
259-#endif /* !USE_SYSV_UTMP */
260+ removeFromUtmp();
261 }
262-#endif
263--- aterm-0.3.4/src/command.c.ewt Wed Mar 24 22:30:36 1999
264+++ aterm-0.3.4/src/command.c Wed Mar 24 22:31:18 1999
265@@ -1037,7 +1037,7 @@
266 #ifdef UTMP_SUPPORT
267 privileges(RESTORE);
268 if (!(Options & Opt_utmpInhibit))
269- makeutent(ttydev, display_name); /* stamp /etc/utmp */
270+ makeutent(ttydev, display_name, ptyfd); /* stamp /etc/utmp */
271 privileges(IGNORE);
272 #endif
273
274--- aterm-0.3.4/src/Makefile.in.ewt Wed Mar 24 22:31:24 1999
275+++ aterm-0.3.4/src/Makefile.in Wed Mar 24 22:31:33 1999
276@@ -45,7 +45,7 @@
277 all: aterm
278
279 aterm: version.h $(PROS) $(OBJS)
280- $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) $(XLIB) $(DLIB)
281+ $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) $(XLIB) $(DLIB) -lutempter
282
283 .c.pro:
284 $(SED) -n -f $(srcdir)/makeprotos-sed $< > $@
This page took 0.127091 seconds and 4 git commands to generate.