* called by a name other than "ssh" or "Secure Shell".
*/
-/*RCSID("$OpenBSD: sshpty.c,v 1.7 2002/06/24 17:57:20 deraadt Exp $");*/
+/*RCSID("OpenBSD: sshpty.c,v 1.7 2002/06/24 17:57:20 deraadt Exp ");*/
#include "includes.h"
-#include "util.h"
+#include "dbutil.h"
#include "errno.h"
#include "sshpty.h"
#ifdef HAVE_PTY_H
# include <pty.h>
#endif
-#if defined(USE_DEV_PTMX) && defined(HAVE_SYS_STROPTS_H)
-# include <sys/stropts.h>
+#if defined(USE_DEV_PTMX) && defined(HAVE_STROPTS_H)
+# include <stropts.h>
#endif
#ifndef O_NOCTTY
int num_minors = strlen(ptyminors);
int num_ptys = strlen(ptymajors) * num_minors;
struct termios tio;
-//printf("Use HAVE_DEV_PTS_AND_PTC_\n");
for (i = 0; i < num_ptys; i++) {
snprintf(buf, sizeof buf, "/dev/pty%c%c", ptymajors[i / num_minors],
return 1;
}
+ dropbear_log(LOG_WARNING, "failed to open any /dev/pty?? devices");
return 0;
#endif /* HAVE_DEV_PTS_AND_PTC */
#endif /* USE_DEV_PTMX */
/* Releases the tty. Its ownership is returned to root, and permissions to 0666. */
void
-pty_release(const char *ttyname)
+pty_release(const char *tty_name)
{
- if (chown(ttyname, (uid_t) 0, (gid_t) 0) < 0
+ if (chown(tty_name, (uid_t) 0, (gid_t) 0) < 0
&& (errno != ENOENT)) {
dropbear_log(LOG_ERR,
- "chown %.100s 0 0 failed: %.100s", ttyname, strerror(errno));
+ "chown %.100s 0 0 failed: %.100s", tty_name, strerror(errno));
}
- if (chmod(ttyname, (mode_t) 0666) < 0
+ if (chmod(tty_name, (mode_t) 0666) < 0
&& (errno != ENOENT)) {
dropbear_log(LOG_ERR,
- "chmod %.100s 0666 failed: %.100s", ttyname, strerror(errno));
+ "chmod %.100s 0666 failed: %.100s", tty_name, strerror(errno));
}
}
/* Makes the tty the processes controlling tty and sets it to sane modes. */
void
-pty_make_controlling_tty(int *ttyfd, const char *ttyname)
+pty_make_controlling_tty(int *ttyfd, const char *tty_name)
{
int fd;
#ifdef USE_VHANGUP
vhangup();
mysignal(SIGHUP, old);
#endif /* USE_VHANGUP */
- fd = open(ttyname, O_RDWR);
+ fd = open(tty_name, O_RDWR);
if (fd < 0) {
dropbear_log(LOG_ERR,
- "%.100s: %.100s", ttyname, strerror(errno));
+ "%.100s: %.100s", tty_name, strerror(errno));
} else {
#ifdef USE_VHANGUP
close(*ttyfd);
}
void
-pty_setowner(struct passwd *pw, const char *ttyname)
+pty_setowner(struct passwd *pw, const char *tty_name)
{
struct group *grp;
gid_t gid;
* Warn but continue if filesystem is read-only and the uids match/
* tty is owned by root.
*/
- if (stat(ttyname, &st)) {
+ if (stat(tty_name, &st)) {
dropbear_exit("pty_setowner: stat(%.101s) failed: %.100s",
- ttyname, strerror(errno));
+ tty_name, strerror(errno));
}
// BRCM begin: commented below
#if 0
if (st.st_uid != pw->pw_uid || st.st_gid != gid) {
- if (chown(ttyname, pw->pw_uid, gid) < 0) {
+ if (chown(tty_name, pw->pw_uid, gid) < 0) {
if (errno == EROFS &&
(st.st_uid == pw->pw_uid || st.st_uid == 0)) {
dropbear_log(LOG_ERR,
"chown(%.100s, %u, %u) failed: %.100s",
- ttyname, (unsigned int)pw->pw_uid, (unsigned int)gid,
+ tty_name, (unsigned int)pw->pw_uid, (unsigned int)gid,
strerror(errno));
} else {
dropbear_exit("chown(%.100s, %u, %u) failed: %.100s",
- ttyname, (unsigned int)pw->pw_uid, (unsigned int)gid,
+ tty_name, (unsigned int)pw->pw_uid, (unsigned int)gid,
strerror(errno));
}
}
}
if ((st.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO)) != mode) {
- if (chmod(ttyname, mode) < 0) {
+ if (chmod(tty_name, mode) < 0) {
if (errno == EROFS &&
(st.st_mode & (S_IRGRP | S_IROTH)) == 0) {
dropbear_log(LOG_ERR,
"chmod(%.100s, 0%o) failed: %.100s",
- ttyname, mode, strerror(errno));
+ tty_name, mode, strerror(errno));
} else {
dropbear_exit("chmod(%.100s, 0%o) failed: %.100s",
- ttyname, mode, strerror(errno));
+ tty_name, mode, strerror(errno));
}
}
}