From: Stefan Metzmacher Date: Wed, 12 May 2010 15:34:02 +0000 (+0200) Subject: s4:dsdb: fix samdb_result_logon_hours() and don't hardcode units_per_week X-Git-Url: http://git.samba.org/?p=metze%2Fsamba%2Fwip.git;a=commitdiff_plain;h=5159dbec812b45a037ba5df88e7b04ae25c877bd s4:dsdb: fix samdb_result_logon_hours() and don't hardcode units_per_week metze --- 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; }