Thu, 04 Oct 2012 20:30:05 +0200
Correct out of date build configuration, porting to Solaris 11 network
link infrastructure and new libpcap logic. This additionally allows for
device drivers in subdirectories of /dev. Correct packaged nmap
personalities and signatures to work out of the box. Finally, hack
arpd logic to properly close sockets and quit on TERM by repeating
signaling in the run command script. Sadly, all this fails to correct
the run time behaviour of honeyd which fails to bind to the IP layer.
michael@13 | 1 | #!@l_prefix@/lib/openpkg/bash |
michael@13 | 2 | ## |
michael@13 | 3 | ## uuid -- OpenPKG UUID Update Utility |
michael@428 | 4 | ## Copyright (c) 2000-2012 OpenPKG GmbH <http://openpkg.com/> |
michael@13 | 5 | ## |
michael@428 | 6 | ## This software is property of the OpenPKG GmbH, DE MUC HRB 160208. |
michael@428 | 7 | ## All rights reserved. Licenses which grant limited permission to use, |
michael@428 | 8 | ## copy, modify and distribute this software are available from the |
michael@428 | 9 | ## OpenPKG GmbH. |
michael@13 | 10 | ## |
michael@428 | 11 | ## THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED |
michael@13 | 12 | ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
michael@13 | 13 | ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
michael@13 | 14 | ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR |
michael@13 | 15 | ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
michael@13 | 16 | ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
michael@13 | 17 | ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
michael@13 | 18 | ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
michael@13 | 19 | ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
michael@13 | 20 | ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
michael@13 | 21 | ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
michael@13 | 22 | ## SUCH DAMAGE. |
michael@13 | 23 | ## |
michael@13 | 24 | |
michael@13 | 25 | # configuration |
michael@13 | 26 | prefix="@l_prefix@" |
michael@13 | 27 | musr="@l_musr@" |
michael@13 | 28 | mgrp="@l_mgrp@" |
michael@13 | 29 | prog_rpm="$prefix/libexec/openpkg/rpm" |
michael@13 | 30 | prog_shtool="$prefix/lib/openpkg/shtool" |
michael@13 | 31 | prog_miniperl="$prefix/lib/openpkg/miniperl" |
michael@13 | 32 | prog_uuid="$prefix/lib/openpkg/uuid" |
michael@13 | 33 | file_uuid="$prefix/etc/openpkg/uuid" |
michael@13 | 34 | |
michael@13 | 35 | # minimum command line parsing |
michael@13 | 36 | opt_v=no |
michael@13 | 37 | opt_m=no |
michael@13 | 38 | while [ 1 ]; do |
michael@13 | 39 | case "$1" in |
michael@13 | 40 | -v | --verbose ) opt_v=yes; shift ;; |
michael@13 | 41 | -m | --multicast ) opt_m=yes; shift ;; |
michael@13 | 42 | * ) break ;; |
michael@13 | 43 | esac |
michael@13 | 44 | done |
michael@13 | 45 | |
michael@13 | 46 | # special "Nil UUID" |
michael@13 | 47 | UUID_NIL="00000000-0000-0000-0000-000000000000" |
michael@13 | 48 | |
michael@13 | 49 | # Query Dynamic Information |
michael@13 | 50 | do_query () { |
michael@13 | 51 | # query RPM information |
michael@13 | 52 | query=":" |
michael@13 | 53 | for var in \ |
michael@13 | 54 | l_openpkg_release \ |
michael@13 | 55 | l_prefix \ |
michael@13 | 56 | l_susr l_suid l_sgrp l_sgid \ |
michael@13 | 57 | l_musr l_muid l_mgrp l_mgid \ |
michael@13 | 58 | l_rusr l_ruid l_rgrp l_rgid \ |
michael@13 | 59 | l_nusr l_nuid l_ngrp l_ngid; do |
michael@13 | 60 | query="$query; `echo $var | sed -e 's;^l_;Q_;'`=\"%{$var}\"" |
michael@13 | 61 | done |
michael@13 | 62 | eval `$prog_rpm --eval "$query" 2>/dev/null` |
michael@13 | 63 | |
michael@13 | 64 | # query OS information |
michael@13 | 65 | Q_platform=`$prog_shtool platform --type=binary 2>/dev/null |\ |
michael@13 | 66 | sed -e 's;^\([^-][^-]*-[^.-][^.-]*\)\..*$;\1;'` |
michael@13 | 67 | if [ ".$Q_platform" = . ]; then |
michael@13 | 68 | Q_platform="unknown" |
michael@13 | 69 | fi |
michael@13 | 70 | Q_discriminator=`$prog_uuid -v1 | $prog_uuid -d -- - | awk '/node:.*global unicast/ { printf("mac:%s", $2); }'` |
michael@13 | 71 | if [ ".$Q_discriminator" = . ]; then |
michael@13 | 72 | Q_discriminator=`$prog_miniperl -e 'if (-f "/etc/openpkg") { printf("inode:%s", (stat("/etc/openpkg"))[1]); }' 2>/dev/null` |
michael@13 | 73 | if [ ".$Q_discriminator" = . ]; then |
michael@13 | 74 | Q_discriminator=`$prog_shtool echo -e 'fqdn:%h%d' 2>/dev/null` |
michael@13 | 75 | fi |
michael@13 | 76 | fi |
michael@13 | 77 | } |
michael@13 | 78 | |
michael@13 | 79 | # Load Configuration |
michael@13 | 80 | do_load () { |
michael@13 | 81 | # start with reasonable defaults |
michael@13 | 82 | UUID_REGISTRY="$UUID_NIL" |
michael@13 | 83 | UUID_INSTANCE="$UUID_NIL" |
michael@13 | 84 | UUID_PLATFORM="$UUID_NIL" |
michael@13 | 85 | |
michael@13 | 86 | # load configuration (and override defaults) |
michael@13 | 87 | if [ -r $file_uuid ]; then |
michael@13 | 88 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 89 | echo "uuid: loading UUID configuration file ($file_uuid)" |
michael@13 | 90 | fi |
michael@13 | 91 | . $file_uuid |
michael@13 | 92 | fi |
michael@13 | 93 | |
michael@13 | 94 | # remember whether something was changed |
michael@13 | 95 | changed=no |
michael@13 | 96 | } |
michael@13 | 97 | |
michael@13 | 98 | # Save Configuration |
michael@13 | 99 | do_save () { |
michael@13 | 100 | if [ ".$changed" = .yes ]; then |
michael@13 | 101 | # save configuration |
michael@13 | 102 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 103 | echo "uuid: saving UUID configuration file ($file_uuid)" |
michael@13 | 104 | fi |
michael@13 | 105 | if [ -f $file_uuid ] && [ ! -w $file_uuid ]; then |
michael@13 | 106 | echo "uuid:ERROR: cannot write to $file_uuid" 1>&2 |
michael@13 | 107 | exit 1 |
michael@13 | 108 | fi |
michael@13 | 109 | ( echo "UUID_REGISTRY=\"$UUID_REGISTRY\"" |
michael@13 | 110 | echo "UUID_INSTANCE=\"$UUID_INSTANCE\"" |
michael@13 | 111 | echo "UUID_PLATFORM=\"$UUID_PLATFORM\"" |
michael@13 | 112 | ) >$file_uuid.new || exit $? |
michael@13 | 113 | n=`egrep 'UUID_(REGISTRY|INSTANCE|PLATFORM)="[0-9a-f-]*"' \ |
michael@13 | 114 | $file_uuid.new | wc -l | awk '{ print $1; }'` |
michael@13 | 115 | if [ ".$n" != .3 ]; then |
michael@13 | 116 | echo "uuid:ERROR: failed to update $file_uuid" 1>&2 |
michael@13 | 117 | rm -f $file_uuid.new |
michael@13 | 118 | exit 1 |
michael@13 | 119 | fi |
michael@13 | 120 | cp $file_uuid.new $file_uuid || exit $? |
michael@13 | 121 | rm -f $file_uuid.new || true |
michael@13 | 122 | chown $musr:$mgrp $file_uuid >/dev/null 2>&1 || true |
michael@13 | 123 | chmod 644 $file_uuid >/dev/null 2>&1 || true |
michael@13 | 124 | |
michael@13 | 125 | # remember that no more changes exist |
michael@13 | 126 | changed=no |
michael@13 | 127 | fi |
michael@13 | 128 | } |
michael@13 | 129 | |
michael@13 | 130 | # Reset UUIDs |
michael@13 | 131 | do_reset () { |
michael@13 | 132 | # reset all UUIDs to the "Nil UUID" |
michael@13 | 133 | if [ ".$UUID_REGISTRY" != ".$UUID_NIL" ]; then |
michael@13 | 134 | UUID_REGISTRY="$UUID_NIL" |
michael@13 | 135 | changed=yes |
michael@13 | 136 | fi |
michael@13 | 137 | if [ ".$UUID_INSTANCE" != ".$UUID_NIL" ]; then |
michael@13 | 138 | UUID_INSTANCE="$UUID_NIL" |
michael@13 | 139 | changed=yes |
michael@13 | 140 | fi |
michael@13 | 141 | if [ ".$UUID_PLATFORM" != ".$UUID_NIL" ]; then |
michael@13 | 142 | UUID_PLATFORM="$UUID_NIL" |
michael@13 | 143 | changed=yes |
michael@13 | 144 | fi |
michael@13 | 145 | } |
michael@13 | 146 | |
michael@13 | 147 | # Update UUIDs |
michael@13 | 148 | do_update () { |
michael@13 | 149 | # update registry UUID |
michael@13 | 150 | if [ ".$UUID_REGISTRY" = ".$UUID_NIL" -o ".$UUID_REGISTRY" = . ]; then |
michael@13 | 151 | opt="" |
michael@13 | 152 | if [ ".$opt_m" = .yes ]; then |
michael@13 | 153 | opt="-m" |
michael@13 | 154 | fi |
michael@13 | 155 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 156 | echo "uuid: calculating OpenPKG Registry UUID (UUID_REGISTRY):" |
michael@13 | 157 | echo "uuid: << $prog_uuid -v1 $opt" |
michael@13 | 158 | fi |
michael@13 | 159 | uuid=`$prog_uuid -v1 $opt` |
michael@13 | 160 | if [ ".$UUID_REGISTRY" != ".$uuid" -a ".$uuid" != . ]; then |
michael@13 | 161 | UUID_REGISTRY="$uuid" |
michael@13 | 162 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 163 | echo "uuid: >> $UUID_REGISTRY (NOT REPEATABLE)" |
michael@13 | 164 | fi |
michael@13 | 165 | changed=yes |
michael@13 | 166 | fi |
michael@13 | 167 | fi |
michael@13 | 168 | |
michael@13 | 169 | # update instance UUID |
michael@13 | 170 | name="${Q_openpkg_release}" |
michael@13 | 171 | name="$name:${Q_prefix}" |
michael@13 | 172 | name="$name:${Q_susr}:${Q_suid}:${Q_sgrp}:${Q_sgid}" |
michael@13 | 173 | name="$name:${Q_musr}:${Q_muid}:${Q_mgrp}:${Q_mgid}" |
michael@13 | 174 | name="$name:${Q_rusr}:${Q_ruid}:${Q_rgrp}:${Q_rgid}" |
michael@13 | 175 | name="$name:${Q_nusr}:${Q_nuid}:${Q_ngrp}:${Q_ngid}" |
michael@13 | 176 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 177 | echo "uuid: querying OpenPKG Instance OID" |
michael@13 | 178 | echo "uuid: << $prog_rpm --eval '%{l_openpkg_oid_instance}'" |
michael@13 | 179 | fi |
michael@13 | 180 | OID_NS_INSTANCE="`$prog_rpm --eval '%{l_openpkg_oid_instance}'`" |
michael@13 | 181 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 182 | echo "uuid: >> $OID_NS_INSTANCE" |
michael@13 | 183 | fi |
michael@13 | 184 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 185 | echo "uuid: calculating OpenPKG Instance Namespace UUID" |
michael@13 | 186 | echo "uuid: << $prog_uuid -v3 ns:OID \"$OID_NS_INSTANCE\"" |
michael@13 | 187 | fi |
michael@13 | 188 | UUID_NS_INSTANCE=`$prog_uuid -v3 ns:OID "$OID_NS_INSTANCE"` |
michael@13 | 189 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 190 | echo "uuid: >> $UUID_NS_INSTANCE" |
michael@13 | 191 | fi |
michael@13 | 192 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 193 | echo "uuid: calculating OpenPKG Instance UUID (UUID_INSTANCE):" |
michael@13 | 194 | echo "uuid: << $prog_uuid -v3 \"$UUID_NS_INSTANCE\" \"$name\"" |
michael@13 | 195 | fi |
michael@13 | 196 | uuid=`$prog_uuid -v3 "$UUID_NS_INSTANCE" "$name"` |
michael@13 | 197 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 198 | echo "uuid: >> $uuid" |
michael@13 | 199 | fi |
michael@13 | 200 | if [ ".$UUID_INSTANCE" != ".$uuid" -a ".$uuid" != . ]; then |
michael@13 | 201 | UUID_INSTANCE="$uuid" |
michael@13 | 202 | changed=yes |
michael@13 | 203 | fi |
michael@13 | 204 | |
michael@13 | 205 | # update platform UUID |
michael@13 | 206 | name="${Q_platform}" |
michael@13 | 207 | name="$name:${Q_discriminator}" |
michael@13 | 208 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 209 | echo "uuid: querying OpenPKG Platform OID" |
michael@13 | 210 | echo "uuid: << $prog_rpm --eval '%{l_openpkg_oid_platform}'" |
michael@13 | 211 | fi |
michael@13 | 212 | OID_NS_PLATFORM="`$prog_rpm --eval '%{l_openpkg_oid_platform}'`" |
michael@13 | 213 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 214 | echo "uuid: >> $OID_NS_PLATFORM" |
michael@13 | 215 | fi |
michael@13 | 216 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 217 | echo "uuid: calculating OpenPKG Platform Namespace UUID" |
michael@13 | 218 | echo "uuid: << $prog_uuid -v3 ns:OID \"$OID_NS_PLATFORM\"" |
michael@13 | 219 | fi |
michael@13 | 220 | UUID_NS_PLATFORM=`$prog_uuid -v3 ns:OID "$OID_NS_PLATFORM"` |
michael@13 | 221 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 222 | echo "uuid: >> $UUID_NS_PLATFORM" |
michael@13 | 223 | fi |
michael@13 | 224 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 225 | echo "uuid: calculating OpenPKG Platform UUID (UUID_PLATFORM):" |
michael@13 | 226 | echo "uuid: << $prog_uuid -v3 \"$UUID_NS_PLATFORM\" \"$name\"" |
michael@13 | 227 | fi |
michael@13 | 228 | uuid=`$prog_uuid -v3 "$UUID_NS_PLATFORM" "$name"` |
michael@13 | 229 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 230 | echo "uuid: >> $uuid" |
michael@13 | 231 | fi |
michael@13 | 232 | if [ ".$UUID_PLATFORM" != ".$uuid" -a ".$uuid" != . ]; then |
michael@13 | 233 | UUID_PLATFORM="$uuid" |
michael@13 | 234 | changed=yes |
michael@13 | 235 | fi |
michael@13 | 236 | } |
michael@13 | 237 | |
michael@13 | 238 | # Info about input and resulting UUIDs |
michael@13 | 239 | do_info () { |
michael@13 | 240 | echo "OpenPKG Summary of Identification Information" |
michael@13 | 241 | echo "=============================================" |
michael@13 | 242 | echo "" |
michael@13 | 243 | echo "OpenPKG Registry" |
michael@13 | 244 | time=""; clock=""; node="" |
michael@13 | 245 | eval `$prog_uuid -d "$UUID_REGISTRY" 2>/dev/null |\ |
michael@13 | 246 | sed -e 's/^/X/' \ |
michael@13 | 247 | -e 's/X.*time: *\(.*\)$/time="\1";/' \ |
michael@13 | 248 | -e 's/X.*clock: *\(.*\)$/clock="\1";/' \ |
michael@13 | 249 | -e 's/X.*node: *\(.*\)$/node="\1";/' \ |
michael@13 | 250 | -e 's/^X.*//'` |
michael@13 | 251 | echo " System Time: ${time:-unknown}" |
michael@13 | 252 | echo " System Clock Sequence: ${clock:-unknown}" |
michael@13 | 253 | echo " System Node Address: ${node:-unknown}" |
michael@13 | 254 | echo " UUID_REGISTRY: $UUID_REGISTRY" |
michael@13 | 255 | echo "" |
michael@13 | 256 | echo "OpenPKG Instance" |
michael@13 | 257 | echo " Release: ${Q_openpkg_release}" |
michael@13 | 258 | echo " Prefix: ${Q_prefix}" |
michael@13 | 259 | echo " Super Account: ${Q_susr}(${Q_suid}):${Q_sgrp}(${Q_sgid})" |
michael@13 | 260 | echo " Management Account: ${Q_musr}(${Q_muid}):${Q_mgrp}(${Q_mgid})" |
michael@13 | 261 | echo " Restricted Account: ${Q_rusr}(${Q_ruid}):${Q_rgrp}(${Q_rgid})" |
michael@13 | 262 | echo " Nonprivileged Account: ${Q_nusr}(${Q_nuid}):${Q_ngrp}(${Q_ngid})" |
michael@13 | 263 | echo " UUID_INSTANCE: $UUID_INSTANCE" |
michael@13 | 264 | echo "" |
michael@13 | 265 | echo "OpenPKG Platform" |
michael@13 | 266 | echo " Platform Id: $Q_platform" |
michael@13 | 267 | echo " Discriminator: $Q_discriminator" |
michael@13 | 268 | echo " UUID_PLATFORM: $UUID_PLATFORM" |
michael@13 | 269 | echo "" |
michael@13 | 270 | echo "(run \"$0 --verbose update\" to reproduce the UUID generation)" |
michael@13 | 271 | } |
michael@13 | 272 | |
michael@13 | 273 | # Command Line Dispatching |
michael@13 | 274 | cmd="$1" |
michael@13 | 275 | shift |
michael@13 | 276 | case "$cmd" in |
michael@13 | 277 | reset ) |
michael@13 | 278 | do_load; do_reset; do_save |
michael@13 | 279 | ;; |
michael@13 | 280 | update ) |
michael@13 | 281 | do_query; do_load; do_update; do_save |
michael@13 | 282 | ;; |
michael@13 | 283 | info ) |
michael@13 | 284 | do_query; do_load; do_info |
michael@13 | 285 | ;; |
michael@13 | 286 | * ) |
michael@13 | 287 | echo "uuid:ERROR: invalid command \"$cmd\"" 1>&2 |
michael@13 | 288 | exit 1 |
michael@13 | 289 | ;; |
michael@13 | 290 | esac |
michael@13 | 291 |