Diff for /embedaddon/sudo/src/ttyname.c between versions 1.1.1.3 and 1.1.1.4

version 1.1.1.3, 2013/07/22 10:46:13 version 1.1.1.4, 2014/06/15 16:12:55
Line 1 Line 1
 /*  /*
 * Copyright (c) 2012-2013 Todd C. Miller <Todd.Miller@courtesan.com> * Copyright (c) 2012-2014 Todd C. Miller <Todd.Miller@courtesan.com>
  *   *
  * Permission to use, copy, modify, and distribute this software for any   * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above   * purpose with or without fee is hereby granted, provided that the above
Line 193  sudo_ttyname_scan(const char *dir, dev_t rdev, bool bu Line 193  sudo_ttyname_scan(const char *dir, dev_t rdev, bool bu
     size_t sdlen, d_len, len, num_subdirs = 0, max_subdirs = 0;      size_t sdlen, d_len, len, num_subdirs = 0, max_subdirs = 0;
     struct dirent *dp;      struct dirent *dp;
     struct stat sb;      struct stat sb;
    int i;    unsigned int i;
     debug_decl(sudo_ttyname_scan, SUDO_DEBUG_UTIL)      debug_decl(sudo_ttyname_scan, SUDO_DEBUG_UTIL)
   
     if (dir[0] == '\0' || (d = opendir(dir)) == NULL)      if (dir[0] == '\0' || (d = opendir(dir)) == NULL)
Line 371  get_process_ttyname(void) Line 371  get_process_ttyname(void)
         rc = sysctl(mib, sudo_kp_namelen, ki_proc, &size, NULL, 0);          rc = sysctl(mib, sudo_kp_namelen, ki_proc, &size, NULL, 0);
     } while (rc == -1 && errno == ENOMEM);      } while (rc == -1 && errno == ENOMEM);
     if (rc != -1) {      if (rc != -1) {
        if (ki_proc->sudo_kp_tdev != (dev_t)-1) {        if ((dev_t)ki_proc->sudo_kp_tdev != (dev_t)-1) {
             tty = sudo_ttyname_dev(ki_proc->sudo_kp_tdev);              tty = sudo_ttyname_dev(ki_proc->sudo_kp_tdev);
             if (tty == NULL) {              if (tty == NULL) {
                 sudo_debug_printf(SUDO_DEBUG_WARN,                  sudo_debug_printf(SUDO_DEBUG_WARN,
Line 441  get_process_ttyname(void) Line 441  get_process_ttyname(void)
         if (len != -1) {          if (len != -1) {
             /* Field 7 is the tty dev (0 if no tty) */              /* Field 7 is the tty dev (0 if no tty) */
             char *cp = line;              char *cp = line;
            int field = 1;            char *ep = line;
            while (*cp != '\0') {            const char *errstr;
                if (*cp++ == ' ') {            int field = 0;
             while (*++ep != '\0') {
                 if (*ep == ' ') {
                     *ep = '\0';
                     if (++field == 7) {                      if (++field == 7) {
                        dev_t tdev = (dev_t)atoi(cp);                        dev_t tdev = strtonum(cp, INT_MIN, INT_MAX, &errstr);
                         if (errstr) {
                             sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
                                 "%s: tty device %s: %s", path, cp, errstr);
                         }
                         if (tdev > 0)                          if (tdev > 0)
                             tty = sudo_ttyname_dev(tdev);                              tty = sudo_ttyname_dev(tdev);
                         break;                          break;
                     }                      }
                       cp = ep + 1;
                 }                  }
             }              }
         }          }
Line 458  get_process_ttyname(void) Line 466  get_process_ttyname(void)
   
     debug_return_str(tty);      debug_return_str(tty);
 }  }
#elif HAVE_PSTAT_GETPROC#elif defined(HAVE_PSTAT_GETPROC)
 /*  /*
  * Return a string from ttyname() containing the tty to which the process is   * Return a string from ttyname() containing the tty to which the process is
  * attached or NULL if the process has no controlling tty.   * attached or NULL if the process has no controlling tty.
Line 468  get_process_ttyname(void) Line 476  get_process_ttyname(void)
 {  {
     struct pst_status pstat;      struct pst_status pstat;
     char *tty = NULL;      char *tty = NULL;
       int rc;
     debug_decl(get_process_ttyname, SUDO_DEBUG_UTIL)      debug_decl(get_process_ttyname, SUDO_DEBUG_UTIL)
   
    /* Try to determine the tty from psdev in struct pst_status. */    /*
    if (pstat_getproc(&pstat, sizeof(pstat), 0, (int)getpid()) != -1) {     * Determine the tty from psdev in struct pst_status.
      * We may get EOVERFLOW if the whole thing doesn't fit but that is OK.
      */
     rc = pstat_getproc(&pstat, sizeof(pstat), (size_t)0, (int)getpid());
     if (rc != -1 || errno == EOVERFLOW) {
         if (pstat.pst_term.psd_major != -1 && pstat.pst_term.psd_minor != -1) {          if (pstat.pst_term.psd_major != -1 && pstat.pst_term.psd_minor != -1) {
             tty = sudo_ttyname_dev(makedev(pstat.pst_term.psd_major,              tty = sudo_ttyname_dev(makedev(pstat.pst_term.psd_major,
                 pstat.pst_term.psd_minor));                  pstat.pst_term.psd_minor));

Removed from v.1.1.1.3  
changed lines
  Added in v.1.1.1.4


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>