1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 18:20:43 +09:00

LibCore: Add query for all accounts and groups

This commit is contained in:
ne0ndrag0n 2022-10-15 00:40:51 -04:00 committed by Andrew Kaster
parent 58e9262ff1
commit 9ddb86f7db
Notes: sideshowbarker 2024-07-17 04:30:45 +09:00
4 changed files with 66 additions and 0 deletions

View file

@ -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)