diff options
author | Damien Miller <djm@mindrot.org> | 2004-08-15 19:12:52 +1000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2004-08-15 19:12:52 +1000 |
commit | 8140959de036cad2a236784f368bbeeec8b10809 (patch) | |
tree | 774b1e654bc9f8390319708a4b73e21d65a86da0 /loginrec.c | |
parent | 36f496502072d82dbb202b41a199eb6032557710 (diff) |
- (djm) [loginrec.c] Check that seek succeeded here too; ok dtucker
Diffstat (limited to 'loginrec.c')
-rw-r--r-- | loginrec.c | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/loginrec.c b/loginrec.c index af32b1867..f07f65fce 100644 --- a/loginrec.c +++ b/loginrec.c | |||
@@ -158,7 +158,7 @@ | |||
158 | #include "log.h" | 158 | #include "log.h" |
159 | #include "atomicio.h" | 159 | #include "atomicio.h" |
160 | 160 | ||
161 | RCSID("$Id: loginrec.c,v 1.57 2004/08/14 14:09:11 dtucker Exp $"); | 161 | RCSID("$Id: loginrec.c,v 1.58 2004/08/15 09:12:52 djm Exp $"); |
162 | 162 | ||
163 | #ifdef HAVE_UTIL_H | 163 | #ifdef HAVE_UTIL_H |
164 | # include <util.h> | 164 | # include <util.h> |
@@ -818,8 +818,8 @@ utmp_write_direct(struct logininfo *li, struct utmp *ut) | |||
818 | endttyent(); | 818 | endttyent(); |
819 | 819 | ||
820 | if((struct ttyent *)0 == ty) { | 820 | if((struct ttyent *)0 == ty) { |
821 | logit("utmp_write_entry: tty not found"); | 821 | logit("%s: tty not found", __func__); |
822 | return(1); | 822 | return (0); |
823 | } | 823 | } |
824 | #else /* FIXME */ | 824 | #else /* FIXME */ |
825 | 825 | ||
@@ -828,7 +828,18 @@ utmp_write_direct(struct logininfo *li, struct utmp *ut) | |||
828 | #endif /* HAVE_GETTTYENT */ | 828 | #endif /* HAVE_GETTTYENT */ |
829 | 829 | ||
830 | if (tty > 0 && (fd = open(UTMP_FILE, O_RDWR|O_CREAT, 0644)) >= 0) { | 830 | if (tty > 0 && (fd = open(UTMP_FILE, O_RDWR|O_CREAT, 0644)) >= 0) { |
831 | (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET); | 831 | off_t pos, ret; |
832 | |||
833 | pos = (off_t)tty * sizeof(struct utmp); | ||
834 | if ((ret = lseek(fd, pos, SEEK_SET)) == -1) { | ||
835 | logit("%s: llseek: %s", strerror(errno)); | ||
836 | return (0); | ||
837 | } | ||
838 | if (ret != pos) { | ||
839 | logit("%s: Couldn't seek to tty %s slot in %s", tty, | ||
840 | UTMP_FILE); | ||
841 | return (0); | ||
842 | } | ||
832 | /* | 843 | /* |
833 | * Prevent luser from zero'ing out ut_host. | 844 | * Prevent luser from zero'ing out ut_host. |
834 | * If the new ut_line is empty but the old one is not | 845 | * If the new ut_line is empty but the old one is not |
@@ -841,9 +852,17 @@ utmp_write_direct(struct logininfo *li, struct utmp *ut) | |||
841 | (void)memcpy(ut->ut_host, old_ut.ut_host, sizeof(ut->ut_host)); | 852 | (void)memcpy(ut->ut_host, old_ut.ut_host, sizeof(ut->ut_host)); |
842 | } | 853 | } |
843 | 854 | ||
844 | (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET); | 855 | if ((ret = lseek(fd, pos, SEEK_SET)) == -1) { |
856 | logit("%s: llseek: %s", __func__, strerror(errno)); | ||
857 | return (0); | ||
858 | } | ||
859 | if (ret != pos) { | ||
860 | logit("%s: Couldn't seek to tty %s slot in %s", | ||
861 | __func__, tty, UTMP_FILE); | ||
862 | return (0); | ||
863 | } | ||
845 | if (atomicio(vwrite, fd, ut, sizeof(*ut)) != sizeof(*ut)) | 864 | if (atomicio(vwrite, fd, ut, sizeof(*ut)) != sizeof(*ut)) |
846 | logit("utmp_write_direct: error writing %s: %s", | 865 | logit("%s: error writing %s: %s", __func__, |
847 | UTMP_FILE, strerror(errno)); | 866 | UTMP_FILE, strerror(errno)); |
848 | 867 | ||
849 | (void)close(fd); | 868 | (void)close(fd); |