7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
29
30 #pragma ident "%Z%%M% %I% %E% SMI"
31
32 #pragma weak _ptsname = ptsname
33 #pragma weak _grantpt = grantpt
34 #pragma weak _unlockpt = unlockpt
35
36 #include "lint.h"
37 #include "libc.h"
38 #include "mtlib.h"
39 #include <sys/types.h>
40 #include <signal.h>
41 #include <sys/param.h>
42 #include <sys/mkdev.h>
43 #include <sys/stream.h>
44 #include <sys/stropts.h>
45 #include <sys/wait.h>
46 #include <sys/signal.h>
47 #include <errno.h>
48 #include <fcntl.h>
49 #include <sys/stat.h>
50 #include <sys/ptms.h>
51 #include <string.h>
116 /*
117 * Send an ioctl down to the master device requesting the
118 * master/slave pair be unlocked.
119 */
120 int
121 unlockpt(int fd)
122 {
123 struct strioctl istr;
124
125 istr.ic_cmd = UNLKPT;
126 istr.ic_len = 0;
127 istr.ic_timout = 0;
128 istr.ic_dp = NULL;
129
130 if (ioctl(fd, I_STR, &istr) < 0)
131 return (-1);
132
133 return (0);
134 }
135
136 int
137 grantpt(int fd)
138 {
139 struct strioctl istr;
140 pt_own_t pto;
141 struct group *gr_name;
142
143 /* validate the file descriptor before proceeding */
144 if (ptsdev(fd) == NODEV)
145 return (-1);
146
147 pto.pto_ruid = getuid();
148
149 gr_name = getgrnam(DEFAULT_TTY_GROUP);
150 if (gr_name)
151 pto.pto_rgid = gr_name->gr_gid;
152 else
153 pto.pto_rgid = getgid();
154
155 istr.ic_cmd = OWNERPT;
|
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
29 */
30
31 /* Copyright (c) 1988 AT&T */
32 /* All Rights Reserved */
33
34 #pragma weak _ptsname = ptsname
35 #pragma weak _grantpt = grantpt
36 #pragma weak _unlockpt = unlockpt
37
38 #include "lint.h"
39 #include "libc.h"
40 #include "mtlib.h"
41 #include <sys/types.h>
42 #include <signal.h>
43 #include <sys/param.h>
44 #include <sys/mkdev.h>
45 #include <sys/stream.h>
46 #include <sys/stropts.h>
47 #include <sys/wait.h>
48 #include <sys/signal.h>
49 #include <errno.h>
50 #include <fcntl.h>
51 #include <sys/stat.h>
52 #include <sys/ptms.h>
53 #include <string.h>
118 /*
119 * Send an ioctl down to the master device requesting the
120 * master/slave pair be unlocked.
121 */
122 int
123 unlockpt(int fd)
124 {
125 struct strioctl istr;
126
127 istr.ic_cmd = UNLKPT;
128 istr.ic_len = 0;
129 istr.ic_timout = 0;
130 istr.ic_dp = NULL;
131
132 if (ioctl(fd, I_STR, &istr) < 0)
133 return (-1);
134
135 return (0);
136 }
137
138 /*
139 * XPG4v2 requires that open of a slave pseudo terminal device
140 * provides the process with an interface that is identical to
141 * the terminal interface.
142 *
143 * To satisfy this, in strict XPG4v2 mode, this routine also sends
144 * a message down the stream that sets a flag in the kernel module
145 * so that additional actions are performed when opening an
146 * associated slave PTY device. When this happens, modules are
147 * automatically pushed onto the stream to provide terminal
148 * semantics and those modules are then informed that they should
149 * behave in strict XPG4v2 mode which modifies their behaviour. In
150 * particular, in strict XPG4v2 mode, empty blocks will be sent up
151 * the master side of the stream rather than being suppressed.
152 *
153 * Most applications do not expect this behaviour so it is only
154 * enabled for programs compiled in strict XPG4v2 mode (see
155 * stdlib.h).
156 */
157 int
158 __unlockpt_xpg4(int fd)
159 {
160 int ret;
161
162 if ((ret = unlockpt(fd)) == 0) {
163 struct strioctl istr;
164
165 istr.ic_cmd = PTSSTTY;
166 istr.ic_len = 0;
167 istr.ic_timout = 0;
168 istr.ic_dp = NULL;
169
170 if (ioctl(fd, I_STR, &istr) < 0)
171 ret = -1;
172 }
173
174 return (ret);
175 }
176
177 int
178 grantpt(int fd)
179 {
180 struct strioctl istr;
181 pt_own_t pto;
182 struct group *gr_name;
183
184 /* validate the file descriptor before proceeding */
185 if (ptsdev(fd) == NODEV)
186 return (-1);
187
188 pto.pto_ruid = getuid();
189
190 gr_name = getgrnam(DEFAULT_TTY_GROUP);
191 if (gr_name)
192 pto.pto_rgid = gr_name->gr_gid;
193 else
194 pto.pto_rgid = getgid();
195
196 istr.ic_cmd = OWNERPT;
|