[SSSD] [PATCH] Improve offline detection in locator plugin

Sumit Bose sbose at redhat.com
Tue May 11 12:23:40 UTC 2010


Hi,

with this patch we avoid to send an illegal address back to libkrb5 and
return KRB5_KDC_UNREACH instead.

bye,
Sumit
-------------- next part --------------
From eb2aac56ac4ef14c90521a27fb58c8b292f7eb0e Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Tue, 11 May 2010 14:17:47 +0200
Subject: [PATCH] Improve offline detection in locator plugin

Instead of using 255.255.255.255 in the kdc/kpasswdinfo files to
indicate that the backend if offline at startup we use OFFLINE and
KRB5_KDC_UNREACH as return value.
---
 src/krb5_plugin/sssd_krb5_locator_plugin.c |   12 ++++++++++++
 src/providers/krb5/krb5_common.c           |    4 +---
 src/providers/krb5/krb5_common.h           |    2 ++
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/krb5_plugin/sssd_krb5_locator_plugin.c b/src/krb5_plugin/sssd_krb5_locator_plugin.c
index 153145b..d93819e 100644
--- a/src/krb5_plugin/sssd_krb5_locator_plugin.c
+++ b/src/krb5_plugin/sssd_krb5_locator_plugin.c
@@ -84,6 +84,7 @@ static int get_krb5info(const char *realm, struct sssd_ctx *ctx,
     int ret;
     char *krb5info_name = NULL;
     size_t len;
+    size_t size;
     uint8_t buf[BUFSIZE + 1];
     uint8_t *p;
     int fd = -1;
@@ -130,6 +131,7 @@ static int get_krb5info(const char *realm, struct sssd_ctx *ctx,
 
     len = BUFSIZE;
     p = buf;
+    size = 0;
     memset(buf, 0, BUFSIZE+1);
     while (len != 0 && (ret = read(fd, p, len)) != 0) {
         if (ret == -1) {
@@ -141,6 +143,7 @@ static int get_krb5info(const char *realm, struct sssd_ctx *ctx,
 
         len -= ret;
         p += ret;
+        size += ret;
     }
     close(fd);
 
@@ -150,6 +153,12 @@ static int get_krb5info(const char *realm, struct sssd_ctx *ctx,
     }
     PLUGIN_DEBUG(("Found [%s] in [%s].\n", buf, krb5info_name));
 
+    if (strlen(OFFLINE_MARKER) == size && memcmp(buf, OFFLINE_MARKER, size) == 0) {
+        PLUGIN_DEBUG(("System is offline.\n"));
+        ret = KRB5_KDC_UNREACH;
+        goto done;
+    }
+
     port_str = strrchr((char *) buf, ':');
     if (port_str == NULL) {
         port = 0;
@@ -286,6 +295,9 @@ krb5_error_code sssd_krb5_locator_lookup(void *private_data,
         ret = get_krb5info(realm, ctx, locate_service_kdc);
         if (ret != EOK) {
             PLUGIN_DEBUG(("get_krb5info failed.\n"));
+            if (ret == KRB5_KDC_UNREACH) {
+                return ret;
+            }
             return KRB5_PLUGIN_NO_HANDLE;
         }
 
diff --git a/src/providers/krb5/krb5_common.c b/src/providers/krb5/krb5_common.c
index da7627c..78c89b3 100644
--- a/src/providers/krb5/krb5_common.c
+++ b/src/providers/krb5/krb5_common.c
@@ -31,8 +31,6 @@
 #include "providers/dp_backend.h"
 #include "providers/krb5/krb5_common.h"
 
-#define DUMMY_ADDRESS "255.255.255.255"
-
 struct dp_option default_krb5_opts[] = {
     { "krb5_kdcip", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "krb5_realm", DP_OPT_STRING, NULL_STRING, NULL_STRING },
@@ -504,7 +502,7 @@ void krb5_init_resolve_done(struct tevent_req *req)
         if (strcmp(service_name, "IPA") == 0) {
             service_name = SSS_KRB5KDC_FO_SRV;
         }
-        ret = write_krb5info_file(krb5_service->realm, DUMMY_ADDRESS,
+        ret = write_krb5info_file(krb5_service->realm, OFFLINE_MARKER,
                                   service_name);
         if (ret != EOK) {
             DEBUG(2, ("write_krb5info_file failed, "
diff --git a/src/providers/krb5/krb5_common.h b/src/providers/krb5/krb5_common.h
index dd7fdf2..5ebdb2d 100644
--- a/src/providers/krb5/krb5_common.h
+++ b/src/providers/krb5/krb5_common.h
@@ -43,6 +43,8 @@
 #define SSS_KRB5KDC_FO_SRV "KERBEROS"
 #define SSS_KRB5KPASSWD_FO_SRV "KPASSWD"
 
+#define OFFLINE_MARKER "OFFLINE"
+
 enum krb5_opts {
     KRB5_KDC = 0,
     KRB5_REALM,
-- 
1.6.6.1



More information about the sssd-devel mailing list