项目作者: gebn

项目描述 :
An improved implementation of members(1)
高级语言: C
项目地址: git://github.com/gebn/members.git
创建时间: 2017-02-08T10:25:07Z
项目社区:https://github.com/gebn/members

开源协议:GNU General Public License v3.0

下载


members

Build Status
Coverity Scan Build Status

A patched drop-in replacement of members(1), a tool for finding users in a group.

Examples

  1. $ members audio
  2. speech-dispatcher pulse george
  3. $ members -p audio
  4. speech-dispatcher
  5. $ members -s audio
  6. pulse george
  7. $ members -t audio
  8. speech-dispatcher
  9. pulse george

Motivation

I started using members(1) to help verify an OpenLDAP directory, but its output did not seem plausible. I took a look at the source, and noticed a glaring bug causing the first primary member of a group (in terms of getent passwd) to always be missed out:

  1. if(theGroup)
  2. {
  3. struct passwd *thePasswd;
  4. setpwent();
  5. thePasswd = getpwent();
  6. if(thePasswd)
  7. {
  8. thePasswd = getpwent(); // overwrites the first entity
  9. while(thePasswd)
  10. {
  11. // ...
  12. thePasswd = getpwent();
  13. }
  14. }
  15. endpwent();
  16. // ...
  17. }

Instead of creating a patch, I realised I’d stumbled across a languishing package not modified since 2008, with a man page not touched since 1999. It was 363 lines of C++ written in the style of C, with negative indentation and lots of unnecessary complexity (especially with regard to options parsing). So I rewrote it.

This repository is the result. I used pure, modern C to match the underlying APIs (pwd.h, grp.h). Ignoring documentation (which the original was heavily lacking), code footprint has simultaneously been reduced by 35% to 235 lines.

Usage

  1. $ members --help
  2. Usage: members [OPTION]... GROUP
  3. Show members of a group.
  4. members(1) is the complement of groups(1): where groups(1) shows the groups a
  5. user belongs to, members(1) shows users belonging to a group.
  6. -p, --primary show only members for which GROUP is their
  7. primary group
  8. -s, --secondary show only members who have a secondary
  9. membership in GROUP
  10. -t, --two-lines show primary members on the first line of output
  11. and secondary members on the second line; two
  12. lines are always printed
  13. -h, --help display this help and exit
  14. -v, --version output version information and exit
  15. Exit status:
  16. 0 OK
  17. 1 input error (e.g. no GROUP, unrecognised flag)
  18. 2 GROUP does not exist
  19. 3 GROUP exists but could not be opened (see error message)
  20. 4 GROUP did not have any members