summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--logintest.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/logintest.c b/logintest.c
index d974f6e49..886052313 100644
--- a/logintest.c
+++ b/logintest.c
@@ -32,7 +32,7 @@
32 ** and lastlog retrieval 32 ** and lastlog retrieval
33 **/ 33 **/
34 34
35#include "config.h" 35#include "includes.h"
36 36
37#include <sys/types.h> 37#include <sys/types.h>
38#include <sys/wait.h> 38#include <sys/wait.h>
@@ -48,9 +48,11 @@
48 48
49#include "loginrec.h" 49#include "loginrec.h"
50 50
51RCSID("$Id: logintest.c,v 1.5 2000/06/13 00:43:47 andre Exp $"); 51RCSID("$Id: logintest.c,v 1.6 2000/06/19 08:25:36 andre Exp $");
52 52
53 53
54#define PAUSE_BEFORE_LOGOUT 3
55
54int nologtest = 0; 56int nologtest = 0;
55int compile_opts_only = 0; 57int compile_opts_only = 0;
56int be_verbose = 0; 58int be_verbose = 0;
@@ -70,7 +72,6 @@ dump_logininfo(struct logininfo *li, char *descname)
70 "struct login_netinfo hostaddr {\n\t\t" 72 "struct login_netinfo hostaddr {\n\t\t"
71 "struct sockaddr sa {\n" 73 "struct sockaddr sa {\n"
72 "\t\t\tfamily\t%d\n\t\t}\n" 74 "\t\t\tfamily\t%d\n\t\t}\n"
73 "\t\t** !!! IP6 stuff not supported yet **\n"
74 "\t}\n" 75 "\t}\n"
75 "}\n", 76 "}\n",
76 descname, li->progname, li->type, 77 descname, li->progname, li->type,
@@ -91,8 +92,9 @@ testAPI()
91 char cmdstring[256], stripline[8]; 92 char cmdstring[256], stripline[8];
92 char username[32]; 93 char username[32];
93#ifdef HAVE_TIME_H 94#ifdef HAVE_TIME_H
94 time_t t0, t1, t2, logouttime; 95 time_t t0, t1, t2, logintime, logouttime;
95 char s_t0[64],s_t1[64],s_t2[64], s_logouttime[64]; /* ctime() strings */ 96 char s_t0[64],s_t1[64],s_t2[64];
97 char s_logintime[64], s_logouttime[64]; /* ctime() strings */
96#endif 98#endif
97 99
98 printf("**\n** Testing the API...\n**\n"); 100 printf("**\n** Testing the API...\n**\n");
@@ -103,7 +105,8 @@ testAPI()
103 /* gethostname(hostname, sizeof(hostname)); */ 105 /* gethostname(hostname, sizeof(hostname)); */
104 106
105 printf("login_alloc_entry test (no host info):\n"); 107 printf("login_alloc_entry test (no host info):\n");
106 /* !!! fake tty more effectively */ 108
109 /* FIXME fake tty more effectively - this could upset some platforms */
107 li1 = login_alloc_entry((int)getpid(), username, NULL, ttyname(0)); 110 li1 = login_alloc_entry((int)getpid(), username, NULL, ttyname(0));
108 strlcpy(li1->progname, "OpenSSH-logintest", sizeof(li1->progname)); 111 strlcpy(li1->progname, "OpenSSH-logintest", sizeof(li1->progname));
109 112
@@ -126,7 +129,7 @@ testAPI()
126 129
127 if ((int)geteuid() != 0) { 130 if ((int)geteuid() != 0) {
128 printf("NOT RUNNING LOGIN TESTS - you are not root!\n"); 131 printf("NOT RUNNING LOGIN TESTS - you are not root!\n");
129 return 1; /* this isn't necessarily an error */ 132 return 1;
130 } 133 }
131 134
132 if (nologtest) 135 if (nologtest)
@@ -136,7 +139,7 @@ testAPI()
136 139
137 printf("Performing an invalid login attempt (no type field)\n--\n"); 140 printf("Performing an invalid login attempt (no type field)\n--\n");
138 login_write(li1); 141 login_write(li1);
139 printf("--\n(Should have written an error to stderr)\n"); 142 printf("--\n(Should have written errors to stderr)\n");
140 143
141#ifdef HAVE_TIME_H 144#ifdef HAVE_TIME_H
142 (void)time(&t0); 145 (void)time(&t0);
@@ -148,15 +151,21 @@ testAPI()
148 (int)t0, s_t0, (int)t1, s_t1); 151 (int)t0, s_t0, (int)t1, s_t1);
149#endif 152#endif
150 153
151 printf("Performing a login on line %s...\n--\n", stripline); 154 printf("Performing a login on line %s ", stripline);
155#ifdef HAVE_TIME_H
156 (void)time(&logintime);
157 strlcpy(s_logintime, ctime(&logintime), sizeof(s_logintime));
158 printf("at %d - %s", (int)logintime, s_logintime);
159#endif
160 printf("--\n");
152 login_login(li1); 161 login_login(li1);
153 162
154 snprintf(cmdstring, sizeof(cmdstring), "who | grep '%s '", 163 snprintf(cmdstring, sizeof(cmdstring), "who | grep '%s '",
155 stripline); 164 stripline);
156 system(cmdstring); 165 system(cmdstring);
157 166
158 printf("--\nWaiting for a few seconds...\n"); 167 printf("--\nPausing for %d second(s)...\n", PAUSE_BEFORE_LOGOUT);
159 sleep(2); 168 sleep(PAUSE_BEFORE_LOGOUT);
160 169
161 printf("Performing a logout "); 170 printf("Performing a logout ");
162#ifdef HAVE_TIME_H 171#ifdef HAVE_TIME_H
@@ -164,7 +173,7 @@ testAPI()
164 strlcpy(s_logouttime, ctime(&logouttime), sizeof(s_logouttime)); 173 strlcpy(s_logouttime, ctime(&logouttime), sizeof(s_logouttime));
165 printf("at %d - %s", (int)logouttime, s_logouttime); 174 printf("at %d - %s", (int)logouttime, s_logouttime);
166#endif 175#endif
167 printf("(the root login shown above should be gone)\n" 176 printf("\nThe root login shown above should be gone.\n"
168 "If the root login hasn't gone, but another user on the same\n" 177 "If the root login hasn't gone, but another user on the same\n"
169 "pty has, this is OK - we're hacking it here, and there\n" 178 "pty has, this is OK - we're hacking it here, and there\n"
170 "shouldn't be two users on one pty in reality...\n" 179 "shouldn't be two users on one pty in reality...\n"
@@ -183,9 +192,13 @@ testAPI()
183 "same.\nThis indicates that lastlog is ** NOT WORKING " 192 "same.\nThis indicates that lastlog is ** NOT WORKING "
184 "CORRECTLY **\n"); 193 "CORRECTLY **\n");
185 else if (t0 != t2) 194 else if (t0 != t2)
195 /* We can be off by a second or so, even when recording works fine.
196 * I'm not 100% sure why, but it's true. */
186 printf("** The login time and the lastlog time differ.\n" 197 printf("** The login time and the lastlog time differ.\n"
187 "** This indicates that lastlog is either recording the " 198 "** This indicates that lastlog is either recording the "
188 "wrong time,\n** or retrieving the wrong entry.\n"); 199 "wrong time,\n** or retrieving the wrong entry.\n"
200 "If it's off by less than %d second(s) "
201 "run the test again.\n", PAUSE_BEFORE_LOGOUT);
189 else 202 else
190 printf("lastlog agrees with the login time. This is a good thing.\n"); 203 printf("lastlog agrees with the login time. This is a good thing.\n");
191 204