bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2015-2018 Dovecot authors, see the included COPYING file */
bf132be3fe1c9e8de84f10d0b05c0b46ca542ac4Timo Sirainentest_server_read_nofd(struct istream *input, unsigned int idx)
3858a7a5da361c35f1e6e50c8e3214dc0cf379d6Phil Carmody test_assert_idx(i_stream_read_more(input, &data, &size) == 1, idx);
bf132be3fe1c9e8de84f10d0b05c0b46ca542ac4Timo Sirainen test_assert_idx(i_stream_unix_get_read_fd(input) == -1, idx);
bf132be3fe1c9e8de84f10d0b05c0b46ca542ac4Timo Sirainentest_server_read_fd(struct istream *input, int wanted_fd, unsigned int idx)
3858a7a5da361c35f1e6e50c8e3214dc0cf379d6Phil Carmody test_assert_idx(i_stream_read_more(input, &data, &size) == 1, idx);
bf132be3fe1c9e8de84f10d0b05c0b46ca542ac4Timo Sirainen test_assert_idx((recv_fd = i_stream_unix_get_read_fd(input)) != -1, idx);
bf132be3fe1c9e8de84f10d0b05c0b46ca542ac4Timo Sirainen if (fstat(recv_fd, &st1) < 0 || fstat(wanted_fd, &st2) < 0)
bf132be3fe1c9e8de84f10d0b05c0b46ca542ac4Timo Sirainen test_assert_idx(st1.st_ino == st2.st_ino, idx);
bf132be3fe1c9e8de84f10d0b05c0b46ca542ac4Timo Sirainen /* 1) simple read */
bf132be3fe1c9e8de84f10d0b05c0b46ca542ac4Timo Sirainen /* 2) fd was sent but we won't get it */
bf132be3fe1c9e8de84f10d0b05c0b46ca542ac4Timo Sirainen /* we still shouldn't have the fd */
3858a7a5da361c35f1e6e50c8e3214dc0cf379d6Phil Carmody test_assert(i_stream_read_more(input, &data, &size) == 0);
bf132be3fe1c9e8de84f10d0b05c0b46ca542ac4Timo Sirainen test_assert(i_stream_unix_get_read_fd(input) == -1);
bf132be3fe1c9e8de84f10d0b05c0b46ca542ac4Timo Sirainen /* 3) the previous fd should be lost now */
bf132be3fe1c9e8de84f10d0b05c0b46ca542ac4Timo Sirainen /* 4) we should get the fd now */
bf132be3fe1c9e8de84f10d0b05c0b46ca542ac4Timo Sirainen /* 5) the previous fd shouldn't be returned anymore */
bf132be3fe1c9e8de84f10d0b05c0b46ca542ac4Timo Sirainen /* 6) with i_stream_unix_unset_read_fd() we shouldn't get fd anymore */
bf132be3fe1c9e8de84f10d0b05c0b46ca542ac4Timo Sirainen /* 7-8) two fds were sent, but we'll get only the first one */
bf132be3fe1c9e8de84f10d0b05c0b46ca542ac4Timo Sirainen /* 9-10) two fds were sent, and we'll get them both */
bf132be3fe1c9e8de84f10d0b05c0b46ca542ac4Timo Sirainen if ((send_fd = open("/dev/null", O_RDONLY)) == -1)
d4e8dbd07007fc558697c9b579f999ef535d5157Timo Sirainen if ((send_fd2 = open("/dev/zero", O_RDONLY)) == -1)