Ejemplo n.º 1
0
        /// <summary>
        /// マネージドな資格情報をアンマネージドなポインタに変換する
        /// </summary>
        /// <param name="managedCred"></param>
        /// <returns></returns>
        private static UnmanagedCredential ConvertToUnmanagedCredential(ManagedCredential managedCred)
        {
            var unmanagedCred = new UnmanagedCredential()
            {
                Flags              = (uint)managedCred.Flags,
                Type               = (uint)managedCred.Type,
                TargetName         = managedCred.TargetName,
                Comment            = managedCred.Comment,
                LastWritten        = managedCred.LastWritten,
                CredentialBlobSize = managedCred.CredentialBlob != null ? (uint)managedCred.CredentialBlob.Length : 0,
                Persist            = (uint)managedCred.Persist,
                TargetAlias        = managedCred.TargetAlias,
                UserName           = managedCred.UserName,
                AttributeCount     = managedCred.Attributes != null ? (uint)managedCred.Attributes.Length : 0,
                Attributes         = IntPtr.Zero,
                CredentialBlob     = IntPtr.Zero,
            };


            if (unmanagedCred.AttributeCount != 0)
            {
                Marshal.Copy(managedCred.Attributes.Cast <int>().ToArray(), 0, unmanagedCred.Attributes, managedCred.Attributes.Length);
            }

            if (unmanagedCred.CredentialBlobSize != 0)
            {
                var p = Marshal.AllocHGlobal(managedCred.CredentialBlob.Length);
                Marshal.Copy(managedCred.CredentialBlob, 0, p, managedCred.CredentialBlob.Length);
                unmanagedCred.CredentialBlob = p;
                Marshal.FreeHGlobal(p);
            }

            return(unmanagedCred);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 資格情報の登録
        /// </summary>
        /// <param name="unmanagedCred"></param>
        /// <param name="flags"></param>
        private static void Write(UnmanagedCredential unmanagedCred, CRED_FLAGS flags)
        {
            if (!CredWrite(ref unmanagedCred, flags))
            {
                Log.Instance.LogWrite(LogState.ERROR, GetErrorMessage());
                //throw new ApplicationException("資格情報の書き込みに失敗しました。");
            }

            Console.WriteLine("ok");
        }
Ejemplo n.º 3
0
 private static extern bool CredWrite(ref UnmanagedCredential credential, CRED_FLAGS flags);