示例#1
0
 public static extern uint DsCrackNames(
     SafeDsHandle hSafeDs,
     DS_NAME_FLAGS flags,
     DS_NAME_FORMAT formatOffered,
     DS_NAME_FORMAT formatDesired,
     uint cNames,
     [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPTStr, SizeParamIndex = 4)] string[] rpNames,
     out IntPtr ppResult);
示例#2
0
 public static string[] CrackNames(this DomainController dc, string[] names,
                                   DS_NAME_FORMAT formatDesired = DS_NAME_FORMAT.DS_USER_PRINCIPAL_NAME,
                                   DS_NAME_FORMAT formatOffered = DS_NAME_FORMAT.DS_NT4_ACCOUNT_NAME,
                                   DS_NAME_FLAGS flags          = DS_NAME_FLAGS.DS_NAME_NO_FLAGS)
 {
     lock (dc)
         using (var ds = dc.GetHandle())
             return(DsCrackNames(ds, names, formatDesired, formatOffered, flags).Select(r => r.pName).ToArray());
 }
示例#3
0
 internal static extern DWORD DsCrackNames(
     HANDLE hDS,
     DS_NAME_FLAGS flags,
     DS_NAME_FORMAT formatOffered,
     DS_NAME_FORMAT formatDesired,
     DWORD cNames,
     LPCTSTR[] rpNames,
     out IntPtr ppResult             //pointer to pointer of DS_NAME_RESULT
     );
 static public extern uint DsCrackNames(
     IntPtr hDS,
     DS_NAME_FLAGS flags,
     DS_NAME_FORMAT formatOffered,
     DS_NAME_FORMAT formatDesired,
     uint cNames,
     string[] rpNames,
     out IntPtr ppResult    // PDS_NAME_RESULT
     );
示例#5
0
        public static DS_NAME_RESULT_ITEM[] DsCrackNames(SafeDsHandle hSafeDs, string[] names,
                                                         DS_NAME_FORMAT formatDesired = DS_NAME_FORMAT.DS_USER_PRINCIPAL_NAME,
                                                         DS_NAME_FORMAT formatOffered = DS_NAME_FORMAT.DS_UNKNOWN_NAME,
                                                         DS_NAME_FLAGS flags          = DS_NAME_FLAGS.DS_NAME_NO_FLAGS)
        {
            var err = DsCrackNames(hSafeDs, flags, formatOffered, formatDesired, (uint)(names?.Length ?? 0), names, out SafeDsNameResult pResult);

            new Win32Error((int)err).ThrowIfFailed();
            return(pResult.Items);
        }
示例#6
0
            /// <summary>
            /// Converts an array of directory service object names from one format to another. Name conversion enables client applications to map between the multiple names used to identify various directory service objects.
            /// </summary>
            /// <param name="names">The names to convert.</param>
            /// <param name="flags">Values used to determine how the name syntax will be cracked.</param>
            /// <param name="formatOffered">Format of the input names.</param>
            /// <param name="formatDesired">Desired format for the output names.</param>
            /// <returns>An array of DS_NAME_RESULT_ITEM structures. Each element of this array represents a single converted name.</returns>
            public DS_NAME_RESULT_ITEM[] CrackNames(string[] names = null, DS_NAME_FLAGS flags = DS_NAME_FLAGS.DS_NAME_NO_FLAGS, DS_NAME_FORMAT formatOffered = DS_NAME_FORMAT.DS_UNKNOWN_NAME, DS_NAME_FORMAT formatDesired = DS_NAME_FORMAT.DS_USER_PRINCIPAL_NAME)
            {
                IntPtr pResult;
                uint   err = DsCrackNames(handle, flags, formatOffered, formatDesired, (uint)(names?.Length ?? 0), names, out pResult);

                if (err != (uint)DS_NAME_ERROR.DS_NAME_NO_ERROR)
                {
                    throw new System.ComponentModel.Win32Exception((int)err);
                }
                try
                {
                    // Next convert the returned structure to managed environment
                    DS_NAME_RESULT Result = (DS_NAME_RESULT)Marshal.PtrToStructure(pResult, typeof(DS_NAME_RESULT));
                    return(Result.Items);
                }
                finally
                {
                    DsFreeNameResult(pResult);
                }
            }
示例#7
0
        /// <summary>A wrapper function for the DsCrackNames OS call</summary>
        /// <param name="hSafeDs">
        /// Contains a directory service handle obtained from either the DSBind or DSBindWithCred function. If flags contains DS_NAME_FLAG_SYNTACTICAL_ONLY, hDS
        /// can be NULL.
        /// </param>
        /// <param name="names">The names to be converted.</param>
        /// <param name="flags">Contains one or m
        /// ore of the DS_NAME_FLAGS values used to determine how the name syntax will be cracked.</param>
        /// <param name="formatOffered">Contains one of the DS_NAME_FORMAT values that identifies the format of the input names.</param>
        /// <param name="formatDesired">
        /// Contains one of the DS_NAME_FORMAT values that identifies the format of the output names. The DS_SID_OR_SID_HISTORY_NAME value is not supported.
        /// </param>
        /// <returns>The crack results.</returns>
        public static IEnumerable <DS_NAME_RESULT_ITEM> DsCrackNames(SafeDsHandle hSafeDs, string[] names = null,
                                                                     DS_NAME_FLAGS flags          = DS_NAME_FLAGS.DS_NAME_NO_FLAGS,
                                                                     DS_NAME_FORMAT formatOffered = DS_NAME_FORMAT.DS_NT4_ACCOUNT_NAME,
                                                                     DS_NAME_FORMAT formatDesired = DS_NAME_FORMAT.DS_USER_PRINCIPAL_NAME)
        {
            IntPtr pResult;
            var    err = DsCrackNames(hSafeDs, flags, formatOffered, formatDesired, (uint)(names?.Length ?? 0), names, out pResult);

            if (err != NO_ERROR)
            {
                throw new Win32Exception((int)err);
            }
            try
            {
                return(pResult.ToStructure <DS_NAME_RESULT>().Items);
            }
            finally
            {
                DsFreeNameResult(pResult);
            }
        }
    /// <summary>
    /// A wrapper function for the DsCrackNames OS call
    /// </summary>
    /// <param name="hDS">DsBind handle</param>
    /// <param name="flags">Flags controlling the process</param>
    /// <param name="formatOffered">Format of the names</param>
    /// <param name="formatDesired">Desired format for the names</param>
    /// <param name="names">The names to crack</param>
    /// <returns>The crack result</returns>
    public static DS_NAME_RESULT_ITEM[] HandleDsCrackNames(IntPtr hDS, DS_NAME_FLAGS flags, DS_NAME_FORMAT formatOffered, DS_NAME_FORMAT formatDesired, string[] names)
    {
        IntPtr pResult;

        DS_NAME_RESULT_ITEM[] ResultArray;
        uint err = DsCrackNames(
            hDS,
            flags,
            formatOffered,
            formatDesired,
            (uint)((names == null) ? 0 : names.Length),
            names,
            out pResult);

        if (err != NO_ERROR)
        {
            throw new System.ComponentModel.Win32Exception((int)err);
        }
        try
        {
            // Next convert the returned structure to managed environment
            DS_NAME_RESULT Result = new DS_NAME_RESULT();
            Result.cItems = (uint)Marshal.ReadInt32(pResult);
            Result.rItems = Marshal.ReadIntPtr(pResult, Marshal.OffsetOf(typeof(DS_NAME_RESULT), "rItems").ToInt32());
            IntPtr curptr = Result.rItems;
            ResultArray = new DS_NAME_RESULT_ITEM[Result.cItems];
            for (int index = 0; index < (int)Result.cItems; index++)
            {
                ResultArray[index] = (DS_NAME_RESULT_ITEM)Marshal.PtrToStructure(curptr, typeof(DS_NAME_RESULT_ITEM));
                curptr             = (IntPtr)((int)curptr + Marshal.SizeOf(ResultArray[index]));
            }
        }
        finally
        {
            DsFreeNameResult(pResult);
        }
        return(ResultArray);
    }
 public static extern unsafe uint DsCrackNamesA(void *hDS, DS_NAME_FLAGS flags, DS_NAME_FORMAT formatOffered, DS_NAME_FORMAT formatDesired, uint cNames, sbyte **rpNames, DS_NAME_RESULTA **ppResult);