Debian Codegraph @

awklib/eg/lib/passwdawk.in

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