<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[13317] PyKerberos/trunk/src/kerberosgss.c</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/13317">13317</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2014-04-18 07:29:33 -0700 (Fri, 18 Apr 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Fix to prevent crash when delegation creds are null.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#PyKerberostrunksrckerberosgssc">PyKerberos/trunk/src/kerberosgss.c</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="PyKerberostrunksrckerberosgssc"></a>
<div class="modfile"><h4>Modified: PyKerberos/trunk/src/kerberosgss.c (13316 => 13317)</h4>
<pre class="diff"><span>
<span class="info">--- PyKerberos/trunk/src/kerberosgss.c        2014-04-18 06:33:45 UTC (rev 13316)
+++ PyKerberos/trunk/src/kerberosgss.c        2014-04-18 14:29:33 UTC (rev 13317)
</span><span class="lines">@@ -673,53 +673,58 @@
</span><span class="cx">
</span><span class="cx"> int authenticate_gss_server_store_delegate(gss_server_state *state)
</span><span class="cx"> {
</span><del>- gss_cred_id_t delegated_cred = state->client_creds;
- char *princ_name = state->username;
- OM_uint32 maj_stat, min_stat;
- krb5_principal princ = NULL;
- krb5_ccache ccache = NULL;
- krb5_error_code problem;
- krb5_context context;
- int ret = 500;
</del><ins>+ gss_cred_id_t delegated_cred = state->client_creds;
+ char *princ_name = state->username;
+ OM_uint32 maj_stat, min_stat;
+ krb5_principal princ = NULL;
+ krb5_ccache ccache = NULL;
+ krb5_error_code problem;
+ krb5_context context;
+ int ret = 500;
</ins><span class="cx">
</span><del>- problem = krb5_init_context(&context);
- if (problem) {
- PyErr_SetObject(KrbException_class, Py_BuildValue("(s)", "Cannot initialize krb5 context"));
- return AUTH_GSS_ERROR;
- }
</del><ins>+ if (delegated_cred == GSS_C_NO_CREDENTIAL){
+ PyErr_SetObject(KrbException_class, Py_BuildValue("(s)", "Ticket is not delegatable"));
+ return AUTH_GSS_ERROR;
+ }
</ins><span class="cx">
</span><del>- problem = krb5_parse_name(context, princ_name, &princ);
- if (problem) {
- PyErr_SetObject(KrbException_class, Py_BuildValue("(s:s)", "Cannot parse delegated username", krb5_get_err_text(context, problem)));
- ret = AUTH_GSS_ERROR;
- goto end;
- }
</del><ins>+ problem = krb5_init_context(&context);
+ if (problem) {
+ PyErr_SetObject(KrbException_class, Py_BuildValue("(s)", "Cannot initialize krb5 context"));
+ return AUTH_GSS_ERROR;
+ }
</ins><span class="cx">
</span><del>- problem = create_krb5_ccache(state, context, princ, &ccache);
- if (problem) {
- PyErr_SetObject(KrbException_class, Py_BuildValue("(s:s)", "Error in creating krb5 cache", krb5_get_err_text(context, problem)));
- ret = AUTH_GSS_ERROR;
- goto end;
- }
</del><ins>+ problem = krb5_parse_name(context, princ_name, &princ);
+ if (problem) {
+ PyErr_SetObject(KrbException_class, Py_BuildValue("(s:s)", "Cannot parse delegated username", krb5_get_err_text(context, problem)));
+ ret = AUTH_GSS_ERROR;
+ goto end;
+ }
</ins><span class="cx">
</span><del>- maj_stat = gss_krb5_copy_ccache(&min_stat, delegated_cred, ccache);
- if (GSS_ERROR(maj_stat)) {
- set_gss_error(maj_stat, min_stat);
- ret = AUTH_GSS_ERROR;
- goto end;
- }
</del><ins>+ problem = create_krb5_ccache(state, context, princ, &ccache);
+ if (problem) {
+ PyErr_SetObject(KrbException_class, Py_BuildValue("(s:s)", "Error in creating krb5 cache", krb5_get_err_text(context, problem)));
+ ret = AUTH_GSS_ERROR;
+ goto end;
+ }
</ins><span class="cx">
</span><del>- krb5_cc_close(context, ccache);
- ccache = NULL;
- ret = 0;
</del><ins>+ maj_stat = gss_krb5_copy_ccache(&min_stat, delegated_cred, ccache);
+ if (GSS_ERROR(maj_stat)) {
+ set_gss_error(maj_stat, min_stat);
+ ret = AUTH_GSS_ERROR;
+ goto end;
+ }
</ins><span class="cx">
</span><del>-end:
- if (princ)
- krb5_free_principal(context, princ);
- if (ccache)
- krb5_cc_destroy(context, ccache);
- krb5_free_context(context);
- return ret;
</del><ins>+ krb5_cc_close(context, ccache);
+ ccache = NULL;
+ ret = 0;
+
+ end:
+ if (princ)
+ krb5_free_principal(context, princ);
+ if (ccache)
+ krb5_cc_destroy(context, ccache);
+ krb5_free_context(context);
+ return ret;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> int create_krb5_ccache(gss_server_state *state,
</span><span class="lines">@@ -727,47 +732,47 @@
</span><span class="cx"> krb5_principal princ,
</span><span class="cx"> krb5_ccache *ccache)
</span><span class="cx"> {
</span><del>- int fd;
- char ccname[32];
- krb5_error_code problem;
- int ret;
- krb5_ccache tmp_ccache = NULL;
</del><ins>+ int fd;
+ char ccname[32];
+ krb5_error_code problem;
+ int ret;
+ krb5_ccache tmp_ccache = NULL;
</ins><span class="cx">
</span><del>- snprintf(ccname, sizeof(ccname), "/tmp/krb5cc_pyserv_XXXXXX");
- fd = mkstemp(ccname);
- if (fd < 0) {
- PyErr_SetObject(KrbException_class, Py_BuildValue("(s:s)", "Error in mkstemp", strerror(errno)));
- ret = 1;
- goto end;
- }
- close(fd);
</del><ins>+ snprintf(ccname, sizeof(ccname), "/tmp/krb5cc_pyserv_XXXXXX");
+ fd = mkstemp(ccname);
+ if (fd < 0) {
+ PyErr_SetObject(KrbException_class, Py_BuildValue("(s:s)", "Error in mkstemp", strerror(errno)));
+ ret = 1;
+ goto end;
+ }
+ close(fd);
</ins><span class="cx">
</span><del>- problem = krb5_cc_resolve(kcontext, ccname, &tmp_ccache);
- if (problem) {
- PyErr_SetObject(KrbException_class, Py_BuildValue("(s:s)", "Error resolving the credential cache", krb5_get_err_text(kcontext, problem)));
- ret = 1;
- unlink(ccname);
- goto end;
- }
</del><ins>+ problem = krb5_cc_resolve(kcontext, ccname, &tmp_ccache);
+ if (problem) {
+ PyErr_SetObject(KrbException_class, Py_BuildValue("(s:s)", "Error resolving the credential cache", krb5_get_err_text(kcontext, problem)));
+ ret = 1;
+ unlink(ccname);
+ goto end;
+ }
</ins><span class="cx">
</span><del>- problem = krb5_cc_initialize(kcontext, tmp_ccache, princ);
- if (problem) {
- PyErr_SetObject(KrbException_class, Py_BuildValue("(s:s)", "Error initialising the credential cache", krb5_get_err_text(kcontext, problem)));
- ret = 1;
- goto end;
- }
</del><ins>+ problem = krb5_cc_initialize(kcontext, tmp_ccache, princ);
+ if (problem) {
+ PyErr_SetObject(KrbException_class, Py_BuildValue("(s:s)", "Error initialising the credential cache", krb5_get_err_text(kcontext, problem)));
+ ret = 1;
+ goto end;
+ }
</ins><span class="cx">
</span><del>- *ccache = tmp_ccache;
- tmp_ccache = NULL;
</del><ins>+ *ccache = tmp_ccache;
+ tmp_ccache = NULL;
</ins><span class="cx">
</span><del>- ret = 0;
</del><ins>+ ret = 0;
</ins><span class="cx">
</span><del>-end:
- if (tmp_ccache)
- krb5_cc_destroy(kcontext, tmp_ccache);
</del><ins>+ end:
+ if (tmp_ccache)
+ krb5_cc_destroy(kcontext, tmp_ccache);
</ins><span class="cx">
</span><del>- state->ccname = (char *)malloc(32*sizeof(char));
- strcpy(state->ccname, ccname);
</del><ins>+ state->ccname = (char *)malloc(32*sizeof(char));
+ strcpy(state->ccname, ccname);
</ins><span class="cx">
</span><del>- return ret;
</del><ins>+ return ret;
</ins><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>