Coverage Report

Created: 2025-12-29 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/mosquitto/plugins/dynamic-security/auth.c
Line
Count
Source
1
/*
2
Copyright (c) 2020-2021 Roger Light <roger@atchoo.org>
3
4
All rights reserved. This program and the accompanying materials
5
are made available under the terms of the Eclipse Public License 2.0
6
and Eclipse Distribution License v1.0 which accompany this distribution.
7
8
The Eclipse Public License is available at
9
   https://www.eclipse.org/legal/epl-2.0/
10
and the Eclipse Distribution License is available at
11
  http://www.eclipse.org/org/documents/edl-v10.php.
12
13
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
14
15
Contributors:
16
   Roger Light - initial implementation and documentation.
17
*/
18
19
#include "config.h"
20
21
#include <openssl/bio.h>
22
#include <openssl/buffer.h>
23
#include <openssl/evp.h>
24
#include <openssl/rand.h>
25
26
#include "dynamic_security.h"
27
28
29
/* ################################################################
30
 * #
31
 * # Username/password check
32
 * #
33
 * ################################################################ */
34
35
36
int dynsec_auth__basic_auth_callback(int event, void *event_data, void *userdata)
37
0
{
38
0
  struct mosquitto_evt_basic_auth *ed = event_data;
39
0
  struct dynsec__data *data = userdata;
40
0
  struct dynsec__client *client;
41
0
  const char *clientid;
42
43
0
  UNUSED(event);
44
0
  UNUSED(userdata);
45
46
0
  if(ed->username == NULL || ed->password == NULL){
47
0
    return MOSQ_ERR_PLUGIN_DEFER;
48
0
  }
49
50
0
  client = dynsec_clients__find(data, ed->username);
51
0
  if(client){
52
0
    if(client->disabled){
53
0
      return MOSQ_ERR_AUTH;
54
0
    }
55
0
    if(client->clientid){
56
0
      clientid = mosquitto_client_id(ed->client);
57
0
      if(clientid == NULL || strcmp(client->clientid, clientid)){
58
0
        return MOSQ_ERR_AUTH;
59
0
      }
60
0
    }
61
0
    if(mosquitto_pw_verify(client->pw, ed->password) == MOSQ_ERR_SUCCESS){
62
0
      return MOSQ_ERR_SUCCESS;
63
0
    }else{
64
0
      return MOSQ_ERR_AUTH;
65
0
    }
66
0
  }else{
67
0
    return MOSQ_ERR_PLUGIN_DEFER;
68
0
  }
69
0
}