~ubuntu-branches/ubuntu/wily/dovecot/wily

« back to all changes in this revision

Viewing changes to src/auth/mech-gssapi.c

  • Committer: Package Import Robot
  • Author(s): Jaldhar H. Vyas
  • Date: 2013-09-09 00:57:32 UTC
  • mfrom: (1.13.11)
  • mto: (4.8.5 experimental) (1.16.1)
  • mto: This revision was merged to the branch mainline in revision 97.
  • Revision ID: package-import@ubuntu.com-20130909005732-dn1eell8srqbhh0e
Tags: upstream-2.2.5
ImportĀ upstreamĀ versionĀ 2.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
404
404
 
405
405
#ifdef USE_KRB5_USEROK
406
406
static bool
 
407
k5_principal_is_authorized(struct auth_request *request, const char *name)
 
408
{
 
409
        const char *value, *const *authorized_names, *const *tmp;
 
410
 
 
411
        value = auth_fields_find(request->extra_fields, "k5principals");
 
412
        if (value == NULL)
 
413
                return FALSE;
 
414
 
 
415
        authorized_names = t_strsplit_spaces(value, ",");
 
416
        for (tmp = authorized_names; *tmp != NULL; tmp++) {
 
417
                if (strcmp(*tmp, name) == 0) {
 
418
                        auth_request_log_debug(request, "gssapi",
 
419
                                "authorized by k5principals field: %s", name);
 
420
                        return TRUE;
 
421
                }
 
422
        }
 
423
        return FALSE;
 
424
}
 
425
 
 
426
static bool
407
427
mech_gssapi_krb5_userok(struct gssapi_auth_request *request,
408
428
                        gss_name_t name, const char *login_user,
409
429
                        bool check_name_type)
413
433
        krb5_error_code krb5_err;
414
434
        gss_OID name_type;
415
435
        const char *princ_display_name;
416
 
        bool ret = FALSE;
 
436
        bool authorized = FALSE;
417
437
 
418
438
        /* Parse out the principal's username */
419
439
        if (get_display_name(&request->auth_request, name, &name_type,
443
463
                                      "krb5_parse_name() failed: %d",
444
464
                                      (int)krb5_err);
445
465
        } else {
 
466
                /* See if the principal is in the list of authorized
 
467
                 * principals for the user */
 
468
                authorized = k5_principal_is_authorized(&request->auth_request,
 
469
                                                        princ_display_name);
 
470
 
446
471
                /* See if the principal is authorized to act as the
447
 
                   specified user */
448
 
                ret = krb5_kuserok(ctx, princ, login_user);
 
472
                   specified (UNIX) user */
 
473
                if (!authorized)
 
474
                        authorized = krb5_kuserok(ctx, princ, login_user);
 
475
 
449
476
                krb5_free_principal(ctx, princ);
450
477
        }
451
478
        krb5_free_context(ctx);
452
 
        return ret;
 
479
        return authorized;
453
480
}
454
481
#endif
455
482
 
507
534
#else
508
535
        auth_request_log_info(auth_request, "gssapi",
509
536
                              "Cross-realm authentication not supported "
510
 
                              "(authz_name=%s)", login_user);
 
537
                              "(authn_name=%s, authz_name=%s)", request->auth_request.original_username, login_user);
511
538
        return -1;
512
539
#endif
513
540
}
514
541
 
 
542
static void
 
543
gssapi_credentials_callback(enum passdb_result result,
 
544
                            const unsigned char *credentials ATTR_UNUSED,
 
545
                            size_t size ATTR_UNUSED,
 
546
                            struct auth_request *request)
 
547
{
 
548
        struct gssapi_auth_request *gssapi_request =
 
549
                (struct gssapi_auth_request *)request;
 
550
 
 
551
        /* We don't care much whether the lookup succeeded or not because GSSAPI
 
552
         * does not strictly require a passdb. But if a passdb is configured,
 
553
         * now the k5principals field will have been filled in. */
 
554
        switch (result) {
 
555
        case PASSDB_RESULT_INTERNAL_FAILURE:
 
556
                auth_request_internal_failure(request);
 
557
                return;
 
558
        case PASSDB_RESULT_USER_DISABLED:
 
559
        case PASSDB_RESULT_PASS_EXPIRED:
 
560
                /* user is explicitly disabled, don't allow it to log in */
 
561
                auth_request_fail(request);
 
562
                return;
 
563
        case PASSDB_RESULT_SCHEME_NOT_AVAILABLE:
 
564
        case PASSDB_RESULT_USER_UNKNOWN:
 
565
        case PASSDB_RESULT_PASSWORD_MISMATCH:
 
566
        case PASSDB_RESULT_OK:
 
567
                break;
 
568
        }
 
569
 
 
570
        if (mech_gssapi_userok(gssapi_request, request->user) == 0)
 
571
                auth_request_success(request, NULL, 0);
 
572
        else
 
573
                auth_request_fail(request);
 
574
}
 
575
 
515
576
static int
516
577
mech_gssapi_unwrap(struct gssapi_auth_request *request, gss_buffer_desc inbuf)
517
578
{
565
626
                return -1;
566
627
        }
567
628
 
568
 
        if (mech_gssapi_userok(request, login_user) < 0)
569
 
                return -1;
570
 
 
 
629
        /* Set username early, so that the credential lookup is for the
 
630
         * authorizing user. This means the username in subsequent log
 
631
         * messagess will be the authorization name, not the authentication
 
632
         * name, which may mean that future log messages should be adjusted
 
633
         * to log the right thing. */
571
634
        if (!auth_request_set_username(auth_request, login_user, &error)) {
572
635
                auth_request_log_info(auth_request, "gssapi",
573
636
                                      "authz_name: %s", error);
574
637
                return -1;
575
638
        }
576
639
 
577
 
        auth_request_success(auth_request, NULL, 0);
 
640
        /* Continue in callback once auth_request is populated with passdb
 
641
           information. */
 
642
        auth_request->passdb_success = TRUE; /* default to success */
 
643
        auth_request_lookup_credentials(&request->auth_request, "",
 
644
                                        gssapi_credentials_callback);
578
645
        return 0;
579
646
}
580
647