[SSSD] [PATCH] set ipa_hostname if not given in config file

Sumit Bose sbose at redhat.com
Mon Nov 2 13:47:55 UTC 2009


Hi,

I find this patch useful. If IPA_HOSTNAME is found to be NULL later on
in the code you can simply assume an error and don't have to call
gethostname again and again.

bye,
Sumit
-------------- next part --------------
>From d87db5a63e0737cc5da955c6679a410350939419 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Wed, 28 Oct 2009 13:09:51 +0100
Subject: [PATCH] set ipa_hostname if not given in config file

---
 server/providers/ipa/ipa_common.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/server/providers/ipa/ipa_common.c b/server/providers/ipa/ipa_common.c
index d324970..3f4d25d 100644
--- a/server/providers/ipa/ipa_common.c
+++ b/server/providers/ipa/ipa_common.c
@@ -144,7 +144,9 @@ int ipa_get_options(TALLOC_CTX *memctx,
     struct ipa_options *opts;
     char *domain;
     char *server;
+    char *ipa_hostname;
     int ret;
+    char hostname[HOST_NAME_MAX + 1];
 
     opts = talloc_zero(memctx, struct ipa_options);
     if (!opts) return ENOMEM;
@@ -173,6 +175,24 @@ int ipa_get_options(TALLOC_CTX *memctx,
         goto done;
     }
 
+    ipa_hostname = dp_opt_get_string(opts->basic, IPA_HOSTNAME);
+    if (ipa_hostname == NULL) {
+        ret = gethostname(hostname, HOST_NAME_MAX);
+        if (ret != EOK) {
+            DEBUG(1, ("gethostname failed [%d][%s].\n", errno,
+                      strerror(errno)));
+            ret = errno;
+            goto done;
+        }
+        hostname[HOST_NAME_MAX] = '\0';
+        DEBUG(9, ("Setting ipa_hostname to [%s].\n", hostname));
+        ret = dp_opt_set_string(opts->basic, IPA_HOSTNAME, hostname);
+        if (ret != EOK) {
+            goto done;
+        }
+    }
+
+
     ret = EOK;
     *_opts = opts;
 
-- 
1.6.2.5



More information about the sssd-devel mailing list