version 1.1.1.1, 2012/02/21 16:23:02
|
version 1.1.1.2, 2012/05/29 12:26:49
|
Line 63 get_pty(int *master, int *slave, char *name, size_t na
|
Line 63 get_pty(int *master, int *slave, char *name, size_t na
|
{ |
{ |
struct group *gr; |
struct group *gr; |
gid_t ttygid = -1; |
gid_t ttygid = -1; |
|
int rval = 0; |
|
debug_decl(get_pty, SUDO_DEBUG_PTY) |
|
|
if ((gr = getgrnam("tty")) != NULL) |
if ((gr = getgrnam("tty")) != NULL) |
ttygid = gr->gr_gid; |
ttygid = gr->gr_gid; |
|
|
if (openpty(master, slave, name, NULL, NULL) != 0) | if (openpty(master, slave, name, NULL, NULL) == 0) { |
return 0; | if (chown(name, ttyuid, ttygid) == 0) |
if (chown(name, ttyuid, ttygid) != 0) | rval = 1; |
return 0; | } |
return 1; | |
| debug_return_bool(rval); |
} |
} |
|
|
#elif defined(HAVE__GETPTY) |
#elif defined(HAVE__GETPTY) |
Line 79 int
|
Line 82 int
|
get_pty(int *master, int *slave, char *name, size_t namesz, uid_t ttyuid) |
get_pty(int *master, int *slave, char *name, size_t namesz, uid_t ttyuid) |
{ |
{ |
char *line; |
char *line; |
|
int rval = 0; |
|
debug_decl(get_pty, SUDO_DEBUG_PTY) |
|
|
/* IRIX-style dynamic ptys (may fork) */ |
/* IRIX-style dynamic ptys (may fork) */ |
line = _getpty(master, O_RDWR, S_IRUSR|S_IWUSR|S_IWGRP, 0); |
line = _getpty(master, O_RDWR, S_IRUSR|S_IWUSR|S_IWGRP, 0); |
if (line == NULL) | if (line != NULL) { |
return 0; | *slave = open(line, O_RDWR|O_NOCTTY, 0); |
*slave = open(line, O_RDWR|O_NOCTTY, 0); | if (*slave != -1) { |
if (*slave == -1) { | (void) chown(line, ttyuid, -1); |
close(*master); | strlcpy(name, line, namesz); |
return 0; | rval = 1; |
| } else { |
| close(*master); |
| *master = -1; |
| } |
} |
} |
(void) chown(line, ttyuid, -1); | debug_return_bool(rval); |
strlcpy(name, line, namesz); | |
return 1; | |
} |
} |
#elif defined(HAVE_GRANTPT) |
#elif defined(HAVE_GRANTPT) |
# ifndef HAVE_POSIX_OPENPT |
# ifndef HAVE_POSIX_OPENPT |
Line 113 int
|
Line 120 int
|
get_pty(int *master, int *slave, char *name, size_t namesz, uid_t ttyuid) |
get_pty(int *master, int *slave, char *name, size_t namesz, uid_t ttyuid) |
{ |
{ |
char *line; |
char *line; |
|
int rval = 0; |
|
debug_decl(get_pty, SUDO_DEBUG_PTY) |
|
|
*master = posix_openpt(O_RDWR|O_NOCTTY); |
*master = posix_openpt(O_RDWR|O_NOCTTY); |
if (*master == -1) | if (*master != -1) { |
return 0; | (void) grantpt(*master); /* may fork */ |
| if (unlockpt(*master) != 0) { |
(void) grantpt(*master); /* may fork */ | close(*master); |
if (unlockpt(*master) != 0) { | goto done; |
close(*master); | } |
return 0; | line = ptsname(*master); |
} | if (line == NULL) { |
line = ptsname(*master); | close(*master); |
if (line == NULL) { | goto done; |
close(*master); | } |
return 0; | *slave = open(line, O_RDWR|O_NOCTTY, 0); |
} | if (*slave == -1) { |
*slave = open(line, O_RDWR|O_NOCTTY, 0); | close(*master); |
if (*slave == -1) { | goto done; |
close(*master); | } |
return 0; | |
} | |
# if defined(I_PUSH) && !defined(_AIX) |
# if defined(I_PUSH) && !defined(_AIX) |
ioctl(*slave, I_PUSH, "ptem"); /* pseudo tty emulation module */ | ioctl(*slave, I_PUSH, "ptem"); /* pseudo tty emulation module */ |
ioctl(*slave, I_PUSH, "ldterm"); /* line discipline module */ | ioctl(*slave, I_PUSH, "ldterm"); /* line discipline module */ |
# endif |
# endif |
(void) chown(line, ttyuid, -1); | (void) chown(line, ttyuid, -1); |
strlcpy(name, line, namesz); | strlcpy(name, line, namesz); |
return 1; | rval = 1; |
| } |
| done: |
| debug_return_bool(rval); |
} |
} |
|
|
#else /* Old-style BSD ptys */ |
#else /* Old-style BSD ptys */ |
Line 152 get_pty(int *master, int *slave, char *name, size_t na
|
Line 162 get_pty(int *master, int *slave, char *name, size_t na
|
char *bank, *cp; |
char *bank, *cp; |
struct group *gr; |
struct group *gr; |
gid_t ttygid = -1; |
gid_t ttygid = -1; |
|
int rval = 0; |
|
debug_decl(get_pty, SUDO_DEBUG_PTY) |
|
|
if ((gr = getgrnam("tty")) != NULL) |
if ((gr = getgrnam("tty")) != NULL) |
ttygid = gr->gr_gid; |
ttygid = gr->gr_gid; |
Line 163 get_pty(int *master, int *slave, char *name, size_t na
|
Line 175 get_pty(int *master, int *slave, char *name, size_t na
|
*master = open(line, O_RDWR|O_NOCTTY, 0); |
*master = open(line, O_RDWR|O_NOCTTY, 0); |
if (*master == -1) { |
if (*master == -1) { |
if (errno == ENOENT) |
if (errno == ENOENT) |
return 0; /* out of ptys */ | goto done; /* out of ptys */ |
continue; /* already in use */ |
continue; /* already in use */ |
} |
} |
line[sizeof("/dev/p") - 2] = 't'; |
line[sizeof("/dev/p") - 2] = 't'; |
Line 175 get_pty(int *master, int *slave, char *name, size_t na
|
Line 187 get_pty(int *master, int *slave, char *name, size_t na
|
*slave = open(line, O_RDWR|O_NOCTTY, 0); |
*slave = open(line, O_RDWR|O_NOCTTY, 0); |
if (*slave != -1) { |
if (*slave != -1) { |
strlcpy(name, line, namesz); |
strlcpy(name, line, namesz); |
return 1; /* success */ | rval = 1; /* success */ |
| goto done; |
} |
} |
(void) close(*master); |
(void) close(*master); |
} |
} |
} |
} |
return 0; | done: |
| debug_return(rval); |
} |
} |
#endif /* HAVE_OPENPTY */ |
#endif /* HAVE_OPENPTY */ |