diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/replace/libreplace.m4 | 1 | ||||
-rw-r--r-- | lib/replace/replace.h | 4 | ||||
-rw-r--r-- | lib/tdb/common/lock.c | 17 | ||||
-rw-r--r-- | lib/tdb/common/tdb_private.h | 2 | ||||
-rw-r--r-- | lib/tdb/common/traverse.c | 22 | ||||
-rw-r--r-- | lib/tevent/testsuite.c | 12 | ||||
-rw-r--r-- | lib/tevent/tevent_req.c | 2 | ||||
-rw-r--r-- | lib/torture/torture.c | 8 | ||||
-rw-r--r-- | lib/torture/torture.h | 3 | ||||
-rw-r--r-- | lib/tsocket/tsocket_bsd.c | 42 | ||||
-rw-r--r-- | lib/util/genrand.c | 3 | ||||
-rw-r--r-- | lib/util/tests/genrand.c | 2 | ||||
-rw-r--r-- | lib/util/util_file.c | 1 |
13 files changed, 63 insertions, 56 deletions
diff --git a/lib/replace/libreplace.m4 b/lib/replace/libreplace.m4 index 2d90d9c7e8..a3a26ef43e 100644 --- a/lib/replace/libreplace.m4 +++ b/lib/replace/libreplace.m4 @@ -103,6 +103,7 @@ AC_CHECK_HEADERS(sys/time.h time.h) AC_CHECK_HEADERS(stdarg.h vararg.h) AC_CHECK_HEADERS(sys/mount.h mntent.h) AC_CHECK_HEADERS(stropts.h) +AC_CHECK_HEADERS(unix.h) AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror) AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename) diff --git a/lib/replace/replace.h b/lib/replace/replace.h index fe1f732acb..2db6aa1226 100644 --- a/lib/replace/replace.h +++ b/lib/replace/replace.h @@ -258,6 +258,10 @@ char *rep_realpath(const char *path, char *resolved_path); int rep_lchown(const char *fname,uid_t uid,gid_t gid); #endif +#ifdef HAVE_UNIX_H +#include <unix.h> +#endif + #ifndef HAVE_SETLINEBUF #define setlinebuf rep_setlinebuf void rep_setlinebuf(FILE *); diff --git a/lib/tdb/common/lock.c b/lib/tdb/common/lock.c index f156c0fa7b..2c72ae1f0d 100644 --- a/lib/tdb/common/lock.c +++ b/lib/tdb/common/lock.c @@ -301,16 +301,21 @@ int tdb_unlock(struct tdb_context *tdb, int list, int ltype) */ int tdb_transaction_lock(struct tdb_context *tdb, int ltype) { - if (tdb->have_transaction_lock || tdb->global_lock.count) { + if (tdb->global_lock.count) { + return 0; + } + if (tdb->transaction_lock_count > 0) { + tdb->transaction_lock_count++; return 0; } + if (tdb->methods->tdb_brlock(tdb, TRANSACTION_LOCK, ltype, F_SETLKW, 0, 1) == -1) { TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_lock: failed to get transaction lock\n")); tdb->ecode = TDB_ERR_LOCK; return -1; } - tdb->have_transaction_lock = 1; + tdb->transaction_lock_count++; return 0; } @@ -320,12 +325,16 @@ int tdb_transaction_lock(struct tdb_context *tdb, int ltype) int tdb_transaction_unlock(struct tdb_context *tdb) { int ret; - if (!tdb->have_transaction_lock) { + if (tdb->global_lock.count) { + return 0; + } + if (tdb->transaction_lock_count > 1) { + tdb->transaction_lock_count--; return 0; } ret = tdb->methods->tdb_brlock(tdb, TRANSACTION_LOCK, F_UNLCK, F_SETLKW, 0, 1); if (ret == 0) { - tdb->have_transaction_lock = 0; + tdb->transaction_lock_count = 0; } return ret; } diff --git a/lib/tdb/common/tdb_private.h b/lib/tdb/common/tdb_private.h index ffac89ff0e..45b85f4c93 100644 --- a/lib/tdb/common/tdb_private.h +++ b/lib/tdb/common/tdb_private.h @@ -166,7 +166,7 @@ struct tdb_context { struct tdb_transaction *transaction; int page_size; int max_dead_records; - bool have_transaction_lock; + int transaction_lock_count; volatile sig_atomic_t *interrupt_sig_ptr; }; diff --git a/lib/tdb/common/traverse.c b/lib/tdb/common/traverse.c index 69c81e6e98..07b0c23858 100644 --- a/lib/tdb/common/traverse.c +++ b/lib/tdb/common/traverse.c @@ -204,23 +204,18 @@ int tdb_traverse_read(struct tdb_context *tdb, { struct tdb_traverse_lock tl = { NULL, 0, 0, F_RDLCK }; int ret; - bool in_transaction = (tdb->transaction != NULL); /* we need to get a read lock on the transaction lock here to cope with the lock ordering semantics of solaris10 */ - if (!in_transaction) { - if (tdb_transaction_lock(tdb, F_RDLCK)) { - return -1; - } + if (tdb_transaction_lock(tdb, F_RDLCK)) { + return -1; } tdb->traverse_read++; ret = tdb_traverse_internal(tdb, fn, private_data, &tl); tdb->traverse_read--; - if (!in_transaction) { - tdb_transaction_unlock(tdb); - } + tdb_transaction_unlock(tdb); return ret; } @@ -237,25 +232,20 @@ int tdb_traverse(struct tdb_context *tdb, { struct tdb_traverse_lock tl = { NULL, 0, 0, F_WRLCK }; int ret; - bool in_transaction = (tdb->transaction != NULL); if (tdb->read_only || tdb->traverse_read) { return tdb_traverse_read(tdb, fn, private_data); } - if (!in_transaction) { - if (tdb_transaction_lock(tdb, F_WRLCK)) { - return -1; - } + if (tdb_transaction_lock(tdb, F_WRLCK)) { + return -1; } tdb->traverse_write++; ret = tdb_traverse_internal(tdb, fn, private_data, &tl); tdb->traverse_write--; - if (!in_transaction) { - tdb_transaction_unlock(tdb); - } + tdb_transaction_unlock(tdb); return ret; } diff --git a/lib/tevent/testsuite.c b/lib/tevent/testsuite.c index d964fb33d3..f9aca91aa1 100644 --- a/lib/tevent/testsuite.c +++ b/lib/tevent/testsuite.c @@ -66,7 +66,13 @@ static bool test_event_context(struct torture_context *test, const char *backend = (const char *)test_data; int alarm_count=0, info_count=0; struct tevent_fd *fde; - struct signal_event *se1, *se2, *se3; +#ifdef SA_RESTART + struct tevent_signal *se1 = NULL; +#endif + struct tevent_signal *se2 = NULL; +#ifdef SA_SIGINFO + struct tevent_signal *se3 = NULL; +#endif int finished=0; struct timeval t; char c = 0; @@ -92,7 +98,9 @@ static bool test_event_context(struct torture_context *test, event_add_timed(ev_ctx, ev_ctx, timeval_current_ofs(2,0), finished_handler, &finished); +#ifdef SA_RESTART se1 = event_add_signal(ev_ctx, ev_ctx, SIGALRM, SA_RESTART, count_handler, &alarm_count); +#endif se2 = event_add_signal(ev_ctx, ev_ctx, SIGALRM, SA_RESETHAND, count_handler, &alarm_count); #ifdef SA_SIGINFO se3 = event_add_signal(ev_ctx, ev_ctx, SIGUSR1, SA_SIGINFO, count_handler, &info_count); @@ -120,7 +128,9 @@ static bool test_event_context(struct torture_context *test, torture_comment(test, "Got %.2f pipe events/sec\n", fde_count/timeval_elapsed(&t)); +#ifdef SA_RESTART talloc_free(se1); +#endif torture_assert_int_equal(test, alarm_count, 1+fde_count, "alarm count mismatch"); diff --git a/lib/tevent/tevent_req.c b/lib/tevent/tevent_req.c index 541f93f99c..0feabb5f1f 100644 --- a/lib/tevent/tevent_req.c +++ b/lib/tevent/tevent_req.c @@ -104,7 +104,7 @@ struct tevent_req *_tevent_req_create(TALLOC_CTX *mem_ctx, return NULL; } - data = talloc_size(req, data_size); + data = talloc_zero_size(req, data_size); if (data == NULL) { talloc_free(req); return NULL; diff --git a/lib/torture/torture.c b/lib/torture/torture.c index 99447e7e53..392cb0ad4c 100644 --- a/lib/torture/torture.c +++ b/lib/torture/torture.c @@ -65,7 +65,6 @@ struct torture_context *torture_context_child(struct torture_context *parent) if (subtorture == NULL) return NULL; - subtorture->level = parent->level+1; subtorture->ev = talloc_reference(subtorture, parent->ev); subtorture->lp_ctx = talloc_reference(subtorture, parent->lp_ctx); subtorture->outputdir = talloc_reference(subtorture, parent->outputdir); @@ -257,7 +256,6 @@ bool torture_run_suite(struct torture_context *context, struct torture_suite *tsuite; char *old_testname; - context->level++; if (context->results->ui_ops->suite_start) context->results->ui_ops->suite_start(context, suite); @@ -282,8 +280,6 @@ bool torture_run_suite(struct torture_context *context, if (context->results->ui_ops->suite_finish) context->results->ui_ops->suite_finish(context, suite); - context->level--; - return ret; } @@ -378,8 +374,6 @@ bool torture_run_tcase(struct torture_context *context, char *old_testname; struct torture_test *test; - context->level++; - context->active_tcase = tcase; if (context->results->ui_ops->tcase_start) context->results->ui_ops->tcase_start(context, tcase); @@ -415,8 +409,6 @@ done: if (context->results->ui_ops->tcase_finish) context->results->ui_ops->tcase_finish(context, tcase); - context->level--; - return ret; } diff --git a/lib/torture/torture.h b/lib/torture/torture.h index bc6365351e..e28801e269 100644 --- a/lib/torture/torture.h +++ b/lib/torture/torture.h @@ -86,9 +86,6 @@ struct torture_context /** Directory used for temporary test data */ const char *outputdir; - /** Indentation level */ - int level; - /** Event context */ struct tevent_context *ev; diff --git a/lib/tsocket/tsocket_bsd.c b/lib/tsocket/tsocket_bsd.c index 78bca4b0b5..8f1ccbeb43 100644 --- a/lib/tsocket/tsocket_bsd.c +++ b/lib/tsocket/tsocket_bsd.c @@ -203,7 +203,7 @@ struct tsocket_address_bsd { static int _tsocket_address_bsd_from_sockaddr(TALLOC_CTX *mem_ctx, struct sockaddr *sa, - socklen_t sa_len, + socklen_t sa_socklen, struct tsocket_address **_addr, const char *location) { @@ -212,20 +212,20 @@ static int _tsocket_address_bsd_from_sockaddr(TALLOC_CTX *mem_ctx, switch (sa->sa_family) { case AF_UNIX: - if (sa_len < sizeof(struct sockaddr_un)) { + if (sa_socklen < sizeof(struct sockaddr_un)) { errno = EINVAL; return -1; } break; case AF_INET: - if (sa_len < sizeof(struct sockaddr_in)) { + if (sa_socklen < sizeof(struct sockaddr_in)) { errno = EINVAL; return -1; } break; #ifdef HAVE_IPV6 case AF_INET6: - if (sa_len < sizeof(struct sockaddr_in6)) { + if (sa_socklen < sizeof(struct sockaddr_in6)) { errno = EINVAL; return -1; } @@ -236,7 +236,7 @@ static int _tsocket_address_bsd_from_sockaddr(TALLOC_CTX *mem_ctx, return -1; } - if (sa_len > sizeof(struct sockaddr_storage)) { + if (sa_socklen > sizeof(struct sockaddr_storage)) { errno = EINVAL; return -1; } @@ -253,7 +253,7 @@ static int _tsocket_address_bsd_from_sockaddr(TALLOC_CTX *mem_ctx, ZERO_STRUCTP(bsda); - memcpy(&bsda->u.ss, sa, sa_len); + memcpy(&bsda->u.ss, sa, sa_socklen); *_addr = addr; return 0; @@ -773,7 +773,7 @@ static void tdgram_bsd_recvfrom_handler(void *private_data) struct tsocket_address_bsd *bsda; ssize_t ret; struct sockaddr *sa = NULL; - socklen_t sa_len = 0; + socklen_t sa_socklen = 0; int err; bool retry; @@ -809,16 +809,16 @@ static void tdgram_bsd_recvfrom_handler(void *private_data) ZERO_STRUCTP(bsda); sa = &bsda->u.sa; - sa_len = sizeof(bsda->u.ss); + sa_socklen = sizeof(bsda->u.ss); /* * for unix sockets we can't use the size of sockaddr_storage * we would get EINVAL */ if (bsda->u.sa.sa_family == AF_UNIX) { - sa_len = sizeof(bsda->u.un); + sa_socklen = sizeof(bsda->u.un); } - ret = recvfrom(bsds->fd, state->buf, state->len, 0, sa, &sa_len); + ret = recvfrom(bsds->fd, state->buf, state->len, 0, sa, &sa_socklen); err = tsocket_bsd_error_from_errno(ret, errno, &retry); if (retry) { /* retry later */ @@ -946,7 +946,7 @@ static void tdgram_bsd_sendto_handler(void *private_data) struct tdgram_context *dgram = state->dgram; struct tdgram_bsd *bsds = tdgram_context_data(dgram, struct tdgram_bsd); struct sockaddr *sa = NULL; - socklen_t sa_len = 0; + socklen_t sa_socklen = 0; ssize_t ret; int err; bool retry; @@ -957,17 +957,17 @@ static void tdgram_bsd_sendto_handler(void *private_data) struct tsocket_address_bsd); sa = &bsda->u.sa; - sa_len = sizeof(bsda->u.ss); + sa_socklen = sizeof(bsda->u.ss); /* * for unix sockets we can't use the size of sockaddr_storage * we would get EINVAL */ if (bsda->u.sa.sa_family == AF_UNIX) { - sa_len = sizeof(bsda->u.un); + sa_socklen = sizeof(bsda->u.un); } } - ret = sendto(bsds->fd, state->buf, state->len, 0, sa, sa_len); + ret = sendto(bsds->fd, state->buf, state->len, 0, sa, sa_socklen); err = tsocket_bsd_error_from_errno(ret, errno, &retry); if (retry) { /* retry later */ @@ -1087,7 +1087,7 @@ static int tdgram_bsd_dgram_socket(const struct tsocket_address *local, int ret; bool do_bind = false; bool do_reuseaddr = false; - socklen_t sa_len = sizeof(lbsda->u.ss); + socklen_t sa_socklen = sizeof(lbsda->u.ss); if (remote) { rbsda = talloc_get_type_abort(remote->private_data, @@ -1108,7 +1108,7 @@ static int tdgram_bsd_dgram_socket(const struct tsocket_address *local, * for unix sockets we can't use the size of sockaddr_storage * we would get EINVAL */ - sa_len = sizeof(lbsda->u.un); + sa_socklen = sizeof(lbsda->u.un); break; case AF_INET: if (lbsda->u.in.sin_port != 0) { @@ -1189,7 +1189,7 @@ static int tdgram_bsd_dgram_socket(const struct tsocket_address *local, } if (do_bind) { - ret = bind(fd, &lbsda->u.sa, sa_len); + ret = bind(fd, &lbsda->u.sa, sa_socklen); if (ret == -1) { int saved_errno = errno; talloc_free(dgram); @@ -1199,7 +1199,7 @@ static int tdgram_bsd_dgram_socket(const struct tsocket_address *local, } if (rbsda) { - ret = connect(fd, &rbsda->u.sa, sa_len); + ret = connect(fd, &rbsda->u.sa, sa_socklen); if (ret == -1) { int saved_errno = errno; talloc_free(dgram); @@ -1889,7 +1889,7 @@ static struct tevent_req * tstream_bsd_connect_send(TALLOC_CTX *mem_ctx, bool retry; bool do_bind = false; bool do_reuseaddr = false; - socklen_t sa_len = sizeof(rbsda->u.ss); + socklen_t sa_socklen = sizeof(rbsda->u.ss); req = tevent_req_create(mem_ctx, &state, struct tstream_bsd_connect_state); @@ -1917,7 +1917,7 @@ static struct tevent_req * tstream_bsd_connect_send(TALLOC_CTX *mem_ctx, * for unix sockets we can't use the size of sockaddr_storage * we would get EINVAL */ - sa_len = sizeof(rbsda->u.un); + sa_socklen = sizeof(rbsda->u.un); break; case AF_INET: if (lbsda->u.in.sin_port != 0) { @@ -1977,7 +1977,7 @@ static struct tevent_req * tstream_bsd_connect_send(TALLOC_CTX *mem_ctx, } } - ret = connect(state->fd, &rbsda->u.sa, sa_len); + ret = connect(state->fd, &rbsda->u.sa, sa_socklen); err = tsocket_bsd_error_from_errno(ret, errno, &retry); if (retry) { /* retry later */ diff --git a/lib/util/genrand.c b/lib/util/genrand.c index cd1823a9a0..5b8456547a 100644 --- a/lib/util/genrand.c +++ b/lib/util/genrand.c @@ -294,6 +294,7 @@ _PUBLIC_ uint32_t generate_random(void) _PUBLIC_ bool check_password_quality(const char *s) { int has_digit=0, has_capital=0, has_lower=0, has_special=0, has_high=0; + const char* reals = s; while (*s) { if (isdigit((unsigned char)*s)) { has_digit |= 1; @@ -310,7 +311,7 @@ _PUBLIC_ bool check_password_quality(const char *s) } return ((has_digit + has_lower + has_capital + has_special) >= 3 - || (has_high > strlen(s)/2)); + || (has_high > strlen(reals)/2)); } /** diff --git a/lib/util/tests/genrand.c b/lib/util/tests/genrand.c index 5fe229c089..20a20ac7fa 100644 --- a/lib/util/tests/genrand.c +++ b/lib/util/tests/genrand.c @@ -40,6 +40,8 @@ static bool test_check_password_quality(struct torture_context *tctx) torture_assert(tctx, !check_password_quality("aaaaaaaaaaaa"), "same char password"); torture_assert(tctx, !check_password_quality("BLA"), "multiple upcases password"); torture_assert(tctx, !check_password_quality("123"), "digits only"); + torture_assert(tctx, !check_password_quality("matthiéu"), "not enough high symbols"); + torture_assert(tctx, check_password_quality("abcdééàçè"), "valid"); torture_assert(tctx, check_password_quality("A2e"), "valid"); torture_assert(tctx, check_password_quality("BA2eLi443"), "valid"); return true; diff --git a/lib/util/util_file.c b/lib/util/util_file.c index 0275e78c54..7466004e5c 100644 --- a/lib/util/util_file.c +++ b/lib/util/util_file.c @@ -380,6 +380,7 @@ _PUBLIC_ bool file_save(const char *fname, const void *packet, size_t length) return false; } if (write(fd, packet, length) != (size_t)length) { + close(fd); return false; } close(fd); |