⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ntsec.sgml

📁 cygwin, 著名的在win32下模拟unix操作系统的东东
💻 SGML
📖 第 1 页 / 共 2 页
字号:
<sect1 id="ntsec"><title>NT security and the <literal>ntsec</literal> usage</title><para>The design goal of the ntsec patch was to get a more UNIX likepermission structure based upon the security features of Windows NT.To describe the changes, I will give a short overview of NT securityin chapter one.</para><para>Chapter two discusses the changes in ntsec related to privileges onprocesses.</para><para>Chapter three shows the basics of UNIX like setting offile permissions.</para><para>Chapter four talks about the advanced settings introduced inrelease 1.1</para><para>Chapter five illustrates the permission mapping leak of Windows NT.</para><para>Chapter six describes the new support of a setuid concept introducedwith release 1.1.3.</para><para>Chapter six describes in short the new acl API since release 1.1</para><para>The setting of UNIX like object permissions is controlled by the new<EnVar>CYGWIN</EnVar> variable setting <literal>(no)ntsec</literal>.</para><sect2 id="ntsec-common"><title>NT security</title><para>The NT security allows a process to allow or deny access ofdifferent kind to `objects'. `Objects' are files, processes,threads, semaphores, etc.</para><para>The main data structure of NT security is the `security descriptor'(SD) structure. It explains the permissions, that are granted (or denied)to an object and contains information, that is related to so called`security identifiers' (SID).</para><para>A SID is a unique identifier for users, groups and domains. SIDs are comparable to UNIX UIDs and GIDs, but are more complicatedbecause they are unique across networks. Example:</para><para>SID of a system `foo':</para><screen>  S-1-5-21-165875785-1005667432-441284377</screen><para>SID of a user `johndoe' of the system `foo':</para><screen>  S-1-5-21-165875785-1005667432-441284377-1023</screen><para>The above example shows the convention for printing SIDs. The leading`S' should show that it is a SID. The next number is a version number whichis always 1. The next number is the so called `top-level authority' thatidentifies the source that issued the SID.</para><para>While each system in a NT network has it's own SID, the situationis modified in NT domains: The SID of the domain controller is thebase SID for each domain user. If an NT user has one account as domainuser and another account on his local machine, this accounts are underany circumstances DIFFERENT, regardless of the usage of the same username and password!</para><para>SID of a domain `bar':</para><screen>  S-1-5-21-186985262-1144665072-740312968</screen><para>SID of a user `johndoe' in the domain `bar':</para><screen>  S-1-5-21-186985262-1144665072-740312968-1207</screen><para>The last part of the SID, the so called `relative identifier' (RID),is by default used as UID and/or GID under cygwin. As the name and theabove example implies, this id is unique only relative to one system ordomain.</para><para>Note, that it's possible, that an user has the same RID on twodifferent systems. The resulting SIDs are nevertheless different, sothe SIDs are representing different users in an NT network.</para><para>There is a big difference between UNIX IDs and NT SIDs, the existence ofthe so called `well known groups'. For example UNIX has no GID for thegroup of `all users'. NT has an SID for them, called `Everyone' in theEnglish versions. The SIDs of well-known groups are not unique acrossan NT network but their meanings are unmistakable.Examples of well-known groups:</para><screen>everyone                        S-1-1-0creator/owner                   S-1-3-0batch process (via `at')        S-1-5-3authenticated users             S-1-5-11system                          S-1-5-18</screen><para>The last important group of SIDs are the `predefined groups'. Thisgroups are used mainly on systems outside of domains to simplify the administration of user permissions. The corresponding SIDs are not uniqueacross the network so they are interpreted only locally:</para><screen>administrators                  S-1-5-32-544users                           S-1-5-32-545guests                          S-1-5-32-546...</screen><para>Now, how are permissions given to objects? A process may assign an SDto the object. The SD of an object consists of three parts:</para><itemizedlist spacing="compact"><listitem><para>the SID of the owner </para></listitem><listitem><para>the SID of the group </para></listitem><listitem><para>a list of SIDs with their permissions, called`access control list' (ACL) </para></listitem></itemizedlist><para>UNIX is able to create three different permissions, the permissionsfor the owner, for the group and for the world. In contrast the ACLhas a potentially infinite number of members. Every member is a so called`access control element' (ACE). An ACE contains three parts:</para><itemizedlist spacing="compact"><listitem><para>the type of the ACE </para></listitem><listitem><para>permissions, described with a DWORD </para></listitem><listitem><para>the SID, for which the above mentioned permissions areset </para></listitem></itemizedlist><para>The two important types of ACEs are the `access allowed ACE' and the`access denied ACE'. The ntsec patch only used `access allowed ACEs' upto Cygwin version 1.1.0. Later versions also use `access denied ACEs' to reflect the UNIX permissions as well as possible.</para><para>The possible permissions on objects are more detailed than inUNIX. For example, the permission to delete an object is differentfrom the write permission.</para><para>With the aforementioned method NT is able to grant or revoke permissionsto objects in a far more specific way. But what about cygwin? In a POSIXenvironment it would be fine to have the security behavior of a POSIXsystem. The NT security model is MOSTLY able to reproduce the POSIX model.The ntsec patch tries to do this in cygwin.</para><para>You ask "Mostly? Why mostly???" Because there's a leak in the NT model.I will describe that in detail in chapter 4.</para><para>Creating  explicit object security is not that easy so you will oftensee only two simple variations in use:</para><itemizedlist spacing="compact"><listitem><para>default permissions, computed by the operating system </para></listitem><listitem><para>each permission to everyone </para></listitem></itemizedlist><para>For parameters to functions that create or open securable objects anotherdata structure is used, the `security attributes' (SA). This structurecontains an SD and a flag that specifies whether the returned handleto the object is inherited to child processes or not.This property is not important for the ntsec patch description so inthis document the difference between SDs and SAs is ignored.</para></sect2><sect2 id="ntsec-processes"><title>Process privileges</title><para>Any process started under control of cygwin has a semaphore attachedto it, that is used for signaling purposes. The creation of this semaphorecan be found in sigproc.cc, function `getsem'. The first parameter to thefunction call `CreateSemaphore' is an SA. Without ntsec patch this SA assigns default security to the semaphore. There is a simple disadvantage:Only the owner of the process may send signals to it. Or, in other words,if the owner of the process is not a member of the administrators' group,no administrator may kill the process! This is especially annoying, ifprocesses are started via service manager.</para><para>The ntsec patch now assigns an SA to the process control semaphore, thathas each permission set for the user of the process, for theadministrators' group and for `system', which is a synonym for theoperating system itself. The creation of this SA is done by the function`sec_user', that can be found in `shared.cc'. Each member of theadministrators' group is now allowed to send signals to any processcreated in cygwin, regardless of the process owner.</para><para>Moreover, each process now has the appropriate security settings, whenit is started via `CreateProcess'. You will find this in function`spawn_guts' in module `spawn.cc'. The security settings for starting aprocess in another user context have to add the sid of the new user, too.In the case of the `CreateProcessAsUser' call, sec_user creates an SA withan additional entry for the sid of the new user.</para></sect2><sect2 id="ntsec-files"><title>File permissions</title><para>If ntsec is turned on, file permissions are set as in UNIX. An SD isassigned to the file containing the owner and group and ACEs for theowner, the group and `Everyone'.</para><para>The complete settings of UNIX like permissions can be found in the file`security.cc'. The two functions `get_nt_attribute' and `set_nt_attribute'are the main code. The reading and writing of the SDs is done by thefunctions `read_sd' and `write_sd'. `write_sd' uses the function `BackupRead'instead of the simpler function `SetFileSecurity' because the latter isunable to set owners different from the caller.</para><para>If you are creating a file `foo' outside of cygwin, you will see somethinglike the following on <command>ls -ln</command>:</para><para>If your login is member of the administrators' group:</para><screen>  rwxrwxrwx 1  544  513  ... foo</screen><para>if not:</para><screen>  rwxrwxrwx 1  1000  513  ... foo</screen><para>Note the user and group IDs. 544 is the UID of the administrators' group.This is a `feature' <literal>:-P</literal> of WinNT. If one is a member ofthe administrators' group, every file, that he has created is owned by theadministrators' group, instead by him.</para><para>The second example shows the UID of the first user, that has beencreated with NT's the user administration tool. The users and groups aresequentially numbered, starting with 1000. Users and groups are using thesame numbering scheme, so a user and a group don't share the same ID.</para><para>In both examples the GID 513 is of special interest. This GID is awell known group with different naming in local systems and domains.Outside of domains the group is named 'None' (`Kein' in German, `Aucun'in French, etc.), in domains it is named 'Domain Users'.  Unfortunately,the group `None' is never shown in the user admin tool outside of domains!This is very confusing but this seems to have no negative consequences.</para><para>To work correctly the ntsec patch depends on the files<filename>/etc/passwd/</filename> and <filename>/etc/group</filename>.In cygwin release 1.0 the names and the IDs must correspond to theappropriate NT IDs! The IDs used in cygwin are the RID of the NT SID, asmentioned earlier.An SID of e.g. the user `corinna' on my NT workstation:</para><screen>  S-1-5-21-165875785-1005667432-441284377-1000</screen><para>Note the last number: It's the RID 1000, the cygwin's UID.</para><para>Unfortunately, workstations and servers outside of domains are notable to set primary groups! In these cases, where there is no correlationof users to primary groups, NT returns 513 (None) as primary group,regardless of the membership to existing local groups.</para><para>When using <command>mkpasswd  -l -g</command> on such systems, youhave to change the primary group by hand if `None' as primary group isnot what you want (and I'm sure, it's not what you want!)</para><para>Look at the following examples, which were parts of my files beforestoring SIDs in /etc/passwd and /etc/group had been introduced (See nextchapter for details).  With the exception of my personal user entry, allentries are well known entries.</para> <example><title>/etc/passwd</title><screen>everyone:*:0:0:::system:*:18:18:::administrator::500:544::/home/root:/bin/bashguest:*:501:546:::administrators:*:544:544::/home/root:corinna::1000:547:Corinna Vinschen:/home/corinna:/bin/tcsh</screen></example><example><title>/etc/group</title><screen>everyone::0:system::18:none::513:administrators::544:users::545:guests::546:powerusers::547:</screen></example><para>As you can see, I changed my primary group membership from 513 (None)to 547 (powerusers).  So all files I created inside of Cygwin were now ownedby the powerusers group instead of None.  This is the way I liked it.</para><para>Groups may be mentioned in the passwd file, too. This has twoadvantages:</para><itemizedlist spacing="compact"><listitem><para>Because NT assigns them to files as owners, a<command>ls -l</command> is often more readable.</para></listitem><listitem><para>Moreover it's possible to assigned them to files asowners with cygwin's <command>chown</command>.</para></listitem></itemizedlist><para>The group `system' is the aforementioned synonym for the operating systemitself and is normally the owner of processes, that are started throughservice manager. The same is true for files, that are created byprocesses, which are started through service manager.</para></sect2><sect2 id="ntsec-release1.1"><title>New since Cygwin release 1.1</title><para>In Cygwin release 1.1 a new technique of using the <filename>/etc/passwd</filename> and <filename>/etc/group</filename> is introduced.</para><para>Both files may now contain SIDs of users and groups. Theyare saved in the last field of pw_gecos in <filename>/etc/passwd</filename>and in the gr_passwd field in <filename>/etc/group</filename>.</para><para>This has the following advantages:</para><itemizedlist spacing="compact"><listitem><para>ntsec works better in domain environments.</para></listitem><listitem><para>Accounts (users and groups) may get another name incygwin than their NT account name. The name in <filename>/etc/passwd</filename>or <filename>/etc/group</filename> is transparently used by cygwinapplications (eg. <command>chown</command>, <command>chmod</command>,<command>ls</command>):</para><screen>root::500:513::/home/root:/bin/sh</screen><para>instead of</para><screen>adminstrator::500:513::/home/root:/bin/sh</screen><para>Caution: If you like to use the account as login account via<command>telnet</command> etc. you have to remain the name unchanged oryou have to use the special version of <command>login</command> which ispart of the standard Cygwin distribution since 1.1.</para></listitem><listitem><para>Cygwin UIDs and GIDs are now not necessarily the RIDpart of the NT SID:</para><screen>root::0:513:S-1-5-21-54355234-56236534-345635656-500:/home/root:/bin/sh</screen><para>instead of</para><screen>root::500:513::/home/root:/bin/sh</screen></listitem><listitem><para>As in U*X systems UIDs and GIDs numbering scheme nowdon't influence each other. So it's possible to have same Id's for auser and a group:</para><example><title>/etc/passwd:</title><screen>root::0:0:S-1-5-21-54355234-56236534-345635656-500:/home/root:/bin/sh</screen></example><example><title>/etc/group:</title><screen>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -