当前位置: 首页>>代码示例>>C#>>正文


C# SecurityIdentifier.ToString方法代码示例

本文整理汇总了C#中System.Security.Principal.SecurityIdentifier.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# SecurityIdentifier.ToString方法的具体用法?C# SecurityIdentifier.ToString怎么用?C# SecurityIdentifier.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Principal.SecurityIdentifier的用法示例。


在下文中一共展示了SecurityIdentifier.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetProfileDir

        public static string GetProfileDir(SecurityIdentifier sid)
        {
            //"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-21-534125731-1308685933-1530606844-1000}"
            using (RegistryKey key = Registry.LocalMachine.OpenSubKey(ROOT_PROFILE_KEY))
            {
                if (key != null)
                {
                    foreach (string keyName in key.GetSubKeyNames())
                    {
                        if (keyName == sid.ToString())
                        {
                            using(RegistryKey subKey = Registry.LocalMachine.OpenSubKey(string.Format("{0}\\{1}", ROOT_PROFILE_KEY, keyName)))
                            {
                                return (string) subKey.GetValue("ProfileImagePath", null, RegistryValueOptions.None);
                            }
                        }
                    }

                    throw new KeyNotFoundException(string.Format("Unable to find value for: {0}", sid));
                }
                else
                {
                    throw new KeyNotFoundException(string.Format("Unable to open registry key"));
                }
            }
        }
开发者ID:woltere,项目名称:toopher-rdp,代码行数:26,代码来源:User.cs

示例2: CertificateUserCredential

        /// <summary>
        /// Creates user credentials
        /// </summary>
        /// <param name="username"></param>
        public CertificateUserCredential(string username)
        {
#if SQLCLR
            SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
            UserID = sid.ToString();
#else
            UserID = UserInfo.UserNameToSID(username);
#endif
        }
开发者ID:GridProtectionAlliance,项目名称:openHistorian,代码行数:13,代码来源:CertificateUserCredential.cs

示例3: IntegratedSecurityUserCredential

        /// <summary>
        /// Creates user credentials
        /// </summary>
        /// <param name="username"></param>
        /// <param name="userToken"></param>
        public IntegratedSecurityUserCredential(string username, Guid userToken)
        {
            Username = username;
#if SQLCLR
            SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
            UserID = sid.ToString();
#else
            UserID = UserInfo.UserNameToSID(username);
#endif
            UserToken = userToken;
        }
开发者ID:GridProtectionAlliance,项目名称:openHistorian,代码行数:16,代码来源:IntegratedSecurityUserCredential.cs

示例4: GetUserSre

        /// <summary>
        /// Find a user by SID and return a <see cref="SamRidEnumeration"/> object
        /// representing the user.
        /// </summary>
        /// <param name="sid">A <see cref="SecurityIdentifier"/> object identifying
        /// the user to search for.</param>
        /// <returns>
        /// A SamRidEnumeration object representing the user.
        /// </returns>
        /// <exception cref="UserNotFoundException">
        /// Thrown when the specified user is not found.
        /// </exception>
        /// <remarks>
        /// This method saves some time and effort over the GetUser method
        /// because it does not have to open a user to populate a full LocalUser
        /// object.
        /// </remarks>
        private SamRidEnumeration GetUserSre(SecurityIdentifier sid)
        {
            foreach (var sre in EnumerateUsers())
                if (RidToSid(sre.domainHandle, sre.RelativeId) == sid)
                    return sre;

            throw new UserNotFoundException(sid.ToString(), sid);
        }
开发者ID:40a,项目名称:PowerShell,代码行数:25,代码来源:Sam.cs

示例5: EnableLocalUser

        /// <summary>
        /// Enable or disable a Local User
        /// </summary>
        /// <param name="sid">
        /// A <see cref="SecurityIdentifier"/> object identifying the user to enable or disable.
        /// </param>
        /// <param name="enable">
        /// One of the <see cref="Enabling"/> enumeration values, indicating whether to
        /// enable or disable the user.
        /// </param>
        internal void EnableLocalUser(SecurityIdentifier sid, Enabling enable)
        {
            context = new Context(enable == Enabling.Enable ? ContextOperation.Enable
                                                            : ContextOperation.Disable,
                                  ContextObjectType.User, sid.ToString(),
                                  sid);

            EnableUser(sid, enable);
        }
开发者ID:40a,项目名称:PowerShell,代码行数:19,代码来源:Sam.cs

示例6: GetProfileDir

        /// <summary>
        /// returns profiledir based on regkey
        /// </summary>
        /// <param name="sid"></param>
        /// <returns></returns>
        public static List<string> GetProfileDir(SecurityIdentifier sid)
        {
            List<string> ret = new List<string>();

            //"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-21-534125731-1308685933-1530606844-1000}"
            using (RegistryKey key = Registry.LocalMachine.OpenSubKey(ROOT_PROFILE_KEY))
            {
                if (key != null)
                {
                    foreach (string keyName in key.GetSubKeyNames())
                    {
                        if (keyName.Contains(sid.ToString())) //get the %SID% and %SID%.bak key
                        {
                            using(RegistryKey subKey = Registry.LocalMachine.OpenSubKey(string.Format("{0}\\{1}", ROOT_PROFILE_KEY, keyName)))
                            {
                                LibraryLogging.Info("ProfileList key found {0}", keyName);
                                ret.Add(subKey.GetValue("ProfileImagePath", "", RegistryValueOptions.None).ToString());
                            }
                        }
                    }
                }
                else
                {
                    LibraryLogging.Info("GetProfileDir key {0} not found", ROOT_PROFILE_KEY);
                }
            }

            return ret;
        }
开发者ID:MutonUfoAI,项目名称:pgina,代码行数:34,代码来源:User.cs

示例7: GetobjectSid

        public static string GetobjectSid(SearchResultAttributeCollection attributes)
        {
            object[] obj = null;
            try
            {
                obj = attributes["objectSid"].GetValues(Type.GetType("System.Byte[]"));
            }
            catch
            {
                //unable to get objectSid attribute, value unset
                return null;
            }
            if (obj.Length > 1)
            {
                throw new Exception("objectSid has more than one entry.");
            }

            SecurityIdentifier objectSid = new SecurityIdentifier((byte[])obj[0], 0);
            return objectSid.ToString();
        }
开发者ID:yazeng,项目名称:WindowsProtocolTestSuites,代码行数:20,代码来源:PacHelper.cs

示例8: Main

        static void Main(string[] args)
        {
            // domainSid: WindowsIdentity.GetCurrent().User.AccountDomainSid);
            if (args.Length > 0)
            {
                if (args[0].StartsWith("-?") ||
                    args[0].StartsWith("-h") ||
                    args[0].StartsWith("-help") ||
                    args[0].StartsWith("/?") ||
                    args[0].StartsWith("/h") ||
                    args[0].StartsWith("/help"))
                {
                    ShowHelp();
                }
                else if (Enum.IsDefined(typeof(WellKnownSidType), args[0]))
                {
                    try
                    {
                        WellKnownSidType sidType = (WellKnownSidType)Enum.Parse(typeof(WellKnownSidType), args[0], false);

                        SecurityIdentifier sid = null;
                        if (args[0].StartsWith("Account"))
                        {
                            sid = new SecurityIdentifier(sidType, WindowsIdentity.GetCurrent().User.AccountDomainSid);
                        }
                        else
                        {
                            sid = new SecurityIdentifier(sidType, null);
                        }

                        NTAccount NTUser = (NTAccount)sid.Translate(typeof(System.Security.Principal.NTAccount));
                        Console.WriteLine("[" + sidType.ToString() + "]");
                        Console.WriteLine("Name=" + NTUser.ToString());
                        Console.WriteLine("Shortname=" + NTUser.ToString().Substring(NTUser.ToString().IndexOf("\\")+1));
                        Console.WriteLine("SID=" + sid.ToString());
                        Console.WriteLine("IsAccountSid=" + sid.IsAccountSid().ToString().ToUpper());

                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else
                {
                    if (args[0].StartsWith("S-"))
                    {
                        try
                        {
                            SecurityIdentifier sid = new SecurityIdentifier(args[0]);
                            NTAccount NTUser = (NTAccount)sid.Translate(typeof(System.Security.Principal.NTAccount));

                            Console.WriteLine("[" + sid.ToString() + "]");
                            Console.WriteLine("Name=" + NTUser.ToString());
                            Console.WriteLine("Shortname=" + NTUser.ToString().Substring(NTUser.ToString().IndexOf("\\") + 1));
                            Console.WriteLine("SID=" + sid.ToString());
                            Console.WriteLine("IsAccountSid=" + sid.IsAccountSid().ToString().ToUpper());
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                    else
                    {
                        try
                        {
                            NTAccount NTUser = new NTAccount(args[0]);
                            SecurityIdentifier sid = (SecurityIdentifier)NTUser.Translate(typeof(SecurityIdentifier));

                            Console.WriteLine("[" + NTUser.ToString() + "]");
                            Console.WriteLine("Name=" + NTUser.ToString());
                            Console.WriteLine("Shortname=" + NTUser.ToString().Substring(NTUser.ToString().IndexOf("\\") + 1));
                            Console.WriteLine("SID=" + sid.ToString());
                            Console.WriteLine("IsAccountSid=" + sid.IsAccountSid().ToString().ToUpper());
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }
            }
            else
            {
                ShowHelp();
            }
        }
开发者ID:andif888,项目名称:SidToUser,代码行数:88,代码来源:Program.cs

示例9: HandleContextHashValue

        //
        // HandleContextHashValue helper for hashtable structured query builder.
        // Constructs and returns UserID XPath portion as a string.
        // Handles both SIDs and domain account names.
        // Writes an error and returns an empty string if the SID or account names are not valid.
        //
        private string HandleContextHashValue(Object value)
        {
            SecurityIdentifier sidCandidate = null;
            try
            {
                sidCandidate = new SecurityIdentifier(value.ToString());
            }
            catch (ArgumentException)
            {
                WriteDebug(string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("InvalidSIDFormat"), value));
            }

            if (sidCandidate == null)
            {
                try
                {
                    NTAccount acct = new NTAccount(value.ToString());
                    sidCandidate = (SecurityIdentifier)acct.Translate(typeof(SecurityIdentifier));
                }
                catch (ArgumentException exc)
                {
                    string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("InvalidContext"), value.ToString());
                    Exception outerExc = new Exception(msg, exc);
                    WriteError(new ErrorRecord(outerExc, "InvalidContext", ErrorCategory.InvalidArgument, null));
                    return "";
                }
            }

            return string.Format(CultureInfo.InvariantCulture, "(System/Security[@UserID='{0}'])", sidCandidate.ToString());
        }
开发者ID:dfinke,项目名称:powershell,代码行数:36,代码来源:GetEventCommand.cs

示例10: Sid

 public Sid(SecurityIdentifier sid)
 {
     this.sid = sid;
     SecurityIdentifier = sid.ToString();
     BinaryLength = sid.BinaryLength;
 }
开发者ID:blinds52,项目名称:ActiveDirectoryServices,代码行数:6,代码来源:Sid.cs

示例11: GetLocalGroup

        /// <summary>
        /// Retrieve a local group by SID
        /// </summary>
        /// <param name="sid">
        /// A <see cref="SecurityIdentifier"/> object identifying the desired group.
        /// </param>
        /// <returns>
        /// A <see cref="LocalGroup"/> object containing information about
        /// the local group.
        /// </returns>
        /// <exception cref="GroupNotFoundException">
        /// Thrown when the specified group cannot be found.
        /// </exception>
        internal LocalGroup GetLocalGroup(SecurityIdentifier sid)
        {
            context = new Context(ContextOperation.Get, ContextObjectType.Group, sid.ToString(), sid);

            foreach (var sre in EnumerateGroups())
                if (RidToSid(sre.domainHandle, sre.RelativeId) == sid)
                    return MakeLocalGroupObject(sre);   // return a populated group

            throw new GroupNotFoundException(sid.ToString(), context.target);
        }
开发者ID:40a,项目名称:PowerShell,代码行数:23,代码来源:Sam.cs

示例12: SetExchangeImpersonation

 /// <summary>
 /// Sets the ExchangeImpersonation soap header on the binding prior to a 
 /// call
 /// </summary>
 /// <param name="sid">SID of user to "Act As"</param>
 /// 
 public void SetExchangeImpersonation(SecurityIdentifier sid)
 {
     ExchangeImpersonationType header = new ExchangeImpersonationType();
     header.ConnectingSID = new ConnectingSIDType();
     header.ConnectingSID.SID = sid.ToString();
     this.ExchangeImpersonation = header;
 }
开发者ID:RazaToosy,项目名称:NhsCommissioningMailer,代码行数:13,代码来源:ExchangeServiceBinding.cs

示例13: GetAllCentralAccessPolicies

		public static string[] GetAllCentralAccessPolicies(PSObject instance)
		{
			unsafe
			{
				string[] strArrays;
				IntPtr zero = IntPtr.Zero;
				try
				{
					int num = 0;
					int num1 = NativeMethods.LsaQueryCAPs(null, 0, out zero, out num);
					if (num1 == 0)
					{
						if (num == 0 || zero == IntPtr.Zero)
						{
							strArrays = null;
						}
						else
						{
							string[] strArrays1 = new string[num];
							IntPtr intPtr = zero;
							uint num2 = 0;
							while (num2 < num)
							{
								NativeMethods.CENTRAL_ACCESS_POLICY structure = (NativeMethods.CENTRAL_ACCESS_POLICY)Marshal.PtrToStructure(intPtr, typeof(NativeMethods.CENTRAL_ACCESS_POLICY));
								strArrays1[num2] = string.Concat("\"", Marshal.PtrToStringUni(structure.Name.Buffer, structure.Name.Length / 2), "\"");
								IntPtr cAPID = structure.CAPID;
								bool flag = NativeMethods.IsValidSid(cAPID);
								if (flag)
								{
									SecurityIdentifier securityIdentifier = new SecurityIdentifier(cAPID);
									string[] strArrays2 = strArrays1;
									string[] strArrays3 = strArrays2;
									uint num3 = num2;
									IntPtr intPtr1 = (IntPtr)num3;
									strArrays2[num3] = string.Concat(strArrays3[intPtr1.ToInt32()], " (", securityIdentifier.ToString(), ")");
									intPtr = intPtr + Marshal.SizeOf(structure);
									num2++;
								}
								else
								{
									throw new Win32Exception(Marshal.GetLastWin32Error());
								}
							}
							strArrays = strArrays1;
						}
					}
					else
					{
						throw new Win32Exception(num1);
					}
				}
				finally
				{
					NativeMethods.LsaFreeMemory(zero);
				}
				return strArrays;
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:58,代码来源:SecurityDescriptorCommandsBase.cs

示例14: GetAllCentralAccessPolicies

        /// <summary>
        /// Gets the names and IDs of all central access policies available on the machine.
        /// </summary>
        /// <remarks>
        /// Function 'LsaQueryCAPs' is not available in OneCoreUAP and NanoServer.
        /// </remarks>
        /// <param name="instance">
        /// The PSObject argument is ignored.
        /// </param>
        /// <returns>
        /// The names and IDs of all central access policies available on the machine.
        /// </returns>
        public static string[] GetAllCentralAccessPolicies(PSObject instance)
        {
            IntPtr caps = IntPtr.Zero;

            try
            {
                // Retrieve all CAPs.
                uint capCount = 0;
                uint rs = NativeMethods.LsaQueryCAPs(
                    null,
                    0,
                    out caps,
                    out capCount);
                if (rs != NativeMethods.STATUS_SUCCESS)
                {
                    throw new Win32Exception((int)rs);
                }
                Dbg.Diagnostics.Assert(capCount < 0xFFFF,
                    "Too many central access policies");
                if (capCount == 0 || caps == IntPtr.Zero)
                {
                    return null;
                }

                // Add CAP names and IDs to a string array.
                string[] policies = new string[capCount];
                NativeMethods.CENTRAL_ACCESS_POLICY cap = new NativeMethods.CENTRAL_ACCESS_POLICY();
                IntPtr capPtr = caps;
                for (uint capIdx = 0; capIdx < capCount; capIdx++)
                {
                    // Retrieve CAP name.
                    Dbg.Diagnostics.Assert(capPtr != IntPtr.Zero,
                        "Invalid central access policies array");
                    cap = ClrFacade.PtrToStructure<NativeMethods.CENTRAL_ACCESS_POLICY>(capPtr);
                    // LSA_UNICODE_STRING is composed of WCHARs, but its length is given in bytes.
                    policies[capIdx] = "\"" + Marshal.PtrToStringUni(
                        cap.Name.Buffer,
                        cap.Name.Length / 2) + "\"";

                    // Retrieve CAPID.
                    IntPtr pCapId = cap.CAPID;
                    Dbg.Diagnostics.Assert(pCapId != IntPtr.Zero,
                        "Invalid central access policies array");
                    bool ret = NativeMethods.IsValidSid(pCapId);
                    if (!ret)
                    {
                        throw new Win32Exception(Marshal.GetLastWin32Error());
                    }
                    SecurityIdentifier sid = new SecurityIdentifier(pCapId);
                    policies[capIdx] += " (" + sid.ToString() + ")";

                    capPtr += Marshal.SizeOf(cap);
                }
                return policies;
            }
            finally
            {
                uint rs = NativeMethods.LsaFreeMemory(caps);
                Dbg.Diagnostics.Assert(rs == NativeMethods.STATUS_SUCCESS,
                    "LsaFreeMemory failed: " + rs.ToString(CultureInfo.CurrentCulture));
            }
        }
开发者ID:dfinke,项目名称:powershell,代码行数:74,代码来源:AclCommands.cs

示例15: RemoveLocalGroup

        /// <summary>
        /// Remove a local group.
        /// </summary>
        /// <param name="sid">
        /// A <see cref="SecurityIdentifier"/> object identifying the
        /// local group to be removed.
        /// </param>
        /// <exception cref="GroupNotFoundException">
        /// Thrown when the specified group cannot be found.
        /// </exception>
        internal void RemoveLocalGroup(SecurityIdentifier sid)
        {
            context = new Context(ContextOperation.Remove, ContextObjectType.Group, sid.ToString(), sid);

            RemoveGroup(sid);
        }
开发者ID:40a,项目名称:PowerShell,代码行数:16,代码来源:Sam.cs


注:本文中的System.Security.Principal.SecurityIdentifier.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。