Last change
on this file since 1158 was 1046, checked in by alloc, 8 years ago |
Daodan: Added Windows MinGW and build batch file
|
File size:
1.8 KB
|
Line | |
---|
1 | # group.awk --- functions for dealing with the group file
|
---|
2 | #
|
---|
3 | # Arnold Robbins, arnold@skeeve.com, Public Domain
|
---|
4 | # May 1993
|
---|
5 | # Revised October 2000
|
---|
6 |
|
---|
7 | BEGIN \
|
---|
8 | {
|
---|
9 | # Change to suit your system
|
---|
10 | _gr_awklib = "/usr/sbin/awk/"
|
---|
11 | }
|
---|
12 |
|
---|
13 | function _gr_init( oldfs, oldrs, olddol0, grcat,
|
---|
14 | using_fw, n, a, i)
|
---|
15 | {
|
---|
16 | if (_gr_inited)
|
---|
17 | return
|
---|
18 |
|
---|
19 | oldfs = FS
|
---|
20 | oldrs = RS
|
---|
21 | olddol0 = $0
|
---|
22 | using_fw = (PROCINFO["FS"] == "FIELDWIDTHS")
|
---|
23 | FS = ":"
|
---|
24 | RS = "\n"
|
---|
25 |
|
---|
26 | grcat = _gr_awklib "grcat"
|
---|
27 | while ((grcat | getline) > 0) {
|
---|
28 | if ($1 in _gr_byname)
|
---|
29 | _gr_byname[$1] = _gr_byname[$1] "," $4
|
---|
30 | else
|
---|
31 | _gr_byname[$1] = $0
|
---|
32 | if ($3 in _gr_bygid)
|
---|
33 | _gr_bygid[$3] = _gr_bygid[$3] "," $4
|
---|
34 | else
|
---|
35 | _gr_bygid[$3] = $0
|
---|
36 |
|
---|
37 | n = split($4, a, "[ \t]*,[ \t]*")
|
---|
38 | for (i = 1; i <= n; i++)
|
---|
39 | if (a[i] in _gr_groupsbyuser)
|
---|
40 | _gr_groupsbyuser[a[i]] = \
|
---|
41 | _gr_groupsbyuser[a[i]] " " $1
|
---|
42 | else
|
---|
43 | _gr_groupsbyuser[a[i]] = $1
|
---|
44 |
|
---|
45 | _gr_bycount[++_gr_count] = $0
|
---|
46 | }
|
---|
47 | close(grcat)
|
---|
48 | _gr_count = 0
|
---|
49 | _gr_inited++
|
---|
50 | FS = oldfs
|
---|
51 | if (using_fw)
|
---|
52 | FIELDWIDTHS = FIELDWIDTHS
|
---|
53 | RS = oldrs
|
---|
54 | $0 = olddol0
|
---|
55 | }
|
---|
56 | function getgrnam(group)
|
---|
57 | {
|
---|
58 | _gr_init()
|
---|
59 | if (group in _gr_byname)
|
---|
60 | return _gr_byname[group]
|
---|
61 | return ""
|
---|
62 | }
|
---|
63 | function getgrgid(gid)
|
---|
64 | {
|
---|
65 | _gr_init()
|
---|
66 | if (gid in _gr_bygid)
|
---|
67 | return _gr_bygid[gid]
|
---|
68 | return ""
|
---|
69 | }
|
---|
70 | function getgruser(user)
|
---|
71 | {
|
---|
72 | _gr_init()
|
---|
73 | if (user in _gr_groupsbyuser)
|
---|
74 | return _gr_groupsbyuser[user]
|
---|
75 | return ""
|
---|
76 | }
|
---|
77 | function getgrent()
|
---|
78 | {
|
---|
79 | _gr_init()
|
---|
80 | if (++_gr_count in _gr_bycount)
|
---|
81 | return _gr_bycount[_gr_count]
|
---|
82 | return ""
|
---|
83 | }
|
---|
84 | function endgrent()
|
---|
85 | {
|
---|
86 | _gr_count = 0
|
---|
87 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.