lkml.org 
[lkml]   [1999]   [Jan]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectfchmod() and Unix domain sockets?
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/*
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);
}

\
 
 \ /
  Last update: 2005-03-22 13:49    [W:0.028 / U:0.076 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site