From 5159dbec812b45a037ba5df88e7b04ae25c877bd Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 12 May 2010 17:34:02 +0200 Subject: [PATCH] s4:dsdb: fix samdb_result_logon_hours() and don't hardcode units_per_week metze --- source4/dsdb/common/util.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/source4/dsdb/common/util.c b/source4/dsdb/common/util.c index b9bff91eb84a..63870278ceb3 100644 --- a/source4/dsdb/common/util.c +++ b/source4/dsdb/common/util.c @@ -630,18 +630,25 @@ NTSTATUS samdb_result_passwords(TALLOC_CTX *mem_ctx, struct loadparm_context *lp struct samr_LogonHours samdb_result_logon_hours(TALLOC_CTX *mem_ctx, struct ldb_message *msg, const char *attr) { struct samr_LogonHours hours; - const int units_per_week = 168; + size_t units_per_week = 168; const struct ldb_val *val = ldb_msg_find_ldb_val(msg, attr); + ZERO_STRUCT(hours); - hours.bits = talloc_array(mem_ctx, uint8_t, units_per_week); + + if (val) { + units_per_week = val->length * 8; + } + + hours.bits = talloc_array(mem_ctx, uint8_t, units_per_week/8); if (!hours.bits) { return hours; } hours.units_per_week = units_per_week; - memset(hours.bits, 0xFF, units_per_week); + memset(hours.bits, 0xFF, units_per_week/8); if (val) { - memcpy(hours.bits, val->data, MIN(val->length, units_per_week)); + memcpy(hours.bits, val->data, val->length); } + return hours; } -- 2.34.1