mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-24 21:46:52 +01:00
236 lines
37 KiB
HTML
236 lines
37 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
|
|
<meta name="generator" content="Doxygen 1.9.8"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<title>tgstation-server: src/Tgstation.Server.Host/Security/WindowsSystemIdentityFactory.cs Source File</title>
|
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="jquery.js"></script>
|
|
<script type="text/javascript" src="dynsections.js"></script>
|
|
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="search/searchdata.js"></script>
|
|
<script type="text/javascript" src="search/search.js"></script>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr id="projectrow">
|
|
<td id="projectalign">
|
|
<div id="projectname">tgstation-server<span id="projectnumber"> 6.19.3</span>
|
|
</div>
|
|
<div id="projectbrief">The /tg/station 13 server suite</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.9.8 -->
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
var searchBox = new SearchBox("searchBox", "search/",'.html');
|
|
/* @license-end */
|
|
</script>
|
|
<script type="text/javascript" src="menudata.js"></script>
|
|
<script type="text/javascript" src="menu.js"></script>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(function() {
|
|
initMenu('',true,false,'search.php','Search');
|
|
$(document).ready(function() { init_search(); });
|
|
});
|
|
/* @license-end */
|
|
</script>
|
|
<div id="main-nav"></div>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(document).ready(function() { init_codefold(0); });
|
|
/* @license-end */
|
|
</script>
|
|
<!-- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
</div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<div id="MSearchResults">
|
|
<div class="SRPage">
|
|
<div id="SRIndex">
|
|
<div id="SRResults"></div>
|
|
<div class="SRStatus" id="Loading">Loading...</div>
|
|
<div class="SRStatus" id="Searching">Searching...</div>
|
|
<div class="SRStatus" id="NoMatches">No Matches</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="nav-path" class="navpath">
|
|
<ul>
|
|
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_34761767c1c3cd212f9d2f80ea0828a8.html">Tgstation.Server.Host</a></li><li class="navelem"><a class="el" href="dir_c5451d9d233744a5b09a29938f0cda9a.html">Security</a></li> </ul>
|
|
</div>
|
|
</div><!-- top -->
|
|
<div class="header">
|
|
<div class="headertitle"><div class="title">WindowsSystemIdentityFactory.cs</div></div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<a href="_windows_system_identity_factory_8cs.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno"> 1</span><span class="keyword">using </span>System;</div>
|
|
<div class="line"><a id="l00002" name="l00002"></a><span class="lineno"> 2</span><span class="keyword">using </span>System.Diagnostics.CodeAnalysis;</div>
|
|
<div class="line"><a id="l00003" name="l00003"></a><span class="lineno"> 3</span><span class="keyword">using </span>System.DirectoryServices.AccountManagement;</div>
|
|
<div class="line"><a id="l00004" name="l00004"></a><span class="lineno"> 4</span><span class="keyword">using </span>System.Runtime.Versioning;</div>
|
|
<div class="line"><a id="l00005" name="l00005"></a><span class="lineno"> 5</span><span class="keyword">using </span>System.Security.Principal;</div>
|
|
<div class="line"><a id="l00006" name="l00006"></a><span class="lineno"> 6</span><span class="keyword">using </span>System.Threading;</div>
|
|
<div class="line"><a id="l00007" name="l00007"></a><span class="lineno"> 7</span><span class="keyword">using </span>System.Threading.Tasks;</div>
|
|
<div class="line"><a id="l00008" name="l00008"></a><span class="lineno"> 8</span> </div>
|
|
<div class="line"><a id="l00009" name="l00009"></a><span class="lineno"> 9</span><span class="keyword">using </span>Microsoft.Extensions.Logging;</div>
|
|
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno"> 10</span><span class="keyword">using </span>Microsoft.Win32.SafeHandles;</div>
|
|
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno"> 11</span> </div>
|
|
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno"> 12</span><span class="keyword">using </span><a class="code hl_namespace" href="namespace_tgstation_1_1_server_1_1_host_1_1_i_o.html">Tgstation.Server.Host.IO</a>;</div>
|
|
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno"> 13</span><span class="keyword">using </span><a class="code hl_namespace" href="namespace_tgstation_1_1_server_1_1_host_1_1_models.html">Tgstation.Server.Host.Models</a>;</div>
|
|
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno"> 14</span><span class="keyword">using </span><a class="code hl_namespace" href="namespace_tgstation_1_1_server_1_1_host_1_1_system.html">Tgstation.Server.Host.System</a>;</div>
|
|
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno"> 15</span> </div>
|
|
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno"> 16</span><span class="keyword">namespace </span><a class="code hl_namespace" href="namespace_tgstation_1_1_server_1_1_host_1_1_security.html">Tgstation.Server.Host.Security</a></div>
|
|
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno"> 17</span>{</div>
|
|
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno"> 21</span> [SupportedOSPlatform(<span class="stringliteral">"windows"</span>)]</div>
|
|
<div class="foldopen" id="foldopen00022" data-start="{" data-end="};">
|
|
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno"><a class="line" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html"> 22</a></span> <span class="keyword">sealed</span> <span class="keyword">class </span><a class="code hl_class" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html">WindowsSystemIdentityFactory</a> : <a class="code hl_interface" href="interface_tgstation_1_1_server_1_1_host_1_1_security_1_1_i_system_identity_factory.html">ISystemIdentityFactory</a></div>
|
|
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno"> 23</span> {</div>
|
|
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno"><a class="line" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#a384470b6fd596dcc97a6e39a0dcdbe74"> 27</a></span> readonly ILogger<WindowsSystemIdentityFactory> <a class="code hl_variable" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#a384470b6fd596dcc97a6e39a0dcdbe74">logger</a>;</div>
|
|
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno"> 28</span> </div>
|
|
<div class="foldopen" id="foldopen00035" data-start="{" data-end="}">
|
|
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno"><a class="line" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#a4892a64479cbfc5e731be98b229ac114"> 35</a></span> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code hl_function" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#a4892a64479cbfc5e731be98b229ac114">GetUserAndDomainName</a>(<span class="keywordtype">string</span> input, out <span class="keywordtype">string</span> username, out <span class="keywordtype">string</span>? domainName)</div>
|
|
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno"> 36</span> {</div>
|
|
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno"> 37</span> var splits = input.Split(<span class="charliteral">'\\'</span>);</div>
|
|
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno"> 38</span> username = splits.Length > 1 ? splits[1] : splits[0];</div>
|
|
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno"> 39</span> domainName = splits.Length > 1 ? splits[0] : <span class="keyword">null</span>;</div>
|
|
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno"> 40</span> }</div>
|
|
</div>
|
|
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno"> 41</span> </div>
|
|
<div class="foldopen" id="foldopen00046" data-start="{" data-end="}">
|
|
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno"><a class="line" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#a46f081a94982769acd01d0fdee271b40"> 46</a></span> <span class="keyword">public</span> <a class="code hl_function" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#a46f081a94982769acd01d0fdee271b40">WindowsSystemIdentityFactory</a>(ILogger<WindowsSystemIdentityFactory> <a class="code hl_variable" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#a384470b6fd596dcc97a6e39a0dcdbe74">logger</a>)</div>
|
|
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno"> 47</span> {</div>
|
|
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno"> 48</span> this.logger = <a class="code hl_variable" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#a384470b6fd596dcc97a6e39a0dcdbe74">logger</a> ?? <span class="keywordflow">throw</span> <span class="keyword">new</span> ArgumentNullException(nameof(<a class="code hl_variable" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#a384470b6fd596dcc97a6e39a0dcdbe74">logger</a>));</div>
|
|
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno"> 49</span> }</div>
|
|
</div>
|
|
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno"> 50</span> </div>
|
|
<div class="line"><a id="l00052" name="l00052"></a><span class="lineno"><a class="line" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#aad49a7d5b5c5f6e796587da47e29215e"> 52</a></span> <span class="keyword">public</span> <a class="code hl_interface" href="interface_tgstation_1_1_server_1_1_host_1_1_security_1_1_i_system_identity.html">ISystemIdentity</a> <a class="code hl_function" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#aad49a7d5b5c5f6e796587da47e29215e">GetCurrent</a>() => <span class="keyword">new</span> <a class="code hl_class" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity.html">WindowsSystemIdentity</a>(WindowsIdentity.GetCurrent());</div>
|
|
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno"> 53</span> </div>
|
|
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno"><a class="line" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#add117d69f999105b2d0e9f21b2ef9dd6"> 55</a></span> <span class="keyword">public</span> Task<ISystemIdentity?> <a class="code hl_function" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#add117d69f999105b2d0e9f21b2ef9dd6">CreateSystemIdentity</a>(<a class="code hl_class" href="class_tgstation_1_1_server_1_1_host_1_1_models_1_1_user.html">User</a> user, CancellationToken cancellationToken) => Task.Factory.StartNew(</div>
|
|
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno"> 56</span> () =></div>
|
|
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno"> 57</span> {</div>
|
|
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno"> 58</span> ArgumentNullException.ThrowIfNull(user);</div>
|
|
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno"> 59</span> </div>
|
|
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno"> 60</span> <span class="keywordflow">if</span> (user.SystemIdentifier == <span class="keyword">null</span>)</div>
|
|
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno"> 61</span> <span class="keywordflow">throw</span> <span class="keyword">new</span> InvalidOperationException(<span class="stringliteral">"User's SystemIdentifier must not be null!"</span>);</div>
|
|
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"> 62</span> </div>
|
|
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno"> 63</span> PrincipalContext? pc = <span class="keyword">null</span>;</div>
|
|
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno"> 64</span> <a class="code hl_function" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#a4892a64479cbfc5e731be98b229ac114">GetUserAndDomainName</a>(user.SystemIdentifier, out _, out var domainName);</div>
|
|
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno"> 65</span> </div>
|
|
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno"> 66</span> <span class="keywordtype">bool</span> TryGetPrincipalFromContextType(ContextType contextType, [NotNullWhen(<span class="keyword">true</span>)] out UserPrincipal? principal)</div>
|
|
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno"> 67</span> {</div>
|
|
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno"> 68</span> principal = <span class="keyword">null</span>;</div>
|
|
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno"> 69</span> <span class="keywordflow">try</span></div>
|
|
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno"> 70</span> {</div>
|
|
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno"> 71</span> pc = domainName != <span class="keyword">null</span></div>
|
|
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno"> 72</span> ? <span class="keyword">new</span> PrincipalContext(contextType, domainName)</div>
|
|
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno"> 73</span> : <span class="keyword">new</span> PrincipalContext(contextType);</div>
|
|
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno"> 74</span> cancellationToken.ThrowIfCancellationRequested();</div>
|
|
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno"> 75</span> principal = UserPrincipal.FindByIdentity(pc, user.SystemIdentifier);</div>
|
|
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno"> 76</span> }</div>
|
|
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno"> 77</span> <span class="keywordflow">catch</span> (OperationCanceledException)</div>
|
|
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno"> 78</span> {</div>
|
|
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno"> 79</span> <span class="keywordflow">throw</span>;</div>
|
|
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno"> 80</span> }</div>
|
|
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno"> 81</span> <span class="keywordflow">catch</span> (<a class="code hl_class" href="class_exception.html">Exception</a> ex)</div>
|
|
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno"> 82</span> {</div>
|
|
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno"> 83</span> <a class="code hl_variable" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#a384470b6fd596dcc97a6e39a0dcdbe74">logger</a>.LogDebug(</div>
|
|
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno"> 84</span> ex,</div>
|
|
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno"> 85</span> <span class="stringliteral">"Error loading user for context type {contextType} and principal \"{domainName}\"!"</span>,</div>
|
|
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno"> 86</span> contextType,</div>
|
|
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno"> 87</span> domainName);</div>
|
|
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno"> 88</span> }</div>
|
|
<div class="line"><a id="l00089" name="l00089"></a><span class="lineno"> 89</span> <span class="keywordflow">finally</span></div>
|
|
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno"> 90</span> {</div>
|
|
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno"> 91</span> <span class="keywordflow">if</span> (principal == <span class="keyword">null</span>)</div>
|
|
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno"> 92</span> {</div>
|
|
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno"> 93</span> pc?.Dispose();</div>
|
|
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno"> 94</span> cancellationToken.ThrowIfCancellationRequested();</div>
|
|
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno"> 95</span> }</div>
|
|
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno"> 96</span> }</div>
|
|
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno"> 97</span> </div>
|
|
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno"> 98</span> <span class="keywordflow">return</span> principal != <span class="keyword">null</span>;</div>
|
|
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno"> 99</span> }</div>
|
|
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno"> 100</span> </div>
|
|
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno"> 101</span> <span class="keywordflow">if</span> (!TryGetPrincipalFromContextType(ContextType.Machine, out var principal) && !TryGetPrincipalFromContextType(ContextType.Domain, out principal))</div>
|
|
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno"> 102</span> <span class="keywordflow">return</span> <span class="keyword">null</span>;</div>
|
|
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno"> 103</span> <span class="keywordflow">return</span> (<a class="code hl_interface" href="interface_tgstation_1_1_server_1_1_host_1_1_security_1_1_i_system_identity.html">ISystemIdentity</a>)<span class="keyword">new</span> <a class="code hl_class" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity.html">WindowsSystemIdentity</a>(principal);</div>
|
|
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno"> 104</span> },</div>
|
|
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno"> 105</span> cancellationToken,</div>
|
|
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno"> 106</span> <a class="code hl_class" href="class_tgstation_1_1_server_1_1_host_1_1_i_o_1_1_default_i_o_manager.html">DefaultIOManager</a>.<a class="code hl_variable" href="class_tgstation_1_1_server_1_1_host_1_1_i_o_1_1_default_i_o_manager.html#ac6dfeef4e622bb46047169215099995d">BlockingTaskCreationOptions</a>,</div>
|
|
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno"> 107</span> TaskScheduler.Current);</div>
|
|
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno"> 108</span> </div>
|
|
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno"><a class="line" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#ae5f37bc12ea1e6dfe0d575962ea1846a"> 110</a></span> <span class="keyword">public</span> Task<ISystemIdentity?> <a class="code hl_function" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#ae5f37bc12ea1e6dfe0d575962ea1846a">CreateSystemIdentity</a>(<span class="keywordtype">string</span> username, <span class="keywordtype">string</span> password, CancellationToken cancellationToken) => Task.Factory.StartNew(</div>
|
|
<div class="line"><a id="l00111" name="l00111"></a><span class="lineno"> 111</span> () =></div>
|
|
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno"> 112</span> {</div>
|
|
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno"> 113</span> ArgumentNullException.ThrowIfNull(username);</div>
|
|
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno"> 114</span> ArgumentNullException.ThrowIfNull(password);</div>
|
|
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno"> 115</span> </div>
|
|
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno"> 116</span> var originalUsername = username;</div>
|
|
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno"> 117</span> <a class="code hl_function" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#a4892a64479cbfc5e731be98b229ac114">GetUserAndDomainName</a>(originalUsername, out username, out var domainName);</div>
|
|
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno"> 118</span> </div>
|
|
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno"> 119</span> var res = <a class="code hl_class" href="class_tgstation_1_1_server_1_1_host_1_1_system_1_1_native_methods.html">NativeMethods</a>.<a class="code hl_function" href="class_tgstation_1_1_server_1_1_host_1_1_system_1_1_native_methods.html#a788e0432d2e082ad31ad79bd6918829f">LogonUser</a>(username, domainName, password, 3 <span class="comment">/*LOGON32_LOGON_NETWORK*/</span>, 0 <span class="comment">/*LOGON32_PROVIDER_DEFAULT*/</span>, out var token);</div>
|
|
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno"> 120</span> <span class="keywordflow">if</span> (!res)</div>
|
|
<div class="line"><a id="l00121" name="l00121"></a><span class="lineno"> 121</span> {</div>
|
|
<div class="line"><a id="l00122" name="l00122"></a><span class="lineno"> 122</span> <a class="code hl_variable" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#a384470b6fd596dcc97a6e39a0dcdbe74">logger</a>.LogTrace(<span class="stringliteral">"Invalid system identity/password combo for username {0}!"</span>, originalUsername);</div>
|
|
<div class="line"><a id="l00123" name="l00123"></a><span class="lineno"> 123</span> <span class="keywordflow">return</span> <span class="keyword">null</span>;</div>
|
|
<div class="line"><a id="l00124" name="l00124"></a><span class="lineno"> 124</span> }</div>
|
|
<div class="line"><a id="l00125" name="l00125"></a><span class="lineno"> 125</span> </div>
|
|
<div class="line"><a id="l00126" name="l00126"></a><span class="lineno"> 126</span> <a class="code hl_variable" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#a384470b6fd596dcc97a6e39a0dcdbe74">logger</a>.LogTrace(<span class="stringliteral">"Authenticated username {0} using system identity!"</span>, originalUsername);</div>
|
|
<div class="line"><a id="l00127" name="l00127"></a><span class="lineno"> 127</span> </div>
|
|
<div class="line"><a id="l00128" name="l00128"></a><span class="lineno"> 128</span> <span class="comment">// checked internally, windows identity always duplicates the handle when constructed</span></div>
|
|
<div class="line"><a id="l00129" name="l00129"></a><span class="lineno"> 129</span> <span class="keyword">using </span>var handle = <span class="keyword">new</span> SafeAccessTokenHandle(token);</div>
|
|
<div class="line"><a id="l00130" name="l00130"></a><span class="lineno"> 130</span> <span class="keywordflow">return</span> (<a class="code hl_interface" href="interface_tgstation_1_1_server_1_1_host_1_1_security_1_1_i_system_identity.html">ISystemIdentity</a>)<span class="keyword">new</span> <a class="code hl_class" href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity.html">WindowsSystemIdentity</a>(</div>
|
|
<div class="line"><a id="l00131" name="l00131"></a><span class="lineno"> 131</span> <span class="keyword">new</span> WindowsIdentity(handle.DangerousGetHandle())); <span class="comment">// https://github.com/dotnet/corefx/blob/6ed61acebe3214fcf79b4274f2bb9b55c0604a4d/src/System.Security.Principal.Windows/src/System/Security/Principal/WindowsIdentity.cs#L271</span></div>
|
|
<div class="line"><a id="l00132" name="l00132"></a><span class="lineno"> 132</span> },</div>
|
|
<div class="line"><a id="l00133" name="l00133"></a><span class="lineno"> 133</span> cancellationToken,</div>
|
|
<div class="line"><a id="l00134" name="l00134"></a><span class="lineno"> 134</span> <a class="code hl_class" href="class_tgstation_1_1_server_1_1_host_1_1_i_o_1_1_default_i_o_manager.html">DefaultIOManager</a>.<a class="code hl_variable" href="class_tgstation_1_1_server_1_1_host_1_1_i_o_1_1_default_i_o_manager.html#ac6dfeef4e622bb46047169215099995d">BlockingTaskCreationOptions</a>,</div>
|
|
<div class="line"><a id="l00135" name="l00135"></a><span class="lineno"> 135</span> TaskScheduler.Current);</div>
|
|
<div class="line"><a id="l00136" name="l00136"></a><span class="lineno"> 136</span> }</div>
|
|
</div>
|
|
<div class="line"><a id="l00137" name="l00137"></a><span class="lineno"> 137</span>}</div>
|
|
<div class="ttc" id="aclass_exception_html"><div class="ttname"><a href="class_exception.html">Exception</a></div></div>
|
|
<div class="ttc" id="aclass_tgstation_1_1_server_1_1_host_1_1_i_o_1_1_default_i_o_manager_html"><div class="ttname"><a href="class_tgstation_1_1_server_1_1_host_1_1_i_o_1_1_default_i_o_manager.html">Tgstation.Server.Host.IO.DefaultIOManager</a></div><div class="ttdoc">IIOManager that resolves paths to Environment.CurrentDirectory.</div><div class="ttdef"><b>Definition</b> <a href="_default_i_o_manager_8cs_source.html#l00018">DefaultIOManager.cs:19</a></div></div>
|
|
<div class="ttc" id="aclass_tgstation_1_1_server_1_1_host_1_1_i_o_1_1_default_i_o_manager_html_ac6dfeef4e622bb46047169215099995d"><div class="ttname"><a href="class_tgstation_1_1_server_1_1_host_1_1_i_o_1_1_default_i_o_manager.html#ac6dfeef4e622bb46047169215099995d">Tgstation.Server.Host.IO.DefaultIOManager.BlockingTaskCreationOptions</a></div><div class="ttdeci">const TaskCreationOptions BlockingTaskCreationOptions</div><div class="ttdoc">The TaskCreationOptions used to spawn Tasks for potentially long running, blocking operations.</div><div class="ttdef"><b>Definition</b> <a href="_default_i_o_manager_8cs_source.html#l00033">DefaultIOManager.cs:33</a></div></div>
|
|
<div class="ttc" id="aclass_tgstation_1_1_server_1_1_host_1_1_models_1_1_user_html"><div class="ttname"><a href="class_tgstation_1_1_server_1_1_host_1_1_models_1_1_user.html">Tgstation.Server.Host.Models.User</a></div><div class="ttdef"><b>Definition</b> <a href="_models_2_user_8cs_source.html#l00013">User.cs:17</a></div></div>
|
|
<div class="ttc" id="aclass_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory_html"><div class="ttname"><a href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html">Tgstation.Server.Host.Security.WindowsSystemIdentityFactory</a></div><div class="ttdoc">ISystemIdentityFactory for windows systems. Uses long running tasks due to potential networked domain...</div><div class="ttdef"><b>Definition</b> <a href="_windows_system_identity_factory_8cs_source.html#l00022">WindowsSystemIdentityFactory.cs:23</a></div></div>
|
|
<div class="ttc" id="aclass_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory_html_a384470b6fd596dcc97a6e39a0dcdbe74"><div class="ttname"><a href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#a384470b6fd596dcc97a6e39a0dcdbe74">Tgstation.Server.Host.Security.WindowsSystemIdentityFactory.logger</a></div><div class="ttdeci">readonly ILogger< WindowsSystemIdentityFactory > logger</div><div class="ttdoc">The ILogger for the WindowsSystemIdentityFactory.</div><div class="ttdef"><b>Definition</b> <a href="_windows_system_identity_factory_8cs_source.html#l00027">WindowsSystemIdentityFactory.cs:27</a></div></div>
|
|
<div class="ttc" id="aclass_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory_html_a46f081a94982769acd01d0fdee271b40"><div class="ttname"><a href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#a46f081a94982769acd01d0fdee271b40">Tgstation.Server.Host.Security.WindowsSystemIdentityFactory.WindowsSystemIdentityFactory</a></div><div class="ttdeci">WindowsSystemIdentityFactory(ILogger< WindowsSystemIdentityFactory > logger)</div><div class="ttdoc">Initializes a new instance of the WindowsSystemIdentityFactory class.</div><div class="ttdef"><b>Definition</b> <a href="_windows_system_identity_factory_8cs_source.html#l00046">WindowsSystemIdentityFactory.cs:46</a></div></div>
|
|
<div class="ttc" id="aclass_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory_html_a4892a64479cbfc5e731be98b229ac114"><div class="ttname"><a href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#a4892a64479cbfc5e731be98b229ac114">Tgstation.Server.Host.Security.WindowsSystemIdentityFactory.GetUserAndDomainName</a></div><div class="ttdeci">static void GetUserAndDomainName(string input, out string username, out string? domainName)</div><div class="ttdoc">Extract the username and domain name from a string in the format "username\\domainname".</div><div class="ttdef"><b>Definition</b> <a href="_windows_system_identity_factory_8cs_source.html#l00035">WindowsSystemIdentityFactory.cs:35</a></div></div>
|
|
<div class="ttc" id="aclass_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory_html_aad49a7d5b5c5f6e796587da47e29215e"><div class="ttname"><a href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#aad49a7d5b5c5f6e796587da47e29215e">Tgstation.Server.Host.Security.WindowsSystemIdentityFactory.GetCurrent</a></div><div class="ttdeci">ISystemIdentity GetCurrent()</div><div class="ttdoc">Retrieves a ISystemIdentity representing the user executing tgstation-server.A ISystemIdentity repres...</div></div>
|
|
<div class="ttc" id="aclass_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory_html_add117d69f999105b2d0e9f21b2ef9dd6"><div class="ttname"><a href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#add117d69f999105b2d0e9f21b2ef9dd6">Tgstation.Server.Host.Security.WindowsSystemIdentityFactory.CreateSystemIdentity</a></div><div class="ttdeci">Task< ISystemIdentity?> CreateSystemIdentity(User user, CancellationToken cancellationToken)</div><div class="ttdoc">Create a ISystemIdentity for a given user .A Task<TResult> resulting in a new ISystemIdentity based o...</div></div>
|
|
<div class="ttc" id="aclass_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory_html_ae5f37bc12ea1e6dfe0d575962ea1846a"><div class="ttname"><a href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_factory.html#ae5f37bc12ea1e6dfe0d575962ea1846a">Tgstation.Server.Host.Security.WindowsSystemIdentityFactory.CreateSystemIdentity</a></div><div class="ttdeci">Task< ISystemIdentity?> CreateSystemIdentity(string username, string password, CancellationToken cancellationToken)</div><div class="ttdoc">Create a ISystemIdentity for a given username and password.A Task<TResult> resulting in a new ISystem...</div></div>
|
|
<div class="ttc" id="aclass_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity_html"><div class="ttname"><a href="class_tgstation_1_1_server_1_1_host_1_1_security_1_1_windows_system_identity.html">Tgstation.Server.Host.Security.WindowsSystemIdentity</a></div><div class="ttdoc">ISystemIdentity for windows systems.</div><div class="ttdef"><b>Definition</b> <a href="_windows_system_identity_8cs_source.html#l00016">WindowsSystemIdentity.cs:17</a></div></div>
|
|
<div class="ttc" id="aclass_tgstation_1_1_server_1_1_host_1_1_system_1_1_native_methods_html"><div class="ttname"><a href="class_tgstation_1_1_server_1_1_host_1_1_system_1_1_native_methods.html">Tgstation.Server.Host.System.NativeMethods</a></div><div class="ttdoc">Native methods used by the code.</div><div class="ttdef"><b>Definition</b> <a href="_tgstation_8_server_8_host_2_system_2_native_methods_8cs_source.html#l00013">NativeMethods.cs:14</a></div></div>
|
|
<div class="ttc" id="aclass_tgstation_1_1_server_1_1_host_1_1_system_1_1_native_methods_html_a788e0432d2e082ad31ad79bd6918829f"><div class="ttname"><a href="class_tgstation_1_1_server_1_1_host_1_1_system_1_1_native_methods.html#a788e0432d2e082ad31ad79bd6918829f">Tgstation.Server.Host.System.NativeMethods.LogonUser</a></div><div class="ttdeci">static bool LogonUser(string lpszUsername, string? lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, out IntPtr phToken)</div><div class="ttdoc">See https://msdn.microsoft.com/en-us/library/windows/desktop/aa378184(v=vs.85).aspx.</div></div>
|
|
<div class="ttc" id="ainterface_tgstation_1_1_server_1_1_host_1_1_security_1_1_i_system_identity_factory_html"><div class="ttname"><a href="interface_tgstation_1_1_server_1_1_host_1_1_security_1_1_i_system_identity_factory.html">Tgstation.Server.Host.Security.ISystemIdentityFactory</a></div><div class="ttdoc">Factory for ISystemIdentitys.</div><div class="ttdef"><b>Definition</b> <a href="_i_system_identity_factory_8cs_source.html#l00011">ISystemIdentityFactory.cs:12</a></div></div>
|
|
<div class="ttc" id="ainterface_tgstation_1_1_server_1_1_host_1_1_security_1_1_i_system_identity_html"><div class="ttname"><a href="interface_tgstation_1_1_server_1_1_host_1_1_security_1_1_i_system_identity.html">Tgstation.Server.Host.Security.ISystemIdentity</a></div><div class="ttdoc">Represents a user on the current global::System.Runtime.InteropServices.OSPlatform.</div><div class="ttdef"><b>Definition</b> <a href="_i_system_identity_8cs_source.html#l00010">ISystemIdentity.cs:11</a></div></div>
|
|
<div class="ttc" id="anamespace_tgstation_1_1_server_1_1_host_1_1_i_o_html"><div class="ttname"><a href="namespace_tgstation_1_1_server_1_1_host_1_1_i_o.html">Tgstation.Server.Host.IO</a></div><div class="ttdef"><b>Definition</b> <a href="_buffered_file_stream_provider_8cs_source.html#l00008">BufferedFileStreamProvider.cs:9</a></div></div>
|
|
<div class="ttc" id="anamespace_tgstation_1_1_server_1_1_host_1_1_models_html"><div class="ttname"><a href="namespace_tgstation_1_1_server_1_1_host_1_1_models.html">Tgstation.Server.Host.Models</a></div><div class="ttdef"><b>Definition</b> <a href="_models_2_chat_bot_8cs_source.html#l00008">ChatBot.cs:9</a></div></div>
|
|
<div class="ttc" id="anamespace_tgstation_1_1_server_1_1_host_1_1_security_html"><div class="ttname"><a href="namespace_tgstation_1_1_server_1_1_host_1_1_security.html">Tgstation.Server.Host.Security</a></div><div class="ttdef"><b>Definition</b> <a href="_authentication_context_8cs_source.html#l00007">AuthenticationContext.cs:8</a></div></div>
|
|
<div class="ttc" id="anamespace_tgstation_1_1_server_1_1_host_1_1_system_html"><div class="ttname"><a href="namespace_tgstation_1_1_server_1_1_host_1_1_system.html">Tgstation.Server.Host.System</a></div><div class="ttdef"><b>Definition</b> <a href="_assembly_information_provider_8cs_source.html#l00008">AssemblyInformationProvider.cs:9</a></div></div>
|
|
</div><!-- fragment --></div><!-- contents -->
|
|
<!-- start footer part -->
|
|
<hr class="footer"/><address class="footer"><small>
|
|
Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.8
|
|
</small></address>
|
|
</body>
|
|
</html>
|