--- libaitio/src/pty.c 2011/09/19 21:59:58 1.1.2.1 +++ libaitio/src/pty.c 2011/09/19 22:41:04 1.1.2.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: pty.c,v 1.1.2.1 2011/09/19 21:59:58 misho Exp $ +* $Id: pty.c,v 1.1.2.2 2011/09/19 22:41:04 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -89,4 +89,80 @@ ioFreePTY(const char *ttyname) chown(ttyname, (uid_t) 0, (gid_t) 0); chmod(ttyname, (mode_t) 0666); +} + +/* + * ioChgWinPTY() Change window size of PTY + * @ptyfd = master fd, pty + * @row = row + * @col = col + * @xpxl = x pixels + * @ypxl = y pixels + * return: -1 error or 0 ok + */ +inline int +ioChgWinPTY(int ptyfd, u_short row, u_short col, u_short xpxl, u_short ypxl) +{ + struct winsize w; + + w.ws_row = row; + w.ws_col = col; + w.ws_xpixel = xpxl; + w.ws_ypixel = ypxl; + + if (ioctl(ptyfd, TIOCSWINSZ, &w) == -1) { + LOGERR; + return -1; + } + + return 0; +} + +/* + * ioSetOwnerPTY() Set owner to PTY + * @ttyname = tty filename + * @UID = uid + * @GID = gid + * return: -1 error or 0 ok + */ +int +ioSetOwnerPTY(const char *ttyname, uid_t UID, gid_t GID) +{ + struct group *grp; + gid_t gid; + mode_t mode; + struct stat st; + + assert(ttyname); + if (!ttyname) { + io_SetErr(EINVAL, "Error:: invalid arguments ..."); + return -1; + } + + grp = getgrnam("tty"); + if (!grp) { + gid = GID; + mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH; + } else { + gid = grp->gr_gid; + mode = S_IRUSR | S_IWUSR | S_IWGRP; + } + + if (stat(ttyname, &st) == -1) { + LOGERR; + return -1; + } + + if (st.st_uid != UID || st.st_gid != gid) + if (chown(ttyname, UID, gid) == -1) { + LOGERR; + return -1; + } + if ((st.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO)) != mode) + if (chmod(ttyname, mode) == -1) { + LOGERR; + return -1; + } + + return 0; }