Modify the Redis support module of mosquitto-auth-plug

Revise


mosquitto-auth-plug supports Redis databases, but not as full-featured as the mysql module supports.
README.md says that if you use Redis database, it will not support superusers and acl permission control function does not support (+/#) wildcards, which is really stupid.

If a user belongs to superusers, it means that the user is a super user and is not controlled by the acl permission module. This function is very useful. And looking at the database table structure of mysql, in fact, there is only one more field to identify whether it is super. It is also very simple to use redis to implement it. Just add an identifier at the end of the value.

The getuser function in the code uses the GET command of Redis, which saves memory by replacing it with hash storage. The most important thing is that the hash has only one key, which is easier to manage.

Then README.md said that acl permissions do not support wildcards, which is also a mess. I tried Redis's key name and hash field can contain + and #, so it is no problem to write a topic containing wildcards directly in the database!

So open be-redis.c, there are not a few lines of code at all, add superusers by yourself and change the GET in getusers to HGET, of course, you must use GET. The advantage of using keys is that you can set the expiration time.
When storing the password, add a :1 at the end of the password to identify the superuser. Or store superusers separately from ordinary users.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325671755&siteId=291194637