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 .\" $Heimdal: krb5_principal.3 21255 2007-06-21 04:36:31Z lha $
39 .Nm krb5_get_default_principal ,
41 .Nm krb5_build_principal ,
42 .Nm krb5_build_principal_ext ,
43 .Nm krb5_build_principal_va ,
44 .Nm krb5_build_principal_va_ext ,
45 .Nm krb5_copy_principal ,
46 .Nm krb5_free_principal ,
47 .Nm krb5_make_principal ,
49 .Nm krb5_parse_name_flags ,
50 .Nm krb5_parse_nametype ,
51 .Nm krb5_princ_realm ,
52 .Nm krb5_princ_set_realm ,
53 .Nm krb5_principal_compare ,
54 .Nm krb5_principal_compare_any_realm ,
55 .Nm krb5_principal_get_comp_string ,
56 .Nm krb5_principal_get_realm ,
57 .Nm krb5_principal_get_type ,
58 .Nm krb5_principal_match ,
59 .Nm krb5_principal_set_type ,
60 .Nm krb5_realm_compare ,
61 .Nm krb5_sname_to_principal ,
62 .Nm krb5_sock_to_principal ,
63 .Nm krb5_unparse_name ,
64 .Nm krb5_unparse_name_flags ,
65 .Nm krb5_unparse_name_fixed ,
66 .Nm krb5_unparse_name_fixed_flags ,
67 .Nm krb5_unparse_name_fixed_short ,
68 .Nm krb5_unparse_name_short
69 .Nd Kerberos 5 principal handling functions
71 Kerberos 5 Library (libkrb5, -lkrb5)
77 .Fn krb5_free_principal "krb5_context context" "krb5_principal principal"
79 .Fn krb5_parse_name "krb5_context context" "const char *name" "krb5_principal *principal"
81 .Fn krb5_parse_name_flags "krb5_context context" "const char *name" "int flags" "krb5_principal *principal"
83 .Fn "krb5_unparse_name" "krb5_context context" "krb5_const_principal principal" "char **name"
85 .Fn "krb5_unparse_name_flags" "krb5_context context" "krb5_const_principal principal" "int flags" "char **name"
87 .Fn krb5_unparse_name_fixed "krb5_context context" "krb5_const_principal principal" "char *name" "size_t len"
89 .Fn krb5_unparse_name_fixed_flags "krb5_context context" "krb5_const_principal principal" "int flags" "char *name" "size_t len"
91 .Fn "krb5_unparse_name_short" "krb5_context context" "krb5_const_principal principal" "char **name"
93 .Fn krb5_unparse_name_fixed_short "krb5_context context" "krb5_const_principal principal" "char *name" "size_t len"
95 .Fn krb5_princ_realm "krb5_context context" "krb5_principal principal"
97 .Fn krb5_princ_set_realm "krb5_context context" "krb5_principal principal" "krb5_realm *realm"
99 .Fn krb5_build_principal "krb5_context context" "krb5_principal *principal" "int rlen" "krb5_const_realm realm" "..."
101 .Fn krb5_build_principal_va "krb5_context context" "krb5_principal *principal" "int rlen" "krb5_const_realm realm" "va_list ap"
103 .Fn "krb5_build_principal_ext" "krb5_context context" "krb5_principal *principal" "int rlen" "krb5_const_realm realm" "..."
105 .Fn krb5_build_principal_va_ext "krb5_context context" "krb5_principal *principal" "int rlen" "krb5_const_realm realm" "va_list ap"
107 .Fn krb5_make_principal "krb5_context context" "krb5_principal *principal" "krb5_const_realm realm" "..."
109 .Fn krb5_copy_principal "krb5_context context" "krb5_const_principal inprinc" "krb5_principal *outprinc"
111 .Fn krb5_principal_compare "krb5_context context" "krb5_const_principal princ1" "krb5_const_principal princ2"
113 .Fn krb5_principal_compare_any_realm "krb5_context context" "krb5_const_principal princ1" "krb5_const_principal princ2"
115 .Fn krb5_principal_get_comp_string "krb5_context context" "krb5_const_principal principal" "unsigned int component"
117 .Fn krb5_principal_get_realm "krb5_context context" "krb5_const_principal principal"
119 .Fn krb5_principal_get_type "krb5_context context" "krb5_const_principal principal"
121 .Fn krb5_principal_match "krb5_context context" "krb5_const_principal principal" "krb5_const_principal pattern"
123 .Fn krb5_principal_set_type "krb5_context context" "krb5_principal principal" "int type"
125 .Fn krb5_realm_compare "krb5_context context" "krb5_const_principal princ1" "krb5_const_principal princ2"
127 .Fn krb5_sname_to_principal "krb5_context context" "const char *hostname" "const char *sname" "int32_t type" "krb5_principal *ret_princ"
129 .Fn krb5_sock_to_principal "krb5_context context" "int socket" "const char *sname" "int32_t type" "krb5_principal *principal"
131 .Fn krb5_get_default_principal "krb5_context context" "krb5_principal *princ"
133 .Fn krb5_parse_nametype "krb5_context context" "const char *str" "int32_t *type"
136 holds the name of a user or service in Kerberos.
138 A principal has two parts, a
142 The PrincipalName consists of one or more components. In printed form,
143 the components are separated by /.
144 The PrincipalName also has a name-type.
146 Examples of a principal are
147 .Li nisse/root@EXAMPLE.COM
149 .Li host/datan.kth.se@KTH.SE .
152 .Fn krb5_parse_name_flags
153 passes a principal name in
155 to the kerberos principal structure.
156 .Fn krb5_parse_name_flags
159 argument the following flags can be passed in
161 .It Dv KRB5_PRINCIPAL_PARSE_NO_REALM
162 requries the input string to be without a realm, and no realm is
166 .It Dv KRB5_PRINCIPAL_PARSE_MUST_REALM
167 requries the input string to with a realm.
170 .Fn krb5_unparse_name
172 .Fn krb5_unparse_name_flags
182 argument the following flags can be passed in
184 .It Dv KRB5_PRINCIPAL_UNPARSE_SHORT
185 no realm if the realm is one of the local realms.
186 .It Dv KRB5_PRINCIPAL_UNPARSE_NO_REALM
187 never include any realm in the principal name.
188 .It Dv KRB5_PRINCIPAL_UNPARSE_DISPLAY
195 .Fn krb5_unparse_name_fixed
197 .Fn krb5_unparse_name_fixed_flags
200 but instead unparses the principal into a fixed size buffer.
202 .Fn krb5_unparse_name_short
203 just returns the principal without the realm if the principal is
204 in the default realm. If the principal isn't, the full name is
206 .Fn krb5_unparse_name_fixed_short
208 .Fn krb5_unparse_name_short
209 but on a fixed size buffer.
211 .Fn krb5_build_principal
212 builds a principal from the realm
216 The following arguments form the components of the principal.
217 The list of components is terminated with
220 .Fn krb5_build_principal_va
222 .Fn krb5_build_principal
225 .Fn krb5_build_principal_ext
227 .Fn krb5_build_principal_va_ext
228 take a list of length-value pairs, the list is terminated with a zero
231 .Fn krb5_make_principal
232 works the same way as
233 .Fn krb5_build_principal ,
234 except it figures out the length of the realm itself.
236 .Fn krb5_copy_principal
237 makes a copy of a principal.
238 The copy needs to be freed with
239 .Fn krb5_free_principal .
241 .Fn krb5_principal_compare
242 compares the two principals, including realm of the principals and returns
244 if they are the same and
248 .Fn krb5_principal_compare_any_realm
249 works the same way as
250 .Fn krb5_principal_compare
251 but doesn't compare the realm component of the principal.
253 .Fn krb5_realm_compare
254 compares the realms of the two principals and returns
256 is they are the same, and
260 .Fn krb5_principal_match
265 The pattern is a globbing expression, where each component (separated
266 by /) is matched against the corresponding component of the principal.
269 .Fn krb5_principal_get_realm
271 .Fn krb5_principal_get_comp_string
272 functions return parts of the
274 either the realm or a specific component.
275 Both functions return string pointers to data inside the principal, so
276 they are valid only as long as the principal exists.
281 .Fn krb5_principal_get_comp_string
282 is the index of the component to return, from zero to the total number of
283 components minus one. If the index is out of range
287 .Fn krb5_principal_get_realm
289 .Fn krb5_principal_get_comp_string
291 .Fn krb5_princ_realm ,
292 .Fn krb5_princ_component
293 and related macros, described as internal in the MIT API
295 Unlike the macros, these functions return strings, not
299 was that it was believed that principal components could contain
300 binary data, but this belief was unfounded, and it has been decided
301 that principal components are infact UTF8, so it's safe to use zero
304 It's generally not necessary to look at the components of a principal.
306 .Fn krb5_principal_get_type
308 .Fn krb5_principal_set_type
309 get and sets the name type for a principal.
310 Name type handling is tricky and not often needed,
311 don't use this unless you know what you do.
314 returns the realm component of the principal.
315 The caller must not free realm unless
316 .Fn krb5_princ_set_realm
317 is called to set a new realm after freeing the realm.
318 .Fn krb5_princ_set_realm
319 sets the realm component of a principal. The old realm is not freed.
321 .Fn krb5_sname_to_principal
323 .Fn krb5_sock_to_principal
324 are for easy creation of
326 principals that can, for instance, be used to lookup a key in a keytab.
327 For both functions the
329 parameter will be used for the first component of the created principal.
335 will be used instead.
337 .Fn krb5_sname_to_principal
340 for the second component.
345 this name will be looked up with
351 the local hostname will be used.
353 .Fn krb5_sock_to_principal
358 which should be a bound
363 There must be a mapping between the address and
365 The function may try to resolve the name in DNS.
367 .Fn krb5_get_default_principal
368 tries to find out what's a reasonable default principal by looking at
369 the environment it is running in.
371 .Fn krb5_parse_nametype
372 parses and returns the name type integer value in
374 On failure the function returns an error code and set the error
378 .Xr krb5_425_conv_principal 3 ,
382 You can not have a NUL in a component in some of the variable argument
384 Until someone can give a good example of where it would be a good idea
385 to have NUL's in a component, this will not be fixed.