diff options
Diffstat (limited to 'logintest.c')
-rw-r--r-- | logintest.c | 65 |
1 files changed, 21 insertions, 44 deletions
diff --git a/logintest.c b/logintest.c index d26f9ef9e..f7e3e99a4 100644 --- a/logintest.c +++ b/logintest.c | |||
@@ -48,7 +48,7 @@ | |||
48 | 48 | ||
49 | #include "loginrec.h" | 49 | #include "loginrec.h" |
50 | 50 | ||
51 | RCSID("$Id: logintest.c,v 1.1 2000/06/03 14:57:40 andre Exp $"); | 51 | RCSID("$Id: logintest.c,v 1.2 2000/06/04 17:07:49 andre Exp $"); |
52 | 52 | ||
53 | 53 | ||
54 | int nologtest = 0; | 54 | int nologtest = 0; |
@@ -56,23 +56,9 @@ int compile_opts_only = 0; | |||
56 | int be_verbose = 0; | 56 | int be_verbose = 0; |
57 | 57 | ||
58 | 58 | ||
59 | #define DOTQUAD_MAXSIZE 17 | ||
60 | void dump_dotquad(char *s, struct in_addr *sin4) { | ||
61 | unsigned int addr; | ||
62 | |||
63 | addr = ntohl(sin4->s_addr); | ||
64 | snprintf(s, DOTQUAD_MAXSIZE, "%d.%d.%d.%d", | ||
65 | (addr >> 24)& 0xff, (addr >>16) & 0xff, | ||
66 | (addr >>8) & 0xff, addr & 0xff ); | ||
67 | } /* dump_dotquad */ | ||
68 | |||
69 | |||
70 | /* Dump a logininfo to stdout. Assumes a tab size of 8 chars. */ | 59 | /* Dump a logininfo to stdout. Assumes a tab size of 8 chars. */ |
71 | void dump_logininfo(struct logininfo *li, char *descname) { | 60 | void dump_logininfo(struct logininfo *li, char *descname) |
72 | char a4[DOTQUAD_MAXSIZE]; | 61 | { |
73 | |||
74 | dump_dotquad(a4, &(li->hostaddr.sa_in4.sin_addr)); | ||
75 | |||
76 | /* yes I know how nasty this is */ | 62 | /* yes I know how nasty this is */ |
77 | printf("struct logininfo %s = {\n\t" | 63 | printf("struct logininfo %s = {\n\t" |
78 | "progname\t'%s'\n\ttype\t\t%d\n\t" | 64 | "progname\t'%s'\n\ttype\t\t%d\n\t" |
@@ -81,8 +67,8 @@ void dump_logininfo(struct logininfo *li, char *descname) { | |||
81 | "hostname\t'%s'\n\texit\t\t%d\n\ttermination\t%d\n\t" | 67 | "hostname\t'%s'\n\texit\t\t%d\n\ttermination\t%d\n\t" |
82 | "tv_sec\t%d\n\ttv_usec\t%d\n\t" | 68 | "tv_sec\t%d\n\ttv_usec\t%d\n\t" |
83 | "struct login_netinfo hostaddr {\n\t\t" | 69 | "struct login_netinfo hostaddr {\n\t\t" |
84 | "struct sockaddr_in sa_in4 {\n" | 70 | "struct sockaddr sa {\n" |
85 | "\t\t\tsin_port\t%d\n\t\t\t*sin_addr\t%d(%s)\n\t\t}\n" | 71 | "\t\t\tfamily\t%d\n\t\t}\n" |
86 | "\t\t** !!! IP6 stuff not supported yet **\n" | 72 | "\t\t** !!! IP6 stuff not supported yet **\n" |
87 | "\t}\n" | 73 | "\t}\n" |
88 | "}\n", | 74 | "}\n", |
@@ -90,13 +76,12 @@ void dump_logininfo(struct logininfo *li, char *descname) { | |||
90 | li->pid, li->uid, li->line, | 76 | li->pid, li->uid, li->line, |
91 | li->username, li->hostname, li->exit, | 77 | li->username, li->hostname, li->exit, |
92 | li->termination, li->tv_sec, li->tv_usec, | 78 | li->termination, li->tv_sec, li->tv_usec, |
93 | ntohs(li->hostaddr.sa_in4.sin_port), | 79 | li->hostaddr.sa.sa_family); |
94 | ntohl(li->hostaddr.sa_in4.sin_addr.s_addr), a4); | ||
95 | /* FIXME: (ATL) print sockaddr_in6 stuff */ | ||
96 | } | 80 | } |
97 | 81 | ||
98 | 82 | ||
99 | int testAPI() { | 83 | int testAPI() |
84 | { | ||
100 | struct logininfo *li1; | 85 | struct logininfo *li1; |
101 | struct passwd *pw; | 86 | struct passwd *pw; |
102 | struct hostent *he; | 87 | struct hostent *he; |
@@ -118,12 +103,12 @@ int testAPI() { | |||
118 | printf("login_alloc_entry test (no host info):\n"); | 103 | printf("login_alloc_entry test (no host info):\n"); |
119 | /* !!! fake tty more effectively */ | 104 | /* !!! fake tty more effectively */ |
120 | li1 = login_alloc_entry((int)getpid(), username, NULL, ttyname(0)); | 105 | li1 = login_alloc_entry((int)getpid(), username, NULL, ttyname(0)); |
121 | login_set_progname(li1, "testlogin"); | 106 | strlcpy(li1->progname, "OpenSSH-logintest", sizeof(li1->progname)); |
122 | 107 | ||
123 | if (be_verbose) | 108 | if (be_verbose) |
124 | dump_logininfo(li1, "li1"); | 109 | dump_logininfo(li1, "li1"); |
125 | 110 | ||
126 | printf("Setting IPv4 host info for 'localhost' (may call out):\n"); | 111 | printf("Setting host address info for 'localhost' (may call out):\n"); |
127 | if (! (he = gethostbyname("localhost"))) { | 112 | if (! (he = gethostbyname("localhost"))) { |
128 | printf("Couldn't set hostname(lookup failed)\n"); | 113 | printf("Couldn't set hostname(lookup failed)\n"); |
129 | } else { | 114 | } else { |
@@ -131,8 +116,8 @@ int testAPI() { | |||
131 | * any of this, a sockaddr_in* would be already prepared */ | 116 | * any of this, a sockaddr_in* would be already prepared */ |
132 | memcpy((void *)&(sa_in4.sin_addr), (void *)&(he->h_addr_list[0][0]), | 117 | memcpy((void *)&(sa_in4.sin_addr), (void *)&(he->h_addr_list[0][0]), |
133 | sizeof(struct in_addr)); | 118 | sizeof(struct in_addr)); |
134 | login_set_ip4(li1, &sa_in4); | 119 | login_set_addr(li1, (struct sockaddr *) &sa_in4, sizeof(sa_in4)); |
135 | login_set_hostname(li1, "localhost"); | 120 | strlcpy(li1->hostname, "localhost", sizeof(li1->hostname)); |
136 | } | 121 | } |
137 | if (be_verbose) | 122 | if (be_verbose) |
138 | dump_logininfo(li1, "li1"); | 123 | dump_logininfo(li1, "li1"); |
@@ -154,7 +139,7 @@ int testAPI() { | |||
154 | #ifdef HAVE_TIME_H | 139 | #ifdef HAVE_TIME_H |
155 | (void)time(&t0); | 140 | (void)time(&t0); |
156 | strlcpy(s_t0, ctime(&t0), sizeof(s_t0)); | 141 | strlcpy(s_t0, ctime(&t0), sizeof(s_t0)); |
157 | t1 = login_getlasttime_uid(getuid()); | 142 | t1 = login_get_lastlog_time(getuid()); |
158 | strlcpy(s_t1, ctime(&t1), sizeof(s_t1)); | 143 | strlcpy(s_t1, ctime(&t1), sizeof(s_t1)); |
159 | printf("Before logging in:\n\tcurrent time is %d - %s\t" | 144 | printf("Before logging in:\n\tcurrent time is %d - %s\t" |
160 | "lastlog time is %d - %s\n", | 145 | "lastlog time is %d - %s\n", |
@@ -183,7 +168,7 @@ int testAPI() { | |||
183 | printf("-- ('who' output ends)\n"); | 168 | printf("-- ('who' output ends)\n"); |
184 | 169 | ||
185 | #ifdef HAVE_TIME_H | 170 | #ifdef HAVE_TIME_H |
186 | t2 = login_getlasttime_uid(getuid()); | 171 | t2 = login_get_lastlog_time(getuid()); |
187 | strlcpy(s_t2, ctime(&t2), sizeof(s_t2)); | 172 | strlcpy(s_t2, ctime(&t2), sizeof(s_t2)); |
188 | printf("After logging in, lastlog time is %d - %s\n", (int)t2, s_t2); | 173 | printf("After logging in, lastlog time is %d - %s\n", (int)t2, s_t2); |
189 | if (t1 == t2) | 174 | if (t1 == t2) |
@@ -214,7 +199,8 @@ int testAPI() { | |||
214 | } /* testAPI() */ | 199 | } /* testAPI() */ |
215 | 200 | ||
216 | 201 | ||
217 | void testLineName(char *line) { | 202 | void testLineName(char *line) |
203 | { | ||
218 | /* have to null-terminate - these functions are designed for | 204 | /* have to null-terminate - these functions are designed for |
219 | * structures with fixed-length char arrays, and don't null-term.*/ | 205 | * structures with fixed-length char arrays, and don't null-term.*/ |
220 | char full[17], strip[9], abbrev[5]; | 206 | char full[17], strip[9], abbrev[5]; |
@@ -244,8 +230,8 @@ int testOutput() { | |||
244 | 230 | ||
245 | 231 | ||
246 | /* show which options got compiled in */ | 232 | /* show which options got compiled in */ |
247 | void showOptions(void) { | 233 | void showOptions(void) |
248 | 234 | { | |
249 | printf("**\n** Compile-time options\n**\n"); | 235 | printf("**\n** Compile-time options\n**\n"); |
250 | 236 | ||
251 | printf("login recording methods selected:\n"); | 237 | printf("login recording methods selected:\n"); |
@@ -269,21 +255,12 @@ void showOptions(void) { | |||
269 | #endif | 255 | #endif |
270 | printf("\n"); | 256 | printf("\n"); |
271 | 257 | ||
272 | printf("IP6 support: %s\n", | ||
273 | #ifdef HAVE_IP6 | ||
274 | "enabled" | ||
275 | #else | ||
276 | "disabled" | ||
277 | #endif | ||
278 | ); | ||
279 | |||
280 | |||
281 | } /* showOptions() */ | 258 | } /* showOptions() */ |
282 | 259 | ||
283 | 260 | ||
284 | int main(int argc, char *argv[]) { | 261 | int main(int argc, char *argv[]) |
285 | 262 | { | |
286 | printf("Platform-independent login recording test driver"); | 263 | printf("Platform-independent login recording test driver\n"); |
287 | 264 | ||
288 | if (argc == 2) { | 265 | if (argc == 2) { |
289 | if (strncmp(argv[1], "-i", 3) == 0) | 266 | if (strncmp(argv[1], "-i", 3) == 0) |