1 .\" Copyright (c) 2003 - 2007 Kungliga Tekniska Högskolan
2 .\" (Royal Institute of Technology, Stockholm, Sweden).
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
16 .\" 3. Neither the name of the Institute nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" $Id: krb5_principal.3 21255 2007-06-21 04:36:31Z lha $
38 .Nm krb5_get_default_principal ,
40 .Nm krb5_build_principal ,
41 .Nm krb5_build_principal_ext ,
42 .Nm krb5_build_principal_va ,
43 .Nm krb5_build_principal_va_ext ,
44 .Nm krb5_copy_principal ,
45 .Nm krb5_free_principal ,
46 .Nm krb5_make_principal ,
48 .Nm krb5_parse_name_flags ,
49 .Nm krb5_parse_nametype ,
50 .Nm krb5_princ_realm ,
51 .Nm krb5_princ_set_realm ,
52 .Nm krb5_principal_compare ,
53 .Nm krb5_principal_compare_any_realm ,
54 .Nm krb5_principal_get_comp_string ,
55 .Nm krb5_principal_get_realm ,
56 .Nm krb5_principal_get_type ,
57 .Nm krb5_principal_match ,
58 .Nm krb5_principal_set_type ,
59 .Nm krb5_realm_compare ,
60 .Nm krb5_sname_to_principal ,
61 .Nm krb5_sock_to_principal ,
62 .Nm krb5_unparse_name ,
63 .Nm krb5_unparse_name_flags ,
64 .Nm krb5_unparse_name_fixed ,
65 .Nm krb5_unparse_name_fixed_flags ,
66 .Nm krb5_unparse_name_fixed_short ,
67 .Nm krb5_unparse_name_short
68 .Nd Kerberos 5 principal handling functions
70 Kerberos 5 Library (libkrb5, -lkrb5)
76 .Fn krb5_free_principal "krb5_context context" "krb5_principal principal"
78 .Fn krb5_parse_name "krb5_context context" "const char *name" "krb5_principal *principal"
80 .Fn krb5_parse_name_flags "krb5_context context" "const char *name" "int flags" "krb5_principal *principal"
82 .Fn "krb5_unparse_name" "krb5_context context" "krb5_const_principal principal" "char **name"
84 .Fn "krb5_unparse_name_flags" "krb5_context context" "krb5_const_principal principal" "int flags" "char **name"
86 .Fn krb5_unparse_name_fixed "krb5_context context" "krb5_const_principal principal" "char *name" "size_t len"
88 .Fn krb5_unparse_name_fixed_flags "krb5_context context" "krb5_const_principal principal" "int flags" "char *name" "size_t len"
90 .Fn "krb5_unparse_name_short" "krb5_context context" "krb5_const_principal principal" "char **name"
92 .Fn krb5_unparse_name_fixed_short "krb5_context context" "krb5_const_principal principal" "char *name" "size_t len"
94 .Fn krb5_princ_realm "krb5_context context" "krb5_principal principal"
96 .Fn krb5_princ_set_realm "krb5_context context" "krb5_principal principal" "krb5_realm *realm"
98 .Fn krb5_build_principal "krb5_context context" "krb5_principal *principal" "int rlen" "krb5_const_realm realm" "..."
100 .Fn krb5_build_principal_va "krb5_context context" "krb5_principal *principal" "int rlen" "krb5_const_realm realm" "va_list ap"
102 .Fn "krb5_build_principal_ext" "krb5_context context" "krb5_principal *principal" "int rlen" "krb5_const_realm realm" "..."
104 .Fn krb5_build_principal_va_ext "krb5_context context" "krb5_principal *principal" "int rlen" "krb5_const_realm realm" "va_list ap"
106 .Fn krb5_make_principal "krb5_context context" "krb5_principal *principal" "krb5_const_realm realm" "..."
108 .Fn krb5_copy_principal "krb5_context context" "krb5_const_principal inprinc" "krb5_principal *outprinc"
110 .Fn krb5_principal_compare "krb5_context context" "krb5_const_principal princ1" "krb5_const_principal princ2"
112 .Fn krb5_principal_compare_any_realm "krb5_context context" "krb5_const_principal princ1" "krb5_const_principal princ2"
114 .Fn krb5_principal_get_comp_string "krb5_context context" "krb5_const_principal principal" "unsigned int component"
116 .Fn krb5_principal_get_realm "krb5_context context" "krb5_const_principal principal"
118 .Fn krb5_principal_get_type "krb5_context context" "krb5_const_principal principal"
120 .Fn krb5_principal_match "krb5_context context" "krb5_const_principal principal" "krb5_const_principal pattern"
122 .Fn krb5_principal_set_type "krb5_context context" "krb5_principal principal" "int type"
124 .Fn krb5_realm_compare "krb5_context context" "krb5_const_principal princ1" "krb5_const_principal princ2"
126 .Fn krb5_sname_to_principal "krb5_context context" "const char *hostname" "const char *sname" "int32_t type" "krb5_principal *ret_princ"
128 .Fn krb5_sock_to_principal "krb5_context context" "int socket" "const char *sname" "int32_t type" "krb5_principal *principal"
130 .Fn krb5_get_default_principal "krb5_context context" "krb5_principal *princ"
132 .Fn krb5_parse_nametype "krb5_context context" "const char *str" "int32_t *type"
135 holds the name of a user or service in Kerberos.
137 A principal has two parts, a
141 The PrincipalName consists of one or more components. In printed form,
142 the components are separated by /.
143 The PrincipalName also has a name-type.
145 Examples of a principal are
146 .Li nisse/root@EXAMPLE.COM
148 .Li host/datan.kth.se@KTH.SE .
151 .Fn krb5_parse_name_flags
152 passes a principal name in
154 to the kerberos principal structure.
155 .Fn krb5_parse_name_flags
158 argument the following flags can be passed in
160 .It Dv KRB5_PRINCIPAL_PARSE_NO_REALM
161 requries the input string to be without a realm, and no realm is
165 .It Dv KRB5_PRINCIPAL_PARSE_MUST_REALM
166 requries the input string to with a realm.
169 .Fn krb5_unparse_name
171 .Fn krb5_unparse_name_flags
181 argument the following flags can be passed in
183 .It Dv KRB5_PRINCIPAL_UNPARSE_SHORT
184 no realm if the realm is one of the local realms.
185 .It Dv KRB5_PRINCIPAL_UNPARSE_NO_REALM
186 never include any realm in the principal name.
187 .It Dv KRB5_PRINCIPAL_UNPARSE_DISPLAY
194 .Fn krb5_unparse_name_fixed
196 .Fn krb5_unparse_name_fixed_flags
199 but instead unparses the principal into a fixed size buffer.
201 .Fn krb5_unparse_name_short
202 just returns the principal without the realm if the principal is
203 in the default realm. If the principal isn't, the full name is
205 .Fn krb5_unparse_name_fixed_short
207 .Fn krb5_unparse_name_short
208 but on a fixed size buffer.
210 .Fn krb5_build_principal
211 builds a principal from the realm
215 The following arguments form the components of the principal.
216 The list of components is terminated with
219 .Fn krb5_build_principal_va
221 .Fn krb5_build_principal
224 .Fn krb5_build_principal_ext
226 .Fn krb5_build_principal_va_ext
227 take a list of length-value pairs, the list is terminated with a zero
230 .Fn krb5_make_principal
231 works the same way as
232 .Fn krb5_build_principal ,
233 except it figures out the length of the realm itself.
235 .Fn krb5_copy_principal
236 makes a copy of a principal.
237 The copy needs to be freed with
238 .Fn krb5_free_principal .
240 .Fn krb5_principal_compare
241 compares the two principals, including realm of the principals and returns
243 if they are the same and
247 .Fn krb5_principal_compare_any_realm
248 works the same way as
249 .Fn krb5_principal_compare
250 but doesn't compare the realm component of the principal.
252 .Fn krb5_realm_compare
253 compares the realms of the two principals and returns
255 is they are the same, and
259 .Fn krb5_principal_match
264 The pattern is a globbing expression, where each component (separated
265 by /) is matched against the corresponding component of the principal.
268 .Fn krb5_principal_get_realm
270 .Fn krb5_principal_get_comp_string
271 functions return parts of the
273 either the realm or a specific component.
274 Both functions return string pointers to data inside the principal, so
275 they are valid only as long as the principal exists.
280 .Fn krb5_principal_get_comp_string
281 is the index of the component to return, from zero to the total number of
282 components minus one. If the index is out of range
286 .Fn krb5_principal_get_realm
288 .Fn krb5_principal_get_comp_string
290 .Fn krb5_princ_realm ,
291 .Fn krb5_princ_component
292 and related macros, described as internal in the MIT API
294 Unlike the macros, these functions return strings, not
298 was that it was believed that principal components could contain
299 binary data, but this belief was unfounded, and it has been decided
300 that principal components are infact UTF8, so it's safe to use zero
303 It's generally not necessary to look at the components of a principal.
305 .Fn krb5_principal_get_type
307 .Fn krb5_principal_set_type
308 get and sets the name type for a principal.
309 Name type handling is tricky and not often needed,
310 don't use this unless you know what you do.
313 returns the realm component of the principal.
314 The caller must not free realm unless
315 .Fn krb5_princ_set_realm
316 is called to set a new realm after freeing the realm.
317 .Fn krb5_princ_set_realm
318 sets the realm component of a principal. The old realm is not freed.
320 .Fn krb5_sname_to_principal
322 .Fn krb5_sock_to_principal
323 are for easy creation of
325 principals that can, for instance, be used to lookup a key in a keytab.
326 For both functions the
328 parameter will be used for the first component of the created principal.
334 will be used instead.
336 .Fn krb5_sname_to_principal
339 for the second component.
344 this name will be looked up with
350 the local hostname will be used.
352 .Fn krb5_sock_to_principal
357 which should be a bound
362 There must be a mapping between the address and
364 The function may try to resolve the name in DNS.
366 .Fn krb5_get_default_principal
367 tries to find out what's a reasonable default principal by looking at
368 the environment it is running in.
370 .Fn krb5_parse_nametype
371 parses and returns the name type integer value in
373 On failure the function returns an error code and set the error
377 .Xr krb5_425_conv_principal 3 ,
381 You can not have a NUL in a component in some of the variable argument
383 Until someone can give a good example of where it would be a good idea
384 to have NUL's in a component, this will not be fixed.