Open database files with correct mode

Make rebuilding maps during upgrade a bit more clever
This commit is contained in:
Honza Horák 2013-01-23 16:19:37 +01:00
parent a0f3e0a57c
commit a6607b423c
2 changed files with 181 additions and 9 deletions

129
ypserv-2.29-dbopen.patch Normal file
View File

@ -0,0 +1,129 @@
diff -up ypserv-2.29/lib/yp_db.c.dbopen ypserv-2.29/lib/yp_db.c
--- ypserv-2.29/lib/yp_db.c.dbopen 2012-05-30 13:28:49.000000000 +0200
+++ ypserv-2.29/lib/yp_db.c 2013-01-23 16:11:32.116224180 +0100
@@ -173,11 +173,14 @@ _db_open (const char *domain, const char
sprintf (buf, "%s/%s", domain, map);
dbp = tcbdbnew ();
- isok = tcbdbopen (dbp, buf, BDBOREADER);
+ isok = tcbdbopen (dbp, buf, BDBOREADER | BDBONOLCK);
if (debug_flag && !isok)
- log_msg ("tcbdbopen: Tokyo Cabinet Error: %s",
- tcbdberrmsg (tcbdbecode (dbp)));
+ {
+ log_msg ("tcbdbopen: Tokyo Cabinet Error: %s",
+ tcbdberrmsg (tcbdbecode (dbp)));
+ log_msg ("tcbdbopen: consider rebuilding maps using ypinit");
+ }
else if (debug_flag)
log_msg ("\t\t->Returning OK!");
}
diff -up ypserv-2.29/makedbm/makedbm.c.dbopen ypserv-2.29/makedbm/makedbm.c
--- ypserv-2.29/makedbm/makedbm.c.dbopen 2012-05-30 13:28:49.000000000 +0200
+++ ypserv-2.29/makedbm/makedbm.c 2013-01-23 16:13:32.896215921 +0100
@@ -490,6 +490,9 @@ create_file (char *fileName, char *dbmNa
#endif
#else
unlink (dbmName);
+#if defined(HAVE_LIBTC)
+ chmod(filename, S_IRUSR|S_IWUSR);
+#endif
rename (filename, dbmName);
#endif
free (filename);
@@ -517,6 +520,7 @@ dump_file (char *dbmName)
if (dbm == NULL)
{
fprintf (stderr, "makedbm: Cannot open %s\n", dbmName);
+ fprintf (stderr, "makedbm: Consider rebuilding maps using ypinit\n");
exit (1);
}
#if defined(HAVE_COMPAT_LIBGDBM)
diff -up ypserv-2.29/yphelper/yphelper.c.dbopen ypserv-2.29/yphelper/yphelper.c
--- ypserv-2.29/yphelper/yphelper.c.dbopen 2012-05-30 13:28:50.000000000 +0200
+++ ypserv-2.29/yphelper/yphelper.c 2013-01-23 16:11:32.117224180 +0100
@@ -507,10 +507,10 @@ get_dbm_entry (char *key, char *map, cha
#if defined(HAVE_COMPAT_LIBGDBM)
dbm = gdbm_open (mappath, 0, GDBM_READER, 0600, NULL);
#elif defined(HAVE_NDBM)
- dbm = dbm_open (mappath, O_CREAT | O_RDWR, 0600);
+ dbm = dbm_open (mappath, O_RDONLY, 0600);
#elif defined(HAVE_LIBTC)
dbm = tcbdbnew();
- if (!tcbdbopen(dbm, mappath, BDBOWRITER | BDBOCREAT))
+ if (!tcbdbopen(dbm, mappath, BDBOREADER))
{
tcbdbdel(dbm);
dbm = NULL;
@@ -519,6 +519,7 @@ get_dbm_entry (char *key, char *map, cha
if (dbm == NULL)
{
fprintf (stderr, "yphelper: cannot open %s\n", mappath);
+ fprintf (stderr, "yphelper: consider rebuilding maps using ypinit\n", mappath);
exit (1);
}
diff -up ypserv-2.29/yppush/yppush.c.dbopen ypserv-2.29/yppush/yppush.c
--- ypserv-2.29/yppush/yppush.c.dbopen 2012-08-30 09:53:16.000000000 +0200
+++ ypserv-2.29/yppush/yppush.c 2013-01-23 16:11:32.117224180 +0100
@@ -290,10 +290,10 @@ get_dbm_entry (char *key)
#if defined(HAVE_COMPAT_LIBGDBM)
dbm = gdbm_open (mappath, 0, GDBM_READER, 0600, NULL);
#elif defined(HAVE_NDBM)
- dbm = dbm_open (mappath, O_CREAT | O_RDWR, 0600);
+ dbm = dbm_open (mappath, O_RDONLY, 0600);
#elif defined(HAVE_LIBTC)
dbm = tcbdbnew();
- if (!tcbdbopen(dbm, mappath, BDBOWRITER | BDBOCREAT))
+ if (!tcbdbopen(dbm, mappath, BDBOREADER))
{
tcbdbdel(dbm);
dbm = NULL;
@@ -302,6 +302,7 @@ get_dbm_entry (char *key)
if (dbm == NULL)
{
log_msg ("YPPUSH: Cannot open %s", mappath);
+ log_msg ("YPPUSH: consider rebuilding maps using ypinit");
exit (1);
}
diff -up ypserv-2.29/ypxfr/ypxfr.c.dbopen ypserv-2.29/ypxfr/ypxfr.c
--- ypserv-2.29/ypxfr/ypxfr.c.dbopen 2013-01-23 16:11:32.068224183 +0100
+++ ypserv-2.29/ypxfr/ypxfr.c 2013-01-23 16:14:05.895213665 +0100
@@ -557,10 +557,10 @@ ypxfr (char *map, char *source_host, cha
#if defined(HAVE_COMPAT_LIBGDBM)
dbm = gdbm_open (dbName_orig, 0, GDBM_READER, 0600, NULL);
#elif defined(HAVE_NDBM)
- dbm = dbm_open (dbName_orig, O_CREAT|O_RDWR, 0600);
+ dbm = dbm_open (dbName_orig, O_RDONLY, 0600);
#elif defined(HAVE_LIBTC)
dbm = tcbdbnew ();
- if (!tcbdbopen (dbm, dbName_orig, BDBOWRITER | BDBOCREAT))
+ if (!tcbdbopen (dbm, dbName_orig, BDBOREADER))
{
tcbdbdel (dbm);
dbm = NULL;
@@ -629,7 +629,7 @@ ypxfr (char *map, char *source_host, cha
dbm = dbm_open (dbName_temp, O_CREAT|O_RDWR, 0600);
#elif defined(HAVE_LIBTC)
dbm = tcbdbnew ();
- if (!tcbdbopen (dbm, dbName_orig, BDBOWRITER | BDBOCREAT))
+ if (!tcbdbopen (dbm, dbName_orig, BDBOWRITER | BDBOCREAT | BDBOTRUNC))
{
tcbdbdel (dbm);
dbm = NULL;
@@ -782,7 +782,12 @@ ypxfr (char *map, char *source_host, cha
}
if (result == 0)
- rename (dbName_temp, dbName_orig);
+ {
+#if defined(HAVE_LIBTC)
+ chmod(dbName_temp, S_IRUSR|S_IWUSR);
+#endif
+ rename (dbName_temp, dbName_orig);
+ }
else
unlink(dbName_temp);

View File

@ -1,10 +1,10 @@
%global first_tc_version 2.28-1
%global first_tc_version 2.29-2
Summary: The NIS (Network Information Service) server
Url: http://www.linux-nis.org/nis/ypserv/index.html
Name: ypserv
Version: 2.29
Release: 5%{?dist}
Release: 6%{?dist}
License: GPLv2
Group: System Environment/Daemons
Source0: http://www.linux-nis.org/download/ypserv/ypserv-%{version}.tar.bz2
@ -35,6 +35,7 @@ Patch17: ypserv-2.27-cloexec.patch
Patch18: ypserv-2.29-sdnotify.patch
Patch19: ypserv-2.29-nomap.patch
Patch20: ypserv-2.29-relro.patch
Patch21: ypserv-2.29-dbopen.patch
BuildRequires: tokyocabinet-devel
BuildRequires: systemd-units
@ -73,6 +74,7 @@ machines.
%patch18 -p1 -b .sdnotify
%patch19 -p1 -b .nomap
%patch20 -p1 -b .relro
%patch21 -p1 -b .dbopen
autoreconf
@ -188,14 +190,51 @@ fi
# /etc/sysconfig/network, we do the same work as service yppasswdd
# do before starting.
# The original domainname value is set back in the end.
# The whole work is created before installing new ypserv, so we use old
# utilities and commands are stored into temporary file (that is necessary,
# because we cannot read old maps using new package)
# If old package used gdbm, the prepared script is executed after new package
# is installed.
%global rebuild_maps_script /var/yp/rpm_rebuild_maps
%pre
if [ $1 == 2 ] ; then
# store old domainname and set the correct one
olddomain=`domainname`
. /etc/sysconfig/network
DOMAINNAME=`domainname`
if [ "$olddomain" = "(none)" -o "x$olddomain" = "x" ]; then
if [ -n "$NISDOMAIN" ]; then
domainname $NISDOMAIN
fi
fi
newdomain=`domainname`
if [ "$newdomain" != "(none)" -a "x$newdomain" != "x" ]; then
pushd "/var/yp/$newdomain">/dev/null
echo "" > %rebuild_maps_script
# loop through maps
for map in * ; do
# this server is a master for this map
if %{_libdir}/yp/yphelper -i "$map" ; then
echo "mv `pwd`/$map `pwd`/${map}.bak" >> %rebuild_maps_script
# this server is a slave for this map
else
master=`%{_libdir}/yp/makedbm -u $map 2>/dev/null | grep YP_MASTER_NAME | sed -e 's/YP_MASTER_NAME//'`
if [ "x$master" != "x" ] ; then
echo "%{_libdir}/yp/ypxfr -f -h $master -c -d $newdomain $map" >> %rebuild_maps_script
fi
fi
done
echo "make NOPUSH=true -C /var/yp" >> %rebuild_maps_script
fi
/bin/domainname "$olddomain"
fi
%triggerpostun -- ypserv < %{first_tc_version}
olddomain=`/bin/domainname`
. /etc/sysconfig/network
export NISDOMAIN
%{_libexecdir}/yppasswdd-pre-setdomain || :
touch /var/yp/Makefile
NOPUSH=true make -eC /var/yp >&2 || :
/bin/domainname "$olddomain"
if [ -e %rebuild_maps_script ] ; then
bash %rebuild_maps_script >/dev/null 2>&1 || :
rm -f %rebuild_maps_script >/dev/null 2>&1
fi
%files
%doc AUTHORS README INSTALL ChangeLog TODO NEWS COPYING
@ -212,6 +251,10 @@ NOPUSH=true make -eC /var/yp >&2 || :
%{_includedir}/*/*
%changelog
* Mon Jan 21 2013 Honza Horak <hhorak@redhat.com> - 2.29-6
- Open database files with correct mode
- Make rebuilding maps during upgrade a bit more clever
* Fri Nov 30 2012 Honza Horak <hhorak@redhat.com> - 2.29-5
- Build daemons and yppush with full relro
- Move rpc.yppasswdd.env into /usr/libexec