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