diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-01-02 15:44:36 -0500 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-01-30 13:33:47 +0200 |
commit | 033cd6816fe4db1a6a8f564183333f9b78354246 (patch) | |
tree | 482dd462b10dccd8f05ca968dc49d2abfbb4ab1e | |
parent | 9e2d258c81af9f8cedba2e4b8874fbaea59b43c4 (diff) | |
download | cpio-033cd6816fe4db1a6a8f564183333f9b78354246.tar.gz cpio-033cd6816fe4db1a6a8f564183333f9b78354246.tar.bz2 |
Treat UID/GID as numeric if prefixed by + (-R option)
The IDs supplied with the -R option are treated as numeric (without
looking them up in the system database), when prefixed with +. This
allows to force using numeric value if a user (group) with a numeric
name exists in the database.
Reported by Joshua Briefman <sirgatez@gmail.com>.
* src/userspec.c (parse_user_spec): Use + as an indicator of
a numeric UID/GID.
* doc/cpio.1: Document changes.
* doc/cpio.texi: Likewise.
-rw-r--r-- | THANKS | 1 | ||||
-rw-r--r-- | doc/cpio.1 | 10 | ||||
-rw-r--r-- | doc/cpio.texi | 22 | ||||
-rw-r--r-- | src/userspec.c | 19 |
4 files changed, 46 insertions, 6 deletions
@@ -14,6 +14,7 @@ Brian Mays <brian@debian.org> Clint Adams <schizo@debian.org> Dmitry V. Levin <ldv@altlinux.org> Jim Castleberry <bhg9aha02@sneakemail.com> +Joshua Briefman <sirgatez@gmail.com> Holger Fleischmann <holger_fleischmann@mra.man.de> Ladislav Michnovič <ladislav.michnovic@gmail.com> Matthew Braithwaite <mab@cnet.com> @@ -13,7 +13,7 @@ .\" .\" You should have received a copy of the GNU General Public License .\" along with GNU cpio. If not, see <http://www.gnu.org/licenses/>. -.TH CPIO 1 "January 29, 2014" "CPIO" "GNU CPIO" +.TH CPIO 1 "January 30, 2014" "CPIO" "GNU CPIO" .SH NAME cpio \- copy files to and from archives .SH SYNOPSIS @@ -182,6 +182,14 @@ files differently). In copy-in and copy-pass mode, set the ownership of all files created to the specified \fIUSER\fR and/or \fIGROUP\fR. In copy-out mode, store the supplied owner information in the archive. + +\fIUSER\fR and \fIGROUP\fR are first looked up in the system user and +group databases. If not found, \fBcpio\fR checks if they consist of +decimal digits only and, if so, treats them as numeric UID and GID, +correspondingly. + +To avoid the lookup and ensure that arguments are treated as numeric +values, prefix them with a plus sign, e.g.: \fB-R +0:+0\fR. .TP .B \-\-quiet Do not print the number of blocks copied at the end of the run. diff --git a/doc/cpio.texi b/doc/cpio.texi index 5a739ab..7c60d5f 100644 --- a/doc/cpio.texi +++ b/doc/cpio.texi @@ -295,7 +295,7 @@ Use @var{command} instead of @command{rsh} to access remote archives. @item -R @itemx --owner=[@var{user}][:.][@var{group}] Set the ownership of all files created to the specified @var{user} -and/or @var{group}. +and/or @var{group}. @xref{owner}. @item -v @itemx --verbose Verbosely list the files processed. @@ -515,7 +515,7 @@ Interactively rename files @item -R @itemx --owner=[@var{user}][:.][@var{group}] Set the ownership of all files created to the specified @var{user} -and/or @var{group}. +and/or @var{group}. @xref{owner}. @item -s @itemx --swap-bytes Swap the bytes of each halfword in the files @@ -796,6 +796,7 @@ Run in copy-pass mode. [@ref{copy-in}] @*Interactively rename files. +@anchor{owner} @item -R @var{owner} @itemx --owner @var{owner} [@ref{copy-in},@ref{copy-out},@ref{copy-pass}] @@ -817,6 +818,23 @@ cpio --owner :users @end group @end smallexample +The argument parts are first looked up in the system user and +group databases, correspondingly. If any of them is not found there, +it is treated as numeric UID or GID, provided that it consists of +decimal digits only. + +To avoid the lookup and ensure that arguments are treated as numeric +values, prefix them with a plus sign, e.g.: + +@smallexample +@group +cpio --owner +0 +cpio --owner +0: +cpio --owner +0:+0 +cpio --owner :+0 +@end group +@end smallexample + @noindent If the group is omitted but the @samp{:} or @samp{.} separator is given, as in the second example. the given user's login group will be diff --git a/src/userspec.c b/src/userspec.c index 8cffd65..82cfcef 100644 --- a/src/userspec.c +++ b/src/userspec.c @@ -108,10 +108,16 @@ parse_user_spec (const char *spec_arg, uid_t *uid, gid_t *gid, if (u != NULL) { - pwd = getpwnam (u); - if (pwd == NULL) + if (*u == '+') { + pwd = NULL; + ++u; + } + else + pwd = getpwnam (u); + if (pwd == NULL) + { if (!isnumber_p (u)) error_msg = _("invalid user"); else @@ -155,7 +161,14 @@ parse_user_spec (const char *spec_arg, uid_t *uid, gid_t *gid, if (g != NULL && error_msg == NULL) { /* Explicit group. */ - grp = getgrnam (g); + if (*g == '+') + { + grp = NULL; + ++g; + } + else + grp = getgrnam (g); + if (grp == NULL) { if (!isnumber_p (g)) |