- This function is derived from the grantpt function in
- sysdeps/unix/grantpt.c in glibc-2.1. */
That makes the actual code unusable by me, but I get the general idea. Thanks.
/ Peter Bortas
Previous text:
2003-02-15 22:03: Subject: setsid
As far as I can tell, that should work.
(it even works if you want to change uid, using the modified version of grantpt below)
/* Sets the permissions on the slave pty suitably for use by USER.
- This function is derived from the grantpt function in
- sysdeps/unix/grantpt.c in glibc-2.1. */
static int pty_check_permissions(const char *name, uid_t user) { struct stat st; struct group *grp; gid_t tty_gid;
if (stat(name, &st) < 0) return 0;
/* Make sure that the user owns the device. */ if ( (st.st_uid != user) && (chown(name, user, st.st_gid) < 0) ) return 0;
/* Points to static area */ grp = getgrnam(TTY_GROUP);
if (grp) tty_gid = grp->gr_gid; else { /* If no tty group is found, use the server's gid */ werror("lshd: server_pty.c: No tty group found.\n"); tty_gid = getgid(); }
if ( (st.st_gid != tty_gid) && (chown(name, user, tty_gid) < 0)) return 0;
/* Make sure the permission mode is set to readable and writable
- by the owner, and writable by the group. */
if ( ((st.st_mode & ACCESSPERMS) != (S_IRUSR | S_IWUSR | S_IWGRP)) && (chmod(name, S_IRUSR | S_IWUSR | S_IWGRP) < 0) ) return 0;
/* Everything is fine */ return 1; }
/* Returns the name of the slave tty, or NULL on failure. */
const char * pty_grantpt_uid(int master, uid_t user) { uid_t me = getuid(); if (me == user) { /* Use standard grantpt call */ if (grantpt(master) < 0) return NULL;
return ptsname(master);
} else { /* Set up permissions for user */
/* Pointer to static area */ char *name = ptsname(master); return (pty_check_permissions(name, user) ? name : NULL);
} }
/ Niels Möller ()