1996-12-09 14:05:35 +00:00
|
|
|
/*-
|
1996-12-10 23:59:04 +00:00
|
|
|
* Copyright (C) 1996
|
|
|
|
* David L. Nugent. All rights reserved.
|
1996-12-09 14:05:35 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
1996-12-10 23:59:04 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer.
|
1996-12-09 14:05:35 +00:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
1996-12-10 23:59:04 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY DAVID L. NUGENT AND CONTRIBUTORS ``AS IS'' AND
|
1996-12-09 14:05:35 +00:00
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
1996-12-10 23:59:04 +00:00
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL DAVID L. NUGENT OR CONTRIBUTORS BE LIABLE
|
1996-12-09 14:05:35 +00:00
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-10-10 06:23:42 +00:00
|
|
|
#ifndef lint
|
|
|
|
static const char rcsid[] =
|
1999-08-28 01:35:59 +00:00
|
|
|
"$FreeBSD$";
|
1997-10-10 06:23:42 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <err.h>
|
1998-08-04 22:31:26 +00:00
|
|
|
#include <fcntl.h>
|
2000-06-22 16:48:41 +00:00
|
|
|
#include <locale.h>
|
1997-01-05 07:15:37 +00:00
|
|
|
#include <paths.h>
|
2015-06-07 14:34:38 +00:00
|
|
|
#include <stdbool.h>
|
1997-01-05 07:15:37 +00:00
|
|
|
#include <sys/wait.h>
|
1999-02-23 07:15:11 +00:00
|
|
|
#include "pw.h"
|
1996-12-09 14:05:35 +00:00
|
|
|
|
2000-01-15 00:20:22 +00:00
|
|
|
#if !defined(_PATH_YP)
|
|
|
|
#define _PATH_YP "/var/yp/"
|
|
|
|
#endif
|
1999-10-26 08:34:09 +00:00
|
|
|
const char *Modes[] = {
|
|
|
|
"add", "del", "mod", "show", "next",
|
|
|
|
NULL};
|
1996-12-09 14:05:35 +00:00
|
|
|
const char *Which[] = {"user", "group", NULL};
|
1996-12-09 23:55:27 +00:00
|
|
|
static const char *Combo1[] = {
|
|
|
|
"useradd", "userdel", "usermod", "usershow", "usernext",
|
1999-10-26 08:34:09 +00:00
|
|
|
"lock", "unlock",
|
1996-12-09 23:55:27 +00:00
|
|
|
"groupadd", "groupdel", "groupmod", "groupshow", "groupnext",
|
|
|
|
NULL};
|
|
|
|
static const char *Combo2[] = {
|
|
|
|
"adduser", "deluser", "moduser", "showuser", "nextuser",
|
1999-10-26 08:34:09 +00:00
|
|
|
"lock", "unlock",
|
1996-12-09 23:55:27 +00:00
|
|
|
"addgroup", "delgroup", "modgroup", "showgroup", "nextgroup",
|
1999-10-26 08:34:09 +00:00
|
|
|
NULL};
|
1996-12-09 14:05:35 +00:00
|
|
|
|
1999-02-23 07:15:11 +00:00
|
|
|
struct pwf PWF =
|
|
|
|
{
|
2015-06-03 19:08:25 +00:00
|
|
|
PWF_REGULAR,
|
1999-02-23 07:15:11 +00:00
|
|
|
setpwent,
|
|
|
|
endpwent,
|
|
|
|
getpwent,
|
|
|
|
getpwuid,
|
|
|
|
getpwnam,
|
|
|
|
setgrent,
|
|
|
|
endgrent,
|
|
|
|
getgrent,
|
|
|
|
getgrgid,
|
|
|
|
getgrnam,
|
|
|
|
|
|
|
|
};
|
|
|
|
struct pwf VPWF =
|
|
|
|
{
|
2015-06-03 19:08:25 +00:00
|
|
|
PWF_ALT,
|
1999-02-23 07:15:11 +00:00
|
|
|
vsetpwent,
|
|
|
|
vendpwent,
|
|
|
|
vgetpwent,
|
|
|
|
vgetpwuid,
|
|
|
|
vgetpwnam,
|
|
|
|
vsetgrent,
|
|
|
|
vendgrent,
|
|
|
|
vgetgrent,
|
|
|
|
vgetgrgid,
|
|
|
|
vgetgrnam,
|
|
|
|
};
|
|
|
|
|
2015-06-07 14:34:38 +00:00
|
|
|
struct pwconf conf;
|
|
|
|
|
1996-12-09 14:05:35 +00:00
|
|
|
static struct cargs arglist;
|
|
|
|
|
|
|
|
static int getindex(const char *words[], const char *word);
|
|
|
|
static void cmdhelp(int mode, int which);
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int ch;
|
|
|
|
int mode = -1;
|
|
|
|
int which = -1;
|
1999-02-23 07:15:11 +00:00
|
|
|
char *config = NULL;
|
2014-11-12 22:27:53 +00:00
|
|
|
struct stat st;
|
2015-06-03 19:08:25 +00:00
|
|
|
char arg;
|
2015-06-07 14:54:07 +00:00
|
|
|
bool relocated, nis;
|
1996-12-09 14:05:35 +00:00
|
|
|
|
|
|
|
static const char *opts[W_NUM][M_NUM] =
|
|
|
|
{
|
1996-12-09 23:55:27 +00:00
|
|
|
{ /* user */
|
2015-06-03 19:08:25 +00:00
|
|
|
"R:V:C:qn:u:c:d:e:p:g:G:mM:k:s:oL:i:w:h:H:Db:NPy:Y",
|
|
|
|
"R:V:C:qn:u:rY",
|
|
|
|
"R:V:C:qn:u:c:d:e:p:g:G:mM:l:k:s:w:L:h:H:FNPY",
|
|
|
|
"R:V:C:qn:u:FPa7",
|
|
|
|
"R:V:C:q",
|
|
|
|
"R:V:C:q",
|
|
|
|
"R:V:C:q"
|
1996-12-09 23:55:27 +00:00
|
|
|
},
|
|
|
|
{ /* grp */
|
2015-06-03 19:08:25 +00:00
|
|
|
"R:V:C:qn:g:h:H:M:opNPY",
|
|
|
|
"R:V:C:qn:g:Y",
|
|
|
|
"R:V:C:qn:d:g:l:h:H:FM:m:NPY",
|
|
|
|
"R:V:C:qn:g:FPa",
|
|
|
|
"R:V:C:q"
|
1996-12-09 23:55:27 +00:00
|
|
|
}
|
1996-12-09 14:05:35 +00:00
|
|
|
};
|
|
|
|
|
2015-06-07 14:34:38 +00:00
|
|
|
static int (*funcs[W_NUM]) (int _mode, struct cargs * _args) =
|
1996-12-09 14:05:35 +00:00
|
|
|
{ /* Request handlers */
|
|
|
|
pw_user,
|
|
|
|
pw_group
|
|
|
|
};
|
|
|
|
|
2015-06-07 14:54:07 +00:00
|
|
|
relocated = nis = false;
|
2015-06-07 14:34:38 +00:00
|
|
|
conf.rootdir[0] = '\0';
|
2015-06-07 15:09:53 +00:00
|
|
|
conf.dryrun = false;
|
2015-06-07 15:27:17 +00:00
|
|
|
conf.pretty = false;
|
2015-06-07 14:34:38 +00:00
|
|
|
strlcpy(conf.etcpath, _PATH_PWD, sizeof(conf.etcpath));
|
|
|
|
|
1996-12-09 14:05:35 +00:00
|
|
|
LIST_INIT(&arglist);
|
|
|
|
|
2000-06-24 13:36:13 +00:00
|
|
|
(void)setlocale(LC_ALL, "");
|
2000-06-22 16:48:41 +00:00
|
|
|
|
1996-12-09 14:05:35 +00:00
|
|
|
/*
|
|
|
|
* Break off the first couple of words to determine what exactly
|
|
|
|
* we're being asked to do
|
|
|
|
*/
|
1999-02-23 07:15:11 +00:00
|
|
|
while (argc > 1) {
|
1996-12-09 14:05:35 +00:00
|
|
|
int tmp;
|
|
|
|
|
1999-02-23 07:15:11 +00:00
|
|
|
if (*argv[1] == '-') {
|
|
|
|
/*
|
|
|
|
* Special case, allow pw -V<dir> <operation> [args] for scripts etc.
|
|
|
|
*/
|
2015-06-03 19:08:25 +00:00
|
|
|
arg = argv[1][1];
|
|
|
|
if (arg == 'V' || arg == 'R') {
|
2015-06-07 14:34:38 +00:00
|
|
|
if (relocated)
|
|
|
|
errx(EXIT_FAILURE, "Both '-R' and '-V' "
|
|
|
|
"specified, only one accepted");
|
|
|
|
relocated = true;
|
1999-02-23 07:15:11 +00:00
|
|
|
optarg = &argv[1][2];
|
|
|
|
if (*optarg == '\0') {
|
2014-11-12 22:27:53 +00:00
|
|
|
if (stat(argv[2], &st) != 0)
|
|
|
|
errx(EX_OSFILE, \
|
|
|
|
"no such directory `%s'",
|
|
|
|
argv[2]);
|
|
|
|
if (!S_ISDIR(st.st_mode))
|
|
|
|
errx(EX_OSFILE, "`%s' not a "
|
|
|
|
"directory", argv[2]);
|
1999-02-23 07:15:11 +00:00
|
|
|
optarg = argv[2];
|
|
|
|
++argv;
|
|
|
|
--argc;
|
|
|
|
}
|
2015-06-07 14:34:38 +00:00
|
|
|
memcpy(&PWF, &VPWF, sizeof PWF);
|
|
|
|
if (arg == 'R') {
|
|
|
|
strlcpy(conf.rootdir, optarg,
|
|
|
|
sizeof(conf.rootdir));
|
|
|
|
PWF._altdir = PWF_ROOTDIR;
|
|
|
|
}
|
|
|
|
snprintf(conf.etcpath, sizeof(conf.etcpath),
|
|
|
|
"%s%s", optarg, arg == 'R' ? "/etc" : "");
|
1999-02-23 10:35:47 +00:00
|
|
|
} else
|
|
|
|
break;
|
1999-02-23 07:15:11 +00:00
|
|
|
}
|
2000-06-18 02:39:17 +00:00
|
|
|
else if (mode == -1 && (tmp = getindex(Modes, argv[1])) != -1)
|
1996-12-09 14:05:35 +00:00
|
|
|
mode = tmp;
|
2000-06-18 02:39:17 +00:00
|
|
|
else if (which == -1 && (tmp = getindex(Which, argv[1])) != -1)
|
1996-12-09 14:05:35 +00:00
|
|
|
which = tmp;
|
2000-06-18 02:39:17 +00:00
|
|
|
else if ((mode == -1 && which == -1) &&
|
|
|
|
((tmp = getindex(Combo1, argv[1])) != -1 ||
|
|
|
|
(tmp = getindex(Combo2, argv[1])) != -1)) {
|
1996-12-09 14:05:35 +00:00
|
|
|
which = tmp / M_NUM;
|
|
|
|
mode = tmp % M_NUM;
|
2000-06-18 02:39:17 +00:00
|
|
|
} else if (strcmp(argv[1], "help") == 0 && argv[2] == NULL)
|
1996-12-09 14:05:35 +00:00
|
|
|
cmdhelp(mode, which);
|
1999-02-23 11:01:50 +00:00
|
|
|
else if (which != -1 && mode != -1)
|
1996-12-09 14:05:35 +00:00
|
|
|
addarg(&arglist, 'n', argv[1]);
|
|
|
|
else
|
1997-10-10 06:23:42 +00:00
|
|
|
errx(EX_USAGE, "unknown keyword `%s'", argv[1]);
|
1996-12-09 14:05:35 +00:00
|
|
|
++argv;
|
|
|
|
--argc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bail out unless the user is specific!
|
|
|
|
*/
|
|
|
|
if (mode == -1 || which == -1)
|
|
|
|
cmdhelp(mode, which);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We know which mode we're in and what we're about to do, so now
|
|
|
|
* let's dispatch the remaining command line args in a genric way.
|
|
|
|
*/
|
|
|
|
optarg = NULL;
|
|
|
|
|
|
|
|
while ((ch = getopt(argc, argv, opts[which][mode])) != -1) {
|
2015-06-07 14:54:07 +00:00
|
|
|
switch (ch) {
|
|
|
|
case '?':
|
2000-01-15 00:20:22 +00:00
|
|
|
errx(EX_USAGE, "unknown switch");
|
2015-06-07 14:54:07 +00:00
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
config = optarg;
|
|
|
|
break;
|
2015-06-07 15:09:53 +00:00
|
|
|
case 'N':
|
|
|
|
conf.dryrun = true;
|
|
|
|
break;
|
2015-06-07 15:27:17 +00:00
|
|
|
case 'P':
|
|
|
|
conf.pretty = true;
|
|
|
|
break;
|
2015-06-07 14:54:07 +00:00
|
|
|
case 'Y':
|
|
|
|
nis = true;
|
|
|
|
break;
|
|
|
|
default:
|
1996-12-09 14:05:35 +00:00
|
|
|
addarg(&arglist, ch, optarg);
|
2015-06-07 14:54:07 +00:00
|
|
|
break;
|
|
|
|
}
|
1996-12-09 14:05:35 +00:00
|
|
|
optarg = NULL;
|
|
|
|
}
|
|
|
|
|
1996-12-09 23:55:27 +00:00
|
|
|
/*
|
|
|
|
* Must be root to attempt an update
|
|
|
|
*/
|
2015-06-07 15:09:53 +00:00
|
|
|
if (geteuid() != 0 && mode != M_PRINT && mode != M_NEXT && !conf.dryrun)
|
1997-10-10 06:23:42 +00:00
|
|
|
errx(EX_NOPERM, "you must be root to run this program");
|
1996-12-09 23:55:27 +00:00
|
|
|
|
1996-12-09 14:05:35 +00:00
|
|
|
/*
|
|
|
|
* We should immediately look for the -q 'quiet' switch so that we
|
|
|
|
* don't bother with extraneous errors
|
|
|
|
*/
|
|
|
|
if (getarg(&arglist, 'q') != NULL)
|
2000-12-09 09:35:55 +00:00
|
|
|
freopen(_PATH_DEVNULL, "w", stderr);
|
1996-12-09 14:05:35 +00:00
|
|
|
|
1999-02-23 07:15:11 +00:00
|
|
|
/*
|
|
|
|
* Set our base working path if not overridden
|
|
|
|
*/
|
|
|
|
|
2015-06-07 14:34:38 +00:00
|
|
|
if (config == NULL) { /* Only override config location if -C not specified */
|
|
|
|
asprintf(&config, "%s/pw.conf", conf.etcpath);
|
|
|
|
if (config == NULL)
|
2015-06-03 19:08:25 +00:00
|
|
|
errx(EX_OSERR, "out of memory");
|
|
|
|
}
|
2008-02-23 01:17:42 +00:00
|
|
|
|
1996-12-09 14:05:35 +00:00
|
|
|
/*
|
|
|
|
* Now, let's do the common initialisation
|
|
|
|
*/
|
2015-06-07 14:34:38 +00:00
|
|
|
conf.userconf = read_userconfig(config);
|
1998-08-04 22:31:26 +00:00
|
|
|
|
2015-06-07 14:34:38 +00:00
|
|
|
ch = funcs[which] (mode, &arglist);
|
1997-01-05 07:15:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If everything went ok, and we've been asked to update
|
|
|
|
* the NIS maps, then do it now
|
|
|
|
*/
|
2015-06-07 14:54:07 +00:00
|
|
|
if (ch == EXIT_SUCCESS && nis) {
|
1997-01-05 07:15:37 +00:00
|
|
|
pid_t pid;
|
|
|
|
|
|
|
|
fflush(NULL);
|
|
|
|
if (chdir(_PATH_YP) == -1)
|
1997-10-10 06:23:42 +00:00
|
|
|
warn("chdir(" _PATH_YP ")");
|
1997-01-05 07:15:37 +00:00
|
|
|
else if ((pid = fork()) == -1)
|
1997-10-10 06:23:42 +00:00
|
|
|
warn("fork()");
|
1997-01-05 07:15:37 +00:00
|
|
|
else if (pid == 0) {
|
|
|
|
/* Is make anywhere else? */
|
2001-07-09 09:24:06 +00:00
|
|
|
execlp("/usr/bin/make", "make", (char *)NULL);
|
1997-01-05 07:15:37 +00:00
|
|
|
_exit(1);
|
|
|
|
} else {
|
|
|
|
int i;
|
|
|
|
waitpid(pid, &i, 0);
|
|
|
|
if ((i = WEXITSTATUS(i)) != 0)
|
1997-10-10 06:23:42 +00:00
|
|
|
errx(ch, "make exited with status %d", i);
|
1997-01-05 07:15:37 +00:00
|
|
|
else
|
2015-06-07 14:34:38 +00:00
|
|
|
pw_log(conf.userconf, mode, which, "NIS maps updated");
|
1997-01-05 07:15:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ch;
|
1996-12-09 14:05:35 +00:00
|
|
|
}
|
|
|
|
|
1998-08-04 22:31:26 +00:00
|
|
|
|
1996-12-09 14:05:35 +00:00
|
|
|
static int
|
|
|
|
getindex(const char *words[], const char *word)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
while (words[i]) {
|
|
|
|
if (strcmp(words[i], word) == 0)
|
|
|
|
return i;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is probably an overkill for a cmdline help system, but it reflects
|
|
|
|
* the complexity of the command line.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
cmdhelp(int mode, int which)
|
|
|
|
{
|
|
|
|
if (which == -1)
|
1999-10-26 08:34:09 +00:00
|
|
|
fprintf(stderr, "usage:\n pw [user|group|lock|unlock] [add|del|mod|show|next] [help|switches/values]\n");
|
1996-12-09 14:05:35 +00:00
|
|
|
else if (mode == -1)
|
1999-10-26 08:34:09 +00:00
|
|
|
fprintf(stderr, "usage:\n pw %s [add|del|mod|show|next] [help|switches/values]\n", Which[which]);
|
1996-12-09 14:05:35 +00:00
|
|
|
else {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We need to give mode specific help
|
|
|
|
*/
|
|
|
|
static const char *help[W_NUM][M_NUM] =
|
|
|
|
{
|
|
|
|
{
|
1997-10-10 06:23:42 +00:00
|
|
|
"usage: pw useradd [name] [switches]\n"
|
1999-02-23 07:15:11 +00:00
|
|
|
"\t-V etcdir alternate /etc location\n"
|
2015-06-03 19:08:25 +00:00
|
|
|
"\t-R rootir alternate root directory\n"
|
1996-12-09 14:05:35 +00:00
|
|
|
"\t-C config configuration file\n"
|
|
|
|
"\t-q quiet operation\n"
|
|
|
|
" Adding users:\n"
|
|
|
|
"\t-n name login name\n"
|
|
|
|
"\t-u uid user id\n"
|
|
|
|
"\t-c comment user name/comment\n"
|
|
|
|
"\t-d directory home directory\n"
|
|
|
|
"\t-e date account expiry date\n"
|
|
|
|
"\t-p date password expiry date\n"
|
|
|
|
"\t-g grp initial group\n"
|
|
|
|
"\t-G grp1,grp2 additional groups\n"
|
|
|
|
"\t-m [ -k dir ] create and set up home\n"
|
2007-03-30 10:02:47 +00:00
|
|
|
"\t-M mode home directory permissions\n"
|
1996-12-09 14:05:35 +00:00
|
|
|
"\t-s shell name of login shell\n"
|
|
|
|
"\t-o duplicate uid ok\n"
|
|
|
|
"\t-L class user class\n"
|
|
|
|
"\t-h fd read password on fd\n"
|
2004-01-11 18:28:08 +00:00
|
|
|
"\t-H fd read encrypted password on fd\n"
|
1997-01-05 07:15:37 +00:00
|
|
|
"\t-Y update NIS maps\n"
|
1996-12-09 23:55:27 +00:00
|
|
|
"\t-N no update\n"
|
1996-12-09 14:05:35 +00:00
|
|
|
" Setting defaults:\n"
|
1999-02-23 07:15:11 +00:00
|
|
|
"\t-V etcdir alternate /etc location\n"
|
2015-06-03 19:08:25 +00:00
|
|
|
"\t-R rootir alternate root directory\n"
|
1999-02-23 07:15:11 +00:00
|
|
|
"\t-D set user defaults\n"
|
1996-12-09 14:05:35 +00:00
|
|
|
"\t-b dir default home root dir\n"
|
|
|
|
"\t-e period default expiry period\n"
|
|
|
|
"\t-p period default password change period\n"
|
|
|
|
"\t-g group default group\n"
|
|
|
|
"\t-G grp1,grp2 additional groups\n"
|
|
|
|
"\t-L class default user class\n"
|
|
|
|
"\t-k dir default home skeleton\n"
|
2007-03-30 11:23:10 +00:00
|
|
|
"\t-M mode home directory permissions\n"
|
1996-12-09 14:05:35 +00:00
|
|
|
"\t-u min,max set min,max uids\n"
|
|
|
|
"\t-i min,max set min,max gids\n"
|
|
|
|
"\t-w method set default password method\n"
|
1997-01-05 07:15:37 +00:00
|
|
|
"\t-s shell default shell\n"
|
|
|
|
"\t-y path set NIS passwd file path\n",
|
1997-10-10 06:23:42 +00:00
|
|
|
"usage: pw userdel [uid|name] [switches]\n"
|
1999-02-23 07:15:11 +00:00
|
|
|
"\t-V etcdir alternate /etc location\n"
|
2015-06-03 19:08:25 +00:00
|
|
|
"\t-R rootir alternate root directory\n"
|
1996-12-09 14:05:35 +00:00
|
|
|
"\t-n name login name\n"
|
|
|
|
"\t-u uid user id\n"
|
1997-01-05 07:15:37 +00:00
|
|
|
"\t-Y update NIS maps\n"
|
1996-12-09 14:05:35 +00:00
|
|
|
"\t-r remove home & contents\n",
|
1997-10-10 06:23:42 +00:00
|
|
|
"usage: pw usermod [uid|name] [switches]\n"
|
1999-02-23 07:15:11 +00:00
|
|
|
"\t-V etcdir alternate /etc location\n"
|
2015-06-03 19:08:25 +00:00
|
|
|
"\t-R rootir alternate root directory\n"
|
1996-12-09 14:05:35 +00:00
|
|
|
"\t-C config configuration file\n"
|
|
|
|
"\t-q quiet operation\n"
|
|
|
|
"\t-F force add if no user\n"
|
|
|
|
"\t-n name login name\n"
|
|
|
|
"\t-u uid user id\n"
|
|
|
|
"\t-c comment user name/comment\n"
|
|
|
|
"\t-d directory home directory\n"
|
|
|
|
"\t-e date account expiry date\n"
|
|
|
|
"\t-p date password expiry date\n"
|
|
|
|
"\t-g grp initial group\n"
|
|
|
|
"\t-G grp1,grp2 additional groups\n"
|
|
|
|
"\t-l name new login name\n"
|
|
|
|
"\t-L class user class\n"
|
|
|
|
"\t-m [ -k dir ] create and set up home\n"
|
2007-03-30 10:02:47 +00:00
|
|
|
"\t-M mode home directory permissions\n"
|
1996-12-09 14:05:35 +00:00
|
|
|
"\t-s shell name of login shell\n"
|
1996-12-09 23:55:27 +00:00
|
|
|
"\t-w method set new password using method\n"
|
|
|
|
"\t-h fd read password on fd\n"
|
2004-01-11 18:28:08 +00:00
|
|
|
"\t-H fd read encrypted password on fd\n"
|
1997-01-05 07:15:37 +00:00
|
|
|
"\t-Y update NIS maps\n"
|
1996-12-09 23:55:27 +00:00
|
|
|
"\t-N no update\n",
|
1997-10-10 06:23:42 +00:00
|
|
|
"usage: pw usershow [uid|name] [switches]\n"
|
1999-02-23 07:15:11 +00:00
|
|
|
"\t-V etcdir alternate /etc location\n"
|
2015-06-03 19:08:25 +00:00
|
|
|
"\t-R rootir alternate root directory\n"
|
1996-12-09 14:05:35 +00:00
|
|
|
"\t-n name login name\n"
|
|
|
|
"\t-u uid user id\n"
|
|
|
|
"\t-F force print\n"
|
1996-12-09 23:55:27 +00:00
|
|
|
"\t-P prettier format\n"
|
1999-03-02 00:53:33 +00:00
|
|
|
"\t-a print all users\n"
|
|
|
|
"\t-7 print in v7 format\n",
|
1997-10-10 06:23:42 +00:00
|
|
|
"usage: pw usernext [switches]\n"
|
1999-02-23 07:15:11 +00:00
|
|
|
"\t-V etcdir alternate /etc location\n"
|
2015-06-03 19:08:25 +00:00
|
|
|
"\t-R rootir alternate root directory\n"
|
1996-12-09 23:55:27 +00:00
|
|
|
"\t-C config configuration file\n"
|
2001-03-14 03:24:30 +00:00
|
|
|
"\t-q quiet operation\n",
|
|
|
|
"usage pw: lock [switches]\n"
|
|
|
|
"\t-V etcdir alternate /etc locations\n"
|
|
|
|
"\t-C config configuration file\n"
|
|
|
|
"\t-q quiet operation\n",
|
|
|
|
"usage pw: unlock [switches]\n"
|
|
|
|
"\t-V etcdir alternate /etc locations\n"
|
|
|
|
"\t-C config configuration file\n"
|
|
|
|
"\t-q quiet operation\n"
|
1996-12-09 14:05:35 +00:00
|
|
|
},
|
|
|
|
{
|
1997-10-10 06:23:42 +00:00
|
|
|
"usage: pw groupadd [group|gid] [switches]\n"
|
1999-02-23 07:15:11 +00:00
|
|
|
"\t-V etcdir alternate /etc location\n"
|
2015-06-03 19:08:25 +00:00
|
|
|
"\t-R rootir alternate root directory\n"
|
1996-12-09 14:05:35 +00:00
|
|
|
"\t-C config configuration file\n"
|
|
|
|
"\t-q quiet operation\n"
|
|
|
|
"\t-n group group name\n"
|
|
|
|
"\t-g gid group id\n"
|
1996-12-09 23:55:27 +00:00
|
|
|
"\t-M usr1,usr2 add users as group members\n"
|
|
|
|
"\t-o duplicate gid ok\n"
|
1997-01-05 07:15:37 +00:00
|
|
|
"\t-Y update NIS maps\n"
|
1996-12-09 23:55:27 +00:00
|
|
|
"\t-N no update\n",
|
1997-10-10 06:23:42 +00:00
|
|
|
"usage: pw groupdel [group|gid] [switches]\n"
|
1999-02-23 07:15:11 +00:00
|
|
|
"\t-V etcdir alternate /etc location\n"
|
2015-06-03 19:08:25 +00:00
|
|
|
"\t-R rootir alternate root directory\n"
|
1996-12-09 14:05:35 +00:00
|
|
|
"\t-n name group name\n"
|
1997-01-05 07:15:37 +00:00
|
|
|
"\t-g gid group id\n"
|
|
|
|
"\t-Y update NIS maps\n",
|
1997-10-10 06:23:42 +00:00
|
|
|
"usage: pw groupmod [group|gid] [switches]\n"
|
1999-02-23 07:15:11 +00:00
|
|
|
"\t-V etcdir alternate /etc location\n"
|
2015-06-03 19:08:25 +00:00
|
|
|
"\t-R rootir alternate root directory\n"
|
1996-12-09 14:05:35 +00:00
|
|
|
"\t-C config configuration file\n"
|
|
|
|
"\t-q quiet operation\n"
|
|
|
|
"\t-F force add if not exists\n"
|
|
|
|
"\t-n name group name\n"
|
|
|
|
"\t-g gid group id\n"
|
1996-12-09 23:55:27 +00:00
|
|
|
"\t-M usr1,usr2 replaces users as group members\n"
|
|
|
|
"\t-m usr1,usr2 add users as group members\n"
|
2008-02-23 01:25:22 +00:00
|
|
|
"\t-d usr1,usr2 delete users as group members\n"
|
1996-12-09 23:55:27 +00:00
|
|
|
"\t-l name new group name\n"
|
1997-01-05 07:15:37 +00:00
|
|
|
"\t-Y update NIS maps\n"
|
1996-12-09 23:55:27 +00:00
|
|
|
"\t-N no update\n",
|
1997-10-10 06:23:42 +00:00
|
|
|
"usage: pw groupshow [group|gid] [switches]\n"
|
1999-02-23 07:15:11 +00:00
|
|
|
"\t-V etcdir alternate /etc location\n"
|
2015-06-03 19:08:25 +00:00
|
|
|
"\t-R rootir alternate root directory\n"
|
1996-12-09 14:05:35 +00:00
|
|
|
"\t-n name group name\n"
|
|
|
|
"\t-g gid group id\n"
|
|
|
|
"\t-F force print\n"
|
1996-12-09 23:55:27 +00:00
|
|
|
"\t-P prettier format\n"
|
|
|
|
"\t-a print all accounting groups\n",
|
1997-10-10 06:23:42 +00:00
|
|
|
"usage: pw groupnext [switches]\n"
|
1999-02-23 07:15:11 +00:00
|
|
|
"\t-V etcdir alternate /etc location\n"
|
2015-06-03 19:08:25 +00:00
|
|
|
"\t-R rootir alternate root directory\n"
|
1996-12-09 23:55:27 +00:00
|
|
|
"\t-C config configuration file\n"
|
2001-03-14 03:24:30 +00:00
|
|
|
"\t-q quiet operation\n"
|
1996-12-09 14:05:35 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2001-07-05 08:01:15 +00:00
|
|
|
fprintf(stderr, "%s", help[which][mode]);
|
1996-12-09 14:05:35 +00:00
|
|
|
}
|
1996-12-09 23:55:27 +00:00
|
|
|
exit(EXIT_FAILURE);
|
1996-12-09 14:05:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct carg *
|
|
|
|
getarg(struct cargs * _args, int ch)
|
|
|
|
{
|
2000-12-29 18:04:54 +00:00
|
|
|
struct carg *c = LIST_FIRST(_args);
|
1996-12-09 14:05:35 +00:00
|
|
|
|
|
|
|
while (c != NULL && c->ch != ch)
|
2000-12-29 18:04:54 +00:00
|
|
|
c = LIST_NEXT(c, list);
|
1996-12-09 14:05:35 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct carg *
|
|
|
|
addarg(struct cargs * _args, int ch, char *argstr)
|
|
|
|
{
|
|
|
|
struct carg *ca = malloc(sizeof(struct carg));
|
|
|
|
|
|
|
|
if (ca == NULL)
|
1997-10-10 06:23:42 +00:00
|
|
|
errx(EX_OSERR, "out of memory");
|
1996-12-09 14:05:35 +00:00
|
|
|
ca->ch = ch;
|
|
|
|
ca->val = argstr;
|
|
|
|
LIST_INSERT_HEAD(_args, ca, list);
|
|
|
|
return ca;
|
|
|
|
}
|