📄 overview2.sgml
字号:
<sect1 id="ov-ex-unix"><title>Expectations for UNIX Programmers</title><para>Developers coming from a UNIX background will find a set of utilitiesthey are already comfortable using, including a working UNIX shell. Thecompiler tools are the standard GNU compilers most people will have previouslyused under UNIX, only ported to the Windows host. Programmers wishing to portUNIX software to Windows NT or 9x will find that the Cygwin library providesan easy way to port many UNIX packages, with only minimal source codechanges.</para></sect1><sect1 id="ov-ex-win"><title>Expectations for Windows Programmers</title><para>Developers coming from a Windows background will find a set of tools capableof writing console or GUI executables that rely on the Microsoft Win32 API.The linker and dlltool utility may be used to write Windows Dynamically LinkedLibraries (DLLs). The resource compiler "windres" is also provided with thenative Windows GNUPro tools. All tools may be used from the Microsoft commandline prompt, with full support for normal Windows pathnames.</para></sect1><sect2 id="ov-hi-intro"><title>Introduction</title> <para>When a binary linkedagainst the library is executed, the Cygwin DLL is loaded into theapplication's text segment. Because we are trying to emulate a UNIX kernelwhich needs access to all processes running under it, the first Cygwin DLL torun creates shared memory areas that other processes using separate instancesof the DLL can access. This is used to keep track of open file descriptors andassist fork and exec, among other purposes. In addition to the shared memoryregions, every process also has a per_process structure that containsinformation such as process id, user id, signal masks, and other similarprocess-specific information.</para><para>The DLL is implemented using the Win32 API, which allows it to run on allWin32 hosts. Because processes run under the standard Win32 subsystem, theycan access both the UNIX compatibility calls provided by Cygwin as well asany of the Win32 API calls. This gives the programmer complete flexibility indesigning the structure of their program in terms of the APIs used. Forexample, they could write a Win32-specific GUI using Win32 API calls on top ofa UNIX back-end that uses Cygwin.</para><para>Early on in the development process, we made the important designdecision that it would not be necessary to strictly adhere to existing UNIXstandards like POSIX.1 if it was not possible or if it would significantlydiminish the usability of the tools on the Win32 platform. In many cases, anenvironment variable can be set to override the default behavior and forcestandards compliance.</para></sect2><sect2 id="ov-hi-win9xnt"><title>Supporting both Windows NT and 9x</title><para>While Windows 95 and Windows 98 are similar enough to each other that wecan safely ignore the distinction when implementing Cygwin, Windows NT is anextremely different operating system. For this reason, whenever the DLL isloaded, the library checks which operating system is active so that it can actaccordingly.</para><para>In some cases, the Win32 API is only different forhistorical reasons. In this situation, the same basic functionality isavailable under Windows 9x and NT but the method used to gain thisfunctionality differs. A trivial example: in our implementation ofuname, the library examines the sysinfo.dwProcessorType structuremember to figure out the processor type under Windows 9x. This fieldis not supported in NT, which has its own operating system-specificstructure member called sysinfo.wProcessorLevel.</para><para>Other differences between NT and 9x are much more fundamental innature. The best example is that only NT provides a security model.</para></sect2><sect2 id="ov-hi-perm"><title>Permissions and Security</title><para>Windows NT includes a sophisticated security model based on AccessControl Lists (ACLs). Cygwin maps Win32 file ownership and permissions to themore standard, older UNIX model by default. Cygwin version 1.1 introducessupport for ACLs according to the system calls used on newer versions ofSolaris. This ability is used when the `ntsec' feature is switched on whichis described in another chapter.The chmod call maps UNIX-style permissionsback to the Win32 equivalents. Because many programs expect to be able to findthe /etc/passwd and /etc/group files, we provide utilities that can be used toconstruct them from the user and group information provided by the operatingsystem.</para><para>Under Windows NT, the administrator is permitted to chown files. Thereis no mechanism to support the setuid concept or API call since Cygwin version1.1.2. With version 1.1.3 Cygwin introduces a mechanism for setting realand effective UIDs under Windows NT/W2K. This is described in the ntsecsection.</para><para>Under Windows 9x, the situation is considerably different. Since asecurity model is not provided, Cygwin fakes file ownership by making allfiles look like they are owned by a default user and group id. As under NT,file permissions can still be determined by examining their read/write/executestatus. Rather than return an unimplemented error, under Windows 9x, thechown call succeeds immediately without actually performing any actionwhatsoever. This is appropriate since essentially all users jointly own thefiles when no concept of file ownership exists.</para><para>It is important that we discuss the implications of our "kernel" usingshared memory areas to store information about Cygwin processes. Becausethese areas are not yet protected in any way, in principle a malicious usercould modify them to cause unexpected behavior in Cygwin processes. Whilethis is not a new problem under Windows 9x (because of the lack of operatingsystem security), it does constitute a security hole under Windows NT.This is because one user could affect the Cygwin programs run byanother user by changing the shared memory information in ways thatthey could not in a more typical WinNT program. For this reason, itis not appropriate to use Cygwin in high-security applications. Inpractice, this will not be a major problem for most uses of thelibrary.</para></sect2><sect2 id="ov-hi-files"><title>File Access</title> <para>Cygwin supportsboth Win32- and POSIX-style paths, using either forward or back slashes as thedirectory delimiter. Paths coming into the DLL are translated from Win32 toPOSIX as needed. As a result, the library believes that the file system is aPOSIX-compliant one, translating paths back to Win32 paths whenever it calls aWin32 API function. UNC pathnames (starting with two slashes) aresupported.</para><para>The layout of this POSIX view of the Windows file system space is storedin the Windows registry. While the slash ('/') directory points to the systempartition by default, this is easy to change with the Cygwin mount utility.In addition to selecting the slash partition, it allows mounting arbitraryWin32 paths into the POSIX file system space. Many people use the utility tomount each drive letter under the slash partition (e.g. C:\ to /c, D:\ to /d,etc...).</para><para>The library exports several Cygwin-specific functions that can be usedby external programs to convert a path or path list from Win32 to POSIX or viceversa. Shell scripts and Makefiles cannot call these functions directly.Instead, they can do the same path translations by executing the cygpathutility program that we provide with Cygwin.</para><para>Win32 file systems are case preserving but case insensitive. Cygwindoes not currently support case distinction because, in practice, few UNIXprograms actually rely on it. While we could mangle file names to support casedistinction, this would add unnecessary overhead to the library and make itmore difficult for non-Cygwin applications to access those files.</para><para>Symbolic links are emulated by files containing a magic cookie followedby the path to which the link points. They are marked with the Systemattribute so that only files with that attribute have to be read to determinewhether or not the file is a symbolic link. Hard links are fully supportedunder Windows NT on NTFS file systems. On a FAT file system, the call fallsback to simply copying the file, a strategy that works in many cases.</para><para>The inode number for a file is calculated by hashing its full Win32 path.The inode number generated by the stat call always matches the one returned ind_ino of the dirent structure. It is worth noting that the number produced bythis method is not guaranteed to be unique. However, we have not found this tobe a significant problem because of the low probability of generating aduplicate inode number.</para><para>Chroot is supported since release 1.1.3. Note that chroot isn'tsupported native by Windows. This implies some restrictions. First of all,the chroot call isn't a privileged call. Each user may call it. Second, thechroot environment isn't safe against native windows processes. If youwant to support a chroot environment as, for example, by allowing ananonymous ftp with restricted access, you'll have to care that onlynative Cygwin applications are accessible inside of the chroot environment.Since that applications are only using the Cygwin POSIX API to access thefile system their access can be restricted as it is intended. This includesnot only POSIX paths but Win32 paths (containing drive letter and/orbackslashes) and CIFS paths (//server/share or \\server\share) as well.</para>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -