summaryrefslogtreecommitdiff
path: root/loginrec.c
diff options
context:
space:
mode:
Diffstat (limited to 'loginrec.c')
-rw-r--r--loginrec.c81
1 files changed, 38 insertions, 43 deletions
diff --git a/loginrec.c b/loginrec.c
index 6697ca7b0..bdac3e959 100644
--- a/loginrec.c
+++ b/loginrec.c
@@ -12,11 +12,6 @@
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Markus Friedl.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 * 15 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@@ -163,7 +158,7 @@
163#include "log.h" 158#include "log.h"
164#include "atomicio.h" 159#include "atomicio.h"
165 160
166RCSID("$Id: loginrec.c,v 1.47 2003/03/10 00:23:07 djm Exp $"); 161RCSID("$Id: loginrec.c,v 1.52 2003/07/06 05:20:46 dtucker Exp $");
167 162
168#ifdef HAVE_UTIL_H 163#ifdef HAVE_UTIL_H
169# include <util.h> 164# include <util.h>
@@ -413,7 +408,7 @@ login_write (struct logininfo *li)
413{ 408{
414#ifndef HAVE_CYGWIN 409#ifndef HAVE_CYGWIN
415 if ((int)geteuid() != 0) { 410 if ((int)geteuid() != 0) {
416 log("Attempt to write login records by non-root user (aborting)"); 411 logit("Attempt to write login records by non-root user (aborting)");
417 return 1; 412 return 1;
418 } 413 }
419#endif 414#endif
@@ -818,7 +813,7 @@ utmp_write_direct(struct logininfo *li, struct utmp *ut)
818 endttyent(); 813 endttyent();
819 814
820 if((struct ttyent *)0 == ty) { 815 if((struct ttyent *)0 == ty) {
821 log("utmp_write_entry: tty not found"); 816 logit("utmp_write_entry: tty not found");
822 return(1); 817 return(1);
823 } 818 }
824#else /* FIXME */ 819#else /* FIXME */
@@ -842,8 +837,8 @@ utmp_write_direct(struct logininfo *li, struct utmp *ut)
842 } 837 }
843 838
844 (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET); 839 (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET);
845 if (atomicio(write, fd, ut, sizeof(*ut)) != sizeof(*ut)) 840 if (atomicio(vwrite, fd, ut, sizeof(*ut)) != sizeof(*ut))
846 log("utmp_write_direct: error writing %s: %s", 841 logit("utmp_write_direct: error writing %s: %s",
847 UTMP_FILE, strerror(errno)); 842 UTMP_FILE, strerror(errno));
848 843
849 (void)close(fd); 844 (void)close(fd);
@@ -862,12 +857,12 @@ utmp_perform_login(struct logininfo *li)
862 construct_utmp(li, &ut); 857 construct_utmp(li, &ut);
863# ifdef UTMP_USE_LIBRARY 858# ifdef UTMP_USE_LIBRARY
864 if (!utmp_write_library(li, &ut)) { 859 if (!utmp_write_library(li, &ut)) {
865 log("utmp_perform_login: utmp_write_library() failed"); 860 logit("utmp_perform_login: utmp_write_library() failed");
866 return 0; 861 return 0;
867 } 862 }
868# else 863# else
869 if (!utmp_write_direct(li, &ut)) { 864 if (!utmp_write_direct(li, &ut)) {
870 log("utmp_perform_login: utmp_write_direct() failed"); 865 logit("utmp_perform_login: utmp_write_direct() failed");
871 return 0; 866 return 0;
872 } 867 }
873# endif 868# endif
@@ -883,12 +878,12 @@ utmp_perform_logout(struct logininfo *li)
883 construct_utmp(li, &ut); 878 construct_utmp(li, &ut);
884# ifdef UTMP_USE_LIBRARY 879# ifdef UTMP_USE_LIBRARY
885 if (!utmp_write_library(li, &ut)) { 880 if (!utmp_write_library(li, &ut)) {
886 log("utmp_perform_logout: utmp_write_library() failed"); 881 logit("utmp_perform_logout: utmp_write_library() failed");
887 return 0; 882 return 0;
888 } 883 }
889# else 884# else
890 if (!utmp_write_direct(li, &ut)) { 885 if (!utmp_write_direct(li, &ut)) {
891 log("utmp_perform_logout: utmp_write_direct() failed"); 886 logit("utmp_perform_logout: utmp_write_direct() failed");
892 return 0; 887 return 0;
893 } 888 }
894# endif 889# endif
@@ -907,7 +902,7 @@ utmp_write_entry(struct logininfo *li)
907 return utmp_perform_logout(li); 902 return utmp_perform_logout(li);
908 903
909 default: 904 default:
910 log("utmp_write_entry: invalid type field"); 905 logit("utmp_write_entry: invalid type field");
911 return 0; 906 return 0;
912 } 907 }
913} 908}
@@ -948,7 +943,7 @@ utmpx_write_library(struct logininfo *li, struct utmpx *utx)
948static int 943static int
949utmpx_write_direct(struct logininfo *li, struct utmpx *utx) 944utmpx_write_direct(struct logininfo *li, struct utmpx *utx)
950{ 945{
951 log("utmpx_write_direct: not implemented!"); 946 logit("utmpx_write_direct: not implemented!");
952 return 0; 947 return 0;
953} 948}
954# endif /* UTMPX_USE_LIBRARY */ 949# endif /* UTMPX_USE_LIBRARY */
@@ -961,12 +956,12 @@ utmpx_perform_login(struct logininfo *li)
961 construct_utmpx(li, &utx); 956 construct_utmpx(li, &utx);
962# ifdef UTMPX_USE_LIBRARY 957# ifdef UTMPX_USE_LIBRARY
963 if (!utmpx_write_library(li, &utx)) { 958 if (!utmpx_write_library(li, &utx)) {
964 log("utmpx_perform_login: utmp_write_library() failed"); 959 logit("utmpx_perform_login: utmp_write_library() failed");
965 return 0; 960 return 0;
966 } 961 }
967# else 962# else
968 if (!utmpx_write_direct(li, &ut)) { 963 if (!utmpx_write_direct(li, &ut)) {
969 log("utmpx_perform_login: utmp_write_direct() failed"); 964 logit("utmpx_perform_login: utmp_write_direct() failed");
970 return 0; 965 return 0;
971 } 966 }
972# endif 967# endif
@@ -1004,7 +999,7 @@ utmpx_write_entry(struct logininfo *li)
1004 case LTYPE_LOGOUT: 999 case LTYPE_LOGOUT:
1005 return utmpx_perform_logout(li); 1000 return utmpx_perform_logout(li);
1006 default: 1001 default:
1007 log("utmpx_write_entry: invalid type field"); 1002 logit("utmpx_write_entry: invalid type field");
1008 return 0; 1003 return 0;
1009 } 1004 }
1010} 1005}
@@ -1026,14 +1021,14 @@ wtmp_write(struct logininfo *li, struct utmp *ut)
1026 int fd, ret = 1; 1021 int fd, ret = 1;
1027 1022
1028 if ((fd = open(WTMP_FILE, O_WRONLY|O_APPEND, 0)) < 0) { 1023 if ((fd = open(WTMP_FILE, O_WRONLY|O_APPEND, 0)) < 0) {
1029 log("wtmp_write: problem writing %s: %s", 1024 logit("wtmp_write: problem writing %s: %s",
1030 WTMP_FILE, strerror(errno)); 1025 WTMP_FILE, strerror(errno));
1031 return 0; 1026 return 0;
1032 } 1027 }
1033 if (fstat(fd, &buf) == 0) 1028 if (fstat(fd, &buf) == 0)
1034 if (atomicio(write, fd, ut, sizeof(*ut)) != sizeof(*ut)) { 1029 if (atomicio(vwrite, fd, ut, sizeof(*ut)) != sizeof(*ut)) {
1035 ftruncate(fd, buf.st_size); 1030 ftruncate(fd, buf.st_size);
1036 log("wtmp_write: problem writing %s: %s", 1031 logit("wtmp_write: problem writing %s: %s",
1037 WTMP_FILE, strerror(errno)); 1032 WTMP_FILE, strerror(errno));
1038 ret = 0; 1033 ret = 0;
1039 } 1034 }
@@ -1070,7 +1065,7 @@ wtmp_write_entry(struct logininfo *li)
1070 case LTYPE_LOGOUT: 1065 case LTYPE_LOGOUT:
1071 return wtmp_perform_logout(li); 1066 return wtmp_perform_logout(li);
1072 default: 1067 default:
1073 log("wtmp_write_entry: invalid type field"); 1068 logit("wtmp_write_entry: invalid type field");
1074 return 0; 1069 return 0;
1075 } 1070 }
1076} 1071}
@@ -1119,12 +1114,12 @@ wtmp_get_entry(struct logininfo *li)
1119 li->tv_sec = li->tv_usec = 0; 1114 li->tv_sec = li->tv_usec = 0;
1120 1115
1121 if ((fd = open(WTMP_FILE, O_RDONLY)) < 0) { 1116 if ((fd = open(WTMP_FILE, O_RDONLY)) < 0) {
1122 log("wtmp_get_entry: problem opening %s: %s", 1117 logit("wtmp_get_entry: problem opening %s: %s",
1123 WTMP_FILE, strerror(errno)); 1118 WTMP_FILE, strerror(errno));
1124 return 0; 1119 return 0;
1125 } 1120 }
1126 if (fstat(fd, &st) != 0) { 1121 if (fstat(fd, &st) != 0) {
1127 log("wtmp_get_entry: couldn't stat %s: %s", 1122 logit("wtmp_get_entry: couldn't stat %s: %s",
1128 WTMP_FILE, strerror(errno)); 1123 WTMP_FILE, strerror(errno));
1129 close(fd); 1124 close(fd);
1130 return 0; 1125 return 0;
@@ -1139,7 +1134,7 @@ wtmp_get_entry(struct logininfo *li)
1139 1134
1140 while (!found) { 1135 while (!found) {
1141 if (atomicio(read, fd, &ut, sizeof(ut)) != sizeof(ut)) { 1136 if (atomicio(read, fd, &ut, sizeof(ut)) != sizeof(ut)) {
1142 log("wtmp_get_entry: read of %s failed: %s", 1137 logit("wtmp_get_entry: read of %s failed: %s",
1143 WTMP_FILE, strerror(errno)); 1138 WTMP_FILE, strerror(errno));
1144 close (fd); 1139 close (fd);
1145 return 0; 1140 return 0;
@@ -1192,15 +1187,15 @@ wtmpx_write(struct logininfo *li, struct utmpx *utx)
1192 int fd, ret = 1; 1187 int fd, ret = 1;
1193 1188
1194 if ((fd = open(WTMPX_FILE, O_WRONLY|O_APPEND, 0)) < 0) { 1189 if ((fd = open(WTMPX_FILE, O_WRONLY|O_APPEND, 0)) < 0) {
1195 log("wtmpx_write: problem opening %s: %s", 1190 logit("wtmpx_write: problem opening %s: %s",
1196 WTMPX_FILE, strerror(errno)); 1191 WTMPX_FILE, strerror(errno));
1197 return 0; 1192 return 0;
1198 } 1193 }
1199 1194
1200 if (fstat(fd, &buf) == 0) 1195 if (fstat(fd, &buf) == 0)
1201 if (atomicio(write, fd, utx, sizeof(*utx)) != sizeof(*utx)) { 1196 if (atomicio(vwrite, fd, utx, sizeof(*utx)) != sizeof(*utx)) {
1202 ftruncate(fd, buf.st_size); 1197 ftruncate(fd, buf.st_size);
1203 log("wtmpx_write: problem writing %s: %s", 1198 logit("wtmpx_write: problem writing %s: %s",
1204 WTMPX_FILE, strerror(errno)); 1199 WTMPX_FILE, strerror(errno));
1205 ret = 0; 1200 ret = 0;
1206 } 1201 }
@@ -1239,7 +1234,7 @@ wtmpx_write_entry(struct logininfo *li)
1239 case LTYPE_LOGOUT: 1234 case LTYPE_LOGOUT:
1240 return wtmpx_perform_logout(li); 1235 return wtmpx_perform_logout(li);
1241 default: 1236 default:
1242 log("wtmpx_write_entry: invalid type field"); 1237 logit("wtmpx_write_entry: invalid type field");
1243 return 0; 1238 return 0;
1244 } 1239 }
1245} 1240}
@@ -1275,12 +1270,12 @@ wtmpx_get_entry(struct logininfo *li)
1275 li->tv_sec = li->tv_usec = 0; 1270 li->tv_sec = li->tv_usec = 0;
1276 1271
1277 if ((fd = open(WTMPX_FILE, O_RDONLY)) < 0) { 1272 if ((fd = open(WTMPX_FILE, O_RDONLY)) < 0) {
1278 log("wtmpx_get_entry: problem opening %s: %s", 1273 logit("wtmpx_get_entry: problem opening %s: %s",
1279 WTMPX_FILE, strerror(errno)); 1274 WTMPX_FILE, strerror(errno));
1280 return 0; 1275 return 0;
1281 } 1276 }
1282 if (fstat(fd, &st) != 0) { 1277 if (fstat(fd, &st) != 0) {
1283 log("wtmpx_get_entry: couldn't stat %s: %s", 1278 logit("wtmpx_get_entry: couldn't stat %s: %s",
1284 WTMPX_FILE, strerror(errno)); 1279 WTMPX_FILE, strerror(errno));
1285 close(fd); 1280 close(fd);
1286 return 0; 1281 return 0;
@@ -1295,7 +1290,7 @@ wtmpx_get_entry(struct logininfo *li)
1295 1290
1296 while (!found) { 1291 while (!found) {
1297 if (atomicio(read, fd, &utx, sizeof(utx)) != sizeof(utx)) { 1292 if (atomicio(read, fd, &utx, sizeof(utx)) != sizeof(utx)) {
1298 log("wtmpx_get_entry: read of %s failed: %s", 1293 logit("wtmpx_get_entry: read of %s failed: %s",
1299 WTMPX_FILE, strerror(errno)); 1294 WTMPX_FILE, strerror(errno));
1300 close (fd); 1295 close (fd);
1301 return 0; 1296 return 0;
@@ -1340,7 +1335,7 @@ syslogin_perform_login(struct logininfo *li)
1340 struct utmp *ut; 1335 struct utmp *ut;
1341 1336
1342 if (! (ut = (struct utmp *)malloc(sizeof(*ut)))) { 1337 if (! (ut = (struct utmp *)malloc(sizeof(*ut)))) {
1343 log("syslogin_perform_login: couldn't malloc()"); 1338 logit("syslogin_perform_login: couldn't malloc()");
1344 return 0; 1339 return 0;
1345 } 1340 }
1346 construct_utmp(li, ut); 1341 construct_utmp(li, ut);
@@ -1359,7 +1354,7 @@ syslogin_perform_logout(struct logininfo *li)
1359 (void)line_stripname(line, li->line, sizeof(line)); 1354 (void)line_stripname(line, li->line, sizeof(line));
1360 1355
1361 if (!logout(line)) { 1356 if (!logout(line)) {
1362 log("syslogin_perform_logout: logout() returned an error"); 1357 logit("syslogin_perform_logout: logout() returned an error");
1363# ifdef HAVE_LOGWTMP 1358# ifdef HAVE_LOGWTMP
1364 } else { 1359 } else {
1365 logwtmp(line, "", ""); 1360 logwtmp(line, "", "");
@@ -1382,7 +1377,7 @@ syslogin_write_entry(struct logininfo *li)
1382 case LTYPE_LOGOUT: 1377 case LTYPE_LOGOUT:
1383 return syslogin_perform_logout(li); 1378 return syslogin_perform_logout(li);
1384 default: 1379 default:
1385 log("syslogin_write_entry: Invalid type field"); 1380 logit("syslogin_write_entry: Invalid type field");
1386 return 0; 1381 return 0;
1387 } 1382 }
1388} 1383}
@@ -1417,7 +1412,7 @@ lastlog_filetype(char *filename)
1417 struct stat st; 1412 struct stat st;
1418 1413
1419 if (stat(LASTLOG_FILE, &st) != 0) { 1414 if (stat(LASTLOG_FILE, &st) != 0) {
1420 log("lastlog_perform_login: Couldn't stat %s: %s", LASTLOG_FILE, 1415 logit("lastlog_perform_login: Couldn't stat %s: %s", LASTLOG_FILE,
1421 strerror(errno)); 1416 strerror(errno));
1422 return 0; 1417 return 0;
1423 } 1418 }
@@ -1448,12 +1443,12 @@ lastlog_openseek(struct logininfo *li, int *fd, int filemode)
1448 LASTLOG_FILE, li->username); 1443 LASTLOG_FILE, li->username);
1449 break; 1444 break;
1450 default: 1445 default:
1451 log("lastlog_openseek: %.100s is not a file or directory!", 1446 logit("lastlog_openseek: %.100s is not a file or directory!",
1452 LASTLOG_FILE); 1447 LASTLOG_FILE);
1453 return 0; 1448 return 0;
1454 } 1449 }
1455 1450
1456 *fd = open(lastlog_file, filemode); 1451 *fd = open(lastlog_file, filemode, 0600);
1457 if ( *fd < 0) { 1452 if ( *fd < 0) {
1458 debug("lastlog_openseek: Couldn't open %s: %s", 1453 debug("lastlog_openseek: Couldn't open %s: %s",
1459 lastlog_file, strerror(errno)); 1454 lastlog_file, strerror(errno));
@@ -1465,7 +1460,7 @@ lastlog_openseek(struct logininfo *li, int *fd, int filemode)
1465 offset = (off_t) ((long)li->uid * sizeof(struct lastlog)); 1460 offset = (off_t) ((long)li->uid * sizeof(struct lastlog));
1466 1461
1467 if ( lseek(*fd, offset, SEEK_SET) != offset ) { 1462 if ( lseek(*fd, offset, SEEK_SET) != offset ) {
1468 log("lastlog_openseek: %s->lseek(): %s", 1463 logit("lastlog_openseek: %s->lseek(): %s",
1469 lastlog_file, strerror(errno)); 1464 lastlog_file, strerror(errno));
1470 return 0; 1465 return 0;
1471 } 1466 }
@@ -1487,9 +1482,9 @@ lastlog_perform_login(struct logininfo *li)
1487 return(0); 1482 return(0);
1488 1483
1489 /* write the entry */ 1484 /* write the entry */
1490 if (atomicio(write, fd, &last, sizeof(last)) != sizeof(last)) { 1485 if (atomicio(vwrite, fd, &last, sizeof(last)) != sizeof(last)) {
1491 close(fd); 1486 close(fd);
1492 log("lastlog_write_filemode: Error writing to %s: %s", 1487 logit("lastlog_write_filemode: Error writing to %s: %s",
1493 LASTLOG_FILE, strerror(errno)); 1488 LASTLOG_FILE, strerror(errno));
1494 return 0; 1489 return 0;
1495 } 1490 }
@@ -1505,7 +1500,7 @@ lastlog_write_entry(struct logininfo *li)
1505 case LTYPE_LOGIN: 1500 case LTYPE_LOGIN:
1506 return lastlog_perform_login(li); 1501 return lastlog_perform_login(li);
1507 default: 1502 default:
1508 log("lastlog_write_entry: Invalid type field"); 1503 logit("lastlog_write_entry: Invalid type field");
1509 return 0; 1504 return 0;
1510 } 1505 }
1511} 1506}