<!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>[13269] PyKerberos/trunk</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/13269">13269</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2014-04-13 08:33:07 -0700 (Sun, 13 Apr 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Apply delegation patch.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#PyKerberostrunkpysrckerberospy">PyKerberos/trunk/pysrc/kerberos.py</a></li>
<li><a href="#PyKerberostrunksrckerberosc">PyKerberos/trunk/src/kerberos.c</a></li>
<li><a href="#PyKerberostrunksrckerberosgssc">PyKerberos/trunk/src/kerberosgss.c</a></li>
<li><a href="#PyKerberostrunksrckerberosgssh">PyKerberos/trunk/src/kerberosgss.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="PyKerberostrunkpysrckerberospy"></a>
<div class="modfile"><h4>Modified: PyKerberos/trunk/pysrc/kerberos.py (13268 => 13269)</h4>
<pre class="diff"><span>
<span class="info">--- PyKerberos/trunk/pysrc/kerberos.py        2014-04-13 15:09:55 UTC (rev 13268)
+++ PyKerberos/trunk/pysrc/kerberos.py        2014-04-13 15:33:07 UTC (rev 13269)
</span><span class="lines">@@ -103,7 +103,7 @@
</span><span class="cx"> GSS_C_PROT_READY_FLAG = 128 
</span><span class="cx"> GSS_C_TRANS_FLAG      = 256 
</span><span class="cx">      
</span><del>-def authGSSClientInit(service, principal=None, gssflags=GSS_C_MUTUAL_FLAG|GSS_C_SEQUENCE_FLAG):
</del><ins>+def authGSSClientInit(service, **kwargs):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Initializes a context for GSSAPI client-side authentication with the given service principal.
</span><span class="cx">     authGSSClientClean must be called after this function returns an OK result to dispose of
</span><span class="lines">@@ -116,6 +116,7 @@
</span><span class="cx">     @param gssflags: optional integer used to set GSS flags.
</span><span class="cx">         (e.g.  GSS_C_DELEG_FLAG|GSS_C_MUTUAL_FLAG|GSS_C_SEQUENCE_FLAG will allow 
</span><span class="cx">         for forwarding credentials to the remote host)
</span><ins>+    @param delegated: optional server context containing delegated credentials
</ins><span class="cx">     @return: a tuple of (result, context) where result is the result code (see above) and
</span><span class="cx">         context is an opaque value that will need to be passed to subsequent functions.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="lines">@@ -220,6 +221,14 @@
</span><span class="cx">     @return: a string containing the base64-encoded server data to be sent to the client.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><ins>+def authGSSServerHasDelegated(context):
+    &quot;&quot;&quot;
+    Checks whether a server context has delegated credentials.
+
+    @param context: the context object returned from authGSSServerInit.
+    @return: a bool saying whether delegated credentials are available.
+    &quot;&quot;&quot;
+
</ins><span class="cx"> def authGSSServerUserName(context):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Get the user name of the principal trying to authenticate to the server.
</span></span></pre></div>
<a id="PyKerberostrunksrckerberosc"></a>
<div class="modfile"><h4>Modified: PyKerberos/trunk/src/kerberos.c (13268 => 13269)</h4>
<pre class="diff"><span>
<span class="info">--- PyKerberos/trunk/src/kerberos.c        2014-04-13 15:09:55 UTC (rev 13268)
+++ PyKerberos/trunk/src/kerberos.c        2014-04-13 15:33:07 UTC (rev 13269)
</span><span class="lines">@@ -89,17 +89,22 @@
</span><span class="cx">     const char *principal = NULL;
</span><span class="cx">     gss_client_state *state;
</span><span class="cx">     PyObject *pystate;
</span><del>-    static char *kwlist[] = {&quot;service&quot;, &quot;principal&quot;, &quot;gssflags&quot;, NULL};
</del><ins>+    gss_server_state *delegatestate = NULL;
+    PyObject *pydelegatestate;
+    static char *kwlist[] = {&quot;service&quot;, &quot;principal&quot;, &quot;gssflags&quot;, &quot;delegated&quot;, NULL};
</ins><span class="cx">     long int gss_flags = GSS_C_MUTUAL_FLAG | GSS_C_SEQUENCE_FLAG;
</span><span class="cx">     int result = 0;
</span><span class="cx"> 
</span><del>-    if (!PyArg_ParseTupleAndKeywords(args, keywds, &quot;s|zl&quot;, kwlist, &amp;service, &amp;principal, &amp;gss_flags))
</del><ins>+    if (!PyArg_ParseTupleAndKeywords(args, keywds, &quot;s|slO&quot;, kwlist, &amp;service, &amp;principal, &amp;gss_flags, &amp;pydelegatestate))
</ins><span class="cx">         return NULL;
</span><span class="cx"> 
</span><span class="cx">     state = (gss_client_state *) malloc(sizeof(gss_client_state));
</span><span class="cx">     pystate = PyCObject_FromVoidPtr(state, NULL);
</span><span class="cx"> 
</span><del>-    result = authenticate_gss_client_init(service, principal, gss_flags, state);
</del><ins>+    if (PyCObject_Check(pydelegatestate))
+        delegatestate = PyCObject_AsVoidPtr(pydelegatestate);
+
+    result = authenticate_gss_client_init(service, principal, gss_flags, delegatestate, state);
</ins><span class="cx">     if (result == AUTH_GSS_ERROR)
</span><span class="cx">         return NULL;
</span><span class="cx"> 
</span><span class="lines">@@ -178,6 +183,26 @@
</span><span class="cx">     return Py_BuildValue(&quot;i&quot;, state-&gt;responseConf);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static PyObject *authGSSServerHasDelegated(PyObject *self, PyObject *args)
+{
+    gss_server_state *state;
+    PyObject *pystate;
+
+    if (!PyArg_ParseTuple(args, &quot;O&quot;, &amp;pystate))
+        return NULL;
+
+    if (!PyCObject_Check(pystate)) {
+        PyErr_SetString(PyExc_TypeError, &quot;Expected a context object&quot;);
+        return NULL;
+    }
+
+    state = (gss_server_state *)PyCObject_AsVoidPtr(pystate);
+    if (state == NULL)
+        return NULL;
+
+    return PyBool_FromLong(authenticate_gss_server_has_delegated(state));
+}
+
</ins><span class="cx"> static PyObject *authGSSClientResponse(PyObject *self, PyObject *args)
</span><span class="cx"> {
</span><span class="cx">     gss_client_state *state;
</span><span class="lines">@@ -478,6 +503,8 @@
</span><span class="cx">      &quot;Terminate server-side GSSAPI operations.&quot;},
</span><span class="cx">     {&quot;authGSSServerStep&quot;,  authGSSServerStep, METH_VARARGS,
</span><span class="cx">      &quot;Do a server-side GSSAPI step.&quot;},
</span><ins>+    {&quot;authGSSServerHasDelegated&quot;,  authGSSServerHasDelegated, METH_VARARGS,
+     &quot;Check whether the client delegated credentials to us.&quot;},
</ins><span class="cx">      {&quot;authGSSServerStoreDelegate&quot;,  authGSSServerStoreDelegate, METH_VARARGS,
</span><span class="cx">      &quot;Store the delegated Credentials.&quot;},
</span><span class="cx">     {&quot;authGSSServerResponse&quot;,  authGSSServerResponse, METH_VARARGS,
</span></span></pre></div>
<a id="PyKerberostrunksrckerberosgssc"></a>
<div class="modfile"><h4>Modified: PyKerberos/trunk/src/kerberosgss.c (13268 => 13269)</h4>
<pre class="diff"><span>
<span class="info">--- PyKerberos/trunk/src/kerberosgss.c        2014-04-13 15:09:55 UTC (rev 13268)
+++ PyKerberos/trunk/src/kerberosgss.c        2014-04-13 15:33:07 UTC (rev 13269)
</span><span class="lines">@@ -108,7 +108,7 @@
</span><span class="cx">     return result;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-int authenticate_gss_client_init(const char* service, const char* principal, long int gss_flags, gss_client_state* state)
</del><ins>+int authenticate_gss_client_init(const char* service, const char* principal, long int gss_flags, gss_server_state* delegatestate, gss_client_state* state)
</ins><span class="cx"> {
</span><span class="cx">     OM_uint32 maj_stat;
</span><span class="cx">     OM_uint32 min_stat;
</span><span class="lines">@@ -135,10 +135,15 @@
</span><span class="cx">         ret = AUTH_GSS_ERROR;
</span><span class="cx">         goto end;
</span><span class="cx">     }
</span><del>-    
-    // Get credential for principal
-    if (principal &amp;&amp; *principal)
</del><ins>+    // Use the delegate credentials if they exist
+    if (delegatestate &amp;&amp; delegatestate-&gt;client_creds != GSS_C_NO_CREDENTIAL)
</ins><span class="cx">     {
</span><ins>+        state-&gt;client_creds = delegatestate-&gt;client_creds;
+    }
+
+    // If available use the principal to extract its associated credentials
+    else if (principal &amp;&amp; *principal)
+    {
</ins><span class="cx">         gss_name_t name;
</span><span class="cx">         principal_token.length = strlen(principal);
</span><span class="cx">         principal_token.value = (char *)principal;
</span><span class="lines">@@ -624,6 +629,10 @@
</span><span class="cx">     return ret;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+int authenticate_gss_server_has_delegated(gss_server_state *state)
+{
+    return (state-&gt;client_creds != GSS_C_NO_CREDENTIAL);
+}
</ins><span class="cx"> 
</span><span class="cx"> static void set_gss_error(OM_uint32 err_maj, OM_uint32 err_min)
</span><span class="cx"> {
</span><span class="lines">@@ -662,8 +671,7 @@
</span><span class="cx">     PyErr_SetObject(GssException_class, Py_BuildValue(&quot;((s:i)(s:i))&quot;, buf_maj, err_maj, buf_min, err_min));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-int
-authenticate_gss_server_store_delegate(gss_server_state *state)
</del><ins>+int authenticate_gss_server_store_delegate(gss_server_state *state)
</ins><span class="cx"> {
</span><span class="cx">    gss_cred_id_t delegated_cred = state-&gt;client_creds;
</span><span class="cx">    char *princ_name = state-&gt;username;
</span><span class="lines">@@ -714,8 +722,7 @@
</span><span class="cx">    return ret;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-int
-create_krb5_ccache(gss_server_state *state,
</del><ins>+int create_krb5_ccache(gss_server_state *state,
</ins><span class="cx">            krb5_context kcontext,
</span><span class="cx">            krb5_principal princ,
</span><span class="cx">            krb5_ccache *ccache)
</span></span></pre></div>
<a id="PyKerberostrunksrckerberosgssh"></a>
<div class="modfile"><h4>Modified: PyKerberos/trunk/src/kerberosgss.h (13268 => 13269)</h4>
<pre class="diff"><span>
<span class="info">--- PyKerberos/trunk/src/kerberosgss.h        2014-04-13 15:09:55 UTC (rev 13268)
+++ PyKerberos/trunk/src/kerberosgss.h        2014-04-13 15:33:07 UTC (rev 13269)
</span><span class="lines">@@ -52,7 +52,7 @@
</span><span class="cx"> 
</span><span class="cx"> char* server_principal_details(const char* service, const char* hostname);
</span><span class="cx"> 
</span><del>-int authenticate_gss_client_init(const char* service, const char* principal, long int gss_flags, gss_client_state* state);
</del><ins>+int authenticate_gss_client_init(const char* service, const char* principal, long int gss_flags, gss_server_state* delegatestate, gss_client_state* state);
</ins><span class="cx"> int authenticate_gss_client_clean(gss_client_state *state);
</span><span class="cx"> int authenticate_gss_client_step(gss_client_state *state, const char *challenge);
</span><span class="cx"> int authenticate_gss_client_unwrap(gss_client_state* state, const char* challenge);
</span><span class="lines">@@ -62,3 +62,4 @@
</span><span class="cx"> int authenticate_gss_server_clean(gss_server_state *state);
</span><span class="cx"> int authenticate_gss_server_step(gss_server_state *state, const char *challenge);
</span><span class="cx"> int authenticate_gss_server_store_delegate(gss_server_state *state);
</span><ins>+int authenticate_gss_server_has_delegated(gss_server_state *state);
</ins></span></pre>
</div>
</div>

</body>
</html>