1 |
I wonder if it would be possible to use the script from sys-apps/getent(included below) |
2 |
to impl. getent in user.eclass instead of using glibc's getent? I cannot see any downside, is there one? |
3 |
|
4 |
This would help a lot(just seed your groups/users is in ROOT/etc/{passwd,group ...} first) |
5 |
when cross building or ROOT != / as it would be trivial for the script to respect ROOT/EPREFIX |
6 |
|
7 |
sys-apps/getent: |
8 |
#!/bin/sh |
9 |
# |
10 |
# Closely (not perfectly) emulate the behavior of glibc's getent utility |
11 |
# |
12 |
#passwd|shadow|group|aliases|hosts|networks|ethers|netgroup|protocols|services|rpc |
13 |
# only returns the first match (by design) |
14 |
# dns based search is not supported (hosts,networks) |
15 |
# case-insensitive matches not supported (ethers; others?) |
16 |
# may return false-positives (hosts,protocols,rpc,services,ethers) |
17 |
|
18 |
[ -z "$PATH" ] && PATH="/bin:/usr/bin" || PATH="${PATH}:/bin:/usr/bin" export PATH |
19 |
|
20 |
file="/etc/$1" |
21 |
case $1 in |
22 |
passwd|group) |
23 |
match="^$2:\|^[^:]*:[^:]*:$2:" ;; |
24 |
shadow) |
25 |
match="^$2:" ;; |
26 |
networks|netgroup) |
27 |
match="^[[:space:]]*$2\>" ;; |
28 |
hosts|protocols|rpc|services|ethers) |
29 |
match="\<$2\>" ;; |
30 |
aliases) |
31 |
match="^[[:space:]]*$2[[:space:]]*:" ;; |
32 |
""|-h|--help) |
33 |
echo "USAGE: $0 database [key]" |
34 |
exit 0 ;; |
35 |
*) |
36 |
echo "$0: Unknown database: $1" 1>&2 |
37 |
exit 1 ;; |
38 |
esac |
39 |
|
40 |
if [ ! -f "$file" ] ; then |
41 |
echo "$0: Could not find database file for $1" 1>&2 |
42 |
exit 1 |
43 |
fi |
44 |
|
45 |
if [ $# -eq 1 ] ; then |
46 |
exec cat "$file" |
47 |
else |
48 |
sed "s/#.*//; /$match/q; d" "$file" | grep . || exit 2 |
49 |
fi |