From 6928165c52fe3a21829403c1eda93fbc5693f35a Mon Sep 17 00:00:00 2001
From: Andreas Gruenbacher <agruen@suse.de>
Date: Mon, 22 Jun 2009 19:57:48 +0200
Subject: [PATCH] Stop quoting nonprintable characters in the getfacl output

What is printable or not depends on the locale settings, and getfacl
often gets it wrong. We still need to quote a few special characters
like newlines so that setfacl can always parse getfacl's output.
---
 getfacl/getfacl.c          |   18 +++++++++---------
 libacl/__acl_to_any_text.c |    4 ++--
 setfacl/setfacl.c          |   20 ++++++++++----------
 3 files changed, 21 insertions(+), 21 deletions(-)

Index: acl-2.2.47/getfacl/getfacl.c
===================================================================
--- acl-2.2.47.orig/getfacl/getfacl.c
+++ acl-2.2.47/getfacl/getfacl.c
@@ -88,9 +88,9 @@ int print_options = TEXT_SOME_EFFECTIVE;
 int opt_numeric;  /* don't convert id's to symbolic names */
 
 
-static const char *xquote(const char *str)
+static const char *xquote(const char *str, const char *quote_chars)
 {
-	const char *q = quote(str);
+	const char *q = quote(str, quote_chars);
 	if (q == NULL) {
 		fprintf(stderr, "%s: %s\n", progname, strerror(errno));
 		exit(1);
@@ -152,7 +152,7 @@ struct name_list *get_list(const struct
 					name = group_name(*id_p, opt_numeric);
 				break;
 		}
-		name = xquote(name);
+		name = xquote(name, "\t\n\r");
 		len = strlen(name);
 		if (last == NULL) {
 			first = last = (struct name_list *)
@@ -360,7 +360,7 @@ int do_show(FILE *stream, const char *pa
 		if (ret < 0)
 			return ret;
 	}
-	fprintf(stream, "# file: %s\n", xquote(path_p));
+	fprintf(stream, "# file: %s\n", xquote(path_p, "\n\r"));
 	while (acl_names != NULL || dacl_names != NULL) {
 		acl_tag_t acl_tag, dacl_tag;
 
@@ -430,7 +430,7 @@ int do_print(const char *path_p, const s
 	int error = 0;
 
 	if (walk_flags & WALK_TREE_FAILED) {
-		fprintf(stderr, "%s: %s: %s\n", progname, xquote(path_p),
+		fprintf(stderr, "%s: %s: %s\n", progname, xquote(path_p, "\n\r"),
 			strerror(errno));
 		return 1;
 	}
@@ -493,11 +493,11 @@ int do_print(const char *path_p, const s
 			goto fail;
 	} else {
 		if (opt_comments) {
-			printf("# file: %s\n", xquote(path_p));
+			printf("# file: %s\n", xquote(path_p, "\n\r"));
 			printf("# owner: %s\n",
-			       xquote(user_name(st->st_uid, opt_numeric)));
+			       xquote(user_name(st->st_uid, opt_numeric), " \t\n\r"));
 			printf("# group: %s\n",
-			       xquote(group_name(st->st_gid, opt_numeric)));
+			       xquote(group_name(st->st_gid, opt_numeric), " \t\n\r"));
 		}
 		if (acl != NULL) {
 			char *acl_text = acl_to_any_text(acl, NULL, '\n',
@@ -534,7 +534,7 @@ cleanup:
 	return error;
 
 fail:
-	fprintf(stderr, "%s: %s: %s\n", progname, xquote(path_p),
+	fprintf(stderr, "%s: %s: %s\n", progname, xquote(path_p, "\n\r"),
 		strerror(errno));
 	error = -1;
 	goto cleanup;
Index: acl-2.2.47/libacl/__acl_to_any_text.c
===================================================================
--- acl-2.2.47.orig/libacl/__acl_to_any_text.c
+++ acl-2.2.47/libacl/__acl_to_any_text.c
@@ -160,7 +160,7 @@ acl_entry_to_any_str(const acl_entry_t e
 					str = NULL;
 				else
 					str = quote(user_name(
-						entry_obj_p->eid.qid));
+						entry_obj_p->eid.qid), ":, \t\n\r");
 				if (str != NULL) {
 					strncpy(text_p, str, size);
 					ADVANCE(strlen(str));
@@ -183,7 +183,7 @@ acl_entry_to_any_str(const acl_entry_t e
 					str = NULL;
 				else
 					str = quote(group_name(
-						entry_obj_p->eid.qid));
+						entry_obj_p->eid.qid), ":, \t\n\r");
 				if (str != NULL) {
 					strncpy(text_p, str, size);
 					ADVANCE(strlen(str));
Index: acl-2.2.47/setfacl/setfacl.c
===================================================================
--- acl-2.2.47.orig/setfacl/setfacl.c
+++ acl-2.2.47/setfacl/setfacl.c
@@ -91,9 +91,9 @@ int chown_error;
 int promote_warning;
 
 
-static const char *xquote(const char *str)
+static const char *xquote(const char *str, const char *quote_chars)
 {
-	const char *q = quote(str);
+	const char *q = quote(str, quote_chars);
 	if (q == NULL) {
 		fprintf(stderr, "%s: %s\n", progname, strerror(errno));
 		exit(1);
@@ -143,7 +143,7 @@ restore(
 			if (filename) {
 				fprintf(stderr, _("%s: %s: No filename found "
 						  "in line %d, aborting\n"),
-					progname, xquote(filename),
+					progname, xquote(filename, "\n\r"),
 					backup_line);
 			} else {
 				fprintf(stderr, _("%s: No filename found in "
@@ -168,7 +168,7 @@ restore(
 				     &line, NULL);
 		if (error != 0) {
 			fprintf(stderr, _("%s: %s: %s in line %d\n"),
-			        progname, xquote(filename), strerror(errno),
+			        progname, xquote(filename, "\n\r"), strerror(errno),
 				line);
 			status = 1;
 			goto getout;
@@ -177,7 +177,7 @@ restore(
 		error = stat(path_p, &st);
 		if (opt_test && error != 0) {
 			fprintf(stderr, "%s: %s: %s\n", progname,
-				xquote(path_p), strerror(errno));
+				xquote(path_p, "\n\r"), strerror(errno));
 			status = 1;
 		}
 
@@ -200,7 +200,7 @@ restore(
 			if (chown(path_p, st.st_uid, st.st_gid) != 0) {
 				fprintf(stderr, _("%s: %s: Cannot change "
 					          "owner/group: %s\n"),
-					progname, xquote(path_p),
+					progname, xquote(path_p, "\n\r"),
 					strerror(errno));
 				status = 1;
 			}
@@ -228,7 +228,7 @@ getout:
 	return status;
 
 fail:
-	fprintf(stderr, "%s: %s: %s\n", progname, xquote(filename),
+	fprintf(stderr, "%s: %s: %s\n", progname, xquote(filename, "\n\r"),
 		strerror(errno));
 	status = 1;
 	goto getout;
@@ -482,7 +482,7 @@ int main(int argc, char *argv[])
 					if (file == NULL) {
 						fprintf(stderr, "%s: %s: %s\n",
 							progname,
-							xquote(optarg),
+							xquote(optarg, "\n\r"),
 							strerror(errno));
 						status = 2;
 						goto cleanup;
@@ -508,7 +508,7 @@ int main(int argc, char *argv[])
 							progname,
 							strerror(errno),
 							lineno,
-							xquote(optarg));
+							xquote(optarg, "\n\r"));
 					} else {
 						fprintf(stderr, _(
 							"%s: %s in line "
@@ -541,7 +541,7 @@ int main(int argc, char *argv[])
 					if (file == NULL) {
 						fprintf(stderr, "%s: %s: %s\n",
 							progname,
-							xquote(optarg),
+							xquote(optarg, "\n\r"),
 							strerror(errno));
 						status = 2;
 						goto cleanup;
