Commit 21459954 21459954c24a8e1669ee78370cade4e5dc224739 by Sergey Poznyakoff

Return meaningful error codes.

1 parent 29b867a3
...@@ -451,26 +451,37 @@ mu_radius_authenticate (struct mu_auth_data **return_data ARG_UNUSED, ...@@ -451,26 +451,37 @@ mu_radius_authenticate (struct mu_auth_data **return_data ARG_UNUSED,
451 const void *key, 451 const void *key,
452 void *func_data ARG_UNUSED, void *call_data) 452 void *func_data ARG_UNUSED, void *call_data)
453 { 453 {
454 int rc; 454 int rc, code;
455 grad_request_t *reply; 455 grad_request_t *reply;
456 const struct mu_auth_data *auth_data = key; 456 const struct mu_auth_data *auth_data = key;
457 457
458 if (!radius_auth_enabled) 458 if (!radius_auth_enabled)
459 { 459 return ENOSYS;
460 errno = ENOSYS;
461 return 1;
462 }
463 460
464 if (!auth_request) 461 if (!auth_request)
465 { 462 {
466 mu_error (_("--radius-auth-request is not specified")); 463 mu_error (_("--radius-auth-request is not specified"));
467 return 1; 464 return EINVAL;
468 } 465 }
469 466
470 reply = send_request (auth_request, RT_ACCESS_REQUEST, 467 reply = send_request (auth_request, RT_ACCESS_REQUEST,
471 auth_data->name, (char*) call_data); 468 auth_data->name, (char*) call_data);
472 rc = !reply || reply->code != RT_ACCESS_ACCEPT; 469 if (!reply)
470 return EAGAIN;
471
472 switch (reply->code) {
473 case RT_ACCESS_ACCEPT:
474 rc = 0;
475 break;
476
477 case RT_ACCESS_CHALLENGE:
478 /* Should return another code here? */
479 default:
480 rc = MU_ERR_AUTH_FAILURE;
481 }
482
473 grad_request_free (reply); 483 grad_request_free (reply);
484
474 return rc; 485 return rc;
475 } 486 }
476 487
...@@ -479,31 +490,35 @@ mu_auth_radius_user_by_name (struct mu_auth_data **return_data, ...@@ -479,31 +490,35 @@ mu_auth_radius_user_by_name (struct mu_auth_data **return_data,
479 const void *key, 490 const void *key,
480 void *unused_func_data, void *unused_call_data) 491 void *unused_func_data, void *unused_call_data)
481 { 492 {
482 int rc = 1; 493 int rc = MU_ERR_AUTH_FAILURE;
483 grad_request_t *reply; 494 grad_request_t *reply;
484 495
485 if (!radius_auth_enabled) 496 if (!radius_auth_enabled)
486 { 497 return ENOSYS;
487 errno = ENOSYS;
488 return 1;
489 }
490 498
491 if (!getpwnam_request) 499 if (!getpwnam_request)
492 { 500 {
493 mu_error (_("--radius-getpwnam-request is not specified")); 501 mu_error (_("--radius-getpwnam-request is not specified"));
494 return 1; 502 return MU_ERR_FAILURE;
495 } 503 }
496 504
497 reply = send_request (getpwnam_request, RT_ACCESS_REQUEST, key, NULL); 505 reply = send_request (getpwnam_request, RT_ACCESS_REQUEST, key, NULL);
498 if (!reply) 506 if (!reply)
499 mu_error (_("radius server did not respond")); 507 {
500 else if (reply->code != RT_ACCESS_ACCEPT) 508 mu_error (_("radius server did not respond"));
501 mu_error (_("%s: server returned %s"), 509 rc = EAGAIN;
502 (char*) key, 510 }
503 grad_request_code_to_name (reply->code));
504 else 511 else
505 rc = decode_reply (reply, key, "x", return_data); 512 {
506 grad_request_free (reply); 513 if (reply->code != RT_ACCESS_ACCEPT)
514 mu_error (_("%s: server returned %s"),
515 (char*) key,
516 grad_request_code_to_name (reply->code));
517 else
518 rc = decode_reply (reply, key, "x", return_data);
519
520 grad_request_free (reply);
521 }
507 return rc; 522 return rc;
508 } 523 }
509 524
...@@ -512,39 +527,37 @@ mu_auth_radius_user_by_uid (struct mu_auth_data **return_data, ...@@ -512,39 +527,37 @@ mu_auth_radius_user_by_uid (struct mu_auth_data **return_data,
512 const void *key, 527 const void *key,
513 void *func_data, void *call_data) 528 void *func_data, void *call_data)
514 { 529 {
515 int rc = 1; 530 int rc = MU_ERR_AUTH_FAILURE;
516 grad_request_t *reply; 531 grad_request_t *reply;
517 char uidstr[64]; 532 char uidstr[64];
518 533
519 if (!radius_auth_enabled) 534 if (!radius_auth_enabled)
520 { 535 return ENOSYS;
521 errno = ENOSYS;
522 return 1;
523 }
524 536
525 if (!key) 537 if (!key)
526 { 538 return EINVAL;
527 errno = EINVAL;
528 return 1;
529 }
530 539
531 if (!getpwuid_request) 540 if (!getpwuid_request)
532 { 541 {
533 mu_error (_("--radius-getpwuid-request is not specified")); 542 mu_error (_("--radius-getpwuid-request is not specified"));
534 return 1; 543 return MU_ERR_FAILURE;
535 } 544 }
536 545
537 snprintf (uidstr, sizeof (uidstr), "%u", *(uid_t*)key); 546 snprintf (uidstr, sizeof (uidstr), "%u", *(uid_t*)key);
538 reply = send_request (getpwuid_request, RT_ACCESS_REQUEST, uidstr, NULL); 547 reply = send_request (getpwuid_request, RT_ACCESS_REQUEST, uidstr, NULL);
548 if (!reply)
549 {
550 mu_error (_("radius server did not respond"));
551 rc = EAGAIN;
552 }
539 if (reply->code != RT_ACCESS_ACCEPT) 553 if (reply->code != RT_ACCESS_ACCEPT)
540 { 554 {
541 mu_error (_("uid %s: server returned %s"), uidstr, 555 mu_error (_("uid %s: server returned %s"), uidstr,
542 grad_request_code_to_name (reply->code)); 556 grad_request_code_to_name (reply->code));
543 } 557 }
544 else 558 else
545 { 559 rc = decode_reply (reply, uidstr, "x", return_data);
546 rc = decode_reply (reply, uidstr, "x", return_data); 560
547 }
548 grad_request_free (reply); 561 grad_request_free (reply);
549 return rc; 562 return rc;
550 } 563 }
...@@ -560,8 +573,7 @@ mu_radius_authenticate (struct mu_auth_data **return_data ARG_UNUSED, ...@@ -560,8 +573,7 @@ mu_radius_authenticate (struct mu_auth_data **return_data ARG_UNUSED,
560 const void *key, 573 const void *key,
561 void *func_data ARG_UNUSED, void *call_data) 574 void *func_data ARG_UNUSED, void *call_data)
562 { 575 {
563 errno = ENOSYS; 576 return ENOSYS;
564 return 1;
565 } 577 }
566 578
567 static int 579 static int
...@@ -570,8 +582,7 @@ mu_auth_radius_user_by_name (struct mu_auth_data **return_data ARG_UNUSED, ...@@ -570,8 +582,7 @@ mu_auth_radius_user_by_name (struct mu_auth_data **return_data ARG_UNUSED,
570 void *func_data ARG_UNUSED, 582 void *func_data ARG_UNUSED,
571 void *call_data ARG_UNUSED) 583 void *call_data ARG_UNUSED)
572 { 584 {
573 errno = ENOSYS; 585 return ENOSYS;
574 return 1;
575 } 586 }
576 587
577 static int 588 static int
...@@ -579,8 +590,7 @@ mu_auth_radius_user_by_uid (struct mu_auth_data **return_data, ...@@ -579,8 +590,7 @@ mu_auth_radius_user_by_uid (struct mu_auth_data **return_data,
579 const void *key, 590 const void *key,
580 void *func_data, void *call_data) 591 void *func_data, void *call_data)
581 { 592 {
582 errno = ENOSYS; 593 return ENOSYS;
583 return 1;
584 } 594 }
585 #endif 595 #endif
586 596
......
...@@ -271,6 +271,56 @@ struct argp mu_sql_argp = { ...@@ -271,6 +271,56 @@ struct argp mu_sql_argp = {
271 }; 271 };
272 272
273 static int 273 static int
274 decode_tuple (mu_sql_connection_t conn, int n, struct mu_auth_data **return_data)
275 {
276 int rc;
277 char *mailbox_name = NULL;
278 char *name;
279
280 if (mu_sql_get_column (conn, 0, 0, &name))
281 return MU_ERR_FAILURE;
282
283 if (n == 7)
284 {
285 char *tmp;
286 if (mu_sql_get_column (conn, 0, 6, &tmp))
287 return MU_ERR_FAILURE;
288 if ((mailbox_name = strdup (tmp)) == NULL)
289 return ENOMEM;
290 }
291 else if (mu_construct_user_mailbox_url (&mailbox_name, name))
292 return MU_ERR_FAILURE;
293
294 if (mailbox_name)
295 {
296 char *passwd, *suid, *sgid, *dir, *shell;
297
298 if (mu_sql_get_column (conn, 0, 1, &passwd)
299 || mu_sql_get_column (conn, 0, 2, &suid)
300 || mu_sql_get_column (conn, 0, 3, &sgid)
301 || mu_sql_get_column (conn, 0, 4, &dir)
302 || mu_sql_get_column (conn, 0, 5, &shell))
303 return MU_ERR_FAILURE;
304
305 rc = mu_auth_data_alloc (return_data,
306 name,
307 passwd,
308 atoi (suid),
309 atoi (sgid),
310 "SQL User",
311 dir,
312 shell,
313 mailbox_name,
314 1);
315 }
316 else
317 rc = MU_ERR_AUTH_FAILURE;
318
319 free (mailbox_name);
320 return rc;
321 }
322
323 static int
274 mu_auth_sql_by_name (struct mu_auth_data **return_data, 324 mu_auth_sql_by_name (struct mu_auth_data **return_data,
275 const void *key, 325 const void *key,
276 void *func_data ARG_UNUSED, 326 void *func_data ARG_UNUSED,
...@@ -282,15 +332,12 @@ mu_auth_sql_by_name (struct mu_auth_data **return_data, ...@@ -282,15 +332,12 @@ mu_auth_sql_by_name (struct mu_auth_data **return_data,
282 size_t n; 332 size_t n;
283 333
284 if (!key) 334 if (!key)
285 { 335 return EINVAL;
286 errno = EINVAL;
287 return 1;
288 }
289 336
290 query_str = mu_sql_expand_query (mu_sql_getpwnam_query, key); 337 query_str = mu_sql_expand_query (mu_sql_getpwnam_query, key);
291 338
292 if (!query_str) 339 if (!query_str)
293 return 1; 340 return MU_ERR_FAILURE;
294 341
295 status = mu_sql_connection_init (&conn, 342 status = mu_sql_connection_init (&conn,
296 sql_interface, 343 sql_interface,
...@@ -304,7 +351,7 @@ mu_auth_sql_by_name (struct mu_auth_data **return_data, ...@@ -304,7 +351,7 @@ mu_auth_sql_by_name (struct mu_auth_data **return_data,
304 mu_error ("%s: %s", mu_strerror (status), mu_sql_strerror (conn)); 351 mu_error ("%s: %s", mu_strerror (status), mu_sql_strerror (conn));
305 mu_sql_connection_destroy (&conn); 352 mu_sql_connection_destroy (&conn);
306 free (query_str); 353 free (query_str);
307 return status; 354 return MU_ERR_FAILURE;
308 } 355 }
309 356
310 status = mu_sql_connect (conn); 357 status = mu_sql_connect (conn);
...@@ -314,7 +361,7 @@ mu_auth_sql_by_name (struct mu_auth_data **return_data, ...@@ -314,7 +361,7 @@ mu_auth_sql_by_name (struct mu_auth_data **return_data,
314 mu_error ("%s: %s", mu_strerror (status), mu_sql_strerror (conn)); 361 mu_error ("%s: %s", mu_strerror (status), mu_sql_strerror (conn));
315 mu_sql_connection_destroy (&conn); 362 mu_sql_connection_destroy (&conn);
316 free (query_str); 363 free (query_str);
317 return status; 364 return EAGAIN;
318 } 365 }
319 366
320 status = mu_sql_query (conn, query_str); 367 status = mu_sql_query (conn, query_str);
...@@ -326,7 +373,7 @@ mu_auth_sql_by_name (struct mu_auth_data **return_data, ...@@ -326,7 +373,7 @@ mu_auth_sql_by_name (struct mu_auth_data **return_data,
326 (status == MU_ERR_SQL) ? mu_sql_strerror (conn) : 373 (status == MU_ERR_SQL) ? mu_sql_strerror (conn) :
327 mu_strerror (status)); 374 mu_strerror (status));
328 mu_sql_connection_destroy (&conn); 375 mu_sql_connection_destroy (&conn);
329 return 1; 376 return MU_ERR_FAILURE;
330 } 377 }
331 378
332 status = mu_sql_store_result (conn); 379 status = mu_sql_store_result (conn);
...@@ -337,59 +384,14 @@ mu_auth_sql_by_name (struct mu_auth_data **return_data, ...@@ -337,59 +384,14 @@ mu_auth_sql_by_name (struct mu_auth_data **return_data,
337 (status == MU_ERR_SQL) ? mu_sql_strerror (conn) : 384 (status == MU_ERR_SQL) ? mu_sql_strerror (conn) :
338 mu_strerror (status)); 385 mu_strerror (status));
339 mu_sql_connection_destroy (&conn); 386 mu_sql_connection_destroy (&conn);
340 return 1; 387 return MU_ERR_FAILURE;
341 } 388 }
342 389
343 mu_sql_num_tuples (conn, &n); 390 mu_sql_num_tuples (conn, &n);
344 if (n == 0) 391 if (n == 0)
345 { 392 rc = MU_ERR_AUTH_FAILURE;
346 rc = 1;
347 }
348 else 393 else
349 { 394 rc = decode_tuple (conn, n, return_data);
350 char *mailbox_name = NULL;
351 char *name;
352
353 mu_sql_get_column (conn, 0, 0, &name);
354
355 if (n == 7)
356 {
357 char *tmp;
358 mu_sql_get_column (conn, 0, 6, &tmp);
359 mailbox_name = strdup (tmp);
360 }
361 else
362 {
363 mu_construct_user_mailbox_url (&mailbox_name, name);
364 /* FIXME: Error code is lost */
365 }
366
367 if (mailbox_name)
368 {
369 char *passwd, *suid, *sgid, *dir, *shell;
370
371 mu_sql_get_column (conn, 0, 1, &passwd);
372 mu_sql_get_column (conn, 0, 2, &suid);
373 mu_sql_get_column (conn, 0, 3, &sgid);
374 mu_sql_get_column (conn, 0, 4, &dir);
375 mu_sql_get_column (conn, 0, 5, &shell);
376
377 rc = mu_auth_data_alloc (return_data,
378 name,
379 passwd,
380 atoi (suid),
381 atoi (sgid),
382 "SQL User",
383 dir,
384 shell,
385 mailbox_name,
386 1);
387 }
388 else
389 rc = 1;
390
391 free (mailbox_name);
392 }
393 395
394 mu_sql_release_result (conn); 396 mu_sql_release_result (conn);
395 mu_sql_disconnect (conn); 397 mu_sql_disconnect (conn);
...@@ -411,16 +413,13 @@ mu_auth_sql_by_uid (struct mu_auth_data **return_data, ...@@ -411,16 +413,13 @@ mu_auth_sql_by_uid (struct mu_auth_data **return_data,
411 size_t n; 413 size_t n;
412 414
413 if (!key) 415 if (!key)
414 { 416 return EINVAL;
415 errno = EINVAL;
416 return 1;
417 }
418 417
419 snprintf (uidstr, sizeof (uidstr), "%u", *(uid_t*)key); 418 snprintf (uidstr, sizeof (uidstr), "%u", *(uid_t*)key);
420 query_str = mu_sql_expand_query (mu_sql_getpwuid_query, uidstr); 419 query_str = mu_sql_expand_query (mu_sql_getpwuid_query, uidstr);
421 420
422 if (!query_str) 421 if (!query_str)
423 return 1; 422 return ENOMEM;
424 423
425 status = mu_sql_connection_init (&conn, 424 status = mu_sql_connection_init (&conn,
426 sql_interface, 425 sql_interface,
...@@ -434,7 +433,7 @@ mu_auth_sql_by_uid (struct mu_auth_data **return_data, ...@@ -434,7 +433,7 @@ mu_auth_sql_by_uid (struct mu_auth_data **return_data,
434 mu_error ("%s: %s", mu_strerror (status), mu_sql_strerror (conn)); 433 mu_error ("%s: %s", mu_strerror (status), mu_sql_strerror (conn));
435 mu_sql_connection_destroy (&conn); 434 mu_sql_connection_destroy (&conn);
436 free (query_str); 435 free (query_str);
437 return status; 436 return MU_ERR_FAILURE;
438 } 437 }
439 438
440 status = mu_sql_connect (conn); 439 status = mu_sql_connect (conn);
...@@ -444,7 +443,7 @@ mu_auth_sql_by_uid (struct mu_auth_data **return_data, ...@@ -444,7 +443,7 @@ mu_auth_sql_by_uid (struct mu_auth_data **return_data,
444 mu_error ("%s: %s", mu_strerror (status), mu_sql_strerror (conn)); 443 mu_error ("%s: %s", mu_strerror (status), mu_sql_strerror (conn));
445 mu_sql_connection_destroy (&conn); 444 mu_sql_connection_destroy (&conn);
446 free (query_str); 445 free (query_str);
447 return status; 446 return EAGAIN;
448 } 447 }
449 448
450 status = mu_sql_query (conn, query_str); 449 status = mu_sql_query (conn, query_str);
...@@ -456,7 +455,7 @@ mu_auth_sql_by_uid (struct mu_auth_data **return_data, ...@@ -456,7 +455,7 @@ mu_auth_sql_by_uid (struct mu_auth_data **return_data,
456 (status == MU_ERR_SQL) ? mu_sql_strerror (conn) : 455 (status == MU_ERR_SQL) ? mu_sql_strerror (conn) :
457 mu_strerror (status)); 456 mu_strerror (status));
458 mu_sql_connection_destroy (&conn); 457 mu_sql_connection_destroy (&conn);
459 return 1; 458 return MU_ERR_FAILURE;
460 } 459 }
461 460
462 status = mu_sql_store_result (conn); 461 status = mu_sql_store_result (conn);
...@@ -467,59 +466,15 @@ mu_auth_sql_by_uid (struct mu_auth_data **return_data, ...@@ -467,59 +466,15 @@ mu_auth_sql_by_uid (struct mu_auth_data **return_data,
467 (status == MU_ERR_SQL) ? mu_sql_strerror (conn) : 466 (status == MU_ERR_SQL) ? mu_sql_strerror (conn) :
468 mu_strerror (status)); 467 mu_strerror (status));
469 mu_sql_connection_destroy (&conn); 468 mu_sql_connection_destroy (&conn);
470 return 1; 469 return MU_ERR_FAILURE;
471 } 470 }
472 471
473 mu_sql_num_tuples (conn, &n); 472 mu_sql_num_tuples (conn, &n);
474 473
475 if (n == 0) 474 if (n == 0)
476 { 475 rc = MU_ERR_AUTH_FAILURE;
477 rc = 1;
478 }
479 else 476 else
480 { 477 rc = decode_tuple (conn, n, return_data);
481 char *name;
482 char *mailbox_name = NULL;
483
484 mu_sql_get_column (conn, 0, 0, &name);
485
486 if (n == 7)
487 {
488 char *tmp;
489 mu_sql_get_column (conn, 0, 6, &tmp);
490 mailbox_name = strdup (tmp);
491 }
492 else
493 {
494 mu_construct_user_mailbox_url (&mailbox_name, name);
495 /* FIXME: Error code is lost */
496 }
497
498 if (mailbox_name)
499 {
500 char *passwd, *suid, *sgid, *dir, *shell;
501
502 mu_sql_get_column (conn, 0, 1, &passwd);
503 mu_sql_get_column (conn, 0, 2, &suid);
504 mu_sql_get_column (conn, 0, 3, &sgid);
505 mu_sql_get_column (conn, 0, 4, &dir);
506 mu_sql_get_column (conn, 0, 5, &shell);
507
508 rc = mu_auth_data_alloc (return_data,
509 name,
510 passwd,
511 atoi (suid),
512 atoi (sgid),
513 "SQL User",
514 dir,
515 shell,
516 mailbox_name,
517 1);
518 }
519 else
520 rc = 1;
521 free (mailbox_name);
522 }
523 478
524 mu_sql_release_result (conn); 479 mu_sql_release_result (conn);
525 mu_sql_disconnect (conn); 480 mu_sql_disconnect (conn);
...@@ -553,7 +508,7 @@ mu_sql_getpass (const char *username, char **passwd) ...@@ -553,7 +508,7 @@ mu_sql_getpass (const char *username, char **passwd)
553 mu_error ("%s: %s", mu_strerror (status), mu_sql_strerror (conn)); 508 mu_error ("%s: %s", mu_strerror (status), mu_sql_strerror (conn));
554 mu_sql_connection_destroy (&conn); 509 mu_sql_connection_destroy (&conn);
555 free (query_str); 510 free (query_str);
556 return status; 511 return MU_ERR_FAILURE;
557 } 512 }
558 513
559 status = mu_sql_connect (conn); 514 status = mu_sql_connect (conn);
...@@ -563,7 +518,7 @@ mu_sql_getpass (const char *username, char **passwd) ...@@ -563,7 +518,7 @@ mu_sql_getpass (const char *username, char **passwd)
563 mu_error ("%s: %s", mu_strerror (status), mu_sql_strerror (conn)); 518 mu_error ("%s: %s", mu_strerror (status), mu_sql_strerror (conn));
564 mu_sql_connection_destroy (&conn); 519 mu_sql_connection_destroy (&conn);
565 free (query_str); 520 free (query_str);
566 return status; 521 return EAGAIN;
567 } 522 }
568 523
569 status = mu_sql_query (conn, query_str); 524 status = mu_sql_query (conn, query_str);
...@@ -575,7 +530,7 @@ mu_sql_getpass (const char *username, char **passwd) ...@@ -575,7 +530,7 @@ mu_sql_getpass (const char *username, char **passwd)
575 (status == MU_ERR_SQL) ? mu_sql_strerror (conn) : 530 (status == MU_ERR_SQL) ? mu_sql_strerror (conn) :
576 mu_strerror (status)); 531 mu_strerror (status));
577 mu_sql_connection_destroy (&conn); 532 mu_sql_connection_destroy (&conn);
578 return status; 533 return MU_ERR_FAILURE;
579 } 534 }
580 535
581 status = mu_sql_store_result (conn); 536 status = mu_sql_store_result (conn);
...@@ -586,7 +541,7 @@ mu_sql_getpass (const char *username, char **passwd) ...@@ -586,7 +541,7 @@ mu_sql_getpass (const char *username, char **passwd)
586 (status == MU_ERR_SQL) ? mu_sql_strerror (conn) : 541 (status == MU_ERR_SQL) ? mu_sql_strerror (conn) :
587 mu_strerror (status)); 542 mu_strerror (status));
588 mu_sql_connection_destroy (&conn); 543 mu_sql_connection_destroy (&conn);
589 return status; 544 return MU_ERR_FAILURE;
590 } 545 }
591 546
592 status = mu_sql_get_column (conn, 0, 0, &sql_pass); 547 status = mu_sql_get_column (conn, 0, 0, &sql_pass);
...@@ -597,7 +552,7 @@ mu_sql_getpass (const char *username, char **passwd) ...@@ -597,7 +552,7 @@ mu_sql_getpass (const char *username, char **passwd)
597 mu_strerror (status)); 552 mu_strerror (status));
598 mu_sql_release_result (conn); 553 mu_sql_release_result (conn);
599 mu_sql_connection_destroy (&conn); 554 mu_sql_connection_destroy (&conn);
600 return status; 555 return MU_ERR_FAILURE;
601 } 556 }
602 557
603 *passwd = strdup (sql_pass); 558 *passwd = strdup (sql_pass);
...@@ -622,10 +577,10 @@ mu_sql_authenticate (struct mu_auth_data **return_data ARG_UNUSED, ...@@ -622,10 +577,10 @@ mu_sql_authenticate (struct mu_auth_data **return_data ARG_UNUSED,
622 int rc; 577 int rc;
623 578
624 if (!auth_data) 579 if (!auth_data)
625 return 1; 580 return EINVAL;
626 581
627 if (mu_sql_getpass (auth_data->name, &sql_pass)) 582 if ((rc = mu_sql_getpass (auth_data->name, &sql_pass)))
628 return 1; 583 return rc;
629 584
630 switch (mu_sql_password_type) 585 switch (mu_sql_password_type)
631 { 586 {
...@@ -640,6 +595,8 @@ mu_sql_authenticate (struct mu_auth_data **return_data ARG_UNUSED, ...@@ -640,6 +595,8 @@ mu_sql_authenticate (struct mu_auth_data **return_data ARG_UNUSED,
640 just as the rest of mu_sql_.* functions do */ 595 just as the rest of mu_sql_.* functions do */
641 #ifdef HAVE_MYSQL 596 #ifdef HAVE_MYSQL
642 rc = mu_check_mysql_scrambled_password (sql_pass, pass); 597 rc = mu_check_mysql_scrambled_password (sql_pass, pass);
598 #else
599 rc = 1;
643 #endif 600 #endif
644 break; 601 break;
645 602
...@@ -650,7 +607,7 @@ mu_sql_authenticate (struct mu_auth_data **return_data ARG_UNUSED, ...@@ -650,7 +607,7 @@ mu_sql_authenticate (struct mu_auth_data **return_data ARG_UNUSED,
650 607
651 free (sql_pass); 608 free (sql_pass);
652 609
653 return rc; 610 return rc == 0 ? 0 : MU_ERR_AUTH_FAILURE;
654 } 611 }
655 612
656 #else 613 #else
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2002 Free Software Foundation, Inc. 2 Copyright (C) 2002, 2006 Free Software Foundation, Inc.
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 5 modify it under the terms of the GNU Lesser General Public
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
52 #include <mailutils/argp.h> 52 #include <mailutils/argp.h>
53 #include <mailutils/mu_auth.h> 53 #include <mailutils/mu_auth.h>
54 #include <mailutils/nls.h> 54 #include <mailutils/nls.h>
55 #include <mailutils/errno.h>
55 56
56 #ifdef ENABLE_VIRTUAL_DOMAINS 57 #ifdef ENABLE_VIRTUAL_DOMAINS
57 58
...@@ -143,20 +144,19 @@ mu_auth_virt_domain_by_name (struct mu_auth_data **return_data, ...@@ -143,20 +144,19 @@ mu_auth_virt_domain_by_name (struct mu_auth_data **return_data,
143 char *mailbox_name; 144 char *mailbox_name;
144 145
145 if (!key) 146 if (!key)
146 { 147 return EINVAL;
147 errno = EINVAL;
148 return 1;
149 }
150 148
151 pw = getpwnam_virtual (key); 149 pw = getpwnam_virtual (key);
152 if (!pw) 150 if (!pw)
153 { 151 {
154 pw = getpwnam_ip_virtual (key); 152 pw = getpwnam_ip_virtual (key);
155 if (!pw) 153 if (!pw)
156 return 1; 154 return MU_ERR_AUTH_FAILURE;
157 } 155 }
158 156
159 mailbox_name = calloc (strlen (pw->pw_dir) + strlen ("/INBOX") + 1, 1); 157 mailbox_name = calloc (strlen (pw->pw_dir) + strlen ("/INBOX") + 1, 1);
158 if (!mailbox_name)
159 return ENOMEM;
160 sprintf (mailbox_name, "%s/INBOX", pw->pw_dir); 160 sprintf (mailbox_name, "%s/INBOX", pw->pw_dir);
161 161
162 rc = mu_auth_data_alloc (return_data, 162 rc = mu_auth_data_alloc (return_data,
...@@ -208,8 +208,7 @@ mu_auth_virt_domain_by_name (struct mu_auth_data **return_data ARG_UNUSED, ...@@ -208,8 +208,7 @@ mu_auth_virt_domain_by_name (struct mu_auth_data **return_data ARG_UNUSED,
208 void *func_data ARG_UNUSED, 208 void *func_data ARG_UNUSED,
209 void *call_data ARG_UNUSED) 209 void *call_data ARG_UNUSED)
210 { 210 {
211 errno = ENOSYS; 211 return ENOSYS;
212 return 1;
213 } 212 }
214 #endif 213 #endif
215 214
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
42 #include <mailutils/mailbox.h> 42 #include <mailutils/mailbox.h>
43 #include <mailutils/argp.h> 43 #include <mailutils/argp.h>
44 #include <mailutils/mu_auth.h> 44 #include <mailutils/mu_auth.h>
45 #include <mailutils/errno.h>
45 46
46 /* System database */ 47 /* System database */
47 static int 48 static int
...@@ -51,11 +52,11 @@ mu_auth_system (struct mu_auth_data **return_data, const struct passwd *pw) ...@@ -51,11 +52,11 @@ mu_auth_system (struct mu_auth_data **return_data, const struct passwd *pw)
51 int rc; 52 int rc;
52 53
53 if (!pw) 54 if (!pw)
54 return 1; 55 return MU_ERR_AUTH_FAILURE;
55 56
56 rc = mu_construct_user_mailbox_url (&mailbox_name, pw->pw_name); 57 rc = mu_construct_user_mailbox_url (&mailbox_name, pw->pw_name);
57 if (rc) 58 if (rc)
58 return 1; /* FIXME: Return code is lost */ 59 return rc; /* FIXME: Return code is lost */
59 60
60 rc = mu_auth_data_alloc (return_data, 61 rc = mu_auth_data_alloc (return_data,
61 pw->pw_name, 62 pw->pw_name,
...@@ -78,10 +79,7 @@ mu_auth_system_by_name (struct mu_auth_data **return_data, ...@@ -78,10 +79,7 @@ mu_auth_system_by_name (struct mu_auth_data **return_data,
78 void *call_data ARG_UNUSED) 79 void *call_data ARG_UNUSED)
79 { 80 {
80 if (!key) 81 if (!key)
81 { 82 return EINVAL;
82 errno = EINVAL;
83 return 1;
84 }
85 return mu_auth_system (return_data, getpwnam (key)); 83 return mu_auth_system (return_data, getpwnam (key));
86 } 84 }
87 85
...@@ -92,10 +90,7 @@ mu_auth_system_by_uid (struct mu_auth_data **return_data, ...@@ -92,10 +90,7 @@ mu_auth_system_by_uid (struct mu_auth_data **return_data,
92 void *call_data ARG_UNUSED) 90 void *call_data ARG_UNUSED)
93 { 91 {
94 if (!key) 92 if (!key)
95 { 93 return EINVAL;
96 errno = EINVAL;
97 return 1;
98 }
99 return mu_auth_system (return_data, getpwuid (*(uid_t*) key)); 94 return mu_auth_system (return_data, getpwuid (*(uid_t*) key));
100 } 95 }
101 96
...@@ -108,9 +103,12 @@ mu_authenticate_generic (struct mu_auth_data **return_data ARG_UNUSED, ...@@ -108,9 +103,12 @@ mu_authenticate_generic (struct mu_auth_data **return_data ARG_UNUSED,
108 const struct mu_auth_data *auth_data = key; 103 const struct mu_auth_data *auth_data = key;
109 char *pass = call_data; 104 char *pass = call_data;
110 105
111 return !auth_data 106 if (!auth_data || !pass)
112 || !auth_data->passwd 107 return EINVAL;
113 || strcmp (auth_data->passwd, crypt (pass, auth_data->passwd)); 108
109 return auth_data->passwd
110 && strcmp (auth_data->passwd, crypt (pass, auth_data->passwd)) == 0 ?
111 0 : MU_ERR_AUTH_FAILURE;
114 } 112 }
115 113
116 /* Called only if generic fails */ 114 /* Called only if generic fails */
...@@ -129,10 +127,11 @@ mu_authenticate_system (struct mu_auth_data **return_data ARG_UNUSED, ...@@ -129,10 +127,11 @@ mu_authenticate_system (struct mu_auth_data **return_data ARG_UNUSED,
129 struct spwd *spw; 127 struct spwd *spw;
130 spw = getspnam (auth_data->name); 128 spw = getspnam (auth_data->name);
131 if (spw) 129 if (spw)
132 return strcmp (spw->sp_pwdp, crypt (pass, spw->sp_pwdp)); 130 return strcmp (spw->sp_pwdp, crypt (pass, spw->sp_pwdp)) == 0 ?
131 0 : MU_ERR_AUTH_FAILURE;
133 } 132 }
134 #endif 133 #endif
135 return 1; 134 return MU_ERR_AUTH_FAILURE;
136 } 135 }
137 136
138 137
......