summaryrefslogtreecommitdiff
path: root/command/groups.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--command/groups.c (renamed from src/commands/groups.c)31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/commands/groups.c b/command/groups.c
index bd2e5f9..cb950be 100644
--- a/src/commands/groups.c
+++ b/command/groups.c
@@ -1,20 +1,41 @@
-#include "../command.h"
+#include "args.h"
+#include "command.h"
+#include "lslib.h"
+#include <errno.h>
#include <grp.h>
#include <pwd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
-COMMAND_EMPTY(groups) {
+static void help (void) {
+ printf("Usage: groups [USER]\n\n");
+ printf("Print the groups USER is in\n");
+}
+
+COMMAND(groups) {
uid_t uid;
int ngroups, i;
gid_t* groups;
struct passwd* pw;
- uid = getuid();
+ parse_help(argc, argv, help);
- pw = getpwuid(uid);
+ if (argc < 1) {
+ uid = getuid();
+ pw = getpwuid(uid);
+ } else {
+ pw = getpwnam(argv[0]);
+ }
+
if(pw == NULL){
- error("failed to fetch groups: %s", strerror(errno));
+ if (errno == 0) {
+ error("user not found");
+ } else {
+ error("failed to fetch groups: %s", strerror(errno));
+ }
}
ngroups = 0;