Path: blob/main/crypto/krb5/src/lib/kadm5/srv/pwqual_princ.c
39566 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* lib/kadm5/srv/pwqual_princ.c */2/*3* Copyright (C) 2010 by the Massachusetts Institute of Technology.4* All rights reserved.5*6* Export of this software from the United States of America may7* require a specific license from the United States Government.8* It is the responsibility of any person or organization contemplating9* export to obtain such a license before exporting.10*11* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and12* distribute this software and its documentation for any purpose and13* without fee is hereby granted, provided that the above copyright14* notice appear in all copies and that both that copyright notice and15* this permission notice appear in supporting documentation, and that16* the name of M.I.T. not be used in advertising or publicity pertaining17* to distribution of the software without specific, written prior18* permission. Furthermore if you modify this software you must label19* your software as modified software and not distribute it in such a20* fashion that it might be confused with the original M.I.T. software.21* M.I.T. makes no representations about the suitability of22* this software for any purpose. It is provided "as is" without express23* or implied warranty.24*/2526/* Password quality module to check passwords against principal components */2728#include "k5-int.h"29#include <krb5/pwqual_plugin.h>30#include "server_internal.h"3132static krb5_error_code33princ_check(krb5_context context, krb5_pwqual_moddata data,34const char *password, const char *policy_name,35krb5_principal princ, const char **languages)36{37int i, n;38char *cp;3940/* Don't check for principals with no password policy. */41if (policy_name == NULL)42return 0;4344/* Check against components of the principal. */45n = krb5_princ_size(handle->context, princ);46cp = krb5_princ_realm(handle->context, princ)->data;47if (strcasecmp(cp, password) == 0)48return KADM5_PASS_Q_DICT;49for (i = 0; i < n; i++) {50cp = krb5_princ_component(handle->context, princ, i)->data;51if (strcasecmp(cp, password) == 0) {52k5_setmsg(context, KADM5_PASS_Q_DICT,53_("Password may not match principal name"));54return KADM5_PASS_Q_DICT;55}56}5758return 0;59}6061krb5_error_code62pwqual_princ_initvt(krb5_context context, int maj_ver, int min_ver,63krb5_plugin_vtable vtable)64{65krb5_pwqual_vtable vt;6667if (maj_ver != 1)68return KRB5_PLUGIN_VER_NOTSUPP;69vt = (krb5_pwqual_vtable)vtable;70vt->name = "princ";71vt->check = princ_check;72return 0;73}747576