On Thu, Feb 20, 2003 at 01:23:43PM -0500, Paul Swartz wrote: > OK, here's what the script looks like on Cygwin: > ----- > stat from filename (49536, 1374655, 27579L, 1, 1005, 513, 51, > 1045764368, 1045764368, 1045764368) > stat from fileno (49590, 1672, 2816L, 1, 0, 0, 0, 1045764368, > 1045764368, 1045764368) > ----- > The lists correspond to (st_mode, st_ino, st_dev, st_nlink, st_uid, > st_gid, st_size, st_atime, st_mtime, st_ctime) > > As you can see, most of the numbers are not the same. In fact, the > only ones that /are/ the same at st_nlink and st_atime. > > On *nix, the results look like this: > ----- > stat from filename (49536, 3228941L, 769L, 1, 1037, 1037, 0L, > 1045736044, 1045736044, 1045736044) > stat from fileno (49663, 5351966L, 0L, 1, 1037, 1037, 0L, > 1045736044, 1045736044, 1045736044) > ----- > The only ones on *nix that are different are the first three > (st_mode, st_ino, and, st_dev). > > The difference in the fstat on the opened fileno and the stat on > the filename make it difficult, and probably impossible in some > cases, to tell if the socket opened is the same as the file. This > makes writing secure software that uses UNIX sockets difficult, if > not impossible.
I created a testcase which allows me to reproduce your observation. First of all let me say that thanks to your report I could find the problem in Cygwin which explains the differences between stat() and fstat(). However, I'm not quite sure if that will help you. I've created a AF_UNIX socket called "pipe.101" and this is the output of my testcase: STAT : "pipe.101" st_dev : b00 st_ino : -857905661 st_mode : 49590 st_nlink : 1 st_uid : 0 st_gid : 0 st_rdev : b00 st_size : 0 st_blksize: 1024 st_blocks : 0 st_ctime : 1045775480 st_mtime : 1045775480 st_atime : 1045775480 FSTAT : "pipe.101" st_dev : b00 st_ino : 1872 st_mode : 49590 st_nlink : 1 st_uid : 0 st_gid : 0 st_rdev : b00 st_size : 0 st_blksize: 1024 st_blocks : 0 st_ctime : 1045775480 st_mtime : 1045775480 st_atime : 1045775480 Note that except for st_ino all other fields are identical. But other than that, I don't see *any* field which you could use to identify the results being the same file. I've checked the same testcase on Linux and I'm getting the following results: STAT : "pipe.101" st_dev : 821 st_ino : 33442 st_mode : 49645 st_nlink : 1 st_uid : 500 st_gid : 100 st_rdev : 0 st_size : 0 st_blksize: 4096 st_blocks : 0 st_ctime : 1045776973 st_mtime : 1045776973 st_atime : 1045776973 FSTAT : "pipe.101" st_dev : 0 st_ino : 378241 st_mode : 49663 st_nlink : 1 st_uid : 500 st_gid : 100 st_rdev : 0 st_size : 0 st_blksize: 4096 st_blocks : 0 st_ctime : 1045776957 st_mtime : 1045776957 st_atime : 1045776804 As you can see, there's also nothing which would help you in using the result to identify the sockets as being the same. Even the timestamps aren't identical. Bottom line: Trying to use the result of fstat/stat to identify a socket is definitely non-portable and will give you more headaches than useful results. Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Developer mailto:[EMAIL PROTECTED] Red Hat, Inc. -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/