From f549c60ebce1e1b26d72936ac9235b2faa604634 Mon Sep 17 00:00:00 2001 From: wangzhiqiang Date: Tue, 5 Jul 2022 16:34:36 +0800 Subject: [PATCH] sync branch master fix semantics of gdbm_load -r. improve handling of -u in gdbm_load Signed-off-by: wangzhiqiang (cherry picked from commit 6749d2328d0262ec4f47611116a3c384758c7218) --- 0003-Fix-semantics-of-gdbm_load-r.patch | 109 ++++++++++++++++++ 0004-Improve-handling-of-u-in-gdbm_load.patch | 78 +++++++++++++ gdbm.spec | 9 +- 3 files changed, 194 insertions(+), 2 deletions(-) create mode 100644 0003-Fix-semantics-of-gdbm_load-r.patch create mode 100644 0004-Improve-handling-of-u-in-gdbm_load.patch diff --git a/0003-Fix-semantics-of-gdbm_load-r.patch b/0003-Fix-semantics-of-gdbm_load-r.patch new file mode 100644 index 0000000..6b3d59e --- /dev/null +++ b/0003-Fix-semantics-of-gdbm_load-r.patch @@ -0,0 +1,109 @@ +From 0591202918948d41e331094b283ff699ab916c54 Mon Sep 17 00:00:00 2001 +From: Sergey Poznyakoff +Date: Fri, 1 Jul 2022 14:03:22 +0300 +Subject: [PATCH] Fix semantics of gdbm_load -r + +Fixes https://puszcza.gnu.org.ua/bugs/index.php?573 + +* src/gdbm_load.c: New option: --update (-U) +The --replace (-r) option is valid only if used together with +--update. +* doc/gdbm.texi: Document changes. +--- + doc/gdbm.texi | 23 ++++++++++++++++++++--- + src/gdbm_load.c | 18 +++++++++++++++++- + 2 files changed, 37 insertions(+), 4 deletions(-) + +diff --git a/doc/gdbm.texi b/doc/gdbm.texi +index 4a0b1a7..f1e23ba 100644 +--- a/doc/gdbm.texi ++++ b/doc/gdbm.texi +@@ -2772,9 +2772,17 @@ must be given as the second argument. + + In general, if two arguments are given the second one is treated as + the name of the database to create, overriding the file name specified +-in the flat file. ++in the flat file. All existing keys will be removed from this ++database prior to loading from the dump. Use the @option{--update} ++(@option{-U}) option if it is not what you wish. + +-The utility understands the following command line arguments: ++When given the @option{--update} (@option{-U}) option, ++@command{gdbm_load} will update the existing database with the data ++from the dump. It will bail out if the dump contains a key that is ++already present in the database. To silently overwrite existing keys, ++use the @option{--replace} (@option{-r}) option. ++ ++The utility understands the following command line options: + + @table @option + +@@ -2800,7 +2808,16 @@ Do not restore file meta-data (ownership and mode) from the flat file. + + @item -r + @itemx --replace +-Replace existing keys. ++Replace existing keys. This option can be used only together with ++@option{--update} (@option{-U}). ++ ++@item -U ++@itemx --update ++Update an existing database. The database name must be given in the ++second argument to @command{gdbm_load}. The key/value pairs from the ++dump file will be added to that database, without removing the ++existing keys. To overwrite the existing keys from the dump file, use ++@option{--update --replace}. + + @item -u @var{user}[:@var{group}] + @itemx --user=@var{user}[:@var{group}] +diff --git a/src/gdbm_load.c b/src/gdbm_load.c +index 2d96ada..dd5cdc5 100644 +--- a/src/gdbm_load.c ++++ b/src/gdbm_load.c +@@ -32,8 +32,9 @@ gid_t owner_gid; + char *parseopt_program_doc = "load a GDBM database from a file"; + char *parseopt_program_args = "FILE [DB_FILE]"; + struct gdbm_option optab[] = { +- { 'r', "replace", NULL, N_("replace records in the existing database") }, ++ { 'r', "replace", NULL, N_("replace records in the existing database (needs -U)") }, + { 'm', "mode", N_("MODE"), N_("set file mode") }, ++ { 'U', "update", NULL, N_("update the existing database") }, + { 'u', "user", N_("NAME|UID[:NAME|GID]"), N_("set file owner") }, + { 'n', "no-meta", NULL, N_("do not attempt to set file meta-data") }, + { 'M', "mmap", NULL, N_("use memory mapping") }, +@@ -139,6 +140,10 @@ main (int argc, char **argv) + } + break; + ++ case 'U': ++ oflags = (oflags & ~GDBM_OPENMASK) | GDBM_WRCREAT; ++ break; ++ + case 'u': + { + size_t len; +@@ -231,10 +236,21 @@ main (int argc, char **argv) + error (_("too many arguments; try `%s -h' for more info"), progname); + exit (EXIT_USAGE); + } ++ ++ if (replace && (oflags & GDBM_OPENMASK) != GDBM_WRCREAT) ++ { ++ error (_("-r is useless without -U")); ++ exit (EXIT_USAGE); ++ } + + filename = argv[0]; + if (argc == 2) + dbname = argv[1]; ++ else if (oflags & GDBM_WRCREAT) ++ { ++ error (_("-U requires DB_FILE to be supplied")); ++ exit (EXIT_USAGE); ++ } + else + dbname = NULL; + +-- +1.8.3.1 + diff --git a/0004-Improve-handling-of-u-in-gdbm_load.patch b/0004-Improve-handling-of-u-in-gdbm_load.patch new file mode 100644 index 0000000..bcb277d --- /dev/null +++ b/0004-Improve-handling-of-u-in-gdbm_load.patch @@ -0,0 +1,78 @@ +From 4cfdc68fd862a4e80f42f14aa92cb25db08b2466 Mon Sep 17 00:00:00 2001 +From: Sergey Poznyakoff +Date: Sat, 2 Jul 2022 19:29:47 +0300 +Subject: [PATCH] Improve handling of -u in gdbm_load + +* src/gdbm_load.c (main): Imply the owner login group if owner name +is followed by a :, and the current login group otherwise. +* doc/gdbm.texi: Document changes. +--- + doc/gdbm.texi | 13 ++++++++----- + src/gdbm_load.c | 9 +++++++-- + 2 files changed, 15 insertions(+), 7 deletions(-) + +diff --git a/doc/gdbm.texi b/doc/gdbm.texi +index f1e23ba..f954212 100644 +--- a/doc/gdbm.texi ++++ b/doc/gdbm.texi +@@ -2819,13 +2819,16 @@ dump file will be added to that database, without removing the + existing keys. To overwrite the existing keys from the dump file, use + @option{--update --replace}. + +-@item -u @var{user}[:@var{group}] +-@itemx --user=@var{user}[:@var{group}] +-Set file owner. The @var{user} can be either a valid user name or ++@item -u @var{owner}[:[@var{group}]] ++@itemx --user=@var{owner}[:[@var{group}]] ++Set file owner. The @var{owner} can be either a valid user name or + UID. Similarly, the @var{group} is either a valid group name or GID. +-If @var{group} is not given, the main group of @var{user} is used. ++If @var{group} is not given, the main group of @var{owner} is implied, if ++@var{owner} is followed by a @samp{:}, otherwise the login group of the ++current user is implied. + +-User and group parts can be separated by a dot, instead of the colon. ++User and group parts can be separated by a dot, instead of the colon, ++but such usage is discouraged. + + @item -h + @itemx --help +diff --git a/src/gdbm_load.c b/src/gdbm_load.c +index dd5cdc5..028134b 100644 +--- a/src/gdbm_load.c ++++ b/src/gdbm_load.c +@@ -148,9 +148,10 @@ main (int argc, char **argv) + { + size_t len; + struct passwd *pw; ++ int delim; + + len = strcspn (optarg, ".:"); +- if (optarg[len]) ++ if ((delim = optarg[len]) != 0) + optarg[len++] = 0; + pw = getpwnam (optarg); + if (pw) +@@ -187,7 +188,7 @@ main (int argc, char **argv) + } + } + } +- else ++ else if (delim) + { + if (!pw) + { +@@ -200,6 +201,10 @@ main (int argc, char **argv) + } + owner_gid = pw->pw_gid; + } ++ else ++ { ++ owner_gid = getgid(); ++ } + meta_mask |= GDBM_META_MASK_OWNER; + } + break; +-- +1.8.3.1 + diff --git a/gdbm.spec b/gdbm.spec index 002bc83..04e836d 100644 --- a/gdbm.spec +++ b/gdbm.spec @@ -1,6 +1,6 @@ Name: gdbm Version: 1.18.1 -Release: 6 +Release: 7 Epoch: 1 Summary: A library of database functions that work similar to the standard UNIX dbm License: GPLv3+ @@ -11,8 +11,10 @@ Patch0: 0000-Fix-gdbmtool-import-command.patch Patch1: 0001-fix-gdbm_dump-usage-stack-overflow.patch Patch2: gdbm_dump-fix-command-line-error-detection.patch Patch3: 0002-Fix-location-tracking-in-gdbmtool.-Fix-the-recover-c.patch +Patch4: 0003-Fix-semantics-of-gdbm_load-r.patch +Patch5: 0004-Improve-handling-of-u-in-gdbm_load.patch -BuildRequires: gcc libtool gettext readline-devel git bison flex +BuildRequires: gcc libtool gettext readline-devel git bison flex texinfo Provides: %{name}-libs Provides: %{name}-libs%{?_isa} @@ -102,6 +104,9 @@ fi %{_infodir}/*.info* %changelog +* Tue Jul 5 2022 wangzhiqiang - 1:1.18.1-7 +- fix semantics of gdbm_load -r. improve handling of -u in gdbm_load + * Mon Jun 27 2022 wangzhiqiang - 1:1.18.1-6 - Fix location tracking in gdbmtool. Fix the recover command -- Gitee