Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
btwise
openssl
提交
30745146
O
openssl
项目概览
btwise
/
openssl
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
openssl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
30745146
编写于
9月 14, 2016
作者:
R
Richard Levitte
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rather than one variable for each passwd type, use one enum variable
Reviewed-by:
N
Rich Salz
<
rsalz@openssl.org
>
上级
49681ae1
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
49 addition
and
38 deletion
+49
-38
apps/passwd.c
apps/passwd.c
+49
-38
未找到文件。
apps/passwd.c
浏览文件 @
30745146
...
@@ -47,10 +47,18 @@ static unsigned const char cov_2char[64] = {
...
@@ -47,10 +47,18 @@ static unsigned const char cov_2char[64] = {
0x73
,
0x74
,
0x75
,
0x76
,
0x77
,
0x78
,
0x79
,
0x7A
0x73
,
0x74
,
0x75
,
0x76
,
0x77
,
0x78
,
0x79
,
0x7A
};
};
typedef
enum
{
passwd_unset
=
0
,
passwd_crypt
,
passwd_md5
,
passwd_apr1
,
passwd_sha256
,
passwd_sha512
}
passwd_modes
;
static
int
do_passwd
(
int
passed_salt
,
char
**
salt_p
,
char
**
salt_malloc_p
,
static
int
do_passwd
(
int
passed_salt
,
char
**
salt_p
,
char
**
salt_malloc_p
,
char
*
passwd
,
BIO
*
out
,
int
quiet
,
int
table
,
char
*
passwd
,
BIO
*
out
,
int
quiet
,
int
table
,
int
reverse
,
size_t
pw_maxlen
,
int
usecrypt
,
int
use1
,
int
reverse
,
size_t
pw_maxlen
,
passwd_modes
mode
);
int
useapr1
,
int
use5
,
int
use6
);
typedef
enum
OPTION_choice
{
typedef
enum
OPTION_choice
{
OPT_ERR
=
-
1
,
OPT_EOF
=
0
,
OPT_HELP
,
OPT_ERR
=
-
1
,
OPT_EOF
=
0
,
OPT_HELP
,
...
@@ -94,8 +102,11 @@ int passwd_main(int argc, char **argv)
...
@@ -94,8 +102,11 @@ int passwd_main(int argc, char **argv)
int
in_noverify
=
0
;
int
in_noverify
=
0
;
#endif
#endif
int
passed_salt
=
0
,
quiet
=
0
,
table
=
0
,
reverse
=
0
;
int
passed_salt
=
0
,
quiet
=
0
,
table
=
0
,
reverse
=
0
;
int
ret
=
1
,
usecrypt
=
0
,
use1
=
0
,
useapr1
=
0
,
use5
=
0
,
use6
=
0
;
int
ret
=
1
;
size_t
passwd_malloc_size
=
0
,
pw_maxlen
=
256
;
passwd_modes
mode
=
passwd_unset
;
size_t
passwd_malloc_size
=
0
;
size_t
pw_maxlen
=
256
;
/* arbitrary limit, should be enough for most
* passwords */
prog
=
opt_init
(
argc
,
argv
,
passwd_options
);
prog
=
opt_init
(
argc
,
argv
,
passwd_options
);
while
((
o
=
opt_next
())
!=
OPT_EOF
)
{
while
((
o
=
opt_next
())
!=
OPT_EOF
)
{
...
@@ -129,20 +140,30 @@ int passwd_main(int argc, char **argv)
...
@@ -129,20 +140,30 @@ int passwd_main(int argc, char **argv)
case
OPT_REVERSE
:
case
OPT_REVERSE
:
reverse
=
1
;
reverse
=
1
;
break
;
break
;
case
OPT_1
:
if
(
mode
!=
passwd_unset
)
goto
opthelp
;
mode
=
passwd_md5
;
break
;
case
OPT_5
:
case
OPT_5
:
use5
=
1
;
if
(
mode
!=
passwd_unset
)
goto
opthelp
;
mode
=
passwd_sha256
;
break
;
break
;
case
OPT_6
:
case
OPT_6
:
use6
=
1
;
if
(
mode
!=
passwd_unset
)
break
;
goto
opthelp
;
case
OPT_1
:
mode
=
passwd_sha512
;
use1
=
1
;
break
;
break
;
case
OPT_APR1
:
case
OPT_APR1
:
useapr1
=
1
;
if
(
mode
!=
passwd_unset
)
goto
opthelp
;
mode
=
passwd_apr1
;
break
;
break
;
case
OPT_CRYPT
:
case
OPT_CRYPT
:
usecrypt
=
1
;
if
(
mode
!=
passwd_unset
)
goto
opthelp
;
mode
=
passwd_crypt
;
break
;
break
;
case
OPT_SALT
:
case
OPT_SALT
:
passed_salt
=
1
;
passed_salt
=
1
;
...
@@ -166,25 +187,21 @@ int passwd_main(int argc, char **argv)
...
@@ -166,25 +187,21 @@ int passwd_main(int argc, char **argv)
passwds
=
argv
;
passwds
=
argv
;
}
}
if
(
!
usecrypt
&&
!
use5
&&
!
use6
&&
!
use1
&&
!
useapr1
)
{
if
(
mode
==
passwd_unset
)
{
/* use default */
/* use default */
usecrypt
=
1
;
mode
=
passwd_crypt
;
}
if
(
usecrypt
+
use5
+
use6
+
use1
+
useapr1
>
1
)
{
/* conflict */
goto
opthelp
;
}
}
# ifdef OPENSSL_NO_DES
# ifdef OPENSSL_NO_DES
if
(
use
crypt
)
if
(
mode
==
passwd_
crypt
)
goto
opthelp
;
goto
opthelp
;
# endif
# endif
# ifdef NO_MD5CRYPT_1
# ifdef NO_MD5CRYPT_1
if
(
use1
||
use
apr1
)
if
(
mode
==
passwd_md5
||
mode
==
passwd_
apr1
)
goto
opthelp
;
goto
opthelp
;
# endif
# endif
# ifdef NO_SHACRYPT
# ifdef NO_SHACRYPT
if
(
use5
||
use6
)
if
(
mode
==
passwd_sha256
||
mode
==
passwd_sha512
)
goto
opthelp
;
goto
opthelp
;
# endif
# endif
...
@@ -203,11 +220,8 @@ int passwd_main(int argc, char **argv)
...
@@ -203,11 +220,8 @@ int passwd_main(int argc, char **argv)
goto
end
;
goto
end
;
}
}
if
(
use
crypt
)
if
(
mode
==
passwd_
crypt
)
pw_maxlen
=
8
;
pw_maxlen
=
8
;
else
if
(
use1
||
useapr1
)
pw_maxlen
=
256
;
/* arbitrary limit, should be enough for most
* passwords */
if
(
passwds
==
NULL
)
{
if
(
passwds
==
NULL
)
{
/* no passwords on the command line */
/* no passwords on the command line */
...
@@ -246,8 +260,7 @@ int passwd_main(int argc, char **argv)
...
@@ -246,8 +260,7 @@ int passwd_main(int argc, char **argv)
do
{
/* loop over list of passwords */
do
{
/* loop over list of passwords */
passwd
=
*
passwds
++
;
passwd
=
*
passwds
++
;
if
(
!
do_passwd
(
passed_salt
,
&
salt
,
&
salt_malloc
,
passwd
,
bio_out
,
if
(
!
do_passwd
(
passed_salt
,
&
salt
,
&
salt_malloc
,
passwd
,
bio_out
,
quiet
,
table
,
reverse
,
pw_maxlen
,
usecrypt
,
use1
,
quiet
,
table
,
reverse
,
pw_maxlen
,
mode
))
useapr1
,
use5
,
use6
))
goto
end
;
goto
end
;
}
}
while
(
*
passwds
!=
NULL
);
while
(
*
passwds
!=
NULL
);
...
@@ -273,8 +286,7 @@ int passwd_main(int argc, char **argv)
...
@@ -273,8 +286,7 @@ int passwd_main(int argc, char **argv)
if
(
!
do_passwd
if
(
!
do_passwd
(
passed_salt
,
&
salt
,
&
salt_malloc
,
passwd
,
bio_out
,
quiet
,
(
passed_salt
,
&
salt
,
&
salt_malloc
,
passwd
,
bio_out
,
quiet
,
table
,
reverse
,
pw_maxlen
,
usecrypt
,
use1
,
useapr1
,
table
,
reverse
,
pw_maxlen
,
mode
))
use5
,
use6
))
goto
end
;
goto
end
;
}
}
done
=
(
r
<=
0
);
done
=
(
r
<=
0
);
...
@@ -703,8 +715,7 @@ static char *shacrypt(const char *passwd, const char *magic, const char *salt)
...
@@ -703,8 +715,7 @@ static char *shacrypt(const char *passwd, const char *magic, const char *salt)
static
int
do_passwd
(
int
passed_salt
,
char
**
salt_p
,
char
**
salt_malloc_p
,
static
int
do_passwd
(
int
passed_salt
,
char
**
salt_p
,
char
**
salt_malloc_p
,
char
*
passwd
,
BIO
*
out
,
int
quiet
,
int
table
,
char
*
passwd
,
BIO
*
out
,
int
quiet
,
int
table
,
int
reverse
,
size_t
pw_maxlen
,
int
usecrypt
,
int
use1
,
int
reverse
,
size_t
pw_maxlen
,
passwd_modes
mode
)
int
useapr1
,
int
use5
,
int
use6
)
{
{
char
*
hash
=
NULL
;
char
*
hash
=
NULL
;
...
@@ -714,7 +725,7 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
...
@@ -714,7 +725,7 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
/* first make sure we have a salt */
/* first make sure we have a salt */
if
(
!
passed_salt
)
{
if
(
!
passed_salt
)
{
# ifndef OPENSSL_NO_DES
# ifndef OPENSSL_NO_DES
if
(
use
crypt
)
{
if
(
mode
==
passwd_
crypt
)
{
if
(
*
salt_malloc_p
==
NULL
)
{
if
(
*
salt_malloc_p
==
NULL
)
{
*
salt_p
=
*
salt_malloc_p
=
app_malloc
(
3
,
"salt buffer"
);
*
salt_p
=
*
salt_malloc_p
=
app_malloc
(
3
,
"salt buffer"
);
}
}
...
@@ -731,7 +742,7 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
...
@@ -731,7 +742,7 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
# endif
/* !OPENSSL_NO_DES */
# endif
/* !OPENSSL_NO_DES */
# ifndef NO_MD5CRYPT_1
# ifndef NO_MD5CRYPT_1
if
(
use1
||
use
apr1
)
{
if
(
mode
==
passwd_md5
||
mode
==
passwd_
apr1
)
{
int
i
;
int
i
;
if
(
*
salt_malloc_p
==
NULL
)
{
if
(
*
salt_malloc_p
==
NULL
)
{
...
@@ -747,7 +758,7 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
...
@@ -747,7 +758,7 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
# endif
/* !NO_MD5CRYPT_1 */
# endif
/* !NO_MD5CRYPT_1 */
# ifndef NO_SHACRYPT
# ifndef NO_SHACRYPT
if
(
use5
||
use6
)
{
if
(
mode
==
passwd_sha256
||
mode
==
passwd_sha512
)
{
int
i
;
int
i
;
if
(
*
salt_malloc_p
==
NULL
)
{
if
(
*
salt_malloc_p
==
NULL
)
{
...
@@ -780,16 +791,16 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
...
@@ -780,16 +791,16 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
/* now compute password hash */
/* now compute password hash */
# ifndef OPENSSL_NO_DES
# ifndef OPENSSL_NO_DES
if
(
use
crypt
)
if
(
mode
==
passwd_
crypt
)
hash
=
DES_crypt
(
passwd
,
*
salt_p
);
hash
=
DES_crypt
(
passwd
,
*
salt_p
);
# endif
# endif
# ifndef NO_MD5CRYPT_1
# ifndef NO_MD5CRYPT_1
if
(
use1
||
use
apr1
)
if
(
mode
==
passwd_md5
||
mode
==
passwd_
apr1
)
hash
=
md5crypt
(
passwd
,
(
use1
?
"1"
:
"apr1"
),
*
salt_p
);
hash
=
md5crypt
(
passwd
,
(
mode
==
passwd_md5
?
"1"
:
"apr1"
),
*
salt_p
);
# endif
# endif
# ifndef NO_SHACRYPT
# ifndef NO_SHACRYPT
if
(
use5
||
use6
)
if
(
mode
==
passwd_sha256
||
mode
==
passwd_sha512
)
hash
=
shacrypt
(
passwd
,
(
use5
?
"5"
:
"6"
),
*
salt_p
);
hash
=
shacrypt
(
passwd
,
(
mode
==
passwd_sha256
?
"5"
:
"6"
),
*
salt_p
);
# endif
# endif
assert
(
hash
!=
NULL
);
assert
(
hash
!=
NULL
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录