mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-06 16:45:03 +00:00
LibCore: Add query for all accounts and groups
This commit is contained in:
committed by
Andrew Kaster
parent
58e9262ff1
commit
9ddb86f7db
@@ -6,8 +6,10 @@
|
||||
|
||||
#include <AK/CharacterTypes.h>
|
||||
#include <AK/ScopeGuard.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/Group.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <errno.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
@@ -60,6 +62,27 @@ ErrorOr<void> Group::add_group(Group& group)
|
||||
}
|
||||
#endif
|
||||
|
||||
ErrorOr<Vector<Group>> Group::all()
|
||||
{
|
||||
Vector<Group> groups;
|
||||
|
||||
ScopeGuard grent_guard([] { endgrent(); });
|
||||
setgrent();
|
||||
errno = 0;
|
||||
for (auto const* gr = getgrent(); gr; gr = getgrent()) {
|
||||
Vector<String> members;
|
||||
for (size_t i = 0; gr->gr_mem[i]; ++i)
|
||||
members.append(*gr->gr_mem);
|
||||
|
||||
groups.append({ gr->gr_name, gr->gr_gid, members });
|
||||
}
|
||||
|
||||
if (errno)
|
||||
return Error::from_errno(errno);
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
Group::Group(String name, gid_t id, Vector<String> members)
|
||||
: m_name(move(name))
|
||||
, m_id(id)
|
||||
|
||||
Reference in New Issue
Block a user