Mon, 28 Jan 2013 17:37:18 +0100
Correct socket error reporting improvement with IPv6 portable code,
after helpful recommendation by Saúl Ibarra Corretgé on OSips devlist.
1 Index: configure
2 --- configure.orig 2006-05-18 21:30:13 +0200
3 +++ configure 2008-12-25 18:48:51 +0100
4 @@ -5015,9 +5015,6 @@
6 fi
8 -if test "$ac_cv_c_compiler_gnu" = yes; then
9 - CFLAGS="-Wall -W ${CFLAGS}"
10 -fi
13 # Check whether --with-purecov was given.
14 @@ -6422,7 +6419,7 @@
15 fi
17 saved_LIBS=$LIBS
18 - for dbname in ${with_bdb} db-4.7 db4.7 db47 db-4.6 db4.6 db46 db-4.5 db4.5 db45 db-4.4 db4.4 db44 db-4.3 db4.3 db43 db-4.2 db4.2 db42 db-4.1 db4.1 db41 db-4.0 db4.0 db-4 db40 db4 db-3.3 db3.3 db33 db-3.2 db3.2 db32 db-3.1 db3.1 db31 db-3 db30 db3 db
19 + for dbname in db
20 do
21 LIBS="$saved_LIBS -l$dbname"
22 cat >conftest.$ac_ext <<_ACEOF
23 @@ -6526,6 +6523,54 @@
24 rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
25 conftest$ac_exeext conftest.$ac_ext
26 fi
27 + if test "$dblib" = "no"; then
28 + cat >conftest.$ac_ext <<_ACEOF
29 +/* confdefs.h. */
30 +_ACEOF
31 +cat confdefs.h >>conftest.$ac_ext
32 +cat >>conftest.$ac_ext <<_ACEOF
33 +/* end confdefs.h. */
34 +#include <db.h>
35 +int
36 +main ()
37 +{
38 +dbm_open(NULL, 0, 0, 0, NULL, NULL, NULL);
39 + ;
40 + return 0;
41 +}
42 +_ACEOF
43 +rm -f conftest.$ac_objext conftest$ac_exeext
44 +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
45 + (eval $ac_link) 2>conftest.er1
46 + ac_status=$?
47 + grep -v '^ *+' conftest.er1 >conftest.err
48 + rm -f conftest.er1
49 + cat conftest.err >&5
50 + echo "$as_me:$LINENO: \$? = $ac_status" >&5
51 + (exit $ac_status); } &&
52 + { ac_try='test -z "$ac_c_werror_flag"
53 + || test ! -s conftest.err'
54 + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
55 + (eval $ac_try) 2>&5
56 + ac_status=$?
57 + echo "$as_me:$LINENO: \$? = $ac_status" >&5
58 + (exit $ac_status); }; } &&
59 + { ac_try='test -s conftest$ac_exeext'
60 + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
61 + (eval $ac_try) 2>&5
62 + ac_status=$?
63 + echo "$as_me:$LINENO: \$? = $ac_status" >&5
64 + (exit $ac_status); }; }; then
65 + BDB_LIBADD="$BDB_LIBADD -ldb"; dblib="berkeley"; dbname=db
66 +else
67 + echo "$as_me: failed program was:" >&5
68 +sed 's/^/| /' conftest.$ac_ext >&5
69 +
70 +dblib="no"
71 +fi
72 +rm -f conftest.err conftest.$ac_objext \
73 + conftest$ac_exeext conftest.$ac_ext
74 + fi
75 LIBS=$saved_LIBS
77 LDFLAGS=$BDB_SAVE_LDFLAGS
78 @@ -7232,7 +7277,7 @@
79 fi
81 saved_LIBS=$LIBS
82 - for dbname in ${with_bdb} db-4.7 db4.7 db47 db-4.6 db4.6 db46 db-4.5 db4.5 db45 db-4.4 db4.4 db44 db-4.3 db4.3 db43 db-4.2 db4.2 db42 db-4.1 db4.1 db41 db-4.0 db4.0 db-4 db40 db4 db-3.3 db3.3 db33 db-3.2 db3.2 db32 db-3.1 db3.1 db31 db-3 db30 db3 db
83 + for dbname in db
84 do
85 LIBS="$saved_LIBS -l$dbname"
86 cat >conftest.$ac_ext <<_ACEOF
87 @@ -7336,6 +7381,54 @@
88 rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
89 conftest$ac_exeext conftest.$ac_ext
90 fi
91 + if test "$dblib" = "no"; then
92 + cat >conftest.$ac_ext <<_ACEOF
93 +/* confdefs.h. */
94 +_ACEOF
95 +cat confdefs.h >>conftest.$ac_ext
96 +cat >>conftest.$ac_ext <<_ACEOF
97 +/* end confdefs.h. */
98 +#include <db.h>
99 +int
100 +main ()
101 +{
102 +dbm_open(NULL, 0, 0, 0, NULL, NULL, NULL);
103 + ;
104 + return 0;
105 +}
106 +_ACEOF
107 +rm -f conftest.$ac_objext conftest$ac_exeext
108 +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
109 + (eval $ac_link) 2>conftest.er1
110 + ac_status=$?
111 + grep -v '^ *+' conftest.er1 >conftest.err
112 + rm -f conftest.er1
113 + cat conftest.err >&5
114 + echo "$as_me:$LINENO: \$? = $ac_status" >&5
115 + (exit $ac_status); } &&
116 + { ac_try='test -z "$ac_c_werror_flag"
117 + || test ! -s conftest.err'
118 + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
119 + (eval $ac_try) 2>&5
120 + ac_status=$?
121 + echo "$as_me:$LINENO: \$? = $ac_status" >&5
122 + (exit $ac_status); }; } &&
123 + { ac_try='test -s conftest$ac_exeext'
124 + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
125 + (eval $ac_try) 2>&5
126 + ac_status=$?
127 + echo "$as_me:$LINENO: \$? = $ac_status" >&5
128 + (exit $ac_status); }; }; then
129 + BDB_LIBADD="$BDB_LIBADD -ldb"; dblib="berkeley"; dbname=db
130 +else
131 + echo "$as_me: failed program was:" >&5
132 +sed 's/^/| /' conftest.$ac_ext >&5
133 +
134 +dblib="no"
135 +fi
136 +rm -f conftest.err conftest.$ac_objext \
137 + conftest$ac_exeext conftest.$ac_ext
138 + fi
139 LIBS=$saved_LIBS
141 LDFLAGS=$BDB_SAVE_LDFLAGS
142 @@ -14476,20 +14569,20 @@
143 fi
145 LIB_SQLITE_DIR=$LIB_SQLITE
146 - LIB_SQLITE="$LIB_SQLITE -lsqlite"
147 + LIB_SQLITE="$LIB_SQLITE -lsqlite3"
149 if test -d ${with_sqlite}/include; then
150 CPPFLAGS="${CPPFLAGS} -I${with_sqlite}/include"
151 else
152 CPPFLAGS="${CPPFLAGS} -I${with_sqlite}"
153 fi
154 - { $as_echo "$as_me:$LINENO: checking for sqlite_open in -lsqlite" >&5
155 -$as_echo_n "checking for sqlite_open in -lsqlite... " >&6; }
156 + echo "$as_me:$LINENO: checking for sqlite3_open in -lsqlite3" >&5
157 +echo $ECHO_N "checking for sqlite3_open in -lsqlite3... $ECHO_C" >&6
158 if test "${ac_cv_lib_sqlite_sqlite_open+set}" = set; then
159 $as_echo_n "(cached) " >&6
160 else
161 ac_check_lib_save_LIBS=$LIBS
162 -LIBS="-lsqlite $LIB_SQLITE_DIR $LIBS"
163 +LIBS="-lsqlite3 $LIB_SQLITE_DIR $LIBS"
164 cat >conftest.$ac_ext <<_ACEOF
165 /* confdefs.h. */
166 _ACEOF
167 @@ -14503,11 +14596,11 @@
168 #ifdef __cplusplus
169 extern "C"
170 #endif
171 -char sqlite_open ();
172 +char sqlite3_open ();
173 int
174 main ()
175 {
176 -return sqlite_open ();
177 +return sqlite3_open ();
178 ;
179 return 0;
180 }
181 Index: lib/saslint.h
182 --- lib/saslint.h.orig 2006-04-18 22:25:45 +0200
183 +++ lib/saslint.h 2008-12-25 18:48:51 +0100
184 @@ -118,8 +118,6 @@
185 const char *appname;
186 } sasl_global_callbacks_t;
188 -extern sasl_global_callbacks_t global_callbacks;
189 -
190 typedef struct _sasl_external_properties
191 {
192 sasl_ssf_t ssf;
193 Index: lib/server.c
194 --- lib/server.c.orig 2006-05-17 18:46:13 +0200
195 +++ lib/server.c 2008-12-25 18:48:51 +0100
196 @@ -90,7 +90,7 @@
198 static mech_list_t *mechlist = NULL; /* global var which holds the list */
200 -sasl_global_callbacks_t global_callbacks;
201 +static sasl_global_callbacks_t global_callbacks;
203 /* set the password for a user
204 * conn -- SASL connection
205 @@ -606,16 +606,8 @@
206 return SASL_CONTINUE;
207 }
209 - /* get the path to the config file */
210 - getconfpath_cb = _sasl_find_getconfpath_callback( global_callbacks.callbacks );
211 - if (getconfpath_cb == NULL) return SASL_BADPARAM;
212 -
213 - /* getconfpath_cb->proc MUST be a sasl_getconfpath_t; if only C had a type
214 - system */
215 - result = ((sasl_getconfpath_t *)(getconfpath_cb->proc))(getconfpath_cb->context,
216 - (char **) &path_to_config);
217 - if (result != SASL_OK) goto done;
218 - if (path_to_config == NULL) path_to_config = "";
219 + result = SASL_OK;
220 + path_to_config = "@l_sysconfdir@";
222 next = path_to_config;
224 Index: plugins/sql.c
225 --- plugins/sql.c.orig 2006-04-07 15:42:16 +0200
226 +++ plugins/sql.c 2008-12-25 21:57:47 +0100
227 @@ -150,9 +150,15 @@
228 return -1;
229 }
230 if (value) {
231 - strncpy(value, row[0], size-2);
232 - value[size-1] = '\0';
233 - if (value_len) *value_len = strlen(value);
234 + unsigned long *col_lens;
235 + size_t col_len;
236 + col_lens = mysql_fetch_lengths(result);
237 + col_len = (size_t)col_lens[0];
238 + if (col_len > size - 1);
239 + col_len = size - 1;
240 + memcpy(value, row[0], col_len);
241 + value[col_len] = '\0';
242 + if (value_len) *value_len = col_len;
243 }
245 /* free result */
246 @@ -277,7 +283,7 @@
247 ExecStatusType status;
249 /* run the query */
250 - result = PQexec(conn, cmd);
251 + result = PQexecParams(conn, cmd, 0, NULL, NULL, NULL, NULL, 1);
253 /* check the status */
254 status = PQresultStatus(result);
255 @@ -298,6 +304,7 @@
256 row_count = PQntuples(result);
257 if (!row_count) {
258 /* umm nothing found */
259 + utils->log(NULL, SASL_LOG_DEBUG, "sql plugin: no result found for query %s", cmd);
260 utils->log(NULL, SASL_LOG_NOTE, "sql plugin: no result found");
261 PQclear(result);
262 return -1;
263 @@ -310,9 +317,26 @@
264 /* now get the result set value and value_len */
265 /* we only fetch one because we don't care about the rest */
266 if (value) {
267 - strncpy(value, PQgetvalue(result,0,0), size-2);
268 - value[size-1] = '\0';
269 - if (value_len) *value_len = strlen(value);
270 + if (PQgetisnull(result, 0, 0)) {
271 + size_t col_len;
272 + col_len = strlen(SQL_NULL_VALUE);
273 + if (col_len > size - 1)
274 + col_len = size - 1;
275 + memcpy(value, SQL_NULL_VALUE, col_len);
276 + value[col_len] = '\0';
277 + if (value_len)
278 + *value_len = col_len;
279 + }
280 + else {
281 + size_t col_len;
282 + col_len = (size_t)PQgetlength(result, 0, 0);
283 + if (col_len > size - 1);
284 + col_len = size - 1;
285 + memcpy(value, PQgetvalue(result, 0, 0), col_len);
286 + value[col_len] = '\0';
287 + if (value_len)
288 + *value_len = col_len;
289 + }
290 }
292 /* free result */
293 @@ -342,7 +366,7 @@
294 #endif /* HAVE_PGSQL */
296 #ifdef HAVE_SQLITE
297 -#include <sqlite.h>
298 +#include <sqlite3.h>
300 static void *_sqlite_open(char *host __attribute__((unused)),
301 char *port __attribute__((unused)),
302 @@ -352,21 +376,23 @@
303 const char *database, const sasl_utils_t *utils)
304 {
305 int rc;
306 - sqlite *db;
307 + sqlite3 *db;
308 char *zErrMsg = NULL;
310 - db = sqlite_open(database, 0, &zErrMsg);
311 - if (db == NULL) {
312 + rc = sqlite3_open(database, &db);
313 + if (rc != SQLITE_OK) {
314 + zErrMsg = (char *)sqlite3_errmsg(db);
315 utils->log(NULL, SASL_LOG_ERR, "sql plugin: %s", zErrMsg);
316 - sqlite_freemem (zErrMsg);
317 + sqlite3_free (zErrMsg);
318 + sqlite3_close (db);
319 return NULL;
320 }
322 - rc = sqlite_exec(db, "PRAGMA empty_result_callbacks = ON", NULL, NULL, &zErrMsg);
323 + rc = sqlite3_exec(db, "PRAGMA empty_result_callbacks = ON", NULL, NULL, &zErrMsg);
324 if (rc != SQLITE_OK) {
325 utils->log(NULL, SASL_LOG_ERR, "sql plugin: %s", zErrMsg);
326 - sqlite_freemem (zErrMsg);
327 - sqlite_close(db);
328 + sqlite3_free (zErrMsg);
329 + sqlite3_close(db);
330 return NULL;
331 }
333 @@ -388,62 +414,67 @@
334 return 0;
335 }
337 -static int sqlite_my_callback(void *pArg, int argc __attribute__((unused)),
338 - char **argv,
339 - char **columnNames __attribute__((unused)))
340 -{
341 - char **result = (char**)pArg;
342 -
343 - if (argv == NULL) {
344 - *result = NULL; /* no record */
345 - } else if (argv[0] == NULL) {
346 - *result = strdup(SQL_NULL_VALUE); /* NULL IS SQL_NULL_VALUE */
347 - } else {
348 - *result = strdup(argv[0]);
349 - }
350 -
351 - return /*ABORT*/1;
352 -}
353 -
354 static int _sqlite_exec(void *db, const char *cmd, char *value, size_t size,
355 size_t *value_len, const sasl_utils_t *utils)
356 {
357 int rc;
358 - char *result = NULL;
359 - char *zErrMsg = NULL;
360 + sqlite3_stmt *stmt;
361 + const char *todo;
362 + size_t len;
364 - rc = sqlite_exec((sqlite*)db, cmd, sqlite_my_callback, (void*)&result, &zErrMsg);
365 - if (rc != SQLITE_OK && rc != SQLITE_ABORT) {
366 - utils->log(NULL, SASL_LOG_DEBUG, "sql plugin: %s ", zErrMsg);
367 - sqlite_freemem (zErrMsg);
368 + rc = sqlite3_prepare((sqlite3*)db, cmd, (int)strlen(cmd), &stmt, &todo);
369 + if (rc != SQLITE_OK) {
370 + utils->log(NULL, SASL_LOG_DEBUG, "sql plugin error: %s", sqlite3_errmsg((sqlite3*)db));
371 return -1;
372 }
373 -
374 - if (rc == SQLITE_OK) {
375 + rc = sqlite3_step(stmt);
376 + if (rc != SQLITE_ROW && rc != SQLITE_DONE) {
377 + utils->log(NULL, SASL_LOG_DEBUG, "sql plugin error: %s", sqlite3_errmsg((sqlite3*)db));
378 + sqlite3_finalize(stmt);
379 + return -1;
380 + }
381 + if (sqlite3_column_count(stmt) == 0) {
382 /* no results (BEGIN, COMMIT, DELETE, INSERT, UPDATE) */
383 + sqlite3_finalize(stmt);
384 return 0;
385 }
386 -
387 - if (result == NULL) {
388 + if (rc == SQLITE_DONE) {
389 /* umm nothing found */
390 + utils->log(NULL, SASL_LOG_DEBUG, "sql plugin: no result found for query %s", cmd);
391 utils->log(NULL, SASL_LOG_NOTE, "sql plugin: no result found");
392 + sqlite3_finalize(stmt);
393 return -1;
394 }
395 -
396 - /* XXX: Duplication cannot be found by this method. */
397 -
398 - /* now get the result set value and value_len */
399 - /* we only fetch one because we don't care about the rest */
400 - if (value) {
401 - strncpy(value, result, size - 2);
402 - value[size - 1] = '\0';
403 - if (value_len) {
404 - *value_len = strlen(value);
405 - }
406 + rc = sqlite3_column_type(stmt, 0);
407 + switch (rc) {
408 + case SQLITE_NULL: {
409 + len = strlen(SQL_NULL_VALUE);
410 + if (len > size - 1)
411 + len = size - 1;
412 + memcpy(value, SQL_NULL_VALUE, len);
413 + value[len] = '\0';
414 + if (value_len)
415 + *value_len = len;
416 + break;
417 + }
418 + default: {
419 + const void *blob = sqlite3_column_blob(stmt, 0);
420 + len = (size_t)sqlite3_column_bytes(stmt, 0);
421 + if (len > size - 1)
422 + len = size - 1;
423 + memcpy(value, blob, len);
424 + value[len] = '\0';
425 + if (value_len)
426 + *value_len = len;
427 + break;
428 + }
429 }
430 -
431 - /* free result */
432 - free(result);
433 + rc = sqlite3_step(stmt);
434 + if (rc != SQLITE_DONE) {
435 + utils->log(NULL, SASL_LOG_WARN,
436 + "sql plugin: found duplicate row for query %s", cmd);
437 + }
438 + sqlite3_finalize(stmt);
439 return 0;
440 }
442 @@ -464,7 +495,7 @@
444 static void _sqlite_close(void *db)
445 {
446 - sqlite_close((sqlite*)db);
447 + sqlite3_close((sqlite3 *)db);
448 }
449 #endif /* HAVE_SQLITE */
451 @@ -918,7 +949,7 @@
452 settings = (sql_settings_t *) glob_context;
454 sparams->utils->log(NULL, SASL_LOG_DEBUG,
455 - "sql plugin Parse the username %s\n", user);
456 + "sql plugin parse the username %s\n", user);
458 user_buf = sparams->utils->malloc(ulen + 1);
459 if (!user_buf) {
460 @@ -1022,7 +1053,7 @@
461 }
463 sparams->utils->log(NULL, SASL_LOG_DEBUG,
464 - "sql plugin create statement from %s %s %s\n",
465 + "sql plugin create statement from name=%s user=%s realm=%s\n",
466 realname, escap_userid, escap_realm);
468 /* create a statement that we will use */
469 @@ -1043,12 +1074,18 @@
470 /* run the query */
471 if (!settings->sql_engine->sql_exec(conn, query, value, sizeof(value),
472 &value_len, sparams->utils)) {
473 + sparams->utils->log(NULL, SASL_LOG_DEBUG,
474 + "sql plugin query successful\n");
475 sparams->utils->prop_set(sparams->propctx,
476 cur->name,
477 value,
478 (int)value_len);
479 ret = SASL_OK;
480 }
481 + else {
482 + sparams->utils->log(NULL, SASL_LOG_DEBUG,
483 + "sql plugin query failed\n");
484 + }
486 sparams->utils->free(query);
487 }
488 Index: sample/client.c
489 --- sample/client.c.orig 2004-03-09 18:35:32 +0100
490 +++ sample/client.c 2008-12-25 18:48:51 +0100
491 @@ -137,13 +137,11 @@
492 return SASL_OK;
493 }
495 -#ifndef HAVE_GETPASSPHRASE
496 static char *
497 -getpassphrase(const char *prompt)
498 +my_getpassphrase(const char *prompt)
499 {
500 return getpass(prompt);
501 }
502 -#endif /* ! HAVE_GETPASSPHRASE */
504 static int
505 getsecret(sasl_conn_t *conn,
506 @@ -159,7 +157,7 @@
507 if (! conn || ! psecret || id != SASL_CB_PASS)
508 return SASL_BADPARAM;
510 - password = getpassphrase("Password: ");
511 + password = my_getpassphrase("Password: ");
512 if (! password)
513 return SASL_FAIL;
515 Index: sample/sample-client.c
516 --- sample/sample-client.c.orig 2004-10-26 13:14:33 +0200
517 +++ sample/sample-client.c 2008-12-25 18:48:51 +0100
518 @@ -245,13 +245,11 @@
519 return SASL_OK;
520 }
522 -#ifndef HAVE_GETPASSPHRASE
523 static char *
524 -getpassphrase(const char *prompt)
525 +my_getpassphrase(const char *prompt)
526 {
527 return getpass(prompt);
528 }
529 -#endif /* ! HAVE_GETPASSPHRASE */
531 static int
532 getsecret(sasl_conn_t *conn,
533 @@ -265,7 +263,7 @@
534 if (! conn || ! psecret || id != SASL_CB_PASS)
535 return SASL_BADPARAM;
537 - password = getpassphrase("Password: ");
538 + password = my_getpassphrase("Password: ");
539 if (! password)
540 return SASL_FAIL;
542 @@ -308,7 +306,7 @@
543 fflush(stdout);
545 if (id == SASL_CB_ECHOPROMPT) {
546 - char *original = getpassphrase("");
547 + char *original = my_getpassphrase("");
548 if (! original)
549 return SASL_FAIL;
550 if (*original)
551 Index: saslauthd/Makefile.am
552 --- saslauthd/Makefile.am.orig 2006-05-17 18:46:17 +0200
553 +++ saslauthd/Makefile.am 2008-12-25 18:48:51 +0100
554 @@ -36,4 +36,4 @@
556 install-data-local: saslauthd.8
557 $(mkinstalldirs) $(DESTDIR)$(mandir)/man8
558 - $(INSTALL_DATA) $(srcdir)/saslauthd.8 $(DESTDIR)$(mandir)/man8/saslauthd.8
559 + $(INSTALL_DATA) $(srcdir)/saslauthd.mdoc $(DESTDIR)$(mandir)/man8/saslauthd.8
560 Index: saslauthd/Makefile.in
561 --- saslauthd/Makefile.in.orig 2008-12-25 18:48:51 +0100
562 +++ saslauthd/Makefile.in 2008-12-25 18:48:51 +0100
563 @@ -722,7 +722,7 @@
565 install-data-local: saslauthd.8
566 $(mkinstalldirs) $(DESTDIR)$(mandir)/man8
567 - $(INSTALL_DATA) $(srcdir)/saslauthd.8 $(DESTDIR)$(mandir)/man8/saslauthd.8
568 + $(INSTALL_DATA) $(srcdir)/saslauthd.mdoc $(DESTDIR)$(mandir)/man8/saslauthd.8
570 # Tell versions [3.59,3.63) of GNU make to not export all variables.
571 # Otherwise a system limit (for SysV at least) may be exceeded.
572 Index: saslauthd/lak.c
573 --- saslauthd/lak.c.orig 2005-05-15 07:49:51 +0200
574 +++ saslauthd/lak.c 2008-12-25 18:48:51 +0100
575 @@ -47,6 +47,7 @@
576 #include <crypt.h>
577 #endif
579 +#include "saslauthd.h" /* get strlcpy macro for non-BSD; get HAVE_OPENSSL from config.h */
580 #ifdef HAVE_OPENSSL
581 #ifndef OPENSSL_DISABLE_OLD_DES_SUPPORT
582 #define OPENSSL_DISABLE_OLD_DES_SUPPORT
583 @@ -58,7 +59,7 @@
584 #define LDAP_DEPRECATED 1
585 #include <ldap.h>
586 #include <lber.h>
587 -#include <sasl.h>
588 +#include "sasl.h"
589 #include "lak.h"
591 typedef struct lak_auth_method {