Blame src/lib/kadm5/srv/pwqual_princ.c

Packit Service 99d1c0
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
Packit Service 99d1c0
/* lib/kadm5/srv/pwqual_princ.c */
Packit Service 99d1c0
/*
Packit Service 99d1c0
 * Copyright (C) 2010 by the Massachusetts Institute of Technology.
Packit Service 99d1c0
 * All rights reserved.
Packit Service 99d1c0
 *
Packit Service 99d1c0
 * Export of this software from the United States of America may
Packit Service 99d1c0
 *   require a specific license from the United States Government.
Packit Service 99d1c0
 *   It is the responsibility of any person or organization contemplating
Packit Service 99d1c0
 *   export to obtain such a license before exporting.
Packit Service 99d1c0
 *
Packit Service 99d1c0
 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
Packit Service 99d1c0
 * distribute this software and its documentation for any purpose and
Packit Service 99d1c0
 * without fee is hereby granted, provided that the above copyright
Packit Service 99d1c0
 * notice appear in all copies and that both that copyright notice and
Packit Service 99d1c0
 * this permission notice appear in supporting documentation, and that
Packit Service 99d1c0
 * the name of M.I.T. not be used in advertising or publicity pertaining
Packit Service 99d1c0
 * to distribution of the software without specific, written prior
Packit Service 99d1c0
 * permission.  Furthermore if you modify this software you must label
Packit Service 99d1c0
 * your software as modified software and not distribute it in such a
Packit Service 99d1c0
 * fashion that it might be confused with the original M.I.T. software.
Packit Service 99d1c0
 * M.I.T. makes no representations about the suitability of
Packit Service 99d1c0
 * this software for any purpose.  It is provided "as is" without express
Packit Service 99d1c0
 * or implied warranty.
Packit Service 99d1c0
 */
Packit Service 99d1c0
Packit Service 99d1c0
/* Password quality module to check passwords against principal components */
Packit Service 99d1c0
Packit Service 99d1c0
#include "k5-int.h"
Packit Service 99d1c0
#include <krb5/pwqual_plugin.h>
Packit Service 99d1c0
#include "server_internal.h"
Packit Service 99d1c0
Packit Service 99d1c0
static krb5_error_code
Packit Service 99d1c0
princ_check(krb5_context context, krb5_pwqual_moddata data,
Packit Service 99d1c0
            const char *password, const char *policy_name,
Packit Service 99d1c0
            krb5_principal princ, const char **languages)
Packit Service 99d1c0
{
Packit Service 99d1c0
    int i, n;
Packit Service 99d1c0
    char *cp;
Packit Service 99d1c0
Packit Service 99d1c0
    /* Don't check for principals with no password policy. */
Packit Service 99d1c0
    if (policy_name == NULL)
Packit Service 99d1c0
        return 0;
Packit Service 99d1c0
Packit Service 99d1c0
    /* Check against components of the principal. */
Packit Service 99d1c0
    n = krb5_princ_size(handle->context, princ);
Packit Service 99d1c0
    cp = krb5_princ_realm(handle->context, princ)->data;
Packit Service 99d1c0
    if (strcasecmp(cp, password) == 0)
Packit Service 99d1c0
        return KADM5_PASS_Q_DICT;
Packit Service 99d1c0
    for (i = 0; i < n; i++) {
Packit Service 99d1c0
        cp = krb5_princ_component(handle->context, princ, i)->data;
Packit Service 99d1c0
        if (strcasecmp(cp, password) == 0) {
Packit Service 99d1c0
            k5_setmsg(context, KADM5_PASS_Q_DICT,
Packit Service 99d1c0
                      _("Password may not match principal name"));
Packit Service 99d1c0
            return KADM5_PASS_Q_DICT;
Packit Service 99d1c0
        }
Packit Service 99d1c0
    }
Packit Service 99d1c0
Packit Service 99d1c0
    return 0;
Packit Service 99d1c0
}
Packit Service 99d1c0
Packit Service 99d1c0
krb5_error_code
Packit Service 99d1c0
pwqual_princ_initvt(krb5_context context, int maj_ver, int min_ver,
Packit Service 99d1c0
                    krb5_plugin_vtable vtable)
Packit Service 99d1c0
{
Packit Service 99d1c0
    krb5_pwqual_vtable vt;
Packit Service 99d1c0
Packit Service 99d1c0
    if (maj_ver != 1)
Packit Service 99d1c0
        return KRB5_PLUGIN_VER_NOTSUPP;
Packit Service 99d1c0
    vt = (krb5_pwqual_vtable)vtable;
Packit Service 99d1c0
    vt->name = "princ";
Packit Service 99d1c0
    vt->check = princ_check;
Packit Service 99d1c0
    return 0;
Packit Service 99d1c0
}