summaryrefslogtreecommitdiffstats
path: root/patches/polkit-0.105/0035-0.114-Refactor-send_to_helper-usage.patch
blob: 8be72ef26bafe8e29542da609bd7d1115185d4f7 (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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
From: Dariusz Gadomski <dariusz.gadomski@canonical.com>
Date: Thu, 12 Nov 2015 15:01:19 +0100
Subject: [PATCH] 0.114: Refactor send_to_helper usage

There were duplicated pieces of code detecting EOLs and escaping the code.
Those actions has been delegated to already-existing send_to_helper function.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92886
Origin: upstream, 0.114, commit:2690cd0312b310946c86674c8dd1f55c63f7dd6a

Imported from policykit-1_0.105-25.debian.tar.xz

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
---
 src/polkitagent/polkitagenthelper-pam.c | 81 ++++++++-----------------
 1 file changed, 26 insertions(+), 55 deletions(-)

diff --git a/src/polkitagent/polkitagenthelper-pam.c b/src/polkitagent/polkitagenthelper-pam.c
index 063d656dcbef..3ea3a3f2e801 100644
--- a/src/polkitagent/polkitagenthelper-pam.c
+++ b/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,9 +242,6 @@ conversation_function (int n, const struct pam_message **msg, struct pam_respons
   struct pam_response *aresp;
   char buf[PAM_MAX_RESP_SIZE];
   int i;
-  gchar *escaped = NULL;
-  gchar *tmp = NULL;
-  size_t len;
 
   (void)data;
   if (n <= 0 || n > PAM_MAX_NUM_MSG)
@@ -251,38 +258,13 @@ conversation_function (int n, const struct pam_message **msg, struct pam_respons
         {
 
         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 */
-          tmp = g_strdup (msg[i]->msg);
-          len = strlen (tmp);
-          if (len > 0 && tmp[len - 1] == '\n')
-            tmp[len - 1] = '\0';
-          escaped = g_strescape (tmp, NULL);
-          g_free (tmp);
-          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;
 
@@ -296,22 +278,11 @@ conversation_function (int n, const struct pam_message **msg, struct pam_respons
           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:
-          tmp = g_strdup (msg[i]->msg);
-          len = strlen (tmp);
-          if (len > 0 && tmp[len - 1] == '\n')
-            tmp[len - 1] = '\0';
-          escaped = g_strescape (tmp, NULL);
-          g_free (tmp);
-          fputs (escaped, stdout);
-          g_free (escaped);
-          fputc ('\n', stdout);
-          fflush (stdout);
+          send_to_helper ("PAM_TEXT_INFO", msg[i]->msg);
           break;
 
         default: