Tue, 20 Aug 2024 12:34:32 +0200
fix pg ext uninitialized memory acces - fixes #420
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2022 Olaf Wintermann. All rights reserved. |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #ifndef WS_PG_CONFIG_H |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #define WS_PG_CONFIG_H |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #include "../../public/nsapi.h" |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #include "../../public/webdav.h" |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #include "../../daemon/config.h" |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #include "../../config/serverconfig.h" |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | #include <inttypes.h> |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | #include <libpq-fe.h> |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
43 | #include <cx/string.h> |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
44 | #include <cx/linked_list.h> |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
45 | #include <cx/hash_map.h> |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
46 | #include <cx/compare.h> |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | #ifdef __cplusplus |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | extern "C" { |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | #endif |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | |
373
f78a585e1a2f
add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
52 | typedef struct { |
f78a585e1a2f
add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
53 | char *table; |
f78a585e1a2f
add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
54 | WSBool isused; |
f78a585e1a2f
add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
55 | } PgExtTable; |
f78a585e1a2f
add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
56 | |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | typedef struct PgRepository { |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | int64_t root_resource_id; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
59 | cxmutstr resourcepool; |
373
f78a585e1a2f
add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
60 | PgExtTable *tables; |
f78a585e1a2f
add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
61 | size_t ntables; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
62 | CxMap *prop_ext; |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | } PgRepository; |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | |
373
f78a585e1a2f
add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
65 | typedef struct { |
f78a585e1a2f
add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
66 | char *column; |
f78a585e1a2f
add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
67 | char *ns; |
f78a585e1a2f
add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
68 | char *name; |
f78a585e1a2f
add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
69 | int tableindex; |
f78a585e1a2f
add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
70 | } PgPropertyStoreExt; |
f78a585e1a2f
add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
71 | |
f78a585e1a2f
add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
72 | typedef struct { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
73 | CxMap *table_lookup; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
74 | CxList *tables; |
373
f78a585e1a2f
add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
75 | } PgExtParser; |
f78a585e1a2f
add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
76 | |
374
77506ec632a4
use configured root node from PgRepository in pg vfs/webdav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
77 | int pg_lookup_root(ResourceData *res, const char *rootnode, int64_t *rootid); |
77506ec632a4
use configured root node from PgRepository in pg vfs/webdav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
78 | |
372
1d2538a1ba8f
add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
79 | PgRepository* pg_init_repo(ServerConfiguration *cfg, pool_handle_t *pool, WSConfigNode *config); |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | #ifdef __cplusplus |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | } |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | #endif |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | #endif /* WS_PG_CONFIG_H */ |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 |