*** pconsole-1.0/pconsole.c.orig Thu Jul 14 05:49:24 2011
--- pconsole-1.0/pconsole.c Thu Jul 14 05:49:07 2011
***************
*** 26,33 ****
--- 26,37 ----
#include "cstring.h"
#include "terminal.h"
#include "Conn.h"
+ #include <stdlib.h>
+ #include "sys/termios.h"
#include <stdio.h>
+ #include <stdlib.h>
+ #include <priv.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
***************
*** 156,164 ****
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);
--- 160,166 ----
***************
*** 166,173 ****
printf("detaching from %s\n", c->dev);
remove_Conn(c);
destroy_Conn(c);
! } else
! seteuid(getuid()); /* drop the root privs */
}
}
if (AllConns == NULL)
--- 168,174 ----
printf("detaching from %s\n", c->dev);
remove_Conn(c);
destroy_Conn(c);
! }
}
}
if (AllConns == NULL)
***************
*** 181,199 ****
}
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);
! }
if (!isatty(fileno(stdin))) {
fprintf(stderr, "pconsole: not a tty\n");
return -1;
}
! printf("pconsole WJ101\n");
signal(SIGTERM, sig_exit);
signal(SIGINT, sig_exit);
--- 182,215 ----
}
int main(int argc, char **argv) {
!
! 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 1.0\n");
signal(SIGTERM, sig_exit);
signal(SIGINT, sig_exit);