xref: /freebsd/crypto/heimdal/doc/doxyout/krb5/html/krb5_keytab_intro.html (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
3<title>HeimdalKerberos5library: The keytab handing functions</title>
4<link href="doxygen.css" rel="stylesheet" type="text/css">
5<link href="tabs.css" rel="stylesheet" type="text/css">
6</head><body>
7<p>
8<a href="http://www.h5l.org/"><img src="http://www.h5l.org/keyhole-heimdal.png" alt="keyhole logo"/></a>
9</p>
10<!-- end of header marker -->
11<!-- Generated by Doxygen 1.5.6 -->
12<div class="navigation" id="top">
13  <div class="tabs">
14    <ul>
15      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
16      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
17      <li><a href="modules.html"><span>Modules</span></a></li>
18      <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
19    </ul>
20  </div>
21</div>
22<div class="contents">
23<h1><a class="anchor" name="krb5_keytab_intro">The keytab handing functions </a></h1><h2><a class="anchor" name="section_krb5_keytab">
24Kerberos Keytabs</a></h2>
25See the library functions here: <a class="el" href="group__krb5__keytab.html">Heimdal Kerberos 5 keytab handling functions</a><p>
26Keytabs are long term key storage for servers, their equvalment of password files.<p>
27Normally the only function that useful for server are to specify what keytab to use to other core functions like krb5_rd_req() <a class="el" href="group__krb5__keytab.html#gc57fead58fb1baa003d6438613731901">krb5_kt_resolve()</a>, and <a class="el" href="group__krb5__keytab.html#gb67f5ae0a7c4b87d193218b842cad590">krb5_kt_close()</a>.<h3><a class="anchor" name="krb5_keytab_names">
28Keytab names</a></h3>
29A keytab name is on the form type:residual. The residual part is specific to each keytab-type.<p>
30When a keytab-name is resolved, the type is matched with an internal list of keytab types. If there is no matching keytab type, the default keytab is used. The current default type is FILE.<p>
31The default value can be changed in the configuration file /etc/krb5.conf by setting the variable [defaults]default_keytab_name.<p>
32The keytab types that are implemented in Heimdal are:<ul>
33<li>file store the keytab in a file, the type's name is FILE . The residual part is a filename. For compatibility with other Kerberos implemtation WRFILE and JAVA14 is also accepted. WRFILE has the same format as FILE. JAVA14 have a format that is compatible with older versions of MIT kerberos and SUN's Java based installation. They store a truncted kvno, so when the knvo excess 255, they are truncted in this format.</li></ul>
34<p>
35<ul>
36<li>keytab store the keytab in a AFS keyfile (usually /usr/afs/etc/KeyFile ), the type's name is AFSKEYFILE. The residual part is a filename.</li></ul>
37<p>
38<ul>
39<li>memory The keytab is stored in a memory segment. This allows sensitive and/or temporary data not to be stored on disk. The type's name is MEMORY. Each MEMORY keytab is referenced counted by and opened by the residual name, so two handles can point to the same memory area. When the last user closes using <a class="el" href="group__krb5__keytab.html#gb67f5ae0a7c4b87d193218b842cad590">krb5_kt_close()</a> the keytab, the keys in they keytab is memset() to zero and freed and can no longer be looked up by name.</li></ul>
40<h3><a class="anchor" name="krb5_keytab_example">
41Keytab example</a></h3>
42This is a minimalistic version of ktutil.<p>
43<div class="fragment"><pre class="fragment"><span class="keywordtype">int</span>
44main (<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
45{
46    krb5_context context;
47    krb5_keytab keytab;
48    krb5_kt_cursor cursor;
49    krb5_keytab_entry entry;
50    krb5_error_code ret;
51    <span class="keywordtype">char</span> *principal;
52
53    <span class="keywordflow">if</span> (<a class="code" href="group__krb5.html#gbd94206e186c58a093975424a4a567a8">krb5_init_context</a> (&amp;context) != 0)
54        errx(1, <span class="stringliteral">"krb5_context"</span>);
55
56    ret = <a class="code" href="group__krb5__keytab.html#gfcd059883c79dbd99a179bc4225d16b5">krb5_kt_default</a> (context, &amp;keytab);
57    <span class="keywordflow">if</span> (ret)
58        krb5_err(context, 1, ret, <span class="stringliteral">"krb5_kt_default"</span>);
59
60    ret = <a class="code" href="group__krb5__keytab.html#g1efd8ee48d6e3caa31cad475423b8917">krb5_kt_start_seq_get</a>(context, keytab, &amp;cursor);
61    <span class="keywordflow">if</span> (ret)
62        krb5_err(context, 1, ret, <span class="stringliteral">"krb5_kt_start_seq_get"</span>);
63    <span class="keywordflow">while</span>((ret = <a class="code" href="group__krb5__keytab.html#gc40140c41333a86d3c40426f50b4e1b0">krb5_kt_next_entry</a>(context, keytab, &amp;entry, &amp;cursor)) == 0){
64        <a class="code" href="group__krb5__principal.html#gac881051ed59fe0dcd08cee62280b332">krb5_unparse_name</a>(context, entry.principal, &amp;principal);
65        printf(<span class="stringliteral">"principal: %s\n"</span>, principal);
66        free(principal);
67        <a class="code" href="group__krb5__keytab.html#gc0774ab1407eaaaa0e5998478de246e2">krb5_kt_free_entry</a>(context, &amp;entry);
68    }
69    ret = <a class="code" href="group__krb5__keytab.html#g11289efb407d93a1f84d5c64731a4bd1">krb5_kt_end_seq_get</a>(context, keytab, &amp;cursor);
70    <span class="keywordflow">if</span> (ret)
71        krb5_err(context, 1, ret, <span class="stringliteral">"krb5_kt_end_seq_get"</span>);
72    ret = <a class="code" href="group__krb5__keytab.html#gb67f5ae0a7c4b87d193218b842cad590">krb5_kt_close</a>(context, keytab);
73    <span class="keywordflow">if</span> (ret)
74        krb5_err(context, 1, ret, <span class="stringliteral">"krb5_kt_close"</span>);
75    <a class="code" href="group__krb5.html#ge51d83f5d5f589883f1cd10887892777">krb5_free_context</a>(context);
76    <span class="keywordflow">return</span> 0;
77}
78</pre></div> </div>
79<hr size="1"><address style="text-align: right;"><small>
80Generated on Wed Jan 11 14:07:47 2012 for HeimdalKerberos5library by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6</small></address>
81</body>
82</html>
83