Permalink
Browse files

Reenable nss_db with a completely new implementation

No longer is Berkeley db used.  Instead a simple hash function is used.
The database files are not updated once they are created and therefore
no complicated database is needed.
  • Loading branch information...
drepper committed Jun 15, 2011
1 parent 9ee76b5 commit 2666d441c2d8107b1987b869714189af64b954c6
View
@@ -1,3 +1,35 @@
+2011-06-14 Ulrich Drepper <drepper@gmail.com>
+
+ * Versions.def: Add entry for libnss_db.
+ * shlib-versions: Likewise.
+ * nss/Makefile: Add rules to build libnss_db.
+ * nss/Versions: Add libnss_db information. Organize libnss_files
+ entries better.
+ * nss/db-Makefile: Add gshadow support. Change rules for the new
+ makedb progra. Some minor improvements to generate smaller files.
+ * nss/nss_db/nss_db.h: Move NSS database header data structures to
+ here from...
+ * nss/makedb.c: ...here.
+ Improve database format to be smaller and require less memory at
+ runtime.
+ * nss/nss_db/db-XXX.x: Adjust for new database format. Don't use
+ db anymore.
+ * nss/nss_db/db-netgrp.c: Likewise.
+ * nss/nss_db/db-open.c: Likewise.
+ * nss/nss_files/flies-XXX.x: Adjust comments.
+ * nss/nss_files/files-ethers.c: Adjust for new DB_LOOKUP definition.
+ * nss/nss_files/files-grp.c: Likewise.
+ * nss/nss_files/files-hosts.c: Likewise.
+ * nss/nss_files/files-network.c: Likewise.
+ * nss/nss_files/files-proto.c: Likewise.
+ * nss/nss_files/files-pwd.c: Likewise.
+ * nss/nss_files/files-rpc.c: Likewise.
+ * nss/nss_files/files-service.c: Likewise.
+ * nss/nss_files/files-sgrp.c: Likewise.
+ * nss/nss_files/files-spwd.c: Likewise.
+ * nss/nss_db/db-alias.c: Removed.
+ * nss/nss_db/dummy-db.h: Removed.
+
2011-06-02 Ulrich Drepper <drepper@gmail.com>
* nss/makedb.c: Rewritten to not use database library.
View
@@ -67,6 +67,9 @@ libnss_compat {
libnss_dns {
GLIBC_PRIVATE
}
+libnss_db {
+ GLIBC_PRIVATE
+}
libnss_files {
GLIBC_PRIVATE
}
View
@@ -53,7 +53,7 @@ otherlibs += $(nssobjdir)/libnss_files.a $(resolvobjdir)/libnss_dns.a \
endif
# Specify rules for the nss_* modules. We have some services.
-services := files
+services := files db
extra-libs = $(services:%=libnss_%)
# These libraries will be built in the `others' pass rather than
@@ -69,10 +69,18 @@ libnss_files-routines := $(addprefix files-,$(databases)) \
files-initgroups files-have_o_cloexec
distribute += files-XXX.c files-parse.c
+libnss_db-dbs := $(addprefix db-,\
+ $(filter-out hosts network key alias,\
+ $(databases)))
+libnss_db-routines := $(libnss_db-dbs) db-open hash-string
+generated += $(filter-out db-alias.c db-netgrp.c, \
+ $(addsuffix .c,$(libnss_db-dbs)))
+distribute += $(addprefix nss_db/, db-XXX.c nss_db.h)
# Build static module if requested
ifneq ($(build-static-nss),yes)
libnss_files-inhibit-o = $(filter-out .os,$(object-suffixes))
+libnss_db-inhibit-o = $(filter-out .os,$(object-suffixes))
endif
include ../Rules
@@ -93,6 +101,15 @@ libnss-libc = $(common-objpfx)linkobj/libc.so
$(services:%=$(objpfx)libnss_%.so): $(libnss-libc) \
$(common-objpfx)libc_nonshared.a
+$(objpfx)libnss_db.so: $(objpfx)libnss_files.so
+
+$(libnss_db-dbs:%=$(objpfx)%.c): $(objpfx)db-%.c: nss_files/files-%.c
+ @rm -f $@.new
+ (echo '#define EXTERN_PARSER';\
+ echo '#define GENERIC "../nss_db/db-XXX.c"';\
+ echo '#include "$<"') > $@.new
+ mv -f $@.new $@
+
$(objpfx)makedb: $(makedb-modules:%=$(objpfx)%.o)
View
@@ -27,6 +27,8 @@ libnss_files {
_nss_files_endetherent;
_nss_files_getetherent_r;
_nss_files_parse_etherent;
+ _nss_files_gethostton_r;
+ _nss_files_getntohost_r;
_nss_files_setgrent;
_nss_files_endgrent;
@@ -41,14 +43,12 @@ libnss_files {
_nss_files_gethostbyname4_r;
_nss_files_gethostbyname_r;
_nss_files_gethostent_r;
- _nss_files_gethostton_r;
_nss_files_setnetent;
_nss_files_endnetent;
_nss_files_getnetbyaddr_r;
_nss_files_getnetbyname_r;
_nss_files_getnetent_r;
- _nss_files_getntohost_r;
_nss_files_parse_netent;
_nss_files_setnetgrent;
@@ -99,3 +99,57 @@ libnss_files {
_nss_files_initgroups_dyn;
}
}
+
+libnss_db {
+ GLIBC_PRIVATE {
+ _nss_db_setetherent;
+ _nss_db_endetherent;
+ _nss_db_getetherent_r;
+ _nss_db_gethostton_r;
+ _nss_db_getntohost_r;
+
+ _nss_db_setgrent;
+ _nss_db_endgrent;
+ _nss_db_getgrent_r;
+ _nss_db_getgrgid_r;
+ _nss_db_getgrnam_r;
+
+ _nss_db_setnetgrent;
+ _nss_db_endnetgrent;
+ _nss_db_getnetgrent_r;
+
+ _nss_db_setprotoent;
+ _nss_db_endprotoent;
+ _nss_db_getprotoent_r;
+ _nss_db_getprotobyname_r;
+ _nss_db_getprotobynumber_r;
+
+ _nss_db_setpwent;
+ _nss_db_endpwent;
+ _nss_db_getpwent_r;
+ _nss_db_getpwnam_r;
+ _nss_db_getpwuid_r;
+
+ _nss_db_setrpcent;
+ _nss_db_endrpcent;
+ _nss_db_getrpcent_r;
+ _nss_db_getrpcbyname_r;
+ _nss_db_getrpcbynumber_r;
+
+ _nss_db_setservent;
+ _nss_db_endservent;
+ _nss_db_getservent_r;
+ _nss_db_getservbyname_r;
+ _nss_db_getservbyport_r;
+
+ _nss_db_setsgent;
+ _nss_db_endsgent;
+ _nss_db_getsgent_r;
+ _nss_db_getsgnam_r;
+
+ _nss_db_setspent;
+ _nss_db_endspent;
+ _nss_db_getspent_r;
+ _nss_db_getspnam_r;
+ }
+}
View
@@ -1,5 +1,5 @@
# Makefile to (re-)generate db versions of system database files.
-# Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
+# Copyright (C) 1996, 1997, 1998, 2011 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
#
@@ -20,7 +20,8 @@
# 02111-1307 USA.
DATABASES = $(wildcard /etc/passwd /etc/group /etc/ethers /etc/protocols \
- /etc/rpc /etc/services /etc/shadow /etc/netgroup)
+ /etc/rpc /etc/services /etc/shadow /etc/gshadow \
+ /etc/netgroup)
VAR_DB = /var/db
@@ -32,43 +33,37 @@ all: $(patsubst %,$(VAR_DB)/%.db,$(notdir $(DATABASES)))
$(VAR_DB)/passwd.db: /etc/passwd
@echo -n "$(patsubst %.db,%,$(@F))... "
- @$(AWK) 'BEGIN { FS=":"; OFS=":"; cnt=0 } \
+ @$(AWK) 'BEGIN { FS=":"; OFS=":" } \
/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
- { printf "0%u ", cnt++; print } \
/^[^#]/ { printf ".%s ", $$1; print; \
printf "=%s ", $$3; print }' $^ | \
$(MAKEDB) -o $@ -
@echo "done."
$(VAR_DB)/group.db: /etc/group
@echo -n "$(patsubst %.db,%,$(@F))... "
- @$(AWK) 'BEGIN { FS=":"; OFS=":"; cnt=0 } \
+ @$(AWK) 'BEGIN { FS=":"; OFS=":" } \
/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
- { printf "0%u ", cnt++; print } \
/^[^#]/ { printf ".%s ", $$1; print; \
printf "=%s ", $$3; print }' $^ | \
$(MAKEDB) -o $@ -
@echo "done."
$(VAR_DB)/ethers.db: /etc/ethers
@echo -n "$(patsubst %.db,%,$(@F))... "
- @$(AWK) 'BEGIN { cnt=0 } \
- /^[ \t]*$$/ { next } \
+ @$(AWK) '/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
- { printf "0%u ", cnt++; print } \
/^[^#]/ { printf ".%s ", $$1; print; \
printf "=%s ", $$2; print }' $^ | \
$(MAKEDB) -o $@ -
@echo "done."
$(VAR_DB)/protocols.db: /etc/protocols
@echo -n "$(patsubst %.db,%,$(@F))... "
- @$(AWK) 'BEGIN { cnt=0 } \
- /^[ \t]*$$/ { next } \
+ @$(AWK) '/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
- { printf "0%u ", cnt++; print } \
/^[^#]/ { printf ".%s ", $$1; print; \
printf "=%s ", $$2; print; \
for (i = 3; i <= NF && !($$i ~ /^#/); ++i) \
@@ -78,10 +73,8 @@ $(VAR_DB)/protocols.db: /etc/protocols
$(VAR_DB)/rpc.db: /etc/rpc
@echo -n "$(patsubst %.db,%,$(@F))... "
- @$(AWK) 'BEGIN { cnt=0 } \
- /^[ \t]*$$/ { next } \
+ @$(AWK) '/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
- { printf "0%u ", cnt++; print } \
/^[^#]/ { printf ".%s ", $$1; print; \
printf "=%s ", $$2; print; \
for (i = 3; i <= NF && !($$i ~ /^#/); ++i) \
@@ -91,26 +84,25 @@ $(VAR_DB)/rpc.db: /etc/rpc
$(VAR_DB)/services.db: /etc/services
@echo -n "$(patsubst %.db,%,$(@F))... "
- @$(AWK) 'BEGIN { FS="[ \t/]+"; cnt=0 } \
+ @$(AWK) 'BEGIN { FS="[ \t/]+" } \
/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
- { printf "0%u ", cnt++; print } \
- /^[^#]/ { printf ".%s/%s ", $$1, $$3; print; \
- printf ".%s/ ", $$1; print; \
+ /^[^#]/ { 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 } }' $^ | \
+ { printf ":%s/%s ", $$i, $$3; print; \
+ printf ":%s/ ", $$i; print } }' $^ | \
$(MAKEDB) -o $@ -
@echo "done."
$(VAR_DB)/shadow.db: /etc/shadow
@echo -n "$(patsubst %.db,%,$(@F))... "
- @$(AWK) 'BEGIN { FS=":"; OFS=":"; cnt=0 } \
+ @$(AWK) 'BEGIN { FS=":"; OFS=":" } \
/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
- { printf "0%u ", cnt++; print } \
/^[^#]/ { printf ".%s ", $$1; print }' $^ | \
(umask 077 && $(MAKEDB) -o $@ -)
@echo "done."
@@ -126,14 +118,38 @@ $(VAR_DB)/shadow.db: /etc/shadow
echo; \
fi
+$(VAR_DB)/gshadow.db: /etc/gshadow
+ @echo -n "$(patsubst %.db,%,$(@F))... "
+ @$(AWK) 'BEGIN { FS=":"; OFS=":" } \
+ /^[ \t]*$$/ { next } \
+ /^[ \t]*#/ { next } \
+ /^[^#]/ { printf ".%s ", $$1; print }' $^ | \
+ (umask 077 && $(MAKEDB) -o $@ -)
+ @echo "done."
+ @if chgrp shadow $@ 2>/dev/null; then \
+ chmod g+r $@; \
+ else \
+ chown 0 $@; chgrp 0 $@; chmod 600 $@; \
+ echo; \
+ echo "Warning: The shadow group database $@"; \
+ 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
+
$(VAR_DB)/netgroup.db: /etc/netgroup
@echo -n "$(patsubst %.db,%,$(@F))... "
- @$(AWK) 'BEGIN { cnt=0 } \
+ @$(AWK) 'BEGIN { ini=1 } \
/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
- { printf "0%u ", cnt++; print } \
- /^[^#]/ { end=sub(/\\/, " "); \
+ /^[^#]/ { if (sub(/[ \t]*\\$$/, " ") == 0) end="\n"; \
+ else end=""; \
gsub(/[ \t]+/, " "); \
- if(end == 1) printf "%s", $$0; else print }' $^ | \
+ 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" }' $^ | \
$(MAKEDB) -o $@ -
@echo "done."
Oops, something went wrong.

0 comments on commit 2666d44

Please sign in to comment.