summaryrefslogtreecommitdiff
path: root/user.xdg.origin.url.patch
blob: 976e93b3c8218893bf8b3ed6bf93c8aed5b55ef2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
in upstream now:
http://git.savannah.gnu.org/cgit/wget.git/commit/?id=a933bdd31eee9c956a3b5cc142f004ef1fa94cb3

From 2c968b81d9d9c4025379242b5f560aab441e1430 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mantas=20Mikul=C4=97nas?= <grawity@gmail.com>
Date: Sat, 7 Dec 2013 20:45:00 +0200
Subject: [PATCH] Set the 'user.xdg.origin.url' xattr for downloaded files

---
 src/ftp.c  |  2 ++
 src/http.c |  2 ++
 src/url.c  | 20 ++++++++++++++++++++
 src/url.h  |  4 ++++
 4 files changed, 28 insertions(+)

diff -urNp -x '*.orig' wget-1.21.1.org/src/ftp.c wget-1.21.1/src/ftp.c
--- wget-1.21.1.org/src/ftp.c	2021-01-08 23:51:43.000000000 +0100
+++ wget-1.21.1/src/ftp.c	2021-05-06 00:07:54.231635623 +0200
@@ -1534,6 +1534,8 @@ Error in server response, closing contro
   else
     fp = output_stream;
 
+  set_xa (u, fileno(fp));
+
   if (passed_expected_bytes)
     {
       print_length (passed_expected_bytes, restval, true);
diff -urNp -x '*.orig' wget-1.21.1.org/src/http.c wget-1.21.1/src/http.c
--- wget-1.21.1.org/src/http.c	2021-01-08 23:51:43.000000000 +0100
+++ wget-1.21.1/src/http.c	2021-05-06 00:07:54.232635623 +0200
@@ -4181,6 +4181,8 @@ gethttp (const struct url *u, struct url
     }
 #endif
 
+  set_xa (u, fileno(fp));
+
   err = read_response_body (hs, sock, fp, contlen, contrange,
                             chunked_transfer_encoding,
                             u->url, warc_timestamp_str,
diff -urNp -x '*.orig' wget-1.21.1.org/src/url.c wget-1.21.1/src/url.c
--- wget-1.21.1.org/src/url.c	2021-01-08 23:51:43.000000000 +0100
+++ wget-1.21.1/src/url.c	2021-05-06 00:07:54.233635623 +0200
@@ -36,6 +36,7 @@ as that of the covered work.  */
 #include <unistd.h>
 #include <errno.h>
 #include <assert.h>
+#include <sys/xattr.h>
 
 #include "utils.h"
 #include "url.h"
@@ -2382,6 +2383,25 @@ are_urls_equal (const char *u1, const ch
   return (*p == 0 && *q == 0 ? true : false);
 }
 
+int
+set_xa (const struct url *origin, int fd)
+{
+  const char *url;
+  int res;
+
+  url = url_string(origin, URL_AUTH_HIDE);
+  res = fsetxattr(fd, XA_ORIGIN, url, strlen(url), 0);
+  if (res != 0)
+    {
+      if (errno == ENOTSUP || errno == EPERM)
+        res = 0;
+      else
+        logprintf (LOG_NOTQUIET, "fsetxattr: %s\n", strerror (errno));
+    }
+
+  return res;
+}
+
 #ifdef TESTING
 /* Debugging and testing support for path_simplify. */
 
diff -urNp -x '*.orig' wget-1.21.1.org/src/url.h wget-1.21.1/src/url.h
--- wget-1.21.1.org/src/url.h	2021-01-08 23:51:43.000000000 +0100
+++ wget-1.21.1/src/url.h	2021-05-06 00:07:54.233635623 +0200
@@ -133,4 +133,8 @@ bool schemes_are_similar_p (enum url_sch
 
 bool are_urls_equal (const char *u1, const char *u2);
 
+#define XA_ORIGIN "user.xdg.origin.url"
+
+int set_xa (const struct url *, int);
+
 #endif /* URL_H */