home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnuawk.zip / awklib / eg / lib / passwdawk.in < prev    next >
Text File  |  1997-03-15  |  1KB  |  57 lines

  1. # passwd.awk --- access password file information
  2. # Arnold Robbins, arnold@gnu.ai.mit.edu, Public Domain
  3. # May 1993
  4.  
  5. BEGIN {
  6.     # tailor this to suit your system
  7.     _pw_awklib = "/usr/local/libexec/awk/"
  8. }
  9.  
  10. function _pw_init(    oldfs, oldrs, olddol0, pwcat)
  11. {
  12.     if (_pw_inited)
  13.         return
  14.     oldfs = FS
  15.     oldrs = RS
  16.     olddol0 = $0
  17.     FS = ":"
  18.     RS = "\n"
  19.     pwcat = _pw_awklib "pwcat"
  20.     while ((pwcat | getline) > 0) {
  21.         _pw_byname[$1] = $0
  22.         _pw_byuid[$3] = $0
  23.         _pw_bycount[++_pw_total] = $0
  24.     }
  25.     close(pwcat)
  26.     _pw_count = 0
  27.     _pw_inited = 1
  28.     FS = oldfs
  29.     RS = oldrs
  30.     $0 = olddol0
  31. }
  32. function getpwnam(name)
  33. {
  34.     _pw_init()
  35.     if (name in _pw_byname)
  36.         return _pw_byname[name]
  37.     return ""
  38. }
  39. function getpwuid(uid)
  40. {
  41.     _pw_init()
  42.     if (uid in _pw_byuid)
  43.         return _pw_byuid[uid]
  44.     return ""
  45. }
  46. function getpwent()
  47. {
  48.     _pw_init()
  49.     if (_pw_count < _pw_total)
  50.         return _pw_bycount[++_pw_count]
  51.     return ""
  52. }
  53. function endpwent()
  54. {
  55.     _pw_count = 0
  56. }
  57.