Changeset 573 for trunk/src/sh_utmp.c
- Timestamp:
- Mar 7, 2022, 6:57:06 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_utmp.c
r541 r573 141 141 #ifdef HAVE_UTMPX_H 142 142 143 #ifndef _PATH_UTMP 144 #ifdef UTMPX_FILE 145 #define _PATH_UTMP UTMPX_FILE 146 #else 143 #if defined(_PATH_UTMPX) 144 #define SH_PATH_UTMP _PATH_UTMPX 145 #elif defined(UTMPX_FILE) 146 #define SH_PATH_UTMP UTMPX_FILE 147 #elif defined(_PATH_UTMP) 148 #define SH_PATH_UTMP _PATH_UTMP 149 #else 147 150 #error You must define UTMPX_FILE in the file config.h 148 151 #endif 149 #endif 150 #ifndef _PATH_WTMP 151 #ifdef WTMPX_FILE 152 #define _PATH_WTMP WTMPX_FILE 153 #else 154 #error You must define WTMPX_FILE in the file config.h 155 #endif 156 #endif 157 158 #else 159 160 #ifndef _PATH_UTMP 161 #ifdef UTMP_FILE 162 #define _PATH_UTMP UTMP_FILE 152 153 #else 154 155 #if defined(_PATH_UTMP) 156 #define SH_PATH_UTMP _PATH_UTMP 157 #elif defined(UTMP_FILE) 158 #define SH_PATH_UTMP UTMP_FILE 163 159 #else 164 160 #error You must define UTMP_FILE in the file config.h 165 161 #endif 166 #endif167 #ifndef _PATH_WTMP168 #ifdef WTMP_FILE169 #define _PATH_WTMP WTMP_FILE170 #else171 #error You must define WTMP_FILE in the file config.h172 #endif173 #endif174 162 175 163 #endif 176 164 177 165 typedef struct log_user { 166 time_t last_checked; 178 167 char ut_tty[UT_LINESIZE+1]; 179 168 char name[UT_NAMESIZE+1]; … … 184 173 } blah_utmp; 185 174 186 #ifdef HAVE_UTTYPE 187 static char terminated_line[UT_HOSTSIZE]; 188 #endif 189 190 static char * mode_path[] = { _PATH_WTMP, _PATH_WTMP, _PATH_UTMP }; 191 192 static struct SH_UTMP_S save_utmp; 175 static char * utmp_path = SH_PATH_UTMP; 193 176 194 177 static void sh_utmp_logout_morechecks(struct log_user * user); 195 178 static void sh_utmp_login_morechecks(struct SH_UTMP_S * ut); 196 static void sh_utmp_ addlogin (struct SH_UTMP_S * ut);197 static void sh_utmp_check_internal( int mode);179 static void sh_utmp_checklogin (struct SH_UTMP_S * ut, time_t start_read); 180 static void sh_utmp_check_internal(); 198 181 199 182 static int ShUtmpLoginSolo = SH_ERR_INFO; … … 258 241 } 259 242 260 261 #if defined (HAVE_SETUTENT) && defined (USE_SETUTENT) 262 263 #ifdef HAVE_UTMPX_H 264 265 #define sh_utmp_utmpname utmpxname 243 #if defined(HAVE_UTMPX_H) && defined(HAVE_GETUTXENT) 244 #define USE_SETUTENT 1 245 #elif defined(HAVE_GETUTENT) 246 #define USE_SETUTENT 1 247 #endif 248 249 250 #if defined (USE_SETUTENT) 251 252 #ifdef HAVE_UTMPX_H 253 254 #define sh_utmp_utmpname(a) (void)(a) 266 255 #define sh_utmp_setutent setutxent 267 256 #define sh_utmp_endutent endutxent … … 292 281 293 282 static FILE * sh_utmpfile = NULL; 294 static char sh_utmppath[80] = _PATH_UTMP; 295 296 /* sh_utmp_feed_forward is for optimizing 297 * (fseek instead of getutent loop) 298 */ 299 static long sh_utmp_feed_forward = 0; 283 static char sh_utmppath[80] = SH_PATH_UTMP; 284 300 285 301 286 static void sh_utmp_utmpname(const char * str) … … 308 293 } 309 294 310 (void) sl_strlcpy (sh_utmppath, str, 80);295 (void) sl_strlcpy (sh_utmppath, str, sizeof(sh_utmppath)); 311 296 SL_RET0(_("sh_utmp_utmpname")); 312 297 } … … 344 329 } 345 330 (void) fseek (sh_utmpfile, 0L, SEEK_SET); 346 if (-1 == fseek (sh_utmpfile, sh_utmp_feed_forward, SEEK_CUR))347 {348 sh_utmp_feed_forward = 0; /* modified Apr 4, 2004 */349 (void) fseek (sh_utmpfile, 0L, SEEK_SET);350 }351 331 clearerr (sh_utmpfile); 352 332 SL_RET0(_("sh_utmp_setutent")); … … 388 368 } 389 369 390 #ifdef USE_UNUSED391 392 static struct SH_UTMP_S * sh_utmp_getutline(struct SH_UTMP_S * ut)393 {394 struct SH_UTMP_S * out;395 396 while (1) {397 if ((out = sh_utmp_getutent()) == NULL) {398 return NULL;399 }400 #ifdef HAVE_UTTYPE401 if (out->ut_type == USER_PROCESS || out->ut_type == LOGIN_PROCESS)402 if (sl_strcmp(ut->ut_line, out->ut_line) == 0)403 return out;404 #else405 if ( 0 != sl_strncmp (out->ut_name, "reboot", 6) &&406 0 != sl_strncmp (out->ut_name, "shutdown", 8) &&407 0 != sl_strncmp (out->ut_name, "date", 4) )408 return out;409 #endif410 }411 return NULL;412 }413 414 static struct SH_UTMP_S * sh_utmp_getutid(struct SH_UTMP_S * ut)415 {416 #ifdef HAVE_UTTYPE417 struct SH_UTMP_S * out;418 419 if (ut->ut_type == RUN_LVL || ut->ut_type == BOOT_TIME ||420 ut->ut_type == NEW_TIME || ut->ut_type == OLD_TIME)421 {422 while (1) {423 if ((out = sh_utmp_getutent()) == NULL) {424 return NULL;425 }426 if (out->ut_type == ut->ut_type)427 return out;428 }429 }430 else if (ut->ut_type == INIT_PROCESS || ut->ut_type == LOGIN_PROCESS ||431 ut->ut_type == USER_PROCESS || ut->ut_type == DEAD_PROCESS )432 {433 while (1) {434 if ((out = sh_utmp_getutent()) == NULL) {435 return NULL;436 }437 if (sl_strcmp(ut->ut_id, out->ut_id) == 0)438 return out;439 }440 }441 #endif442 return NULL;443 }444 /* #ifdef USE_UNUSED */445 #endif446 447 370 /* #ifdef HAVE_SETUTENT */ 448 371 #endif … … 511 434 lastcheck = time (NULL); 512 435 userlist = NULL; 513 memset (&save_utmp, 0, sizeof(struct SH_UTMP_S)); 514 sh_utmp_check_internal (2); /* current logins */ 515 sh_utmp_check_internal (0); 436 sh_utmp_check_internal (); /* current logins */ 516 437 init_done = 1; 517 438 SL_RETURN( (0), _("sh_utmp_init")); … … 618 539 sh.flag.checkSum != SH_CHECK_INIT ) 619 540 { 620 sh_inotify_wait_for_change( mode_path[1], &inotify_watch,541 sh_inotify_wait_for_change(utmp_path, &inotify_watch, 621 542 &errnum, ShUtmpInterval); 622 543 } … … 657 578 sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_UT_CHECK); 658 579 SH_MUTEX_UNLOCK(mutex_thread_nolog); 659 sh_utmp_check_internal ( 1);580 sh_utmp_check_internal (); 660 581 661 582 SL_RETURN(0, _("sh_utmp_check")); … … 737 658 } 738 659 739 #ifdef HAVE_UTTYPE 660 740 661 struct login_ct { 741 662 char name[UT_NAMESIZE+1]; … … 817 738 } 818 739 819 #endif820 740 821 741 … … 826 746 */ 827 747 828 #i fdef HAVE_UTTYPE748 #include <ctype.h> 829 749 static int sh_utmp_is_virtual (char * in_utline, char * in_uthost) 830 750 { … … 833 753 in_utline != NULL && 834 754 in_uthost[0] == ':' && 835 i n_uthost[1] == '0'&&755 isdigit((int) in_uthost[1]) && 836 756 0 == sl_strncmp(in_utline, _("pts/"), 4)) 837 757 { … … 841 761 return 0; 842 762 } 843 #endif 763 764 765 static void sh_utmp_log_out(int sev, struct log_user * user, int n) 766 { 767 char ttt[TIM_MAX]; 768 769 SH_MUTEX_LOCK(mutex_thread_nolog); 770 (void) sh_unix_time (user->time, ttt, TIM_MAX); 771 sh_error_handle( sev, FIL__, __LINE__, 0, 772 #if defined(HAVE_UTHOST) && defined(HAVE_UTADDR) 773 MSG_UT_LG3X, 774 #elif defined(HAVE_UTHOST) 775 MSG_UT_LG3A, 776 #else 777 MSG_UT_LG3B, 778 #endif 779 user->name, 780 user->ut_tty, 781 #if defined(HAVE_UTHOST) && defined(HAVE_UTADDR) 782 user->ut_host, 783 user->ut_ship, 784 #elif defined(HAVE_UTHOST) 785 user->ut_host, 786 #endif 787 ttt, 788 n 789 ); 790 SH_MUTEX_UNLOCK(mutex_thread_nolog); 791 } 792 793 static void sh_utmp_log_multi(int sev, struct log_user * user, int n) 794 { 795 char ttt[TIM_MAX]; 796 797 SH_MUTEX_LOCK(mutex_thread_nolog); 798 (void) sh_unix_time (user->time, ttt, TIM_MAX); 799 sh_error_handle( sev, FIL__, __LINE__, 0, 800 #if defined(HAVE_UTHOST) && defined(HAVE_UTADDR) 801 MSG_UT_LG2X, 802 #elif defined(HAVE_UTHOST) 803 MSG_UT_LG2A, 804 #else 805 MSG_UT_LG2B, 806 #endif 807 user->name, 808 user->ut_tty, 809 #if defined(HAVE_UTHOST) && defined(HAVE_UTADDR) 810 user->ut_host, 811 user->ut_ship, 812 #elif defined(HAVE_UTHOST) 813 user->ut_host, 814 #endif 815 ttt, 816 n 817 ); 818 SH_MUTEX_UNLOCK(mutex_thread_nolog); 819 } 820 821 static void sh_utmp_log_one(int sev, struct log_user * user, int n) 822 { 823 char ttt[TIM_MAX]; 824 825 SH_MUTEX_LOCK(mutex_thread_nolog); 826 (void) sh_unix_time (user->time, ttt, TIM_MAX); 827 sh_error_handle( sev, FIL__, __LINE__, 0, 828 #if defined(HAVE_UTHOST) && defined(HAVE_UTADDR) 829 MSG_UT_LG1X, 830 #elif defined(HAVE_UTHOST) 831 MSG_UT_LG1A, 832 #else 833 MSG_UT_LG1B, 834 #endif 835 user->name, 836 user->ut_tty, 837 #if defined(HAVE_UTHOST) && defined(HAVE_UTADDR) 838 user->ut_host, 839 user->ut_ship, 840 #elif defined(HAVE_UTHOST) 841 user->ut_host, 842 #endif 843 ttt, 844 n 845 ); 846 SH_MUTEX_UNLOCK(mutex_thread_nolog); 847 } 848 849 static void sh_utmp_purge_old (time_t start_read) 850 { 851 struct log_user * user = userlist; 852 struct log_user * userold = userlist; 853 volatile int status; 854 855 /* ------- find old entries -------- 856 */ 857 while (user != NULL) 858 { 859 if (user->last_checked < start_read) 860 { 861 /* report logout */ 862 if (0 == sh_utmp_is_virtual(user->ut_tty, user->ut_host)) 863 { 864 /* reference count down on list of logged in users */ 865 status = sh_utmp_login_r(user->name); 866 867 sh_utmp_log_out(ShUtmpLogout, user, status); 868 sh_utmp_logout_morechecks((struct log_user *)user); 869 } 870 871 /* remove entry */ 872 if (userold == user && userold == userlist) 873 { 874 /* first element in userlist, advance userlist & userold */ 875 userold = user->next; 876 userlist = user->next; 877 SH_FREE((struct log_user *)user); 878 user = userlist; 879 } 880 else 881 { 882 /* other element in userlist, cut it out */ 883 userold->next = user->next; 884 SH_FREE((struct log_user *)user); 885 user = userold->next; 886 } 887 } 888 else 889 { 890 userold = user; 891 user = user->next; 892 } 893 } 894 return; 895 } 844 896 845 897 /* These variables are not used anywhere. They only exist … … 852 904 853 905 854 static void sh_utmp_ addlogin (struct SH_UTMP_S * ut)906 static void sh_utmp_checklogin (struct SH_UTMP_S * ut, time_t start_read) 855 907 { 856 908 struct log_user * user = userlist; 857 909 struct log_user * userold = userlist; 858 #ifdef HAVE_UTTYPE 910 859 911 struct log_user * username = userlist; 860 #endif861 862 char ttt[TIM_MAX];863 #ifdef HAVE_UTTYPE864 912 volatile int status; 865 #endif 866 867 SL_ENTER(_("sh_utmp_ addlogin"));913 914 915 SL_ENTER(_("sh_utmp_checklogin")); 868 916 869 917 if (ut->ut_line[0] == '\0') 870 SL_RET0(_("sh_utmp_addlogin")); 871 872 /* for some stupid reason, AIX repeats the wtmp entry for logouts 873 * with ssh 874 */ 875 if (memcmp (&save_utmp, ut, sizeof(struct SH_UTMP_S)) == 0) 876 { 877 memset(&save_utmp, 0, sizeof(struct SH_UTMP_S)); 878 SL_RET0(_("sh_utmp_addlogin")); 879 } 880 memcpy (&save_utmp, ut, sizeof(struct SH_UTMP_S)); 918 SL_RET0(_("sh_utmp_checklogin")); 881 919 882 920 /* Take the address to keep gcc from putting them into registers. … … 890 928 while (user != NULL) 891 929 { 892 if (0 == sl_strncmp((char*)(user->ut_tty), ut->ut_line, UT_LINESIZE) ) 930 if (0 == sl_strncmp(user->ut_tty, ut->ut_line, UT_LINESIZE) && 931 0 == sl_strncmp(user->name, ut->ut_name, UT_NAMESIZE)) 893 932 break; 894 933 userold = user; … … 896 935 } 897 936 898 #ifdef HAVE_UTTYPE 937 899 938 while (username != NULL) 900 939 { … … 903 942 username = username->next; 904 943 } 905 #endif 944 906 945 907 #ifdef HAVE_UTTYPE 908 /* ---------- LOGIN -------------- */ 909 if (ut->ut_type == USER_PROCESS) 910 { 911 if (user == NULL) 946 if (user == NULL) 947 { 948 user = SH_ALLOC(sizeof(struct log_user)); 949 user->next = userlist; 950 userlist = (struct log_user *) user; 951 } 952 else if ( (user->time == ut->ut_time) && 953 0 == sl_strcmp (user->name, ut->ut_name)) 954 { 955 /* we have it on record and nothing has changed */ 956 user->last_checked = start_read; 957 goto out; 958 } 959 else 960 { 961 /* we have it on record and something has changed */ 962 if (0 == sh_utmp_is_virtual(user->ut_tty, user->ut_host)) 912 963 { 913 user = SH_ALLOC(sizeof(struct log_user)); 914 user->next = userlist; 915 userlist = (struct log_user *) user; 964 /* reference count down on list of logged in users */ 965 status = sh_utmp_login_r(user->name); 966 967 sh_utmp_log_out(ShUtmpLogout, user, status); 968 sh_utmp_logout_morechecks((struct log_user *)user); 916 969 } 917 (void) sl_strlcpy((char*)(user->ut_tty), ut->ut_line, UT_LINESIZE+1); 918 (void) sl_strlcpy((char*)(user->name), ut->ut_name, UT_NAMESIZE+1); 970 } 971 972 user->last_checked = start_read; 973 974 (void) sl_strlcpy(user->ut_tty, ut->ut_line, UT_LINESIZE+1); 975 (void) sl_strlcpy(user->name, ut->ut_name, UT_NAMESIZE+1); 919 976 #ifdef HAVE_UTHOST 920 (void) sl_strlcpy((char*)(user->ut_host), ut->ut_host, UT_HOSTSIZE+1);921 #else 922 977 (void) sl_strlcpy(user->ut_host, ut->ut_host, UT_HOSTSIZE+1); 978 #else 979 user->ut_host[0] = '\0'; 923 980 #endif 924 981 #ifdef HAVE_UTADDR 925 982 #ifdef HAVE_UTADDR_V6 926 my_inet_ntoa(ut->ut_addr_v6, user->ut_ship, SH_IP_BUF); 927 #else 928 my_inet_ntoa(ut->ut_addr, user->ut_ship, SH_IP_BUF); 929 #endif 930 #endif 931 user->time = ut->ut_time; 932 933 if (username == NULL /* not yet logged in */ 934 || 0 == sl_strncmp(ut->ut_line, _("ttyp"), 4) /* in virt. console */ 935 || 0 == sl_strncmp(ut->ut_line, _("ttyq"), 4) /* in virt. console */ 936 ) { 937 status = sh_utmp_login_a((char*)user->name); 938 SH_MUTEX_LOCK(mutex_thread_nolog); 939 (void) sh_unix_time (user->time, ttt, TIM_MAX); 940 sh_error_handle( ShUtmpLoginSolo, FIL__, __LINE__, 0, 941 #if defined(HAVE_UTHOST) && defined(HAVE_UTADDR) 942 MSG_UT_LG1X, 943 #elif defined(HAVE_UTHOST) 944 MSG_UT_LG1A, 945 #else 946 MSG_UT_LG1B, 947 #endif 948 user->name, 949 user->ut_tty, 950 #if defined(HAVE_UTHOST) && defined(HAVE_UTADDR) 951 user->ut_host, 952 user->ut_ship, 953 #elif defined(HAVE_UTHOST) 954 user->ut_host, 955 #endif 956 ttt, 957 status 958 ); 959 SH_MUTEX_UNLOCK(mutex_thread_nolog); 960 } else 961 if (0 == sh_utmp_is_virtual(ut->ut_line, (char*)user->ut_host)) 962 { 963 status = sh_utmp_login_a((char*)user->name); 964 SH_MUTEX_LOCK(mutex_thread_nolog); 965 (void) sh_unix_time (user->time, ttt, TIM_MAX); 966 sh_error_handle( ShUtmpLoginMulti, FIL__, __LINE__, 0, 967 #if defined(HAVE_UTHOST) && defined(HAVE_UTADDR) 968 MSG_UT_LG2X, 969 #elif defined(HAVE_UTHOST) 970 MSG_UT_LG2A, 971 #else 972 MSG_UT_LG2B, 973 #endif 974 user->name, 975 user->ut_tty, 976 #if defined(HAVE_UTHOST) && defined(HAVE_UTADDR) 977 user->ut_host, 978 user->ut_ship, 979 #elif defined(HAVE_UTHOST) 980 user->ut_host, 981 #endif 982 ttt, 983 status 984 ); 985 SH_MUTEX_UNLOCK(mutex_thread_nolog); 986 } 983 my_inet_ntoa(ut->ut_addr_v6, user->ut_ship, SH_IP_BUF); 984 #else 985 my_inet_ntoa(ut->ut_addr, user->ut_ship, SH_IP_BUF); 986 #endif 987 #endif 988 user->time = ut->ut_time; 989 990 if (username == NULL) /* not yet logged in */ 991 { 992 /* add this username to the list of logged in users */ 993 status = sh_utmp_login_a(user->name); 987 994 988 sh_utmp_login_morechecks(ut); 989 goto out; 990 } 991 992 993 /* --------- LOGOUT ---------------- */ 994 else if (ut->ut_name[0] == '\0' 995 || ut->ut_type == DEAD_PROCESS /* solaris does not clear ut_name */ 996 ) 997 { 998 if (user != NULL) 999 { 1000 #if defined(__linux__) 1001 if (0 == sh_utmp_is_virtual(ut->ut_line, (char*)user->ut_host)) { 1002 #endif 1003 status = sh_utmp_login_r((char*)user->name); 1004 SH_MUTEX_LOCK(mutex_thread_nolog); 1005 (void) sh_unix_time (ut->ut_time, ttt, TIM_MAX); 1006 sh_error_handle( ShUtmpLogout, FIL__, __LINE__, 0, 1007 #if defined(HAVE_UTHOST) && defined(HAVE_UTADDR) 1008 MSG_UT_LG3X, 1009 #elif defined(HAVE_UTHOST) 1010 MSG_UT_LG3A, 1011 #else 1012 MSG_UT_LG3B, 1013 #endif 1014 user->name, 1015 user->ut_tty, 1016 #if defined(HAVE_UTHOST) && defined(HAVE_UTADDR) 1017 user->ut_host, 1018 user->ut_ship, 1019 #elif defined(HAVE_UTHOST) 1020 user->ut_host, 1021 #endif 1022 ttt, 1023 status 1024 ); 1025 SH_MUTEX_UNLOCK(mutex_thread_nolog); 1026 userold->next = user->next; 1027 if (user == userlist) 1028 userlist = user->next; 1029 sh_utmp_logout_morechecks((struct log_user *)user); 1030 SH_FREE((struct log_user *)user); 1031 user = NULL; 1032 #if defined(__linux__) 1033 } 1034 #endif 1035 } 1036 else 1037 { 1038 (void) sl_strlcpy(terminated_line, ut->ut_line, UT_HOSTSIZE); 1039 SH_MUTEX_LOCK(mutex_thread_nolog); 1040 (void) sh_unix_time (ut->ut_time, ttt, TIM_MAX); 1041 sh_error_handle( ShUtmpLogout, FIL__, __LINE__, 0, 1042 MSG_UT_LG3C, 1043 terminated_line, 1044 ttt, 0 1045 ); 1046 SH_MUTEX_UNLOCK(mutex_thread_nolog); 1047 } 1048 goto out; 1049 } 1050 1051 /* default */ 995 sh_utmp_log_one(ShUtmpLoginSolo, user, status); 996 997 } 998 else if (0 == sh_utmp_is_virtual(user->ut_tty, (char*)user->ut_host)) 999 { 1000 /* add this username to the list of logged in users */ 1001 status = sh_utmp_login_a((char*)user->name); 1002 1003 sh_utmp_log_multi(ShUtmpLoginMulti, user, status); 1004 } 1005 sh_utmp_login_morechecks(ut); 1052 1006 goto out; 1053 1007 1054 /* #ifdef HAVE_UTTYPE */1055 #else1056 1057 if (user == NULL) /* probably a login */1058 {1059 user = SH_ALLOC(sizeof(struct log_user));1060 sl_strlcpy(user->ut_tty, ut->ut_line, UT_LINESIZE+1);1061 sl_strlcpy(user->name, ut->ut_name, UT_NAMESIZE+1);1062 #ifdef HAVE_UTHOST1063 sl_strlcpy(user->ut_host, ut->ut_host, UT_HOSTSIZE+1);1064 #endif1065 #ifdef HAVE_UTADDR1066 #ifdef HAVE_UTADDR_V61067 my_inet_ntoa(ut->ut_addr_v6, user->ut_ship, SH_IP_BUF);1068 #else1069 my_inet_ntoa(ut->ut_addr, user->ut_ship, SH_IP_BUF);1070 #endif1071 #endif1072 user->time = ut->ut_time;1073 user->next = userlist;1074 userlist = user;1075 1076 SH_MUTEX_LOCK(mutex_thread_nolog);1077 (void) sh_unix_time (user->time, ttt, TIM_MAX);1078 sh_error_handle( ShUtmpLoginSolo, FIL__, __LINE__, 0,1079 #if defined(HAVE_UTHOST) && defined(HAVE_UTADDR)1080 MSG_UT_LG1X,1081 #elif defined(HAVE_UTHOST)1082 MSG_UT_LG1A,1083 #else1084 MSG_UT_LG1B,1085 #endif1086 user->name,1087 user->ut_tty,1088 #if defined(HAVE_UTHOST) && defined(HAVE_UTADDR)1089 user->ut_host,1090 user->ut_ship,1091 #elif defined(HAVE_UTHOST)1092 user->ut_host,1093 #endif1094 ttt,1095 11096 );1097 SH_MUTEX_UNLOCK(mutex_thread_nolog);1098 sh_utmp_login_morechecks(ut);1099 }1100 else /* probably a logout */1101 {1102 SH_MUTEX_LOCK(mutex_thread_nolog);1103 (void) sh_unix_time (ut->ut_time, ttt, TIM_MAX);1104 sh_error_handle( ShUtmpLogout, FIL__, __LINE__, 0,1105 #if defined(HAVE_UTHOST) && defined(HAVE_UTADDR)1106 MSG_UT_LG2X,1107 #elif defined(HAVE_UTHOST)1108 MSG_UT_LG2A,1109 #else1110 MSG_UT_LG2B,1111 #endif1112 user->name,1113 user->ut_tty,1114 #if defined(HAVE_UTHOST) && defined(HAVE_UTADDR)1115 user->ut_host,1116 user->ut_ship,1117 #elif defined(HAVE_UTHOST)1118 user->ut_host,1119 #endif1120 ttt,1121 11122 );1123 SH_MUTEX_UNLOCK(mutex_thread_nolog);1124 sh_utmp_logout_morechecks(user);1125 userold->next = user->next;1126 if (user == userlist) /* inserted Apr 4, 2004 */1127 userlist = user->next;1128 SH_FREE(user);1129 user = NULL;1130 }1131 1132 #endif1133 1008 1134 1009 out: … … 1136 1011 sh_dummy_850_userold = NULL; 1137 1012 1138 SL_RET0(_("sh_utmp_ addlogin"));1013 SL_RET0(_("sh_utmp_checklogin")); 1139 1014 } 1140 1015 1141 1016 static time_t lastmod = 0; 1142 static off_t lastsize = 0; 1143 static unsigned long lastread = 0; 1144 1145 static void sh_utmp_check_internal (int mode) 1017 1018 static void sh_utmp_check_internal () 1146 1019 { 1147 1020 struct stat buf; 1148 1021 int error; 1149 1022 struct SH_UTMP_S * ut; 1150 unsigned long this_read;1151 1023 int val_retry; 1024 time_t start_read; 1152 1025 1153 1026 SL_ENTER(_("sh_utmp_check_internal")); … … 1156 1029 */ 1157 1030 do { 1158 val_retry = /*@-unrecog@*/lstat ( mode_path[mode], &buf)/*@+unrecog@*/;1031 val_retry = /*@-unrecog@*/lstat ( utmp_path, &buf)/*@+unrecog@*/; 1159 1032 } while (val_retry < 0 && errno == EINTR); 1160 1033 … … 1164 1037 SH_MUTEX_LOCK(mutex_thread_nolog); 1165 1038 sh_error_handle((-1), FIL__, __LINE__, error, MSG_E_ACCESS, 1166 (long) sh.real.uid, mode_path[mode]);1039 (long) sh.real.uid, utmp_path); 1167 1040 SH_MUTEX_UNLOCK(mutex_thread_nolog); 1168 1041 SL_RET0(_("sh_utmp_check_internal")); 1169 1042 } 1170 1043 1171 /* modification time1044 /* check modification time 1172 1045 */ 1173 if (mode < 2) 1174 { 1175 if (/*@-usedef@*/buf.st_mtime <= lastmod/*@+usedef@*/) 1176 { 1177 SL_RET0(_("sh_utmp_check_internal")); 1178 } 1179 else 1180 lastmod = buf.st_mtime; 1181 } 1182 1183 /* file size 1184 */ 1185 if (/*@-usedef@*/buf.st_size < lastsize/*@+usedef@*/ && mode < 2) 1046 if (/*@-usedef@*/buf.st_mtime <= lastmod/*@+usedef@*/) 1186 1047 { 1187 SH_MUTEX_LOCK(mutex_thread_nolog); 1188 sh_error_handle((-1), FIL__, __LINE__, 0, MSG_UT_ROT, 1189 mode_path[mode]); 1190 SH_MUTEX_UNLOCK(mutex_thread_nolog); 1191 lastread = 0; 1192 #ifndef USE_SETUTENT 1193 sh_utmp_feed_forward = 0L; 1194 #endif 1195 } 1196 1197 if (mode < 2) 1198 lastsize = buf.st_size; 1199 1200 if (buf.st_size == 0) 1201 SL_RET0(_("sh_utmp_check_internal")); 1202 1203 sh_utmp_utmpname(mode_path[mode]); 1048 SL_RET0(_("sh_utmp_check_internal")); 1049 } 1050 else 1051 lastmod = buf.st_mtime; 1052 1053 sh_utmp_utmpname(utmp_path); 1204 1054 sh_utmp_setutent(); 1205 1206 /*1207 * feed forward if initializing1208 * we need to do this here1209 */1210 this_read = 0;1211 1212 if (mode < 2)1213 {1214 while (this_read < lastread) {1215 (void) sh_utmp_getutent();1216 ++this_read;1217 }1218 }1219 1055 1220 1056 /* start reading 1221 1057 */ 1222 this_read = 0; 1058 start_read = time(NULL); 1059 1223 1060 while (1 == 1) { 1224 1061 ut = sh_utmp_getutent(); … … 1226 1063 break; 1227 1064 /* modified: ut_user --> ut_name */ 1228 if ( mode == 1 || (mode == 2 &&ut->ut_name[0] != '\0'1065 if (ut->ut_name[0] != '\0' 1229 1066 #ifdef HAVE_UTTYPE 1230 && ut->ut_type != DEAD_PROCESS 1231 #endif 1232 )) 1233 sh_utmp_addlogin (ut); 1234 ++this_read; 1067 && ut->ut_type == USER_PROCESS 1068 #endif 1069 ) 1070 sh_utmp_checklogin (ut, start_read); 1235 1071 } 1236 1072 1237 1073 sh_utmp_endutent(); 1238 1074 1239 if (mode < 2) 1240 { 1241 lastread += this_read; 1242 #ifndef USE_SETUTENT 1243 sh_utmp_feed_forward += (long) (this_read * sizeof(struct SH_UTMP_S)); 1244 lastread = 0; 1245 #endif 1246 } 1075 sh_utmp_purge_old (start_read); 1247 1076 1248 1077 SL_RET0(_("sh_utmp_check_internal"));
Note:
See TracChangeset
for help on using the changeset viewer.