Split process_flags() out of main().
This commit is contained in:
parent
4af02cb083
commit
7ed7e14dee
@ -1,3 +1,7 @@
|
||||
2007-12-31 Nicolas François <nicolas.francois@centraliens.net>
|
||||
|
||||
* src/chsh.c: Split process_flags() out of main().
|
||||
|
||||
2007-12-31 Nicolas François <nicolas.francois@centraliens.net>
|
||||
|
||||
* src/chfn.c: New function: process_flags() split out of main().
|
||||
|
79
src/chsh.c
79
src/chsh.c
@ -71,6 +71,7 @@ static void usage (void);
|
||||
static void new_fields (void);
|
||||
static int check_shell (const char *);
|
||||
static int restricted_shell (const char *);
|
||||
static void process_flags (int argc, char **argv);
|
||||
|
||||
/*
|
||||
* usage - print command line syntax and exit
|
||||
@ -167,6 +168,46 @@ static int check_shell (const char *sh)
|
||||
return found;
|
||||
}
|
||||
|
||||
/*
|
||||
* * process_flags - parse the command line options
|
||||
*
|
||||
* It will not return if an error is encountered.
|
||||
*/
|
||||
static void process_flags (int argc, char **argv)
|
||||
{
|
||||
int option_index = 0;
|
||||
int c;
|
||||
static struct option long_options[] = {
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"shell", required_argument, NULL, 's'},
|
||||
{NULL, 0, NULL, '\0'}
|
||||
};
|
||||
|
||||
while ((c =
|
||||
getopt_long (argc, argv, "hs:", long_options,
|
||||
&option_index)) != -1) {
|
||||
switch (c) {
|
||||
case 'h':
|
||||
usage ();
|
||||
break;
|
||||
case 's':
|
||||
sflg++;
|
||||
STRFCPY (loginsh, optarg);
|
||||
break;
|
||||
default:
|
||||
usage ();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* There should be only one remaining argument at most and it should
|
||||
* be the user's name.
|
||||
*/
|
||||
if (argc > (optind + 1)) {
|
||||
usage ();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* chsh - this command controls changes to the user's shell
|
||||
*
|
||||
@ -204,42 +245,8 @@ int main (int argc, char **argv)
|
||||
|
||||
OPENLOG ("chsh");
|
||||
|
||||
/*
|
||||
* There is only one option, but use getopt() anyway to
|
||||
* keep things consistent.
|
||||
*/
|
||||
{
|
||||
int option_index = 0;
|
||||
int c;
|
||||
static struct option long_options[] = {
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"shell", required_argument, NULL, 's'},
|
||||
{NULL, 0, NULL, '\0'}
|
||||
};
|
||||
|
||||
while ((c =
|
||||
getopt_long (argc, argv, "hs:", long_options,
|
||||
&option_index)) != -1) {
|
||||
switch (c) {
|
||||
case 'h':
|
||||
usage ();
|
||||
break;
|
||||
case 's':
|
||||
sflg++;
|
||||
STRFCPY (loginsh, optarg);
|
||||
break;
|
||||
default:
|
||||
usage ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* There should be only one remaining argument at most and it should
|
||||
* be the user's name.
|
||||
*/
|
||||
if (argc > optind + 1)
|
||||
usage ();
|
||||
/* parse the command line options */
|
||||
process_flags (argc, argv);
|
||||
|
||||
/*
|
||||
* Get the name of the user to check. It is either the command line
|
||||
|
Loading…
Reference in New Issue
Block a user