[Category("AndroidNotWorking")] // API 21 conditionally has setgrent in the NDK headers, but bionic doesn't export it public void NonReentrantSyscalls() { var seen = new Dictionary <string, object> (); foreach (UnixGroupInfo group in UnixGroupInfo.GetLocalGroups()) { if (seen.ContainsKey(group.GroupName)) { continue; } seen.Add(group.GroupName, null); try { Group byName = Syscall.getgrnam(group.GroupName); Group byId = Syscall.getgrgid((uint)group.GroupId); Assert.IsNotNull(byName, "#TNRS: access by name"); Assert.IsNotNull(byId, "#TNRS: access by gid"); UnixGroupInfo n = new UnixGroupInfo(byName); UnixGroupInfo u = new UnixGroupInfo(byId); Assert.AreEqual(group, n, "#TNRS: construct by name"); Assert.AreEqual(group, u, "#TNRS: construct by gid"); Assert.AreEqual(n, u, "#TNRS: name == gid?"); } catch (Exception e) { Assert.Fail( string.Format("#TRC: Exception constructing UnixGroupInfo: {0}", e.ToString())); } } }
/// <summary> /// Create a principal for a Unix user. /// </summary> /// <param name="userInfo">The user information.</param> /// <returns>The claims principal.</returns> public static ClaimsPrincipal CreateUnixPrincipal(UnixUserInfo userInfo) { var groups = UnixGroupInfo.GetLocalGroups(); var userGroups = groups .Where(x => x.GetMemberNames().Any(memberName => memberName == userInfo.UserName)) .ToList(); var claims = new List <Claim>() { new Claim(ClaimsIdentity.DefaultNameClaimType, userInfo.GroupName), new Claim(FtpClaimTypes.UserId, userInfo.UserId.ToString(CultureInfo.InvariantCulture), ClaimValueTypes.Integer64), new Claim(ClaimTypes.AuthenticationMethod, "pam"), }; if (!string.IsNullOrWhiteSpace(userInfo.HomeDirectory)) { claims.Add(new Claim(FtpClaimTypes.HomePath, userInfo.HomeDirectory)); } foreach (var userGroup in userGroups) { claims.Add(new Claim(FtpClaimTypes.GroupId, userGroup.GroupId.ToString(CultureInfo.InvariantCulture), ClaimValueTypes.Integer64)); claims.Add(new Claim(ClaimsIdentity.DefaultRoleClaimType, userGroup.GroupName)); } return(new ClaimsPrincipal(new ClaimsIdentity(claims, "pam"))); }
[Category("AndroidNotWorking")] // API 21 conditionally has setgrent in the NDK headers, but bionic doesn't export it public void ReentrantConstructors() { var seen = new Dictionary <string, object> (); foreach (UnixGroupInfo group in UnixGroupInfo.GetLocalGroups()) { if (seen.ContainsKey(group.GroupName)) { continue; } seen.Add(group.GroupName, null); try { UnixGroupInfo byName = new UnixGroupInfo(group.GroupName); UnixGroupInfo byId = new UnixGroupInfo(group.GroupId); Assert.AreEqual(group, byName, "#TRC: construct by name"); Assert.AreEqual(group, byId, "#TRC: construct by gid"); Assert.AreEqual(byName, byId, "#TRC: name == gid?"); } catch (Exception e) { Assert.Fail( string.Format("#TRC: Exception constructing UnixGroupInfo: {0}", e.ToString())); } } }
public void NonReentrantSyscalls() { foreach (UnixGroupInfo group in UnixGroupInfo.GetLocalGroups()) { try { Group byName = Syscall.getgrnam(group.GroupName); Group byId = Syscall.getgrgid((uint)group.GroupId); Assert.IsNotNull(byName, "#TNRS: access by name"); Assert.IsNotNull(byId, "#TNRS: access by gid"); UnixGroupInfo n = new UnixGroupInfo(byName); UnixGroupInfo u = new UnixGroupInfo(byId); Assert.AreEqual(group, n, "#TNRS: construct by name"); Assert.AreEqual(group, u, "#TNRS: construct by gid"); Assert.AreEqual(n, u, "#TNRS: name == gid?"); } catch (Exception e) { Assert.Fail( string.Format("#TRC: Exception constructing UnixGroupInfo: {0}", e.ToString())); } } }
public RootUserInfo() { var currentUser = UnixUserInfo.GetRealUser(); Info = currentUser; IsUserRoot = currentUser.UserId == 0; var rootGroup = new UnixGroupInfo(0); IsGroupRoot = rootGroup.GetMembers().Any(x => x.UserId == currentUser.UserId); var groups = UnixGroupInfo.GetLocalGroups(); var sudoGroup = groups.FirstOrDefault(x => x.GroupName == "sudo"); IsSudo = sudoGroup != null && sudoGroup.GetMembers().Any(x => x.UserId == currentUser.UserId); }
[Category("AndroidNotWorking")] // API 21 conditionally has setgrent in the NDK headers, but bionic doesn't export it public void ListAllGroups_ToString() { try { Console.WriteLine("Listing all groups"); foreach (UnixGroupInfo group in UnixGroupInfo.GetLocalGroups()) { Console.WriteLine("\t{0}", group); } } catch (Exception e) { Assert.Fail( string.Format("#TLAU_TS: Exception listing local groups: {0}", e.ToString())); } }
/// <summary> /// Initializes a new instance of the <see cref="PamFtpUser"/> class. /// </summary> /// <param name="userInfo">The Unix PAM user information.</param> internal PamFtpUser([NotNull] UnixUserInfo userInfo) { var groups = UnixGroupInfo.GetLocalGroups(); var userGroups = groups .Where(x => x.GetMemberNames().Any(memberName => memberName == userInfo.UserName)) .ToList(); _userGroupNames = new HashSet <string>( userGroups.Select(x => x.GroupName), StringComparer.Ordinal); Name = userInfo.UserName; HomeDirectory = userInfo.HomeDirectory; UserId = userInfo.UserId; GroupId = userInfo.GroupId; }
public void ReentrantConstructors() { foreach (UnixGroupInfo group in UnixGroupInfo.GetLocalGroups()) { try { UnixGroupInfo byName = new UnixGroupInfo(group.GroupName); UnixGroupInfo byId = new UnixGroupInfo(group.GroupId); Assert.AreEqual(group, byName, "#TRC: construct by name"); Assert.AreEqual(group, byId, "#TRC: construct by gid"); Assert.AreEqual(byName, byId, "#TRC: name == gid?"); } catch (Exception e) { Assert.Fail( string.Format("#TRC: Exception constructing UnixGroupInfo: {0}", e.ToString())); } } }