bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

grantpt, devfs mounted and devpts unmounted!


From: Francois Armand
Subject: grantpt, devfs mounted and devpts unmounted!
Date: Tue, 26 Aug 2003 11:38:56 +0200
User-agent: Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.0.1) Gecko/20020920 Netscape/7.0

   Hi,

I have trouble with  the grantpt() library (glibc 2.2.5) on Linux (2.4.20)
on Intel  when /devfs is mounted while /dev/pts is not mounted.

grantpt() is expected to set the access rights of a pseudo-tty, so
that they are "crw--w----". This works fine when the devpts file system is
mounted with the appropriate (0620) mode option.

When the devpts file system is not mounted, the access rights are
left to 0600 by grantpt() although grantpt() returns a success
indication.

The implementation I found in sysdeps/unix/sysv/linux/grantpt.c, has the
following comment and code:

 /* If the slave pseudo terminal lives on a `devpts' filesystem, the
    ownership and access permission are already set.  */

if (fsbuf.f_type == DEVPTS_SUPER_MAGIC || fsbuf.f_type == DEVFS_SUPER_MAGIC)
   return 0;

 return __unix_grantpt (fd);

Where __unix_grantpt() is doing the actual work quite correctly when invoked.

I have trouble understanding the reason why the file system type has to be
tested as devfs since devfs does not set the access right correctly
by its own. Well, in fact devpts does not either since it
depends upon the mode given at mount time, but we assume the mount has
been done correctly. I did run a modified version of grantpt as follows:

 /* If the slave pseudo terminal lives on a `devpts' filesystem, the
    ownership and access permission are already set.  */

 if (fsbuf.f_type == DEVPTS_SUPER_MAGIC)
   return 0;

 return __unix_grantpt (fd);

and my grantpt() invocation did the work I expected. However, I am still
unsure about this modification. Did I introduce some flaw while
apparently fixing my issue?

I am attaching a small test program I crafted quickly.
I've also attached the patch file in case it's worth applying.

Thanks in advance for any help,

Francois

#include        <stdlib.h>
#include        <sys/types.h>
#include        <sys/stat.h>
#include        <unistd.h>
#include        <errno.h>
#include        <fcntl.h>
#include        <stdio.h>

#define PTY_MODE        (mode_t)(S_IRUSR|S_IWUSR|S_IWGRP)
#define PERM_MASK       (mode_t)(S_IRWXU|S_IRWXG|S_IRWXO)

main()
{

  int fd;
  int res;
  char * pts;
  struct stat stbuf;

  fd = open("/dev/ptmx", O_RDWR);
  if (fd <0) {
    printf("Cannot open /dev/ptx err= %d\n", errno);
    exit(1);
  }
  pts = (char*) ptsname(fd);

  res = stat(pts, &stbuf);
  if (res <0) {
    printf("Cannot stat %s, err= %d\n", pts, errno);
    exit(1);
  }

  printf ("Owner uid %d, my uid %d\n", stbuf.st_uid, geteuid());

  if ((stbuf.st_mode & PERM_MASK) != PTY_MODE) {
    printf("got mode 0%lo instead of 0%lo full mode 0%lo\n",
           stbuf.st_mode & PERM_MASK, PTY_MODE, stbuf.st_mode);
  } else
    printf("OK\n");

  res = grantpt(fd);
  if (res < 0) {
    printf("grantpt failed, errno %d\n", errno);
    exit(1);
  }

  res = stat(pts, &stbuf);
  if (res <0) {
    printf("Cannot stat %s, err= %d\n", pts, errno);
    exit(1);
  }
  printf ("Owner uid %d, my uid %d\n", stbuf.st_uid, geteuid());

  if ((stbuf.st_mode & PERM_MASK) != PTY_MODE) {
    printf("got mode 0%lo instead of 0%lo full mode 0%lo\n",
           stbuf.st_mode & PERM_MASK, PTY_MODE, stbuf.st_mode);
  } else
    printf("OK\n");
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]