/src/samba/source3/smbd/notifyd/notifyd_entry.c
Line | Count | Source |
1 | | /* |
2 | | * This program is free software; you can redistribute it and/or modify |
3 | | * it under the terms of the GNU General Public License as published by |
4 | | * the Free Software Foundation; either version 3 of the License, or |
5 | | * (at your option) any later version. |
6 | | * |
7 | | * This program is distributed in the hope that it will be useful, |
8 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | | * GNU General Public License for more details. |
11 | | * |
12 | | * You should have received a copy of the GNU General Public License |
13 | | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
14 | | */ |
15 | | |
16 | | #include "replace.h" |
17 | | #include "lib/util/debug.h" |
18 | | #include "notifyd_private.h" |
19 | | |
20 | | /* |
21 | | * Parse an entry in the notifyd_context->entries database |
22 | | */ |
23 | | |
24 | | /** |
25 | | * @brief Parse a notifyd database entry. |
26 | | * |
27 | | * The memory we pass down needs to be aligned. If it isn't aligned we can run |
28 | | * into obscure errors as we just point into the data buffer. |
29 | | * |
30 | | * @param data The data to parse |
31 | | * @param data_len The length of the data to parse |
32 | | * @param watcher A pointer to store the watcher data or NULL. |
33 | | * @param instances A pointer to store the array of notify instances or NULL. |
34 | | * @param pnum_instances The number of elements in the array. If you just want |
35 | | * the number of elements pass NULL for the watcher and instances pointers. |
36 | | * |
37 | | * @return true on success, false if an error occurred. |
38 | | */ |
39 | | bool notifyd_parse_entry(uint8_t *data, |
40 | | size_t data_len, |
41 | | struct notifyd_watcher *watcher, |
42 | | struct notifyd_instance **instances, |
43 | | size_t *pnum_instances) |
44 | 0 | { |
45 | 0 | size_t ilen; |
46 | |
|
47 | 0 | if (data_len < sizeof(struct notifyd_watcher)) { |
48 | 0 | return false; |
49 | 0 | } |
50 | | |
51 | 0 | if (watcher != NULL) { |
52 | 0 | *watcher = *((struct notifyd_watcher *)(uintptr_t)data); |
53 | 0 | } |
54 | |
|
55 | 0 | ilen = data_len - sizeof(struct notifyd_watcher); |
56 | 0 | if ((ilen % sizeof(struct notifyd_instance)) != 0) { |
57 | 0 | return false; |
58 | 0 | } |
59 | | |
60 | 0 | if (pnum_instances != NULL) { |
61 | 0 | *pnum_instances = ilen / sizeof(struct notifyd_instance); |
62 | 0 | } |
63 | 0 | if (instances != NULL) { |
64 | | /* The (uintptr_t) cast removes a warning from -Wcast-align. */ |
65 | 0 | *instances = |
66 | 0 | (struct notifyd_instance *)(uintptr_t) |
67 | 0 | (data + sizeof(struct notifyd_watcher)); |
68 | 0 | } |
69 | |
|
70 | | return true; |
71 | 0 | } |