Print this page
XXX Remove nawk(1)

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libsecdb/common/i.rbac
          +++ new/usr/src/lib/libsecdb/common/i.rbac
↓ open down ↓ 41 lines elided ↑ open up ↑
  42   42  
  43   43  tmp_dir=${TMPDIR:-/tmp}
  44   44  
  45   45  PATH="/usr/bin:/usr/sbin:${PATH}"
  46   46  export PATH
  47   47  
  48   48  basename_cmd=basename
  49   49  cp_cmd=cp
  50   50  egrep_cmd=egrep
  51   51  mv_cmd=mv
  52      -nawk_cmd=nawk
       52 +awk_cmd=/usr/xpg4/bin/awk
  53   53  rm_cmd=rm
  54   54  sed_cmd=sed
  55   55  sort_cmd=sort
  56   56  
  57   57  # $1 is the type
  58   58  # $2 is the "old/existing file"
  59   59  # $3 is the "new (to be merged)" file
  60   60  # $4 is the output file
  61   61  # returns 0 on success
  62      -# returns 2 on failure if nawk fails with non-zero exit status
       62 +# returns 2 on failure if awk fails with non-zero exit status
  63   63  #
  64   64  dbmerge() {
  65   65  #
  66   66  # Remove the ident lines.
  67   67  #
  68   68          ${egrep_cmd} -v '^#[pragma      ]*ident' $2 > $4.old 2>/dev/null
  69   69  #
  70   70  # If the new file has a Sun copyright, remove the Sun copyright from the old
  71   71  # file.
  72   72  #
↓ open down ↓ 73 lines elided ↑ open up ↑
 146  146              -e '/\\$/{N;s/\\\n//;}'  -e '/\\$/{N;s/\\\n//;}' \
 147  147              -e '/\\$/{N;s/\\\n//;}'  -e '/\\$/{N;s/\\\n//;}' \
 148  148              -e '/\\$/{N;s/\\\n//;}'  -e '/\\$/{N;s/\\\n//;}' \
 149  149              $2 > $4.old
 150  150          $sed_cmd \
 151  151              -e '/\\$/{N;s/\\\n//;}'  -e '/\\$/{N;s/\\\n//;}' \
 152  152              -e '/\\$/{N;s/\\\n//;}'  -e '/\\$/{N;s/\\\n//;}' \
 153  153              -e '/\\$/{N;s/\\\n//;}'  -e '/\\$/{N;s/\\\n//;}' \
 154  154              $3 > $4.new
 155  155  #
 156      -# The nawk script below processes the old and new files using up to
      156 +# The awk script below processes the old and new files using up to
 157  157  # three passes.  If the old file is empty, only the final pass over
 158  158  # the new file is required.
 159  159  #
 160  160          if [ -s $4.old ]; then
 161      -                nawk_pass1=$4.old
 162      -                nawk_pass2=$4.new
 163      -                nawk_pass3=$4.new
      161 +                awk_pass1=$4.old
      162 +                awk_pass2=$4.new
      163 +                awk_pass3=$4.new
 164  164          else
 165      -                nawk_pass1=
 166      -                nawk_pass2=
 167      -                nawk_pass3=$4.new
      165 +                awk_pass1=
      166 +                awk_pass2=
      167 +                awk_pass3=$4.new
 168  168          fi
 169  169  #
 170      -#!/usr/bin/nawk -f
      170 +#!/usr/xpg4/bin/awk -f
 171  171  #
 172  172  #       dbmerge type=[auth|prof|user|exec] [ old-file new-file ] new-file
 173  173  #
 174  174  #       Merge two versions of an RBAC database file. The output
 175  175  #       consists of the lines from the new-file, while preserving
 176  176  #       user customizations in the old-file.
 177  177  #
 178  178  #       Entries in the new-file replace corresponding entries in the
 179  179  #       old-file, except as follows:  For exec_attr, all old entries
 180  180  #       for profiles contained in the new-file are discarded.  For
↓ open down ↓ 10 lines elided ↑ open up ↑
 191  191  #       "root" where values from the old-file are always retained.
 192  192  #
 193  193  #       [1] The following file type and keyword combinations are merged:
 194  194  #           prof_attr: auths, profiles, privs
 195  195  #           user_attr: auths, profiles, roles
 196  196  #
 197  197  #       The output is run through sort except for the comments
 198  198  #       which will appear first in the output.
 199  199  #
 200  200  #
 201      -        $nawk_cmd  '
      201 +        $awk_cmd  '
 202  202  
 203  203  # This script may be invoked with up to three file names.  Each file
 204  204  # name corresponds to a separate processing pass.  The passes are
 205  205  # defined as follows:
 206  206  #
 207  207  # Pass 1: Read existing data.
 208  208  # Data from the old-file is read into memory.
 209  209  #
 210  210  # Pass 2: Remove obsolete data.
 211  211  # Discard any data from the old-file that is part of profiles that
↓ open down ↓ 15 lines elided ↑ open up ↑
 227  227          keyword_behavior["prof", "auths"] =     "merge";
 228  228          keyword_behavior["prof", "profiles"] =  "merge";
 229  229          keyword_behavior["prof", "privs"] =     "merge";
 230  230          keyword_behavior["user", "auths"] =     "merge";
 231  231          keyword_behavior["user", "profiles"] =  "merge";
 232  232          keyword_behavior["user", "roles"] =     "merge";
 233  233  
 234  234          FS=":"
 235  235  }
 236  236  
 237      -# When FNR (current file record number) is 1 it indicates that nawk
      237 +# When FNR (current file record number) is 1 it indicates that awk
 238  238  # is starting to read the next file specified on its command line,
 239  239  # and is beginning the next processing pass.
 240  240  FNR == 1 {
 241  241          pass++;
 242  242  }
 243  243  
 244  244  /^#/ || /^$/ {
 245      -        continue;
      245 +        next;
 246  246  }
 247  247  
 248  248  {
 249      -        # For each input line, nawk automatically assigns the complete
      249 +        # For each input line, awk automatically assigns the complete
 250  250          # line to $0 and also splits the line at field separators and
 251  251          # assigns each field to a variable $1..$n.  Assignment to $0
 252  252          # re-splits the line into the field variables.  Conversely,
 253      -        # assgnment to a variable $1..$n will cause $0 to be recomputed
      253 +        # assignment to a variable $1..$n will cause $0 to be recomputed
 254  254          # from the field variable values.
 255  255          #
 256  256          # This code adds awareness of escaped field separators by using
 257  257          # a custom function to split the line into a temporary array.
 258  258          # It assigns the empty string to $0 to clear any excess field
 259  259          # variables, and assigns the desired elements of the temporary
 260  260          # array back to the field variables $1..$7.
 261  261          #
 262  262          # Subsequent code must not assign directly to $0 or the fields
 263  263          # will be re-split without regard to escaped field separators.
↓ open down ↓ 149 lines elided ↑ open up ↑
 413  413                          if (list[j] == new_list[i])
 414  414                                  break;
 415  415                  }
 416  416                  if (j > cnt)
 417  417                          list[++cnt] = new_list[i];
 418  418          }
 419  419  
 420  420          return keyword "=" unsplit(list, cnt, ",");
 421  421  }
 422  422  
 423      -# This function is similar to the nawk built-in split() function,
      423 +# This function is similar to the awk built-in split() function,
 424  424  # except that a "\" character may be used to escape any subsequent
 425  425  # character, so that the escaped character will not be treated as a
 426  426  # field separator or as part of a field separator regular expression.
 427  427  # The "\" characters will remain in the elements of the output array
 428  428  # variable upon completion.
 429  429  function split_escape(str, list, fs, cnt, saved, sep)
 430  430  {
 431  431          # default to global FS
 432  432          if (fs == "")
 433  433                  fs = FS;
↓ open down ↓ 30 lines elided ↑ open up ↑
 464  464          return cnt;
 465  465  }
 466  466  
 467  467  function unsplit(list, cnt, delim, str)
 468  468  {
 469  469          str = list[1];
 470  470          for (i = 2; i <= cnt; i++)
 471  471                  str = str delim list[i];
 472  472          return str;
 473  473  }' \
 474      -        type=$1 $nawk_pass1 $nawk_pass2 $nawk_pass3 > $4.unsorted
      474 +        type=$1 $awk_pass1 $awk_pass2 $awk_pass3 > $4.unsorted
 475  475          rc=$?
 476  476          $sort_cmd < $4.unsorted >> $4
 477  477          return $rc
 478  478  }
 479  479  
 480  480  # $1 is the merged file
 481  481  # $2 is the target file
 482  482  #
 483  483  commit() {
 484  484          # Make sure that the last mv uses rename(2) by first moving to
↓ open down ↓ 86 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX