handle later iniparser version assigning a zero length string value for 'key='
authorNoel Power <noel.power@suse.com>
Tue, 5 Nov 2013 17:24:46 +0000 (17:24 +0000)
committerDavid Disseldorp <ddiss@samba.org>
Wed, 20 Nov 2013 15:12:13 +0000 (16:12 +0100)
older iniparser versions ( like that used in upstream samba ) ignore 'key='
entries, the key is not entered into the dictionary at all. Later
versions of iniparse specifically handle the following special cases

* key=
* key=;
* key=#

by assigning a value of "" ( a zero length string ) to the key
in the dictionary.

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: David Disseldorp <ddiss@samba.org>
Autobuild-User(master): David Disseldorp <ddiss@samba.org>
Autobuild-Date(master): Wed Nov 20 16:12:13 CET 2013 on sn-devel-104

nsswitch/pam_winbind.c

index 9f855564bcca4af13ea8872e999b38eb2a47b4b8..2e37662959c37ad50d7ee015de756ce04cf696d4 100644 (file)
@@ -330,6 +330,21 @@ static void _pam_log_state_datum(struct pwb_context *ctx,
 #define _PAM_LOG_STATE_ITEM_PASSWORD(ctx, item_type) \
        _pam_log_state_datum(ctx, item_type, #item_type, \
                             _LOG_PASSWORD_AS_STRING)
+/*
+ * wrapper to preserve old behaviour of iniparser which ignored
+ * key values that had no value assigned like
+ *    key =
+ * for a key like above newer iniparser will return a zero-length
+ * string, previously iniparser would return NULL
+ */
+static char *iniparser_getstring_nonempty(dictionary *d, char *key, char *def)
+{
+       char *ret = iniparser_getstring(d, key, def);
+       if (ret && strlen(ret) == 0) {
+               ret = NULL;
+       }
+       return ret;
+}
 
 static void _pam_log_state(struct pwb_context *ctx)
 {
@@ -418,13 +433,13 @@ static int _pam_parse(const pam_handle_t *pamh,
                ctrl |= WINBIND_SILENT;
        }
 
-       if (iniparser_getstring(d, discard_const_p(char, "global:krb5_ccache_type"), NULL) != NULL) {
+       if (iniparser_getstring_nonempty(d, discard_const_p(char, "global:krb5_ccache_type"), NULL) != NULL) {
                ctrl |= WINBIND_KRB5_CCACHE_TYPE;
        }
 
-       if ((iniparser_getstring(d, discard_const_p(char, "global:require-membership-of"), NULL)
+       if ((iniparser_getstring_nonempty(d, discard_const_p(char, "global:require-membership-of"), NULL)
             != NULL) ||
-           (iniparser_getstring(d, discard_const_p(char, "global:require_membership_of"), NULL)
+           (iniparser_getstring_nonempty(d, discard_const_p(char, "global:require_membership_of"), NULL)
             != NULL)) {
                ctrl |= WINBIND_REQUIRED_MEMBERSHIP;
        }
@@ -2262,7 +2277,7 @@ static const char *get_conf_item_string(struct pwb_context *ctx,
                        goto out;
                }
 
-               parm_opt = iniparser_getstring(ctx->dict, key, NULL);
+               parm_opt = iniparser_getstring_nonempty(ctx->dict, key, NULL);
                TALLOC_FREE(key);
 
                _pam_log_debug(ctx, LOG_INFO, "CONFIG file: %s '%s'\n",