diff options
author | Ondrej Kos <okos@redhat.com> | 2012-11-08 14:34:36 +0100 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2012-11-19 13:35:55 +0100 |
commit | 4c9a85ab708ec7debecad51e4240e04d8bc6ca4e (patch) | |
tree | bcc2ac0722065b8832bd4073479ba08792888956 /src/db/sysdb.c | |
parent | c475ce7bfa230a0a0167a294317c1120211cbb4c (diff) | |
download | sssd-4c9a85ab708ec7debecad51e4240e04d8bc6ca4e.tar.gz sssd-4c9a85ab708ec7debecad51e4240e04d8bc6ca4e.tar.xz sssd-4c9a85ab708ec7debecad51e4240e04d8bc6ca4e.zip |
Display more information on DB version mismatch
https://fedorahosted.org/sssd/ticket/1589
Added check for determining, whether database version is higher or
lower than expected. To distinguish it from other errors it uses
following retun values (further used for appropriate error message):
EMEDIUMTYPE for lower version than expected
EUCLEAN for higher version than expected
When SSSD or one of it's tools fails on DB version mismatch, new error
message is showed suggesting how to proceed.
Diffstat (limited to 'src/db/sysdb.c')
-rw-r--r-- | src/db/sysdb.c | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/db/sysdb.c b/src/db/sysdb.c index 9685163b3..dda288f76 100644 --- a/src/db/sysdb.c +++ b/src/db/sysdb.c @@ -947,6 +947,38 @@ errno_t sysdb_add_to_domain(struct sss_domain_info *domain, return EOK; } +/* Compare versions of sysdb, returns ERRNO accordingly */ +static errno_t +sysdb_version_check(const char *expected, + const char *received) +{ + int ret; + unsigned int exp_major, exp_minor, recv_major, recv_minor; + + ret = sscanf(expected, "%u.%u", &exp_major, &exp_minor); + if (ret != 2) { + return EINVAL; + } + ret = sscanf(received, "%u.%u", &recv_major, &recv_minor); + if (ret != 2) { + return EINVAL; + } + + if (recv_major > exp_major) { + return EUCLEAN; + } else if (recv_major < exp_major) { + return EMEDIUMTYPE; + } + + if (recv_minor > exp_minor) { + return EUCLEAN; + } else if (recv_minor < exp_minor) { + return EMEDIUMTYPE; + } + + return EOK; +} + int sysdb_domain_init_internal(TALLOC_CTX *mem_ctx, struct sss_domain_info *domain, const char *db_path, @@ -1037,7 +1069,7 @@ int sysdb_domain_init_internal(TALLOC_CTX *mem_ctx, if (!allow_upgrade) { DEBUG(0, ("Wrong DB version (got %s expected %s)\n", version, SYSDB_VERSION)); - ret = EINVAL; + ret = sysdb_version_check(SYSDB_VERSION, version); goto done; } @@ -1136,7 +1168,7 @@ int sysdb_domain_init_internal(TALLOC_CTX *mem_ctx, DEBUG(0,("Unknown DB version [%s], expected [%s] for domain %s!\n", version?version:"not found", SYSDB_VERSION, domain->name)); - ret = EINVAL; + ret = sysdb_version_check(SYSDB_VERSION, version); goto done; } |