diff options
author | Andrew Tridgell <tridge@samba.org> | 2004-05-25 13:57:39 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:56:14 -0500 |
commit | 579c13da43d5b40ac6d6c1436399fbc1d8dfd054 (patch) | |
tree | 42299570746f2d7f80356b689cb15e3db6c53d3c /source4/rpc_server/samr/samdb.c | |
parent | 81e8de9ca85fe9a6658beb1dab0d231c13cda063 (diff) | |
download | samba-579c13da43d5b40ac6d6c1436399fbc1d8dfd054.tar.gz samba-579c13da43d5b40ac6d6c1436399fbc1d8dfd054.tar.bz2 samba-579c13da43d5b40ac6d6c1436399fbc1d8dfd054.zip |
r873: converted samba4 to use real 64 bit integers instead of
structures. This was suggested by metze recently.
I checked on the build farm and all the machines we have support 64
bit ints, and support the LL suffix for 64 bit constants. I suspect
some won't support strtoll() and related functions, so we will
probably need replacements for those.
(This used to be commit 9a9244a1c66654c12abe4379661cba83a73c4c21)
Diffstat (limited to 'source4/rpc_server/samr/samdb.c')
-rw-r--r-- | source4/rpc_server/samr/samdb.c | 105 |
1 files changed, 78 insertions, 27 deletions
diff --git a/source4/rpc_server/samr/samdb.c b/source4/rpc_server/samr/samdb.c index c7a2f770c0..1d5b90a22d 100644 --- a/source4/rpc_server/samr/samdb.c +++ b/source4/rpc_server/samr/samdb.c @@ -233,6 +233,32 @@ uint_t samdb_search_uint(void *ctx, } /* + search the sam for a single signed 64 bit integer attribute in exactly 1 record +*/ +int64_t samdb_search_int64(void *ctx, + TALLOC_CTX *mem_ctx, + int64_t default_value, + const char *basedn, + const char *attr_name, + const char *format, ...) +{ + va_list ap; + int count; + struct ldb_message **res; + const char * const attrs[2] = { attr_name, NULL }; + + va_start(ap, format); + count = samdb_search_v(ctx, mem_ctx, basedn, &res, attrs, format, ap); + va_end(ap); + + if (count != 1) { + return default_value; + } + + return samdb_result_int64(res[0], attr_name, default_value); +} + +/* search the sam for multipe records each giving a single string attribute return the number of matches, or -1 on error */ @@ -289,6 +315,14 @@ uint_t samdb_result_uint(struct ldb_message *msg, const char *attr, uint_t defau } /* + pull a (signed) int64 from a result set. +*/ +int64_t samdb_result_int64(struct ldb_message *msg, const char *attr, int64_t default_value) +{ + return ldb_msg_find_int64(msg, attr, default_value); +} + +/* pull a string from a result set. */ const char *samdb_result_string(struct ldb_message *msg, const char *attr, @@ -350,11 +384,11 @@ NTTIME samdb_result_nttime(struct ldb_message *msg, const char *attr, const char } /* - pull a double (really a large integer) from a result set. + pull a uint64_t from a result set. */ -double samdb_result_double(struct ldb_message *msg, const char *attr, double default_value) +uint64_t samdb_result_uint64(struct ldb_message *msg, const char *attr, uint64_t default_value) { - return ldb_msg_find_double(msg, attr, default_value); + return ldb_msg_find_uint64(msg, attr, default_value); } @@ -365,17 +399,20 @@ double samdb_result_double(struct ldb_message *msg, const char *attr, double def NTTIME samdb_result_allow_pwd_change(void *ctx, TALLOC_CTX *mem_ctx, const char *domain_dn, struct ldb_message *msg, const char *attr) { - double attr_time = samdb_result_double(msg, attr, 0); - if (attr_time > 0) { - const char *minPwdAge = samdb_search_string(ctx, mem_ctx, NULL, "minPwdAge", - "dn=%s", domain_dn); - if (minPwdAge) { - /* yes, this is a -= not a += as minPwdAge is stored as the negative - of the number of 100-nano-seconds */ - attr_time -= strtod(minPwdAge, NULL); - } + uint64_t attr_time = samdb_result_uint64(msg, attr, 0); + int64_t minPwdAge; + + if (attr_time == 0) { + return 0; } - return nttime_from_double_nt(attr_time); + + minPwdAge = samdb_search_int64(ctx, mem_ctx, 0, "minPwdAge", "dn=%s", domain_dn); + + /* yes, this is a -= not a += as minPwdAge is stored as the negative + of the number of 100-nano-seconds */ + attr_time -= minPwdAge; + + return attr_time; } /* @@ -385,17 +422,21 @@ NTTIME samdb_result_allow_pwd_change(void *ctx, TALLOC_CTX *mem_ctx, NTTIME samdb_result_force_pwd_change(void *ctx, TALLOC_CTX *mem_ctx, const char *domain_dn, struct ldb_message *msg, const char *attr) { - double attr_time = samdb_result_double(msg, attr, 0); - if (attr_time > 0) { - const char *maxPwdAge = samdb_search_string(ctx, mem_ctx, NULL, "maxPwdAge", - "dn=%s", domain_dn); - if (!maxPwdAge || strcmp(maxPwdAge, "0") == 0) { - attr_time = 0; - } else { - attr_time -= strtod(maxPwdAge, NULL); - } + uint64_t attr_time = samdb_result_uint64(msg, attr, 0); + int64_t maxPwdAge; + + if (attr_time == 0) { + return 0; } - return nttime_from_double_nt(attr_time); + + maxPwdAge = samdb_search_int64(ctx, mem_ctx, 0, "maxPwdAge", "dn=%s", domain_dn); + if (maxPwdAge == 0) { + attr_time = 0; + } else { + attr_time -= maxPwdAge; + } + + return attr_time; } /* @@ -721,12 +762,22 @@ int samdb_msg_add_uint(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg, } /* - add a double element to a message (actually a large integer) + add a (signed) int64_t element to a message +*/ +int samdb_msg_add_int64(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg, + const char *attr_name, int64_t v) +{ + const char *s = talloc_asprintf(mem_ctx, "%lld", v); + return samdb_msg_add_string(ctx, mem_ctx, msg, attr_name, s); +} + +/* + add a uint64_t element to a message */ -int samdb_msg_add_double(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg, - const char *attr_name, double v) +int samdb_msg_add_uint64(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg, + const char *attr_name, uint64_t v) { - const char *s = talloc_asprintf(mem_ctx, "%.0f", v); + const char *s = talloc_asprintf(mem_ctx, "%llu", v); return samdb_msg_add_string(ctx, mem_ctx, msg, attr_name, s); } |