--- pconsole-1.1/pconsole.c 2018-08-19 13:30:22.000000000 +0000 +++ pconsole-1.1/pconsole.c 2019-07-21 05:29:54.242138304 +0000 @@ -26,9 +26,12 @@ #include "cstring.h" #include "terminal.h" #include "Conn.h" +#include +#include "sys/termios.h" #include #include +#include #include #include #include @@ -163,9 +166,7 @@ Conn *c, *c_next; c_next = c->next; if (c->fd > 0) { - seteuid(0); /* regain root privs */ if (ioctl(c->fd, TIOCSTI, &kar) == -1) { /* simulate terminal input */ - seteuid(getuid()); /* drop root privs again */ printf("\nioctl() : %s\n", strerror(errno)); if (c->hostname != NULL) printf("detaching from %s#%s\n", c->hostname, c->dev); @@ -173,8 +174,7 @@ Conn *c, *c_next; printf("detaching from %s\n", c->dev); remove_Conn(c); destroy_Conn(c); - } else - seteuid(getuid()); /* drop the root privs */ + } } } if (AllConns == NULL) @@ -188,19 +188,34 @@ RETSIGTYPE sig_exit(int sig) { } int main(int argc, char **argv) { - if (geteuid()) { - fprintf(stderr, "You must be root to run this program or this program should be setuid root.\n"); - return -1; - } - if (seteuid(getuid())) { /* drop root privs */ - fprintf(stderr, "failed to drop root privileges\n"); - exit(-1); + + priv_set_t *privset = NULL; + + if ((privset = priv_allocset()) == NULL) { + fprintf(stderr, "couldn't allocate privilege\n"); + return -1; + } + + if (getppriv(PRIV_EFFECTIVE, privset) < 0) { + fprintf(stderr, "couldn't get privilege\n"); + return -1; + } + + if (priv_isfullset(privset) != B_TRUE) { + fprintf(stderr, "You must be root or granted the \"Parallel Console Access\" rights profile.\n"); + return -1; + } + priv_freeset(privset); + + if ((argc > 1) && (!strcmp(argv[1],"-t"))) { + return 0; } + if (!isatty(fileno(stdin))) { fprintf(stderr, "pconsole: not a tty\n"); return -1; } - printf("pconsole WJ101\n"); + printf("pconsole 1.0\n"); signal(SIGTERM, sig_exit); signal(SIGINT, sig_exit);