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 BFD4C385483E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=SystematicSw.ab.ca Authentication-Results: sourceware.org; spf=none smtp.mailfrom=brian DOT inglis AT systematicsw DOT ab DOT ca X-Authority-Analysis: v=2.4 cv=INe8tijG c=1 sm=1 tr=0 ts=5ff49c9d a=kiZT5GMN3KAWqtYcXc+/4Q==:117 a=kiZT5GMN3KAWqtYcXc+/4Q==:17 a=IkcTkHD0fZMA:10 a=w_pzkKWiAAAA:8 a=uYT-Tk0qkVT609LjNaIA:9 a=QEXdDO2ut3YA:10 a=tMPTF2wDCtEA:10 a=sRI3_1zDfAgwuvI8zelB:22 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> <6fade6a2-af9d-243a-9719-7177ad76fbf7 AT interocitors DOT com> From: Brian Inglis Organization: Systematic Software Subject: Re: Is it possible to define the root directory in a cross compiled program Message-ID: <8ffbaeaf-f3e9-841a-3e85-6fcef3a3d683@SystematicSw.ab.ca> Date: Tue, 5 Jan 2021 10:06:35 -0700 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: <6fade6a2-af9d-243a-9719-7177ad76fbf7@interocitors.com> Content-Language: en-CA X-CMAE-Envelope: MS4xfBu7C6rALTL0OFw/3yZurvCQjw8/9rLD2lZ+akcLwhvX7H8BXwUbFTHQqzFMkE5zbIw0qbxLzTuMeXP7QAJNXlC5eyKYt/Hwl1Nu16hyXMUDZ++isyrV hZRGpK/7KAIvFk5glar1uIrfp5bAXrDcBN1O5Vwu3v/ByX4Etc1Y4qpwbaNYSRbnuuTZroZ5uYj+mNPhZV9Sy61FQ4N27wPcm7BuojSrjW1okOHdxpbyqxzD jS993BFUfZOm8KOJRqjo3g== X-Spam-Status: No, score=-6.0 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 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 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: cygwin AT cygwin DOT com Cc: Roger Kaufman Content-Type: text/plain; charset="utf-8"; Format="flowed" Errors-To: cygwin-bounces AT cygwin DOT com Sender: "Cygwin" Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 105H767w027793 On 2021-01-05 09:49, Roger Kaufman wrote: >> 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. > 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 You can adapt at runtime to the OS, check which device and root path exists (good programming practices anyway) as a default, and override if env var exists and includes a valid path which is also safe, or conditionally compile to hardwire included or excluded behaviour, with the same portable source: SMOP. -- Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada This email may be disturbing to some readers as it contains too much technical detail. Reader discretion is advised. [Data in binary units and prefixes, physical quantities in SI.] -- 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