Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #537: should not log connection message if option disabled #613

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/mosquitto.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ libmosq_EXPORT int mosquitto_username_pw_set(struct mosquitto *mosq, const char
* mosq - a valid mosquitto instance.
* host - the hostname or ip address of the broker to connect to.
* port - the network port to connect to. Usually 1883.
* keepalive - the number of seconds after which the broker should send a PING
* message to the client if no other messages have been exchanged
* keepalive - the number of seconds after which the client should send a PING
* message to the broker if no other messages have been exchanged
* in that time.
*
* Returns:
Expand All @@ -362,8 +362,8 @@ libmosq_EXPORT int mosquitto_connect(struct mosquitto *mosq, const char *host, i
* mosq - a valid mosquitto instance.
* host - the hostname or ip address of the broker to connect to.
* port - the network port to connect to. Usually 1883.
* keepalive - the number of seconds after which the broker should send a PING
* message to the client if no other messages have been exchanged
* keepalive - the number of seconds after which the client should send a PING
* message to the broker if no other messages have been exchanged
* in that time.
* bind_address - the hostname or ip address of the local network interface to
* bind to.
Expand Down Expand Up @@ -395,8 +395,8 @@ libmosq_EXPORT int mosquitto_connect_bind(struct mosquitto *mosq, const char *ho
* mosq - a valid mosquitto instance.
* host - the hostname or ip address of the broker to connect to.
* port - the network port to connect to. Usually 1883.
* keepalive - the number of seconds after which the broker should send a PING
* message to the client if no other messages have been exchanged
* keepalive - the number of seconds after which the client should send a PING
* message to the broker if no other messages have been exchanged
* in that time.
*
* Returns:
Expand Down Expand Up @@ -430,8 +430,8 @@ libmosq_EXPORT int mosquitto_connect_async(struct mosquitto *mosq, const char *h
* mosq - a valid mosquitto instance.
* host - the hostname or ip address of the broker to connect to.
* port - the network port to connect to. Usually 1883.
* keepalive - the number of seconds after which the broker should send a PING
* message to the client if no other messages have been exchanged
* keepalive - the number of seconds after which the client should send a PING
* message to the broker if no other messages have been exchanged
* in that time.
* bind_address - the hostname or ip address of the local network interface to
* bind to.
Expand Down Expand Up @@ -466,8 +466,8 @@ libmosq_EXPORT int mosquitto_connect_bind_async(struct mosquitto *mosq, const ch
* Parameters:
* mosq - a valid mosquitto instance.
* host - the hostname or ip address of the broker to connect to.
* keepalive - the number of seconds after which the broker should send a PING
* message to the client if no other messages have been exchanged
* keepalive - the number of seconds after which the client should send a PING
* message to the broker if no other messages have been exchanged
* in that time.
* bind_address - the hostname or ip address of the local network interface to
* bind to.
Expand Down
6 changes: 3 additions & 3 deletions man/mosquitto.conf.5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<para><code>user &lt;username&gt;</code></para>

<para>The username referred to here is the same as in
<option>password_fil</option>e. It is not the
<option>password_file</option>. It is not the
clientid.</para>

<para>It is also possible to define ACLs based on pattern
Expand Down Expand Up @@ -189,7 +189,7 @@
<term><option>auth_opt_*</option> <replaceable>value</replaceable></term>
<listitem>
<para>Options to be passed to the auth plugin. See the
specific plugin instructions. </para>
specific plugin instructions.</para>
</listitem>
</varlistentry>
<varlistentry>
Expand Down Expand Up @@ -698,7 +698,7 @@
client connected to a listener with mount point
<replaceable>example</replaceable> can only see
messages that are published in the topic hierarchy
<replaceable>example</replaceable> and above.</para>
<replaceable>example</replaceable> and below.</para>
<para>Not reloaded on reload signal.</para>
</listitem>
</varlistentry>
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ to build. For Windows, see also `readme-windows.md`.

If you are building from the git repository then the documentation will not
already be built. Use `make binary` to skip building the man pages, or install
`docbook-xsl` on Debian/Ubuntu systems.
`docbook-xsl` and `xsltproc` on Debian/Ubuntu systems.

### Build Dependencies

Expand Down
12 changes: 7 additions & 5 deletions src/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,14 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li
* expire it and clean up.
*/
if(now_time > context->disconnect_t+db->config->persistent_client_expiration){
if(context->id){
id = context->id;
}else{
id = "<unknown>";
if(db->config->connection_messages == true){
if(context->id){
id = context->id;
}else{
id = "<unknown>";
}
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "Expiring persistent client %s due to timeout.", id);
}
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "Expiring persistent client %s due to timeout.", id);
#ifdef WITH_SYS_TREE
g_clients_expired++;
#endif
Expand Down
28 changes: 18 additions & 10 deletions src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ Copyright (c) 2009-2014 Roger Light <[email protected]>
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
and Eclipse Distribution License v1.0 which accompany this distribution.

The Eclipse Public License is available at
http:https://www.eclipse.org/legal/epl-v10.html
and the Eclipse Distribution License is available at
http:https://www.eclipse.org/org/documents/edl-v10.php.

Contributors:
Roger Light - initial implementation and documentation.
*/
Expand Down Expand Up @@ -118,7 +118,9 @@ int mqtt3_socket_accept(struct mosquitto_db *db, mosq_sock_t listensock)
if(!hosts_access(&wrap_req)){
/* Access is denied */
if(!_mosquitto_socket_get_address(new_sock, address, 1024)){
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "Client connection from %s denied access by tcpd.", address);
if(db->config->connection_messages == true){
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "Client connection from %s denied access by tcpd.", address);
}
}
COMPAT_CLOSE(new_sock);
return -1;
Expand All @@ -144,7 +146,9 @@ int mqtt3_socket_accept(struct mosquitto_db *db, mosq_sock_t listensock)
}

if(new_context->listener->max_connections > 0 && new_context->listener->client_count > new_context->listener->max_connections){
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "Client connection from %s denied: max_connections exceeded.", new_context->address);
if(db->config->connection_messages == true){
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "Client connection from %s denied: max_connections exceeded.", new_context->address);
}
mqtt3_context_cleanup(db, new_context, true);
return -1;
}
Expand Down Expand Up @@ -174,12 +178,14 @@ int mqtt3_socket_accept(struct mosquitto_db *db, mosq_sock_t listensock)
}else if(rc == SSL_ERROR_WANT_WRITE){
new_context->want_write = true;
}else{
e = ERR_get_error();
while(e){
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE,
"Client connection from %s failed: %s.",
new_context->address, ERR_error_string(e, ebuf));
if(db->config->connection_messages == true){
e = ERR_get_error();
while(e){
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE,
"Client connection from %s failed: %s.",
new_context->address, ERR_error_string(e, ebuf));
e = ERR_get_error();
}
}
mqtt3_context_cleanup(db, new_context, true);
return -1;
Expand All @@ -191,7 +197,9 @@ int mqtt3_socket_accept(struct mosquitto_db *db, mosq_sock_t listensock)
}
#endif

_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "New connection from %s on port %d.", new_context->address, new_context->listener->port);
if(db->config->connection_messages == true){
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "New connection from %s on port %d.", new_context->address, new_context->listener->port);
}

return new_sock;
}
Expand Down
8 changes: 6 additions & 2 deletions src/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,15 @@ int mosquitto_acl_check(struct mosquitto_db *db, struct mosquitto *context, cons
* plugins against possible pattern based attacks.
*/
if(username && strpbrk(username, "+#")){
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "ACL denying access to client with dangerous username \"%s\"", username);
if(db->config->connection_messages == true){
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "ACL denying access to client with dangerous username \"%s\"", username);
}
return MOSQ_ERR_ACL_DENIED;
}
if(context->id && strpbrk(context->id, "+#")){
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "ACL denying access to client with dangerous client id \"%s\"", context->id);
if(db->config->connection_messages == true){
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "ACL denying access to client with dangerous client id \"%s\"", context->id);
}
return MOSQ_ERR_ACL_DENIED;
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/security_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,16 @@ int mosquitto_acl_check_default(struct mosquitto_db *db, struct mosquitto *conte
* publish or receive messages to its own place in the hierarchy).
*/
if(context->username && strpbrk(context->username, "+#")){
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "ACL denying access to client with dangerous username \"%s\"", context->username);
if(db->config->connection_messages == true){
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "ACL denying access to client with dangerous username \"%s\"", context->username);
}
return MOSQ_ERR_ACL_DENIED;
}

if(context->id && strpbrk(context->id, "+#")){
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "ACL denying access to client with dangerous client id \"%s\"", context->id);
if(db->config->connection_messages == true){
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "ACL denying access to client with dangerous client id \"%s\"", context->id);
}
return MOSQ_ERR_ACL_DENIED;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/websockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ static int callback_mqtt(struct libwebsocket_context *context,
return -1;
}
if(mosq->listener->max_connections > 0 && mosq->listener->client_count > mosq->listener->max_connections){
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "Client connection from %s denied: max_connections exceeded.", mosq->address);
if(db->config->connection_messages == true){
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "Client connection from %s denied: max_connections exceeded.", mosq->address);
}
_mosquitto_free(mosq);
u->mosq = NULL;
return -1;
Expand Down Expand Up @@ -535,7 +537,7 @@ static int callback_http(struct libwebsocket_context *context,
"Server: mosquitto\r\n"
"Content-Length: %u\r\n\r\n",
(unsigned int)filestat.st_size);
if(libwebsocket_write(wsi, buf, buflen, LWS_WRITE_HTTP) < 0){
if(libwebsocket_write(wsi, buf, buflen, LWS_WRITE_HTTP) < 0){
fclose(u->fptr);
u->fptr = NULL;
return -1;
Expand Down