Path: blob/main/crypto/krb5/src/plugins/authdata/greet_server/greet_auth.c
34909 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* plugins/authdata/greet_server/greet_auth.c */2/*3* Copyright 2009 by the Massachusetts Institute of Technology.4*5* Export of this software from the United States of America may6* require a specific license from the United States Government.7* It is the responsibility of any person or organization contemplating8* export to obtain such a license before exporting.9*10* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and11* distribute this software and its documentation for any purpose and12* without fee is hereby granted, provided that the above copyright13* notice appear in all copies and that both that copyright notice and14* this permission notice appear in supporting documentation, and that15* the name of M.I.T. not be used in advertising or publicity pertaining16* to distribution of the software without specific, written prior17* permission. Furthermore if you modify this software you must label18* your software as modified software and not distribute it in such a19* fashion that it might be confused with the original M.I.T. software.20* M.I.T. makes no representations about the suitability of21* this software for any purpose. It is provided "as is" without express22* or implied warranty.23*/2425/*26*27* Sample authorization data plugin28*/2930#include <k5-int.h>31#include <krb5/kdcauthdata_plugin.h>3233static krb5_error_code greet_hello(krb5_context context, krb5_data **ret)34{35krb5_data tmp;3637tmp.data = "Hello, KDC issued acceptor world!";38tmp.length = strlen(tmp.data);3940return krb5_copy_data(context, &tmp, ret);41}4243static krb5_error_code44greet_kdc_sign(krb5_context context,45krb5_enc_tkt_part *enc_tkt_reply,46krb5_const_principal tgs,47krb5_data *greeting)48{49krb5_error_code code;50krb5_authdata ad_datum, *ad_data[2], **kdc_issued = NULL;51krb5_authdata **if_relevant = NULL;52krb5_authdata **tkt_authdata;5354ad_datum.ad_type = -42;55ad_datum.contents = (krb5_octet *)greeting->data;56ad_datum.length = greeting->length;5758ad_data[0] = &ad_datum;59ad_data[1] = NULL;6061code = krb5_make_authdata_kdc_issued(context,62enc_tkt_reply->session,63tgs,64ad_data,65&kdc_issued);66if (code != 0)67return code;6869code = krb5_encode_authdata_container(context,70KRB5_AUTHDATA_IF_RELEVANT,71kdc_issued,72&if_relevant);73if (code != 0) {74krb5_free_authdata(context, kdc_issued);75return code;76}7778code = krb5_merge_authdata(context,79if_relevant,80enc_tkt_reply->authorization_data,81&tkt_authdata);82if (code == 0) {83krb5_free_authdata(context, enc_tkt_reply->authorization_data);84enc_tkt_reply->authorization_data = tkt_authdata;85}8687krb5_free_authdata(context, if_relevant);88krb5_free_authdata(context, kdc_issued);8990return code;91}9293static krb5_error_code94greet_authdata(krb5_context context,95krb5_kdcauthdata_moddata moddata,96unsigned int flags,97krb5_db_entry *client,98krb5_db_entry *server,99krb5_db_entry *tgs,100krb5_keyblock *client_key,101krb5_keyblock *server_key,102krb5_keyblock *krbtgt_key,103krb5_data *req_pkt,104krb5_kdc_req *request,105krb5_const_principal for_user_princ,106krb5_enc_tkt_part *enc_tkt_request,107krb5_enc_tkt_part *enc_tkt_reply)108{109krb5_error_code code;110krb5_data *greeting = NULL;111112if (request->msg_type != KRB5_TGS_REQ)113return 0;114115code = greet_hello(context, &greeting);116if (code != 0)117return code;118119code = greet_kdc_sign(context, enc_tkt_reply, tgs->princ, greeting);120121krb5_free_data(context, greeting);122123return code;124}125126krb5_error_code127kdcauthdata_greet_initvt(krb5_context context, int maj_ver, int min_ver,128krb5_plugin_vtable vtable);129130krb5_error_code131kdcauthdata_greet_initvt(krb5_context context, int maj_ver, int min_ver,132krb5_plugin_vtable vtable)133{134krb5_kdcauthdata_vtable vt = (krb5_kdcauthdata_vtable)vtable;135136vt->name = "greet";137vt->handle = greet_authdata;138return 0;139}140141142