21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

free_context = 1;<br />

}<br />

if ((rc = krb5_sname_to_principal(bundle->ctx, 0, service,<br />

KRB5_NT_SRV_HST, &server)) != 0) goto error;<br />

rc = krb5_recvauth(bundle->ctx, &(bundle->auth_ctx), &sockfd, version,<br />

server, 0, 0, &(bundle->ticket));<br />

if (!rc) {<br />

krb5_free_principal(bundle->ctx, server);<br />

return 0;<br />

}<br />

error:<br />

if (server) krb5_free_principal(bundle->ctx, server);<br />

if (bundle->ctx && free_context) {<br />

krb5_free_context(bundle->ctx);<br />

bundle->ctx = 0;<br />

}<br />

return rc;<br />

}<br />

When a successful authentication is completed, an spc_krb5bundle_t object is filled<br />

with information resulting from the authentication. This information should eventually<br />

be cleaned up, of course. You may safely keep the information around as long as<br />

you need it, or you may clean it up at any time. If, once the authentication is complete,<br />

you don’t need to retain any of the resulting information for further communication,<br />

you may even clean it up immediately.<br />

Call the function spc_krb5_cleanup( )when you no longer need any of the information<br />

contained in an spc_krb5bundle_t object. It will free all of the allocated resources<br />

in the proper order.<br />

void spc_krb5_cleanup(spc_krb5bundle_t *bundle) {<br />

if (bundle->ticket) {<br />

krb5_free_ticket(bundle->ctx, bundle->ticket);<br />

bundle->ticket = 0;<br />

}<br />

if (bundle->auth_ctx) {<br />

krb5_auth_con_free(bundle->ctx, bundle->auth_ctx);<br />

bundle->auth_ctx = 0;<br />

}<br />

if (bundle->ctx) {<br />

krb5_free_context(bundle->ctx);<br />

bundle->ctx = 0;<br />

}<br />

}<br />

See Also<br />

Recipe 9.6<br />

418 | Chapter 8: Authentication and Key Exchange<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!