fchmod() and Unix domain sockets?

Dan Kegel (dank@alumni.caltech.edu)
Wed, 20 Jan 1999 21:25:06 -0800


Dies ist eine mehrteilige Nachricht im MIME-Format.
--------------91F928CDF94A8C04639B97BE
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I'm posting this for a friend not on the list.
- Dan

fchmod() doesn't seem to work with Unix
domain sockets, but chmod() works fine.
Bug exists on 2.1.130. Did not test any other versions.
Test code attached.

-- 
Speaking only for myself, not for my employer
--------------91F928CDF94A8C04639B97BE
Content-Type: text/plain; charset=us-ascii;
 name="fchmod.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="fchmod.txt"

/* Under Linux 2.1.130, fchmod and fstat do not handle Unix domain socket permissions correctly. fstat always returns 0000 user permissions, and fchmod is unable to change the permissions. chmod and stat (using the sockaddr_un sun_path) work correctly. The following test code demonstrates the problem with fchmod. jscanlin@activision.com */

#include <sys/types.h> #include <sys/stat.h> #include <sys/socket.h> #include <sys/un.h> #include <sys/errno.h>

#define fchmodtest_SOCKETNAME "/tmp/fchmodtest.sock"

void main(int argc, char *argv[]) { int sockfd; struct sockaddr_un my_addr; struct stat filestat; mode_t filemode;

if ((sockfd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0) { printf("fchmodtest: socket error:%d\n", errno); exit(1); } memset(&my_addr, 0, sizeof(my_addr)); my_addr.sun_family = AF_LOCAL; strcpy(my_addr.sun_path, fchmodtest_SOCKETNAME); if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(my_addr)) < 0) { printf("fchmodtest: bind error:%d\n", errno); exit(1); } if (stat(my_addr.sun_path, &filestat) == -1) { printf("fchmodtest: stat error:%d\n", errno); exit(1); } filemode = filestat.st_mode; printf("fchmodtest: attempting to fchmod unix socket:%d from %o to %o\n", sockfd, filemode, filemode ^ S_IWOTH); if (fchmod(sockfd, filemode ^ S_IWOTH) == -1) { printf("fchmodtest: fchmod error:%d\n", errno); exit(1); } if (stat(my_addr.sun_path, &filestat) == -1) { printf("fchmodtest: stat error:%d\n", errno); exit(1); } if (filestat.st_mode != filemode ^ S_IWOTH) printf("fchmodtest: fchmod failed.\n"); else printf("fchmodtest: fchmod succeeded.\n"); close(sockfd); unlink(my_addr.sun_path); }

--------------91F928CDF94A8C04639B97BE--

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/