~ampelbein/ubuntu/oneiric/heartbeat/lp-770743

« back to all changes in this revision

Viewing changes to debian/shellfuncs.m4

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2002-10-09 21:03:59 UTC
  • Revision ID: james.westby@ubuntu.com-20021009210359-6y1hyn4lhsoey9ul
Tags: 0.4.9.0l-7.2
* Non-maintainer upload by security team
* Fixed several buffer overflows found by Nathan Wallwork.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
dnl shellfuncs.m4 ... phew, a really nice m4 file containing shellfunction defs
 
2
dnl                   for several shell functions that I wanted to be
 
3
dnl                 concentrated on one point rather than spilling it over
 
4
dnl                 several places.
 
5
dnl
 
6
dnl is needed since most of the shellcode deals with '
 
7
dnl
 
8
dnl
 
9
dnl now write a generic header - for all files using this shellfunc (lib)
 
10
#!/bin/bash
 
11
# don't edit this file - it has been autogenerated by debian/rules
 
12
# instead edit the corresponding .in file or have a look at debian/shellfuncs
 
13
#
 
14
changequote([,])dnl
 
15
dnl
 
16
define([V], [$])dnl
 
17
define([AT], [@])dnl
 
18
define([N1], [1])dnl
 
19
define([N2], [2])dnl
 
20
define([N3], [3])dnl
 
21
define([VALL], [V()AT()])dnl
 
22
define([V1], [V()N1()])dnl
 
23
define([V2], [V()N2()])dnl
 
24
define([V3], [V()N3()])dnl
 
25
dnl
 
26
define([STRCAT],
 
27
dnl space separated value - add at the right side (string end)
 
28
dnl $ 1 = value that should be added
 
29
dnl $ 2 = ssv list
 
30
[strcat() { changequote(%,%)
 
31
    if %[% -z "V2()" %]%; then changequote([,])
 
32
        echo "V1()"
 
33
    else
 
34
        echo "V2() V1()"
 
35
    fi
 
36
}])dnl
 
37
dnl
 
38
define([SSV_ADD],
 
39
[dnl space separated value - add at the left side (string start)
 
40
dnl $ 1 = value that should be added
 
41
dnl $ 2 = ssv list
 
42
ssv_add() {
 
43
    echo "VALL()"
 
44
dnl | sed -e 's/ $//'
 
45
dnl | sed -ne "s/^\($1\)\(.*\)$/\1\2/p" | sed -e 's/, $//'
 
46
}])dnl
 
47
dnl
 
48
define([SSV_GET],
 
49
[dnl coma separated value - get function 
 
50
dnl $ 1 = field (integer describing position)
 
51
dnl $ 2 = csv list
 
52
ssv_get() { changequote(%,%)
 
53
    if [ "`echo "V2()" | grep ' '`" != "" -o "V1()" = 1 ]; then
 
54
changequote([,])dnl
 
55
        echo "V2()" | cut -d" " --fields=V1()
 
56
    fi
 
57
}])dnl
 
58
dnl
 
59
define([SSV_TEST],
 
60
[dnl space separated value - test function - to see if value is in the ssv list
 
61
dnl $ 1 = string to test for
 
62
dnl $ 2 = ssv list
 
63
ssv_test() { changequote(_,_)
 
64
dnl eliminate first parameter and then grep for it
 
65
    if [ -n "`echo "VALL()" | sed -e "s%^V1()\ *%%;" | grep "V1()"`" ]; then 
 
66
changequote([,])dnl
 
67
        echo 'true'
 
68
    else
 
69
        echo 'false'
 
70
    fi
 
71
}])dnl
 
72
dnl
 
73
define([CSV_ADD],
 
74
[dnl coma separated value - add at the left side (string start)
 
75
dnl $ 1 = value that should be added
 
76
dnl $ 2 = csv list
 
77
csv_add() {
 
78
    echo "VALL()" | sed -ne "s%^\(V1()\)\(.*\)$%\1,\2%p" | sed -e 's/, $//'
 
79
}])dnl
 
80
dnl
 
81
define([CSV_ADD_RIGHT],
 
82
[dnl coma separated value - add at the right side (string end)
 
83
dnl $ 1 = value that should be added
 
84
dnl $ 2 = csv list
 
85
csv_add_right() {
 
86
    echo "VALL()" | sed -ne "s/^\(V1()\) \(.*\)$/\2, \1/p" | sed -e 's/^, //'
 
87
}])dnl
 
88
dnl
 
89
define([CSV_GET],
 
90
[dnl coma separated value - get function 
 
91
dnl $ 1 = field (integer describing position, starting with 1)
 
92
dnl $ 2 = csv list
 
93
csv_get() { changequote(_,_)
 
94
    if [ "`echo "V2()" | grep ','`" != "" -o "V1()" = 1 ]; then 
 
95
changequote([,])dnl
 
96
        echo "V2()" | cut -d, --fields=V1() | sed -e 's/^ //'
 
97
    fi
 
98
}])dnl
 
99
dnl
 
100
define([CSV_TEST],
 
101
[dnl coma separated value - test function - to see if value is in the csv list
 
102
dnl $ 1 = string to test for
 
103
dnl $ 2 = csv list
 
104
csv_test() { changequote(_,_)
 
105
    if [ -n "`echo "VALL()" | sed -e "s/^V1() //" | grep "V1()"`" ]; then
 
106
changequote([,])        echo 'true'
 
107
    else
 
108
        echo 'false'
 
109
    fi
 
110
}])dnl
 
111
dnl
 
112
define([CSV_RM],
 
113
[dnl coma separated value - remove function - to remove a specific value
 
114
dnl $ 1 = value to remove
 
115
dnl $ 2 = csv list
 
116
csv_rm() {
 
117
dnl CSV_LIST = $@ without $1
 
118
    CSV_LIST=`echo "VALL()" | sed -e "s/^V1() //"` changequote(_,_)
 
119
dnl check if $1 is in CSV_LIST 
 
120
    if [ -n "`echo "$CSV_LIST" | grep "V1()"`" ]; then changequote([,])
 
121
        dnl 1) remove add a ', ' to the front and a ',' to the end
 
122
        dnl 2) remove entry
 
123
        dnl 3) remove leading and trailing ',' and ' '
 
124
        echo "VALL()" | sed -e "s/^V1() //" | sed -ne 's/^\(.*\)$/, \1,/p' | \
 
125
            sed -ne "s/^\(.*\), V1(),\(.*\)$/\1,\2/p" | \
 
126
            sed -e 's/^, //' | sed -e 's/,$//'
 
127
    else
 
128
        echo "$CSV_LIST"
 
129
    fi
 
130
}])dnl
 
131
dnl
 
132
define([MCAST_ADD],
 
133
[dnl multicast helper function to add a new value
 
134
dnl $ 1 = new interface
 
135
dnl $ 2 = new value 
 
136
dnl $ 3 = csv list
 
137
mcast_add() {
 
138
    csv_add_right "V1()$1 V2()" "V3()"
 
139
}])dnl
 
140
dnl
 
141
define([MCAST_GET],
 
142
[dnl multicast helper function to retrieve a value
 
143
dnl $ 1 = interface to search for
 
144
dnl $ 2 = list containing all values
 
145
mcast_get() {
 
146
dnl init vars
 
147
    COUNT=2
 
148
    ENTRY=`csv_get "1" "V2()"`
 
149
changequote(_,_)dnl
 
150
  
 
151
dnl as long as entry not empty
 
152
    while [ -n "$ENTRY" ]; do changequote([,])
 
153
        # get the nic in front of the value
 
154
        INT=`echo "$ENTRY" | cut -d"$1" -f1 | sed -ne 's/^\ *\(.*\)\ *$/\1/p'`
 
155
changequote(_,_)dnl
 
156
        # when specified nic (V1()) = NIC is
 
157
        if [ "$INT" = "V1()" ]; then changequote([,])
 
158
            # return the value
 
159
            echo "$ENTRY"| sed -e "s/$INT$1//"| sed -ne "s/^\ *\(.*\)\ *$/\1/p"
 
160
            exit 0
 
161
        fi
 
162
        ENTRY=`csv_get "$COUNT" "V2()"`
 
163
        COUNT=$(($COUNT + 1))
 
164
    done
 
165
}])dnl
 
166
dnl
 
167
define([MCAST_RM],
 
168
[dnl multicast helper function to remove a value
 
169
dnl $ 1 = interface to search for
 
170
dnl $ 2 = list containing all values
 
171
mcast_rm() {
 
172
    dnl init vars
 
173
    COUNT=2
 
174
    ENTRY=`csv_get "1" "V2()"`
 
175
    NCSVLIST="" changequote(_,_)
 
176
 
 
177
    dnl as long as entry not empty
 
178
    while [ -n "$ENTRY" ]; do changequote([,])
 
179
        # get the nic in front of the value
 
180
        INT=`echo "$ENTRY" | cut -d$1 -f1 | sed -e 's/\ //g'` changequote(_,_)
 
181
        # when specified nic ($1) != NIC is
 
182
        if [ "$INT" != "V1()" ]; then changequote([,])
 
183
            # return this value
 
184
            NCSVLIST=`csv_add_right "$ENTRY" "$NCSVLIST"`
 
185
        fi
 
186
        ENTRY=`csv_get "$COUNT" "V2()"`
 
187
        COUNT=$(($COUNT + 1))
 
188
    done
 
189
    echo "$NCSVLIST" | sed -e 's/,$//'
 
190
}])dnl
 
191
dnl
 
192
define([PRE],
 
193
[dnl writes everything from $2 til $1 occurs (while interpreting $2 with -e)
 
194
dnl $ 1 = stop when finding this at the start of a line
 
195
dnl $ 2 = text to filter (with -e)
 
196
pre() { changequote(_,_)
 
197
    if [ -n "V1()" ]; then changequote([,])
 
198
        echo -e "V2()" | sed -e "s/^V1().*//; t end; b fur; : end q; : fur s///;"
 
199
    else
 
200
        echo -e "V2()"
 
201
    fi
 
202
}])dnl
 
203
dnl
 
204
define([POST],
 
205
[dnl writes everything after the first occurence of $1, but not before removing
 
206
dnl every line that starts with $1
 
207
dnl $ 1 = remove line when starting with this
 
208
dnl $ 2 = complete text (text to filter)
 
209
dnl $ 3 = PRE text (generated by pre)
 
210
post() {
 
211
    LC=`echo -e "V2()" | wc -l`
 
212
    PRELC=`echo -e "V3()" | wc -l`
 
213
    LENGTH=$(($LC - $PRELC))
 
214
    echo -e "V2()" | tail -$LENGTH | (grep -v "^V1()" || true)
 
215
}])dnl
 
216
dnl
 
217
changequote(<,_)dnl