codekingpro/portable-devtools
114k
1# passwd.awk --- access password file information2#3# This file and how to use it are described in the manual.4# Therefore, we respectfully advise you to Read The Fine Manual5# for more information.6#7# Arnold Robbins, arnold@skeeve.com, Public Domain8# May 19939# Revised October 200010# Revised December 201011 12BEGIN {13 # tailor this to suit your system14 _pw_awklib = "/usr/lib/awk/"15}16 17function _pw_init( oldfs, oldrs, olddol0, pwcat, using_fw, using_fpat)18{19 if (_pw_inited)20 return21 22 oldfs = FS23 oldrs = RS24 olddol0 = $025 using_fw = (PROCINFO["FS"] == "FIELDWIDTHS")26 using_fpat = (PROCINFO["FS"] == "FPAT")27 FS = ":"28 RS = "\n"29 30 pwcat = _pw_awklib "pwcat"31 while ((pwcat | getline) > 0) {32 _pw_byname[$1] = $033 _pw_byuid[$3] = $034 _pw_bycount[++_pw_total] = $035 }36 close(pwcat)37 _pw_count = 038 _pw_inited = 139 FS = oldfs40 if (using_fw)41 FIELDWIDTHS = FIELDWIDTHS42 else if (using_fpat)43 FPAT = FPAT44 RS = oldrs45 $0 = olddol046}47function getpwnam(name)48{49 _pw_init()50 return _pw_byname[name]51}52function getpwuid(uid)53{54 _pw_init()55 return _pw_byuid[uid]56}57function getpwent()58{59 _pw_init()60 if (_pw_count < _pw_total)61 return _pw_bycount[++_pw_count]62 return ""63}64function endpwent()65{66 _pw_count = 067}68 