summaryrefslogtreecommitdiffstats
path: root/source4/dsdb
diff options
context:
space:
mode:
authorKamen Mazdrashki <kamenim@samba.org>2015-01-28 01:43:10 +0200
committerAndrew Bartlett <abartlet@samba.org>2015-02-03 05:02:12 +0100
commit3c066661e826bed16869a6c0d52c4e083ea6bae0 (patch)
tree7858d34419da5f829b074f7e684c1d5c86b3fe67 /source4/dsdb
parented60811893e1362c0067001113a5bf267ae2c52e (diff)
downloadsamba-3c066661e826bed16869a6c0d52c4e083ea6bae0.tar.gz
samba-3c066661e826bed16869a6c0d52c4e083ea6bae0.tar.xz
samba-3c066661e826bed16869a6c0d52c4e083ea6bae0.zip
s4-dsdb: Refactor user objects defaults setter to use attribute/value map
Change-Id: Iaa32af4225219a4c5c42c663022e8be429b8a1d2 Signed-off-by: Kamen Mazdrashki <kamenim@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
Diffstat (limited to 'source4/dsdb')
-rw-r--r--source4/dsdb/common/util.c77
1 files changed, 49 insertions, 28 deletions
diff --git a/source4/dsdb/common/util.c b/source4/dsdb/common/util.c
index ac90cbc83b..7b948f2d81 100644
--- a/source4/dsdb/common/util.c
+++ b/source4/dsdb/common/util.c
@@ -4854,35 +4854,56 @@ NTSTATUS dsdb_update_bad_pwd_count(TALLOC_CTX *mem_ctx,
*/
int dsdb_user_obj_set_defaults(struct ldb_context *ldb, struct ldb_message *usr_obj)
{
- int ret;
+ int i, ret;
+ const struct attribute_values {
+ const char *name;
+ const char *value;
+ } map[] = {
+ {
+ .name = "accountExpires",
+ .value = "9223372036854775807"
+ },
+ {
+ .name = "badPasswordTime",
+ .value = "0"
+ },
+ {
+ .name = "badPwdCount",
+ .value = "0"
+ },
+ {
+ .name = "codePage",
+ .value = "0"
+ },
+ {
+ .name = "countryCode",
+ .value = "0"
+ },
+ {
+ .name = "lastLogoff",
+ .value = "0"
+ },
+ {
+ .name = "lastLogon",
+ .value = "0"
+ },
+ {
+ .name = "logonCount",
+ .value = "0"
+ },
+ {
+ .name = "pwdLastSet",
+ .value = "0"
+ }
+ };
- ret = samdb_find_or_add_attribute(ldb, usr_obj,
- "accountExpires", "9223372036854775807");
- if (ret != LDB_SUCCESS) return ret;
- ret = samdb_find_or_add_attribute(ldb, usr_obj,
- "badPasswordTime", "0");
- if (ret != LDB_SUCCESS) return ret;
- ret = samdb_find_or_add_attribute(ldb, usr_obj,
- "badPwdCount", "0");
- if (ret != LDB_SUCCESS) return ret;
- ret = samdb_find_or_add_attribute(ldb, usr_obj,
- "codePage", "0");
- if (ret != LDB_SUCCESS) return ret;
- ret = samdb_find_or_add_attribute(ldb, usr_obj,
- "countryCode", "0");
- if (ret != LDB_SUCCESS) return ret;
- ret = samdb_find_or_add_attribute(ldb, usr_obj,
- "lastLogoff", "0");
- if (ret != LDB_SUCCESS) return ret;
- ret = samdb_find_or_add_attribute(ldb, usr_obj,
- "lastLogon", "0");
- if (ret != LDB_SUCCESS) return ret;
- ret = samdb_find_or_add_attribute(ldb, usr_obj,
- "logonCount", "0");
- if (ret != LDB_SUCCESS) return ret;
- ret = samdb_find_or_add_attribute(ldb, usr_obj,
- "pwdLastSet", "0");
- if (ret != LDB_SUCCESS) return ret;
+ for (i = 0; i < ARRAY_SIZE(map); i++) {
+ ret = samdb_find_or_add_attribute(ldb, usr_obj,
+ map[i].name, map[i].value);
+ if (ret != LDB_SUCCESS) {
+ return ret;
+ }
+ }
return LDB_SUCCESS;
}