1/* See LICENSE file for copyright and license details. */
2
3
4#include <sys/types.h>
5#include <sys/stat.h>
6#include <sys/ioctl.h>
7
8#include <fcntl.h>
9#include <stdio.h>
10#include <string.h>
11#include <unistd.h>
12
13#include "util.h"
14
15#define CONSOLE "/dev/console"
16
17#define VT_LOCKSWITCH 0x560B /* disallow vt switching */
18#define VT_UNLOCKSWITCH 0x560C /* allow vt switching */
19
20static void
21usage(void)
22{
23 eprintf("usage: %s n | y\n", argv0);
24}
25
26// ?man vtallow: allow non-root vt access
27// ?man arguments: n | y
28// ?man allow non-root users to access virtual terminal devices
29int
30main(int argc, char *argv[])
31{
32 int fd;
33 int allow;
34
35 ARGBEGIN {
36 default:
37 usage();
38 } ARGEND;
39
40 if (argc != 1)
41 usage();
42
43 if (!strcmp(argv[0], "y"))
44 allow = 1;
45 else if (!strcmp(argv[0], "n"))
46 allow = 0;
47 else
48 usage();
49
50 if ((fd = open(CONSOLE, O_WRONLY)) < 0)
51 eprintf("open %s:", CONSOLE);
52 if (ioctl(fd, allow ? VT_UNLOCKSWITCH : VT_LOCKSWITCH) < 0)
53 eprintf("cannot %s VT switch:",
54 allow ? "unlock" : "lock");
55 close(fd);
56 return 0;
57}