Revision | f6c9e87b2622d34b878775865af437ab63fadaa5 (tree) |
---|---|
Zeit | 2012-03-18 11:08:06 |
Autor | matsuand <matsuand@user...> |
Commiter | matsuand |
[BLFS] Modified cyrus-sasl and added an unofficial patch.
@@ -36,8 +36,8 @@ rm -fr $TARGETDIR | ||
36 | 36 | cd $TARGETDIR |
37 | 37 | |
38 | 38 | echo \ \ Patching unofficial... |
39 | -#patch -Np1 -i $WRK/patch/cyrus-sasl-$VER.patch | |
40 | -patch -Np1 -i $WRK/patch/cyrus-sasl-2.1.23.patch | |
39 | +#patch -Np1 -i $WRK/patch/cyrus-sasl-2.1.23.patch | |
40 | +patch -Np1 -i $WRK/patch/cyrus-sasl-2.1.25.patch | |
41 | 41 | |
42 | 42 | sed -i.bak 's/#elif WITH_DES/#elif defined(WITH_DES)/' \ |
43 | 43 | plugins/digestmd5.c |
@@ -0,0 +1,597 @@ | ||
1 | +Submitted By: Michio Matsuyama <matsuand AT users DOT sourceforge DOT jp> | |
2 | +Date: 2012-03-18 | |
3 | +Description: Unofficial patch for Cyrus SASL 2.1.25. | |
4 | + NO WARRANTY | |
5 | + | |
6 | +diff -Naur cyrus-sasl-2.1.25.orig/plugins/gs2.c cyrus-sasl-2.1.25/plugins/gs2.c | |
7 | +--- cyrus-sasl-2.1.25.orig/plugins/gs2.c 2011-09-02 21:58:02.000000000 +0900 | |
8 | ++++ cyrus-sasl-2.1.25/plugins/gs2.c 2012-03-18 01:45:58.675987888 +0900 | |
9 | +@@ -72,9 +72,11 @@ | |
10 | + | |
11 | + #include <config.h> | |
12 | + #include <gssapi/gssapi.h> | |
13 | ++#ifndef KRB5_HEIMDAL | |
14 | + #ifdef HAVE_GSSAPI_GSSAPI_EXT_H | |
15 | + #include <gssapi/gssapi_ext.h> | |
16 | + #endif | |
17 | ++#endif | |
18 | + #include <fcntl.h> | |
19 | + #include <stdio.h> | |
20 | + #include <sasl.h> | |
21 | +diff -Naur cyrus-sasl-2.1.25.orig/plugins/gs2_token.h cyrus-sasl-2.1.25/plugins/gs2_token.h | |
22 | +--- cyrus-sasl-2.1.25.orig/plugins/gs2_token.h 2011-09-02 21:58:02.000000000 +0900 | |
23 | ++++ cyrus-sasl-2.1.25/plugins/gs2_token.h 2012-03-18 01:46:50.310989370 +0900 | |
24 | +@@ -26,9 +26,11 @@ | |
25 | + #include <config.h> | |
26 | + | |
27 | + #include <gssapi/gssapi.h> | |
28 | ++#ifndef KRB5_HEIMDAL | |
29 | + #ifdef HAVE_GSSAPI_GSSAPI_EXT_H | |
30 | + #include <gssapi/gssapi_ext.h> | |
31 | + #endif | |
32 | ++#endif | |
33 | + | |
34 | + #ifndef HAVE_GSS_DECAPSULATE_TOKEN | |
35 | + OM_uint32 | |
36 | +diff -Naur cyrus-sasl-2.1.25.orig/sasldb/db_berkeley.c cyrus-sasl-2.1.25/sasldb/db_berkeley.c | |
37 | +--- cyrus-sasl-2.1.25.orig/sasldb/db_berkeley.c 2011-09-02 21:58:02.000000000 +0900 | |
38 | ++++ cyrus-sasl-2.1.25/sasldb/db_berkeley.c 2012-03-18 01:44:09.641973608 +0900 | |
39 | +@@ -101,7 +101,7 @@ | |
40 | + ret = db_create(mbdb, NULL, 0); | |
41 | + if (ret == 0 && *mbdb != NULL) | |
42 | + { | |
43 | +-#if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1 | |
44 | ++#if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1) || DB_VERSION_MAJOR == 5 | |
45 | + ret = (*mbdb)->open(*mbdb, NULL, path, NULL, DB_HASH, flags, 0660); | |
46 | + #else | |
47 | + ret = (*mbdb)->open(*mbdb, path, NULL, DB_HASH, flags, 0660); | |
48 | +diff -Naur cyrus-sasl-2.1.25.orig/sasldb/db_berkeley.c.orig cyrus-sasl-2.1.25/sasldb/db_berkeley.c.orig | |
49 | +--- cyrus-sasl-2.1.25.orig/sasldb/db_berkeley.c.orig 1970-01-01 09:00:00.000000000 +0900 | |
50 | ++++ cyrus-sasl-2.1.25/sasldb/db_berkeley.c.orig 2011-09-02 21:58:02.000000000 +0900 | |
51 | +@@ -0,0 +1,534 @@ | |
52 | ++/* db_berkeley.c--SASL berkeley db interface | |
53 | ++ * Rob Siemborski | |
54 | ++ * Tim Martin | |
55 | ++ * $Id: db_berkeley.c,v 1.10 2011/09/01 14:12:18 mel Exp $ | |
56 | ++ */ | |
57 | ++/* | |
58 | ++ * Copyright (c) 1998-2003 Carnegie Mellon University. All rights reserved. | |
59 | ++ * | |
60 | ++ * Redistribution and use in source and binary forms, with or without | |
61 | ++ * modification, are permitted provided that the following conditions | |
62 | ++ * are met: | |
63 | ++ * | |
64 | ++ * 1. Redistributions of source code must retain the above copyright | |
65 | ++ * notice, this list of conditions and the following disclaimer. | |
66 | ++ * | |
67 | ++ * 2. Redistributions in binary form must reproduce the above copyright | |
68 | ++ * notice, this list of conditions and the following disclaimer in | |
69 | ++ * the documentation and/or other materials provided with the | |
70 | ++ * distribution. | |
71 | ++ * | |
72 | ++ * 3. The name "Carnegie Mellon University" must not be used to | |
73 | ++ * endorse or promote products derived from this software without | |
74 | ++ * prior written permission. For permission or any other legal | |
75 | ++ * details, please contact | |
76 | ++ * Office of Technology Transfer | |
77 | ++ * Carnegie Mellon University | |
78 | ++ * 5000 Forbes Avenue | |
79 | ++ * Pittsburgh, PA 15213-3890 | |
80 | ++ * (412) 268-4387, fax: (412) 268-7395 | |
81 | ++ * tech-transfer@andrew.cmu.edu | |
82 | ++ * | |
83 | ++ * 4. Redistributions of any form whatsoever must retain the following | |
84 | ++ * acknowledgment: | |
85 | ++ * "This product includes software developed by Computing Services | |
86 | ++ * at Carnegie Mellon University (http://www.cmu.edu/computing/)." | |
87 | ++ * | |
88 | ++ * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO | |
89 | ++ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | |
90 | ++ * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE | |
91 | ++ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
92 | ++ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN | |
93 | ++ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING | |
94 | ++ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
95 | ++ */ | |
96 | ++ | |
97 | ++#include <config.h> | |
98 | ++ | |
99 | ++#include <db.h> | |
100 | ++ | |
101 | ++#include <sys/stat.h> | |
102 | ++#include <stdlib.h> | |
103 | ++#include <assert.h> | |
104 | ++#include <errno.h> | |
105 | ++#include "sasldb.h" | |
106 | ++ | |
107 | ++static int db_ok = 0; | |
108 | ++#if defined(KEEP_DB_OPEN) | |
109 | ++static DB * g_db = NULL; | |
110 | ++#endif | |
111 | ++ | |
112 | ++/* | |
113 | ++ * Open the database | |
114 | ++ */ | |
115 | ++static int berkeleydb_open(const sasl_utils_t *utils, | |
116 | ++ sasl_conn_t *conn, | |
117 | ++ int rdwr, DB **mbdb) | |
118 | ++{ | |
119 | ++ const char *path = SASL_DB_PATH; | |
120 | ++ int ret; | |
121 | ++ int flags; | |
122 | ++ void *cntxt; | |
123 | ++ sasl_getopt_t *getopt; | |
124 | ++ | |
125 | ++#if defined(KEEP_DB_OPEN) | |
126 | ++ if (g_db) { | |
127 | ++ *mbdb = g_db; | |
128 | ++ return SASL_OK; | |
129 | ++ } | |
130 | ++#endif | |
131 | ++ | |
132 | ++ if (utils->getcallback(conn, SASL_CB_GETOPT, | |
133 | ++ &getopt, &cntxt) == SASL_OK) { | |
134 | ++ const char *p; | |
135 | ++ if (getopt(cntxt, NULL, "sasldb_path", &p, NULL) == SASL_OK | |
136 | ++ && p != NULL && *p != 0) { | |
137 | ++ path = p; | |
138 | ++ } | |
139 | ++ } | |
140 | ++ | |
141 | ++ if (rdwr) flags = DB_CREATE; | |
142 | ++ else flags = DB_RDONLY; | |
143 | ++#if defined(KEEP_DB_OPEN) | |
144 | ++#if defined(DB_THREAD) | |
145 | ++ flags |= DB_THREAD; | |
146 | ++#endif | |
147 | ++#endif | |
148 | ++ | |
149 | ++#if DB_VERSION_MAJOR < 3 | |
150 | ++ ret = db_open(path, DB_HASH, flags, 0660, NULL, NULL, mbdb); | |
151 | ++#else /* DB_VERSION_MAJOR < 3 */ | |
152 | ++ ret = db_create(mbdb, NULL, 0); | |
153 | ++ if (ret == 0 && *mbdb != NULL) | |
154 | ++ { | |
155 | ++#if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1 | |
156 | ++ ret = (*mbdb)->open(*mbdb, NULL, path, NULL, DB_HASH, flags, 0660); | |
157 | ++#else | |
158 | ++ ret = (*mbdb)->open(*mbdb, path, NULL, DB_HASH, flags, 0660); | |
159 | ++#endif | |
160 | ++ if (ret != 0) | |
161 | ++ { | |
162 | ++ (void) (*mbdb)->close(*mbdb, 0); | |
163 | ++ *mbdb = NULL; | |
164 | ++ } | |
165 | ++ } | |
166 | ++#endif /* DB_VERSION_MAJOR < 3 */ | |
167 | ++ | |
168 | ++ if (ret != 0) { | |
169 | ++ if (rdwr == 0 && ret == ENOENT) { | |
170 | ++ /* File not found and we are only reading the data. | |
171 | ++ Treat as SASL_NOUSER. */ | |
172 | ++ return SASL_NOUSER; | |
173 | ++ } | |
174 | ++ utils->log(conn, SASL_LOG_ERR, | |
175 | ++ "unable to open Berkeley db %s: %s", | |
176 | ++ path, db_strerror(ret)); | |
177 | ++ utils->seterror(conn, SASL_NOLOG, "Unable to open DB"); | |
178 | ++ return SASL_FAIL; | |
179 | ++ } | |
180 | ++ | |
181 | ++#if defined(KEEP_DB_OPEN) | |
182 | ++ /* Save the DB handle for later use */ | |
183 | ++ g_db = *mbdb; | |
184 | ++#endif | |
185 | ++ return SASL_OK; | |
186 | ++} | |
187 | ++ | |
188 | ++/* | |
189 | ++ * Close the database | |
190 | ++ */ | |
191 | ++static void berkeleydb_close(const sasl_utils_t *utils, DB *mbdb) | |
192 | ++{ | |
193 | ++ int ret; | |
194 | ++ | |
195 | ++#if defined(KEEP_DB_OPEN) | |
196 | ++ /* Prevent other threads from reusing the same handle */ | |
197 | ++ /* msdb == g_db */ | |
198 | ++ g_db = NULL; | |
199 | ++#endif | |
200 | ++ | |
201 | ++ ret = mbdb->close(mbdb, 0); | |
202 | ++ if (ret!=0) { | |
203 | ++ /* error closing! */ | |
204 | ++ utils->log(NULL, SASL_LOG_ERR, | |
205 | ++ "error closing sasldb: %s", | |
206 | ++ db_strerror(ret)); | |
207 | ++ } | |
208 | ++} | |
209 | ++ | |
210 | ++ | |
211 | ++/* | |
212 | ++ * Retrieve the secret from the database. | |
213 | ++ * | |
214 | ++ * Return SASL_NOUSER if the entry doesn't exist, | |
215 | ++ * SASL_OK on success. | |
216 | ++ * | |
217 | ++ */ | |
218 | ++int _sasldb_getdata(const sasl_utils_t *utils, | |
219 | ++ sasl_conn_t *context, | |
220 | ++ const char *auth_identity, | |
221 | ++ const char *realm, | |
222 | ++ const char *propName, | |
223 | ++ char *out, const size_t max_out, size_t *out_len) | |
224 | ++{ | |
225 | ++ int result = SASL_OK; | |
226 | ++ char *key; | |
227 | ++ size_t key_len; | |
228 | ++ DBT dbkey, data; | |
229 | ++ DB *mbdb = NULL; | |
230 | ++ | |
231 | ++ if(!utils) return SASL_BADPARAM; | |
232 | ++ | |
233 | ++ /* check parameters */ | |
234 | ++ if (!auth_identity || !realm || !propName || !out || !max_out) { | |
235 | ++ utils->seterror(context, 0, | |
236 | ++ "Bad parameter in db_berkeley.c: _sasldb_getdata"); | |
237 | ++ return SASL_BADPARAM; | |
238 | ++ } | |
239 | ++ | |
240 | ++ if (!db_ok) { | |
241 | ++ utils->seterror(context, 0, | |
242 | ++ "Database not checked"); | |
243 | ++ return SASL_FAIL; | |
244 | ++ } | |
245 | ++ | |
246 | ++ /* allocate a key */ | |
247 | ++ result = _sasldb_alloc_key(utils, auth_identity, realm, propName, | |
248 | ++ &key, &key_len); | |
249 | ++ if (result != SASL_OK) { | |
250 | ++ utils->seterror(context, 0, | |
251 | ++ "Could not allocate key in _sasldb_getdata"); | |
252 | ++ return result; | |
253 | ++ } | |
254 | ++ | |
255 | ++ /* zero out */ | |
256 | ++ memset(&dbkey, 0, sizeof(dbkey)); | |
257 | ++ memset(&data, 0, sizeof(data)); | |
258 | ++ | |
259 | ++ /* open the db */ | |
260 | ++ result = berkeleydb_open(utils, context, 0, &mbdb); | |
261 | ++ if (result != SASL_OK) goto cleanup; | |
262 | ++ | |
263 | ++ /* create the key to search for */ | |
264 | ++ dbkey.data = key; | |
265 | ++ dbkey.size = (u_int32_t) key_len; | |
266 | ++ dbkey.flags = DB_DBT_USERMEM; | |
267 | ++ data.flags = DB_DBT_MALLOC; | |
268 | ++ | |
269 | ++ /* ask berkeley db for the entry */ | |
270 | ++ result = mbdb->get(mbdb, NULL, &dbkey, &data, 0); | |
271 | ++ | |
272 | ++ switch (result) { | |
273 | ++ case 0: | |
274 | ++ /* success */ | |
275 | ++ break; | |
276 | ++ | |
277 | ++ case DB_NOTFOUND: | |
278 | ++ result = SASL_NOUSER; | |
279 | ++ utils->seterror(context, SASL_NOLOG, | |
280 | ++ "user: %s@%s property: %s not found in sasldb", | |
281 | ++ auth_identity,realm,propName); | |
282 | ++ goto cleanup; | |
283 | ++ break; | |
284 | ++ default: | |
285 | ++ utils->seterror(context, 0, | |
286 | ++ "error fetching from sasldb: %s", | |
287 | ++ db_strerror(result)); | |
288 | ++ result = SASL_FAIL; | |
289 | ++ goto cleanup; | |
290 | ++ break; | |
291 | ++ } | |
292 | ++ | |
293 | ++ if(data.size > max_out + 1) | |
294 | ++ return SASL_BUFOVER; | |
295 | ++ | |
296 | ++ if(out_len) *out_len = data.size; | |
297 | ++ memcpy(out, data.data, data.size); | |
298 | ++ out[data.size] = '\0'; | |
299 | ++ | |
300 | ++ cleanup: | |
301 | ++ | |
302 | ++#if !defined(KEEP_DB_OPEN) | |
303 | ++ if (mbdb != NULL) berkeleydb_close(utils, mbdb); | |
304 | ++#endif | |
305 | ++ | |
306 | ++ utils->free(key); | |
307 | ++ utils->free(data.data); | |
308 | ++ | |
309 | ++ return result; | |
310 | ++} | |
311 | ++ | |
312 | ++/* | |
313 | ++ * Put or delete an entry | |
314 | ++ * | |
315 | ++ * | |
316 | ++ */ | |
317 | ++ | |
318 | ++int _sasldb_putdata(const sasl_utils_t *utils, | |
319 | ++ sasl_conn_t *context, | |
320 | ++ const char *authid, | |
321 | ++ const char *realm, | |
322 | ++ const char *propName, | |
323 | ++ const char *data_in, size_t data_len) | |
324 | ++{ | |
325 | ++ int result = SASL_OK; | |
326 | ++ char *key; | |
327 | ++ size_t key_len; | |
328 | ++ DBT dbkey; | |
329 | ++ DB *mbdb = NULL; | |
330 | ++ | |
331 | ++ if (!utils) return SASL_BADPARAM; | |
332 | ++ | |
333 | ++ if (!authid || !realm || !propName) { | |
334 | ++ utils->seterror(context, 0, | |
335 | ++ "Bad parameter in db_berkeley.c: _sasldb_putdata"); | |
336 | ++ return SASL_BADPARAM; | |
337 | ++ } | |
338 | ++ | |
339 | ++ if (!db_ok) { | |
340 | ++ utils->seterror(context, 0, | |
341 | ++ "Database not checked"); | |
342 | ++ return SASL_FAIL; | |
343 | ++ } | |
344 | ++ | |
345 | ++ result = _sasldb_alloc_key(utils, authid, realm, propName, | |
346 | ++ &key, &key_len); | |
347 | ++ if (result != SASL_OK) { | |
348 | ++ utils->seterror(context, 0, | |
349 | ++ "Could not allocate key in _sasldb_putdata"); | |
350 | ++ return result; | |
351 | ++ } | |
352 | ++ | |
353 | ++ /* open the db */ | |
354 | ++ result=berkeleydb_open(utils, context, 1, &mbdb); | |
355 | ++ if (result!=SASL_OK) goto cleanup; | |
356 | ++ | |
357 | ++ /* create the db key */ | |
358 | ++ memset(&dbkey, 0, sizeof(dbkey)); | |
359 | ++ dbkey.data = key; | |
360 | ++ dbkey.size = (u_int32_t) key_len; | |
361 | ++ | |
362 | ++ if (data_in) { /* putting secret */ | |
363 | ++ DBT data; | |
364 | ++ | |
365 | ++ memset(&data, 0, sizeof(data)); | |
366 | ++ | |
367 | ++ data.data = (char *)data_in; | |
368 | ++ if(!data_len) data_len = strlen(data_in); | |
369 | ++ data.size = (u_int32_t) data_len; | |
370 | ++ | |
371 | ++ result = mbdb->put(mbdb, NULL, &dbkey, &data, 0); | |
372 | ++ | |
373 | ++ if (result != 0) | |
374 | ++ { | |
375 | ++ utils->log(NULL, SASL_LOG_ERR, | |
376 | ++ "error updating sasldb: %s", db_strerror(result)); | |
377 | ++ utils->seterror(context, SASL_NOLOG, | |
378 | ++ "Couldn't update db"); | |
379 | ++ result = SASL_FAIL; | |
380 | ++ goto cleanup; | |
381 | ++ } | |
382 | ++ } else { /* removing secret */ | |
383 | ++ result=mbdb->del(mbdb, NULL, &dbkey, 0); | |
384 | ++ | |
385 | ++ if (result != 0) | |
386 | ++ { | |
387 | ++ utils->log(NULL, SASL_LOG_ERR, | |
388 | ++ "error deleting entry from sasldb: %s", db_strerror(result)); | |
389 | ++ utils->seterror(context, SASL_NOLOG, | |
390 | ++ "Couldn't update db"); | |
391 | ++ if (result == DB_NOTFOUND) | |
392 | ++ result = SASL_NOUSER; | |
393 | ++ else | |
394 | ++ result = SASL_FAIL; | |
395 | ++ goto cleanup; | |
396 | ++ } | |
397 | ++ } | |
398 | ++ | |
399 | ++ cleanup: | |
400 | ++ | |
401 | ++#if !defined(KEEP_DB_OPEN) | |
402 | ++ if (mbdb != NULL) berkeleydb_close(utils, mbdb); | |
403 | ++#endif | |
404 | ++ | |
405 | ++ utils->free(key); | |
406 | ++ | |
407 | ++ return result; | |
408 | ++} | |
409 | ++ | |
410 | ++int _sasl_check_db(const sasl_utils_t *utils, | |
411 | ++ sasl_conn_t *conn) | |
412 | ++{ | |
413 | ++ const char *path = SASL_DB_PATH; | |
414 | ++ int ret; | |
415 | ++ void *cntxt; | |
416 | ++ sasl_getopt_t *getopt; | |
417 | ++ sasl_verifyfile_t *vf; | |
418 | ++ | |
419 | ++ if (!utils) return SASL_BADPARAM; | |
420 | ++ | |
421 | ++ if (utils->getcallback(conn, SASL_CB_GETOPT, | |
422 | ++ &getopt, &cntxt) == SASL_OK) { | |
423 | ++ const char *p; | |
424 | ++ if (getopt(cntxt, NULL, "sasldb_path", &p, NULL) == SASL_OK | |
425 | ++ && p != NULL && *p != 0) { | |
426 | ++ path = p; | |
427 | ++ } | |
428 | ++ } | |
429 | ++ | |
430 | ++ ret = utils->getcallback(conn, SASL_CB_VERIFYFILE, | |
431 | ++ (sasl_callback_ft *)&vf, &cntxt); | |
432 | ++ if (ret != SASL_OK) { | |
433 | ++ utils->seterror(conn, 0, "verifyfile failed"); | |
434 | ++ return ret; | |
435 | ++ } | |
436 | ++ | |
437 | ++ ret = vf(cntxt, path, SASL_VRFY_PASSWD); | |
438 | ++ | |
439 | ++ if (ret == SASL_OK) { | |
440 | ++ db_ok = 1; | |
441 | ++ } | |
442 | ++ | |
443 | ++ if (ret == SASL_OK || ret == SASL_CONTINUE) { | |
444 | ++ return SASL_OK; | |
445 | ++ } else { | |
446 | ++ return ret; | |
447 | ++ } | |
448 | ++} | |
449 | ++ | |
450 | ++#if defined(KEEP_DB_OPEN) | |
451 | ++void sasldb_auxprop_free (void *glob_context, | |
452 | ++ const sasl_utils_t *utils) | |
453 | ++{ | |
454 | ++ if (g_db != NULL) berkeleydb_close(utils, g_db); | |
455 | ++} | |
456 | ++#endif | |
457 | ++ | |
458 | ++typedef struct berkeleydb_handle | |
459 | ++{ | |
460 | ++ DB *mbdb; | |
461 | ++ DBC *cursor; | |
462 | ++} berkleyhandle_t; | |
463 | ++ | |
464 | ++sasldb_handle _sasldb_getkeyhandle(const sasl_utils_t *utils, | |
465 | ++ sasl_conn_t *conn) | |
466 | ++{ | |
467 | ++ int ret; | |
468 | ++ DB *mbdb; | |
469 | ++ berkleyhandle_t *handle; | |
470 | ++ | |
471 | ++ if(!utils || !conn) return NULL; | |
472 | ++ | |
473 | ++ if(!db_ok) { | |
474 | ++ utils->seterror(conn, 0, "Database not OK in _sasldb_getkeyhandle"); | |
475 | ++ return NULL; | |
476 | ++ } | |
477 | ++ | |
478 | ++ ret = berkeleydb_open(utils, conn, 0, &mbdb); | |
479 | ++ | |
480 | ++ if (ret != SASL_OK) { | |
481 | ++ return NULL; | |
482 | ++ } | |
483 | ++ | |
484 | ++ handle = utils->malloc(sizeof(berkleyhandle_t)); | |
485 | ++ if(!handle) { | |
486 | ++#if !defined(KEEP_DB_OPEN) | |
487 | ++ (void)mbdb->close(mbdb, 0); | |
488 | ++#endif | |
489 | ++ utils->seterror(conn, 0, "Memory error in _sasldb_gethandle"); | |
490 | ++ return NULL; | |
491 | ++ } | |
492 | ++ | |
493 | ++ handle->mbdb = mbdb; | |
494 | ++ handle->cursor = NULL; | |
495 | ++ | |
496 | ++ return (sasldb_handle)handle; | |
497 | ++} | |
498 | ++ | |
499 | ++int _sasldb_getnextkey(const sasl_utils_t *utils __attribute__((unused)), | |
500 | ++ sasldb_handle handle, char *out, | |
501 | ++ const size_t max_out, size_t *out_len) | |
502 | ++{ | |
503 | ++ DB *mbdb; | |
504 | ++ int result; | |
505 | ++ berkleyhandle_t *dbh = (berkleyhandle_t *)handle; | |
506 | ++ DBT key, data; | |
507 | ++ | |
508 | ++ if(!utils || !handle || !out || !max_out) | |
509 | ++ return SASL_BADPARAM; | |
510 | ++ | |
511 | ++ mbdb = dbh->mbdb; | |
512 | ++ | |
513 | ++ memset(&key,0, sizeof(key)); | |
514 | ++ memset(&data,0,sizeof(data)); | |
515 | ++ | |
516 | ++ if(!dbh->cursor) { | |
517 | ++ /* make cursor */ | |
518 | ++#if DB_VERSION_MAJOR < 3 | |
519 | ++#if DB_VERSION_MINOR < 6 | |
520 | ++ result = mbdb->cursor(mbdb, NULL,&dbh->cursor); | |
521 | ++#else | |
522 | ++ result = mbdb->cursor(mbdb, NULL,&dbh->cursor, 0); | |
523 | ++#endif /* DB_VERSION_MINOR < 7 */ | |
524 | ++#else /* DB_VERSION_MAJOR < 3 */ | |
525 | ++ result = mbdb->cursor(mbdb, NULL,&dbh->cursor, 0); | |
526 | ++#endif /* DB_VERSION_MAJOR < 3 */ | |
527 | ++ | |
528 | ++ if (result!=0) { | |
529 | ++ return SASL_FAIL; | |
530 | ++ } | |
531 | ++ | |
532 | ++ /* loop thru */ | |
533 | ++ result = dbh->cursor->c_get(dbh->cursor, &key, &data, | |
534 | ++ DB_FIRST); | |
535 | ++ } else { | |
536 | ++ result = dbh->cursor->c_get(dbh->cursor, &key, &data, | |
537 | ++ DB_NEXT); | |
538 | ++ } | |
539 | ++ | |
540 | ++ if (result == DB_NOTFOUND) return SASL_OK; | |
541 | ++ | |
542 | ++ if (result != 0) { | |
543 | ++ return SASL_FAIL; | |
544 | ++ } | |
545 | ++ | |
546 | ++ if (key.size > max_out) { | |
547 | ++ return SASL_BUFOVER; | |
548 | ++ } | |
549 | ++ | |
550 | ++ memcpy(out, key.data, key.size); | |
551 | ++ if (out_len) *out_len = key.size; | |
552 | ++ | |
553 | ++ return SASL_CONTINUE; | |
554 | ++} | |
555 | ++ | |
556 | ++ | |
557 | ++int _sasldb_releasekeyhandle(const sasl_utils_t *utils, | |
558 | ++ sasldb_handle handle) | |
559 | ++{ | |
560 | ++ berkleyhandle_t *dbh = (berkleyhandle_t *)handle; | |
561 | ++ int ret = 0; | |
562 | ++ | |
563 | ++ if (!utils || !dbh) return SASL_BADPARAM; | |
564 | ++ | |
565 | ++ if (dbh->cursor) { | |
566 | ++ dbh->cursor->c_close(dbh->cursor); | |
567 | ++ } | |
568 | ++ | |
569 | ++#if !defined(KEEP_DB_OPEN) | |
570 | ++ /* This is almost the same berkeleydb_close(), except that | |
571 | ++ berkeleydb_close logs a message on error and does not return | |
572 | ++ any error */ | |
573 | ++ if (dbh->mbdb) { | |
574 | ++ ret = dbh->mbdb->close(dbh->mbdb, 0); | |
575 | ++ } | |
576 | ++#endif | |
577 | ++ | |
578 | ++ utils->free(dbh); | |
579 | ++ | |
580 | ++ if (ret) { | |
581 | ++ return SASL_FAIL; | |
582 | ++ } else { | |
583 | ++ return SASL_OK; | |
584 | ++ } | |
585 | ++} | |
586 | +diff -Naur cyrus-sasl-2.1.25.orig/utils/dbconverter-2.c cyrus-sasl-2.1.25/utils/dbconverter-2.c | |
587 | +--- cyrus-sasl-2.1.25.orig/utils/dbconverter-2.c 2003-02-14 04:56:17.000000000 +0900 | |
588 | ++++ cyrus-sasl-2.1.25/utils/dbconverter-2.c 2012-03-18 01:44:09.646974025 +0900 | |
589 | +@@ -214,7 +214,7 @@ | |
590 | + ret = db_create(mbdb, NULL, 0); | |
591 | + if (ret == 0 && *mbdb != NULL) | |
592 | + { | |
593 | +-#if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1 | |
594 | ++#if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1) || DB_VERSION_MAJOR == 5 | |
595 | + ret = (*mbdb)->open(*mbdb, NULL, path, NULL, DB_HASH, DB_CREATE, 0664); | |
596 | + #else | |
597 | + ret = (*mbdb)->open(*mbdb, path, NULL, DB_HASH, DB_CREATE, 0664); |