diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2012-05-11 16:27:46 +0200 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2012-05-11 14:01:39 -0400 |
commit | a6cd03ae90df8ed8de8fd53c6e408a3f8d1ca077 (patch) | |
tree | b5e0d7b9e31d7165c3cd6cc22a5b2a16e2d3e0cc /src/db/sysdb_ops.c | |
parent | 5280fa952a30ca58c5739729abd21a307396cb9c (diff) | |
download | sssd-803c10b2a107aaa79457cefb5d57257463387744.tar.gz sssd-803c10b2a107aaa79457cefb5d57257463387744.tar.xz sssd-803c10b2a107aaa79457cefb5d57257463387744.zip |
SYSDB: Handle user and group renames bettersssd-1.8.0-27.el6
Fixes a regression in the local domain tools where sss_groupadd no longer
detected a GID duplicate. The check for EEXIST is moved one level up into
more high level function.
The patch also adds the same rename support for users. I found it odd that
we allowed a rename of groups but not users. There is a catch when storing
a user -- his cached password would be gone. I think that renaming a user
is such a rare operation that it's not severe, plus there is a warning in
the logs.
Diffstat (limited to 'src/db/sysdb_ops.c')
-rw-r--r-- | src/db/sysdb_ops.c | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c index 87c13017f..17cd81ed2 100644 --- a/src/db/sysdb_ops.c +++ b/src/db/sysdb_ops.c @@ -1159,13 +1159,8 @@ int sysdb_add_group(struct sysdb_ctx *sysdb, ret = sysdb_search_group_by_gid(tmp_ctx, sysdb, gid, NULL, &msg); if (ret != ENOENT) { - if (ret == EOK) { - ret = sysdb_delete_group(sysdb, NULL, gid); - } - - if (ret != EOK) { - goto done; - } + if (ret == EOK) ret = EEXIST; + goto done; } } @@ -1507,6 +1502,25 @@ int sysdb_store_user(struct sysdb_ctx *sysdb, /* users doesn't exist, turn into adding a user */ ret = sysdb_add_user(sysdb, name, uid, gid, gecos, homedir, shell, attrs, cache_timeout, now); + if (ret == EEXIST) { + /* This may be a user rename. If there is a user with the + * same UID, remove it and try to add the basic user again + */ + ret = sysdb_delete_user(sysdb, NULL, uid); + if (ret == ENOENT) { + /* Not found by UID, return the original EEXIST, + * this may be a conflict in MPG domain or something + * else */ + return EEXIST; + } else if (ret != EOK) { + goto done; + } + DEBUG(SSSDBG_MINOR_FAILURE, + ("A user with the same UID [%llu] was removed from the " + "cache\n", uid)); + ret = sysdb_add_user(sysdb, name, uid, gid, gecos, + homedir, shell, attrs, cache_timeout, now); + } goto done; } @@ -1635,6 +1649,24 @@ int sysdb_store_group(struct sysdb_ctx *sysdb, if (new_group) { /* group doesn't exist, turn into adding a group */ ret = sysdb_add_group(sysdb, name, gid, attrs, cache_timeout, now); + if (ret == EEXIST) { + /* This may be a group rename. If there is a group with the + * same GID, remove it and try to add the basic group again + */ + ret = sysdb_delete_group(sysdb, NULL, gid); + if (ret == ENOENT) { + /* Not found by GID, return the original EEXIST, + * this may be a conflict in MPG domain or something + * else */ + return EEXIST; + } else if (ret != EOK) { + goto done; + } + DEBUG(SSSDBG_MINOR_FAILURE, + ("A group with the same GID [%llu] was removed from the " + "cache\n", gid)); + ret = sysdb_add_group(sysdb, name, gid, attrs, cache_timeout, now); + } goto done; } |