|
|
464b57 |
From 9fe64023e32ab9e3fbbfeefc2168a49b748a1846 Mon Sep 17 00:00:00 2001
|
|
|
464b57 |
From: Samuel Cabrero <scabrero@suse.de>
|
|
|
464b57 |
Date: Fri, 19 Jul 2019 12:24:56 +0200
|
|
|
464b57 |
Subject: [PATCH 21/21] MONITOR: Resolve symlinks setting the inotify watchers
|
|
|
464b57 |
MIME-Version: 1.0
|
|
|
464b57 |
Content-Type: text/plain; charset=UTF-8
|
|
|
464b57 |
Content-Transfer-Encoding: 8bit
|
|
|
464b57 |
|
|
|
464b57 |
If resolv.conf is a symlink and sssd starts before getting an address
|
|
|
464b57 |
from dhcp the data provider will remain forever offline, as the watched
|
|
|
464b57 |
parent directory is the directory containing the symlink.
|
|
|
464b57 |
|
|
|
464b57 |
Signed-off-by: Samuel Cabrero <scabrero@suse.de>
|
|
|
464b57 |
|
|
|
464b57 |
Reviewed-by: Sumit Bose <sbose@redhat.com>
|
|
|
464b57 |
(cherry picked from commit d57c67e4efc64a16b874b46eb9670fdc9c73a39f)
|
|
|
464b57 |
|
|
|
464b57 |
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
|
|
|
464b57 |
---
|
|
|
464b57 |
src/util/inotify.c | 55 +++++++++++++++++++++++++++++++++++++++++++---
|
|
|
464b57 |
1 file changed, 52 insertions(+), 3 deletions(-)
|
|
|
464b57 |
|
|
|
464b57 |
diff --git a/src/util/inotify.c b/src/util/inotify.c
|
|
|
464b57 |
index 2e2dc1a6e..ffc15ad4d 100644
|
|
|
464b57 |
--- a/src/util/inotify.c
|
|
|
464b57 |
+++ b/src/util/inotify.c
|
|
|
464b57 |
@@ -381,13 +381,62 @@ static int watch_ctx_destructor(void *memptr)
|
|
|
464b57 |
return 0;
|
|
|
464b57 |
}
|
|
|
464b57 |
|
|
|
464b57 |
+static errno_t resolve_filename(struct snotify_ctx *snctx,
|
|
|
464b57 |
+ const char *filename,
|
|
|
464b57 |
+ char *resolved,
|
|
|
464b57 |
+ size_t resolved_size)
|
|
|
464b57 |
+{
|
|
|
464b57 |
+ /* NOTE: The code below relies in the GNU extensions for realpath,
|
|
|
464b57 |
+ * which will store in 'resolved' the prefix of 'filename' that does
|
|
|
464b57 |
+ * not exists if realpath call fails and errno is set to ENOENT */
|
|
|
464b57 |
+ if (realpath(filename, resolved) == NULL) {
|
|
|
464b57 |
+ char fcopy[PATH_MAX + 1];
|
|
|
464b57 |
+ char *p;
|
|
|
464b57 |
+ struct stat st;
|
|
|
464b57 |
+
|
|
|
464b57 |
+ if (errno != ENOENT) {
|
|
|
464b57 |
+ return errno;
|
|
|
464b57 |
+ }
|
|
|
464b57 |
+
|
|
|
464b57 |
+ /* Check if the unique missing component is the basename. The
|
|
|
464b57 |
+ * dirname must exist to be notified watching the parent dir. */
|
|
|
464b57 |
+ strncpy(fcopy, filename, sizeof(fcopy) - 1);
|
|
|
464b57 |
+ fcopy[PATH_MAX] = '\0';
|
|
|
464b57 |
+
|
|
|
464b57 |
+ p = dirname(fcopy);
|
|
|
464b57 |
+ if (p == NULL) {
|
|
|
464b57 |
+ return EIO;
|
|
|
464b57 |
+ }
|
|
|
464b57 |
+
|
|
|
464b57 |
+ if (stat(p, &st) == -1) {
|
|
|
464b57 |
+ return errno;
|
|
|
464b57 |
+ }
|
|
|
464b57 |
+
|
|
|
464b57 |
+ /* The basedir exist, check the caller requested to watch it.
|
|
|
464b57 |
+ * Otherwise return error as never will be notified. */
|
|
|
464b57 |
+
|
|
|
464b57 |
+ if ((snctx->snotify_flags & SNOTIFY_WATCH_DIR) == 0) {
|
|
|
464b57 |
+ return ENOENT;
|
|
|
464b57 |
+ }
|
|
|
464b57 |
+ }
|
|
|
464b57 |
+
|
|
|
464b57 |
+ return EOK;
|
|
|
464b57 |
+}
|
|
|
464b57 |
+
|
|
|
464b57 |
static errno_t copy_filenames(struct snotify_ctx *snctx,
|
|
|
464b57 |
const char *filename)
|
|
|
464b57 |
{
|
|
|
464b57 |
char *p;
|
|
|
464b57 |
+ char resolved[PATH_MAX + 1];
|
|
|
464b57 |
char fcopy[PATH_MAX + 1];
|
|
|
464b57 |
+ errno_t ret;
|
|
|
464b57 |
+
|
|
|
464b57 |
+ ret = resolve_filename(snctx, filename, resolved, sizeof(resolved));
|
|
|
464b57 |
+ if (ret != EOK) {
|
|
|
464b57 |
+ return ret;
|
|
|
464b57 |
+ }
|
|
|
464b57 |
|
|
|
464b57 |
- strncpy(fcopy, filename, sizeof(fcopy) - 1);
|
|
|
464b57 |
+ strncpy(fcopy, resolved, sizeof(fcopy) - 1);
|
|
|
464b57 |
fcopy[PATH_MAX] = '\0';
|
|
|
464b57 |
|
|
|
464b57 |
p = dirname(fcopy);
|
|
|
464b57 |
@@ -400,7 +449,7 @@ static errno_t copy_filenames(struct snotify_ctx *snctx,
|
|
|
464b57 |
return ENOMEM;
|
|
|
464b57 |
}
|
|
|
464b57 |
|
|
|
464b57 |
- strncpy(fcopy, filename, sizeof(fcopy) - 1);
|
|
|
464b57 |
+ strncpy(fcopy, resolved, sizeof(fcopy) - 1);
|
|
|
464b57 |
fcopy[PATH_MAX] = '\0';
|
|
|
464b57 |
|
|
|
464b57 |
p = basename(fcopy);
|
|
|
464b57 |
@@ -413,7 +462,7 @@ static errno_t copy_filenames(struct snotify_ctx *snctx,
|
|
|
464b57 |
return ENOMEM;
|
|
|
464b57 |
}
|
|
|
464b57 |
|
|
|
464b57 |
- snctx->filename = talloc_strdup(snctx, filename);
|
|
|
464b57 |
+ snctx->filename = talloc_strdup(snctx, resolved);
|
|
|
464b57 |
if (snctx->filename == NULL) {
|
|
|
464b57 |
return ENOMEM;
|
|
|
464b57 |
}
|
|
|
464b57 |
--
|
|
|
464b57 |
2.21.1
|
|
|
464b57 |
|