Coverage Report

Created: 2025-06-20 06:45

/src/mosquitto/plugins/dynamic-security/auth.c
Line
Count
Source (jump to first uncovered line)
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
 * # Username/password check
31
 * #
32
 * ################################################################ */
33
34
int dynsec_auth__basic_auth_callback(int event, void *event_data, void *userdata)
35
0
{
36
0
  struct mosquitto_evt_basic_auth *ed = event_data;
37
0
  struct dynsec__data *data = userdata;
38
0
  struct dynsec__client *client;
39
0
  const char *clientid;
40
41
0
  UNUSED(event);
42
0
  UNUSED(userdata);
43
44
0
  if(ed->username == NULL || ed->password == NULL) return MOSQ_ERR_PLUGIN_DEFER;
45
46
0
  client = dynsec_clients__find(data, ed->username);
47
0
  if(client){
48
0
    if(client->disabled){
49
0
      return MOSQ_ERR_AUTH;
50
0
    }
51
0
    if(client->clientid){
52
0
      clientid = mosquitto_client_id(ed->client);
53
0
      if(clientid == NULL || strcmp(client->clientid, clientid)){
54
0
        return MOSQ_ERR_AUTH;
55
0
      }
56
0
    }
57
0
    if(mosquitto_pw_verify(client->pw, ed->password) == MOSQ_ERR_SUCCESS){
58
0
      return MOSQ_ERR_SUCCESS;
59
0
    }else{
60
0
      return MOSQ_ERR_AUTH;
61
0
    }
62
0
  }else{
63
0
    return MOSQ_ERR_PLUGIN_DEFER;
64
0
  }
65
0
}