delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2021/01/05/11:49:54

X-Recipient: archive-cygwin AT delorie DOT com
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 01DE03857036
Authentication-Results: sourceware.org; dmarc=none (p=none dis=none)
header.from=interocitors.com
Authentication-Results: sourceware.org;
spf=fail smtp.mailfrom=rogerkaufman AT interocitors DOT com
X-Authority-Reason: nr=8
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
d=interocitors.com; s=default; h=Content-Transfer-Encoding:Content-Type:
In-Reply-To:MIME-Version:Date:Message-ID:From:References:To:Subject:Sender:
Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From:
Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:
List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive;
bh=/iXAjTsX5xBpKUxR0LYAjWLllk9tzjN2d7zqjGPPLNM=; b=3QCNrR7XjOScCopuIupEoXnxNq
gDWemlTz4aWqfUeK96gg0tSU8ikOu30aeO/qL4pAllvLv0Di/NHLDGYw/WjdkfSeakGjmZcB7dxY+
jJc/mktqkdTWqUHoCcsWSjWYW;
Subject: Re: Is it possible to define the root directory in a cross compiled
program
To: cygwin AT cygwin DOT com
References: <48b833bd-547a-92eb-542e-b7da8e0d601b AT interocitors DOT com>
<9d339f8b-83ff-8b9c-b2fe-1c6fa4b2a92d AT SystematicSw DOT ab DOT ca>
From: Roger Kaufman <rogerkaufman AT interocitors DOT com>
Message-ID: <6fade6a2-af9d-243a-9719-7177ad76fbf7@interocitors.com>
Date: Tue, 5 Jan 2021 11:49:01 -0500
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.6.0
MIME-Version: 1.0
In-Reply-To: <9d339f8b-83ff-8b9c-b2fe-1c6fa4b2a92d@SystematicSw.ab.ca>
X-AntiAbuse: This header was added to track abuse,
please include it with any abuse report
X-AntiAbuse: Primary Hostname - host2043.hostmonster.com
X-AntiAbuse: Original Domain - cygwin.com
X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse: Sender Address Domain - interocitors.com
X-BWhitelist: no
X-Source-IP: 207.44.76.119
X-Source-L: No
X-Exim-ID: 1kwpW1-0046MA-Nb
X-Source:
X-Source-Args:
X-Source-Dir:
X-Source-Sender: 207.44.76.119.res-cmts.hol.ptd.net ([192.168.1.99])
[207.44.76.119]:57142
X-Source-Auth: rogerkaufman AT interocitors DOT com
X-Email-Count: 5
X-Source-Cap: aW50ZXJvY2k7aW50ZXJvY2k7aG9zdDIwNDMuaG9zdG1vbnN0ZXIuY29t
X-Local-Domain: yes
X-Spam-Status: No, score=2.9 required=5.0 tests=BAYES_00, DKIM_SIGNED,
DKIM_VALID, JMQ_SPF_NEUTRAL, NICE_REPLY_A, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE,
RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NEUTRAL,
TXREP autolearn=no autolearn_force=no version=3.4.2
X-Spam-Level: **
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on
server2.sourceware.org
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.29
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
Errors-To: cygwin-bounces AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces AT cygwin DOT com>
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 105GnZvx023949

Hi All,

> On 1/5/2021 10:02 AM, Bill Stewart wrote:
> > On Tue, Jan 5, 2021 at 6:34 AM Eliot Moss wrote:
> >
> >> Is there a Windows equivalent to chroot (either the program or the 
> library/system call)?
> >
> > See: https://cygwin.com/cygwin-ug-net/highlights.html
> >
> > Quoting:
> >
> > "Chroot is supported. Kind of. Chroot is not a concept known by
> > Windows. This implies some serious restrictions. First of all, the
> > chroot call isn't a privileged call. Any user may call it. Second, the
> > chroot environment isn't safe against native windows processes. Given
> > that, chroot in Cygwin is only a hack which pretends security where
> > there is none. For that reason the usage of chroot is discouraged.
> > Don't use it unless you really, really know what you're doing."
> >
> > What I have found is that the cygwin chroot is not a security boundary
>
> Right.  My impression was that the OP was more interested in having the
> functionality of where / is, though I could be wrong, of course.
>
> I also saw web posts about Windows' RUNAS command, which deals with 
> some of
> the security implications, but does not re-root your file hierarchy.
>
> Best - Eliot 

This is the OP. We can close this out. Brian Inglis mentioned the 
Windows /dev/null is "nul"
and so that solved the problem in this case. In the code below, both 
fopen's succeed
when compiled with gcc and the "nul" fopen succeeds when cross compiled with
x86_64-w64-mingw32-g++

The backstory is, I cross compile because I have code only compatible 
when cross
compiled. However, I run the code in the bash shell. Now in the bash 
shell, I can't change
directory higher than / which is expected (I know of cygdrive/c of course)

However since it is now technically a windows  program it can "see out" 
into the
file system. I have for that program, an environment variable path I 
also have to prefix e.g.
/cygwin64/home... its just something I have to live with. But it does 
make portability
imperfect as the same code compiles in Linux.

#include <cstdio>

int main(int argc, char **argv)
{
   FILE *errfile1 = fopen("/dev/null", "w");
   if (!errfile1) // must be a valid pointer
     errfile1 = stderr;

   FILE *errfile2 = fopen("nul", "w");
   if (!errfile2) // must be a valid pointer
     errfile2 = stderr;

   fprintf(errfile1, "/dev/null did not succeed\n");
   fprintf(errfile2, "nul did not succeed\n");

   return 0;
}

Roger

--
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019