Example #1
0
		 protected internal override AuthorizationInfo DoGetAuthorizationInfo( PrincipalCollection principals )
		 {
			  if ( !_authorizationEnabled )
			  {
					return null;
			  }

			  string username = ( string ) getAvailablePrincipal( principals );
			  if ( string.ReferenceEquals( username, null ) )
			  {
					return null;
			  }

			  User user = _userRepository.getUserByName( username );
			  if ( user == null )
			  {
					return null;
			  }

			  if ( user.PasswordChangeRequired() || user.HasFlag(IS_SUSPENDED) )
			  {
					return new SimpleAuthorizationInfo();
			  }
			  else
			  {
					ISet<string> roles = _roleRepository.getRoleNamesByUsername( user.Name() );
					return new SimpleAuthorizationInfo( roles );
			  }
		 }
Example #2
0
        // Non recursive group check (immediate membership only currently)
        private static bool IsUserInGroup(UserPrincipal user, GroupPrincipal group)
        {
            if (user == null || group == null)
            {
                return(false);
            }

            // This may seem a convoluted and strange way to check group membership.
            // Especially because I could just call user.IsMemberOf(group).
            // The reason for all of this is that IsMemberOf will throw an exception
            // if there is an unresolvable SID in the list of group members.  Unfortunately,
            // even looping over the members with a standard foreach loop doesn't allow
            // for catching the exception and continuing.  Therefore, we need to use the
            // IEnumerator object and iterate through the members carefully, catching the
            // exception if it is thrown.  I throw in a sanity check because there's no
            // guarantee that MoveNext will actually move the enumerator forward when an
            // exception occurs, although it has done so in my tests.
            //
            // For additional details, see the following bug:
            // https://connect.microsoft.com/VisualStudio/feedback/details/453812/principaloperationexception-when-enumerating-the-collection-groupprincipal-members

            PrincipalCollection members = group.Members;
            bool ok         = true;
            int  errorCount = 0; // This is a sanity check in case the loop gets out of control
            IEnumerator <Principal> membersEnum = members.GetEnumerator();

            while (ok)
            {
                try { ok = membersEnum.MoveNext(); }
                catch (PrincipalOperationException)
                {
                    m_logger.ErrorFormat("PrincipalOperationException when checking group membership for user {0} in group {1}." +
                                         "  This usually means that you have an unresolvable SID as a group member." +
                                         "  I strongly recommend that you fix this problem as soon as possible by removing the SID from the group. " +
                                         "  Ignoring the exception and continuing.",
                                         user.Name, group.Name);

                    // Sanity check to avoid infinite loops
                    errorCount++;
                    if (errorCount > 1000)
                    {
                        return(false);
                    }

                    continue;
                }

                if (ok)
                {
                    Principal principal = membersEnum.Current;

                    if (principal is UserPrincipal && principal.Sid == user.Sid)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected org.apache.shiro.authz.AuthorizationInfo queryForAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection principals, org.apache.shiro.realm.ldap.LdapContextFactory ldapContextFactory) throws javax.naming.NamingException
            protected internal override AuthorizationInfo QueryForAuthorizationInfo(PrincipalCollection principals, LdapContextFactory ldapContextFactory)
            {
                if (FailAuth)
                {
                    throw new NamingException("Simulated failure");
                }
                return(new SimpleAuthorizationInfo());
            }
Example #4
0
        public PrincipalCollectionWrapper(PrincipalCollection principalCollection)
        {
            if (principalCollection == null)
            {
                throw new ArgumentNullException("principalCollection");
            }

            this._principalCollection = principalCollection;
        }
Example #5
0
 protected internal override AuthorizationInfo DoGetAuthorizationInfo(PrincipalCollection principals)
 {
     try
     {
         AuthorizationInfo info = base.DoGetAuthorizationInfo(principals);
         _securityLog.debug(WithRealm("Queried for authorization info for user '%s'", principals.PrimaryPrincipal));
         return(info);
     }
     catch (AuthorizationException e)
     {
         _securityLog.warn(WithRealm("Failed to get authorization info: '%s' caused by '%s'", e.Message, e.InnerException.Message));
         return(null);
     }
 }
Example #6
0
        /// <summary>
        /// This method returns the members of the specified group that are UserPrincipals.
        /// </summary>
        /// <param name="group">The unique identifier of the group.</param>
        /// <returns>A list of UserPrincipal objects.</returns>
        public static List <UserPrincipal> GetUsersInGroup(string group)
        {
            List <UserPrincipal> results = new List <UserPrincipal>();
            GroupPrincipal       g       = GroupPrincipal.FindByIdentity(GetPrincipalContext(), group);
            PrincipalCollection  members = g.Members;

            foreach (Principal member in members)
            {
                if (member is UserPrincipal)
                {
                    results.Add(GetUser(member.SamAccountName));
                }
            }
            return(results);
        }
        public void Add <T>(T value)
        {
            if (value.GetType() == typeof(D))
            {
                var dependantKey = DependantKeyInfo.GetValue(value);

                var principals = PrincipalCollection.Where(p => this.PrincipalForeignKeyInfo.GetValue(p).Equals(dependantKey))
                                 .ToList();

                foreach (var principal in principals)
                {
                    PrincipalRelationInfo.SetValue(principal, value);
                }
            }
        }
Example #8
0
        private string GetUsername(PrincipalCollection principals)
        {
            string username = null;

            System.Collections.ICollection ldapPrincipals = principals.fromRealm(Name);
            if (ldapPrincipals.Count > 0)
            {
                username = ( string )ldapPrincipals.GetEnumerator().next();
            }
            else if (_useSystemAccountForAuthorization.Value)
            {
                username = ( string )principals.PrimaryPrincipal;
            }
            return(username);
        }
        private static ICollection <User> getUsers(PrincipalCollection principalCollection)
        {
            var users = new Collection <User>();

            foreach (var principal in principalCollection)
            {
                if (principal is UserPrincipal)
                {
                    var foundUserPrincipal = (UserPrincipal)principal;
                    users.Add(bindUser(foundUserPrincipal));
                }
            }

            return(users);
        }
Example #10
0
        public virtual ICollection <AuthorizationInfo> GetAuthorizationInfo(PrincipalCollection principalCollection)
        {
            IList <AuthorizationInfo> infoList = new List <AuthorizationInfo>(1);

            foreach (Realm realm in _realms)
            {
                if (realm is ShiroAuthorizationInfoProvider)
                {
                    AuthorizationInfo info = (( ShiroAuthorizationInfoProvider )realm).GetAuthorizationInfoSnapshot(principalCollection);
                    if (info != null)
                    {
                        infoList.Add(info);
                    }
                }
            }
            return(infoList);
        }
Example #11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected org.apache.shiro.authz.AuthorizationInfo queryForAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection principals, org.apache.shiro.realm.ldap.LdapContextFactory ldapContextFactory) throws javax.naming.NamingException
        protected internal override AuthorizationInfo QueryForAuthorizationInfo(PrincipalCollection principals, LdapContextFactory ldapContextFactory)
        {
            if (_authorizationEnabled.Value)
            {
                string username = GetUsername(principals);
                if (string.ReferenceEquals(username, null))
                {
                    return(null);
                }

                if (_useSystemAccountForAuthorization.Value)
                {
                    // Perform context search using the system context
                    LdapContext ldapContext = _useStartTls ? GetSystemLdapContextUsingStartTls(ldapContextFactory) : ldapContextFactory.SystemLdapContext;

                    ISet <string> roleNames;
                    try
                    {
                        roleNames = FindRoleNamesForUser(username, ldapContext);
                    }
                    finally
                    {
                        LdapUtils.closeContext(ldapContext);
                    }

                    return(new SimpleAuthorizationInfo(roleNames));
                }
                else
                {
                    // Authorization info is cached during authentication
                    Cache <object, AuthorizationInfo> authorizationCache = AuthorizationCache;
                    AuthorizationInfo authorizationInfo = authorizationCache.get(username);
                    if (authorizationInfo == null)
                    {
                        // The cached authorization info has expired.
                        // Since we do not have the subject's credentials we cannot perform a new LDAP search
                        // for authorization info. Instead we need to fail with a special status,
                        // so that the client can react by re-authenticating.
                        throw new AuthorizationExpiredException("LDAP authorization info expired.");
                    }
                    return(authorizationInfo);
                }
            }
            return(null);
        }
Example #12
0
        private void AddPropertiesToWrangler(ResultWrangler wrangler, PrincipalCollection objectlist, List <KeyValuePair <string, XElement> > PropertyTemplates)
        {
            foreach (UserPrincipal user in objectlist)
            {
                wrangler.NewResult();
                FormattedProperty prop = null;

                //if properties have been specified in the xml, query them directly in order
                if (PropertyTemplates.Count != 0)
                {
                    foreach (KeyValuePair <string, XElement> template in PropertyTemplates)
                    {
                        prop       = new FormattedProperty(template.Value);
                        prop.Input = PropertyInterogation.GetStringFromPropertyValue(user, template.Key);
                        wrangler.AddFormattedProperty(prop);
                    }
                }
            }
        }
Example #13
0
        /// <summary>
        /// Sets members of the group.
        /// </summary>
        /// <param name="newMembers">List of group members.</param>
        public override async Task SetGroupMembersAsync(IList <IPrincipal> newMembers)
        {
            PrincipalCollection     members  = groupPrincipal.Members;
            IEnumerable <Principal> toDelete = members.Where(m => !newMembers.Where(nm => ((PrincipalBase)nm).Principal.Sid.Value == m.Sid.Value).Any()).ToList();

            foreach (Principal p in toDelete)
            {
                groupPrincipal.Members.Remove(p);
            }

            IEnumerable <IPrincipal> toAdd = newMembers.Where(nm => !members.Where(m => m.Sid.Value == ((PrincipalBase)nm).Principal.Sid.Value).Any()).ToList();

            foreach (PrincipalBase p in toAdd)
            {
                groupPrincipal.Members.Add(p.Principal);
            }

            Context.PrincipalOperation(groupPrincipal.Save);
        }
Example #14
0
        static List <UserPrincipal> GetGroupMembers(PrincipalContext oPrincipalContext, String group)
        {
            GroupPrincipal       oGroupPrincipal = GroupPrincipal.FindByIdentity(oPrincipalContext, group);
            List <UserPrincipal> ret             = new List <UserPrincipal>();

            if (oGroupPrincipal == null)
            {
                return(ret);
            }
            PrincipalCollection     coll      = oGroupPrincipal.Members;
            IEnumerator <Principal> principal = coll.GetEnumerator();

            while (principal.MoveNext())
            {
                try
                {
                    if ("group".Equals(principal.Current.StructuralObjectClass.ToLower()))
                    {
                        ret.AddRange(GetGroupMembers(oPrincipalContext, principal.Current.SamAccountName));
                    }
                    else
                    {
                        UserPrincipal user = UserPrincipal.FindByIdentity(oPrincipalContext, principal.Current.SamAccountName);
                        if (user == null)
                        {
                            continue;
                        }
                        ret.Add(user);
                    }
                }
                catch (MultipleMatchesException)
                {
                    continue;
                }
                catch (PrincipalOperationException)
                {
                    continue;
                }
            }
            return(ret);
        }
Example #15
0
        /// <summary>
        /// This method returns a list of AdMember objects compilied from the specified
        /// PrincipalCollection.
        /// </summary>
        /// <param name="members"></param>
        /// <returns>A list of AdMember objects.</returns>
        public static List <AdMember> GetAdMembers(PrincipalCollection members)
        {
            List <AdMember> results = new List <AdMember>();

            foreach (Principal m in members)
            {
                AdMember member = new AdMember();

                member.Description       = m.Description;
                member.DisplayName       = m.DisplayName;
                member.DistinguishedName = m.DistinguishedName;
                member.Guid              = m.Guid.ToString();
                member.Name              = m.Name;
                member.SamAccountName    = m.SamAccountName;
                member.Sid               = m.Sid.Value;
                member.UserPrincipalName = m.UserPrincipalName;

                results.Add(member);
            }

            return(results.OrderBy(x => x.SamAccountName).ToList());
        }
Example #16
0
 /// <summary>
 ///
 /// </summary>
 public PrincipalCollectionWrap(PrincipalCollection principalCollection)
 {
     this.principalCollection = principalCollection;
 }
Example #17
0
 protected internal override AuthorizationInfo DoGetAuthorizationInfo(PrincipalCollection principals)
 {
     AuthorizationFlag = true;
     return(new AuthorizationInfoAnonymousInnerClass(this));
 }
Example #18
0
 /// <summary>
 /// This method returns a list of strings that are the SamAccountNames of the Principals in the
 /// specified PrincipalCollection.
 /// </summary>
 /// <param name="members"></param>
 /// <returns>A list of strings that are SamAccountNames.</returns>
 public static List <string> GetAdMemberSamAccountNames(PrincipalCollection members)
 {
     return(GetAdMembers(members).Select(x => x.SamAccountName).OrderBy(x => x).ToList());
 }
Example #19
0
 public override AuthorizationInfo GetAuthorizationInfoSnapshot(PrincipalCollection principalCollection)
 {
     return(getAuthorizationInfo(principalCollection));
 }
Example #20
0
 /// <summary>
 /// This method returns a list of strings that are the SamAccountNames of the Principals in the
 /// specified PrincipalCollection.
 /// </summary>
 /// <param name="members"></param>
 /// <returns>A list of strings that are SamAccountNames.</returns>
 public static List<string> GetAdMemberSamAccountNames(PrincipalCollection members)
 {
     return GetAdMembers(members).Select(x => x.SamAccountName).OrderBy(x => x).ToList();
 }
Example #21
0
        /// <summary>
        /// This method returns a list of AdMember objects compilied from the specified
        /// PrincipalCollection.
        /// </summary>
        /// <param name="members"></param>
        /// <returns>A list of AdMember objects.</returns>
        public static List<AdMember> GetAdMembers(PrincipalCollection members)
        {
            List<AdMember> results = new List<AdMember>();

            foreach (Principal m in members)
            {
                AdMember member = new AdMember();

                member.Description = m.Description;
                member.DisplayName = m.DisplayName;
                member.DistinguishedName = m.DistinguishedName;
                member.Guid = m.Guid.ToString();
                member.Name = m.Name;
                member.SamAccountName = m.SamAccountName;
                member.Sid = m.Sid.Value;
                member.UserPrincipalName = m.UserPrincipalName;

                results.Add(member);
            }

            return results.OrderBy(x => x.SamAccountName).ToList();
        }
Example #22
0
 protected internal override AuthorizationInfo DoGetAuthorizationInfo(PrincipalCollection principals)
 {
     AuthorizationFlag = true;
     return(base.DoGetAuthorizationInfo(principals));
 }
Example #23
0
 public static PrincipalCollectionWrapper FromPrincipalCollection(PrincipalCollection principalCollection)
 {
     return(principalCollection);
 }
 /// <summary>
 /// 
 /// </summary>
 public PrincipalCollectionWrap(PrincipalCollection principalCollection)
 {
     this.principalCollection = principalCollection;
 }
Example #25
0
        private SupportInfoElement LoadData(SupportInfotype sit, int number, int col)
        {
            if (sit == SupportInfotype.UserName)
            {
                var user = WindowsIdentity.GetCurrent().Name;

                StringBuilder sbu      = new StringBuilder(1024);
                uint          sbu_size = (uint)sbu.Capacity;

                var fn = string.Empty;

                //fn = System.DirectoryServices.AccountManagement.UserPrincipal.Current.GivenName;



                return(new SupportInfoElement()
                {
                    Name = "Benutzername", Value = $"{user} {fn}", Number = number, Column = col
                });
            }

            if (sit == SupportInfotype.IsAdmin)
            {
                var current_user_sid = WindowsIdentity.GetCurrent().User.Value;

                bool CurrentUserIsmemberOfAdminGroup = false;
                try
                {
                    var administrator_group_sid = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);

                    using (PrincipalContext pc = new PrincipalContext(ContextType.Machine, Environment.MachineName))
                    {
                        GroupPrincipal gp = GroupPrincipal.FindByIdentity(pc, IdentityType.Sid, administrator_group_sid.Value);
                        if (gp != null)
                        {
                            PrincipalCollection members = gp.Members;
                            if (members != null)
                            {
                                foreach (Principal p in members)
                                {
                                    if (p.Sid != null)
                                    {
                                        if (p.Sid.Value.Equals(current_user_sid))
                                        {
                                            CurrentUserIsmemberOfAdminGroup = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch { }

                if (CurrentUserIsmemberOfAdminGroup)
                {
                    return new SupportInfoElement()
                           {
                               Name = "Administrative Rechte", Value = "JA", MakeBold = true, Number = number, Column = col
                           }
                }
                ;
                else
                {
                    return new SupportInfoElement()
                           {
                               Name = "Administrative Rechte", Value = "NEIN", Number = number, Column = col
                           }
                };
            }

            if (sit == SupportInfotype.ComputerName)
            {
                return(new SupportInfoElement()
                {
                    Name = "Computername", Value = Environment.MachineName, Number = number, Column = col
                });
            }

            if (sit == SupportInfotype.OperatingSystem)
            {
                var versionString = (string)Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion")?.GetValue("productName");
                var releaseID     = (string)Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion")?.GetValue("ReleaseID");
                var x64           = Environment.Is64BitOperatingSystem ? "x64" : "x86";

                return(new SupportInfoElement()
                {
                    Name = "Betriebssystem-Edition | -Release | -Architektur", Value = $"{versionString}  |  {releaseID}  |  {x64}", Number = number, Column = col
                });
            }

            if (sit == SupportInfotype.WindowsVersionInfo)
            {
                var os_major           = (int)Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion")?.GetValue("CurrentMajorVersionNumber");
                var os_minor           = (int)Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion")?.GetValue("CurrentMinorVersionNumber");
                var currentBuildNumber = (string)Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion")?.GetValue("currentBuildNumber");
                var ubr = (int)Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion")?.GetValue("UBR");

                return(new SupportInfoElement()
                {
                    Name = "Betriebssystem-Version", Value = $"{os_major}.{os_minor}.{currentBuildNumber}.{ubr}", Number = number, Column = col
                });
            }

            if (sit == SupportInfotype.ComputerManufacturer)
            {
                string manufacturer = string.Empty;

                try
                {
                    ManagementClass cs = new ManagementClass("win32_baseboard");

                    ManagementObjectCollection moc = cs.GetInstances();
                    if (moc.Count != 0)
                    {
                        foreach (ManagementObject MO in cs.GetInstances())
                        {
                            manufacturer = MO.Properties["Manufacturer"].Value.ToString();
                        }
                    }
                }
                catch { }

                return(new SupportInfoElement()
                {
                    Name = "Hersteller", Value = manufacturer, Number = number, Column = col
                });
            }

            if (sit == SupportInfotype.ComputerModel)
            {
                string model = string.Empty;

                try
                {
                    ManagementClass            cs  = new ManagementClass("win32_baseboard");
                    ManagementObjectCollection moc = cs.GetInstances();
                    if (moc.Count != 0)
                    {
                        foreach (ManagementObject MO in cs.GetInstances())
                        {
                            model = MO.Properties["Product"].Value.ToString();
                        }
                    }
                }
                catch { }

                return(new SupportInfoElement()
                {
                    Name = "Modell", Value = model, Number = number, Column = col
                });
            }

            if (sit == SupportInfotype.SerialBaseboard)
            {
                string serial = string.Empty;

                try
                {
                    ManagementClass            cs  = new ManagementClass("win32_baseboard");
                    ManagementObjectCollection moc = cs.GetInstances();
                    if (moc.Count != 0)
                    {
                        foreach (ManagementObject MO in cs.GetInstances())
                        {
                            serial = MO.Properties["SerialNumber"].Value.ToString();
                        }
                    }
                }
                catch { }

                return(new SupportInfoElement()
                {
                    Name = "Serien-Nummer (Baseboard)", Value = $"{serial}", Number = number, Column = col
                });
            }

            if (sit == SupportInfotype.SerialBios)
            {
                string serial = string.Empty;

                try
                {
                    ManagementClass            cs  = new ManagementClass("win32_bios");
                    ManagementObjectCollection moc = cs.GetInstances();
                    if (moc.Count != 0)
                    {
                        foreach (ManagementObject MO in cs.GetInstances())
                        {
                            serial = MO.Properties["SerialNumber"].Value.ToString();
                        }
                    }
                }
                catch { }

                return(new SupportInfoElement()
                {
                    Name = "Serien-Nummer (BIOS)", Value = $"{serial}", Number = number, Column = col
                });
            }

            if (sit == SupportInfotype.CPU)
            {
                string cpu = string.Empty;
                try
                {
                    ManagementClass            cs  = new ManagementClass("win32_processor");
                    ManagementObjectCollection moc = cs.GetInstances();
                    if (moc.Count != 0)
                    {
                        foreach (ManagementObject MO in cs.GetInstances())
                        {
                            cpu = MO.Properties["Name"].Value.ToString();
                        }
                    }
                }
                catch { }
                return(new SupportInfoElement()
                {
                    Name = "CPU", Value = cpu, Number = number, Column = col
                });
            }

            if (sit == SupportInfotype.Firmware)
            {
                // Firmware

                string   bios_manufacturer = string.Empty;
                string   bios_version      = string.Empty;
                DateTime bios_datetime     = DateTime.MinValue;

                try
                {
                    ManagementClass            cs  = new ManagementClass("win32_bios");
                    ManagementObjectCollection moc = cs.GetInstances();
                    if (moc.Count != 0)
                    {
                        foreach (ManagementObject MO in cs.GetInstances())
                        {
                            bios_manufacturer = MO.Properties["Manufacturer"].Value.ToString();
                            bios_version      = MO.Properties["SMBIOSBIOSVersion"].Value.ToString();
                            bios_datetime     = ManagementDateTimeConverter.ToDateTime(MO.Properties["ReleaseDate"].Value.ToString());
                        }
                    }
                }
                catch { }

                return(new SupportInfoElement()
                {
                    Name = "Firmware-Hersteller | -Version | -Datum", Value = $"{bios_manufacturer}  |  {bios_version}  | {bios_datetime.ToString("dd.MM.yyyy")}", Number = number, Column = col
                });
            }

            if (sit == SupportInfotype.Memory)
            {
                // RAM

                string ram = string.Empty;

                try
                {
                    ManagementClass            cs  = new ManagementClass("Win32_OperatingSystem");
                    ManagementObjectCollection moc = cs.GetInstances();
                    if (moc.Count != 0)
                    {
                        foreach (ManagementObject MO in cs.GetInstances())
                        {
                            ram = Convert.ToInt64(MO.Properties["TotalVisibleMemorySize"].Value).Kilobytes().Humanize("#.#");
                        }
                    }
                }
                catch { }

                return(new SupportInfoElement()
                {
                    Name = "RAM", Value = ram, Number = number, Column = col
                });
            }

            if (sit == SupportInfotype.PhysicalDrives)
            {
                // physical disk drives

                List <DiskDrive> DiskDrives = new List <DiskDrive>();

                string disk_info = string.Empty;

                try
                {
                    string caption   = string.Empty;
                    string size_text = string.Empty;

                    ManagementClass            cs  = new ManagementClass("win32_diskdrive");
                    ManagementObjectCollection moc = cs.GetInstances();
                    if (moc.Count != 0)
                    {
                        foreach (ManagementObject MO in cs.GetInstances())
                        {
                            var type = MO.Properties["MediaType"]?.Value?.ToString();

                            if (type == null)
                            {
                                continue;
                            }
                            if (!type.Equals("fixed hard disk media", StringComparison.InvariantCultureIgnoreCase))
                            {
                                continue;
                            }

                            DiskDrives.Add(new DiskDrive()
                            {
                                Caption      = MO.Properties["Caption"].Value.ToString(),
                                Size         = Convert.ToInt64(MO.Properties["Size"].Value),
                                SerialNumber = MO.Properties["SerialNumber"].Value.ToString(),
                                Index        = Convert.ToInt32(MO.Properties["Index"].Value)
                            });
                        }

                        // sortieren
                        DiskDrives = DiskDrives.OrderBy(x => x.Index).ToList();
                    }
                }
                catch { }

                return(new SupportInfoElement()
                {
                    Name = "Laufwerke (physikalisch)",
                    Value = string.Join("\n", DiskDrives.Select(x => x.ToString())),
                    Number = number,
                    Column = col
                });
            }

            if (sit == SupportInfotype.LogicalDrives)
            {
                // logical drives

                List <LogicalVolume> L = new List <LogicalVolume>();

                string drive_string = string.Empty;

                try
                {
                    foreach (var d in DriveInfo.GetDrives())
                    {
                        if (!d.DriveType.Equals(DriveType.Fixed))
                        {
                            continue;
                        }

                        L.Add(new LogicalVolume()
                        {
                            Name       = d.Name,
                            TotalSpace = d.TotalSize,
                            FreeSpace  = d.AvailableFreeSpace
                        });
                    }
                }
                catch { }

                return(new SupportInfoElement()
                {
                    Name = "Laufwerke (logisch)",
                    Value = string.Join("\n", L.Select(x => x.ToString())),
                    Number = number,
                    Column = col
                });
            }

            if (sit == SupportInfotype.Network)
            {
                // netzwerk info

                List <NetworkInfo> NetworkAdapter = new List <NetworkInfo>();
                string             net_info       = string.Empty;

                try
                {
                    foreach (var n in NetworkInterface.GetAllNetworkInterfaces())
                    {
                        if (n.NetworkInterfaceType.Equals(NetworkInterfaceType.Loopback))
                        {
                            continue;
                        }


                        //if (n.OperationalStatus.Equals(OperationalStatus.Down)) continue;


                        IPInterfaceProperties ipip = n.GetIPProperties();

                        if ((ipip.GatewayAddresses == null) || (ipip.GatewayAddresses.Count.Equals(0)))
                        {
                            NetworkAdapter.Add(new NetworkInfo()
                            {
                                AdapterName = n.Description, Speed = n.Speed
                            });
                            continue;
                        }
                        ;

                        foreach (var u in ipip.UnicastAddresses)
                        {
                            if (!u.Address.AddressFamily.Equals(System.Net.Sockets.AddressFamily.InterNetwork))
                            {
                                continue;
                            }

                            NetworkAdapter.Add(new NetworkInfo()
                            {
                                AdapterName = n.Description, Speed = n.Speed, IP = u.Address.ToString()
                            });
                        }
                    }
                }
                catch { }

                return(new SupportInfoElement()
                {
                    Name = "Netzwerk",
                    Value = string.Join("\n", NetworkAdapter.Select(x => x.ToString())),
                    Number = number,
                    Column = col
                });
            }

            if (sit == SupportInfotype.Ping)
            {
                // Ping

                string ping_info = string.Empty;

                Ping ping = new Ping();

                try
                {
                    PingReply pr = ping.Send(new System.Net.IPAddress(new byte[] { 8, 8, 8, 8 }), 1000);

                    var ping_result = pr.Status.ToString();
                    var ping_ms     = pr.RoundtripTime.ToString();

                    ping_info = $"Ergebnis: {ping_result}, {ping_ms} ms";
                }
                catch { }

                return(new SupportInfoElement()
                {
                    Name = "Ping (8.8.8.8)", Value = ping_info, Number = number, Column = col
                });
            }

            if (sit == SupportInfotype.Webcam)
            {
                // Webcam

                string WebCamInfo = string.Empty;

                FilterInfoCollection videoInputCollection = new FilterInfoCollection(FilterCategory.VideoInputDevice);

                if ((videoInputCollection != null) && (videoInputCollection.Count > 0))
                {
                    foreach (FilterInfo videoDevice in videoInputCollection)
                    {
                        WebCamInfo += $"{videoDevice.Name}\n";
                    }
                }

                return(new SupportInfoElement()
                {
                    Name = "Webcam", Value = WebCamInfo, Number = number, Column = col
                });
            }

            if (sit == SupportInfotype.AudioOutDevices)
            {
                // Audio

                string AudioOutInfo = string.Empty;


                try
                {
                    for (int i = -1; i < WaveOut.DeviceCount; i++)
                    {
                        var c = WaveOut.GetCapabilities(i);
                        AudioOutInfo += c.ProductName + "\n";
                    }
                }
                catch { }

                return(new SupportInfoElement()
                {
                    Name = "Audio (Out)", Value = AudioOutInfo, Number = number, Column = col
                });
            }

            if (sit == SupportInfotype.AudioInDevices)
            {
                string AudioInInfo = string.Empty;

                try
                {
                    for (int i = -1; i < WaveIn.DeviceCount; i++)
                    {
                        var c = WaveIn.GetCapabilities(i);
                        AudioInInfo += c.ProductName + "\n";
                    }
                }
                catch { }

                return(new SupportInfoElement()
                {
                    Name = "Audio (In)", Value = AudioInInfo, Number = number, Column = col
                });
            }

            if (sit == SupportInfotype.GraphicsCard)
            {
                // Grafik

                List <GraphicsAdapter> G = new List <GraphicsAdapter>();

                try
                {
                    ManagementClass            cs  = new ManagementClass("win32_videocontroller");
                    ManagementObjectCollection moc = cs.GetInstances();
                    if (moc.Count != 0)
                    {
                        foreach (ManagementObject MO in cs.GetInstances())
                        {
                            G.Add(new GraphicsAdapter()
                            {
                                Name          = MO.Properties["Name"].Value.ToString(),
                                DriverVersion = MO.Properties["DriverVersion"].Value.ToString()
                            });
                        }
                    }
                }
                catch { }

                return(new SupportInfoElement()
                {
                    Name = "Grafikkarte", Value = string.Join("\n", G.Select(x => x.ToString())), Number = number, Column = col
                });
            }

            if (sit == SupportInfotype.Display)
            {
                List <DisplayInfo> D = new List <DisplayInfo>();

                try
                {
                    ManagementClass            cs  = new ManagementClass("win32_desktopmonitor");
                    ManagementObjectCollection moc = cs.GetInstances();
                    if (moc.Count != 0)
                    {
                        foreach (ManagementObject MO in cs.GetInstances())
                        {
                            D.Add(new DisplayInfo()
                            {
                                Manufacturer = MO.Properties["MonitorManufacturer"].Value != null ? MO.Properties["MonitorManufacturer"].Value.ToString() : string.Empty,
                                Name         = MO.Properties["MonitorType"].Value != null ? MO.Properties["MonitorType"].Value.ToString() : string.Empty
                            });
                        }
                    }
                }
                catch { }

                return(new SupportInfoElement()
                {
                    Name = "Monitor",
                    Value = string.Join("\n", D.Select(x => x.ToString())),
                    Number = number,
                    Column = col
                });
            }

            if (sit == SupportInfotype.Bitlocker)
            {
                // Bitlocker

                var bitLocker = string.Empty;

                IShellProperty prop = ShellObject.FromParsingName("C:").Properties.GetProperty("System.Volume.BitLockerProtection");
                int?           bitLockerProtectionStatus = (prop as ShellProperty <int?>).Value;

                if (bitLockerProtectionStatus.HasValue && (bitLockerProtectionStatus == 1 || bitLockerProtectionStatus == 3 || bitLockerProtectionStatus == 5))
                {
                    bitLocker = "Ein";
                }
                else
                {
                    bitLocker = "Aus";
                }

                return(new SupportInfoElement()
                {
                    Name = "Bitlocker (C:)", Value = bitLocker, Number = number, Column = col
                });
            }

            return(null);
        }