|
|
905b4d |
From aeb6e3d066122621e1ec043f0c7848363539ca5f Mon Sep 17 00:00:00 2001
|
|
|
905b4d |
From: Michal Zidek <mzidek@redhat.com>
|
|
|
905b4d |
Date: Fri, 31 Oct 2014 16:39:25 +0100
|
|
|
905b4d |
Subject: [PATCH 81/82] proxy: Do not try to store same alias twice
|
|
|
905b4d |
|
|
|
905b4d |
LDB does not store attributes if they have the
|
|
|
905b4d |
same name and value and errors out instead.
|
|
|
905b4d |
|
|
|
905b4d |
Fixes:
|
|
|
905b4d |
https://fedorahosted.org/sssd/ticket/2461
|
|
|
905b4d |
|
|
|
905b4d |
Reviewed-by: Pavel Reichl <preichl@redhat.com>
|
|
|
905b4d |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
905b4d |
---
|
|
|
905b4d |
src/providers/proxy/proxy_id.c | 77 +++++++++++++++++++++++++++---------------
|
|
|
905b4d |
1 file changed, 49 insertions(+), 28 deletions(-)
|
|
|
905b4d |
|
|
|
905b4d |
diff --git a/src/providers/proxy/proxy_id.c b/src/providers/proxy/proxy_id.c
|
|
|
905b4d |
index d867ec45f633fb5869f5658e0ac1b54bcbab8369..96d9910f7c81d8e1d4245adc69ebc8af6b5b7112 100644
|
|
|
905b4d |
--- a/src/providers/proxy/proxy_id.c
|
|
|
905b4d |
+++ b/src/providers/proxy/proxy_id.c
|
|
|
905b4d |
@@ -222,6 +222,7 @@ static int save_user(struct sss_domain_info *domain,
|
|
|
905b4d |
struct sysdb_attrs *attrs = NULL;
|
|
|
905b4d |
errno_t ret;
|
|
|
905b4d |
const char *cased_alias;
|
|
|
905b4d |
+ const char *lc_pw_name = NULL;
|
|
|
905b4d |
|
|
|
905b4d |
if (pwd->pw_shell && pwd->pw_shell[0] != '\0') {
|
|
|
905b4d |
shell = pwd->pw_shell;
|
|
|
905b4d |
@@ -239,31 +240,42 @@ static int save_user(struct sss_domain_info *domain,
|
|
|
905b4d |
attrs = sysdb_new_attrs(NULL);
|
|
|
905b4d |
if (!attrs) {
|
|
|
905b4d |
DEBUG(SSSDBG_CRIT_FAILURE, "Allocation error ?!\n");
|
|
|
905b4d |
- return ENOMEM;
|
|
|
905b4d |
+ ret = ENOMEM;
|
|
|
905b4d |
+ goto done;
|
|
|
905b4d |
}
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
if (lowercase) {
|
|
|
905b4d |
- ret = sysdb_attrs_add_lc_name_alias(attrs, pwd->pw_name);
|
|
|
905b4d |
+ lc_pw_name = sss_tc_utf8_str_tolower(attrs, pwd->pw_name);
|
|
|
905b4d |
+ if (lc_pw_name == NULL) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_OP_FAILURE, "Cannot convert name to lowercase.\n");
|
|
|
905b4d |
+ ret = ENOMEM;
|
|
|
905b4d |
+ goto done;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = sysdb_attrs_add_string(attrs, SYSDB_NAME_ALIAS, lc_pw_name);
|
|
|
905b4d |
if (ret) {
|
|
|
905b4d |
DEBUG(SSSDBG_OP_FAILURE, "Could not add name alias\n");
|
|
|
905b4d |
- talloc_zfree(attrs);
|
|
|
905b4d |
- return ret;
|
|
|
905b4d |
+ ret = ENOMEM;
|
|
|
905b4d |
+ goto done;
|
|
|
905b4d |
}
|
|
|
905b4d |
+
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
if (alias) {
|
|
|
905b4d |
cased_alias = sss_get_cased_name(attrs, alias, !lowercase);
|
|
|
905b4d |
if (!cased_alias) {
|
|
|
905b4d |
- talloc_zfree(attrs);
|
|
|
905b4d |
- return ENOMEM;
|
|
|
905b4d |
+ ret = ENOMEM;
|
|
|
905b4d |
+ goto done;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
- ret = sysdb_attrs_add_string(attrs, SYSDB_NAME_ALIAS, cased_alias);
|
|
|
905b4d |
- if (ret) {
|
|
|
905b4d |
- DEBUG(SSSDBG_OP_FAILURE, "Could not add name alias\n");
|
|
|
905b4d |
- talloc_zfree(attrs);
|
|
|
905b4d |
- return ret;
|
|
|
905b4d |
+ /* Add the alias only if it differs from lowercased pw_name */
|
|
|
905b4d |
+ if (lc_pw_name == NULL || strcmp(cased_alias, lc_pw_name) != 0) {
|
|
|
905b4d |
+ ret = sysdb_attrs_add_string(attrs, SYSDB_NAME_ALIAS, cased_alias);
|
|
|
905b4d |
+ if (ret) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_OP_FAILURE, "Could not add name alias\n");
|
|
|
905b4d |
+ goto done;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
}
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
@@ -280,13 +292,14 @@ static int save_user(struct sss_domain_info *domain,
|
|
|
905b4d |
NULL,
|
|
|
905b4d |
cache_timeout,
|
|
|
905b4d |
0);
|
|
|
905b4d |
- talloc_zfree(attrs);
|
|
|
905b4d |
if (ret) {
|
|
|
905b4d |
DEBUG(SSSDBG_OP_FAILURE, "Could not add user to cache\n");
|
|
|
905b4d |
- return ret;
|
|
|
905b4d |
+ goto done;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
- return EOK;
|
|
|
905b4d |
+done:
|
|
|
905b4d |
+ talloc_zfree(attrs);
|
|
|
905b4d |
+ return ret;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
/* =Getpwuid-wrapper======================================================*/
|
|
|
905b4d |
@@ -527,6 +540,7 @@ static int save_group(struct sysdb_ctx *sysdb, struct sss_domain_info *dom,
|
|
|
905b4d |
errno_t ret, sret;
|
|
|
905b4d |
struct sysdb_attrs *attrs = NULL;
|
|
|
905b4d |
const char *cased_alias;
|
|
|
905b4d |
+ const char *lc_gr_name = NULL;
|
|
|
905b4d |
TALLOC_CTX *tmp_ctx;
|
|
|
905b4d |
time_t now = time(NULL);
|
|
|
905b4d |
bool in_transaction = false;
|
|
|
905b4d |
@@ -578,27 +592,34 @@ static int save_group(struct sysdb_ctx *sysdb, struct sss_domain_info *dom,
|
|
|
905b4d |
goto done;
|
|
|
905b4d |
}
|
|
|
905b4d |
}
|
|
|
905b4d |
+ }
|
|
|
905b4d |
|
|
|
905b4d |
- if (dom->case_sensitive == false) {
|
|
|
905b4d |
- ret = sysdb_attrs_add_lc_name_alias(attrs, grp->gr_name);
|
|
|
905b4d |
- if (ret) {
|
|
|
905b4d |
- DEBUG(SSSDBG_OP_FAILURE, "Could not add name alias\n");
|
|
|
905b4d |
- ret = ENOMEM;
|
|
|
905b4d |
- goto done;
|
|
|
905b4d |
- }
|
|
|
905b4d |
+ if (dom->case_sensitive == false) {
|
|
|
905b4d |
+ lc_gr_name = sss_tc_utf8_str_tolower(attrs, grp->gr_name);
|
|
|
905b4d |
+ if (lc_gr_name == NULL) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_OP_FAILURE, "Cannot convert name to lowercase.\n");
|
|
|
905b4d |
+ ret = ENOMEM;
|
|
|
905b4d |
+ goto done;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
- if (alias) {
|
|
|
905b4d |
- cased_alias = sss_get_cased_name(attrs, alias, dom->case_sensitive);
|
|
|
905b4d |
- if (!cased_alias) {
|
|
|
905b4d |
- talloc_zfree(attrs);
|
|
|
905b4d |
- return ENOMEM;
|
|
|
905b4d |
- }
|
|
|
905b4d |
+ ret = sysdb_attrs_add_string(attrs, SYSDB_NAME_ALIAS, lc_gr_name);
|
|
|
905b4d |
+ if (ret != EOK) {
|
|
|
905b4d |
+ goto done;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ if (alias) {
|
|
|
905b4d |
+ cased_alias = sss_get_cased_name(attrs, alias, dom->case_sensitive);
|
|
|
905b4d |
+ if (!cased_alias) {
|
|
|
905b4d |
+ ret = ENOMEM;
|
|
|
905b4d |
+ DEBUG(SSSDBG_OP_FAILURE, "Could not add name alias\n");
|
|
|
905b4d |
+ goto done;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
|
|
|
905b4d |
+ if (lc_gr_name == NULL || strcmp(cased_alias, lc_gr_name)) {
|
|
|
905b4d |
ret = sysdb_attrs_add_string(attrs, SYSDB_NAME_ALIAS, cased_alias);
|
|
|
905b4d |
if (ret) {
|
|
|
905b4d |
DEBUG(SSSDBG_OP_FAILURE, "Could not add name alias\n");
|
|
|
905b4d |
- ret = ENOMEM;
|
|
|
905b4d |
goto done;
|
|
|
905b4d |
}
|
|
|
905b4d |
}
|
|
|
905b4d |
--
|
|
|
905b4d |
1.9.3
|
|
|
905b4d |
|