summaryrefslogtreecommitdiff
path: root/logintest.c
diff options
context:
space:
mode:
authorandre <andre>2000-06-13 00:43:47 +0000
committerandre <andre>2000-06-13 00:43:47 +0000
commit6e5d3475a54b33f73d057a83a0f9e4e6d01a5336 (patch)
tree754b49788ce75bc38ecbc22d867e922b8c90bff3 /logintest.c
parent55661d99b83cf8480993cd39e94d58d473c37c45 (diff)
downloadopenssh-git-6e5d3475a54b33f73d057a83a0f9e4e6d01a5336.tar.gz
Changed to OpenBSD indent and function declaration style
Added display of time when logging out, to try to catch lastlog bugs
Diffstat (limited to 'logintest.c')
-rw-r--r--logintest.c334
1 files changed, 173 insertions, 161 deletions
diff --git a/logintest.c b/logintest.c
index d7c62ab8..d974f6e4 100644
--- a/logintest.c
+++ b/logintest.c
@@ -48,7 +48,7 @@
#include "loginrec.h"
-RCSID("$Id: logintest.c,v 1.4 2000/06/13 00:29:34 andre Exp $");
+RCSID("$Id: logintest.c,v 1.5 2000/06/13 00:43:47 andre Exp $");
int nologtest = 0;
@@ -57,228 +57,240 @@ int be_verbose = 0;
/* Dump a logininfo to stdout. Assumes a tab size of 8 chars. */
-void dump_logininfo(struct logininfo *li, char *descname)
+void
+dump_logininfo(struct logininfo *li, char *descname)
{
- /* yes I know how nasty this is */
- printf("struct logininfo %s = {\n\t"
- "progname\t'%s'\n\ttype\t\t%d\n\t"
- "pid\t\t%d\n\tuid\t\t%d\n\t"
- "line\t\t'%s'\n\tusername\t'%s'\n\t"
- "hostname\t'%s'\n\texit\t\t%d\n\ttermination\t%d\n\t"
- "tv_sec\t%d\n\ttv_usec\t%d\n\t"
- "struct login_netinfo hostaddr {\n\t\t"
- "struct sockaddr sa {\n"
- "\t\t\tfamily\t%d\n\t\t}\n"
- "\t\t** !!! IP6 stuff not supported yet **\n"
- "\t}\n"
- "}\n",
- descname, li->progname, li->type,
- li->pid, li->uid, li->line,
- li->username, li->hostname, li->exit,
- li->termination, li->tv_sec, li->tv_usec,
- li->hostaddr.sa.sa_family);
+ /* yes I know how nasty this is */
+ printf("struct logininfo %s = {\n\t"
+ "progname\t'%s'\n\ttype\t\t%d\n\t"
+ "pid\t\t%d\n\tuid\t\t%d\n\t"
+ "line\t\t'%s'\n\tusername\t'%s'\n\t"
+ "hostname\t'%s'\n\texit\t\t%d\n\ttermination\t%d\n\t"
+ "tv_sec\t%d\n\ttv_usec\t%d\n\t"
+ "struct login_netinfo hostaddr {\n\t\t"
+ "struct sockaddr sa {\n"
+ "\t\t\tfamily\t%d\n\t\t}\n"
+ "\t\t** !!! IP6 stuff not supported yet **\n"
+ "\t}\n"
+ "}\n",
+ descname, li->progname, li->type,
+ li->pid, li->uid, li->line,
+ li->username, li->hostname, li->exit,
+ li->termination, li->tv_sec, li->tv_usec,
+ li->hostaddr.sa.sa_family);
}
-int testAPI()
+int
+testAPI()
{
- struct logininfo *li1;
- struct passwd *pw;
- struct hostent *he;
- struct sockaddr_in sa_in4;
- char cmdstring[256], stripline[8];
- char username[32];
+ struct logininfo *li1;
+ struct passwd *pw;
+ struct hostent *he;
+ struct sockaddr_in sa_in4;
+ char cmdstring[256], stripline[8];
+ char username[32];
#ifdef HAVE_TIME_H
- time_t t0, t1, t2;
- char s_t0[64],s_t1[64],s_t2[64]; /* ctime() strings */
+ time_t t0, t1, t2, logouttime;
+ char s_t0[64],s_t1[64],s_t2[64], s_logouttime[64]; /* ctime() strings */
#endif
- printf("**\n** Testing the API...\n**\n");
-
- pw = getpwuid(getuid());
- strlcpy(username, pw->pw_name, sizeof(username));
-
- /* gethostname(hostname, sizeof(hostname)); */
-
- printf("login_alloc_entry test (no host info):\n");
- /* !!! fake tty more effectively */
- li1 = login_alloc_entry((int)getpid(), username, NULL, ttyname(0));
- strlcpy(li1->progname, "OpenSSH-logintest", sizeof(li1->progname));
-
- if (be_verbose)
- dump_logininfo(li1, "li1");
-
- printf("Setting host address info for 'localhost' (may call out):\n");
- if (! (he = gethostbyname("localhost"))) {
- printf("Couldn't set hostname(lookup failed)\n");
- } else {
- /* NOTE: this is messy, but typically a program wouldn't have to set
- * any of this, a sockaddr_in* would be already prepared */
- memcpy((void *)&(sa_in4.sin_addr), (void *)&(he->h_addr_list[0][0]),
- sizeof(struct in_addr));
- login_set_addr(li1, (struct sockaddr *) &sa_in4, sizeof(sa_in4));
- strlcpy(li1->hostname, "localhost", sizeof(li1->hostname));
- }
- if (be_verbose)
- dump_logininfo(li1, "li1");
-
- if ((int)geteuid() != 0) {
- printf("NOT RUNNING LOGIN TESTS - you are not root!\n");
- return 1; /* this isn't necessarily an error */
- }
-
- if (nologtest)
- return 1;
+ printf("**\n** Testing the API...\n**\n");
+
+ pw = getpwuid(getuid());
+ strlcpy(username, pw->pw_name, sizeof(username));
+
+ /* gethostname(hostname, sizeof(hostname)); */
+
+ printf("login_alloc_entry test (no host info):\n");
+ /* !!! fake tty more effectively */
+ li1 = login_alloc_entry((int)getpid(), username, NULL, ttyname(0));
+ strlcpy(li1->progname, "OpenSSH-logintest", sizeof(li1->progname));
+
+ if (be_verbose)
+ dump_logininfo(li1, "li1");
+
+ printf("Setting host address info for 'localhost' (may call out):\n");
+ if (! (he = gethostbyname("localhost"))) {
+ printf("Couldn't set hostname(lookup failed)\n");
+ } else {
+ /* NOTE: this is messy, but typically a program wouldn't have to set
+ * any of this, a sockaddr_in* would be already prepared */
+ memcpy((void *)&(sa_in4.sin_addr), (void *)&(he->h_addr_list[0][0]),
+ sizeof(struct in_addr));
+ login_set_addr(li1, (struct sockaddr *) &sa_in4, sizeof(sa_in4));
+ strlcpy(li1->hostname, "localhost", sizeof(li1->hostname));
+ }
+ if (be_verbose)
+ dump_logininfo(li1, "li1");
+
+ if ((int)geteuid() != 0) {
+ printf("NOT RUNNING LOGIN TESTS - you are not root!\n");
+ return 1; /* this isn't necessarily an error */
+ }
+
+ if (nologtest)
+ return 1;
- line_stripname(stripline, li1->line, sizeof(stripline));
+ line_stripname(stripline, li1->line, sizeof(stripline));
- printf("Performing an invalid login attempt (no type field)\n--\n");
- login_write(li1);
- printf("--\n(Should have written an error to stderr)\n");
+ printf("Performing an invalid login attempt (no type field)\n--\n");
+ login_write(li1);
+ printf("--\n(Should have written an error to stderr)\n");
#ifdef HAVE_TIME_H
- (void)time(&t0);
- strlcpy(s_t0, ctime(&t0), sizeof(s_t0));
- t1 = login_get_lastlog_time(getuid());
- strlcpy(s_t1, ctime(&t1), sizeof(s_t1));
- printf("Before logging in:\n\tcurrent time is %d - %s\t"
- "lastlog time is %d - %s\n",
- (int)t0, s_t0, (int)t1, s_t1);
+ (void)time(&t0);
+ strlcpy(s_t0, ctime(&t0), sizeof(s_t0));
+ t1 = login_get_lastlog_time(getuid());
+ strlcpy(s_t1, ctime(&t1), sizeof(s_t1));
+ printf("Before logging in:\n\tcurrent time is %d - %s\t"
+ "lastlog time is %d - %s\n",
+ (int)t0, s_t0, (int)t1, s_t1);
#endif
- printf("Performing a login on line %s...\n--\n", stripline);
- login_login(li1);
+ printf("Performing a login on line %s...\n--\n", stripline);
+ login_login(li1);
- snprintf(cmdstring, sizeof(cmdstring), "who | grep '%s '",
- stripline);
- system(cmdstring);
+ snprintf(cmdstring, sizeof(cmdstring), "who | grep '%s '",
+ stripline);
+ system(cmdstring);
- printf("--\nWaiting for a few seconds...\n");
- sleep(2);
+ printf("--\nWaiting for a few seconds...\n");
+ sleep(2);
- printf("Performing a logout (the root login "
- "shown above should be gone)\n"
- "If the root login hasn't gone, but another user on the same\n"
- "pty has, this is OK - we're hacking it here, and there\n"
- "shouldn't be two users on one pty in reality...\n"
- "-- ('who' output follows)\n");
- login_logout(li1);
+ printf("Performing a logout ");
+#ifdef HAVE_TIME_H
+ (void)time(&logouttime);
+ strlcpy(s_logouttime, ctime(&logouttime), sizeof(s_logouttime));
+ printf("at %d - %s", (int)logouttime, s_logouttime);
+#endif
+ printf("(the root login shown above should be gone)\n"
+ "If the root login hasn't gone, but another user on the same\n"
+ "pty has, this is OK - we're hacking it here, and there\n"
+ "shouldn't be two users on one pty in reality...\n"
+ "-- ('who' output follows)\n");
+ login_logout(li1);
- system(cmdstring);
- printf("-- ('who' output ends)\n");
+ system(cmdstring);
+ printf("-- ('who' output ends)\n");
#ifdef HAVE_TIME_H
- t2 = login_get_lastlog_time(getuid());
- strlcpy(s_t2, ctime(&t2), sizeof(s_t2));
- printf("After logging in, lastlog time is %d - %s\n", (int)t2, s_t2);
- if (t1 == t2)
- printf("The lastlog times before and after logging in are the "
- "same.\nThis indicates that lastlog is ** NOT WORKING "
- "CORRECTLY **\n");
- else if (t0 != t2)
- printf("** The login time and the lastlog time differ.\n"
- "** This indicates that lastlog is either recording the "
- "wrong time,\n** or retrieving the wrong entry.\n");
- else
- printf("lastlog agrees with the login time. This is a good thing.\n");
+ t2 = login_get_lastlog_time(getuid());
+ strlcpy(s_t2, ctime(&t2), sizeof(s_t2));
+ printf("After logging in, lastlog time is %d - %s\n", (int)t2, s_t2);
+ if (t1 == t2)
+ printf("The lastlog times before and after logging in are the "
+ "same.\nThis indicates that lastlog is ** NOT WORKING "
+ "CORRECTLY **\n");
+ else if (t0 != t2)
+ printf("** The login time and the lastlog time differ.\n"
+ "** This indicates that lastlog is either recording the "
+ "wrong time,\n** or retrieving the wrong entry.\n");
+ else
+ printf("lastlog agrees with the login time. This is a good thing.\n");
#endif
- printf("--\nThe output of 'last' shown next should have "
- "an entry for root \n on %s for the time shown above:\n--\n",
- stripline);
- snprintf(cmdstring, sizeof(cmdstring), "last | grep '%s ' | head -3",
- stripline);
- system(cmdstring);
+ printf("--\nThe output of 'last' shown next should have "
+ "an entry for root \n on %s for the time shown above:\n--\n",
+ stripline);
+ snprintf(cmdstring, sizeof(cmdstring), "last | grep '%s ' | head -3",
+ stripline);
+ system(cmdstring);
- printf("--\nEnd of login test.\n");
+ printf("--\nEnd of login test.\n");
- login_free_entry(li1);
+ login_free_entry(li1);
- return 1;
+ return 1;
} /* testAPI() */
-void testLineName(char *line)
+void
+testLineName(char *line)
{
- /* have to null-terminate - these functions are designed for
- * structures with fixed-length char arrays, and don't null-term.*/
- char full[17], strip[9], abbrev[5];
+ /* have to null-terminate - these functions are designed for
+ * structures with fixed-length char arrays, and don't null-term.*/
+ char full[17], strip[9], abbrev[5];
- memset(full, '\0', sizeof(full));
- memset(strip, '\0', sizeof(strip));
- memset(abbrev, '\0', sizeof(abbrev));
+ memset(full, '\0', sizeof(full));
+ memset(strip, '\0', sizeof(strip));
+ memset(abbrev, '\0', sizeof(abbrev));
- line_fullname(full, line, sizeof(full)-1);
- line_stripname(strip, full, sizeof(strip)-1);
- line_abbrevname(abbrev, full, sizeof(abbrev)-1);
- printf("%s: %s, %s, %s\n", line, full, strip, abbrev);
+ line_fullname(full, line, sizeof(full)-1);
+ line_stripname(strip, full, sizeof(strip)-1);
+ line_abbrevname(abbrev, full, sizeof(abbrev)-1);
+ printf("%s: %s, %s, %s\n", line, full, strip, abbrev);
} /* testLineName() */
-int testOutput() {
- printf("**\n** Testing linename functions\n**\n");
- testLineName("/dev/pts/1");
- testLineName("pts/1");
- testLineName("pts/999");
- testLineName("/dev/ttyp00");
- testLineName("ttyp00");
-
- return 1;
+int
+testOutput()
+{
+ printf("**\n** Testing linename functions\n**\n");
+ testLineName("/dev/pts/1");
+ testLineName("pts/1");
+ testLineName("pts/999");
+ testLineName("/dev/ttyp00");
+ testLineName("ttyp00");
+
+ return 1;
} /* testOutput() */
/* show which options got compiled in */
-void showOptions(void)
+void
+showOptions(void)
{
- printf("**\n** Compile-time options\n**\n");
+ printf("**\n** Compile-time options\n**\n");
- printf("login recording methods selected:\n");
+ printf("login recording methods selected:\n");
#ifdef USE_LOGIN
- printf("\tUSE_LOGIN\n");
+ printf("\tUSE_LOGIN\n");
#endif
#ifdef USE_UTMP
- printf("\tUSE_UTMP (UTMP_FILE=%s)\n", UTMP_FILE);
+ printf("\tUSE_UTMP (UTMP_FILE=%s)\n", UTMP_FILE);
#endif
#ifdef USE_UTMPX
- printf("\tUSE_UTMPX (UTMPX_FILE=%s)\n", UTMPX_FILE);
+ printf("\tUSE_UTMPX (UTMPX_FILE=%s)\n", UTMPX_FILE);
#endif
#ifdef USE_WTMP
- printf("\tUSE_WTMP (WTMP_FILE=%s)\n", WTMP_FILE);
+ printf("\tUSE_WTMP (WTMP_FILE=%s)\n", WTMP_FILE);
#endif
#ifdef USE_WTMPX
- printf("\tUSE_WTMPX (WTMPX_FILE=%s)\n", WTMPX_FILE);
+ printf("\tUSE_WTMPX (WTMPX_FILE=%s)\n", WTMPX_FILE);
#endif
#ifdef USE_LASTLOG
- printf("\tUSE_LASTLOG (LASTLOG_FILE=%s)\n", LASTLOG_FILE);
+ printf("\tUSE_LASTLOG (LASTLOG_FILE=%s)\n", LASTLOG_FILE);
#endif
- printf("\n");
+ printf("\n");
} /* showOptions() */
-int main(int argc, char *argv[])
+int
+main(int argc, char *argv[])
{
- printf("Platform-independent login recording test driver\n");
-
- if (argc == 2) {
- if (strncmp(argv[1], "-i", 3) == 0)
- compile_opts_only = 1;
- else if (strncmp(argv[1], "-v", 3) == 0)
- be_verbose=1;
- }
+ printf("Platform-independent login recording test driver\n");
+
+ if (argc == 2) {
+ if (strncmp(argv[1], "-i", 3) == 0)
+ compile_opts_only = 1;
+ else if (strncmp(argv[1], "-v", 3) == 0)
+ be_verbose=1;
+ }
- if (!compile_opts_only) {
- if (be_verbose && !testOutput())
- return 1;
+ if (!compile_opts_only) {
+ if (be_verbose && !testOutput())
+ return 1;
- if (!testAPI())
- return 1;
- }
+ if (!testAPI())
+ return 1;
+ }
- showOptions();
+ showOptions();
- return 0;
+ return 0;
} /* main() */