Package: policykit-1 / 0.105-15~deb8u2

master/Fix-multi-line-pam-text-info.patch Patch series | download
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
Description: Escape helper output to handle multiline messages
 Some pam modules produce multiline messages which caused errors in
 PolkitAgentSession as the subsequent lines were interpreted as separate
 messages unrecognized by the authenticator. Escaping every message allows
 to avoid such behaviour.
Author: Dariusz Gadomski <dariusz.gadomski@canonical.com>
Bug-Ubuntu: https://bugs.launchpad.net/bugs/1510824
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92886
Origin: upstream

--- policykit-1-0.105.orig/src/polkitagent/polkitagenthelper-pam.c
+++ policykit-1-0.105/src/polkitagent/polkitagenthelper-pam.c
@@ -39,25 +39,35 @@ static void
 send_to_helper (const gchar *str1,
                 const gchar *str2)
 {
+  char *escaped;
+  char *tmp2;
+  size_t len2;
+
+  tmp2 = g_strdup(str2);
+  len2 = strlen(tmp2);
 #ifdef PAH_DEBUG
-  fprintf (stderr, "polkit-agent-helper-1: writing `%s' to stdout\n", str1);
+  fprintf (stderr, "polkit-agent-helper-1: writing `%s ' to stdout\n", str1);
 #endif /* PAH_DEBUG */
-  fprintf (stdout, "%s", str1);
+  fprintf (stdout, "%s ", str1);
+
+  if (len2 > 0 && tmp2[len2 - 1] == '\n')
+    tmp2[len2 - 1] = '\0';
+  escaped = g_strescape (tmp2, NULL);
 #ifdef PAH_DEBUG
-  fprintf (stderr, "polkit-agent-helper-1: writing `%s' to stdout\n", str2);
+  fprintf (stderr, "polkit-agent-helper-1: writing `%s' to stdout\n", escaped);
 #endif /* PAH_DEBUG */
-  fprintf (stdout, "%s", str2);
-  if (strlen (str2) > 0 && str2[strlen (str2) - 1] != '\n')
-    {
+  fprintf (stdout, "%s", escaped);
 #ifdef PAH_DEBUG
-      fprintf (stderr, "polkit-agent-helper-1: writing newline to stdout\n");
+  fprintf (stderr, "polkit-agent-helper-1: writing newline to stdout\n");
 #endif /* PAH_DEBUG */
-      fputc ('\n', stdout);
-    }
+  fputc ('\n', stdout);
 #ifdef PAH_DEBUG
   fprintf (stderr, "polkit-agent-helper-1: flushing stdout\n");
 #endif /* PAH_DEBUG */
   fflush (stdout);
+
+  g_free (escaped);
+  g_free (tmp2);
 }
 
 int
@@ -89,7 +99,7 @@ main (int argc, char *argv[])
 
       /* Special-case a very common error triggered in jhbuild setups */
       s = g_strdup_printf ("Incorrect permissions on %s (needs to be setuid root)", argv[0]);
-      send_to_helper ("PAM_ERROR_MSG ", s);
+      send_to_helper ("PAM_ERROR_MSG", s);
       g_free (s);
       goto error;
     }
@@ -232,7 +242,6 @@ conversation_function (int n, const stru
   struct pam_response *aresp;
   char buf[PAM_MAX_RESP_SIZE];
   int i;
-  gchar *escaped = NULL;
 
   data = data;
   if (n <= 0 || n > PAM_MAX_NUM_MSG)
@@ -249,35 +258,13 @@ conversation_function (int n, const stru
         {
 
         case PAM_PROMPT_ECHO_OFF:
-#ifdef PAH_DEBUG
-          fprintf (stderr, "polkit-agent-helper-1: writing `PAM_PROMPT_ECHO_OFF ' to stdout\n");
-#endif /* PAH_DEBUG */
-          fprintf (stdout, "PAM_PROMPT_ECHO_OFF ");
+          send_to_helper ("PAM_PROMPT_ECHO_OFF", msg[i]->msg);
           goto conv1;
 
         case PAM_PROMPT_ECHO_ON:
-#ifdef PAH_DEBUG
-          fprintf (stderr, "polkit-agent-helper-1: writing `PAM_PROMPT_ECHO_ON ' to stdout\n");
-#endif /* PAH_DEBUG */
-          fprintf (stdout, "PAM_PROMPT_ECHO_ON ");
-        conv1:
-#ifdef PAH_DEBUG
-          fprintf (stderr, "polkit-agent-helper-1: writing `%s' to stdout\n", msg[i]->msg);
-#endif /* PAH_DEBUG */
-          if (strlen (msg[i]->msg) > 0 && msg[i]->msg[strlen (msg[i]->msg) - 1] == '\n')
-            msg[i]->msg[strlen (msg[i]->msg) - 1] == '\0';
-          escaped = g_strescape (msg[i]->msg, NULL);
-          fputs (escaped, stdout);
-          g_free (escaped);
-#ifdef PAH_DEBUG
-          fprintf (stderr, "polkit-agent-helper-1: writing newline to stdout\n");
-#endif /* PAH_DEBUG */
-          fputc ('\n', stdout);
-#ifdef PAH_DEBUG
-          fprintf (stderr, "polkit-agent-helper-1: flushing stdout\n");
-#endif /* PAH_DEBUG */
-          fflush (stdout);
+          send_to_helper ("PAM_PROMPT_ECHO_ON", msg[i]->msg);
 
+        conv1:
           if (fgets (buf, sizeof buf, stdin) == NULL)
             goto error;
 
@@ -291,17 +278,11 @@ conversation_function (int n, const stru
           break;
 
         case PAM_ERROR_MSG:
-          fprintf (stdout, "PAM_ERROR_MSG ");
-          goto conv2;
+          send_to_helper ("PAM_ERROR_MSG", msg[i]->msg);
+          break;
 
         case PAM_TEXT_INFO:
-          fprintf (stdout, "PAM_TEXT_INFO ");
-        conv2:
-          fputs (msg[i]->msg, stdout);
-          if (strlen (msg[i]->msg) > 0 &&
-              msg[i]->msg[strlen (msg[i]->msg) - 1] != '\n')
-            fputc ('\n', stdout);
-          fflush (stdout);
+          send_to_helper ("PAM_TEXT_INFO", msg[i]->msg);
           break;
 
         default: