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
a95a086b
Commit
a95a086b
authored
Apr 23, 2020
by
antirez
Browse files
ACL GENPASS: take number of bits as argument.
parent
dc1bc0f4
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/acl.c
View file @
a95a086b
...
@@ -1626,7 +1626,7 @@ void addACLLogEntry(client *c, int reason, int keypos, sds username) {
...
@@ -1626,7 +1626,7 @@ void addACLLogEntry(client *c, int reason, int keypos, sds username) {
* ACL SETUSER <username> ... acl rules ...
* ACL SETUSER <username> ... acl rules ...
* ACL DELUSER <username> [...]
* ACL DELUSER <username> [...]
* ACL GETUSER <username>
* ACL GETUSER <username>
* ACL GENPASS
* ACL GENPASS
[<bits>]
* ACL WHOAMI
* ACL WHOAMI
* ACL LOG [<count> | RESET]
* ACL LOG [<count> | RESET]
*/
*/
...
@@ -1818,10 +1818,25 @@ void aclCommand(client *c) {
...
@@ -1818,10 +1818,25 @@ void aclCommand(client *c) {
}
}
dictReleaseIterator
(
di
);
dictReleaseIterator
(
di
);
setDeferredArrayLen
(
c
,
dl
,
arraylen
);
setDeferredArrayLen
(
c
,
dl
,
arraylen
);
}
else
if
(
!
strcasecmp
(
sub
,
"genpass"
)
&&
c
->
argc
==
2
)
{
}
else
if
(
!
strcasecmp
(
sub
,
"genpass"
)
&&
(
c
->
argc
==
2
||
c
->
argc
==
3
))
{
char
pass
[
64
];
/* 256 bits of actual pseudo random data. */
#define GENPASS_MAX_BITS 4096
getRandomHexChars
(
pass
,
sizeof
(
pass
));
char
pass
[
GENPASS_MAX_BITS
/
8
*
2
];
/* Hex representation. */
addReplyBulkCBuffer
(
c
,
pass
,
sizeof
(
pass
));
long
bits
=
256
;
/* By default generate 256 bits passwords. */
if
(
c
->
argc
==
3
&&
getLongFromObjectOrReply
(
c
,
c
->
argv
[
2
],
&
bits
,
NULL
)
!=
C_OK
)
return
;
if
(
bits
<=
0
||
bits
>
GENPASS_MAX_BITS
)
{
addReplyErrorFormat
(
c
,
"ACL GENPASS argument must be the number of "
"bits for the output password, a positive number "
"up to %d"
,
GENPASS_MAX_BITS
);
return
;
}
long
chars
=
(
bits
+
3
)
/
4
;
/* Round to number of characters to emit. */
getRandomHexChars
(
pass
,
chars
);
addReplyBulkCBuffer
(
c
,
pass
,
chars
);
}
else
if
(
!
strcasecmp
(
sub
,
"log"
)
&&
(
c
->
argc
==
2
||
c
->
argc
==
3
))
{
}
else
if
(
!
strcasecmp
(
sub
,
"log"
)
&&
(
c
->
argc
==
2
||
c
->
argc
==
3
))
{
long
count
=
10
;
/* Number of entries to emit by default. */
long
count
=
10
;
/* Number of entries to emit by default. */
...
@@ -1899,7 +1914,7 @@ void aclCommand(client *c) {
...
@@ -1899,7 +1914,7 @@ void aclCommand(client *c) {
"DELUSER <username> [...] -- Delete a list of users."
,
"DELUSER <username> [...] -- Delete a list of users."
,
"CAT -- List available categories."
,
"CAT -- List available categories."
,
"CAT <category> -- List commands inside category."
,
"CAT <category> -- List commands inside category."
,
"GENPASS
-- Generate a secure user password."
,
"GENPASS
[<bits>]
-- Generate a secure user password."
,
"WHOAMI -- Return the current connection username."
,
"WHOAMI -- Return the current connection username."
,
"LOG [<count> | RESET] -- Show the ACL log entries."
,
"LOG [<count> | RESET] -- Show the ACL log entries."
,
NULL
NULL
...
...
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