51bd1a
commit 6207330c2705fdb5f02de13b99a0d994f7c4f14a
51bd1a
Author: Zheng Gu <zhenggu@cisco.com>
51bd1a
Date:   Fri Nov 22 22:34:16 2019 +0800
51bd1a
51bd1a
    fix bug where sasl will load config the wrong path
51bd1a
    
51bd1a
    /etc/sasl2/memcached.conf/memcached.conf instead of
51bd1a
    /etc/sasl2/memcached.conf
51bd1a
51bd1a
diff --git a/sasl_defs.c b/sasl_defs.c
51bd1a
index c60d1bf..370f947 100644
51bd1a
--- a/sasl_defs.c
51bd1a
+++ b/sasl_defs.c
51bd1a
@@ -16,6 +16,23 @@ const char * const locations[] = {
51bd1a
     "/etc/sasl2/memcached.conf",
51bd1a
     NULL
51bd1a
 };
51bd1a
+
51bd1a
+/* If the element of locations is file, locations_dir_path stores the
51bd1a
+ * directory path of these elements */
51bd1a
+const char *const locations_dir_path[] = {
51bd1a
+    "/etc/sasl",
51bd1a
+    "/etc/sasl2",
51bd1a
+    NULL
51bd1a
+};
51bd1a
+
51bd1a
+/* If the element of locations is directory, locations_file_path stores
51bd1a
+ * the actual configue file which used by sasl, when GETCONFPATH is
51bd1a
+ * enabled */
51bd1a
+const char *const locations_file_path[] = {
51bd1a
+    "/etc/sasl/memcached.conf/memcached.conf",
51bd1a
+    "/etc/sasl2/memcached.conf/memcached.conf",
51bd1a
+    NULL
51bd1a
+};
51bd1a
 #endif
51bd1a
 
51bd1a
 #ifndef HAVE_SASL_CALLBACK_FT
51bd1a
@@ -88,12 +105,24 @@ static int sasl_getconf(void *context, const char **path)
51bd1a
     *path = getenv("SASL_CONF_PATH");
51bd1a
 
51bd1a
     if (*path == NULL) {
51bd1a
+#if defined(HAVE_SASL_CB_GETCONF)
51bd1a
         for (int i = 0; locations[i] != NULL; ++i) {
51bd1a
             if (access(locations[i], F_OK) == 0) {
51bd1a
                 *path = locations[i];
51bd1a
                 break;
51bd1a
             }
51bd1a
         }
51bd1a
+#elif defined(HAVE_SASL_CB_GETCONFPATH)
51bd1a
+        for (int i = 0; locations[i] != NULL; ++i) {
51bd1a
+            if (access(locations_file_path[i], F_OK) == 0) {
51bd1a
+                *path = locations[i];
51bd1a
+                break;
51bd1a
+            } else if (access(locations[i], F_OK) == 0) {
51bd1a
+                *path = locations_dir_path[i];
51bd1a
+                break;
51bd1a
+            }
51bd1a
+        }
51bd1a
+#endif
51bd1a
     }
51bd1a
 
51bd1a
     if (settings.verbose) {