SDDL 格式的 SID 的最大长度是多少

发布于 2024-07-27 03:56:37 字数 152 浏览 2 评论 0原文

我正在将 Active Directory 身份验证构建到我的应用程序中,并计划将我的应用程序的内部帐户链接到用户的域 SID。 对我来说,使用 sid 的字符串格式比使用字节数组更容易,因此我计划将其作为字符串存储在数据库中。 我应该将该字段设置多长时间才能确保 SID 不会被截断?

I'm building Active Directory Authentication into my application and I am planning to link my application's internal accounts to a user's domain SID. It is easier for me to work with the string format of the sid than a byte array so I was planning to store it in the database as a string. How long should I make the field to ensure SID's will not get truncated?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

星光不落少年眉 2024-08-03 03:56:37

我有同样的问题,我相信正确的答案是:

  • ID 作为字符串:184 个字符,或 SQL Server
  • SID 中的 varchar(184) 作为十六进制数字字符串:136 个字符,或 SQL Server SID 中的 varchar(136)
  • 作为二进制:68 字节,或 SQL Server 中的 varbinary(68)

我自己没有检查过数学,但这里使用的技术看起来是有效的:
https://groups.google.com/d/msg /microsoft.public.dotnet.security/NpIi7c2Toi8/31SVhcepY58J

参考Russell Mangel于2006年8月19日编写的程序,也复制在此供参考:

所以我的问题的答案是:

varbinary(68)——纯二进制
varchar(136) -- (68*2) = 十六进制字符串
varchar(184) -- SID 字符串

我写了一个小程序来测试,
请注意 .NET 2.0 有
安全标识符.MaxBinaryLength,I
不知道这个。

Console.WriteLine("SID 最小字节数:{0}", 
  SecurityIdentifier.MinBinaryLength); 
  Console.WriteLine("SID 最大字节数:{0}", 
  SecurityIdentifier.MaxBinaryLength); 
  Byte[] 字节 = 新字节[SecurityIdentifier.MaxBinaryLength]; 
  for (Int32 i = 0; i < bytes.Length; i++) 
  { 
      字节[i] = 0xFF; 
  } 
  字节[0] = 0x01;   // 必须为 1 
  字节[1] = 0x0F;   // 最大 15 (base10) 
  SecurityIdentifier sid = new SecurityIdentifier(字节, 0); 
  字符串 sidString = sid.ToString(); 
  Console.WriteLine("字符串格式的SID最大长度: {0} ", sidString.Length); 
  Console.WriteLine(sidString); 
  

结果

SID 最小值  字节数:8 
  SID 最大  字节数:68 
  字符串格式的 SID 最大长度:184 
  S-1-281474976710655-4294967295-4294967295-4294967295-4294967295-4294967295- 
    4294967295-4294967295-4294967295-4294967295-4294967295-4294967295- 
    4294967295-4294967295-4294967295-4294967295  
  

I had the same question, and I believe the right answer is:

  • ID as string: 184 characters, or varchar(184) in SQL Server
  • SID as string of Hex digits: 136 characters, or varchar(136) in SQL Server
  • SID as binary: 68 bytes, or varbinary(68) in SQL Server

I haven't checked the math myself, but the technique used here looks valid:
https://groups.google.com/d/msg/microsoft.public.dotnet.security/NpIi7c2Toi8/31SVhcepY58J

Refer to the program written by Russell Mangel on Aug 19, 2006, also copied here for reference:

So the answer to my question is:

varbinary(68)-- pure binary
varchar(136) -- (68*2) = hexString
varchar(184) -- SID String

I wrote a little program to test,
notice that .NET 2.0 has
SecurityIdentifier.MaxBinaryLength, I
didn't know about this.

Console.WriteLine("SID Min. num Bytes: {0}",
SecurityIdentifier.MinBinaryLength);
Console.WriteLine("SID Max. num Bytes: {0}",
SecurityIdentifier.MaxBinaryLength);
Byte[] bytes = new byte[SecurityIdentifier.MaxBinaryLength];
for (Int32 i = 0; i < bytes.Length; i++)
{
    bytes[i] = 0xFF;
}
bytes[0] = 0x01; // Must be 1
bytes[1] = 0x0F; // Max 15 (base10)
SecurityIdentifier sid = new SecurityIdentifier(bytes, 0);
String sidString = sid.ToString();
Console.WriteLine("Max length of SID in String format: {0} ", sidString.Length);
Console.WriteLine(sidString);

Results

SID Min. num Bytes: 8
SID Max. num Bytes: 68
Max length of SID in String format: 184
S-1-281474976710655-4294967295-4294967295-4294967295-4294967295-4294967295-
  4294967295-4294967295-4294967295-4294967295-4294967295-4294967295-
  4294967295-4294967295-4294967295-4294967295 
泪之魂 2024-08-03 03:56:37

根据 ntseapi_x.h:

typedef struct _SID_IDENTIFIER_AUTHORITY {
    UCHAR Value[6];
} SID_IDENTIFIER_AUTHORITY, *PSID_IDENTIFIER_AUTHORITY; 

typedef struct _SID {
   UCHAR Revision;
   UCHAR SubAuthorityCount;
   SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
   ULONG SubAuthority[ANYSIZE_ARRAY];
} SID, *PISID;
    
#define SID_MAX_SUB_AUTHORITIES          (15)

UCHAR 实际上是一个 unsigned char,它是 1 个字节。 ULONG 是一个 unsigned long,大小为 4 个字节。

SID 的最大数据大小为 68 字节: UCHAR + UCHAR + (UCHAR * 6) + (ULONG * 15) = 1 + 1 + 6 + 60 = 68

将 SID 转换为字符串,就像您一样将通过调用 ConvertSidToStringSid 获得,可能看起来像这样: L"S-1-5-21-66"

  • "S-1" <= 是所有 SID 的开头
    • 3 个字符
  • “5”<=是标识符权限
    • 数字通常以小数形式打印。 一个例外是,如果权限大于 4 个字节,则将其打印为十六进制,例如。 0x1234...
    • 因此最大值将为“4294967296”或“0xffffffffffff”或 14 个字符
  • “21”& "66" <= 是子权限
    • 每个权限最多为“4294967296”或 10 个字符,最多有 15 个子权限
  • 各个部分由“-”分隔

SID 的最大字符串长度为 184: 3 + 1 + 14 + 1 + (10 * 15) + 14 = 183,或 184 计算空值。

您可以考虑仅使用 MAX_UNICODE_STACK_BUFFER_LENGTH 或 256,它们非常适合内存。

According to ntseapi_x.h:

typedef struct _SID_IDENTIFIER_AUTHORITY {
    UCHAR Value[6];
} SID_IDENTIFIER_AUTHORITY, *PSID_IDENTIFIER_AUTHORITY; 

typedef struct _SID {
   UCHAR Revision;
   UCHAR SubAuthorityCount;
   SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
   ULONG SubAuthority[ANYSIZE_ARRAY];
} SID, *PISID;
    
#define SID_MAX_SUB_AUTHORITIES          (15)

A UCHAR is actually an unsigned char which is 1 byte. ULONG is an unsigned long which is 4 bytes.

SID's max data size is 68 bytes: UCHAR + UCHAR + (UCHAR * 6) + (ULONG * 15) = 1 + 1 + 6 + 60 = 68

Converting a SID to a string, like what you would get by calling ConvertSidToStringSid, might look something like this: L"S-1-5-21-66"

  • "S-1" <= is the start of all SIDs
    • 3 characters
  • "5" <= is the identifier authority
    • the numbers are printed as decimals normally. One exception is if the authority is larger 4 bytes, then it is printed as hex, eg. 0x1234...
    • So the max value would be "4294967296" or "0xffffffffffff" or 14 characters
  • "21" & "66" <= are sub-authrities
    • Each can be up "4294967296" or 10 characters, with 15 max sub authorities
  • the sections are delimited by a "-"

SID's max string length is 184: 3 + 1 + 14 + 1 + (10 * 15) + 14 = 183, or 184 counting the null.

You may consider just using MAX_UNICODE_STACK_BUFFER_LENGTH or 256 which fits nicely in memory.

ぽ尐不点ル 2024-08-03 03:56:37
  1. 对于字符串格式,常见的答案 184 是不正确的。 如果权限在 32 到最大 48 位之间,则必须将其表示为十六进制字符串,而不是十进制,并在前面添加“0x”。 这意味着您实际上需要 (48 位/4 位 + 2) 14 个字符的字符串,而不是表示十进制最大 48 位所需的 15 个字符的字符串,这意味着整个需要 (184 - 15 + 14) 183 个字符SID 字符串。 对于小于 32 位,使用十进制格式(最多 10 个十进制字符)。
  1. For string format, the common answer of 184 isn't correct. If authority is between 32 and the maximum of 48 bits, then it must be represented as a hex string, not decimal, and prepended with '0x'. This means instead of a 15-character string needed to represent the maximum 48 bits in decimal, you actually need a (48 bit / 4 bit + 2) 14 character string, meaning (184 - 15 + 14) 183 characters are required for whole SID string. For less than 32 bits, decimal format is used (maximum 10 decimal characters).
沙与沫 2024-08-03 03:56:37

虽然 184 看起来是正确的,但在官方文档中有一个不同的值:

SID - 指定域帐户的安全标识符。 SID 是一个最大长度为 256 个字符的字符串。

https://learn.microsoft.com/en-us/windows-hardware/customize/桌面/无人参与/microsoft-windows-shell-setup-offlineuseraccounts-offlinedomainaccounts-offlinedomainaccount-sid#:~:text=SID%20is%20a%20string%20with%20a%20maximum%20length%20of%20256%20characters

While 184 looks correct, on the official docs there is a different value:

SID - Specifies the security identifier of the domain account. SID is a string with a maximum length of 256 characters.

https://learn.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-shell-setup-offlineuseraccounts-offlinedomainaccounts-offlinedomainaccount-sid#:~:text=SID%20is%20a%20string%20with%20a%20maximum%20length%20of%20256%20characters.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文