]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lmtp: Moved client_input_data_write_local() from commands.c to lmtp-local.c.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sun, 17 Sep 2017 09:40:53 +0000 (11:40 +0200)
committerStephan Bosch <stephan.bosch@dovecot.fi>
Thu, 7 Dec 2017 23:08:14 +0000 (00:08 +0100)
src/lmtp/commands.c
src/lmtp/lmtp-local.c
src/lmtp/lmtp-local.h

index 040299c029b8159fb84b71edeb7efb8304c29eea..d4cc9144498a968131109ae540ed9dfc09543487 100644 (file)
@@ -10,7 +10,6 @@
 #include "ostream.h"
 #include "istream-dot.h"
 #include "safe-mkstemp.h"
-#include "restrict-access.h"
 #include "anvil-client.h"
 #include "master-service.h"
 #include "master-service-ssl.h"
@@ -22,7 +21,6 @@
 #include "index/raw/raw-storage.h"
 #include "lda-settings.h"
 #include "lmtp-settings.h"
-#include "mail-autoexpunge.h"
 #include "lmtp-local.h"
 #include "mail-deliver.h"
 #include "message-address.h"
@@ -572,56 +570,6 @@ static struct istream *client_get_input(struct client *client)
        return cinput;
 }
 
-static void
-client_input_data_write_local(struct client *client, struct istream *input)
-{
-       struct mail_deliver_session *session;
-       uid_t old_uid, first_uid;
-
-       if (client_open_raw_mail(client, input) < 0)
-               return;
-
-       session = mail_deliver_session_init();
-       old_uid = geteuid();
-       first_uid = client_deliver_to_rcpts(client, session);
-       mail_deliver_session_deinit(&session);
-
-       if (client->state.first_saved_mail != NULL) {
-               struct mail *mail = client->state.first_saved_mail;
-               struct mailbox_transaction_context *trans = mail->transaction;
-               struct mailbox *box = trans->box;
-               struct mail_user *user = box->storage->user;
-
-               /* just in case these functions are going to write anything,
-                  change uid back to user's own one */
-               if (first_uid != old_uid) {
-                       if (seteuid(0) < 0)
-                               i_fatal("seteuid(0) failed: %m");
-                       if (seteuid(first_uid) < 0)
-                               i_fatal("seteuid() failed: %m");
-               }
-
-               mail_free(&mail);
-               mailbox_transaction_rollback(&trans);
-               mailbox_free(&box);
-               mail_user_autoexpunge(user);
-               mail_user_unref(&user);
-       }
-
-       if (old_uid == 0) {
-               /* switch back to running as root, since that's what we're
-                  practically doing anyway. it's also important in case we
-                  lose e.g. config connection and need to reconnect to it. */
-               if (seteuid(0) < 0)
-                       i_fatal("seteuid(0) failed: %m");
-               /* enable core dumping again. we need to chdir also to
-                  root-owned directory to get core dumps. */
-               restrict_access_allow_coredumps(TRUE);
-               if (chdir(base_dir) < 0)
-                       i_error("chdir(%s) failed: %m", base_dir);
-       }
-}
-
 static void client_input_data_finish(struct client *client)
 {
        client_io_reset(client);
index a8d49be38bdbe4f64981fba141abc7035e83f467..3d8ecd3bbeb949d65ded61fad97760639611b217 100644 (file)
@@ -7,6 +7,7 @@
 #include "hostpid.h"
 #include "var-expand.h"
 #include "ioloop.h"
+#include "restrict-access.h"
 #include "settings-parser.h"
 #include "mail-storage.h"
 #include "mail-storage-service.h"
@@ -331,8 +332,8 @@ static bool client_rcpt_to_is_last(struct client *client)
        return client->state.rcpt_idx >= array_count(&client->state.rcpt_to);
 }
 
-uid_t client_deliver_to_rcpts(struct client *client,
-                             struct mail_deliver_session *session)
+static uid_t client_deliver_to_rcpts(struct client *client,
+                                    struct mail_deliver_session *session)
 {
        uid_t first_uid = (uid_t)-1;
        struct mail *src_mail;
@@ -374,7 +375,7 @@ uid_t client_deliver_to_rcpts(struct client *client,
        return first_uid;
 }
 
-int client_open_raw_mail(struct client *client, struct istream *input)
+static int client_open_raw_mail(struct client *client, struct istream *input)
 {
        static const char *wanted_headers[] = {
                "From", "To", "Message-ID", "Subject", "Return-Path",
@@ -403,3 +404,52 @@ int client_open_raw_mail(struct client *client, struct istream *input)
        mail_set_seq(client->state.raw_mail, 1);
        return 0;
 }
+
+void client_input_data_write_local(struct client *client, struct istream *input)
+{
+       struct mail_deliver_session *session;
+       uid_t old_uid, first_uid;
+
+       if (client_open_raw_mail(client, input) < 0)
+               return;
+
+       session = mail_deliver_session_init();
+       old_uid = geteuid();
+       first_uid = client_deliver_to_rcpts(client, session);
+       mail_deliver_session_deinit(&session);
+
+       if (client->state.first_saved_mail != NULL) {
+               struct mail *mail = client->state.first_saved_mail;
+               struct mailbox_transaction_context *trans = mail->transaction;
+               struct mailbox *box = trans->box;
+               struct mail_user *user = box->storage->user;
+
+               /* just in case these functions are going to write anything,
+                  change uid back to user's own one */
+               if (first_uid != old_uid) {
+                       if (seteuid(0) < 0)
+                               i_fatal("seteuid(0) failed: %m");
+                       if (seteuid(first_uid) < 0)
+                               i_fatal("seteuid() failed: %m");
+               }
+
+               mail_free(&mail);
+               mailbox_transaction_rollback(&trans);
+               mailbox_free(&box);
+               mail_user_autoexpunge(user);
+               mail_user_unref(&user);
+       }
+
+       if (old_uid == 0) {
+               /* switch back to running as root, since that's what we're
+                  practically doing anyway. it's also important in case we
+                  lose e.g. config connection and need to reconnect to it. */
+               if (seteuid(0) < 0)
+                       i_fatal("seteuid(0) failed: %m");
+               /* enable core dumping again. we need to chdir also to
+                  root-owned directory to get core dumps. */
+               restrict_access_allow_coredumps(TRUE);
+               if (chdir(base_dir) < 0)
+                       i_error("chdir(%s) failed: %m", base_dir);
+       }
+}
index c23b913c71b72b4bb62bf74ef2687b77cbed8759..1f9b7efd7eb5db04413867c6b2ca5bba14ea871a 100644 (file)
@@ -11,9 +11,6 @@ bool cmd_rcpt_finish(struct client *client, struct mail_recipient *rcpt);
 
 void rcpt_anvil_lookup_callback(const char *reply, void *context);
 
-uid_t client_deliver_to_rcpts(struct client *client,
-                                   struct mail_deliver_session *session);
-
-int client_open_raw_mail(struct client *client, struct istream *input);
+void client_input_data_write_local(struct client *client, struct istream *input);
 
 #endif