<i id='K2fnW'><tr id='K2fnW'><dt id='K2fnW'><q id='K2fnW'><span id='K2fnW'><b id='K2fnW'><form id='K2fnW'><ins id='K2fnW'></ins><ul id='K2fnW'></ul><sub id='K2fnW'></sub></form><legend id='K2fnW'></legend><bdo id='K2fnW'><pre id='K2fnW'><center id='K2fnW'></center></pre></bdo></b><th id='K2fnW'></th></span></q></dt></tr></i><div id='K2fnW'><tfoot id='K2fnW'></tfoot><dl id='K2fnW'><fieldset id='K2fnW'></fieldset></dl></div>
  • <small id='K2fnW'></small><noframes id='K2fnW'>

        <bdo id='K2fnW'></bdo><ul id='K2fnW'></ul>

        <legend id='K2fnW'><style id='K2fnW'><dir id='K2fnW'><q id='K2fnW'></q></dir></style></legend>

        <tfoot id='K2fnW'></tfoot>
      1. Python ldap3 代码从 SID 获取用户名

        Python ldap3 code to get username from SID(Python ldap3 代码从 SID 获取用户名)
          • <bdo id='i3Iwi'></bdo><ul id='i3Iwi'></ul>

            <small id='i3Iwi'></small><noframes id='i3Iwi'>

                <tbody id='i3Iwi'></tbody>
                <tfoot id='i3Iwi'></tfoot>
                <i id='i3Iwi'><tr id='i3Iwi'><dt id='i3Iwi'><q id='i3Iwi'><span id='i3Iwi'><b id='i3Iwi'><form id='i3Iwi'><ins id='i3Iwi'></ins><ul id='i3Iwi'></ul><sub id='i3Iwi'></sub></form><legend id='i3Iwi'></legend><bdo id='i3Iwi'><pre id='i3Iwi'><center id='i3Iwi'></center></pre></bdo></b><th id='i3Iwi'></th></span></q></dt></tr></i><div id='i3Iwi'><tfoot id='i3Iwi'></tfoot><dl id='i3Iwi'><fieldset id='i3Iwi'></fieldset></dl></div>

                <legend id='i3Iwi'><style id='i3Iwi'><dir id='i3Iwi'><q id='i3Iwi'></q></dir></style></legend>
                  本文介绍了Python ldap3 代码从 SID 获取用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个共享 Windows 服务器上用户的 SID 字符串(例如,S-1-5-21-500000003-1000000000-1000000003-1001"),我需要获取相关的用户名.

                  I have a SID string (e.g., "S-1-5-21-500000003-1000000000-1000000003-1001") of a user on a shared Windows server, and I need to get the related username.

                  我想这可以通过以下方式实现:

                  I suppose that this may be achieved by:

                  1. 将 SID 字符串转换为字节数组.
                  2. 使用合适的 ldpa 查询来获取相关的用户名.
                  1. Turning the SID string into byte array.
                  2. Using a suitable ldpa query to get the related username.

                  但我没有找到准确可靠的操作说明(以这种或另一种方式).

                  But I failed to find exact and reliable instructions of how to do it (this way or another).

                  我会很感激任何有用的指南,特别是如果它附带演示 Python (ldap3) 代码.

                  I'll appreciate any useful guide, especially if it comes with demo Python (ldap3) code.

                  推荐答案

                  def unsigned_number_to_slashed_byte_array_string(number, little_endian, digits_count):
                          """
                          Convert given unsigned number into a string that represents it as a sequence of bytes in given order (either little or big Endian).
                          In case the total number of digits in the string is greater than given digits count, the string is left-padded with zeroes.
                          Each such byte is represented by a substring that's composed of a preceding slash character followed by two (uppercase) hexadecimal digits (e.g., "\0A").
                          :param number: An unsigned non-negative integer.
                          :param little_endian: A flag that says whether little Endian order is requested; otherwise, big Endian order is selected.
                          :param digits_count: The total count of hexadecimal digits in the resulting possibly left-padded string, which is twice the number of bytes.
                          :except ValueError: In case given number isn't a non-negative number, or given digits count isn't a positive even number.
                          :return: A string that represents given number as a sequence of bytes in given order.
                          """
                          if number < 0: raise ValueError("{0}: Argument number must be a non-negative! ({1})".format(func_name(), number))
                          if (digits_count <= 0) or ((digits_count % 2) != 0): raise ValueError("{0}: Argument digits_count must be an even positive! ({1})".format(func_name(), digits_count))
                  
                          zero_padded_hex_number_str = "{0:0{1}X}".format(number, digits_count) # Format: no leading "0x", zero-padded digits_count digits (or half digits_count bytes), uppercase hexadecimal letters.
                          number_byte_array_str = ""
                          byte_starter_digits_indices_list = range(len(zero_padded_hex_number_str))[::2]
                          if little_endian: byte_starter_digits_indices_list = reversed(byte_starter_digits_indices_list)
                          for byte_starter_digit_index in byte_starter_digits_indices_list:
                              number_byte_array_str = "{0}\{1}".format(number_byte_array_str, zero_padded_hex_number_str[byte_starter_digit_index:(byte_starter_digit_index + 2)])
                          return number_byte_array_str
                  
                  
                  def sid_str_to_byte_array_str(sid_str):
                      """
                      :param sid_str: An active-directory SID string (e.g., "S-1-5-21-1241979920-1440912824-1533017923-1106").
                      :return: A string that represents given SID string as a byte array string (e.g., "\01\05\00\00\00\00\00\05\15\00\00\00\10\1C\07\4A\B8\95\E2\55\43\FF\5F\5B").
                      """
                      dashes_count = sid_str.count("-")
                      sid_numbers_str = sid_str[2:] # Removes the preceding "S-"
                      sid_number_strings = sid_numbers_str.split("-")
                      sid_numbers = [int(sid_number_string) for sid_number_string in sid_number_strings]
                      sid_byte_array_str  = unsigned_number_to_slashed_byte_array_string(sid_numbers[0],       True,   2)
                      sid_byte_array_str += unsigned_number_to_slashed_byte_array_string((dashes_count - 2),   True,   2)
                      sid_byte_array_str += unsigned_number_to_slashed_byte_array_string(sid_numbers[1],       False, 12)
                      sid_byte_array_str += unsigned_number_to_slashed_byte_array_string(sid_numbers[2],       True,   8)
                      sid_byte_array_str += unsigned_number_to_slashed_byte_array_string(sid_numbers[3],       True,   8)
                      sid_byte_array_str += unsigned_number_to_slashed_byte_array_string(sid_numbers[4],       True,   8)
                      sid_byte_array_str += unsigned_number_to_slashed_byte_array_string(sid_numbers[5],       True,   8)
                      return sid_byte_array_str
                  

                  这篇关于Python ldap3 代码从 SID 获取用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pythonic and efficient way of finding adjacent cells in grid(在网格中查找相邻单元格的 Pythonic 和有效方法)
                  map a hexagonal grid in matplotlib(在 matplotlib 中映射六边形网格)
                  Execute arbitrary python code remotely - can it be done?(远程执行任意 python 代码 - 可以吗?)
                  Python - Plotting colored grid based on values(Python - 根据值绘制彩色网格)
                  Is there a GUI design app for the Tkinter / grid geometry?(是否有 Tkinter/网格几何图形的 GUI 设计应用程序?)
                  tkinter Canvas Scrollbar with Grid?(带有网格的 tkinter 画布滚动条?)
                  <legend id='APpMO'><style id='APpMO'><dir id='APpMO'><q id='APpMO'></q></dir></style></legend>

                  <tfoot id='APpMO'></tfoot>

                  1. <i id='APpMO'><tr id='APpMO'><dt id='APpMO'><q id='APpMO'><span id='APpMO'><b id='APpMO'><form id='APpMO'><ins id='APpMO'></ins><ul id='APpMO'></ul><sub id='APpMO'></sub></form><legend id='APpMO'></legend><bdo id='APpMO'><pre id='APpMO'><center id='APpMO'></center></pre></bdo></b><th id='APpMO'></th></span></q></dt></tr></i><div id='APpMO'><tfoot id='APpMO'></tfoot><dl id='APpMO'><fieldset id='APpMO'></fieldset></dl></div>

                    <small id='APpMO'></small><noframes id='APpMO'>

                          <tbody id='APpMO'></tbody>
                        • <bdo id='APpMO'></bdo><ul id='APpMO'></ul>