View | Details | Raw Unified | Return to bug 249860 | Differences between
and this patch

Collapse All | Expand All

(-)mail/fetchmailconf/Makefile (+1 lines)
Lines 1-6 Link Here
1
# $FreeBSD$
1
# $FreeBSD$
2
2
3
PORTNAME=	fetchmailconf
3
PORTNAME=	fetchmailconf
4
PORTREVISION=	0
4
DISTNAME=	fetchmail-${DISTVERSIONPREFIX}${DISTVERSION}${DISTVERSIONSUFFIX}
5
DISTNAME=	fetchmail-${DISTVERSIONPREFIX}${DISTVERSION}${DISTVERSIONSUFFIX}
5
# NOTE: MASTER_SITES in ../fetchmail must NOT use the $PORTNAME variable,
6
# NOTE: MASTER_SITES in ../fetchmail must NOT use the $PORTNAME variable,
6
# else _this_ port (fetchmailconf) becomes unfetchable
7
# else _this_ port (fetchmailconf) becomes unfetchable
(-)mail/fetchmail/Makefile (+1 lines)
Lines 3-8 Link Here
3
3
4
PORTNAME?=	fetchmail
4
PORTNAME?=	fetchmail
5
DISTVERSION=	6.4.12
5
DISTVERSION=	6.4.12
6
PORTREVISION?=	1
6
CATEGORIES=	mail
7
CATEGORIES=	mail
7
# The next line is inherited by the fetchmailconf slave port,
8
# The next line is inherited by the fetchmailconf slave port,
8
# do NOT replace fetchmail by ${PORTNAME}
9
# do NOT replace fetchmail by ${PORTNAME}
(-)mail/fetchmail/files/fetchmail.in (-47 / +102 lines)
Lines 15-29 Link Here
15
#
15
#
16
# There are two variants:
16
# There are two variants:
17
#
17
#
18
#  Note that there are two variables with only very slightly
19
#  different names, fetchmail_user and fetchmail_users
20
#  (mind the trailing plural-'s').
21
#
18
#  * Single system-wide fetchmail daemon:
22
#  * Single system-wide fetchmail daemon:
23
#    - This mode applies if the 'fetchmail_users' variable
24
#      is unset or empty.
19
#    - It is run as user `fetchmail_user' (default: fetchmail)
25
#    - It is run as user `fetchmail_user' (default: fetchmail)
20
#      Note: The directory /var/run/fetchmail must be writable for
26
#      Note: The directory /var/run/fetchmail must be writable for
21
#            'fetchmail_user'.
27
#            'fetchmail_user'.
22
#    - All configuration is contained in one global file
28
#    - All configuration is contained in one global file
23
#      'fetchmail_config' (default: %%PREFIX%%/etc/fetchmailrc)
29
#      'fetchmail_config' (default: %%PREFIX%%/etc/fetchmailrc)
24
#      that must be owned by 'fetchmail_user' (mode 700)
30
#      that must be owned by 'fetchmail_user' and access mode
31
#      may not be more than 700.
25
#    - The fetchmail daemon awakes to fetch mail every 
32
#    - The fetchmail daemon awakes to fetch mail every 
26
#      'fetchmail_polling_interval' seconds (default: 900).
33
#      'fetchmail_polling_interval' seconds (default: 900).
34
#        Note that a "set daemon 123" in the file $fetchmail_config
35
#      takes precedence. The rc.conf value is only a fall-back.
36
#    - The fetchmail logs will go to the syslog by default, but
37
#      you can override it to a file by setting 
38
#      'fetchmail_logging_facility=--logfile=/path/to/logfile'
39
#      in the rcfile or set logfile /path/to/logfile in the $fetchmail_config
40
#      file.  The log-file must pre-exist and be writable by the
41
#      'fetchmail_user'.
27
#
42
#
28
#  * Per-user daemon
43
#  * Per-user daemon
29
#    - Users for which a fetchmail daemon is to be started must be
44
#    - Users for which a fetchmail daemon is to be started must be
Lines 30-45 Link Here
30
#      listed in 'fetchmail_users', e.g. fetchmail_users="user1 user2"
45
#      listed in 'fetchmail_users', e.g. fetchmail_users="user1 user2"
31
#      The 'fetchmail_user' (sic!) variable is ignored in this
46
#      The 'fetchmail_user' (sic!) variable is ignored in this
32
#      configuration variant.
47
#      configuration variant.
33
#    - The config files for the individual users must be located at
48
#    - The config files for the individual users must be located in
34
#      ${fetchmail_home_prefix}/${user}/${fetchmail_config_name}. The
49
#      the fetchmail_user's home directory as ${fetchmail_config_name}. The
35
#      default for 'fetchmail_home_prefix' is "/home", and that for
50
#      default for 'fetchmail_config_name' is ".fetchmailrc".
36
#      'fetchmail_config_name' is ".fetchmailrc".
51
#    - There are user-specific versions of 'fetchmail_config',
37
#    - Note that "${fetchmail_home_prefix}/${user}" must be writable
52
#      'fetchmail_logging_facility' and 'fetchmail_polling_interval' as well as
38
#      for ${user} since it is used to store the per-user PID files!
53
#      the usual rc.subr variables that can be used to override the defaults,
39
#    - There are user-specific versions of 'fetchmail_config' and
54
#      i.e. for the user 'user1' there are variables 'fetchmail_user1_config'
40
#      'fetchmail_polling_interval' that can be used to override the
55
#      and 'fetchmail_user1_polling_interval', or fetchmail_user1_env to
41
#      defaults, i.e. for the user 'user1' there are variables
56
#      set user-daemon specific environment variables.
42
#      'fetchmail_user1_config' and 'fetchmail_user1_polling_interval'
57
#        Note that a "set daemon 123" in the config file (.fetchmailrc
58
#      by default) takes precedence. The rc.conf value is only a fall-back.
43
#    - All commands (e.g. start, stop, awaken (see below)) can be either
59
#    - All commands (e.g. start, stop, awaken (see below)) can be either
44
#      passed to all instances of the daemon (if %%PREFIX%%/etc/rc.d/fetchmail)
60
#      passed to all instances of the daemon (if %%PREFIX%%/etc/rc.d/fetchmail)
45
#      is run as root), or just to the instance belonging to the respective
61
#      is run as root), or just to the instance belonging to the respective
Lines 54-64 Link Here
54
#
70
#
55
# In any case, you will need a working fetchmailrc file. Please consult
71
# In any case, you will need a working fetchmailrc file. Please consult
56
# the man page fetchmail(1), the documentation in %%PREFIX%%/share/doc/fetchmail/
72
# the man page fetchmail(1), the documentation in %%PREFIX%%/share/doc/fetchmail/
57
# and/or the material found at <http://www.fetchmail.info/>.
73
# and/or the material found at <https://www.fetchmail.info/> or
74
# <https://fetchmail.sourceforge.io/>.
58
75
59
. /etc/rc.subr
76
. /etc/rc.subr
60
77
78
# prevent reading passwords from the boot console
79
exec < /dev/null
80
61
name=fetchmail
81
name=fetchmail
82
# note we do not override name for instances, because we want to have a fallback
83
# to global defaults.  Check for PULLVARS below.
62
rcvar=fetchmail_enable
84
rcvar=fetchmail_enable
63
85
64
command=%%PREFIX%%/bin/${name}
86
command=%%PREFIX%%/bin/${name}
Lines 71-81 Link Here
71
# read settings, set default values
93
# read settings, set default values
72
load_rc_config "$name"
94
load_rc_config "$name"
73
: ${fetchmail_enable="NO"}
95
: ${fetchmail_enable="NO"}
96
: ${fetchmail_flags=""}
74
: ${fetchmail_user="fetchmail"}
97
: ${fetchmail_user="fetchmail"}
75
: ${fetchmail_config="%%PREFIX%%/etc/fetchmailrc"}
98
: ${fetchmail_config="%%PREFIX%%/etc/fetchmailrc"}
76
: ${fetchmail_polling_interval="900"}
99
: ${fetchmail_polling_interval="900"}
77
: ${fetchmail_logging_facility="--syslog"}
100
: ${fetchmail_logging_facility="--syslog"}
78
: ${fetchmail_home_prefix="/home"}
79
: ${fetchmail_config_name=".fetchmailrc"}
101
: ${fetchmail_config_name=".fetchmailrc"}
80
102
81
# send signal to fetchmail process(es) to check for new mail immediately
103
# send signal to fetchmail process(es) to check for new mail immediately
Lines 91-150 Link Here
91
	return
113
	return
92
}
114
}
93
115
94
if [ -n "$2" ]; then
116
# query a value from the fetchmail config file, value specified in first argument
95
	# perform action for an instance of fetchmail daemon
117
fetchmail_dump_config()
96
        user="$2"
118
{
97
        if [ "x${fetchmail_users}" != "x" -o "x$3" = "xGLOBALCONFIG"  ]; then
119
	su -m ${fetchmail_user} -c sh -c "fetchmail -f ${fetchmail_config} --configdump" | fgrep $1 | cut -d: -f2
98
		if [ "x${fetchmail_users}" != "x" ]; then
120
}
99
			# multiuser setup:  determine user specific config and pid file
121
100
			eval fetchmail_config="\${fetchmail_${user}_config:-${fetchmail_home_prefix}/${user}}/${fetchmail_config_name}"
122
# arguments:
101
			eval pidfile="${fetchmail_home_prefix}/${user}/.fetchmail.pid"
123
# ACTION - perform ACTION for the one global daemon
102
			eval fetchmail_user=$user
124
# ACTION USER GLOBALCONFIG - ditto, inside the recursive call
103
		else
125
# ACTION USER - perform ACTION for the USER-specific daemon, inside recursive call
104
			eval pidfile=/var/run/fetchmail/fetchmail.pid
126
105
		fi
127
# if this is the global or 'umbrella' run
106
		required_files=${fetchmail_config}
128
if [ -z "$2" ] ; then
107
		eval fetchmail_polling_interval="\${fetchmail_${user}_polling_interval:-${fetchmail_polling_interval}}"
129
	uid=$(id -u)
108
		fetchmail_flags="-f ${fetchmail_config} \
130
	if [ "x${fetchmail_users}" != "x" -a "x$1" != "x" -a "$uid" = "0" ]; then
109
				--pidfile ${pidfile} \
110
				-d ${fetchmail_polling_interval} \
111
				${fetchmail_logging_facility}"
112
        else
113
                echo "$0: extra argument ignored"
114
        fi
115
else
116
	uid=`id -u`
117
        if [ "x${fetchmail_users}" != "x" -a "x$1" != "x" -a "$uid" = "0" ]; then
118
		# root mode: multiple user profiles are handled by recursive
131
		# root mode: multiple user profiles are handled by recursive
119
		# calls of this script
132
		# calls of this script
120
		for user in ${fetchmail_users}; do
133
		for user in ${fetchmail_users}; do
121
			echo "===> fetchmail user: ${user}"
134
			echo "===> fetchmail user: ${user}"
122
			$fetchmail_script $1 ${user}
135
			$fetchmail_script "$1" "${user}"
123
			retcode="$?"
136
			retcode="$?"
124
			if [ "0${retcode}" -ne 0 ]; then
137
			if [ "0${retcode}" -ne 0 ]; then
125
				failed="${user} (${retcode}) ${failed:-}"
138
				failed="${user} (${retcode}) ${failed:-}"
126
			else
127
				success="${user} ${success:-}"
128
			fi
139
			fi
129
		done
140
		done
130
		exit 0
131
	else
141
	else
132
		if [ "x${fetchmail_users}" = "x" ]; then
142
		if [ "x${fetchmail_users}" = "x" ]; then
133
			# There is only one global configuration file
143
			# There is only one global configuration file
134
			globalconfig=GLOBALCONFIG
144
			globalconfig=GLOBALCONFIG
135
		fi
145
		fi
136
		$fetchmail_script $1 `id -u -n` $globalconfig
146
		$fetchmail_script "$1" "$(id -u -n)" $globalconfig
137
		retcode="$?"
147
		retcode="$?"
138
		if [ "0${retcode}" -ne 0 ]; then
148
		if [ "0${retcode}" -ne 0 ]; then
139
			failed="${user} (${retcode}) ${failed:-}"
149
			failed="${name} (${retcode}) ${failed:-}"
140
			exit 1
141
		else
142
			success="${user} ${success:-}"
143
		fi
150
		fi
144
		exit 0
145
        fi
151
        fi
152
153
	# if we had any failures, exit witn an error
154
	if [ -n "${failed}" ] ; then
155
		exit 1
156
	fi
157
158
	# otherwise, exit success
159
	exit 0
146
fi
160
fi
147
161
162
# perform action for an instance of fetchmail daemon
163
fetchmail_user="$2"
164
if [ "x${fetchmail_users}" != "x" -o "x$3" = "xGLOBALCONFIG" ]; then
165
	if [ "x${fetchmail_users}" != "x" ]; then
166
		# multiuser setup:  determine user specific config and pid file
167
		fetchmail_home="$(getent passwd ${fetchmail_user} | cut -f6 -d:)"
168
		fetchmail_home="${fetchmail_home%/}"
169
		fetchmail_config="${fetchmail_home}/${fetchmail_config_name}"
170
		pidfile="${fetchmail_home}/.fetchmail.pid"
171
		# PULLVARS - pull user specific variables into scope if existing
172
		# else use global defaults
173
		for i in chdir chroot env env_file fib flags nice \
174
			limits login_class oomprotect program user group groups prepend \
175
			logging_facility polling_interval
176
		do
177
			uvarname=fetchmail_${fetchmail_user}_${i}
178
	 		eval fetchmail_${i}="\${${uvarname}-\${fetchmail_${i}}}"
179
		done
180
	else
181
		pidfile=/var/run/fetchmail/fetchmail.pid
182
	fi
183
	required_files=${fetchmail_config}
184
185
	# add early command line arguments
186
	# if logfile set in config file, do not override with rc.conf default (note logfile overrides syslog)
187
	_logfile="$(fetchmail_dump_config logfile)"
188
	if [ _"${_logfile}" != _"None," ] ; then
189
		fetchmail_logging_facility=""
190
	fi
191
192
	fetchmail_flags="${fetchmail_flags} -f ${fetchmail_config} --pidfile ${pidfile} ${fetchmail_logging_facility}"
193
194
	# add late command line arguments
195
	# if no polling interval in config file, use value from rc.conf
196
	if [ "$(fetchmail_dump_config poll_interval)" = "0," ] ; then
197
		fetchmail_flags="${fetchmail_flags} -d ${fetchmail_polling_interval}"
198
	fi
199
else
200
	echo "$0: extra argument ignored"
201
fi
202
148
# actually execute the fetchmail program
203
# actually execute the fetchmail program
149
export FETCHMAILUSER=$fetchmail_user
204
export FETCHMAILUSER=$fetchmail_user
150
run_rc_command "$1"
205
run_rc_command "$1"

Return to bug 249860