summaryrefslogtreecommitdiffstats
path: root/login-utils
diff options
context:
space:
mode:
authorKarel Zak2007-03-09 14:56:18 +0100
committerKarel Zak2007-03-09 14:56:18 +0100
commit71562c1fddf8d025b5de94d1df3b89278fc679b2 (patch)
treeac33dd6e1441c543400cdf7a05869251c04eebe6 /login-utils
parentlogin: update 32bit utmp correctly on 64bit system (diff)
downloadkernel-qcow2-util-linux-71562c1fddf8d025b5de94d1df3b89278fc679b2.tar.gz
kernel-qcow2-util-linux-71562c1fddf8d025b5de94d1df3b89278fc679b2.tar.xz
kernel-qcow2-util-linux-71562c1fddf8d025b5de94d1df3b89278fc679b2.zip
login: add regression test for IP address checking code
The hnmatch() in checktty.c is checking IP addresses if the login util is compiled without PAM support. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'login-utils')
-rw-r--r--login-utils/Makefile.am5
-rw-r--r--login-utils/checktty.c59
2 files changed, 64 insertions, 0 deletions
diff --git a/login-utils/Makefile.am b/login-utils/Makefile.am
index cc894e196..0a36e158f 100644
--- a/login-utils/Makefile.am
+++ b/login-utils/Makefile.am
@@ -116,3 +116,8 @@ install-exec-hook::
cd $(DESTDIR)$(mandir)/man8 && ln -sf initctl.8 provide.8
endif
+
+noinst_PROGRAMS = checktty_test
+checktty_test_SOURCES = checktty.c login.h
+checktty_test_CFLAGS = -DMAIN_TEST_CHECKTTY
+
diff --git a/login-utils/checktty.c b/login-utils/checktty.c
index 9c3ce46d0..f47b7ad4d 100644
--- a/login-utils/checktty.c
+++ b/login-utils/checktty.c
@@ -186,6 +186,65 @@ hnmatch(const char *hn, const char *pat)
}
}
+#ifdef MAIN_TEST_CHECKTTY
+
+char hostaddress[4];
+char *hostname;
+void sleepexit(int eval) {} /* dummy for this test */
+void badlogin(const char *s) {} /* dummy for this test */
+
+int
+main(int argc, char **argv)
+{
+ struct addrinfo hints, *info = NULL;
+ struct addrexp {
+ const char *range;
+ const char *ip;
+ } alist[] = {
+ { "130.225.16.0/255.255.254.0", "130.225.16.1" },
+ { "130.225.16.0/255.255.254.0", "10.20.30.1" },
+ { "130.225.0.0/255.254.0.0", "130.225.16.1" },
+ { "130.225.0.0/255.254.0.0", "130.225.17.1" },
+ { "130.225.0.0/255.254.0.0", "150.160.170.180" },
+ { NULL, NULL }
+ }, *item;
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_INET;
+ hints.ai_flags = AI_NUMERICHOST | AI_PASSIVE | AI_ADDRCONFIG;
+ hints.ai_socktype = SOCK_STREAM;
+
+ for (item = alist; item->range; item++) {
+
+ printf("hnmatch() on %-30s <-- %-15s: ", item->range, item->ip);
+
+ if (getaddrinfo(item->ip, NULL, &hints, &info)==0 && info) {
+ if (info->ai_family == AF_INET) {
+ struct sockaddr_in *sa =
+ (struct sockaddr_in *) info->ai_addr;
+ memcpy(hostaddress, &(sa->sin_addr),
+ sizeof(sa->sin_addr));
+ }
+/***
+ if (info->ai_family == AF_INET6) {
+ struct sockaddr_in6 *sa =
+ (struct sockaddr_in6 *) info->ai_addr;
+ memcpy(hostaddress, &(sa->sin6_addr),
+ sizeof(sa->sin6_addr));
+ }
+***/
+ freeaddrinfo(info);
+ printf("%s\n", hnmatch("dummy", item->range) ?
+ "match" : "mismatch");
+ }
+ else
+ printf("getaddrinfo() failed\n");
+
+ }
+ return 0;
+}
+#endif /* MAIN_TEST_CHECKTTY */
+
static char *wdays[] = { "sun", "mon", "tue", "wed", "thu", "fri", "sat" };
/* example timespecs: