Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
cdcf5af5
Commit
cdcf5af5
authored
May 14, 2020
by
Madelyn Olson
Committed by
antirez
May 22, 2020
Browse files
Converge hash validation for adding and removing
parent
e8b09d22
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/acl.c
View file @
cdcf5af5
...
@@ -166,6 +166,25 @@ sds ACLHashPassword(unsigned char *cleartext, size_t len) {
...
@@ -166,6 +166,25 @@ sds ACLHashPassword(unsigned char *cleartext, size_t len) {
return
sdsnewlen
(
hex
,
HASH_PASSWORD_LEN
);
return
sdsnewlen
(
hex
,
HASH_PASSWORD_LEN
);
}
}
/* Given a hash and the hash length, returns C_OK if it is a valid password
* hash, or C_ERR otherwise. */
int
ACLCheckPasswordHash
(
unsigned
char
*
hash
,
int
hashlen
)
{
if
(
hashlen
!=
HASH_PASSWORD_LEN
)
{
return
C_ERR
;
}
/* Password hashes can only be characters that represent
* hexadecimal values, which are numbers and lowercase
* characters 'a' through 'f'. */
for
(
int
i
=
0
;
i
<
HASH_PASSWORD_LEN
;
i
++
)
{
char
c
=
hash
[
i
];
if
((
c
<
'a'
||
c
>
'f'
)
&&
(
c
<
'0'
||
c
>
'9'
))
{
return
C_ERR
;
}
}
return
C_OK
;
}
/* =============================================================================
/* =============================================================================
* Low level ACL API
* Low level ACL API
* ==========================================================================*/
* ==========================================================================*/
...
@@ -753,22 +772,10 @@ int ACLSetUser(user *u, const char *op, ssize_t oplen) {
...
@@ -753,22 +772,10 @@ int ACLSetUser(user *u, const char *op, ssize_t oplen) {
if
(
op
[
0
]
==
'>'
)
{
if
(
op
[
0
]
==
'>'
)
{
newpass
=
ACLHashPassword
((
unsigned
char
*
)
op
+
1
,
oplen
-
1
);
newpass
=
ACLHashPassword
((
unsigned
char
*
)
op
+
1
,
oplen
-
1
);
}
else
{
}
else
{
if
(
oplen
!=
HASH_PASSWORD_LEN
+
1
)
{
if
(
ACLCheckPasswordHash
((
unsigned
char
*
)
op
+
1
,
oplen
-
1
)
==
C_ERR
)
{
errno
=
EBADMSG
;
errno
=
EBADMSG
;
return
C_ERR
;
return
C_ERR
;
}
}
/* Password hashes can only be characters that represent
* hexadecimal values, which are numbers and lowercase
* characters 'a' through 'f'.
*/
for
(
int
i
=
1
;
i
<
HASH_PASSWORD_LEN
+
1
;
i
++
)
{
char
c
=
op
[
i
];
if
((
c
<
'a'
||
c
>
'f'
)
&&
(
c
<
'0'
||
c
>
'9'
))
{
errno
=
EBADMSG
;
return
C_ERR
;
}
}
newpass
=
sdsnewlen
(
op
+
1
,
oplen
-
1
);
newpass
=
sdsnewlen
(
op
+
1
,
oplen
-
1
);
}
}
...
@@ -784,7 +791,7 @@ int ACLSetUser(user *u, const char *op, ssize_t oplen) {
...
@@ -784,7 +791,7 @@ int ACLSetUser(user *u, const char *op, ssize_t oplen) {
if
(
op
[
0
]
==
'<'
)
{
if
(
op
[
0
]
==
'<'
)
{
delpass
=
ACLHashPassword
((
unsigned
char
*
)
op
+
1
,
oplen
-
1
);
delpass
=
ACLHashPassword
((
unsigned
char
*
)
op
+
1
,
oplen
-
1
);
}
else
{
}
else
{
if
(
oplen
!=
HASH_PASSWORD_LEN
+
1
)
{
if
(
ACLCheckPasswordHash
((
unsigned
char
*
)
op
+
1
,
oplen
-
1
)
==
C_ERR
)
{
errno
=
EBADMSG
;
errno
=
EBADMSG
;
return
C_ERR
;
return
C_ERR
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment