diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2012-05-11 16:27:46 +0200 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2012-05-11 12:17:12 -0400 |
commit | 79a93ba6dc35ebe525e2d7587bc7e293e8cf3b81 (patch) | |
tree | e5d6bb7251fed15182474d956e1f5bbbfd850bc2 /src/db | |
parent | 3db7aca0479a30f4a1e66a35b4b7b7bcfd81a78f (diff) | |
download | sssd-79a93ba6dc35ebe525e2d7587bc7e293e8cf3b81.tar.gz sssd-79a93ba6dc35ebe525e2d7587bc7e293e8cf3b81.tar.xz sssd-79a93ba6dc35ebe525e2d7587bc7e293e8cf3b81.zip |
SYSDB: Handle user and group renames better
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')
-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 bedd8cfa2..5b7dba3db 100644 --- a/src/db/sysdb_ops.c +++ b/src/db/sysdb_ops.c @@ -1165,13 +1165,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; } } @@ -1513,6 +1508,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; } @@ -1641,6 +1655,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; } |