/src/mosquitto/plugins/password-file/password_check.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | Copyright (c) 2011-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 <uthash.h> |
22 | | |
23 | | #include "mosquitto.h" |
24 | | #include "password_file.h" |
25 | | |
26 | | int password_file__check(int event, void *event_data, void *userdata) |
27 | 0 | { |
28 | 0 | struct mosquitto_evt_basic_auth *ed = event_data; |
29 | 0 | struct password_file_data *data = userdata; |
30 | 0 | struct mosquitto__unpwd *u; |
31 | |
|
32 | 0 | UNUSED(event); |
33 | |
|
34 | 0 | if(ed->username == NULL){ |
35 | 0 | return MOSQ_ERR_PLUGIN_IGNORE; |
36 | 0 | } |
37 | | |
38 | | // FIXME if(ed->client->bridge) return MOSQ_ERR_SUCCESS; |
39 | | |
40 | 0 | HASH_FIND(hh, data->unpwd, ed->username, strlen(ed->username), u); |
41 | 0 | if(u){ |
42 | 0 | if(u->pw){ |
43 | 0 | if(ed->password){ |
44 | 0 | return mosquitto_pw_verify(u->pw, ed->password); |
45 | 0 | }else{ |
46 | 0 | return MOSQ_ERR_AUTH; |
47 | 0 | } |
48 | 0 | }else{ |
49 | 0 | return MOSQ_ERR_SUCCESS; |
50 | 0 | } |
51 | 0 | } |
52 | | |
53 | 0 | return MOSQ_ERR_AUTH; |
54 | 0 | } |