perl/Module-Build-Tiny: update to 0.051 for Perl 5.36 and 5.38
[oi-userland.git] / components / shell / pconsole / patches / pconsole.c.patch
blob83966f61c8d4897fd9eebfd9ab2842ed60151a43
1 --- pconsole-1.1/pconsole.c 2018-08-19 13:30:22.000000000 +0000
2 +++ pconsole-1.1/pconsole.c 2019-07-21 05:29:54.242138304 +0000
3 @@ -26,9 +26,12 @@
4 #include "cstring.h"
5 #include "terminal.h"
6 #include "Conn.h"
7 +#include <stdlib.h>
8 +#include "sys/termios.h"
10 #include <stdio.h>
11 #include <stdlib.h>
12 +#include <priv.h>
13 #include <unistd.h>
14 #include <errno.h>
15 #include <signal.h>
16 @@ -163,9 +166,7 @@ Conn *c, *c_next;
17 c_next = c->next;
19 if (c->fd > 0) {
20 - seteuid(0); /* regain root privs */
21 if (ioctl(c->fd, TIOCSTI, &kar) == -1) { /* simulate terminal input */
22 - seteuid(getuid()); /* drop root privs again */
23 printf("\nioctl() : %s\n", strerror(errno));
24 if (c->hostname != NULL)
25 printf("detaching from %s#%s\n", c->hostname, c->dev);
26 @@ -173,8 +174,7 @@ Conn *c, *c_next;
27 printf("detaching from %s\n", c->dev);
28 remove_Conn(c);
29 destroy_Conn(c);
30 - } else
31 - seteuid(getuid()); /* drop the root privs */
32 + }
35 if (AllConns == NULL)
36 @@ -188,19 +188,34 @@ RETSIGTYPE sig_exit(int sig) {
39 int main(int argc, char **argv) {
40 - if (geteuid()) {
41 - fprintf(stderr, "You must be root to run this program or this program should be setuid root.\n");
42 - return -1;
43 - }
44 - if (seteuid(getuid())) { /* drop root privs */
45 - fprintf(stderr, "failed to drop root privileges\n");
46 - exit(-1);
48 + priv_set_t *privset = NULL;
50 + if ((privset = priv_allocset()) == NULL) {
51 + fprintf(stderr, "couldn't allocate privilege\n");
52 + return -1;
53 + }
55 + if (getppriv(PRIV_EFFECTIVE, privset) < 0) {
56 + fprintf(stderr, "couldn't get privilege\n");
57 + return -1;
58 + }
60 + if (priv_isfullset(privset) != B_TRUE) {
61 + fprintf(stderr, "You must be root or granted the \"Parallel Console Access\" rights profile.\n");
62 + return -1;
63 + }
64 + priv_freeset(privset);
66 + if ((argc > 1) && (!strcmp(argv[1],"-t"))) {
67 + return 0;
70 if (!isatty(fileno(stdin))) {
71 fprintf(stderr, "pconsole: not a tty\n");
72 return -1;
74 - printf("pconsole WJ101\n");
75 + printf("pconsole 1.0\n");
77 signal(SIGTERM, sig_exit);
78 signal(SIGINT, sig_exit);