Debian Codegraph @

awklib/eg/lib/ns_passwd.awk

raw
1 # ns_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 # Reworked for namespaces June 2017, with help from
9 # Andrew J.: Schorr, [email protected]
10
11 @namespace "passwd"
12
13 BEGIN {
14 # tailor this to suit your system
15 Awklib = "/usr/local/libexec/awk/"
16 }
17
18 function Init( oldfs, oldrs, olddol0, pwcat, using_fw, using_fpat)
19 {
20 if (Inited)
21 return
22
23 oldfs = FS
24 oldrs = RS
25 olddol0 = $0
26 using_fw = (PROCINFO["FS"] == "FIELDWIDTHS")
27 using_fpat = (PROCINFO["FS"] == "FPAT")
28 FS = ":"
29 RS = "\n"
30
31 pwcat = Awklib "pwcat"
32 while ((pwcat | getline) > 0) {
33 Byname[$1] = $0
34 Byuid[$3] = $0
35 Bycount[++Total] = $0
36 }
37 close(pwcat)
38 Count = 0
39 Inited = 1
40 FS = oldfs
41 if (using_fw)
42 FIELDWIDTHS = FIELDWIDTHS
43 else if (using_fpat)
44 FPAT = FPAT
45 RS = oldrs
46 $0 = olddol0
47 }
48
49 function awk::getpwnam(name)
50 {
51 Init()
52 return Byname[name]
53 }
54
55 function awk::getpwuid(uid)
56 {
57 Init()
58 return Byuid[uid]
59 }
60
61 function awk::getpwent()
62 {
63 Init()
64 if (Count < Total)
65 return Bycount[++Count]
66 return ""
67 }
68
69 function awk::endpwent()
70 {
71 Count = 0
72 }