]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
checkpassword: Allow setting uid/gid in userdb_uid and userdb_gid environment.
authorTimo Sirainen <tss@iki.fi>
Wed, 8 Oct 2008 19:44:20 +0000 (22:44 +0300)
committerTimo Sirainen <tss@iki.fi>
Wed, 8 Oct 2008 19:44:20 +0000 (22:44 +0300)
--HG--
branch : HEAD

src/auth/checkpassword-reply.c

index f7b55205defc57861a1b6c0568d73b6c1393f1d7..c27ebdf3b36be23751e1d12b0e7c7d703e521176 100644 (file)
@@ -11,7 +11,8 @@ int main(void)
 {
        string_t *str;
        const char *user, *home;
-       const char *extra_env, *value, *const *tmp;
+       const char *extra_env, *key, *value, *const *tmp;
+       bool uid_found = FALSE, gid_found = FALSE;
 
        lib_init();
        str = t_str_new(1024);
@@ -34,19 +35,24 @@ int main(void)
                str_printfa(str, "userdb_home=%s\t", home);
        }
 
-       str_printfa(str, "userdb_uid=%s\tuserdb_gid=%s\t",
-                   dec2str(getuid()), dec2str(getgid()));
-
        extra_env = getenv("EXTRA");
        if (extra_env != NULL) {
                for (tmp = t_strsplit(extra_env, " "); *tmp != NULL; tmp++) {
                        value = getenv(*tmp);
                        if (value != NULL) {
-                               str_printfa(str, "%s=%s\t",
-                                           t_str_lcase(*tmp), value);
+                               key = t_str_lcase(*tmp);
+                               if (strcmp(key, "userdb_uid") == 0)
+                                       uid_found = TRUE;
+                               else if (strcmp(key, "userdb_gid") == 0)
+                                       gid_found = TRUE;
+                               str_printfa(str, "%s=%s\t", key, value);
                        }
                }
        }
+       if (!uid_found)
+               str_printfa(str, "userdb_uid=%s\t",  dec2str(getuid()));
+       if (!gid_found)
+               str_printfa(str, "userdb_gid=%s\t",  dec2str(getgid()));
 
        if (write_full(4, str_data(str), str_len(str)) < 0) {
                i_error("checkpassword: write_full() failed: %m");