[PATCH] fstat() problem in libc/rexec.cc

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] fstat() problem in libc/rexec.cc

Earl Chew
The current implementation of rexec() uses fstat() and it seems
to pick up the wrong values for st_mode. As a consequence
the code keeps complaining about the permissions for ~/.netrc
and won't complete successfully.

I don't know enough about the how the re-mapping of stat/stat64
works within cygwin1.dll itself, but changing to fstat64()
like libc/iruserok.c resolves the problem.




winsup/cygwin/Changlog

     * libc/rexec.cc: Use fstat64() instead of fstat().


--- winsup/cygwin/libc/rexec.cc.orig    2009-04-06 12:11:02.046875000 -0700
+++ winsup/cygwin/libc/rexec.cc 2009-04-06 12:12:31.578125000 -0700
@@ -159,7 +159,7 @@
         char myname[INTERNET_MAX_HOST_NAME_LENGTH + 1];
         const char *mydomain;
         int t, i, c, usedefault = 0;
-       struct stat stb;
+       struct __stat64 stb;

         hdir = getenv("HOME");
         if (hdir == NULL)
@@ -218,7 +218,7 @@
                         break;
                 case PASSWD:
                         if ((*aname == 0 || strcmp(*aname, "anonymous")) &&
-                           fstat(fileno(cfile), &stb) >= 0 &&
+                           fstat64(fileno(cfile), &stb) >= 0 &&
                             (stb.st_mode & 077) != 0) {
         warnx("Error: .netrc file is readable by others.");
         warnx("Remove password or make file unreadable by others.");
@@ -230,7 +230,7 @@
                         }
                         break;
                 case ACCOUNT:
-                       if (fstat(fileno(cfile), &stb) >= 0
+                       if (fstat64(fileno(cfile), &stb) >= 0
                             && (stb.st_mode & 077) != 0) {
         warnx("Error: .netrc file is readable by others.");
         warnx("Remove account or make file unreadable by others.");




Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] fstat() problem in libc/rexec.cc

Corinna Vinschen-2
Hi Earl,

On Apr  6 13:20, Earl Chew wrote:
> The current implementation of rexec() uses fstat() and it seems
> to pick up the wrong values for st_mode. As a consequence
> the code keeps complaining about the permissions for ~/.netrc
> and won't complete successfully.
>
> I don't know enough about the how the re-mapping of stat/stat64
> works within cygwin1.dll itself, but changing to fstat64()
> like libc/iruserok.c resolves the problem.

That's exactly the right thing to do.  The mapping from fstat to fstat64
only works for applications and libs linked against Cygwin, not within
Cygwin itself.  So the call to fstat in rexec calls the old fstat
function which uses the old backward compatible style struct stat with
different member sizes.  This explains that the mode bits are not
correct.  I really thought I had catched them all, but this slipped
through my cracks, apparently :}

> winsup/cygwin/Changlog
>
>     * libc/rexec.cc: Use fstat64() instead of fstat().

Patch applied.


Thank you,
Corinna

--
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] fstat() problem in libc/rexec.cc

Charles Wilson-2
In reply to this post by Earl Chew
Corinna Vinschen wrote:

>On Apr  6 13:20, Earl Chew wrote:
>> The current implementation of rexec() uses fstat() and it seems
>> to pick up the wrong values for st_mode. As a consequence
>> the code keeps complaining about the permissions for ~/.netrc
>> and won't complete successfully.
>>
>> I don't know enough about the how the re-mapping of stat/stat64
>> works within cygwin1.dll itself, but changing to fstat64()
>> like libc/iruserok.c resolves the problem.
>
> That's exactly the right thing to do.  The mapping from fstat to fstat64
> only works for applications and libs linked against Cygwin, not within
> Cygwin itself.  So the call to fstat in rexec calls the old fstat
> function which uses the old backward compatible style struct stat with
> different member sizes.  This explains that the mode bits are not
> correct.  I really thought I had catched them all, but this slipped
> through my cracks, apparently :}

I think this should also fix the (long-standing) problem documented in
the rexecd section of /usr/share/doc/Cygwin/inetutils*README:

  I verified that the REXEC_USER/REXEC_PASS variables work, but
  cygwin's rcmd() implementation is problematic. It complained that my
  ~/.netrc file was readable by others, and refused to use it; however,
  the permissions were 0600.  I did not track this down further.

--
Chuck