script-login.c revision 02c335c23bf5fa225a467c19f2c063fb0dc7b8c3
5f5870385cff47efd2f58e7892f251cf13761528Timo Sirainen/* Copyright (c) 2009-2016 Dovecot authors, see the included COPYING file */
0f39a57760d93cddbce3ca43096d78e0fe2f42fdTimo Sirainenstatic const char **exec_args;
3313a51ef9b245248d672c20f930c52a577a42f7Timo Sirainenstatic void client_connected(struct master_service_connection *conn)
0f39a57760d93cddbce3ca43096d78e0fe2f42fdTimo Sirainen const char **args, *key, *value, *error, *version_line, *data_line;
3313a51ef9b245248d672c20f930c52a577a42f7Timo Sirainen unsigned int i, socket_count;
58bc77731bb25e900498a28409337e747f622722Timo Sirainen ret = fd_read(conn->fd, buf, sizeof(buf), &fd);
c2f24d55319fad0b6c03425f402f0cb0cb1a318bTimo Sirainen while (ret > 0) {
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen version_line = t_strdup_until(version_line, data_line++);
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen !version_string_verify(version_line, "script-login",
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen i_fatal("Client not compatible with this binary "
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen "(connecting to wrong socket?)");
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen /* put everything to environment */
e9371f899a3d4207a0ffd3923ea5ec7250cf5e75Timo Sirainen input.module = "mail"; /* need to get mail_uid, mail_gid */
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen (void)net_addr2ip(args[i++], &input.local_ip);
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen (void)net_addr2ip(args[i++], &input.remote_ip);
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen env_put(t_strconcat("LOCAL_IP=", net_ip2addr(&input.local_ip), NULL));
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen env_put(t_strconcat("IP=", net_ip2addr(&input.remote_ip), NULL));
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen env_put(t_strconcat("USER=", input.username, NULL));
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen args[i] = str_tabunescape(t_strdup_noconst(args[i]));
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen key = t_str_ucase(t_strdup_until(args[i], value));
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen env_put(t_strconcat(ENV_USERDB_KEYS"=", str_c(keys), NULL));
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen t_strdup_printf("script-login(%s): ", input.username));
e9371f899a3d4207a0ffd3923ea5ec7250cf5e75Timo Sirainen service_ctx = mail_storage_service_init(master_service, NULL, flags);
91e2dc36b9c0c91f0af716be81dc2aa6cbbed6c2Timo Sirainen if (mail_storage_service_lookup(service_ctx, &input, &user, &error) <= 0)
2e29e4797a48d78d669821722bdb54fd0a1d3b94Timo Sirainen mail_storage_service_restrict_setenv(service_ctx, user);
for (i = 0; i < socket_count; i++) {
static void script_execute_finish(void)
if (ret < 0)
return FATAL_DEFAULT;
if (!drop_to_userdb_privileges &&
for (i = 0; i < argc; i++)