系统偏好设置的 uids/名称列表 >账户
如何获取包含 uid 和名称的数组?
我可以从 0 迭代到 99999 并执行 getpwnam()
。 然而,大多数机器的帐户数量少于 5 个,因此这不是最佳选择。我不知道哪个框架负责此操作,因此我不知道要搜索什么。
有没有更优化的方案可以遍历账户呢?
编辑:在我发布后,我发现了用于遍历帐户的 getpwent()
。
setpwent();
struct passwd *pw;
while ((pw = getpwent())) printf("%d\n", pw->pw_uid);
endpwent();
但是,这并不表明帐户是否是系统偏好设置帐户。
那么如何获取系统偏好设置帐户呢?
编辑:我找到了与此等效的命令行,即 dscl 命令。
prompt> dscl . -list /Users UniqueID
_mysql 74
_postfix 27
_spotlight 89
_sshd 75
_windowserver 88
_www 70
daemon 1
johndoe 501
nobody -2
root 0
How can I obtain an array with uid and names?
I could iterate from 0 to 99999 and do a getpwnam()
.
However most machines have less than 5 accounts, so it's not optimal. I don't know what framework is responsible for this and thus I have no clue what to search for.
Is there a more optimal solution that can traverse the accounts?
Edit: Right after I posted I discovered getpwent()
for traversing accounts.
setpwent();
struct passwd *pw;
while ((pw = getpwent())) printf("%d\n", pw->pw_uid);
endpwent();
However that doesn't indicate wether an account is a System Preferences account or not.
So still how does one obtain the System Preferences accounts?
Edit: I have found the commandline equivalent of this, the dscl
command.
prompt> dscl . -list /Users UniqueID
_mysql 74
_postfix 27
_spotlight 89
_sshd 75
_windowserver 88
_www 70
daemon 1
johndoe 501
nobody -2
root 0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
getgrnam("staff")
获取员工组的组记录。 gr_mem 成员虽然手册页中没有详细解释,但它似乎是一个以 NULL 指针结尾的用户名数组。要查找哪些用户是管理员,请对管理员组执行相同的操作。
Use
getgrnam("staff")
to get a group record for the staff group. Thegr_mem
member, while not explained in detail by the manpage, appears to be an array of user names terminated by a NULL pointer.To find which users are administrators, do the same thing with the admin group.