www.usr.com/support/gpl/USR9107_release.1.4.tar.gz
[bcm963xx.git] / userapps / opensource / sshd / sshpty.c
index 8b5eed1..b7133c8 100755 (executable)
  * 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"
 
@@ -30,8 +30,8 @@
 #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
@@ -189,7 +189,6 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen)
        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],
@@ -235,6 +234,7 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen)
 
                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 */
@@ -245,24 +245,24 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen)
 /* 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
@@ -314,10 +314,10 @@ pty_make_controlling_tty(int *ttyfd, const char *ttyname)
        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);
@@ -353,7 +353,7 @@ pty_change_window_size(int ptyfd, int row, int col,
 }
 
 void
-pty_setowner(struct passwd *pw, const char *ttyname)
+pty_setowner(struct passwd *pw, const char *tty_name)
 {
        struct group *grp;
        gid_t gid;
@@ -375,38 +375,38 @@ pty_setowner(struct passwd *pw, const char *ttyname)
         * 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));
                        }
                }
        }