summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/glibc/glibc/makedbs.sh
blob: 7d51a673521887d9c759ec570b100f94abc28ef9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/sh

#
# Make passwd.db, group.db, etc.
#

VAR_DB=/var/db

# Use make if available
if [ -x /usr/bin/make -o -x /bin/make ]; then
	make -C $VAR_DB
	exit 0
fi

# No make available, do it in hard way

# passwd.db
if [ -e /etc/passwd ]; then
target=$VAR_DB/passwd.db
echo -n "passwd... "
awk 'BEGIN { FS=":"; OFS=":" } \
 /^[ \t]*$$/ { next } \
 /^[ \t]*#/ { next } \
 /^[^#]/ { printf ".%s ", $$1; print; \
	   printf "=%s ", $$3; print }' /etc/passwd | \
makedb --quiet -o $target -
echo "done."
fi

# group.db
if [ -e /etc/group ]; then
target=$VAR_DB/group.db
echo -n "group... "
awk 'BEGIN { FS=":"; OFS=":" } \
 /^[ \t]*$$/ { next } \
 /^[ \t]*#/ { next } \
 /^[^#]/ { printf ".%s ", $$1; print; \
	   printf "=%s ", $$3; print; \
	   if ($$4 != "") { \
	     split($$4, grmems, ","); \
	     for (memidx in grmems) { \
	       mem=grmems[memidx]; \
	       if (members[mem] == "") \
		 members[mem]=$$3; \
	       else \
		 members[mem]=members[mem] "," $$3; \
	     } \
	     delete grmems; } } \
 END { for (mem in members) \
	 printf ":%s %s %s\n", mem, mem, members[mem]; }' /etc/group | \
makedb --quiet -o $target -
echo "done."
fi

# ethers.db
if [ -e /etc/ethers ]; then
target=$VAR_DB/ethers.db
echo -n "ethers... "
awk '/^[ \t]*$$/ { next } \
 /^[ \t]*#/ { next } \
 /^[^#]/ { printf ".%s ", $$1; print; \
	   printf "=%s ", $$2; print }' /etc/ethers | \
makedb --quiet -o $target -
echo "done."
fi

# protocols.db
if [ -e /etc/protocols ]; then
target=$VAR_DB/protocols.db
echo -n "protocols... "
awk '/^[ \t]*$$/ { next } \
 /^[ \t]*#/ { next } \
 /^[^#]/ { printf ".%s ", $$1; print; \
	   printf "=%s ", $$2; print; \
	   for (i = 3; i <= NF && !($$i ~ /^#/); ++i) \
	     { printf ".%s ", $$i; print } }' /etc/protocols | \
makedb --quiet -o $target -
echo "done."
fi

# rpc.db
if [ -e /etc/rpc ]; then
target=$VAR_DB/rpc.db
echo -n "rpc... "
awk '/^[ \t]*$$/ { next } \
 /^[ \t]*#/ { next } \
 /^[^#]/ { printf ".%s ", $$1; print; \
	   printf "=%s ", $$2; print; \
	   for (i = 3; i <= NF && !($$i ~ /^#/); ++i) \
	     { printf ".%s ", $$i; print } }' /etc/rpc | \
makedb --quiet -o $target -
echo "done."
fi

# services.db
if [ -e /etc/services ]; then
target=$VAR_DB/services.db
echo -n "services... "
awk 'BEGIN { FS="[ \t/]+" } \
 /^[ \t]*$$/ { next } \
 /^[ \t]*#/ { next } \
 /^[^#]/ { sub(/[ \t]*#.*$$/, "");\
	   printf ":%s/%s ", $$1, $$3; print; \
	   printf ":%s/ ", $$1; print; \
	   printf "=%s/%s ", $$2, $$3; print; \
	   printf "=%s/ ", $$2; print; \
	   for (i = 4; i <= NF && !($$i ~ /^#/); ++i) \
	     { printf ":%s/%s ", $$i, $$3; print; \
	       printf ":%s/ ", $$i; print } }' /etc/services | \
makedb --quiet -o $target -
echo "done."
fi

# shadow.db
if [ -e /etc/shadow ]; then
target=$VAR_DB/shadow.db
echo -n "shadow... "
awk 'BEGIN { FS=":"; OFS=":" } \
 /^[ \t]*$$/ { next } \
 /^[ \t]*#/ { next } \
 /^[^#]/ { printf ".%s ", $$1; print }' /etc/shadow | \
(umask 077 && makedb --quiet -o $target -)
echo "done."
if chgrp shadow $target 2>/dev/null; then
	chmod g+r $target
else
	chown 0 $target; chgrp 0 $target; chmod 600 $target;
	echo
	echo "Warning: The shadow password database $target"
	echo "has been set to be readable only by root.  You may want"
	echo "to make it readable by the \`shadow' group depending"
	echo "on your configuration."
	echo
fi
fi

# gshadow.db
if [ -e /etc/gshadow ]; then
target=$VAR_DB/gshadow.db
echo -n "gshadow... "
awk 'BEGIN { FS=":"; OFS=":" } \
 /^[ \t]*$$/ { next } \
 /^[ \t]*#/ { next } \
 /^[^#]/ { printf ".%s ", $$1; print }' /etc/gshadow | \
(umask 077 && makedb --quiet -o $target -)
echo "done."
if chgrp shadow $target 2>/dev/null; then
	chmod g+r $target
else
	chown 0 $target; chgrp 0 $target; chmod 600 $target
	echo
	echo "Warning: The shadow group database $target"
	echo "has been set to be readable only by root.  You may want"
	echo "to make it readable by the \`shadow' group depending"
	echo "on your configuration."
	echo
fi
fi

# netgroup.db
if [ -e /etc/netgroup ]; then
target=$VAR_DB/netgroup.db
echo -n "netgroup... "
awk 'BEGIN { ini=1 } \
 /^[ \t]*$$/ { next } \
 /^[ \t]*#/ { next } \
 /^[^#]/ { if (sub(/[ \t]*\\$$/, " ") == 0) end="\n"; \
	   else end=""; \
	   gsub(/[ \t]+/, " "); \
	   sub(/^[ \t]*/, ""); \
	   if (ini == 0) printf "%s%s", $$0, end; \
	   else printf ".%s %s%s", $$1, $$0, end; \
	   ini=end == "" ? 0 : 1; } \
 END { if (ini==0) printf "\n" }' /etc/netgroup | \
makedb --quiet -o $target
echo "done."
fi