예제 #1
0
        private void LookupAccount(string accountname, string systemname)
        {
            byte[] sid   = null;
            uint   cbSid = 0;

            _referencedDomainName = new StringBuilder();
            uint cchReferencedDomainName = (uint)_referencedDomainName.Capacity;

            if (Advapi32.LookupAccountName(systemname, accountname, sid, ref cbSid, _referencedDomainName, ref cchReferencedDomainName, out _sidNameUse))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), string.Format("LookupAccountName failed for {0}\\{1}",
                                                                                    string.IsNullOrEmpty(systemname) ? "." : systemname, accountname));
            }

            int err = Marshal.GetLastWin32Error();

            switch (err)
            {
            case Windows.ERROR_INSUFFICIENT_BUFFER:
            case Windows.ERROR_INVALID_FLAGS:
                sid = new byte[cbSid];
                _referencedDomainName.EnsureCapacity((int)cchReferencedDomainName);
                break;

            default:
                throw new Win32Exception(err);
            }

            if (!Advapi32.LookupAccountName(systemname, accountname, sid, ref cbSid, _referencedDomainName, ref cchReferencedDomainName, out _sidNameUse))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(),
                                         string.Format("LookupAccountName failed for {0}\\{1}",
                                                       string.IsNullOrEmpty(systemname) ? "." : systemname, accountname));
            }

            WindowsAccountName windowsAccountName = new WindowsAccountName(accountname);

            _accountName = windowsAccountName.AccountName;

            _sid = new SecurityIdentifier(sid, 0);
            _fqn = string.Format(@"{0}\{1}", _referencedDomainName, _accountName);
        }
예제 #2
0
 /// <summary>
 /// Implementation of <see cref="T:Waffle.Windows.AuthProvider.IWindowsAuthProvider.LogonUser" />.
 /// </summary>
 public IWindowsIdentity LogonUser(string username, string password)
 {
     WindowsAccountName windowsAccountName = new WindowsAccountName(username);
     return LogonDomainUser(windowsAccountName.AccountName, windowsAccountName.DomainName, password);
 }
예제 #3
0
        /// <summary>
        /// Implementation of <see cref="T:Waffle.Windows.AuthProvider.IWindowsAuthProvider.LogonUser" />.
        /// </summary>
        public IWindowsIdentity LogonUser(string username, string password)
        {
            WindowsAccountName windowsAccountName = new WindowsAccountName(username);

            return(LogonDomainUser(windowsAccountName.AccountName, windowsAccountName.DomainName, password));
        }
예제 #4
0
        private void LookupAccount(string accountname, string systemname)
        {
            byte[] sid = null;
            uint cbSid = 0;
            _referencedDomainName = new StringBuilder();
            uint cchReferencedDomainName = (uint)_referencedDomainName.Capacity;

            if (Advapi32.LookupAccountName(systemname, accountname, sid, ref cbSid, _referencedDomainName, ref cchReferencedDomainName, out _sidNameUse))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), string.Format("LookupAccountName failed for {0}\\{1}",
                    string.IsNullOrEmpty(systemname) ? "." : systemname, accountname));
            }

            int err = Marshal.GetLastWin32Error();
            switch (err)
            {
                case Windows.ERROR_INSUFFICIENT_BUFFER:
                case Windows.ERROR_INVALID_FLAGS:
                    sid = new byte[cbSid];
                    _referencedDomainName.EnsureCapacity((int)cchReferencedDomainName);
                    break;
                default:
                    throw new Win32Exception(err);
            }

            if (!Advapi32.LookupAccountName(systemname, accountname, sid, ref cbSid, _referencedDomainName, ref cchReferencedDomainName, out _sidNameUse))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(),
                    string.Format("LookupAccountName failed for {0}\\{1}",
                    string.IsNullOrEmpty(systemname) ? "." : systemname, accountname));
            }

            WindowsAccountName windowsAccountName = new WindowsAccountName(accountname);
            _accountName = windowsAccountName.AccountName;

            _sid = new SecurityIdentifier(sid, 0);
            _fqn = string.Format(@"{0}\{1}", _referencedDomainName, _accountName);
        }