author | Jingning Ji <jingning.ji@oracle.com> |
Thu, 22 Sep 2016 16:33:05 -0700 | |
changeset 7117 | f7dc231928a9 |
parent 409 | 9f1b2b9b0fd9 |
permissions | -rw-r--r-- |
409
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
1 |
*** pconsole-1.0/pconsole.c.orig Thu Jul 14 05:49:24 2011 |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
2 |
--- pconsole-1.0/pconsole.c Thu Jul 14 05:49:07 2011 |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
3 |
*************** |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
4 |
*** 26,33 **** |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
5 |
--- 26,37 ---- |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
6 |
#include "cstring.h" |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
7 |
#include "terminal.h" |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
8 |
#include "Conn.h" |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
9 |
+ #include <stdlib.h> |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
10 |
+ #include "sys/termios.h" |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
11 |
|
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
12 |
#include <stdio.h> |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
13 |
+ #include <stdlib.h> |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
14 |
+ #include <priv.h> |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
15 |
#include <unistd.h> |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
16 |
#include <errno.h> |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
17 |
#include <signal.h> |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
18 |
*************** |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
19 |
*** 156,164 **** |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
20 |
c_next = c->next; |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
21 |
|
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
22 |
if (c->fd > 0) { |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
23 |
- seteuid(0); /* regain root privs */ |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
24 |
if (ioctl(c->fd, TIOCSTI, &kar) == -1) { /* simulate terminal input */ |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
25 |
- seteuid(getuid()); /* drop root privs again */ |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
26 |
printf("\nioctl() : %s\n", strerror(errno)); |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
27 |
if (c->hostname != NULL) |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
28 |
printf("detaching from %s#%s\n", c->hostname, c->dev); |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
29 |
--- 160,166 ---- |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
30 |
*************** |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
31 |
*** 166,173 **** |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
32 |
printf("detaching from %s\n", c->dev); |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
33 |
remove_Conn(c); |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
34 |
destroy_Conn(c); |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
35 |
! } else |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
36 |
! seteuid(getuid()); /* drop the root privs */ |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
37 |
} |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
38 |
} |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
39 |
if (AllConns == NULL) |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
40 |
--- 168,174 ---- |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
41 |
printf("detaching from %s\n", c->dev); |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
42 |
remove_Conn(c); |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
43 |
destroy_Conn(c); |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
44 |
! } |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
45 |
} |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
46 |
} |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
47 |
if (AllConns == NULL) |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
48 |
*************** |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
49 |
*** 181,199 **** |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
50 |
} |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
51 |
|
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
52 |
int main(int argc, char **argv) { |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
53 |
! if (geteuid()) { |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
54 |
! fprintf(stderr, "You must be root to run this program or this program should be setuid root.\n"); |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
55 |
! return -1; |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
56 |
} |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
57 |
! if (seteuid(getuid())) { /* drop root privs */ |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
58 |
! fprintf(stderr, "failed to drop root privileges\n"); |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
59 |
! exit(-1); |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
60 |
! } |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
61 |
if (!isatty(fileno(stdin))) { |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
62 |
fprintf(stderr, "pconsole: not a tty\n"); |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
63 |
return -1; |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
64 |
} |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
65 |
! printf("pconsole WJ101\n"); |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
66 |
|
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
67 |
signal(SIGTERM, sig_exit); |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
68 |
signal(SIGINT, sig_exit); |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
69 |
--- 182,215 ---- |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
70 |
} |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
71 |
|
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
72 |
int main(int argc, char **argv) { |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
73 |
! |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
74 |
! priv_set_t *privset = NULL; |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
75 |
! |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
76 |
! if ((privset = priv_allocset()) == NULL) { |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
77 |
! fprintf(stderr, "couldn't allocate privilege\n"); |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
78 |
! return -1; |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
79 |
! } |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
80 |
! |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
81 |
! if (getppriv(PRIV_EFFECTIVE, privset) < 0) { |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
82 |
! fprintf(stderr, "couldn't get privilege\n"); |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
83 |
! return -1; |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
84 |
! } |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
85 |
! |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
86 |
! if (priv_isfullset(privset) != B_TRUE) { |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
87 |
! fprintf(stderr, "You must be root or granted the \"Parallel Console Access\" rights profile.\n"); |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
88 |
! return -1; |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
89 |
! } |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
90 |
! priv_freeset(privset); |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
91 |
! |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
92 |
! if ((argc > 1) && (!strcmp(argv[1],"-t"))) { |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
93 |
! return 0; |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
94 |
} |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
95 |
! |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
96 |
if (!isatty(fileno(stdin))) { |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
97 |
fprintf(stderr, "pconsole: not a tty\n"); |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
98 |
return -1; |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
99 |
} |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
100 |
! printf("pconsole 1.0\n"); |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
101 |
|
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
102 |
signal(SIGTERM, sig_exit); |
9f1b2b9b0fd9
7067082 Move pconsole to userland
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
103 |
signal(SIGINT, sig_exit); |