xref: /illumos-gate/usr/src/cmd/lp/cmd/lpsched/print-svc (revision 7ddce999)
1#!/sbin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22#
23# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26# Copyright 2016 Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
27#
28
29. /lib/svc/share/smf_include.sh
30. /lib/svc/share/ipf_include.sh
31
32# SERVICE = parent service name
33SERVICE=`echo $SMF_FMRI | /usr/bin/cut -f1,2 -d":"`
34
35case "$1" in
36'start')
37
38isopts=`/usr/sbin/svccfg <<-EOF
39	select $SMF_FMRI
40	listpg cmd_opts
41
42	EOF`
43
44if [ "$isopts" ] ; then
45
46#called by /usr/lib/lpsched; use cmd_opts properties only
47
48	num_notifiers=`/bin/svcprop -p cmd_opts/num_notifiers $SMF_FMRI`
49
50	if [ "$num_notifiers" != "" ] ; then
51		OPTS="$OPTS -n $num_notifiers" 
52	fi
53
54	num_filters=`/bin/svcprop -p cmd_opts/num_filters $SMF_FMRI`
55
56	if [ "$num_filters" != "" ]  ; then
57		OPTS="$OPTS -f $num_filters"
58	fi
59
60	fd_limit=`/bin/svcprop -p cmd_opts/fd_limit $SMF_FMRI`
61
62	if [ "$fd_limit" != "" ]  ; then
63		OPTS="$OPTS -p $fd_limit"
64	fi
65
66	reserved_fds=`/bin/svcprop -p cmd_opts/reserved_fds $SMF_FMRI`
67
68	if [ "$reserved_fds" != "" ] ; then
69		OPTS="$OPTS -r $reserved_fds"
70	fi
71
72# clear out cmd_opts property group
73
74	svccfg <<-EOF
75	select $SMF_FMRI
76	delpg cmd_opts
77
78	EOF
79
80else
81
82# We are here through enable; use lpsched properties
83# Check for saved properties
84
85	num_notifiers=`/bin/svcprop -p lpsched/num_notifiers $SERVICE`
86	if [ "$num_notifiers" != "" ] && [ "$num_notifiers" != "0" ] ; then
87		OPTS="$OPTS -n $num_notifiers"
88	fi
89
90	num_filters=`/bin/svcprop -p lpsched/num_filters $SERVICE`
91	if [ "$num_filters" != "" ] && [ "$num_filters" != "0" ] ; then
92		OPTS="$OPTS -f $num_filters"
93	fi
94
95	fd_limit=`/bin/svcprop -p lpsched/fd_limit $SERVICE`
96	if [ "$fd_limit" != "" ]  && [ "$fd_limit" != "0" ]; then
97		OPTS="$OPTS -p $fd_limit"
98	fi
99
100	reserved_fds=`/bin/svcprop -p lpsched/reserved_fds $SERVICE`
101	if [ "$reserved_fds" != "" ] && [ "$reserved_fds" != "0" ] ; then
102		OPTS="$OPTS -r $reserved_fds"
103	fi
104fi
105
106# set temporary or permanent properties from OPTS
107
108	[ -f /usr/lib/lp/local/lpsched ] || exit $SMF_EXIT_ERR_CONFIG
109
110	/usr/lib/lp/local/lpsched ${OPTS}
111
112	;;
113
114'stop')
115	[ -f /usr/lib/lp/local/lpshut ] || exit $SMF_EXIT_ERR_CONFIG
116
117	/usr/lib/lp/local/lpshut
118	;;
119
120'ipfilter')
121	FMRI=$2
122	IPP_FMRI="svc:/application/print/ipp-listener:default"
123	RFC1179_FMRI="svc:/application/print/rfc1179:default"
124	IPP_CONF=/etc/lp/ipp/httpd-standalone-ipp.conf
125
126	policy=`get_policy $FMRI`
127
128	file=`fmri_to_file $RFC1179_FMRI $IPF_SUFFIX`
129	file6=`fmri_to_file $RFC1179_FMRI $IPF6_SUFFIX`
130	echo "# $RFC1179_FMRI" >$file
131	echo "# $RFC1179_FMRI" >$file6
132        service_is_enabled ${RFC1179_FMRI}
133        if [ $? -eq 0 ]; then
134		rfc_name=`svcprop -p inetd/name ${RFC1179_FMRI} 2>/dev/null`
135		rfc_proto=`svcprop -p inetd/proto ${RFC1179_FMRI} 2>/dev/null | \
136		    sed 's/6/ /'`
137		rfc_port=`$SERVINFO -p -t -s $rfc_name`
138		generate_rules $FMRI $policy $rfc_proto $rfc_port $file
139		generate_rules $FMRI $policy $rfc_proto $rfc_port $file6 _6
140        fi
141
142	file=`fmri_to_file $IPP_FMRI $IPF_SUFFIX`
143	file6=`fmri_to_file $IPP_FMRI $IPF6_SUFFIX`
144	echo "# $IPP_FMRI" >$file
145	echo "# $IPP_FMRI" >$file6
146        service_is_enabled ${IPP_FMRI}
147        if [ $? -eq 0 ]; then
148		#
149		# If Listen directives are used, it's possibie to listen on
150		# more than one ports. Process the Port directives only when Listen
151		# directives don't exist.
152		#
153		ipp_ports=`grep '^[ \t]*[^# ]*Listen' ${IPP_CONF} | awk '{print $2}'`
154
155		if [ -z "$ipp_ports" ]; then
156			ipp_ports=`grep '^[ \t]*[^# ]*Port' ${IPP_CONF} | \
157			    awk '{print $2}' | tail -1`
158		fi
159
160		for port in $ipp_ports; do
161			generate_rules $FMRI $policy "tcp" $port $file
162			generate_rules $FMRI $policy "tcp" $port $file6 _6
163		done
164	fi
165
166	;;
167
168*)
169	echo "Usage: $0 { start | stop }"
170	exit 1
171	;;
172esac
173exit $SMF_EXIT_OK
174