1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/*
* Copyright (C) 2000-2002 Red Hat, Inc.
*
* This is free software; you can redistribute it and/or modify it under
* the terms of the GNU Library General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <libintl.h>
#include <locale.h>
#include <popt.h>
#include "../lib/user.h"
#include "apputil.h"
int
main(int argc, const char **argv)
{
struct lu_context *ctx;
struct lu_ent *ent;
struct lu_error *error = NULL;
const char *group;
int interactive = FALSE;
int c;
poptContext popt;
struct poptOption options[] = {
{"interactive", 'i', POPT_ARG_NONE, &interactive, 0,
"prompt for all information", NULL},
POPT_AUTOHELP POPT_TABLEEND
};
/* Set up for i18n. */
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
setlocale(LC_ALL, "");
/* Parse arguments. */
popt = poptGetContext("lgroupdel", argc, argv, options, 0);
poptSetOtherOptionHelp(popt, _("[OPTION...] group"));
c = poptGetNextOpt(popt);
if (c != -1) {
fprintf(stderr, _("Error parsing arguments: %s.\n"),
poptStrerror(c));
poptPrintUsage(popt, stderr, 0);
exit(1);
}
group = poptGetArg(popt);
/* The caller has to specify a group name. */
if (group == NULL) {
fprintf(stderr, _("No group name specified.\n"));
poptPrintUsage(popt, stderr, 0);
return 1;
}
/* Start up the library. */
ctx = lu_start(NULL, 0, NULL, NULL,
interactive ? lu_prompt_console :
lu_prompt_console_quiet, NULL, &error);
if (ctx == NULL) {
fprintf(stderr, _("Error initializing %s: %s.\n"), PACKAGE,
lu_strerror(error));
return 1;
}
/* Look up the group structure. */
ent = lu_ent_new();
if (lu_group_lookup_name(ctx, group, ent, &error) == FALSE) {
fprintf(stderr, _("Group %s does not exist.\n"), group);
return 2;
}
/* Delete the group. */
if (lu_group_delete(ctx, ent, &error) == FALSE) {
fprintf(stderr, _("Group %s could not be deleted: %s\n"),
group, lu_strerror(error));
return 3;
}
lu_hup_nscd();
lu_ent_free(ent);
lu_end(ctx);
return 0;
}
|