1 #!/sbin/sh |
|
2 # |
|
3 # |
|
4 # CDDL HEADER START |
|
5 # |
|
6 # The contents of this file are subject to the terms of the |
|
7 # Common Development and Distribution License (the "License"). |
|
8 # You may not use this file except in compliance with the License. |
|
9 # |
|
10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
11 # or http://www.opensolaris.org/os/licensing. |
|
12 # See the License for the specific language governing permissions |
|
13 # and limitations under the License. |
|
14 # |
|
15 # When distributing Covered Code, include this CDDL HEADER in each |
|
16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
17 # If applicable, add the following below this CDDL HEADER, with the |
|
18 # fields enclosed by brackets "[]" replaced with your own identifying |
|
19 # information: Portions Copyright [yyyy] [name of copyright owner] |
|
20 # |
|
21 # CDDL HEADER END |
|
22 # |
|
23 # |
|
24 # Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. |
|
25 # |
|
26 |
|
27 . /lib/svc/share/smf_include.sh |
|
28 |
|
29 PATH=$PATH:/usr/sbin |
|
30 |
|
31 # Retrieve an unescaped property value from a method token. |
|
32 # Arguments: |
|
33 # - raw method token value |
|
34 # Outputs: |
|
35 # - unescaped property value |
|
36 # Returns: |
|
37 # - 0 on succes |
|
38 # - 1 when unescaping failed |
|
39 # - 2 when the value is empty |
|
40 function get_property |
|
41 { |
|
42 VALUE="$(echo "$1" | /usr/bin/sed 's/\\\(.\)/\1/g')" |
|
43 |
|
44 if [[ $? -ne 0 ]]; then |
|
45 exit 1 |
|
46 fi |
|
47 |
|
48 echo "$VALUE" |
|
49 } |
|
50 |
|
51 function failure |
|
52 { |
|
53 echo "An unknown error occurred. Probably either /usr/bin/sed is" |
|
54 echo "missing or system resources are exhausted." |
|
55 exit $SMF_EXIT_ERR_FATAL |
|
56 } |
|
57 |
|
58 # store and unescape property values |
|
59 PFLOGD_LOGFILE="$(get_property "$2")" || failure |
|
60 PFLOGD_SNAPLEN="$(get_property "$3")" || failure |
|
61 PFLOGD_IFACE="$(get_property "$4")" || failure |
|
62 PFLOGD_DELAY="$(get_property "$5")" || failure |
|
63 PFLOGD_FILTER="$(get_property "$6")" || failure |
|
64 |
|
65 # check property values for emptiness (pflog/filter may be empty) |
|
66 if [[ -z $PFLOGD_LOGFILE ]]; then |
|
67 echo "The pflog/logfile property cannot be empty." |
|
68 exit $SMF_EXIT_ERR_FATAL |
|
69 fi |
|
70 if [[ -z $PFLOGD_SNAPLEN ]]; then |
|
71 echo "The pflog/snaplen property cannot be empty." |
|
72 exit $SMF_EXIT_ERR_FATAL |
|
73 fi |
|
74 if [[ -z $PFLOGD_IFACE ]]; then |
|
75 echo "The pflog/interface property cannot be empty." |
|
76 exit $SMF_EXIT_ERR_FATAL |
|
77 fi |
|
78 if [[ -z $PFLOGD_DELAY ]]; then |
|
79 echo "The pflog/delay property cannot be empty." |
|
80 exit $SMF_EXIT_ERR_FATAL |
|
81 fi |
|
82 |
|
83 case "$1" in |
|
84 start) |
|
85 # Create non-persistent capture link if it does not exist. |
|
86 echo "Checking if capture link exists.." |
|
87 dladm show-cap "$PFLOGD_IFACE" |
|
88 if [[ $? -ne 0 ]] ; then |
|
89 echo "Creating a temporary capture link.." |
|
90 dladm create-cap -t "$PFLOGD_IFACE" |
|
91 if [ $? -ne 0 ] ; then |
|
92 exit $SMF_EXIT_ERR_FATAL |
|
93 fi |
|
94 fi |
|
95 |
|
96 # Start the daemon. |
|
97 smf_clear_env |
|
98 pflogd -i "$PFLOGD_IFACE" -s "$PFLOGD_SNAPLEN" \ |
|
99 -f "$PFLOGD_LOGFILE" -d "$PFLOGD_DELAY" "$PFLOGD_FILTER" |
|
100 if [[ $? -ne 0 ]] ; then |
|
101 exit $SMF_EXIT_ERR_FATAL |
|
102 fi |
|
103 ;; |
|
104 |
|
105 *) |
|
106 echo "Usage: $0 \c" >&2 |
|
107 echo "(start)" >&2 |
|
108 exit 1 |
|
109 ;; |
|
110 |
|
111 esac |
|
112 |
|
113 exit $SMF_EXIT_OK |
|