2
* Copyright (C) 2000-2002, 2004 Red Hat, Inc.
4
* This is free software; you can redistribute it and/or modify it under
5
* the terms of the GNU Library General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* General Public License for more details.
14
* You should have received a copy of the GNU Library General Public
15
* License along with this program; if not, write to the Free Software
16
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
#ident "$Id: lgroupadd.c,v 1.28 2004/11/13 23:50:28 mitr Exp $"
33
#include "../lib/user_private.h"
37
main(int argc, const char **argv)
39
const char *name = NULL, *gid_number_str = NULL;
40
gid_t gidNumber = LU_VALUE_INVALID_ID;
41
struct lu_context *ctx = NULL;
42
struct lu_ent *ent = NULL;
43
struct lu_error *error = NULL;
44
int interactive = FALSE;
45
int system_account = FALSE;
49
struct poptOption options[] = {
50
{"interactive", 'i', POPT_ARG_NONE, &interactive, 0,
51
"prompt for all information", NULL},
52
{"gid", 'g', POPT_ARG_STRING, &gid_number_str, 0,
53
"gid to force for new group", "NUM"},
54
{"reserved", 'r', POPT_ARG_NONE, &system_account, 0,
55
"make this a system group", NULL},
56
POPT_AUTOHELP POPT_TABLEEND
60
bindtextdomain(PACKAGE, LOCALEDIR);
62
setlocale(LC_ALL, "");
64
/* Parse arguments. */
65
popt = poptGetContext("lgroupadd", argc, argv, options, 0);
66
poptSetOtherOptionHelp(popt, _("[OPTION...] group"));
67
c = poptGetNextOpt(popt);
69
fprintf(stderr, _("Error parsing arguments: %s.\n"),
71
poptPrintUsage(popt, stderr, 0);
74
name = poptGetArg(popt);
76
/* We require a group name to be specified. */
78
fprintf(stderr, _("No group name specified.\n"));
79
poptPrintUsage(popt, stderr, 0);
83
if (gid_number_str != NULL) {
88
val = strtoimax(gid_number_str, &p, 10);
89
if (errno != 0 || *p != 0 || p == gid_number_str
90
|| (gid_t)val != val) {
91
fprintf(stderr, _("Invalid group ID %s\n"),
93
poptPrintUsage(popt, stderr, 0);
99
/* Start up the library. */
100
ctx = lu_start(NULL, 0, NULL, NULL,
101
interactive ? lu_prompt_console :
102
lu_prompt_console_quiet, NULL, &error);
104
fprintf(stderr, _("Error initializing %s: %s.\n"), PACKAGE,
109
/* Create a group entity object holding sensible defaults for a
112
lu_group_default(ctx, name, system_account, ent);
114
/* If the user specified a particular GID number, override the
116
if (gidNumber != LU_VALUE_INVALID_ID) {
119
memset(&value, 0, sizeof(value));
120
lu_value_init_set_id(&value, gidNumber);
121
lu_ent_clear(ent, LU_GIDNUMBER);
122
lu_ent_add(ent, LU_GIDNUMBER, &value);
123
g_value_unset(&value);
126
/* Try to create the group. */
127
if (lu_group_add(ctx, ent, &error) == FALSE) {
128
fprintf(stderr, _("Group creation failed: %s\n"),