diff options
author | Damien Miller <djm@mindrot.org> | 2000-06-28 00:50:50 +1000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2000-06-28 00:50:50 +1000 |
commit | 53c5d467c366122df252a7ffe599c1f2ded06370 (patch) | |
tree | 336c6b6508a735790bf4c552ac4106e8429b60e9 | |
parent | dd47aa21fa928354cb53a423b4f1ebcd64a83d27 (diff) |
- (djm) Fixes to lastlog code for Irix
- (djm) Use atomicio in loginrec
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | loginrec.c | 56 |
2 files changed, 28 insertions, 32 deletions
@@ -1,3 +1,7 @@ | |||
1 | 20000628 | ||
2 | - (djm) Fixes to lastlog code for Irix | ||
3 | - (djm) Use atomicio in loginrec | ||
4 | |||
1 | 20000627 | 5 | 20000627 |
2 | - (djm) Fixes to login code - not setting li->uid, cleanups | 6 | - (djm) Fixes to login code - not setting li->uid, cleanups |
3 | - (djm) Formatting | 7 | - (djm) Formatting |
diff --git a/loginrec.c b/loginrec.c index 5b487eb70..6a6443d2b 100644 --- a/loginrec.c +++ b/loginrec.c | |||
@@ -170,7 +170,7 @@ | |||
170 | #include "xmalloc.h" | 170 | #include "xmalloc.h" |
171 | #include "loginrec.h" | 171 | #include "loginrec.h" |
172 | 172 | ||
173 | RCSID("$Id: loginrec.c,v 1.11 2000/06/27 01:18:27 djm Exp $"); | 173 | RCSID("$Id: loginrec.c,v 1.12 2000/06/27 14:50:50 djm Exp $"); |
174 | 174 | ||
175 | /** | 175 | /** |
176 | ** prototypes for helper functions in this file | 176 | ** prototypes for helper functions in this file |
@@ -281,17 +281,16 @@ login_get_lastlog_time(const int uid) | |||
281 | struct logininfo * | 281 | struct logininfo * |
282 | login_get_lastlog(struct logininfo *li, const int uid) | 282 | login_get_lastlog(struct logininfo *li, const int uid) |
283 | { | 283 | { |
284 | #ifndef USE_LASTLOG | ||
285 | struct passwd *pw; | 284 | struct passwd *pw; |
286 | #endif | ||
287 | 285 | ||
288 | memset(li, '\0', sizeof(struct logininfo)); | 286 | memset(li, '\0', sizeof(struct logininfo)); |
289 | li->uid = uid; | 287 | li->uid = uid; |
290 | 288 | ||
291 | #ifndef USE_LASTLOG | 289 | /* |
292 | /* If we don't have a 'real' lastlog, we need the username to | 290 | * If we don't have a 'real' lastlog, we need the username to |
293 | * reliably search wtmp(x) for the last login (see | 291 | * reliably search wtmp(x) for the last login (see |
294 | * wtmp_get_entry().) */ | 292 | * wtmp_get_entry().) |
293 | */ | ||
295 | pw = getpwuid(uid); | 294 | pw = getpwuid(uid); |
296 | if (pw == NULL) | 295 | if (pw == NULL) |
297 | fatal("login_get_lastlog: Cannot find account for uid %i", uid); | 296 | fatal("login_get_lastlog: Cannot find account for uid %i", uid); |
@@ -299,7 +298,6 @@ login_get_lastlog(struct logininfo *li, const int uid) | |||
299 | /* No MIN_SIZEOF here - we absolutely *must not* truncate the | 298 | /* No MIN_SIZEOF here - we absolutely *must not* truncate the |
300 | * username */ | 299 | * username */ |
301 | strlcpy(li->username, pw->pw_name, sizeof(li->username)); | 300 | strlcpy(li->username, pw->pw_name, sizeof(li->username)); |
302 | #endif | ||
303 | 301 | ||
304 | if (getlast_entry(li)) | 302 | if (getlast_entry(li)) |
305 | return li; | 303 | return li; |
@@ -452,10 +450,7 @@ int | |||
452 | getlast_entry(struct logininfo *li) | 450 | getlast_entry(struct logininfo *li) |
453 | { | 451 | { |
454 | #ifdef USE_LASTLOG | 452 | #ifdef USE_LASTLOG |
455 | if (lastlog_get_entry(li)) | 453 | return(lastlog_get_entry(li)); |
456 | return 1; | ||
457 | else | ||
458 | return 0; | ||
459 | #else /* !USE_LASTLOG */ | 454 | #else /* !USE_LASTLOG */ |
460 | 455 | ||
461 | #ifdef DISABLE_LASTLOG | 456 | #ifdef DISABLE_LASTLOG |
@@ -738,22 +733,23 @@ utmp_write_direct(struct logininfo *li, struct utmp *ut) | |||
738 | * If the new ut_line is empty but the old one is not | 733 | * If the new ut_line is empty but the old one is not |
739 | * and ut_line and ut_name match, preserve the old ut_line. | 734 | * and ut_line and ut_name match, preserve the old ut_line. |
740 | */ | 735 | */ |
741 | if ( read(fd, &old_ut, sizeof(struct utmp)) == sizeof(struct utmp) | 736 | if (atomicio(read, fd, &old_ut, sizeof(old_ut)) == sizeof(old_ut) && |
742 | && ut->ut_host[0] == '\0' | 737 | (ut->ut_host[0] == '\0') && (old_ut.ut_host[0] != '\0') && |
743 | && old_ut.ut_host[0] != '\0' | 738 | (strncmp(old_ut.ut_line, ut->ut_line, sizeof(ut->ut_line)) == 0) && |
744 | && strncmp(old_ut.ut_line, ut->ut_line, sizeof(ut->ut_line)) == 0 | 739 | (strncmp(old_ut.ut_name, ut->ut_name, sizeof(ut->ut_name)) == 0)) { |
745 | && strncmp(old_ut.ut_name, ut->ut_name, sizeof(ut->ut_name)) == 0 ) | ||
746 | (void)memcpy(ut->ut_host, old_ut.ut_host, sizeof(ut->ut_host)); | 740 | (void)memcpy(ut->ut_host, old_ut.ut_host, sizeof(ut->ut_host)); |
747 | 741 | } | |
742 | |||
748 | (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET); | 743 | (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET); |
749 | if (write(fd, ut, sizeof(struct utmp))==-1) | 744 | if (atomicio(write, fd, ut, sizeof(ut)) != sizeof(ut)) |
750 | log("utmp_write_direct: error writing %s: %s", | 745 | log("utmp_write_direct: error writing %s: %s", |
751 | UTMP_FILE, strerror(errno)); | 746 | UTMP_FILE, strerror(errno)); |
752 | 747 | ||
753 | (void)close(fd); | 748 | (void)close(fd); |
754 | return 1; | 749 | return 1; |
755 | } else | 750 | } else { |
756 | return 0; | 751 | return 0; |
752 | } | ||
757 | } | 753 | } |
758 | # endif /* UTMP_USE_LIBRARY */ | 754 | # endif /* UTMP_USE_LIBRARY */ |
759 | 755 | ||
@@ -936,8 +932,7 @@ wtmp_write(struct logininfo *li, struct utmp *ut) | |||
936 | return 0; | 932 | return 0; |
937 | } | 933 | } |
938 | if (fstat(fd, &buf) == 0) | 934 | if (fstat(fd, &buf) == 0) |
939 | if (write(fd, (char *)ut, sizeof(struct utmp)) != | 935 | if (atomicio(write, fd, ut, sizeof(*ut)) != sizeof(*ut)) { |
940 | sizeof(struct utmp)) { | ||
941 | ftruncate(fd, buf.st_size); | 936 | ftruncate(fd, buf.st_size); |
942 | log("wtmp_write: problem writing %s: %s", | 937 | log("wtmp_write: problem writing %s: %s", |
943 | WTMP_FILE, strerror(errno)); | 938 | WTMP_FILE, strerror(errno)); |
@@ -1044,7 +1039,7 @@ wtmp_get_entry(struct logininfo *li) | |||
1044 | } | 1039 | } |
1045 | 1040 | ||
1046 | while (!found) { | 1041 | while (!found) { |
1047 | if (read(fd, &ut, sizeof(ut)) != sizeof(ut)) { | 1042 | if (atomicio(read, fd, &ut, sizeof(ut)) != sizeof(ut)) { |
1048 | log("wtmp_get_entry: read of %s failed: %s", | 1043 | log("wtmp_get_entry: read of %s failed: %s", |
1049 | WTMP_FILE, strerror(errno)); | 1044 | WTMP_FILE, strerror(errno)); |
1050 | close (fd); | 1045 | close (fd); |
@@ -1104,8 +1099,7 @@ wtmpx_write(struct logininfo *li, struct utmpx *utx) | |||
1104 | } | 1099 | } |
1105 | 1100 | ||
1106 | if (fstat(fd, &buf) == 0) | 1101 | if (fstat(fd, &buf) == 0) |
1107 | if (write(fd, (char *)utx, sizeof(struct utmpx)) != | 1102 | if (atomicio(write, fd, utx, sizeof(*utx)) != sizeof(*utx)) { |
1108 | sizeof(struct utmpx)) { | ||
1109 | ftruncate(fd, buf.st_size); | 1103 | ftruncate(fd, buf.st_size); |
1110 | log("wtmpx_write: problem writing %s: %s", | 1104 | log("wtmpx_write: problem writing %s: %s", |
1111 | WTMPX_FILE, strerror(errno)); | 1105 | WTMPX_FILE, strerror(errno)); |
@@ -1201,7 +1195,7 @@ wtmpx_get_entry(struct logininfo *li) | |||
1201 | } | 1195 | } |
1202 | 1196 | ||
1203 | while (!found) { | 1197 | while (!found) { |
1204 | if (read(fd, &utx, sizeof(utx)) != sizeof(utx)) { | 1198 | if (atomicio(read, fd, &utx, sizeof(utx)) != sizeof(utx)) { |
1205 | log("wtmpx_get_entry: read of %s failed: %s", | 1199 | log("wtmpx_get_entry: read of %s failed: %s", |
1206 | WTMPX_FILE, strerror(errno)); | 1200 | WTMPX_FILE, strerror(errno)); |
1207 | close (fd); | 1201 | close (fd); |
@@ -1360,7 +1354,7 @@ lastlog_openseek(struct logininfo *li, int *fd, int filemode) | |||
1360 | 1354 | ||
1361 | *fd = open(lastlog_file, filemode); | 1355 | *fd = open(lastlog_file, filemode); |
1362 | if ( *fd < 0) { | 1356 | if ( *fd < 0) { |
1363 | log("lastlog_openseek: Couldn't open %s: %s", | 1357 | debug("lastlog_openseek: Couldn't open %s: %s", |
1364 | lastlog_file, strerror(errno)); | 1358 | lastlog_file, strerror(errno)); |
1365 | return 0; | 1359 | return 0; |
1366 | } | 1360 | } |
@@ -1386,9 +1380,8 @@ lastlog_perform_login(struct logininfo *li) | |||
1386 | lastlog_construct(li, &last); | 1380 | lastlog_construct(li, &last); |
1387 | 1381 | ||
1388 | /* write the entry */ | 1382 | /* write the entry */ |
1389 | if (lastlog_openseek(li, &fd, O_RDWR)) { | 1383 | if (lastlog_openseek(li, &fd, O_RDWR|O_CREAT)) { |
1390 | if (write(fd, &last, sizeof(struct lastlog)) != | 1384 | if (atomicio(write, fd, &last, sizeof(last)) != sizeof(last)) { |
1391 | sizeof(struct lastlog)) { | ||
1392 | log("lastlog_write_filemode: Error writing to %s: %s", | 1385 | log("lastlog_write_filemode: Error writing to %s: %s", |
1393 | LASTLOG_FILE, strerror(errno)); | 1386 | LASTLOG_FILE, strerror(errno)); |
1394 | return 0; | 1387 | return 0; |
@@ -1427,9 +1420,8 @@ lastlog_get_entry(struct logininfo *li) | |||
1427 | int fd; | 1420 | int fd; |
1428 | 1421 | ||
1429 | if (lastlog_openseek(li, &fd, O_RDONLY)) { | 1422 | if (lastlog_openseek(li, &fd, O_RDONLY)) { |
1430 | if ( read(fd, &last, sizeof(struct lastlog)) != | 1423 | if (atomicio(read, fd, &last, sizeof(last)) != sizeof(last)) { |
1431 | sizeof(struct lastlog) ) { | 1424 | log("lastlog_get_entry: Error reading from %s: %s", |
1432 | log("lastlog_write_filemode: Error reading from %s: %s", | ||
1433 | LASTLOG_FILE, strerror(errno)); | 1425 | LASTLOG_FILE, strerror(errno)); |
1434 | return 0; | 1426 | return 0; |
1435 | } else { | 1427 | } else { |