<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
<div class="moz-cite-prefix">On 11/06/2014 07:48 PM, Michal Židek
wrote:<br>
</div>
<blockquote cite="mid:545BC274.8050607@redhat.com" type="cite">
<fieldset class="mimeAttachmentHeader"><legend
class="mimeAttachmentHeaderName">0001-proxy-Do-not-try-to-store-same-alias-twice.patch</legend></fieldset>
<br>
<div class="moz-text-plain" wrap="true" graphical-quote="true"
style="font-family: -moz-fixed; font-size: 12px;"
lang="x-western">
<pre wrap="">From f6c84c306cf921344ad2b23040588040ac407186 Mon Sep 17 00:00:00 2001
From: Michal Zidek <a moz-do-not-send="true" class="moz-txt-link-rfc2396E" href="mailto:mzidek@redhat.com"><mzidek@redhat.com></a>
Date: Fri, 31 Oct 2014 16:39:25 +0100
Subject: [PATCH 1/2] proxy: Do not try to store same alias twice
LDB does not store attributes if they have the
same name and value and errors out instead.
Fixes:
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="https://fedorahosted.org/sssd/ticket/2461">https://fedorahosted.org/sssd/ticket/2461</a>
---
src/providers/proxy/proxy_id.c | 68 ++++++++++++++++++++++++++----------------
1 file changed, 42 insertions(+), 26 deletions(-)
diff --git a/src/providers/proxy/proxy_id.c b/src/providers/proxy/proxy_id.c
index d867ec4..bb79202 100644
--- a/src/providers/proxy/proxy_id.c
+++ b/src/providers/proxy/proxy_id.c
@@ -222,6 +222,7 @@ static int save_user(struct sss_domain_info *domain,
struct sysdb_attrs *attrs = NULL;
errno_t ret;
const char *cased_alias;
+ const char *lc_pw_name = NULL;
if (pwd->pw_shell && pwd->pw_shell[0] != '\0') {
shell = pwd->pw_shell;
@@ -239,31 +240,40 @@ static int save_user(struct sss_domain_info *domain,
attrs = sysdb_new_attrs(NULL);
if (!attrs) {
DEBUG(SSSDBG_CRIT_FAILURE, "Allocation error ?!\n");
- return ENOMEM;
+ ret = ENOMEM;
+ goto done;
}
}
if (lowercase) {
- ret = sysdb_attrs_add_lc_name_alias(attrs, pwd->pw_name);
+ lc_pw_name = sss_tc_utf8_str_tolower(attrs, pwd->pw_name);
+ if (lc_pw_name == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, "Cannot convert name to lowercase.\n");
+ ret = ENOMEM;
+ goto done;
+ }
+
+ ret = sysdb_attrs_add_string(attrs, SYSDB_NAME_ALIAS, lc_pw_name);
if (ret) {
DEBUG(SSSDBG_OP_FAILURE, "Could not add name alias\n");
- talloc_zfree(attrs);
- return ret;
+ goto done;
}
+
}
if (alias) {
cased_alias = sss_get_cased_name(attrs, alias, !lowercase);
if (!cased_alias) {
- talloc_zfree(attrs);
- return ENOMEM;</pre>
</div>
</blockquote>
ret = ENOMEM;<br>
<blockquote cite="mid:545BC274.8050607@redhat.com" type="cite">
<div class="moz-text-plain" wrap="true" graphical-quote="true"
style="font-family: -moz-fixed; font-size: 12px;"
lang="x-western">
<pre wrap="">
+ goto done;
}
- ret = sysdb_attrs_add_string(attrs, SYSDB_NAME_ALIAS, cased_alias);
- if (ret) {
- DEBUG(SSSDBG_OP_FAILURE, "Could not add name alias\n");
- talloc_zfree(attrs);
- return ret;
+ /* Add the alias only if it differs from lowercased pw_name */
+ if (lc_pw_name == NULL || strcmp(cased_alias, lc_pw_name) != 0) {
+ ret = sysdb_attrs_add_string(attrs, SYSDB_NAME_ALIAS, cased_alias);
+ if (ret) {
+ DEBUG(SSSDBG_OP_FAILURE, "Could not add name alias\n");
+ goto done;
+ }
}
}
@@ -280,12 +290,13 @@ static int save_user(struct sss_domain_info *domain,
NULL,
cache_timeout,
0);
- talloc_zfree(attrs);
if (ret) {
DEBUG(SSSDBG_OP_FAILURE, "Could not add user to cache\n");
- return ret;
+ goto done;
}
+done:
+ talloc_zfree(attrs);
return EOK;</pre>
</div>
</blockquote>
Did you mean "return ret"?<br>
<blockquote cite="mid:545BC274.8050607@redhat.com" type="cite">
<div class="moz-text-plain" wrap="true" graphical-quote="true"
style="font-family: -moz-fixed; font-size: 12px;"
lang="x-western">
<pre wrap="">
}
</pre>
</div>
</blockquote>
</body>
</html>