summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-05-25 12:27:49 +0100
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-05-25 12:27:49 +0100
commite84dce78061c1fa18ee4da1aa858c5cf0f539f82 (patch)
treecdaa3b5a1e7eefc05f7fab7cd8b6a90d3b23c904 /src
parentf64ce3f5afad89276b8e54688a4df668c4e1ee34 (diff)
e auth - nicely prefix logs and clean up error reports and report more
Diffstat (limited to 'src')
-rw-r--r--src/bin/e_ckpasswd_main.c94
1 files changed, 45 insertions, 49 deletions
diff --git a/src/bin/e_ckpasswd_main.c b/src/bin/e_ckpasswd_main.c
index 092128035..b5e01d4ae 100644
--- a/src/bin/e_ckpasswd_main.c
+++ b/src/bin/e_ckpasswd_main.c
@@ -179,11 +179,11 @@ polkit_agent_response(void *data EINA_UNUSED, const Eldbus_Message *msg,
179 ecore_main_loop_quit(); 179 ecore_main_loop_quit();
180 if (eldbus_message_error_get(msg, &name, &text)) 180 if (eldbus_message_error_get(msg, &name, &text))
181 { 181 {
182 printf("Could not respond to auth.\n %s:\n %s\n", name, text); 182 fprintf(stderr, "AUTH: Could not respond to auth.\n %s:\n %s\n", name, text);
183 return; 183 return;
184 } 184 }
185 polkit_auth_ok = 0; 185 polkit_auth_ok = 0;
186 printf("Auth OK\n"); 186 fprintf(stderr, "AUTH: OK\n");
187} 187}
188 188
189int 189int
@@ -199,46 +199,42 @@ polkit_auth(const char *cookie, unsigned int auth_uid)
199 ecore_init(); 199 ecore_init();
200 eldbus_init(); 200 eldbus_init();
201 c = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM); 201 c = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM);
202 if (!c) return -1; 202#define BARF(str) do { \
203 fprintf(stderr, "AUTH: POLKIT: %s\n", str); \
204 return -1; \
205} while (0)
206 if (!c) BARF("Cannot get session dbus");
203 obj = eldbus_object_get(c, "org.freedesktop.PolicyKit1", 207 obj = eldbus_object_get(c, "org.freedesktop.PolicyKit1",
204 "/org/freedesktop/PolicyKit1/Authority"); 208 "/org/freedesktop/PolicyKit1/Authority");
205 if (!obj) return -1; 209 if (!obj) BARF("Cannot get obj: org.freedesktop.PolicyKit1 /org/freedesktop/PolicyKit1/Authority");
206 proxy = eldbus_proxy_get(obj, "org.freedesktop.PolicyKit1.Authority"); 210 proxy = eldbus_proxy_get(obj, "org.freedesktop.PolicyKit1.Authority");
207 if (!proxy) return -1; 211 if (!proxy) BARF("Cannot proxy: org.freedesktop.PolicyKit1.Authority");
208 m = eldbus_proxy_method_call_new(proxy, "AuthenticationAgentResponse2"); 212 m = eldbus_proxy_method_call_new(proxy, "AuthenticationAgentResponse2");
209 if (!m) return -1; 213 if (!m) BARF("Cannot get method call: AuthenticationAgentResponse2");
210 iter = eldbus_message_iter_get(m); 214 iter = eldbus_message_iter_get(m);
211 if (!iter) return -1; 215 if (!iter) BARF("Cannot set iter on proxy");
212 if (eldbus_message_iter_arguments_append(iter, "us", auth_uid, cookie)) 216 if (!eldbus_message_iter_arguments_append(iter, "us", auth_uid, cookie))
213 { 217 BARF("Cannot append 'us' args");
214 if (eldbus_message_iter_arguments_append(iter, "(sa{sv})", &subj)) 218 if (!eldbus_message_iter_arguments_append(iter, "(sa{sv})", &subj))
215 { 219 BARF("Cannot append '(sa{sv})' args");
216 if (eldbus_message_iter_basic_append(subj, 's', "unix-user")) 220 if (!eldbus_message_iter_basic_append(subj, 's', "unix-user"))
217 { 221 BARF("Cannot append 's' arg for unix-user");
218 if (eldbus_message_iter_arguments_append(subj, "a{sv}", &array)) 222 if (!eldbus_message_iter_arguments_append(subj, "a{sv}", &array))
219 { 223 BARF("Cannot append 'a{sv}' args");
220 if (eldbus_message_iter_arguments_append(array, "{sv}", &dict)) 224 if (!eldbus_message_iter_arguments_append(array, "{sv}", &dict))
221 { 225 BARF("Cannot append '{sv}' args");
222 if (eldbus_message_iter_basic_append(dict, 's', "uid")) 226 if (!eldbus_message_iter_basic_append(dict, 's', "uid"))
223 { 227 BARF("Cannot append 's' arg for uid");
224 vari = eldbus_message_iter_container_new(dict, 'v', "u"); 228 vari = eldbus_message_iter_container_new(dict, 'v', "u");
225 if (vari) 229 if (!vari)
226 { 230 BARF("Cannot create new iter container");
227 if (eldbus_message_iter_basic_append(vari, 'u', auth_uid)) 231 if (!eldbus_message_iter_basic_append(vari, 'u', auth_uid))
228 { 232 BARF("Cannot append 'u' arg for auth_id");
229 eldbus_message_iter_container_close(dict, vari); 233 eldbus_message_iter_container_close(dict, vari);
230 } else return -1; 234 eldbus_message_iter_container_close(array, dict);
231 } else return -1; 235 eldbus_message_iter_container_close(subj, array);
232 } else return -1; 236 eldbus_message_iter_container_close(iter, subj);
233 eldbus_message_iter_container_close(array, dict); 237 eldbus_proxy_send(proxy, m, polkit_agent_response, NULL, -1);
234 } else return -1;
235 eldbus_message_iter_container_close(subj, array);
236 } else return -1;
237 } else return -1;
238 eldbus_message_iter_container_close(iter, subj);
239 } else return -1;
240 eldbus_proxy_send(proxy, m, polkit_agent_response, NULL, -1);
241 } else return -1;
242 238
243 ecore_main_loop_begin(); 239 ecore_main_loop_begin();
244 240
@@ -273,7 +269,7 @@ main(int argc, char **argv)
273 rd = read(0, pw, sizeof(pw) - 1); 269 rd = read(0, pw, sizeof(pw) - 1);
274 if (rd < 0) 270 if (rd < 0)
275 { 271 {
276 fprintf(stderr, "Error. Can't read passwd on stdin\n"); 272 fprintf(stderr, "AUTH: Error. Can't read passwd on stdin\n");
277 goto err; 273 goto err;
278 } 274 }
279 pw[rd] = 0; 275 pw[rd] = 0;
@@ -296,7 +292,7 @@ main(int argc, char **argv)
296 rd = read(0, pw + pos, 1); 292 rd = read(0, pw + pos, 1);
297 if (rd < 0) 293 if (rd < 0)
298 { 294 {
299 fprintf(stderr, "Error. Can't read polkit cookie on stdin\n"); 295 fprintf(stderr, "AUTH: Error. Can't read polkit cookie on stdin\n");
300 goto err; 296 goto err;
301 } 297 }
302 if (pw[pos] == ' ') 298 if (pw[pos] == ' ')
@@ -312,7 +308,7 @@ main(int argc, char **argv)
312 pos++; 308 pos++;
313 if (pos > 4000) 309 if (pos > 4000)
314 { 310 {
315 fprintf(stderr, "Error. Polkit cookie too long\n"); 311 fprintf(stderr, "AUTH: Error. Polkit cookie too long\n");
316 return -10; 312 return -10;
317 } 313 }
318 } 314 }
@@ -322,14 +318,14 @@ main(int argc, char **argv)
322 rd = read(0, pw + pos, 1); 318 rd = read(0, pw + pos, 1);
323 if (rd < 0) 319 if (rd < 0)
324 { 320 {
325 fprintf(stderr, "Error. Can't read polkit uid on stdin\n"); 321 fprintf(stderr, "AUTH: Error. Can't read polkit uid on stdin\n");
326 goto err; 322 goto err;
327 } 323 }
328 if (pw[pos] == ' ') 324 if (pw[pos] == ' ')
329 { 325 {
330 pw[pos] = 0; 326 pw[pos] = 0;
331 polkit_uid = atoi(pw); 327 polkit_uid = atoi(pw);
332 printf("UID: [%u]\n", polkit_uid); 328 printf("AUTH: UID: [%u]\n", polkit_uid);
333 break; 329 break;
334 } 330 }
335 else 331 else
@@ -337,17 +333,17 @@ main(int argc, char **argv)
337 pos++; 333 pos++;
338 if (pos > 4000) 334 if (pos > 4000)
339 { 335 {
340 fprintf(stderr, "Error. Polkit uid too long\n"); 336 fprintf(stderr, "AUTH: Error. Polkit uid too long\n");
341 return -11; 337 return -11;
342 } 338 }
343 } 339 }
344 } 340 }
345 // password 341 // password
346 printf("READPASS...\n"); 342 fprintf(stderr, "AUTH: readpass...\n");
347 rd = read(0, pw, sizeof(pw) - 1); 343 rd = read(0, pw, sizeof(pw) - 1);
348 if (rd < 0) 344 if (rd < 0)
349 { 345 {
350 fprintf(stderr, "Error. Can't read passwd on stdin\n"); 346 fprintf(stderr, "AUTH: Error. Can't read passwd on stdin\n");
351 goto err; 347 goto err;
352 } 348 }
353 pw[rd] = 0; 349 pw[rd] = 0;
@@ -366,20 +362,20 @@ main(int argc, char **argv)
366 362
367 if (_check_auth(uid, pw) == 0) 363 if (_check_auth(uid, pw) == 0)
368 { 364 {
369 fprintf(stderr, "Password OK\n"); 365 fprintf(stderr, "AUTH: Password OK\n");
370 if (polkit_mode == 1) 366 if (polkit_mode == 1)
371 { 367 {
372 if (polkit_auth(polkit_cookie, polkit_uid) == 0) 368 if (polkit_auth(polkit_cookie, polkit_uid) == 0)
373 { 369 {
374 fprintf(stderr, "Polkit AuthenticationAgentResponse2 success\n"); 370 fprintf(stderr, "AUTH: Polkit AuthenticationAgentResponse2 success\n");
375 return 0; 371 return 0;
376 } 372 }
377 fprintf(stderr, "Polkit AuthenticationAgentResponse2 failure\n"); 373 fprintf(stderr, "AUTH: Polkit AuthenticationAgentResponse2 failure\n");
378 return -2; 374 return -2;
379 } 375 }
380 return 0; 376 return 0;
381 } 377 }
382err: 378err:
383 fprintf(stderr, "Password auth fail\n"); 379 fprintf(stderr, "AUTH: Password auth fail\n");
384 return -1; 380 return -1;
385} 381}