Skip to content

Commit

Permalink
New mosquitto_unpwd_check().
Browse files Browse the repository at this point in the history
  • Loading branch information
ralight committed Jul 8, 2016
1 parent 63f46a9 commit b3df015
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ mosquitto_passwd : mosquitto_passwd.o
mosquitto_passwd.o : mosquitto_passwd.c
${CROSS_COMPILE}${CC} $(CFLAGS) ${CPPFLAGS} -c $< -o $@

plugin_defer.so : plugin_defer.c mosquitto_plugin.h
plugin_defer.so : plugin_defer.c mosquitto_plugin.h mosquitto_broker.h mosquitto_broker_internal.h
${CROSS_COMPILE}${CC} -I. -I../lib -fPIC -shared $< -o $@

install : all
Expand Down
2 changes: 1 addition & 1 deletion src/handle_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
}else{
#endif /* WITH_TLS */
if(username_flag){
rc = mosquitto_unpwd_check(db, username, password);
rc = mosquitto_unpwd_check(db, context, username, password);
switch(rc){
case MOSQ_ERR_SUCCESS:
break;
Expand Down
4 changes: 2 additions & 2 deletions src/mosquitto_broker_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ struct mosquitto__auth_plugin{
int (*security_init)(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count, bool reload);
int (*security_cleanup)(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count, bool reload);
int (*acl_check)(void *user_data, int access, const struct mosquitto *client, struct mosquitto_acl_msg *msg);
int (*unpwd_check)(void *user_data, const char *username, const char *password);
int (*unpwd_check)(void *user_data, const struct mosquitto *client, const char *username, const char *password);
int (*psk_key_get)(void *user_data, const char *hint, const char *identity, char *key, int max_key_len);
};

Expand Down Expand Up @@ -558,7 +558,7 @@ int mosquitto_security_init(struct mosquitto_db *db, bool reload);
int mosquitto_security_apply(struct mosquitto_db *db);
int mosquitto_security_cleanup(struct mosquitto_db *db, bool reload);
int mosquitto_acl_check(struct mosquitto_db *db, struct mosquitto *context, const char *topic, int access);
int mosquitto_unpwd_check(struct mosquitto_db *db, const char *username, const char *password);
int mosquitto_unpwd_check(struct mosquitto_db *db, struct mosquitto *context, const char *username, const char *password);
int mosquitto_psk_key_get(struct mosquitto_db *db, const char *hint, const char *identity, char *key, int max_key_len);

int mosquitto_security_init_default(struct mosquitto_db *db, bool reload);
Expand Down
2 changes: 1 addition & 1 deletion src/mosquitto_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ int mosquitto_auth_acl_check(void *user_data, int access, const struct mosquitto
* MOSQ_ERR_UNKNOWN for an application specific error.
* MOSQ_ERR_PLUGIN_DEFER if your plugin does not wish to handle this check.
*/
int mosquitto_auth_unpwd_check(void *user_data, const char *username, const char *password);
int mosquitto_auth_unpwd_check(void *user_data, const struct mosquitto *client, const char *username, const char *password);

/*
* Function: mosquitto_psk_key_get
Expand Down
2 changes: 1 addition & 1 deletion src/plugin_defer.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int mosquitto_auth_acl_check(void *user_data, int access, const struct mosquitto
return MOSQ_ERR_PLUGIN_DEFER;
}

int mosquitto_auth_unpwd_check(void *user_data, const char *username, const char *password)
int mosquitto_auth_unpwd_check(void *user_data, const struct mosquitto *client, const char *username, const char *password)
{
return MOSQ_ERR_PLUGIN_DEFER;
}
Expand Down
6 changes: 3 additions & 3 deletions src/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ typedef int (*FUNC_auth_plugin_cleanup)(void *, struct mosquitto_auth_opt *, int
typedef int (*FUNC_auth_plugin_security_init)(void *, struct mosquitto_auth_opt *, int, bool);
typedef int (*FUNC_auth_plugin_security_cleanup)(void *, struct mosquitto_auth_opt *, int, bool);
typedef int (*FUNC_auth_plugin_acl_check)(void *, int, const struct mosquitto *, struct mosquitto_acl_msg *);
typedef int (*FUNC_auth_plugin_unpwd_check)(void *, const char *, const char *);
typedef int (*FUNC_auth_plugin_unpwd_check)(void *, const struct mosquitto *, const char *, const char *);
typedef int (*FUNC_auth_plugin_psk_key_get)(void *, const char *, const char *, char *, int);

void LIB_ERROR(void)
Expand Down Expand Up @@ -267,7 +267,7 @@ int mosquitto_acl_check(struct mosquitto_db *db, struct mosquitto *context, cons
return rc;
}

int mosquitto_unpwd_check(struct mosquitto_db *db, const char *username, const char *password)
int mosquitto_unpwd_check(struct mosquitto_db *db, struct mosquitto *context, const char *username, const char *password)
{
int rc;
int i;
Expand All @@ -281,7 +281,7 @@ int mosquitto_unpwd_check(struct mosquitto_db *db, const char *username, const c
*/
rc = MOSQ_ERR_SUCCESS;
for(i=0; i<db->auth_plugin_count; i++){
rc = db->auth_plugins[i].unpwd_check(db->auth_plugins[i].user_data, username, password);
rc = db->auth_plugins[i].unpwd_check(db->auth_plugins[i].user_data, context, username, password);
if(rc != MOSQ_ERR_PLUGIN_DEFER){
return rc;
}
Expand Down
5 changes: 3 additions & 2 deletions test/broker/c/auth_plugin.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <string.h>
#include <stdio.h>
#include <string.h>
#include <mosquitto.h>
#include <mosquitto_broker.h>
Expand Down Expand Up @@ -33,14 +33,15 @@ int mosquitto_auth_acl_check(void *user_data, int access, const struct mosquitto
{
const char *username = mosquitto_client_username(client);

printf("%s\n", username);
if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_READ){
return MOSQ_ERR_SUCCESS;
}else{
return MOSQ_ERR_ACL_DENIED;
}
}

int mosquitto_auth_unpwd_check(void *user_data, const char *username, const char *password)
int mosquitto_auth_unpwd_check(void *user_data, const struct mosquitto *client, const char *username, const char *password)
{
if(!strcmp(username, "test-username") && password && !strcmp(password, "cnwTICONIURW")){
return MOSQ_ERR_SUCCESS;
Expand Down

0 comments on commit b3df015

Please sign in to comment.