]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveconf: Add find_next_secret
authorAki Tuomi <aki.tuomi@dovecot.fi>
Tue, 19 Jun 2018 11:26:29 +0000 (14:26 +0300)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Tue, 21 Aug 2018 09:14:01 +0000 (12:14 +0300)
Find start of possible next secret, and return
what the found secret was. Makes next commit easier.

src/config/doveconf.c

index 625a3aaaa94da066c30ba09a31d2f5d18827f3e1..d401625c4478adde78bcf58f9fb64562b4005649 100644 (file)
@@ -47,6 +47,14 @@ struct config_dump_human_context {
 
 static const char *indent_str = "                              !!!!";
 
+static const char *const secrets[] = {
+       "key",
+       "secret",
+       "pass",
+       NULL
+};
+
+
 static void
 config_request_get_strings(const char *key, const char *value,
                           enum config_key_type type, void *context)
@@ -168,18 +176,25 @@ static bool value_need_quote(const char *value)
        return FALSE;
 }
 
+static const char *find_next_secret(const char *input, const char **secret_r)
+{
+       const char *const *secret;
+       for(secret = secrets; *secret != NULL; secret++) {
+               const char *ptr;
+               if ((ptr = strstr(input, *secret)) != NULL) {
+                       *secret_r = *secret;
+                       return ptr;
+               }
+       }
+       return NULL;
+}
+
 static bool
 hide_secrets_from_value(struct ostream *output, const char *key,
                        const char *value)
 {
        bool ret = FALSE, quote = value_need_quote(value);
-       const char *ptr, *optr;
-       const char *const secrets[] = {
-               "key",
-               "secret",
-               "pass",
-               NULL
-       };
+       const char *ptr, *optr, *secret;
        if (*value != '\0' &&
            ((value-key > 8 && strncmp(value-9, "_password", 8) == 0) ||
             (value-key > 7 && strncmp(value-8, "_api_key", 7) == 0) ||
@@ -193,7 +208,7 @@ hide_secrets_from_value(struct ostream *output, const char *key,
           secrets. It should match things like secret_api_key or pass or password,
           etc. but not something like nonsecret. */
        optr = ptr = value;
-       while((ptr = i_strstr_arr(ptr, secrets)) != NULL) {
+       while((ptr = find_next_secret(ptr, &secret)) != NULL) {
                /* we have found something that we hide, and will deal with output
                   here. */
                ret = TRUE;