void _DtTermPrimReleasePty(char *ptySlave) { /* this function needs to be suid root... */ (void) _DtTermPrimToggleSuidRoot(True); (void) ReleasePty(ptySlave); /* we now need to turn off setuid root... */ (void) _DtTermPrimToggleSuidRoot(False); }
int _DtTermPrimSetupPty(char *ptySlave, int ptyFd) { int retValue; /* this function needs to be suid root... */ (void) _DtTermPrimToggleSuidRoot(True); retValue = SetupPty(ptySlave, ptyFd); /* we now need to turn off setuid root... */ (void) _DtTermPrimToggleSuidRoot(False); return(retValue); }
/* ** NOTE: ** Setcsmap() only operates on STDIN, so we have to do some ** munging around to map the pty to STDIN in order to get ** the desired result. This may seem wasteful, but it ** makes it easier to encapsulate the OS dependencies in ** this function. */ if (pty != 0) { oldStdin = fcntl(0, F_DUPFD, 1); (void) close(0); (void) dup(pty); } sprintf(path, "%s%s", CSMAP_DIR, nl_langinfo(CODESET)); if(access(path, E_ACC|R_ACC) == 0) { setcsmap(path); } if (pty != 0) { (void) close(0); if (oldStdin >= 0) { (void) dup(oldStdin); (void) close(oldStdin); } } #endif /* (USE_SETCSMAP) */ } #if defined(USE_TIOCCONS) #ifndef CONSOLE_DEVICE #define CONSOLE_DEVICE "/dev/console" #endif /* CONSOLE_DEVICE */ void _DtTermPrimPtyConsoleModeEnable(int pty) { struct stat st; int one = 1; /* check to see if we are the owner of the device... */ if (!stat(CONSOLE_DEVICE, &st)) { /* stat succeeded... */ if (st.st_uid == getuid()) { /* we are the owner, check the access... */ if (!access(CONSOLE_DEVICE, R_OK | W_OK)) { /* and we can read/write it... */ /* we need to be setuid root... */ (void) _DtTermPrimToggleSuidRoot(True); if (ioctl(pty, TIOCCONS, &one)) { /* failure, errno was set... */ (void) perror(CONSOLE_DEVICE); (void) fprintf(stderr, "attempt to make tty the console failed\n"); } /* we no longer need to be suid root... */ (void) _DtTermPrimToggleSuidRoot(False); } else { /* we can't read/write it... */ (void) perror(CONSOLE_DEVICE); (void) fprintf(stderr, "-C console access denied\n"); } } else { /* we are not the owner -- return an access owner... */ errno = EACCES; (void) perror(CONSOLE_DEVICE); (void) fprintf(stderr, "-C console access denied\n"); } } else { /* we were unable to stat the file, errno is already set, * failure... */ (void) perror(CONSOLE_DEVICE); (void) fprintf(stderr, "-C console access denied\n"); } }
static int GetPty(char **ptySlave, char **ptyMaster) { char *c; int ptyFd; int ttyFd; *ptyMaster = malloc(strlen(PTY_CLONE_DEVICE) + 1); (void) strcpy(*ptyMaster, PTY_CLONE_DEVICE); if (isDebugFSet('p', 10)) { #ifdef BBA #pragma BBA_IGNORE #endif /*BBA*/ return(-1); } if ((ptyFd = open(*ptyMaster, O_RDWR, 0))) { _Xttynameparams tty_buf; #if defined(linux) if (c = _XTtyname(ptyFd)) { #else if (c = _XTtyname(ptyFd, tty_buf)) { #endif *ptySlave = malloc(strlen(c) + 1); (void) strcpy(*ptySlave, c); if ((ttyFd = open(*ptySlave, O_RDWR | O_NOCTTY, 0)) < 0) { /* failure... */ (void) perror(*ptySlave); (void) close(ptyFd); } else { /* success... */ /* close off the pty slave... */ (void) close(ttyFd); /* fix the owner, mode, and group... */ #ifdef HP_ARCHITECTURE { struct group *grp; gid_t gid; _Xgetgrparams grp_buf; if (grp = _XGetgrnam("tty", grp_buf)) { gid = grp->gr_gid; } else { gid = 0; } (void) endgrent(); (void) chown(*ptySlave, getuid(), gid); (void) chmod(*ptySlave, 0620); } #else /* HP_ARCHITECTURE */ (void) chown(*ptySlave, getuid(), getgid()); (void) chmod(*ptySlave, 0622); #endif /* HP_ARCHITECTURE */ /* pty master and slave names are already set. Return * the file descriptor... */ return(ptyFd); } } else { /* ttyname on the pty master failed. This should not happen!... */ (void) perror("ttyname"); (void) close(ptyFd); } } else { (void) perror(*ptyMaster); } return(-1); } /* this is a public wrapper around the previous function that runs the * previous function setuid root... */ int _DtTermPrimGetPty(char **ptySlave, char **ptyMaster) { int retValue; /* this function needs to be suid root... */ (void) _DtTermPrimToggleSuidRoot(True); retValue = GetPty(ptySlave, ptyMaster); /* we now need to turn off setuid root... */ (void) _DtTermPrimToggleSuidRoot(False); return(retValue); }