From: Tom Yu Date: Mon, 2 Jul 2001 21:58:00 +0000 (+0000) Subject: * update_utmp.c (pty_update_utmp): Remember to chop off leading X-Git-Tag: krb5-1.3-alpha1~1250 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=76c660f9c2d17707678d41b6e5b0270a322a5a5f;p=krb5.git * 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 --- 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 + + * 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 * 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);