6
Copyright (C) Jakub Hrozek <jhrozek@redhat.com> 2009
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 3 of the License, or
11
(at your option) any later version.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program. If not, see <http://www.gnu.org/licenses/>.
28
#include "util/util.h"
29
#include "tools/tools_util.h"
30
#include "tools/sss_sync_ops.h"
32
int main(int argc, const char **argv)
34
int ret = EXIT_SUCCESS;
36
const char *pc_groupname = NULL;
37
struct tools_ctx *tctx = NULL;
39
poptContext pc = NULL;
40
struct poptOption long_options[] = {
42
{ "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug,
43
0, _("The debug level to run with"), NULL },
47
debug_prg_name = argv[0];
51
DEBUG(1, ("set_locale failed (%d): %s\n", ret, strerror(ret)));
52
ERROR("Error setting the locale\n");
58
pc = poptGetContext(NULL, argc, argv, long_options, 0);
59
poptSetOtherOptionHelp(pc, "GROUPNAME");
60
if ((ret = poptGetNextOpt(pc)) < -1) {
61
usage(pc, poptStrerror(ret));
66
debug_level = pc_debug;
68
pc_groupname = poptGetArg(pc);
69
if (pc_groupname == NULL) {
70
usage(pc, _("Specify group to delete\n"));
75
CHECK_ROOT(ret, debug_prg_name);
77
ret = init_sss_tools(&tctx);
79
DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret)));
81
ERROR("Error initializing the tools - no local domain\n");
83
ERROR("Error initializing the tools\n");
89
/* if the domain was not given as part of FQDN, default to local domain */
90
ret = parse_name_domain(tctx, pc_groupname);
92
ERROR("Invalid domain specified in FQDN\n");
97
ret = sysdb_getgrnam_sync(tctx, tctx->ev, tctx->sysdb,
98
tctx->octx->name, tctx->local,
101
/* Error message will be printed in the switch */
105
if ((tctx->octx->gid < tctx->local->id_min) ||
106
(tctx->local->id_max && tctx->octx->gid > tctx->local->id_max)) {
107
ERROR("Group %s is outside the defined ID range for domain\n",
113
start_transaction(tctx);
114
if (tctx->error != EOK) {
119
ret = groupdel(tctx, tctx->ev, tctx->sysdb, tctx->handle, tctx->octx);
123
/* cancel transaction */
124
talloc_zfree(tctx->handle);
128
end_transaction(tctx);
133
DEBUG(1, ("sysdb operation failed (%d)[%s]\n", ret, strerror(ret)));
136
ERROR("No such group in local domain. "
137
"Removing groups only allowed in local domain.\n");
141
ERROR("Internal error. Could not remove group.\n");