| 692 | #endif |
| 693 | |
| 694 | static int rsync_module(int f_in, int f_out, int i, const char *addr, const char *host) |
| 695 | { |
| 696 | int argc; |
| 697 | char **argv, **orig_argv, **orig_early_argv, *module_chdir; |
| 698 | char line[BIGPATHBUFLEN]; |
| 699 | #if defined HAVE_INITGROUPS && !defined HAVE_GETGROUPLIST |
| 700 | struct passwd *pw = NULL; |
| 701 | #endif |
| 702 | uid_t uid; |
| 703 | int set_uid; |
| 704 | char *p, *err_msg = NULL; |
| 705 | char *name = lp_name(i); |
| 706 | int use_chroot = lp_use_chroot(i); /* might be 1 (yes), 0 (no), or -1 (unset) */ |
| 707 | int ret, pre_exec_arg_fd = -1, pre_exec_error_fd = -1; |
| 708 | int save_munge_symlinks; |
| 709 | pid_t pre_exec_pid = 0; |
| 710 | char *request = NULL; |
| 711 | |
| 712 | set_env_str("RSYNC_MODULE_NAME", name); |
| 713 | |
| 714 | #ifdef ICONV_OPTION |
| 715 | iconv_opt = lp_charset(i); |
| 716 | if (*iconv_opt) |
| 717 | setup_iconv(); |
| 718 | iconv_opt = NULL; |
| 719 | #endif |
| 720 | |
| 721 | /* If reverse lookup is disabled globally but enabled for this module, |
| 722 | * we need to do it now before the access check. */ |
| 723 | if (host == undetermined_hostname && lp_reverse_lookup(i)) |
| 724 | host = client_name(client_addr(f_in)); |
| 725 | set_env_str("RSYNC_HOST_NAME", host); |
| 726 | set_env_str("RSYNC_HOST_ADDR", addr); |
| 727 | |
| 728 | if (!allow_access(addr, &host, i)) { |
| 729 | rprintf(FLOG, "rsync denied on module %s from %s (%s)\n", |
| 730 | name, host, addr); |
| 731 | if (!lp_list(i)) |
| 732 | io_printf(f_out, "@ERROR: Unknown module '%s'\n", name); |
| 733 | else { |
| 734 | io_printf(f_out, |
| 735 | "@ERROR: access denied to %s from %s (%s)\n", |
| 736 | name, host, addr); |
| 737 | } |
| 738 | return -1; |
| 739 | } |
| 740 | |
| 741 | if (am_daemon > 0) { |
| 742 | rprintf(FLOG, "rsync allowed access on module %s from %s (%s)\n", |
| 743 | name, host, addr); |
| 744 | } |
| 745 | |
| 746 | if (!claim_connection(lp_lock_file(i), lp_max_connections(i))) { |
| 747 | if (errno) { |
| 748 | rsyserr(FLOG, errno, "failed to open lock file %s", |
| 749 | lp_lock_file(i)); |
| 750 | io_printf(f_out, "@ERROR: failed to open lock file\n"); |
| 751 | } else { |
no test coverage detected