aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2014-01-02 15:44:36 -0500
committerSergey Poznyakoff <gray@gnu.org.ua>2014-01-30 13:33:47 +0200
commit033cd6816fe4db1a6a8f564183333f9b78354246 (patch)
tree482dd462b10dccd8f05ca968dc49d2abfbb4ab1e
parent9e2d258c81af9f8cedba2e4b8874fbaea59b43c4 (diff)
downloadcpio-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--THANKS1
-rw-r--r--doc/cpio.110
-rw-r--r--doc/cpio.texi22
-rw-r--r--src/userspec.c19
4 files changed, 46 insertions, 6 deletions
diff --git a/THANKS b/THANKS
index 4c47877..45b0dfb 100644
--- a/THANKS
+++ b/THANKS
@@ -11,12 +11,13 @@ code. Help us keep it complete and exempt of errors.
Benigno B. Junior <bbj@gentux.com.br>
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>
Mike Frysinger <vapier@gentoo.org>
Mitsuru Chinen <mchinen@yamato.ibm.com>
Peter Breitenlohner <peb@mppmu.mpg.de>
diff --git a/doc/cpio.1 b/doc/cpio.1
index 53f9395..d48d2df 100644
--- a/doc/cpio.1
+++ b/doc/cpio.1
@@ -10,13 +10,13 @@
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
.\" GNU General Public License for more details.
.\"
.\" 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
.B cpio
{\fB\-o\fR|\fB\-\-create\fR} [\fB\-0acvABLV\fR] [\fB\-C\fR \fIBYTES\fR]
[\fB\-H\fR \fIFORMAT\fR] [\fB\-M\fR \fIMESSAGE\fR]
@@ -179,12 +179,20 @@ files differently).
.RE
.TP
\fB\-R\fR, \fB\-\-owner=\fR[\fIUSER\fR][\fB:.\fR][\fIGROUP\fR]
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.
.TP
.BI \-\-rsh\-command= COMMAND
Use remote \fICOMMAND\fR instead of \fBrsh\fR.
diff --git a/doc/cpio.texi b/doc/cpio.texi
index 5a739ab..7c60d5f 100644
--- a/doc/cpio.texi
+++ b/doc/cpio.texi
@@ -292,13 +292,13 @@ reached.
Do not print the number of blocks copied.
@item --rsh-command=@var{command}
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.
@item -V
@itemx --dot
Print a @samp{.} for each file processed.
@@ -512,13 +512,13 @@ Use @var{command} instead of @command{rsh} to access remote archives.
@item -r
@itemx --rename
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
@item --sparse
Write files with large blocks of zeros as sparse files.
@item -S
@@ -793,12 +793,13 @@ Run in copy-pass mode.
@item -r
@itemx --rename
[@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}]
@*In copy-in and copy-pass mode, set the ownership of all files created
to the specified @var{owner} (this operation is allowed only for the
super-user). In copy-out mode, store the supplied owner information in
@@ -814,12 +815,29 @@ cpio --owner smith
cpio --owner smith:
cpio --owner smith:users
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
used.
@item --rsh-command=@var{command}
diff --git a/src/userspec.c b/src/userspec.c
index 8cffd65..82cfcef 100644
--- a/src/userspec.c
+++ b/src/userspec.c
@@ -105,16 +105,22 @@ parse_user_spec (const char *spec_arg, uid_t *uid, gid_t *gid,
if (u == NULL && g == NULL)
return "can not omit both user and group";
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
{
int use_login_group;
use_login_group = (separator != NULL && g == NULL);
@@ -152,13 +158,20 @@ parse_user_spec (const char *spec_arg, uid_t *uid, gid_t *gid,
endpwent ();
}
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))
error_msg = _("invalid group");
else
*gid = atoi (g);

Return to:

Send suggestions and report system problems to the System administrator.