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:
parent
58e9262ff1
commit
9ddb86f7db
Notes:
sideshowbarker
2024-07-17 04:30:45 +09:00
Author: https://github.com/ne0ndrag0n
Commit: 9ddb86f7db
Pull-request: https://github.com/SerenityOS/serenity/pull/15965
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/FireFox317
Reviewed-by: https://github.com/awesomekling
4 changed files with 66 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue