summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorBob Beck <beck@cvs.openbsd.org>2004-01-18 20:56:23 +0000
committerBob Beck <beck@cvs.openbsd.org>2004-01-18 20:56:23 +0000
commit73e6550d6871245c762c9afe087b8c055cc1454a (patch)
treef7429ac90d66fdd8add7bbaa2d89a23ebb1ce7c3 /regress
parent5a66967f6c6be0b5fe912508ce99f47e376edea0 (diff)
add regression tests for /dev/ptm.
ok deraadt@
Diffstat (limited to 'regress')
-rw-r--r--regress/sys/kern/ptmget/Makefile5
-rw-r--r--regress/sys/kern/ptmget/ptmget.c57
2 files changed, 62 insertions, 0 deletions
diff --git a/regress/sys/kern/ptmget/Makefile b/regress/sys/kern/ptmget/Makefile
new file mode 100644
index 00000000000..8f495ee7f25
--- /dev/null
+++ b/regress/sys/kern/ptmget/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2004/01/18 20:56:22 beck Exp $
+
+PROG= ptmget
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/kern/ptmget/ptmget.c b/regress/sys/kern/ptmget/ptmget.c
new file mode 100644
index 00000000000..943e2c4f0c3
--- /dev/null
+++ b/regress/sys/kern/ptmget/ptmget.c
@@ -0,0 +1,57 @@
+/* $OpenBSD: ptmget.c,v 1.1 2004/01/18 20:56:22 beck Exp $ */
+/*
+ * Written by Bob Beck <beck@openbsd.org> 2004 Public Domain.
+ * Basic test to ensure /dev/ptm works, and what it returns
+ * can be used via tty(4);
+ */
+#include <err.h>
+#include <fcntl.h>
+#include <grp.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <sys/tty.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+int
+main(int argc, char *argv[])
+{
+ int fd;
+ struct ptmget ptm;
+ struct termios ti;
+ struct stat sb;
+ struct group *gr;
+ gid_t ttygid;
+
+ if ((gr = getgrnam("tty")) != NULL)
+ ttygid = gr->gr_gid;
+ else
+ ttygid = 4;
+ fd = open("/dev/ptm", O_RDWR, 0);
+ if (fd == -1)
+ err(1, "Can't open /dev/ptm");
+ if ((ioctl(fd, PTMGET, &ptm) == -1))
+ err(1, "ioctl PTMGET failed");
+ if ((tcgetattr(ptm.sfd, &ti) == -1))
+ err(1, "tcgetattr failed on slave");
+ if ((tcgetattr(ptm.cfd, &ti) == -1))
+ err(1, "tcgetattr failed on master");
+ if ((ioctl(ptm.sfd, TIOCSTOP) == -1))
+ err(1, "ioctl TIOCSTOP failed on slave");
+ if ((ioctl(ptm.cfd, TIOCSTOP) == -1))
+ err(1, "ioctl TIOCSTOP failed on master");
+ bzero(&sb, sizeof(sb));
+ if ((stat(ptm.sn, &sb) == -1))
+ err(1, "can't stat slave %s", ptm.sn);
+ if (sb.st_mode != (S_IFCHR | S_IWUSR | S_IRUSR | S_IWGRP))
+ errx(1, "Bad mode %o on %s, should be %o", sb.st_mode,
+ ptm.sn, (S_IFCHR | S_IWUSR | S_IRUSR | S_IWGRP));
+ if (sb.st_gid != ttygid)
+ errx(1, "%s gid is %d not the tty group(%d)", ptm.sn,
+ sb.st_gid, ttygid);
+ if (sb.st_uid != geteuid())
+ errx(1, "%s owned by %d, not the current user (%d)", ptm.sn,
+ sb.st_uid, geteuid());
+ return(0);
+}