* src/chfn.c, man/chfn.1.xml: Add support for long options.

* src/chfn.c, man/chfn.1.xml: Add -u/--help option
This commit is contained in:
nekral-guest 2011-11-06 18:39:19 +00:00
parent e2068416c9
commit b26f73f427
3 changed files with 118 additions and 36 deletions

View File

@ -1,3 +1,8 @@
2011-10-30 Nicolas François <nicolas.francois@centraliens.net>
* src/chfn.c, man/chfn.1.xml: Add support for long options.
* src/chfn.c, man/chfn.1.xml: Add -u/--help option
2011-10-30 Nicolas François <nicolas.francois@centraliens.net> 2011-10-30 Nicolas François <nicolas.francois@centraliens.net>
* NEWS, src/vipw.c, man/vipw.8.xml: Add --root option. * NEWS, src/vipw.c, man/vipw.8.xml: Add --root option.

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!--
Copyright (c) 1990 - 1994, Julianne Frances Haugh Copyright (c) 1990 - 1994, Julianne Frances Haugh
Copyright (c) 2007 - 2008, Nicolas François Copyright (c) 2007 - 2011, Nicolas François
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
@ -35,7 +35,6 @@
<!ENTITY LOGIN_STRING SYSTEM "login.defs.d/LOGIN_STRING.xml"> <!ENTITY LOGIN_STRING SYSTEM "login.defs.d/LOGIN_STRING.xml">
<!-- SHADOW-CONFIG-HERE --> <!-- SHADOW-CONFIG-HERE -->
]> ]>
<refentry id='chfn.1'> <refentry id='chfn.1'>
<!-- $Id$ --> <!-- $Id$ -->
<refmeta> <refmeta>
@ -53,12 +52,12 @@
<refsynopsisdiv id='synopsis'> <refsynopsisdiv id='synopsis'>
<cmdsynopsis> <cmdsynopsis>
<command>chfn</command> <command>chfn</command>
<arg choice='opt'>-f <replaceable>full_name</replaceable></arg> <arg choice='opt'>
<arg choice='opt'>-r <replaceable>room_no</replaceable></arg> <replaceable>options</replaceable>
<arg choice='opt'>-w <replaceable>work_ph</replaceable></arg> </arg>
<arg choice='opt'>-h <replaceable>home_ph</replaceable></arg> <arg choice='opt'>
<arg choice='opt'>-o <replaceable>other</replaceable></arg> <replaceable>LOGIN</replaceable>
<arg choice='opt'><replaceable>user</replaceable></arg> </arg>
</cmdsynopsis> </cmdsynopsis>
</refsynopsisdiv> </refsynopsisdiv>
@ -66,7 +65,7 @@
<title>DESCRIPTION</title> <title>DESCRIPTION</title>
<para> <para>
The <command>chfn</command> command changes user fullname, The <command>chfn</command> command changes user fullname,
office number, office extension, and home phone number information office room number, office phone number, and home phone number information
for a user's account. This information is typically printed by for a user's account. This information is typically printed by
<citerefentry><refentrytitle>finger</refentrytitle><manvolnum>1</manvolnum> <citerefentry><refentrytitle>finger</refentrytitle><manvolnum>1</manvolnum>
</citerefentry> and similar programs. A normal user may only change </citerefentry> and similar programs. A normal user may only change
@ -87,6 +86,67 @@
store accounting information used by other applications. store accounting information used by other applications.
</para> </para>
</refsect1>
<refsect1 id='options'>
<title>OPTIONS</title>
<para>
The options which apply to the <command>chfn</command> command are:
</para>
<variablelist remap='IP'>
<varlistentry>
<term>
<option>-f</option>, <option>--full-name</option> <replaceable>FULL_NAME</replaceable>
</term>
<listitem>
<para>Change the user's full name.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-h</option>, <option>--home-phone</option> <replaceable>HOME_PHONE</replaceable>
</term>
<listitem>
<para>Change the user's home phone number.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-o</option>, <option>--other</option> <replaceable>OTHER</replaceable>
</term>
<listitem>
<para>
Change the user's other GECOS information. This field is used to
store accounting information used by other applications, and can
be changed only by a superuser.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-r</option>, <option>--room</option> <replaceable>ROOM_NUMBER</replaceable>
</term>
<listitem>
<para>Change the user's room number.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-u</option>, <option>--help</option>
</term>
<listitem>
<para>Display help message and exit.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-w</option>, <option>--work-phone</option> <replaceable>WORK_PHONE</replaceable>
</term>
<listitem>
<para>Change the user's office phone number.</para>
</listitem>
</varlistentry>
</variablelist>
<para> <para>
If none of the options are selected, <command>chfn</command> If none of the options are selected, <command>chfn</command>
operates in an interactive fashion, prompting the user with the operates in an interactive fashion, prompting the user with the

View File

@ -2,7 +2,7 @@
* Copyright (c) 1989 - 1994, Julianne Frances Haugh * Copyright (c) 1989 - 1994, Julianne Frances Haugh
* Copyright (c) 1996 - 2000, Marek Michałkiewicz * Copyright (c) 1996 - 2000, Marek Michałkiewicz
* Copyright (c) 2001 - 2006, Tomasz Kłoczko * Copyright (c) 2001 - 2006, Tomasz Kłoczko
* Copyright (c) 2007 - 2008, Nicolas François * Copyright (c) 2007 - 2011, Nicolas François
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -39,6 +39,7 @@
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <getopt.h>
#ifdef WITH_SELINUX #ifdef WITH_SELINUX
#include <selinux/selinux.h> #include <selinux/selinux.h>
#include <selinux/av_permissions.h> #include <selinux/av_permissions.h>
@ -79,7 +80,7 @@ static bool pw_locked = false;
/* local function prototypes */ /* local function prototypes */
static void fail_exit (int code); static void fail_exit (int code);
static void usage (void); static /*@noreturn@*/void usage (int status);
static bool may_change_field (int); static bool may_change_field (int);
static void new_fields (void); static void new_fields (void);
static char *copy_field (char *, char *, char *); static char *copy_field (char *, char *, char *);
@ -110,19 +111,22 @@ static void fail_exit (int code)
/* /*
* usage - print command line syntax and exit * usage - print command line syntax and exit
*/ */
static void usage (void) static /*@noreturn@*/void usage (int status)
{ {
if (amroot) { FILE *usageout = (E_SUCCESS != status) ? stderr : stdout;
fprintf (stderr, (void) fprintf (usageout,
_("Usage: %s [-f full_name] [-r room_no] " _("Usage: %s [options] [LOGIN]\n"
"[-w work_ph]\n" "\n"
"\t[-h home_ph] [-o other] [user]\n"), Prog); "Options:\n"),
} else { Prog);
fprintf (stderr, (void) fputs (_(" -f, --full-name FULL_NAME change user's full name\n"), usageout);
_("Usage: %s [-f full_name] [-r room_no] " (void) fputs (_(" -h, --home-phone HOME_PHONE change user's home phone number\n"), usageout);
"[-w work_ph] [-h home_ph]\n"), Prog); (void) fputs (_(" -o, --other OTHER_INFO change user's other GECOS information\n"), usageout);
} (void) fputs (_(" -r, --room ROOM_NUMBER change user's room number\n"), usageout);
exit (E_USAGE); (void) fputs (_(" -u, --help display this help message and exit\n"), usageout);
(void) fputs (_(" -w, --work-phone WORK_PHONE change user's office phone number\n"), usageout);
(void) fputs ("\n", usageout);
exit (status);
} }
/* /*
@ -262,7 +266,16 @@ static char *copy_field (char *in, char *out, char *extra)
*/ */
static void process_flags (int argc, char **argv) static void process_flags (int argc, char **argv)
{ {
int flag; /* flag currently being processed */ int c; /* flag currently being processed */
static struct option long_options[] = {
{"full-name", required_argument, NULL, 'f'},
{"home-phone", required_argument, NULL, 'h'},
{"other", required_argument, NULL, 'o'},
{"room", required_argument, NULL, 'r'},
{"help", no_argument, NULL, 'u'},
{"work-phone", required_argument, NULL, 'w'},
{NULL, 0, NULL, '\0'}
};
/* /*
* The remaining arguments will be processed one by one and executed * The remaining arguments will be processed one by one and executed
@ -271,8 +284,9 @@ static void process_flags (int argc, char **argv)
* environment and must agree with the real UID. Also, the UID will * environment and must agree with the real UID. Also, the UID will
* be checked for any commands which are restricted to root only. * be checked for any commands which are restricted to root only.
*/ */
while ((flag = getopt (argc, argv, "f:r:w:h:o:")) != EOF) { while ((c = getopt_long (argc, argv, "f:h:o:r:uw:",
switch (flag) { long_options, NULL)) != -1) {
switch (c) {
case 'f': case 'f':
if (!may_change_field ('f')) { if (!may_change_field ('f')) {
fprintf (stderr, fprintf (stderr,
@ -291,15 +305,6 @@ static void process_flags (int argc, char **argv)
hflg = true; hflg = true;
STRFCPY (homeph, optarg); STRFCPY (homeph, optarg);
break; break;
case 'r':
if (!may_change_field ('r')) {
fprintf (stderr,
_("%s: Permission denied.\n"), Prog);
exit (E_NOPERM);
}
rflg = true;
STRFCPY (roomno, optarg);
break;
case 'o': case 'o':
if (!amroot) { if (!amroot) {
fprintf (stderr, fprintf (stderr,
@ -309,6 +314,18 @@ static void process_flags (int argc, char **argv)
oflg = true; oflg = true;
STRFCPY (slop, optarg); STRFCPY (slop, optarg);
break; break;
case 'r':
if (!may_change_field ('r')) {
fprintf (stderr,
_("%s: Permission denied.\n"), Prog);
exit (E_NOPERM);
}
rflg = true;
STRFCPY (roomno, optarg);
break;
case 'u':
usage (E_SUCCESS);
/*@notreached@*/break;
case 'w': case 'w':
if (!may_change_field ('w')) { if (!may_change_field ('w')) {
fprintf (stderr, fprintf (stderr,
@ -319,7 +336,7 @@ static void process_flags (int argc, char **argv)
STRFCPY (workph, optarg); STRFCPY (workph, optarg);
break; break;
default: default:
usage (); usage (E_USAGE);
} }
} }
} }