[c5c522c] | 1 | /* $Id: storage_driver.c,v 1.15 2011/06/28 00:13:48 sbajic Exp $ */ |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | DSPAM |
---|
| 5 | COPYRIGHT (C) 2002-2012 DSPAM PROJECT |
---|
| 6 | |
---|
| 7 | This program is free software: you can redistribute it and/or modify |
---|
| 8 | it under the terms of the GNU Affero General Public License as |
---|
| 9 | published by the Free Software Foundation, either version 3 of the |
---|
| 10 | License, or (at your option) any later version. |
---|
| 11 | |
---|
| 12 | This program is distributed in the hope that it will be useful, |
---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | GNU Affero General Public License for more details. |
---|
| 16 | |
---|
| 17 | You should have received a copy of the GNU Affero General Public License |
---|
| 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
| 19 | |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | #ifdef HAVE_CONFIG_H |
---|
| 23 | #include <auto-config.h> |
---|
| 24 | #endif |
---|
| 25 | |
---|
| 26 | #include <stdlib.h> |
---|
| 27 | #include <dlfcn.h> |
---|
| 28 | |
---|
| 29 | #include "libdspam.h" |
---|
| 30 | #include "storage_driver.h" |
---|
| 31 | #include "error.h" |
---|
| 32 | #include "language.h" |
---|
| 33 | |
---|
| 34 | int dspam_init_driver (DRIVER_CTX *DTX) { |
---|
| 35 | int (*ptr)(DRIVER_CTX *); |
---|
| 36 | ptr = (int (*)(DRIVER_CTX *))(intptr_t)dlsym(_drv_handle, "dspam_init_driver"); |
---|
| 37 | if (!ptr) { |
---|
| 38 | LOG(LOG_CRIT, "dlsym(dspam_init_driver) failed: %s", dlerror()); |
---|
| 39 | return EFAILURE; |
---|
| 40 | } |
---|
| 41 | return (*ptr)(DTX); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | int dspam_shutdown_driver (DRIVER_CTX *DTX) { |
---|
| 45 | int (*ptr)(DRIVER_CTX *); |
---|
| 46 | ptr = (int (*)(DRIVER_CTX *))(intptr_t)dlsym(_drv_handle, "dspam_shutdown_driver"); |
---|
| 47 | if (!ptr) { |
---|
| 48 | LOG(LOG_CRIT, "dlsym(dspam_shutdown_driver) failed: %s", dlerror()); |
---|
| 49 | return EFAILURE; |
---|
| 50 | } |
---|
| 51 | return (*ptr)(DTX); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | int _ds_init_storage (DSPAM_CTX * CTX, void *dbh) { |
---|
| 55 | int (*ptr)(DSPAM_CTX *, void *); |
---|
| 56 | ptr = (int (*)(DSPAM_CTX *, void *))(intptr_t)dlsym(_drv_handle, "_ds_init_storage"); |
---|
| 57 | if (!ptr) { |
---|
| 58 | LOG(LOG_CRIT, "dlsym(_ds_init_storage) failed: %s", dlerror()); |
---|
| 59 | return EFAILURE; |
---|
| 60 | } |
---|
| 61 | return (*ptr)(CTX, dbh); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | int _ds_shutdown_storage (DSPAM_CTX * CTX) |
---|
| 65 | { |
---|
| 66 | int (*ptr)(DSPAM_CTX *); |
---|
| 67 | ptr = (int (*)(DSPAM_CTX *))(intptr_t)dlsym(_drv_handle, "_ds_shutdown_storage"); |
---|
| 68 | if (!ptr) { |
---|
| 69 | LOG(LOG_CRIT, "dlsym(_ds_shutdown_storage) failed: %s", dlerror()); |
---|
| 70 | return EFAILURE; |
---|
| 71 | } |
---|
| 72 | return (*ptr)(CTX); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | int _ds_getall_spamrecords (DSPAM_CTX * CTX, ds_diction_t diction) |
---|
| 76 | { |
---|
| 77 | int (*ptr)(DSPAM_CTX *, ds_diction_t); |
---|
| 78 | ptr = (int (*)(DSPAM_CTX *, ds_diction_t))(intptr_t)dlsym(_drv_handle, "_ds_getall_spamrecords"); |
---|
| 79 | if (!ptr) { |
---|
| 80 | LOG(LOG_CRIT, "dlsym(_ds_getall_spamrecords) failed: %s", dlerror()); |
---|
| 81 | return EFAILURE; |
---|
| 82 | } |
---|
| 83 | return (*ptr)(CTX, diction); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | int _ds_setall_spamrecords (DSPAM_CTX * CTX, ds_diction_t diction) |
---|
| 87 | { |
---|
| 88 | int (*ptr)(DSPAM_CTX *, ds_diction_t); |
---|
| 89 | ptr = (int (*)(DSPAM_CTX *, ds_diction_t))(intptr_t)dlsym(_drv_handle, "_ds_setall_spamrecords"); |
---|
| 90 | if (!ptr) { |
---|
| 91 | LOG(LOG_CRIT, "dlsym(_ds_setall_spamrecords) failed: %s", dlerror()); |
---|
| 92 | return EFAILURE; |
---|
| 93 | } |
---|
| 94 | return (*ptr)(CTX, diction); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | int _ds_delall_spamrecords (DSPAM_CTX * CTX, ds_diction_t diction) |
---|
| 98 | { |
---|
| 99 | int (*ptr)(DSPAM_CTX *, ds_diction_t); |
---|
| 100 | ptr = (int (*)(DSPAM_CTX *, ds_diction_t))(intptr_t)dlsym(_drv_handle, "_ds_delall_spamrecords"); |
---|
| 101 | if (!ptr) { |
---|
| 102 | LOG(LOG_CRIT, "dlsym(_ds_delall_spamrecords) failed: %s", dlerror()); |
---|
| 103 | return EFAILURE; |
---|
| 104 | } |
---|
| 105 | return (*ptr)(CTX, diction); |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | int _ds_get_spamrecord ( |
---|
| 109 | DSPAM_CTX * CTX, |
---|
| 110 | unsigned long long token, |
---|
| 111 | struct _ds_spam_stat *stat) |
---|
| 112 | { |
---|
| 113 | int (*ptr)(DSPAM_CTX *, unsigned long long, struct _ds_spam_stat *); |
---|
| 114 | ptr = (int (*)(DSPAM_CTX *, unsigned long long, struct _ds_spam_stat *))(intptr_t)dlsym(_drv_handle, "_ds_get_spamrecord"); |
---|
| 115 | if (!ptr) { |
---|
| 116 | LOG(LOG_CRIT, "dlsym(_ds_get_spamrecord) failed: %s", dlerror()); |
---|
| 117 | return EFAILURE; |
---|
| 118 | } |
---|
| 119 | return (*ptr)(CTX, token, stat); |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | int _ds_set_spamrecord ( |
---|
| 123 | DSPAM_CTX * CTX, |
---|
| 124 | unsigned long long token, |
---|
| 125 | struct _ds_spam_stat *stat) |
---|
| 126 | { |
---|
| 127 | int (*ptr)(DSPAM_CTX *, unsigned long long, struct _ds_spam_stat *); |
---|
| 128 | ptr = (int (*)(DSPAM_CTX *, unsigned long long, struct _ds_spam_stat *))(intptr_t)dlsym(_drv_handle, "_ds_set_spamrecord"); |
---|
| 129 | if (!ptr) { |
---|
| 130 | LOG(LOG_CRIT, "dlsym(_ds_set_spamrecord) failed: %s", dlerror()); |
---|
| 131 | return EFAILURE; |
---|
| 132 | } |
---|
| 133 | return (*ptr)(CTX, token, stat); |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | int _ds_del_spamrecord (DSPAM_CTX * CTX, unsigned long long token) |
---|
| 137 | { |
---|
| 138 | int (*ptr)(DSPAM_CTX *, unsigned long long); |
---|
| 139 | ptr = (int (*)(DSPAM_CTX *, unsigned long long))(intptr_t)dlsym(_drv_handle, "_ds_del_spamrecord"); |
---|
| 140 | if (!ptr) { |
---|
| 141 | LOG(LOG_CRIT, "dlsym(_ds_del_spamrecord) failed: %s", dlerror()); |
---|
| 142 | return EFAILURE; |
---|
| 143 | } |
---|
| 144 | return (*ptr)(CTX, token); |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | struct _ds_storage_record *_ds_get_nexttoken (DSPAM_CTX * CTX) |
---|
| 148 | { |
---|
| 149 | struct _ds_storage_record *(*ptr)(DSPAM_CTX *); |
---|
| 150 | ptr = (struct _ds_storage_record * (*)(DSPAM_CTX *))(intptr_t)dlsym(_drv_handle, "_ds_get_nexttoken"); |
---|
| 151 | if (!ptr) { |
---|
| 152 | LOG(LOG_CRIT, "dlsym(_ds_get_nexttoken) failed: %s", dlerror()); |
---|
| 153 | return NULL; |
---|
| 154 | } |
---|
| 155 | return (*ptr)(CTX); |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | struct _ds_storage_signature *_ds_get_nextsignature (DSPAM_CTX * CTX) |
---|
| 159 | { |
---|
| 160 | struct _ds_storage_signature *(*ptr)(DSPAM_CTX *); |
---|
| 161 | ptr = (struct _ds_storage_signature * (*)(DSPAM_CTX *))(intptr_t)dlsym(_drv_handle, "_ds_get_nextsignature"); |
---|
| 162 | if (!ptr) { |
---|
| 163 | LOG(LOG_CRIT, "dlsym(_ds_get_nextsignature) failed: %s", dlerror()); |
---|
| 164 | return NULL; |
---|
| 165 | } |
---|
| 166 | return (*ptr)(CTX); |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | char *_ds_get_nextuser (DSPAM_CTX * CTX) |
---|
| 170 | { |
---|
| 171 | char *(*ptr)(DSPAM_CTX *); |
---|
| 172 | ptr = (char * (*)(DSPAM_CTX *))(intptr_t)dlsym(_drv_handle, "_ds_get_nextuser"); |
---|
| 173 | if (!ptr) { |
---|
| 174 | LOG(LOG_CRIT, "dlsym(_ds_get_nextuser) failed: %s", dlerror()); |
---|
| 175 | return NULL; |
---|
| 176 | } |
---|
| 177 | return (*ptr)(CTX); |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | int _ds_delete_signature (DSPAM_CTX * CTX, const char *signature) |
---|
| 181 | { |
---|
| 182 | int (*ptr)(DSPAM_CTX *, const char *); |
---|
| 183 | ptr = (int (*)(DSPAM_CTX *, const char *))(intptr_t)dlsym(_drv_handle, "_ds_delete_signature"); |
---|
| 184 | if (!ptr) { |
---|
| 185 | LOG(LOG_CRIT, "dlsym(_ds_delete_signature) failed: %s", dlerror()); |
---|
| 186 | return EFAILURE; |
---|
| 187 | } |
---|
| 188 | return (*ptr)(CTX, signature); |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | int _ds_get_signature ( |
---|
| 192 | DSPAM_CTX * CTX, |
---|
| 193 | struct _ds_spam_signature *SIG, |
---|
| 194 | const char *signature) |
---|
| 195 | { |
---|
| 196 | int (*ptr)(DSPAM_CTX *, struct _ds_spam_signature *, const char *); |
---|
| 197 | ptr = (int (*)(DSPAM_CTX *, struct _ds_spam_signature *, const char *))(intptr_t)dlsym(_drv_handle, "_ds_get_signature"); |
---|
| 198 | if (!ptr) { |
---|
| 199 | LOG(LOG_CRIT, "dlsym(_ds_get_signature) failed: %s", dlerror()); |
---|
| 200 | return EFAILURE; |
---|
| 201 | } |
---|
| 202 | return (*ptr)(CTX, SIG, signature); |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | int _ds_set_signature ( |
---|
| 206 | DSPAM_CTX * CTX, |
---|
| 207 | struct _ds_spam_signature *SIG, |
---|
| 208 | const char *signature) |
---|
| 209 | { |
---|
| 210 | int (*ptr)(DSPAM_CTX *, struct _ds_spam_signature *, const char *); |
---|
| 211 | ptr = (int (*)(DSPAM_CTX *, struct _ds_spam_signature *, const char *))(intptr_t)dlsym(_drv_handle, "_ds_set_signature"); |
---|
| 212 | if (!ptr) { |
---|
| 213 | LOG(LOG_CRIT, "dlsym(_ds_set_signature) failed: %s", dlerror()); |
---|
| 214 | return EFAILURE; |
---|
| 215 | } |
---|
| 216 | return (*ptr)(CTX, SIG, signature); |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | int _ds_verify_signature (DSPAM_CTX * CTX, const char *signature) |
---|
| 220 | { |
---|
| 221 | int (*ptr)(DSPAM_CTX *, const char *); ptr = (int (*)(DSPAM_CTX *, const char *))(intptr_t)dlsym(_drv_handle, "_ds_verify_signature"); |
---|
| 222 | if (!ptr) { |
---|
| 223 | LOG(LOG_CRIT, "dlsym(_ds_verify_signature) failed: %s", dlerror()); |
---|
| 224 | return EFAILURE; |
---|
| 225 | } |
---|
| 226 | return (*ptr)(CTX, signature); |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | int _ds_create_signature_id (DSPAM_CTX * CTX, char *buf, size_t len) |
---|
| 230 | { |
---|
| 231 | int (*ptr)(DSPAM_CTX *, char *, size_t); |
---|
| 232 | ptr = (int (*)(DSPAM_CTX *, char *, size_t))(intptr_t)dlsym(_drv_handle, "_ds_create_signature_id"); |
---|
| 233 | if (!ptr) { |
---|
| 234 | LOG(LOG_CRIT, "dlsym(_ds_create_signature_id) failed: %s", dlerror()); |
---|
| 235 | return EFAILURE; |
---|
| 236 | } |
---|
| 237 | return (*ptr)(CTX, buf, len); |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | void *_ds_connect (DSPAM_CTX *CTX) |
---|
| 241 | { |
---|
| 242 | void *(*ptr)(DSPAM_CTX *); |
---|
| 243 | ptr = (void * (*)(DSPAM_CTX *))(intptr_t)dlsym(_drv_handle, "_ds_connect"); |
---|
| 244 | if (!ptr) { |
---|
| 245 | LOG(LOG_CRIT, "dlsym(_ds_connect) failed: %s", dlerror()); |
---|
| 246 | return NULL; |
---|
| 247 | } |
---|
| 248 | return (*ptr)(CTX); |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | agent_pref_t _ds_pref_load( |
---|
| 252 | config_t config, |
---|
| 253 | const char *user, |
---|
| 254 | const char *home, void *dbh) |
---|
| 255 | { |
---|
| 256 | agent_pref_t (*ptr)(config_t, const char *, const char *, void *); |
---|
| 257 | ptr = (agent_pref_t (*)(config_t, const char *, const char *, void *))(intptr_t)dlsym(_drv_handle, "_ds_pref_load"); |
---|
| 258 | if (!ptr) { |
---|
| 259 | LOG(LOG_CRIT, "dlsym(_ds_pref_load) failed: %s", dlerror()); |
---|
| 260 | return NULL; |
---|
| 261 | } |
---|
| 262 | return (*ptr)(config, user, home, dbh); |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | int _ds_pref_set( |
---|
| 266 | config_t config, |
---|
| 267 | const char *user, |
---|
| 268 | const char *home, |
---|
| 269 | const char *attrib, |
---|
| 270 | const char *value, |
---|
| 271 | void *dbh) |
---|
| 272 | { |
---|
| 273 | int (*ptr)(config_t, const char *, const char *, const char *, const char *, void *); |
---|
| 274 | ptr = (int (*)(config_t, const char *, const char *, const char *, const char *, void *))(intptr_t)dlsym(_drv_handle, "_ds_pref_set"); |
---|
| 275 | if (!ptr) { |
---|
| 276 | LOG(LOG_CRIT, "dlsym(_ds_pref_set) failed: %s", dlerror()); |
---|
| 277 | return EFAILURE; |
---|
| 278 | } |
---|
| 279 | return (*ptr)(config, user, home, attrib, value, dbh); |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | int _ds_pref_del( |
---|
| 283 | config_t config, |
---|
| 284 | const char *user, |
---|
| 285 | const char *home, |
---|
| 286 | const char *attrib, |
---|
| 287 | void *dbh) |
---|
| 288 | { |
---|
| 289 | int (*ptr)(config_t, const char *, const char *, const char *, void *); |
---|
| 290 | ptr = (int (*)(config_t, const char *, const char *, const char *, void *))(intptr_t)dlsym(_drv_handle, "_ds_pref_del"); |
---|
| 291 | if (!ptr) { |
---|
| 292 | LOG(LOG_CRIT, "dlsym(_ds_pref_del) failed: %s", dlerror()); |
---|
| 293 | return EFAILURE; |
---|
| 294 | } |
---|
| 295 | return (*ptr)(config, user, home, attrib, dbh); |
---|
| 296 | } |
---|