Ejemplo n.º 1
0
        public static KeyTabEntries GetKeyTabEntries(string hostname,
                                                string keyTabPath,
                                                UInt32 lastRecordId,
                                                UInt32 recordsPerPage)
        {
            KeyTabEntries keyTabEntries = null;
            IntPtr pKeyTabEntries = IntPtr.Zero;

            try
            {

                LSAMgmtAPI.LWMGMT_LSA_KEYTAB_ENTRIES KeyTabEntries = new LSAMgmtAPI.LWMGMT_LSA_KEYTAB_ENTRIES();

                int ret = (int)LSAMgmtAPI.LWMGMTReadKeyTab(hostname,
                                                           keyTabPath,
                                                           lastRecordId,
                                                           recordsPerPage,
                                                           out pKeyTabEntries);
                if (ret != 0)
                {
                    throw new ApplicationException("Failed to get the key tab entries information");
                }

                Marshal.PtrToStructure(pKeyTabEntries, KeyTabEntries);

                if (KeyTabEntries.dwCount != 0)
                {
                    keyTabEntries = new KeyTabEntries();
                    keyTabEntries.Count = KeyTabEntries.dwCount;

                    IntPtr pCur = KeyTabEntries.pLsaKeyTabEntryArray;

                    for (int index = 0; index < KeyTabEntries.dwCount; index++)
                    {
                        KerberosKeyTabEntry keytabEntry = new KerberosKeyTabEntry();
                        LSAMgmtAPI.LWMGMT_LSA_KEYTAB_ENTRY pKeytabEntry = new LSAMgmtAPI.LWMGMT_LSA_KEYTAB_ENTRY();

                        Marshal.PtrToStructure(pCur, pKeytabEntry);

                        keytabEntry.EncriptionType = pKeytabEntry.enctype;

                        keytabEntry.keyVersionNumber = pKeytabEntry.kvno;

                        keytabEntry.Timestamp = pKeytabEntry.timestamp;

                        if (!IntPtr.Zero.Equals(pKeytabEntry.pszPrincipal))
                        {
                            keytabEntry.PrincipalName = Marshal.PtrToStringAuto(pKeytabEntry.pszPrincipal);
                        }

                        if (!IntPtr.Zero.Equals(pKeytabEntry.pszPassword))
                        {
                            keytabEntry.Password = Marshal.PtrToStringAuto(pKeytabEntry.pszPassword);
                        }

                        keyTabEntries.KeyTabEntriesList.Add(keytabEntry);

                        pCur = (IntPtr)((int)pCur + Marshal.SizeOf(pKeytabEntry));
                    }
                }
            }
            catch (Exception e)
            {
                Logger.ShowUserError(e.Message.ToString());
                keyTabEntries = null;
            }
            finally
            {
                if (!IntPtr.Zero.Equals(pKeyTabEntries))
                {
                    LSAMgmtAPI.LWMGMTFreeKeyTabEntries(pKeyTabEntries);
                }
            }

            return keyTabEntries;
        }
Ejemplo n.º 2
0
        public static KeyTabEntries GetKeyTabEntries(string hostname,
                                                     string keyTabPath,
                                                     UInt32 lastRecordId,
                                                     UInt32 recordsPerPage)
        {
            KeyTabEntries keyTabEntries  = null;
            IntPtr        pKeyTabEntries = IntPtr.Zero;

            try
            {
                LSAMgmtAPI.LWMGMT_LSA_KEYTAB_ENTRIES KeyTabEntries = new LSAMgmtAPI.LWMGMT_LSA_KEYTAB_ENTRIES();

                int ret = (int)LSAMgmtAPI.LWMGMTReadKeyTab(hostname,
                                                           keyTabPath,
                                                           lastRecordId,
                                                           recordsPerPage,
                                                           out pKeyTabEntries);
                if (ret != 0)
                {
                    throw new ApplicationException("Failed to get the key tab entries information");
                }

                Marshal.PtrToStructure(pKeyTabEntries, KeyTabEntries);

                if (KeyTabEntries.dwCount != 0)
                {
                    keyTabEntries       = new KeyTabEntries();
                    keyTabEntries.Count = KeyTabEntries.dwCount;

                    IntPtr pCur = KeyTabEntries.pLsaKeyTabEntryArray;

                    for (int index = 0; index < KeyTabEntries.dwCount; index++)
                    {
                        KerberosKeyTabEntry keytabEntry = new KerberosKeyTabEntry();
                        LSAMgmtAPI.LWMGMT_LSA_KEYTAB_ENTRY pKeytabEntry = new LSAMgmtAPI.LWMGMT_LSA_KEYTAB_ENTRY();

                        Marshal.PtrToStructure(pCur, pKeytabEntry);

                        keytabEntry.EncriptionType = pKeytabEntry.enctype;

                        keytabEntry.keyVersionNumber = pKeytabEntry.kvno;

                        keytabEntry.Timestamp = pKeytabEntry.timestamp;

                        if (!IntPtr.Zero.Equals(pKeytabEntry.pszPrincipal))
                        {
                            keytabEntry.PrincipalName = Marshal.PtrToStringAuto(pKeytabEntry.pszPrincipal);
                        }

                        if (!IntPtr.Zero.Equals(pKeytabEntry.pszPassword))
                        {
                            keytabEntry.Password = Marshal.PtrToStringAuto(pKeytabEntry.pszPassword);
                        }

                        keyTabEntries.KeyTabEntriesList.Add(keytabEntry);

                        pCur = (IntPtr)((int)pCur + Marshal.SizeOf(pKeytabEntry));
                    }
                }
            }
            catch (Exception e)
            {
                Logger.ShowUserError(e.Message.ToString());
                keyTabEntries = null;
            }
            finally
            {
                if (!IntPtr.Zero.Equals(pKeyTabEntries))
                {
                    LSAMgmtAPI.LWMGMTFreeKeyTabEntries(pKeyTabEntries);
                }
            }

            return(keyTabEntries);
        }