Skip to content
This repository has been archived by the owner on Mar 12, 2019. It is now read-only.

Commit

Permalink
support clientid in be_*_getuser()
Browse files Browse the repository at this point in the history
	closes #266
  • Loading branch information
jpmens committed Nov 21, 2018
1 parent 2795fef commit 837e3c7
Show file tree
Hide file tree
Showing 25 changed files with 30 additions and 27 deletions.
6 changes: 4 additions & 2 deletions README.md
Expand Up @@ -163,8 +163,9 @@ The following `auth_opt_` options are supported by the mysql back-end:
The SQL query for looking up a user's password hash is mandatory. The query
MUST return a single row only (any other number of rows is considered to be
"user not found"), and it MUST return a single column only with the PBKDF2
password hash. A single `'%s'` in the query string is replaced by the
username attempting to access the broker.
password hash. Two `'%s'` in the userquery string are replaced by the
username attempting to access the broker and the clientid respectively. (If the clientid is not
to be used in the SQL, insert just a single `'%s'` into the _userquery_ parameter.)

```sql
SELECT pw FROM users WHERE username = '%s' LIMIT 1
Expand Down Expand Up @@ -209,6 +210,7 @@ auth_opt_dbname test
auth_opt_user jjj
auth_opt_pass supersecret
auth_opt_userquery SELECT pw FROM users WHERE username = '%s'
# auth_opt_userquery SELECT pwhash FROM user WHERE username = '%s' AND clientid = '%s'
auth_opt_superquery SELECT COUNT(*) FROM users WHERE username = '%s' AND super = 1
auth_opt_aclquery SELECT topic FROM acls WHERE (username = '%s') AND (rw >= %d)
auth_opt_anonusername AnonymouS
Expand Down
2 changes: 1 addition & 1 deletion auth-plug.c
Expand Up @@ -552,7 +552,7 @@ int mosquitto_auth_unpwd_check(void *userdata, const char *username, const char
free(phash);
phash = NULL;
}
rc = b->getuser(b->conf, username, password, &phash);
rc = b->getuser(b->conf, username, password, &phash, mosquitto_client_id(client));
if (rc == BACKEND_ALLOW) {
backend_name = (*bep)->name;
authenticated = TRUE;
Expand Down
2 changes: 1 addition & 1 deletion backends.h
Expand Up @@ -50,7 +50,7 @@
# define __BACKENDS_H

typedef void (f_kill)(void *conf);
typedef int (f_getuser)(void *conf, const char *username, const char *password, char **phash);
typedef int (f_getuser)(void *conf, const char *username, const char *password, char **phash, const char *clientid);
typedef int (f_superuser)(void *conf, const char *username);
typedef int (f_aclcheck)(void *conf, const char *clientid, const char *username, const char *topic, int acc);

Expand Down
2 changes: 1 addition & 1 deletion be-cdb.c
Expand Up @@ -85,7 +85,7 @@ void be_cdb_destroy(void *handle)
}
}

int be_cdb_getuser(void *handle, const char *username, const char *password, char **phash)
int be_cdb_getuser(void *handle, const char *username, const char *password, char **phash, const char *clientid)
{
struct cdb_backend *conf = (struct cdb_backend *)handle;
char *k, *v = NULL;
Expand Down
2 changes: 1 addition & 1 deletion be-cdb.h
Expand Up @@ -36,7 +36,7 @@ struct cdb_backend {

void *be_cdb_init();
void be_cdb_destroy(void *handle);
int be_cdb_getuser(void *handle, const char *username, const char *password, char **phash);
int be_cdb_getuser(void *handle, const char *username, const char *password, char **phash, const char *clientid);
int be_cdb_access(void *handle, const char *username, char *topic);
int be_cdb_superuser(void *handle, const char *username);
int be_cdb_aclcheck(void *handle, const char *clientid, const char *username, const char *topic, int acc);
Expand Down
2 changes: 1 addition & 1 deletion be-files.c
Expand Up @@ -337,7 +337,7 @@ void be_files_destroy(void *handle)
int be_files_getuser(void *handle,
const char *username,
const char *password,
char **phash)
char **phash, const char *clientid)
{
be_files *const conf = (be_files *) handle;
pwd_entry *entry = find_pwd(conf, username);
Expand Down
2 changes: 1 addition & 1 deletion be-files.h
Expand Up @@ -31,7 +31,7 @@

void *be_files_init();
void be_files_destroy(void *handle);
int be_files_getuser(void *handle, const char *username, const char *password, char **phash);
int be_files_getuser(void *handle, const char *username, const char *password, char **phash, const char *clientid);
int be_files_superuser(void *handle, const char *username);
int be_files_aclcheck(void *handle, const char *clientid, const char *username, const char *topic, int access);

Expand Down
2 changes: 1 addition & 1 deletion be-http.c
Expand Up @@ -305,7 +305,7 @@ void be_http_destroy(void *handle)
}
};

int be_http_getuser(void *handle, const char *username, const char *password, char **phash) {
int be_http_getuser(void *handle, const char *username, const char *password, char **phash, const char *clientid) {
struct http_backend *conf = (struct http_backend *)handle;
int re, try;
if (username == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion be-http.h
Expand Up @@ -50,7 +50,7 @@ struct http_backend {

void *be_http_init();
void be_http_destroy(void *conf);
int be_http_getuser(void *conf, const char *username, const char *password, char **phash);
int be_http_getuser(void *conf, const char *username, const char *password, char **phash, const char *clientid);
int be_http_superuser(void *conf, const char *username);
int be_http_aclcheck(void *conf, const char *clientid, const char *username, const char *topic, int acc);
#endif /* BE_HTTP */
2 changes: 1 addition & 1 deletion be-jwt.c
Expand Up @@ -284,7 +284,7 @@ void be_jwt_destroy(void *handle)
}
};

int be_jwt_getuser(void *handle, const char *token, const char *pass, char **phash)
int be_jwt_getuser(void *handle, const char *token, const char *pass, char **phash, const char *clientid)
{
struct jwt_backend *conf = (struct jwt_backend *)handle;
int re;
Expand Down
2 changes: 1 addition & 1 deletion be-jwt.h
Expand Up @@ -49,7 +49,7 @@ struct jwt_backend {

void *be_jwt_init();
void be_jwt_destroy(void *conf);
int be_jwt_getuser(void *conf, const char *token, const char *password, char **phash);
int be_jwt_getuser(void *conf, const char *token, const char *password, char **phash, const char *clientid);
int be_jwt_superuser(void *conf, const char *token);
int be_jwt_aclcheck(void *conf, const char *clientid, const char *token, const char *topic, int acc);
#endif /* BE_JWT */
2 changes: 1 addition & 1 deletion be-ldap.c
Expand Up @@ -186,7 +186,7 @@ static int user_bind(char *connstr, char *dn, const char *password)

}

int be_ldap_getuser(void *handle, const char *username, const char *password, char **phash)
int be_ldap_getuser(void *handle, const char *username, const char *password, char **phash, const char *clientid)
{
struct ldap_backend *conf = (struct ldap_backend *)handle;
LDAPMessage *msg,*entry;
Expand Down
2 changes: 1 addition & 1 deletion be-ldap.h
Expand Up @@ -34,7 +34,7 @@

void *be_ldap_init();
void be_ldap_destroy(void *conf);
int be_ldap_getuser(void *conf, const char *username, const char *password, char **phash);
int be_ldap_getuser(void *conf, const char *username, const char *password, char **phash, const char *clientid);
int be_ldap_superuser(void *conf, const char *username);
int be_ldap_aclcheck(void *conf, const char *clientid, const char *username, const char *topic, int acc);
#endif /* BE_LDAP */
2 changes: 1 addition & 1 deletion be-memcached.c
Expand Up @@ -136,7 +136,7 @@ void be_memcached_destroy(void *handle)
}
}

int be_memcached_getuser(void *handle, const char *username, const char *password, char **phash)
int be_memcached_getuser(void *handle, const char *username, const char *password, char **phash, const char *clientid)
{
struct memcached_backend *conf = (struct memcached_backend *)handle;

Expand Down
2 changes: 1 addition & 1 deletion be-memcached.h
Expand Up @@ -31,7 +31,7 @@

void *be_memcached_init();
void be_memcached_destroy(void *conf);
int be_memcached_getuser(void *handle, const char *username, const char *password, char **phash);
int be_memcached_getuser(void *handle, const char *username, const char *password, char **phash, const char *clientid);
int be_memcached_superuser(void *conf, const char *username);
int be_memcached_aclcheck(void *conf, const char *clientid, const char *username, const char *topic, int acc);
#endif /* BE_MEMCACHED */
2 changes: 1 addition & 1 deletion be-mongo.c
Expand Up @@ -114,7 +114,7 @@ mongoc_uri_t *be_mongo_new_uri_from_options() {
return uri;
}

int be_mongo_getuser(void *handle, const char *username, const char *password, char **phash)
int be_mongo_getuser(void *handle, const char *username, const char *password, char **phash, const char *clientid)
{
struct mongo_backend *conf = (struct mongo_backend *)handle;
mongoc_collection_t *collection;
Expand Down
2 changes: 1 addition & 1 deletion be-mongo.h
Expand Up @@ -31,7 +31,7 @@

void *be_mongo_init();
void be_mongo_destroy(void *conf);
int be_mongo_getuser(void *conf, const char *username, const char *password, char **phash);
int be_mongo_getuser(void *conf, const char *username, const char *password, char **phash, const char *clientid);
int be_mongo_superuser(void *conf, const char *username);
int be_mongo_aclcheck(void *conf, const char *clientid, const char *username, const char *topic, int acc);
#endif /* BE_MONGO */
5 changes: 3 additions & 2 deletions be-mysql.c
Expand Up @@ -186,14 +186,15 @@ static bool auto_connect(struct mysql_backend *conf)
return false;
}

int be_mysql_getuser(void *handle, const char *username, const char *password, char **phash)
int be_mysql_getuser(void *handle, const char *username, const char *password, char **phash, const char *clientid)
{
struct mysql_backend *conf = (struct mysql_backend *)handle;
char *query = NULL, *u = NULL, *value = NULL, *v;
long nrows, ulen;
MYSQL_RES *res = NULL;
MYSQL_ROW rowdata;

// fprintf(stderr, "------>%s<-----\n", clientid);
if (!conf || !conf->userquery || !username || !*username)
return BACKEND_DEFER;

Expand All @@ -210,7 +211,7 @@ int be_mysql_getuser(void *handle, const char *username, const char *password, c
free(u);
return BACKEND_ERROR;
}
sprintf(query, conf->userquery, u);
sprintf(query, conf->userquery, u, clientid);
free(u);

if (mysql_query(conf->mysql, query)) {
Expand Down
2 changes: 1 addition & 1 deletion be-mysql.h
Expand Up @@ -33,7 +33,7 @@

void *be_mysql_init();
void be_mysql_destroy(void *conf);
int be_mysql_getuser(void *conf, const char *username, const char *password, char **phash);
int be_mysql_getuser(void *conf, const char *username, const char *password, char **phash, const char *clientid);
int be_mysql_superuser(void *conf, const char *username);
int be_mysql_aclcheck(void *conf, const char *clientid, const char *username, const char *topic, int acc);
#endif /* BE_MYSQL */
2 changes: 1 addition & 1 deletion be-postgres.c
Expand Up @@ -162,7 +162,7 @@ void be_pg_destroy(void *handle)
}
}

int be_pg_getuser(void *handle, const char *username, const char *password, char **phash)
int be_pg_getuser(void *handle, const char *username, const char *password, char **phash, const char *clientid)
{
struct pg_backend *conf = (struct pg_backend *)handle;
char *value = NULL, *v = NULL;
Expand Down
2 changes: 1 addition & 1 deletion be-postgres.h
Expand Up @@ -33,7 +33,7 @@

void *be_pg_init();
void be_pg_destroy(void *conf);
int be_pg_getuser(void *conf, const char *username, const char *password, char **phash);
int be_pg_getuser(void *conf, const char *username, const char *password, char **phash, const char *clientid);
int be_pg_superuser(void *conf, const char *username);
int be_pg_aclcheck(void *conf, const char *clientid, const char *username, const char *topic, int acc);
#endif /* BE_POSTGRES */
2 changes: 1 addition & 1 deletion be-redis.c
Expand Up @@ -136,7 +136,7 @@ void be_redis_destroy(void *handle)
}
}

int be_redis_getuser(void *handle, const char *username, const char *password, char **phash)
int be_redis_getuser(void *handle, const char *username, const char *password, char **phash, const char *clientid)
{
struct redis_backend *conf = (struct redis_backend *)handle;

Expand Down
2 changes: 1 addition & 1 deletion be-redis.h
Expand Up @@ -31,7 +31,7 @@

void *be_redis_init();
void be_redis_destroy(void *conf);
int be_redis_getuser(void *conf, const char *username, const char *password, char **phash);
int be_redis_getuser(void *conf, const char *username, const char *password, char **phash, const char *clientid);
int be_redis_superuser(void *conf, const char *username);
int be_redis_aclcheck(void *conf, const char *clientid, const char *username, const char *topic, int acc);
#endif /* BE_REDIS */
2 changes: 1 addition & 1 deletion be-sqlite.c
Expand Up @@ -87,7 +87,7 @@ void be_sqlite_destroy(void *handle)
}
}

int be_sqlite_getuser(void *handle, const char *username, const char *password, char **phash)
int be_sqlite_getuser(void *handle, const char *username, const char *password, char **phash, const char *clientid)
{
struct sqlite_backend *conf = (struct sqlite_backend *)handle;
int res, retries;
Expand Down
2 changes: 1 addition & 1 deletion be-sqlite.h
Expand Up @@ -38,7 +38,7 @@ struct sqlite_backend {

void *be_sqlite_init();
void be_sqlite_destroy(void *handle);
int be_sqlite_getuser(void *handle, const char *username, const char *password, char **phash);
int be_sqlite_getuser(void *handle, const char *username, const char *password, char **phash, const char *clientid);
int be_sqlite_access(void *handle, const char *username, char *topic);
int be_sqlite_superuser(void *handle, const char *username);
int be_sqlite_aclcheck(void *handle, const char *clientid, const char *username, const char *topic, int acc);
Expand Down

0 comments on commit 837e3c7

Please sign in to comment.