diff options
-rw-r--r-- | src/db/sysdb.c | 7 | ||||
-rw-r--r-- | src/db/sysdb_private.h | 7 | ||||
-rw-r--r-- | src/db/sysdb_upgrade.c | 92 | ||||
-rw-r--r-- | src/tests/sysdb-tests.c | 14 |
4 files changed, 118 insertions, 2 deletions
diff --git a/src/db/sysdb.c b/src/db/sysdb.c index d872bc927..399beee3c 100644 --- a/src/db/sysdb.c +++ b/src/db/sysdb.c @@ -929,6 +929,13 @@ int sysdb_domain_init_internal(TALLOC_CTX *mem_ctx, } } + if (strcmp(version, SYSDB_VERSION_0_8) == 0) { + ret = sysdb_upgrade_08(sysdb, &version); + if (ret != EOK) { + goto done; + } + } + /* The version should now match SYSDB_VERSION. * If not, it means we didn't match any of the * known older versions. The DB might be diff --git a/src/db/sysdb_private.h b/src/db/sysdb_private.h index 8d3eee723..37090f8a8 100644 --- a/src/db/sysdb_private.h +++ b/src/db/sysdb_private.h @@ -23,6 +23,7 @@ #ifndef __INT_SYS_DB_H__ #define __INT_SYS_DB_H__ +#define SYSDB_VERSION_0_9 "0.9" #define SYSDB_VERSION_0_8 "0.8" #define SYSDB_VERSION_0_7 "0.7" #define SYSDB_VERSION_0_6 "0.6" @@ -32,7 +33,7 @@ #define SYSDB_VERSION_0_2 "0.2" #define SYSDB_VERSION_0_1 "0.1" -#define SYSDB_VERSION SYSDB_VERSION_0_8 +#define SYSDB_VERSION SYSDB_VERSION_0_9 #define SYSDB_BASE_LDIF \ "dn: @ATTRIBUTES\n" \ @@ -55,6 +56,8 @@ "@IDXATTR: dataExpireTimestamp\n" \ "@IDXATTR: originalDN\n" \ "@IDXATTR: nameAlias\n" \ + "@IDXATTR: servicePort\n" \ + "@IDXATTR: serviceProtocol\n" \ "@IDXONE: 1\n" \ "\n" \ "dn: @MODULES\n" \ @@ -97,7 +100,7 @@ int sysdb_upgrade_04(struct sysdb_ctx *sysdb, const char **ver); int sysdb_upgrade_05(struct sysdb_ctx *sysdb, const char **ver); int sysdb_upgrade_06(struct sysdb_ctx *sysdb, const char **ver); int sysdb_upgrade_07(struct sysdb_ctx *sysdb, const char **ver); - +int sysdb_upgrade_08(struct sysdb_ctx *sysdb, const char **ver); int add_string(struct ldb_message *msg, int flags, const char *attr, const char *value); diff --git a/src/db/sysdb_upgrade.c b/src/db/sysdb_upgrade.c index 808b31f17..ab8394f57 100644 --- a/src/db/sysdb_upgrade.c +++ b/src/db/sysdb_upgrade.c @@ -980,3 +980,95 @@ done: talloc_free(tmp_ctx); return ret; } + +int sysdb_upgrade_08(struct sysdb_ctx *sysdb, const char **ver) +{ + TALLOC_CTX *tmp_ctx; + int ret; + struct ldb_message *msg; + + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { + return ENOMEM; + } + + DEBUG(0, ("UPGRADING DB TO VERSION %s\n", SYSDB_VERSION_0_9)); + + ret = ldb_transaction_start(sysdb->ldb); + if (ret != LDB_SUCCESS) { + ret = EIO; + goto done; + } + + /* Add new indexes */ + msg = ldb_msg_new(tmp_ctx); + if (!msg) { + ret = ENOMEM; + goto done; + } + msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@INDEXLIST"); + if (!msg->dn) { + ret = ENOMEM; + goto done; + } + + /* Add Index for servicePort and serviceProtocol */ + ret = ldb_msg_add_empty(msg, "@IDXATTR", LDB_FLAG_MOD_ADD, NULL); + if (ret != LDB_SUCCESS) { + ret = ENOMEM; + goto done; + } + ret = ldb_msg_add_string(msg, "@IDXATTR", "servicePort"); + if (ret != LDB_SUCCESS) { + ret = ENOMEM; + goto done; + } + + ret = ldb_msg_add_string(msg, "@IDXATTR", "serviceProtocol"); + if (ret != LDB_SUCCESS) { + ret = ENOMEM; + goto done; + } + + ret = ldb_modify(sysdb->ldb, msg); + if (ret != LDB_SUCCESS) { + ret = sysdb_error_to_errno(ret); + goto done; + } + + /* conversion done, upgrade version number */ + msg = ldb_msg_new(tmp_ctx); + if (!msg) { + ret = ENOMEM; + goto done; + } + msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, SYSDB_BASE); + if (!msg->dn) { + ret = ENOMEM; + goto done; + } + + ret = ldb_msg_add_empty(msg, "version", LDB_FLAG_MOD_REPLACE, NULL); + if (ret != LDB_SUCCESS) { + ret = ENOMEM; + goto done; + } + ret = ldb_msg_add_string(msg, "version", SYSDB_VERSION_0_9); + if (ret != LDB_SUCCESS) { + ret = ENOMEM; + goto done; + } + + ret = ldb_modify(sysdb->ldb, msg); + if (ret != LDB_SUCCESS) { + ret = sysdb_error_to_errno(ret); + goto done; + } + + ret = EOK; + +done: + ret = finish_upgrade(ret, sysdb->ldb, SYSDB_VERSION_0_9, ver); + talloc_free(tmp_ctx); + return ret; +} diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c index 8b78ff320..fa034cec8 100644 --- a/src/tests/sysdb-tests.c +++ b/src/tests/sysdb-tests.c @@ -2889,6 +2889,15 @@ void services_check_match(struct sysdb_test_ctx *test_ctx, services_check_match(test_ctx, false, primary_name, port, aliases, protocols); \ } while(0); +errno_t +sysdb_svc_add(TALLOC_CTX *mem_ctx, + struct sysdb_ctx *sysdb, + const char *primary_name, + int port, + const char **aliases, + const char **protocols, + struct ldb_dn **dn); + START_TEST(test_sysdb_add_services) { errno_t ret; @@ -3078,6 +3087,11 @@ START_TEST(test_sysdb_store_services) } END_TEST +errno_t +sysdb_svc_remove_alias(struct sysdb_ctx *sysdb, + struct ldb_dn *dn, + const char *alias); + START_TEST(test_sysdb_svc_remove_alias) { errno_t ret; |