* src/chpasswd.c: Added crypt method: NONE.
* src/chpasswd.c: Added --sha-rounds to the usage(). * libmisc/Makefile.am, libmisc/getlong.c, src/chgpasswd.c, src/chpasswd.c: New getlong function. Replace chpasswd's and chgpasswd's getnumber.
This commit is contained in:
parent
d8d8f70b0e
commit
add1c18b2e
@ -1,3 +1,11 @@
|
||||
2007-11-23 Nicolas François <nicolas.francois@centraliens.net>
|
||||
|
||||
* src/chpasswd.c: Added crypt method: NONE.
|
||||
* src/chpasswd.c: Added --sha-rounds to the usage().
|
||||
* libmisc/Makefile.am, libmisc/getlong.c, src/chgpasswd.c,
|
||||
src/chpasswd.c: New getlong function. Replace chpasswd's and
|
||||
chgpasswd's getnumber.
|
||||
|
||||
2007-11-23 Nicolas François <nicolas.francois@centraliens.net>
|
||||
|
||||
* lib/groupio.c: Removed unused variable 'member'.
|
||||
|
@ -23,6 +23,7 @@ libmisc_a_SOURCES = \
|
||||
fields.c \
|
||||
getdate.h \
|
||||
getdate.y \
|
||||
getlong.c \
|
||||
hushed.c \
|
||||
isexpired.c \
|
||||
limits.c \
|
||||
|
49
libmisc/getlong.c
Normal file
49
libmisc/getlong.c
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2007, Nicolas François
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 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.
|
||||
* 3. Neither the name of Julianne F. Haugh nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NICOLAS FRANÇOIS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL NICOLAS FRANÇOIS OR CONTRIBUTORS BE LIABLE
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ident "$Id:$"
|
||||
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
|
||||
int getlong(const char *numstr, long int *result)
|
||||
{
|
||||
long val;
|
||||
char *endptr;
|
||||
|
||||
val = strtol (numstr, &endptr, 10);
|
||||
if (*endptr || errno == ERANGE)
|
||||
return 0;
|
||||
|
||||
*result = val;
|
||||
return 1;
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ static int md5flg = 0;
|
||||
static int sflg = 0;
|
||||
|
||||
static char *crypt_method = NULL;
|
||||
static int sha_rounds = 5000;
|
||||
static long sha_rounds = 5000;
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
static int is_shadow_grp;
|
||||
@ -70,39 +70,27 @@ static void usage (void);
|
||||
*/
|
||||
static void usage (void)
|
||||
{
|
||||
fprintf (stderr, _("Usage: chgpasswd [options]\n"
|
||||
fprintf (stderr, _("Usage: %s [options]\n"
|
||||
"\n"
|
||||
"Options:\n"
|
||||
" -c, --crypt-method the crypt method (one of %s)\n"
|
||||
" -e, --encrypted supplied passwords are encrypted\n"
|
||||
" -h, --help display this help message and exit\n"
|
||||
" -m, --md5 use MD5 encryption instead DES when the supplied\n"
|
||||
" -m, --md5 use MD5 encryption instead of DES when the supplied\n"
|
||||
" passwords are not encrypted\n"
|
||||
"%s"
|
||||
"\n"),
|
||||
Prog,
|
||||
#ifndef ENCRYPTMETHOD_SELECT
|
||||
"DES MD5"
|
||||
"NONE DES MD5", ""
|
||||
#else
|
||||
"DES MD5 SHA256 SHA512"
|
||||
"NONE DES MD5 SHA256 SHA512",
|
||||
_(" -s, --sha-rounds number of SHA rounds for the SHA* crypt algorithms\n")
|
||||
#endif
|
||||
);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
static long getnumber (const char *numstr)
|
||||
{
|
||||
long val;
|
||||
char *errptr;
|
||||
|
||||
val = strtol (numstr, &errptr, 10);
|
||||
if (*errptr || errno == ERANGE) {
|
||||
fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
|
||||
numstr);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
char buf[BUFSIZ];
|
||||
@ -163,7 +151,12 @@ int main (int argc, char **argv)
|
||||
break;
|
||||
case 's':
|
||||
sflg = 1;
|
||||
sha_rounds = getnumber(optarg);
|
||||
if (!getlong(optarg, &sha_rounds)) {
|
||||
fprintf (stderr,
|
||||
_("%s: invalid numeric argument '%s'\n"),
|
||||
Prog, optarg);
|
||||
usage ();
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
/* long option */
|
||||
@ -192,14 +185,15 @@ int main (int argc, char **argv)
|
||||
if (cflg) {
|
||||
if (0 != strcmp (crypt_method, "DES") &&
|
||||
0 != strcmp (crypt_method, "MD5") &&
|
||||
0 != strcmp (crypt_method, "NONE") &&
|
||||
#ifdef ENCRYPTMETHOD_SELECT
|
||||
0 != strcmp (crypt_method, "SHA256") &&
|
||||
0 != strcmp (crypt_method, "SHA512")
|
||||
#endif
|
||||
) {
|
||||
fprintf (stderr,
|
||||
_("%s: unsupported crypt method: %s\n"),
|
||||
Prog, crypt_method);
|
||||
_("%s: unsupported crypt method: %s\n"),
|
||||
Prog, crypt_method);
|
||||
usage ();
|
||||
}
|
||||
}
|
||||
@ -308,7 +302,9 @@ int main (int argc, char **argv)
|
||||
continue;
|
||||
}
|
||||
newpwd = cp;
|
||||
if (!eflg) {
|
||||
if (!eflg &&
|
||||
(NULL == crypt_method ||
|
||||
0 != strcmp(crypt_method, "NONE"))) {
|
||||
void *arg = NULL;
|
||||
if (md5flg)
|
||||
crypt_method = "MD5";
|
||||
|
@ -55,7 +55,7 @@ static int md5flg = 0;
|
||||
static int sflg = 0;
|
||||
|
||||
static char *crypt_method = NULL;
|
||||
static int sha_rounds = 5000;
|
||||
static long sha_rounds = 5000;
|
||||
|
||||
static int is_shadow_pwd;
|
||||
|
||||
@ -67,39 +67,27 @@ static void usage (void);
|
||||
*/
|
||||
static void usage (void)
|
||||
{
|
||||
fprintf (stderr, _("Usage: chpasswd [options]\n"
|
||||
fprintf (stderr, _("Usage: %s [options]\n"
|
||||
"\n"
|
||||
"Options:\n"
|
||||
" -c, --crypt-method the crypt method (one of %s)\n"
|
||||
" -e, --encrypted supplied passwords are encrypted\n"
|
||||
" -h, --help display this help message and exit\n"
|
||||
" -m, --md5 use MD5 encryption instead DES when the supplied\n"
|
||||
" -m, --md5 use MD5 encryption instead of DES when the supplied\n"
|
||||
" passwords are not encrypted\n"
|
||||
"%s"
|
||||
"\n"),
|
||||
Prog,
|
||||
#ifndef ENCRYPTMETHOD_SELECT
|
||||
"DES MD5"
|
||||
"NONE DES MD5", ""
|
||||
#else
|
||||
"DES MD5 SHA256 SHA512"
|
||||
"NONE DES MD5 SHA256 SHA512",
|
||||
_(" -s, --sha-rounds number of SHA rounds for the SHA* crypt algorithms\n")
|
||||
#endif
|
||||
);
|
||||
exit (E_USAGE);
|
||||
}
|
||||
|
||||
static long getnumber (const char *numstr)
|
||||
{
|
||||
long val;
|
||||
char *errptr;
|
||||
|
||||
val = strtol (numstr, &errptr, 10);
|
||||
if (*errptr || errno == ERANGE) {
|
||||
fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
|
||||
numstr);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
char buf[BUFSIZ];
|
||||
@ -159,7 +147,12 @@ int main (int argc, char **argv)
|
||||
break;
|
||||
case 's':
|
||||
sflg = 1;
|
||||
sha_rounds = getnumber(optarg);
|
||||
if (!getlong(optarg, &sha_rounds)) {
|
||||
fprintf (stderr,
|
||||
_("%s: invalid numeric argument '%s'\n"),
|
||||
Prog, optarg);
|
||||
usage ();
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
/* long option */
|
||||
@ -188,14 +181,15 @@ int main (int argc, char **argv)
|
||||
if (cflg) {
|
||||
if (0 != strcmp (crypt_method, "DES") &&
|
||||
0 != strcmp (crypt_method, "MD5") &&
|
||||
0 != strcmp (crypt_method, "NONE") &&
|
||||
#ifdef ENCRYPTMETHOD_SELECT
|
||||
0 != strcmp (crypt_method, "SHA256") &&
|
||||
0 != strcmp (crypt_method, "SHA512")
|
||||
#endif
|
||||
) {
|
||||
fprintf (stderr,
|
||||
_("%s: unsupported crypt method: %s\n"),
|
||||
Prog, crypt_method);
|
||||
_("%s: unsupported crypt method: %s\n"),
|
||||
Prog, crypt_method);
|
||||
usage ();
|
||||
}
|
||||
}
|
||||
@ -306,7 +300,9 @@ int main (int argc, char **argv)
|
||||
continue;
|
||||
}
|
||||
newpwd = cp;
|
||||
if (!eflg) {
|
||||
if (!eflg &&
|
||||
(NULL == crypt_method ||
|
||||
0 != strcmp(crypt_method, "NONE"))) {
|
||||
void *arg = NULL;
|
||||
if (md5flg)
|
||||
crypt_method = "MD5";
|
||||
|
Loading…
Reference in New Issue
Block a user