简体   繁体   English

uid列表/“系统偏好设置”>“帐户”的名称

[英]list of uids / names of System Preferences > Accounts

How can I obtain an array with uid and names? 如何获得具有uid和名称的数组?

I could iterate from 0 to 99999 and do a getpwnam() . 我可以从0迭代到99999并执行getpwnam() However most machines have less than 5 accounts, so it's not optimal. 但是,大多数计算机的帐户少于5个,因此并非最佳选择。 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. 编辑:在我发布后,我发现遍历帐户的getpwent()

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. 编辑:我已经找到了等效的命令行, 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

Use getgrnam("staff") to get a group record for the staff group. 使用getgrnam("staff")获取人员组的组记录。 The gr_mem member, while not explained in detail by the manpage, appears to be an array of user names terminated by a NULL pointer. gr_mem成员虽然没有在手册页中进行详细说明,但似乎是由NULL指针终止的用户名数组。

To find which users are administrators, do the same thing with the admin group. 要查找哪些用户是管理员,请对admin组执行相同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM