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.

server-side part of the authentication. It ultimately calls krb5_recvauth( ), which<br />

waits for the client to initiate an authenticate request.<br />

The function spc_krb5_server( ) has the following signature:<br />

krb5_error_code spc_krb5_server(int sockfd, spc_krb5bundle_t *bundle,<br />

char *service, char *version);<br />

This function has the following arguments:<br />

sockfd<br />

Socket descriptor over which the authentication should be performed. The connection<br />

to the client should already be established, and the socket should be in<br />

blocking mode.<br />

bundle<br />

spc_krb5bundle_t object that will be loaded with information if the authentication<br />

with the server is successful. Before calling spc_krb5_server( ), you should<br />

be sure to zero the contents of this structure. If the structure contains a pointer<br />

to a Kerberos context object, spc_krb5_server( ) will use it instead of creating a<br />

new one.<br />

service<br />

Name component of the server’s principal. It is combined with the server’s hostname<br />

or instance to build the principal for the server. The server’s principal will<br />

be of the form service/hostname@REALM.<br />

On the client side, an additional argument is required to specify the hostname of<br />

the server, but on the server side, the hostname of the machine on which the<br />

program is running will be used.<br />

version<br />

Version string that is generally used to indicate a version of the protocol that the<br />

client and server will speak to each other. It does not have anything to do with<br />

the Kerberos protocol or the version of Kerberos in use. The string may be anything<br />

you want, but both the client and server must agree on the same string for<br />

authentication to succeed.<br />

If authentication is successful, the return value from spc_krb5_server( ) will be 0,<br />

and the relevant fields in the spc_krb5bundle_t object will be filled in. If any kind of<br />

error occurs while attempting to authenticate with the server, the return value from<br />

spc_krb5_server( ) will be the error code returned by the Kerberos API function that<br />

failed.<br />

krb5_error_code spc_krb5_server(int sockfd, spc_krb5bundle_t *bundle,<br />

char *service, char *version) {<br />

int free_context = 0;<br />

krb5_principal server = 0;<br />

krb5_error_code rc;<br />

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

if ((rc = krb5_init_context(&(bundle->ctx))) != 0) goto error;<br />

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

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.<br />

Authenticating with Kerberos | 417

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

Saved successfully!

Ooh no, something went wrong!