Path: blob/main/crypto/krb5/src/clients/kinit/kinit_kdb.c
34914 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* clients/kinit/kinit_kdb.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/**27* @file kinit_kdb.c28* Operations to open the KDB and make the KDB key table available29* for kinit.30*/313233#include <k5-int.h>34#include <kadm5/admin.h>35#include <kdb.h>36#include "extern.h"3738/* Server handle */39static void *server_handle;4041/* Free and reinitialize *pcontext with the KDB opened to the given realm, so42* that it can be used with the KDB keytab type. */43krb5_error_code44kinit_kdb_init(krb5_context *pcontext, char *realm)45{46kadm5_config_params config;47krb5_error_code ret;4849if (*pcontext) {50krb5_free_context(*pcontext);51*pcontext = NULL;52}53memset(&config, 0, sizeof config);5455ret = kadm5_init_krb5_context(pcontext);56if (ret)57return ret;5859config.mask = KADM5_CONFIG_REALM;60config.realm = realm;61ret = kadm5_init(*pcontext, "kinit", NULL, "kinit", &config,62KADM5_STRUCT_VERSION, KADM5_API_VERSION_4, NULL,63&server_handle);64if (ret)65return ret;6667return krb5_db_register_keytab(*pcontext);68}6970void71kinit_kdb_fini(void)72{73kadm5_destroy(server_handle);74}757677