URL: https://github.com/SSSD/sssd/pull/5750
Author: pbrezina
 Title: #5750: fix compilation warnings
Action: synchronized

To pull the PR as Git branch:
git remote add ghsssd https://github.com/SSSD/sssd
git fetch ghsssd pull/5750/head:pr5750
git checkout pr5750
From e284006aebdc8f0163b28969a958b9557ed2808a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrez...@redhat.com>
Date: Tue, 17 Aug 2021 12:26:31 +0200
Subject: [PATCH 1/2] remove deprecated talloc_autofree_context()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

```
/home/pbrezina/workspace/sssd/src/util/server.c: In function ‘server_setup’:
/home/pbrezina/workspace/sssd/src/util/server.c:545:5: error: ‘talloc_autofree_context’ is deprecated [-Werror=deprecated-declarations]
  545 |     event_ctx = tevent_context_init(talloc_autofree_context());
      |     ^~~~~~~~~
In file included from /usr/include/ldb.h:50,
                 from /home/pbrezina/workspace/sssd/src/util/server.c:33:
/usr/include/talloc.h:1071:16: note: declared here
 1071 | _PUBLIC_ void *talloc_autofree_context(void) _DEPRECATED_;
      |                ^~~~~~~~~~~~~~~~~~~~~~~
```
---
 src/util/server.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/util/server.c b/src/util/server.c
index 4fe29f96b8..e3133a61dd 100644
--- a/src/util/server.c
+++ b/src/util/server.c
@@ -38,6 +38,13 @@
 #include <sys/prctl.h>
 #endif
 
+static TALLOC_CTX *autofree_ctx;
+
+static void server_atexit(void)
+{
+    talloc_zfree(autofree_ctx);
+}
+
 /*******************************************************************
  Close the low 3 FDs and open dev/null in their place.
 ********************************************************************/
@@ -264,6 +271,7 @@ static void default_quit(struct tevent_context *ev,
 {
     struct main_context *ctx = talloc_get_type(private_data, struct main_context);
     talloc_free(ctx);
+
     orderly_shutdown(0);
 }
 
@@ -464,7 +472,14 @@ int server_setup(const char *name, int flags,
     char *pidfile_name;
     int cfg_debug_level = SSSDBG_INVALID;
 
-    debug_prg_name = strdup(name);
+    autofree_ctx = talloc_named_const(NULL, 0, "autofree_context");
+    if (autofree_ctx == NULL) {
+        return ENOMEM;
+    }
+
+    atexit(server_atexit);
+
+    debug_prg_name = talloc_strdup(autofree_ctx, name);
     if (!debug_prg_name) {
         return ENOMEM;
     }
@@ -542,7 +557,7 @@ int server_setup(const char *name, int flags,
 
     /* the event context is the top level structure.
      * Everything else should hang off that */
-    event_ctx = tevent_context_init(talloc_autofree_context());
+    event_ctx = tevent_context_init(autofree_ctx);
     if (event_ctx == NULL) {
         DEBUG(SSSDBG_FATAL_FAILURE,
               "The event context initialization failed\n");

From 922cfbf4bf8a9d3aa9581bf034b044f2aa035ea7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrez...@redhat.com>
Date: Tue, 17 Aug 2021 12:24:39 +0200
Subject: [PATCH 2/2] fix warnings around sss_getenv()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Introduced in
- 44525a9995c775ac284a6203d0e505dc4bf0d459
- c1dd121142fb22648793a38e45257b348d658460

```
/home/pbrezina/workspace/sssd/src/db/sysdb_init.c: In function ‘sysdb_ldb_connect’:
/home/pbrezina/workspace/sssd/src/db/sysdb_init.c:82:49: error: passing argument 3 of ‘sss_getenv’ from incompatible pointer type [-Werror=incompatible-pointer-types]
   82 |     ret = sss_getenv(tmp_ctx, LDB_MODULES_PATH, &mod_path);
      |                                                 ^~~~~~~~~
      |                                                 |
      |                                                 const char **
In file included from /home/pbrezina/workspace/sssd/src/db/sysdb_init.c:23:
/home/pbrezina/workspace/sssd/src/util/util.h:806:75: note: expected ‘char **’ but argument is of type ‘const char **’
  806 | errno_t sss_getenv(TALLOC_CTX *mem_ctx, const char *variable_name, char **_value);

/home/pbrezina/workspace/sssd/src/providers/files/files_init.c: In function ‘files_init_file_sources’:
/home/pbrezina/workspace/sssd/src/providers/files/files_init.c:61:26: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
   61 |         dfl_passwd_files = DEFAULT_PASSWD_FILE;
      |                          ^
/home/pbrezina/workspace/sssd/src/providers/files/files_init.c:77:25: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
   77 |         env_group_files = DEFAULT_GROUP_FILE;
      |                         ^
```
---
 src/db/sysdb_init.c              |  7 ++++---
 src/providers/files/files_init.c | 14 ++++++--------
 src/util/util.c                  | 11 +++++++----
 src/util/util.h                  |  8 +++++++-
 4 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/src/db/sysdb_init.c b/src/db/sysdb_init.c
index e84d76129d..f19e776318 100644
--- a/src/db/sysdb_init.c
+++ b/src/db/sysdb_init.c
@@ -54,7 +54,7 @@ errno_t sysdb_ldb_connect(TALLOC_CTX *mem_ctx,
     TALLOC_CTX *tmp_ctx = NULL;
     errno_t ret;
     struct ldb_context *ldb;
-    const char *mod_path = NULL;
+    char *mod_path = NULL;
 
     tmp_ctx = talloc_new(NULL);
     if (tmp_ctx == NULL) {
@@ -79,14 +79,15 @@ errno_t sysdb_ldb_connect(TALLOC_CTX *mem_ctx,
         goto done;
     }
 
-    ret = sss_getenv(tmp_ctx, LDB_MODULES_PATH, &mod_path);
+    ret = sss_getenv(tmp_ctx, LDB_MODULES_PATH, NULL, &mod_path);
     if (ret == EOK) {
         DEBUG(SSSDBG_TRACE_ALL, "Setting ldb module path to [%s].\n", mod_path);
         ldb_set_modules_dir(ldb, mod_path);
     } else if (ret == ENOENT) {
         DEBUG(SSSDBG_TRACE_ALL, "No ldb module path set in env\n");
     } else {
-        DEBUG(SSSDBG_TRACE_ALL, "sss_getenv() failed\n");
+        DEBUG(SSSDBG_CRIT_FAILURE, "sss_getenv() failed [%d]: %s\n",
+              ret, sss_strerror(ret));
         goto done;
     }
 
diff --git a/src/providers/files/files_init.c b/src/providers/files/files_init.c
index f4a522b318..54f3600a2f 100644
--- a/src/providers/files/files_init.c
+++ b/src/providers/files/files_init.c
@@ -51,15 +51,14 @@ static errno_t files_init_file_sources(TALLOC_CTX *mem_ctx,
         goto done;
     }
 
-    ret = sss_getenv(tmp_ctx, "SSS_FILES_PASSWD", &dfl_passwd_files);
+    ret = sss_getenv(tmp_ctx, "SSS_FILES_PASSWD", DEFAULT_PASSWD_FILE,
+                     &dfl_passwd_files);
     if (ret == EOK) {
         sss_log(SSS_LOG_ALERT,
                 "Defaulting to %s for the passwd file, "
                 "this should only be used for testing!\n",
                 dfl_passwd_files);
-    } else if (ret == ENOENT) {
-        dfl_passwd_files = DEFAULT_PASSWD_FILE;
-    } else {
+    } else if (ret != ENOENT) {
         sss_log(SSS_LOG_ALERT, "sss_getenv() failed");
         goto done;
     }
@@ -67,15 +66,14 @@ static errno_t files_init_file_sources(TALLOC_CTX *mem_ctx,
           "Using passwd file: [%s].\n",
           dfl_passwd_files);
 
-    ret = sss_getenv(tmp_ctx, "SSS_FILES_GROUP", &env_group_files);
+    ret = sss_getenv(tmp_ctx, "SSS_FILES_GROUP", DEFAULT_GROUP_FILE,
+                     &env_group_files);
     if (ret == EOK) {
         sss_log(SSS_LOG_ALERT,
                 "Defaulting to %s for the group file, "
                 "this should only be used for testing!\n",
                 env_group_files);
-    } else if (ret == ENOENT) {
-        env_group_files = DEFAULT_GROUP_FILE;
-    } else {
+    } else if (ret != ENOENT) {
         sss_log(SSS_LOG_ALERT, "sss_getenv() failed");
         goto done;
     }
diff --git a/src/util/util.c b/src/util/util.c
index ea1ca53e03..7e29237738 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -1067,17 +1067,20 @@ bool is_valid_domain_name(const char *domain)
     return true;
 }
 
-errno_t sss_getenv(TALLOC_CTX *mem_ctx, const char *variable_name, char **_value)
+errno_t sss_getenv(TALLOC_CTX *mem_ctx,
+                   const char *variable_name,
+                   const char *default_value,
+                   char **_value)
 {
     char *value = getenv(variable_name);
-    if (value == NULL) {
+    if (value == NULL && default_value == NULL) {
         return ENOENT;
     }
 
-    *_value = talloc_strdup(mem_ctx, value);
+    *_value = talloc_strdup(mem_ctx, value != NULL ? value : default_value);
     if (*_value == NULL) {
         return ENOMEM;
     }
 
-    return EOK;
+    return value != NULL ? EOK : ENOENT;
 }
diff --git a/src/util/util.h b/src/util/util.h
index d8f3e5769a..c5ecba72fa 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -803,6 +803,12 @@ errno_t create_preauth_indicator(void);
 #define N_ELEMENTS(arr) (sizeof(arr) / sizeof(arr[0]))
 #endif
 
-errno_t sss_getenv(TALLOC_CTX *mem_ctx, const char *variable_name, char **_value);
+/* If variable is not set, it stores a copy of default_value (if not NULL)
+ * in _value but returns ENOENT so the information is propagated to the caller.
+ */
+errno_t sss_getenv(TALLOC_CTX *mem_ctx,
+                   const char *variable_name,
+                   const char *default_value,
+                   char **_value);
 
 #endif /* __SSSD_UTIL_H__ */
_______________________________________________
sssd-devel mailing list -- sssd-devel@lists.fedorahosted.org
To unsubscribe send an email to sssd-devel-le...@lists.fedorahosted.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedorahosted.org/archives/list/sssd-devel@lists.fedorahosted.org
Do not reply to spam on the list, report it: 
https://pagure.io/fedora-infrastructure

Reply via email to