From 54a695f7edf7c40a92391aa94ddbbd2db8b11ec3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 9 May 2004 09:39:47 +0000 Subject: r601: added the server code for all the samr_SetUserInfo and samr_QueryUserInfo levels except for the password set levels. This means that a large part of the RPC-SAMR torture test now runs correctly against Samba4 (This used to be commit ec0a51898f543578e755207d81ed5c1524861c64) --- source4/lib/ldb/common/ldb_msg.c | 36 ++++++++++++++++++++++-------------- source4/lib/time.c | 26 ++++++++++++++++++-------- 2 files changed, 40 insertions(+), 22 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c index 01f32751e1..59d480a33a 100644 --- a/source4/lib/ldb/common/ldb_msg.c +++ b/source4/lib/ldb/common/ldb_msg.c @@ -136,7 +136,7 @@ int ldb_msg_add(struct ldb_context *ldb, */ int ldb_msg_add_value(struct ldb_context *ldb, struct ldb_message *msg, - char *attr_name, + const char *attr_name, struct ldb_val *val) { struct ldb_message_element *el; @@ -200,51 +200,59 @@ int ldb_msg_element_compare(struct ldb_message_element *el1, return 0; } - /* convenience functions to return common types from a message these return the first value if the attribute is multi-valued */ +const struct ldb_val *ldb_msg_find_ldb_val(const struct ldb_message *msg, const char *attr_name) +{ + struct ldb_message_element *el = ldb_msg_find_element(msg, attr_name); + if (!el || el->num_values == 0) { + return NULL; + } + return &el->values[0]; +} + int ldb_msg_find_int(const struct ldb_message *msg, const char *attr_name, int default_value) { - struct ldb_message_element *el = ldb_msg_find_element(msg, attr_name); - if (!el || el->num_values == 0) { + const struct ldb_val *v = ldb_msg_find_ldb_val(msg, attr_name); + if (!v || !v->data) { return default_value; } - return strtol(el->values[0].data, NULL, 0); + return strtol(v->data, NULL, 0); } unsigned int ldb_msg_find_uint(const struct ldb_message *msg, const char *attr_name, int default_value) { - struct ldb_message_element *el = ldb_msg_find_element(msg, attr_name); - if (!el || el->num_values == 0) { + const struct ldb_val *v = ldb_msg_find_ldb_val(msg, attr_name); + if (!v || !v->data) { return default_value; } - return strtoul(el->values[0].data, NULL, 0); + return strtoul(v->data, NULL, 0); } double ldb_msg_find_double(const struct ldb_message *msg, const char *attr_name, double default_value) { - struct ldb_message_element *el = ldb_msg_find_element(msg, attr_name); - if (!el || el->num_values == 0) { + const struct ldb_val *v = ldb_msg_find_ldb_val(msg, attr_name); + if (!v || !v->data) { return default_value; } - return strtod(el->values[0].data, NULL); + return strtod(v->data, NULL); } const char *ldb_msg_find_string(const struct ldb_message *msg, const char *attr_name, const char *default_value) { - struct ldb_message_element *el = ldb_msg_find_element(msg, attr_name); - if (!el || el->num_values == 0) { + const struct ldb_val *v = ldb_msg_find_ldb_val(msg, attr_name); + if (!v || !v->data) { return default_value; } - return el->values[0].data; + return v->data; } diff --git a/source4/lib/time.c b/source4/lib/time.c index 65b85b2180..ba650668c5 100644 --- a/source4/lib/time.c +++ b/source4/lib/time.c @@ -428,21 +428,31 @@ NTTIME pull_nttime(void *base, uint16 offset) return ret; } +/* + convert a NTTIME to a double in 100-nano-seconds since 1601 +*/ +double nttime_to_double_nt(NTTIME t) +{ + const double t32 = 4294967296.0; + return t.high*t32 + t.low; +} /* - parse a nttime as a integer in a string and return a NTTIME + convert a double in 100-nano-seconds since 1601 to a NTTIME */ -NTTIME nttime_from_string(const char *s) +NTTIME nttime_from_double_nt(double t) { - double t = 0; const double t32 = 4294967296.0; NTTIME ret; - /* i wish we could rely on 64 bit systems and sscanf %llu */ - if (sscanf(s, "%lf", &t) != 1) { - ret.low = 0; - ret.high = 0; - } ret.high = t / t32; ret.low = t - (ret.high*t32); return ret; } + +/* + parse a nttime as a large integer in a string and return a NTTIME +*/ +NTTIME nttime_from_string(const char *s) +{ + return nttime_from_double_nt(strtod(s, NULL)); +} -- cgit