de751138b7478cb5f583a0f4c4ad739397a90ed5
[privoxy.git] / debian / patches / 26_edit_only_writable.dpatch
1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## 26_edit_only_writable.dpatch by Fabian Keil <fabiankeil@users.sf.net>
3 ##
4 ## All lines beginning with `## DP:' are a description of the patch.
5 ## DP: Hide the edit button on http://p.p/show-status if action file can 
6 ## DP: not be written by the privoxy user.
7 ## DP: Extended version action.patch by Fabian Keil which shows a
8 ## DP: message, that the file is write protected.
9 ## DP: http://sf.net/tracker/?func=detail&atid=311118&aid=1564026&group_id=11118
10
11 @DPATCH@
12 diff -urNad privoxy~/cgisimple.c privoxy/cgisimple.c
13 --- privoxy~/cgisimple.c
14 +++ privoxy/cgisimple.c
15 @@ -248,6 +248,10 @@
16  #include <string.h>
17  #include <assert.h>
18  
19 +#ifdef HAVE_ACCESS
20 +#include <unistd.h>
21 +#endif /* def HAVE_ACCESS */
22 +
23  #ifdef _WIN32
24  #define snprintf _snprintf
25  #endif /* def _WIN32 */
26 @@ -1040,8 +1044,20 @@
27  #ifdef FEATURE_CGI_EDIT_ACTIONS
28           if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
29           {
30 -            snprintf(buf, 100, "&nbsp;&nbsp;<a href=\"/edit-actions-list?f=%s\">Edit</a>", csp->config->actions_file_short[i]);
31 -            if (!err) err = string_append(&s, buf);
32 +#ifdef HAVE_ACCESS
33 +            if (access(csp->config->actions_file[i], W_OK) == 0)
34 +            {
35 +#endif /* def HAVE_ACCESS */
36 +               snprintf(buf, 100, "&nbsp;&nbsp;<a href=\"/edit-actions-list?f=%s\">Edit</a>",
37 +                  csp->config->actions_file_short[i]);
38 +               if (!err) err = string_append(&s, buf);
39 +#ifdef HAVE_ACCESS
40 +            }
41 +            else
42 +            {
43 +               if (!err) err = string_append(&s, "&nbsp;&nbsp;<strong>File is write protected.</strong>");
44 +            }
45 +#endif /* def HAVE_ACCESS */
46           }
47  #endif
48  
49 diff -urNad privoxy~/configure.in privoxy/configure.in
50 --- privoxy~/configure.in
51 +++ privoxy/configure.in
52 @@ -1129,7 +1129,7 @@
53  AC_TYPE_SIGNAL
54  dnl uncommenting does not work for swa. suse linux
55  dnl AC_FUNC_STAT
56 -AC_CHECK_FUNCS([atexit getcwd gethostbyaddr gethostbyaddr_r gethostbyname gethostbyname_r inet_ntoa localtime_r memchr memmove memset random regcomp select setlocale socket strchr strdup strerror strftime strptime strstr strtoul timegm])
57 +AC_CHECK_FUNCS([access atexit getcwd gethostbyaddr gethostbyaddr_r gethostbyname gethostbyname_r inet_ntoa localtime_r memchr memmove memset random regcomp select setlocale socket strchr strdup strerror strftime strptime strstr strtoul timegm])
58  
59  
60  dnl =================================================================