2 * Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
14 #include <RegistrarDefs.h>
15 #include <user_group.h>
16 #include <util/KMessage.h>
18 #include "multiuser_utils.h"
21 extern const char *__progname
;
24 static const char* kUsage
=
25 "Usage: %s [ <options> ] <group name>\n"
26 "Deletes the specified group.\n"
30 " Print usage info.\n"
34 print_usage_and_exit(bool error
)
36 fprintf(error
? stderr
: stdout
, kUsage
, __progname
);
42 main(int argc
, const char* const* argv
)
45 static struct option sLongOptions
[] = {
46 { "help", no_argument
, 0, 'h' },
50 opterr
= 0; // don't print errors
51 int c
= getopt_long(argc
, (char**)argv
, "h", sLongOptions
, NULL
);
58 print_usage_and_exit(false);
62 print_usage_and_exit(true);
67 if (optind
!= argc
- 1)
68 print_usage_and_exit(true);
70 const char* group
= argv
[optind
];
73 fprintf(stderr
, "Error: Only root may delete groups.\n");
77 if (getgrnam(group
) == NULL
) {
78 fprintf(stderr
, "Error: Group \"%s\" doesn't exists.\n", group
);
82 // prepare request for the registrar
83 KMessage
message(BPrivate::B_REG_DELETE_GROUP
);
84 if (message
.AddString("name", group
) != B_OK
) {
85 fprintf(stderr
, "Error: Out of memory!\n");
91 status_t error
= send_authentication_request_to_registrar(message
, reply
);
93 fprintf(stderr
, "Error: Failed to delete group: %s\n", strerror(error
));