Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/extattr Improve extended attribute commands:
details: https://anonhg.NetBSD.org/src/rev/3a7ac210dee5
branches: trunk
changeset: 767285:3a7ac210dee5
user: manu <manu%NetBSD.org@localhost>
date: Thu Jul 14 15:25:27 2011 +0000
description:
Improve extended attribute commands:
- allow namespace to be omitted when using a namespace-prefixed attribute
name, a la Linux.
- Improve hexdump for getextattr -x
- Add more display option for binary attributes, using vis(3)
- Add a -i option to setextattr to get the attribute value from file, so
that we can set binary values
diffstat:
usr.bin/extattr/getextattr.1 | 92 +++++++++++++++++++--
usr.bin/extattr/getextattr.c | 179 +++++++++++++++++++++++++++++++++++++-----
2 files changed, 236 insertions(+), 35 deletions(-)
diffs (truncated from 447 to 300 lines):
diff -r f513bfa6544b -r 3a7ac210dee5 usr.bin/extattr/getextattr.1
--- a/usr.bin/extattr/getextattr.1 Thu Jul 14 12:44:10 2011 +0000
+++ b/usr.bin/extattr/getextattr.1 Thu Jul 14 15:25:27 2011 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: getextattr.1,v 1.3 2011/06/17 18:19:58 wiz Exp $
+.\" $NetBSD: getextattr.1,v 1.4 2011/07/14 15:25:27 manu Exp $
.\"
.\"-
.\" Copyright (c) 2000, 2001 Robert N. M. Watson
@@ -44,35 +44,61 @@
.Nd manipulate extended attributes
.Sh SYNOPSIS
.Nm getextattr
-.Op Fl fhqsx
-.Ar attrnamespace
+.Op Fl fhq
+.Op Fl s | Fl x | Fl v Ar style
+.Op Ar namespace
.Ar attrname
.Ar filename ...
.Nm lsextattr
.Op Fl fhq
-.Ar attrnamespace
+.Ar namespace
.Ar filename ...
.Nm rmextattr
.Op Fl fhq
-.Ar attrnamespace
+.Op Ar namespace
.Ar attrname
.Ar filename ...
.Nm setextattr
.Op Fl fhnq
-.Ar attrnamespace
+.Op Ar namespace
.Ar attrname
.Ar attrvalue
.Ar filename ...
+.Nm setextattr
+.Op Fl fhnq
+.Fl i Ar valuefile
+.Op Ar namespace
+.Ar attrname
+.Ar filename ...
.Sh DESCRIPTION
These utilities are user tools to manipulate the named extended
attributes on files and directories.
+.Pp
The
-.Ar attrnamespace
+.Ar namespace
argument should be the namespace of the attribute to retrieve: legal
values are
.Cm user
and
.Cm system .
+For all operations except
+.Nm lsextattr ,
+the namespace argument may be omitted if the attribute name is namespace
+prefixed, like in
+.Cm user.test .
+In that later case, the
+.Cm user
+namespace prefix obviously selects
+.Cm user
+namespace.
+.Cm system ,
+.Cm security ,
+and
+.Cm trusted
+namespace prefixes select the
+.Cm system
+namespace.
+.Pp
The
.Ar attrname
argument should be the name of the attribute,
@@ -91,6 +117,11 @@
(No follow.)
If the file is a symbolic link, perform the operation on the
link itself rather than the file that the link points to.
+.It Fl i Ar valuefile
+(Input file.)
+Read the attribute value from file
+.Ar valuefile .
+Use this flag in order to set a binary value for an attribute.
.It Fl n
.Dv ( NUL Ns
-terminate.)
@@ -102,6 +133,39 @@
.It Fl s
(Stringify.)
Escape nonprinting characters and put quotes around the output.
+.It Fl v Ar style
+(Visual.)
+Process the attribute value through
+.Xr vis 3 ,
+using
+.Ar style .
+Valid values for
+.Ar style
+are:
+.Bl -tag -width indent
+.It Ar default
+Use default
+.Xr vis 3
+encoding.
+.It Ar c
+Use C-style backslash sequences, like in
+.Nm vis Fl c .
+.It Ar http
+Use URI encoding from RFC 1808, like in
+.Nm vis Fl h .
+.It Ar octal
+Display in octal, like in
+.Nm vis Fl o .
+.It Ar vis
+Alias for
+.Ar default .
+.It Ar cstyle
+Alias for
+.Ar c .
+.It Ar httpstyle
+Alias for
+.Ar http .
+.El
.It Fl x
(Hex.)
Print the output in hexadecimal.
@@ -113,6 +177,12 @@
lsextattr system /boot/kernel/kernel
rmextattr system md5 /boot/kernel/kernel
.Ed
+.Pp
+Examples omitting namespace (and attribute value) argument:
+.Bd -literal
+setextattr -i valuefile trusted.gfid /export/wd3a
+getextattr -x trusted.gfid /export/wd3a
+.Ed
.Sh SEE ALSO
.\" .Xr extattr 2 ,
.Xr extattr 3 ,
@@ -128,10 +198,10 @@
.Nx 3.0 .
It was developed to support security extensions requiring additional labels
to be associated with each file or directory.
+.Pp
+Exented attribute support was resurected and made more usable in
+.Nx 5.2 .
.Sh AUTHORS
.An Robert N M Watson
.An Poul-Henning Kamp
-.Sh BUGS
-The
-.Nm setextattr
-utility can only be used to set attributes to strings.
+.An Emmanuel Dreyfus
diff -r f513bfa6544b -r 3a7ac210dee5 usr.bin/extattr/getextattr.c
--- a/usr.bin/extattr/getextattr.c Thu Jul 14 12:44:10 2011 +0000
+++ b/usr.bin/extattr/getextattr.c Thu Jul 14 15:25:27 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: getextattr.c,v 1.7 2011/07/04 08:07:32 manu Exp $ */
+/* $NetBSD: getextattr.c,v 1.8 2011/07/14 15:25:27 manu Exp $ */
/*-
* Copyright (c) 2002, 2003 Networks Associates Technology, Inc.
@@ -50,6 +50,8 @@
#include <string.h>
#include <unistd.h>
#include <vis.h>
+#include <fcntl.h>
+#include <sys/stat.h>
//#include <util.h>
static enum { EADUNNO, EAGET, EASET, EARM, EALS } what = EADUNNO;
@@ -60,7 +62,7 @@
switch (what) {
case EAGET:
- fprintf(stderr, "usage: %s [-fhqsx] "
+ fprintf(stderr, "usage: %s [-fhq] [-s | -x | -v style] "
"attrnamespace attrname filename ...\n", getprogname());
exit(1);
@@ -68,6 +70,9 @@
fprintf(stderr, "usage: %s [-fhnq] "
"attrnamespace attrname attrvalue filename ...\n",
getprogname());
+ fprintf(stderr, "usage: %s [-fhnq] -i attrvalue_file "
+ "attrnamespace attrname filename ...\n",
+ getprogname());
exit(1);
case EARM:
@@ -103,6 +108,58 @@
return;
}
+static int
+parse_flag_vis(const char *opt)
+{
+ if (strcmp(opt, "default") == 0)
+ return 0;
+ else if (strcmp(opt, "cstyle") == 0)
+ return VIS_CSTYLE;
+ else if (strcmp(opt, "octal") == 0)
+ return VIS_OCTAL;
+ else if (strcmp(opt, "httpstyle") == 0)
+ return VIS_HTTPSTYLE;
+
+ /* Convenient aliases */
+ else if (strcmp(opt, "vis") == 0)
+ return 0;
+ else if (strcmp(opt, "c") == 0)
+ return VIS_CSTYLE;
+ else if (strcmp(opt, "http") == 0)
+ return VIS_HTTPSTYLE;
+ else
+ fprintf(stderr, "%s: invalid -s option \"%s\"",
+ getprogname(), opt);
+
+ return -1;
+}
+
+#define HEXDUMP_PRINT(x) ((uint8_t)x >= 32 && (uint8_t)x < 128) ? x : '.'
+static void
+hexdump(const char *addr, size_t len)
+{
+ unsigned int i, j;
+
+ for (i = 0; i < len; i += 16) {
+ printf(" %03x ", i);
+ for (j = 0; j < 16; j++) {
+ if (i + j > len)
+ printf(" ");
+ else
+ printf("%02x ", addr[i + j] & 0xff);
+ }
+ printf(" ");
+ for (j = 0; j < 16; j++) {
+ if (i + j > len)
+ printf(" ");
+ else
+ printf("%c", HEXDUMP_PRINT(addr[i + j]));
+ }
+ printf("\n");
+ }
+}
+#undef HEXDUMP_PRINT
+
int
main(int argc, char *argv[])
{
@@ -111,14 +168,15 @@
const char *options, *attrname;
int buflen, visbuflen, ch, error, i, arg_counter, attrnamespace,
- minargc;
+ minargc, val_len = 0;
int flag_force = 0;
int flag_nofollow = 0;
int flag_null = 0;
int flag_quiet = 0;
- int flag_string = 0;
+ int flag_vis = -1;
int flag_hex = 0;
+ char *filename = NULL;
options = NULL;
minargc = 0;
@@ -128,16 +186,16 @@
p = getprogname();
if (strcmp(p, "getextattr") == 0) {
what = EAGET;
- options = "fhqsx";
- minargc = 3;
+ options = "fhqsxv:";
+ minargc = 2;
} else if (strcmp(p, "setextattr") == 0) {
what = EASET;
- options = "fhnq";
- minargc = 4;
+ options = "fhnqi:";
+ minargc = 3;
} else if (strcmp(p, "rmextattr") == 0) {
what = EARM;
options = "fhq";
- minargc = 3;
+ minargc = 2;
} else if (strcmp(p, "lsextattr") == 0) {
what = EALS;
options = "fhq";
@@ -160,11 +218,18 @@
flag_quiet = 1;
break;
case 's':
- flag_string = 1;
+ flag_vis = VIS_SAFE | VIS_WHITE;
+ break;
Home |
Main Index |
Thread Index |
Old Index