summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTom Yu <tlyu@mit.edu>2001-07-02 21:58:00 +0000
committerTom Yu <tlyu@mit.edu>2001-07-02 21:58:00 +0000
commit76c660f9c2d17707678d41b6e5b0270a322a5a5f (patch)
tree04e5c6ab5fcdaea22ce8856a361e9076d82a1b1b /src
parent9290f6560a540ba9252433828c608c83035ba823 (diff)
downloadkrb5-76c660f9c2d17707678d41b6e5b0270a322a5a5f.tar.gz
krb5-76c660f9c2d17707678d41b6e5b0270a322a5a5f.tar.xz
krb5-76c660f9c2d17707678d41b6e5b0270a322a5a5f.zip
* update_utmp.c (pty_update_utmp): Remember to chop off leading
"/dev/" for the non-sysV case. Handle lseek() returning non-zero yet non-negative values (it usually does... :-), so that we can actually write somewhere not at the beginning of the utmp file if necessary. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@13548 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src')
-rw-r--r--src/util/pty/ChangeLog8
-rw-r--r--src/util/pty/update_utmp.c21
2 files changed, 22 insertions, 7 deletions
diff --git a/src/util/pty/ChangeLog b/src/util/pty/ChangeLog
index 39797d41e..64842e2dd 100644
--- a/src/util/pty/ChangeLog
+++ b/src/util/pty/ChangeLog
@@ -1,3 +1,11 @@
+2001-07-02 Tom Yu <tlyu@mit.edu>
+
+ * update_utmp.c (pty_update_utmp): Remember to chop off leading
+ "/dev/" for the non-sysV case. Handle lseek() returning non-zero
+ yet non-negative values (it usually does... :-), so that we can
+ actually write somewhere not at the beginning of the utmp file if
+ necessary.
+
2001-06-28 Ken Raeburn <raeburn@mit.edu>
* update_utmp.c (pty_update_utmp): Don't copy host if it's a null
diff --git a/src/util/pty/update_utmp.c b/src/util/pty/update_utmp.c
index 21f1fab6d..af4e9874d 100644
--- a/src/util/pty/update_utmp.c
+++ b/src/util/pty/update_utmp.c
@@ -636,7 +636,10 @@ pty_update_utmp(int process_type, int pid, const char *username,
const char *line, const char *host, int flags)
{
struct utmp ent, ut;
+ const char *cp;
int tty, lc, fd;
+ off_t seekpos;
+ ssize_t ret;
struct stat statb;
memset(&ent, 0, sizeof(ent));
@@ -645,10 +648,13 @@ pty_update_utmp(int process_type, int pid, const char *username,
strncpy(ent.ut_host, host, sizeof(ent.ut_host));
#endif
strncpy(ent.ut_name, username, sizeof(ent.ut_name));
- strncpy(ent.ut_line, line, sizeof(ent.ut_line));
+ cp = line;
+ if (strncmp(cp, "/dev/", sizeof("/dev/") - 1) == 0)
+ cp += sizeof("/dev/") - 1;
+ strncpy(ent.ut_line, cp, sizeof(ent.ut_line));
(void)time(&ent.ut_time);
- if (flags & PTY_TTYSLOT_USABLE)
+ if (flags & PTY_TTYSLOT_USABLE)
tty = ttyslot();
else {
tty = -1;
@@ -656,8 +662,8 @@ pty_update_utmp(int process_type, int pid, const char *username,
if (fd == -1)
return errno;
for (lc = 0; ; lc++) {
- if (lseek(fd, (off_t)(lc * sizeof(struct utmp)),
- SEEK_SET))
+ seekpos = lseek(fd, (off_t)(lc * sizeof(struct utmp)), SEEK_SET);
+ if (seekpos != (off_t)(lc * sizeof(struct utmp)))
break;
if (read(fd, (char *) &ut, sizeof(struct utmp))
!= sizeof(struct utmp))
@@ -677,12 +683,13 @@ pty_update_utmp(int process_type, int pid, const char *username,
close(fd);
return 0;
}
- if (lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET)) {
+ seekpos = lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET);
+ if (seekpos != (off_t)(tty * sizeof(struct utmp))) {
close(fd);
return 0;
}
- if (write(fd, (char *)&ent, sizeof(struct utmp))
- != sizeof(struct utmp)) {
+ ret = write(fd, (char *)&ent, sizeof(struct utmp));
+ if (ret != sizeof(struct utmp)) {
ftruncate(fd, statb.st_size);
}
close(fd);