2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: usl_ptty.c /main/3 1995/10/27 16:16:16 rswiston $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
26 * (c) Copyright 1993, 1994 International Business Machines Corp. *
27 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
28 * (c) Copyright 1993, 1994 Novell, Inc. *
30 /* usl_ptty.c: routines to perform USL's password authentication */
32 #include <stdio.h> /* just so file isn't empty */
34 #if defined (USL) || defined(__uxp__)
36 #include <sys/byteorder.h>
39 #include <sys/stream.h>
42 #include <sys/types.h>
56 /* externally defined routines */
59 extern int unlockpt();
60 extern char *ptsname();
61 extern char *strncpy();
65 /* externally defined global variables */
67 int Termios_received = 0; /* received termios structure flag */
68 struct termios Termios; /* termios buffer */
70 #define RX_SLAVENAMELEN 32
73 /* locally defined global variables */
75 int Ptty_open; /* ptty open flag */
76 int Ptty_fd; /* master ptty fd */
77 int Slaveptty_fd; /* slave ptty fd */
78 char Slaveptty_name[RX_SLAVENAMELEN]; /* slave ptty device file name */
84 * This function creates and opens a master/slave pair of pseudo ttys.
85 * It returns 0 for success, -1 for failure
92 char *ttyname; /* file name of slave pseudo tty */
93 pid_t mypid = getpid(); /* my process id */
94 struct passwd *pwp; /* password file entry */
96 Debug("makettypair\n");
97 if ((Ptty_fd = open("/dev/ptmx", O_RDWR)) == -1) {
98 Debug ("ptty: open ptmx failed, errno = %d\n", errno);
101 if (grantpt(Ptty_fd) == -1) {
102 Debug ("ptty: grantpt failed\n");
105 if (unlockpt(Ptty_fd) == -1) {
106 Debug ("ptty: unlockpt failed\n");
109 if ((ttyname = ptsname(Ptty_fd)) == NULL) {
110 Debug ("ptty: ptsname failed\n");
113 (void) strncpy(Slaveptty_name, ttyname, RX_SLAVENAMELEN);
114 if ((Slaveptty_fd = open(Slaveptty_name, O_RDWR)) == -1) {
115 Debug ("ptty: could not open pts %s, errno = %d\n",
116 Slaveptty_name, errno);
120 if (ioctl(Slaveptty_fd, I_PUSH, "ptem") == -1) {
121 Debug ("ptty: push ptem failed\n");
124 if (ioctl(Slaveptty_fd, I_PUSH, "ldterm") == -1) {
125 Debug ("ptty: push ldterm failed\n");
130 * Note that since the following ioctl() is performed
131 * before the pckt module is pushed, it will not be sent back
132 * to the client. This is what we want.
136 if (Termios_received)
137 if (ioctl(Slaveptty_fd, TCSETS, &Termios) == -1) {
138 Debug ("ptty: TCSETS failed\n");
142 if (ioctl(Ptty_fd, I_PUSH, "pckt") == -1) {
143 Debug ("ptty: push pckt failed\n");
147 /* disable ldterm input processing on server end */
148 if (ioctl(Ptty_fd, TIOCREMOTE, 1) == -1) {
149 Debug ("ptty: ioctl(TIOCREMOTE) failed\n");
155 Debug ("ptty: pttys created\n");
160 #endif /* USL || __uxp__ */