summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2002-02-10 06:13:14 +0000
committerrwatson <rwatson@FreeBSD.org>2002-02-10 06:13:14 +0000
commit31155c8524adf628f11f4a975fb9e6136b915321 (patch)
treee013cdb15de27c8f3ffba12b138b19dbec5ec8c7 /usr.sbin
parentc9034a8d20bf4bc830f6ba11aa835927093fe032 (diff)
downloadFreeBSD-src-31155c8524adf628f11f4a975fb9e6136b915321.zip
FreeBSD-src-31155c8524adf628f11f4a975fb9e6136b915321.tar.gz
Teach getextattr to query the EA size and allocate appropriate sized
buffers before reading the memory. Arguably, the failure modes here are poor, but we can now read >2k EAs. Also, update the copyrights and licenses while I'm here.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/getextattr/getextattr.810
-rw-r--r--usr.sbin/getextattr/getextattr.c37
2 files changed, 37 insertions, 10 deletions
diff --git a/usr.sbin/getextattr/getextattr.8 b/usr.sbin/getextattr/getextattr.8
index 1ffd038..a80780c 100644
--- a/usr.sbin/getextattr/getextattr.8
+++ b/usr.sbin/getextattr/getextattr.8
@@ -1,7 +1,10 @@
.\"-
-.\" Copyright (c) 2000, 2001 Robert N. M. Watson
+.\" Copyright (c) 2000, 2001, 2002 Robert N. M. Watson
.\" All rights reserved.
.\"
+.\" This software was developed by Robert Watson for the TrustedBSD
+.\" Project.
+.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
@@ -23,7 +26,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
+.\" $FreeBSD$
.\"
.Dd March 30, 2000
.Dt GETEXTATTR 8
@@ -102,5 +105,4 @@ to be associated with each file or directory.
.Sh AUTHORS
Robert N M Watson
.Sh BUGS
-Only the first 2048 bytes of the extended attribute value are displayed
-due to a hard-coded buffer limit.
+The output format for this utility is ugly, and worse yet, not very useful.
diff --git a/usr.sbin/getextattr/getextattr.c b/usr.sbin/getextattr/getextattr.c
index 677b6fb..1923cd7 100644
--- a/usr.sbin/getextattr/getextattr.c
+++ b/usr.sbin/getextattr/getextattr.c
@@ -1,7 +1,16 @@
/*-
- * Copyright (c) 1999, 2000, 2001 Robert N. M. Watson
+ * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
+ * Copyright (c) 2002 Networks Associates Technologies, Inc.
* All rights reserved.
*
+ * This software was developed by Robert Watson for the TrustedBSD Project.
+ *
+ * This software was developed for the FreeBSD Project in part by NAI Labs,
+ * the Security Research Division of Network Associates, Inc. under
+ * DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA
+ * CHATS research program.
+ *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -54,11 +63,10 @@ usage(void)
int
main(int argc, char *argv[])
{
+ size_t len;
char *attrname;
- char buf[BUFSIZE];
- char visbuf[BUFSIZE*4];
- int error, i, arg_counter, attrnamespace;
- int ch;
+ char *buf, *visbuf;
+ int ch, error, i, arg_counter, attrnamespace;
int flag_as_string = 0;
int flag_reverse = 0;
@@ -98,13 +106,28 @@ main(int argc, char *argv[])
* truncating at BUFSIZE.
*/
for (arg_counter = 1; arg_counter < argc; arg_counter++) {
+ len = extattr_get_file(argv[arg_counter], attrnamespace,
+ attrname, NULL, 0);
+ if (len == -1) {
+ perror(argv[arg_counter]);
+ continue;
+ }
+ buf = (char *)malloc(len);
+ if (buf == NULL) {
+ perror("malloc");
+ return (-1);
+ }
error = extattr_get_file(argv[arg_counter], attrnamespace,
attrname, buf, BUFSIZE);
-
if (error == -1)
perror(argv[arg_counter]);
else {
if (flag_as_string) {
+ visbuf = (char *)malloc(len*4);
+ if (visbuf == NULL) {
+ perror("malloc");
+ return (-1);
+ }
strvisx(visbuf, buf, error, VIS_SAFE
| VIS_WHITE);
if (flag_reverse) {
@@ -114,6 +137,7 @@ main(int argc, char *argv[])
printf("%s:", argv[arg_counter]);
printf(" \"%s\"\n", visbuf);
}
+ free(visbuf);
} else {
printf("%s:", argv[arg_counter]);
for (i = 0; i < error; i++)
@@ -126,6 +150,7 @@ main(int argc, char *argv[])
printf("\n");
}
}
+ free(buf);
}
return (0);
OpenPOWER on IntegriCloud