]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - crypto/heimdal/lib/krb5/krb5_principal.3
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / crypto / heimdal / lib / krb5 / krb5_principal.3
1 .\" Copyright (c) 2003 - 2007 Kungliga Tekniska Högskolan
2 .\" (Royal Institute of Technology, Stockholm, Sweden).
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\"
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\"    notice, this list of conditions and the following disclaimer.
11 .\"
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.
15 .\"
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.
19 .\"
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
30 .\" SUCH DAMAGE.
31 .\"
32 .\" $Id$
33 .\"
34 .Dd May  1, 2006
35 .Dt KRB5_PRINCIPAL 3
36 .Os HEIMDAL
37 .Sh NAME
38 .Nm krb5_get_default_principal ,
39 .Nm krb5_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 ,
47 .Nm krb5_parse_name ,
48 .Nm krb5_parse_name_flags ,
49 .Nm krb5_parse_nametype ,
50 .Nm krb5_princ_set_realm ,
51 .Nm krb5_principal_compare ,
52 .Nm krb5_principal_compare_any_realm ,
53 .Nm krb5_principal_get_comp_string ,
54 .Nm krb5_principal_get_realm ,
55 .Nm krb5_principal_get_type ,
56 .Nm krb5_principal_match ,
57 .Nm krb5_principal_set_type ,
58 .Nm krb5_realm_compare ,
59 .Nm krb5_sname_to_principal ,
60 .Nm krb5_sock_to_principal ,
61 .Nm krb5_unparse_name ,
62 .Nm krb5_unparse_name_flags ,
63 .Nm krb5_unparse_name_fixed ,
64 .Nm krb5_unparse_name_fixed_flags ,
65 .Nm krb5_unparse_name_fixed_short ,
66 .Nm krb5_unparse_name_short
67 .Nd Kerberos 5 principal handling functions
68 .Sh LIBRARY
69 Kerberos 5 Library (libkrb5, -lkrb5)
70 .Sh SYNOPSIS
71 .In krb5.h
72 .Pp
73 .Li krb5_principal ;
74 .Ft void
75 .Fn krb5_free_principal "krb5_context context" "krb5_principal principal"
76 .Ft krb5_error_code
77 .Fn krb5_parse_name "krb5_context context" "const char *name" "krb5_principal *principal"
78 .Ft krb5_error_code
79 .Fn krb5_parse_name_flags "krb5_context context" "const char *name" "int flags" "krb5_principal *principal"
80 .Ft krb5_error_code
81 .Fn "krb5_unparse_name" "krb5_context context" "krb5_const_principal principal" "char **name"
82 .Ft krb5_error_code
83 .Fn "krb5_unparse_name_flags" "krb5_context context" "krb5_const_principal principal" "int flags" "char **name"
84 .Ft krb5_error_code
85 .Fn krb5_unparse_name_fixed "krb5_context context" "krb5_const_principal principal" "char *name" "size_t len"
86 .Ft krb5_error_code
87 .Fn krb5_unparse_name_fixed_flags "krb5_context context" "krb5_const_principal principal" "int flags" "char *name" "size_t len"
88 .Ft krb5_error_code
89 .Fn "krb5_unparse_name_short" "krb5_context context" "krb5_const_principal principal" "char **name"
90 .Ft krb5_error_code
91 .Fn krb5_unparse_name_fixed_short "krb5_context context" "krb5_const_principal principal" "char *name" "size_t len"
92 .Ft void
93 .Fn krb5_princ_set_realm "krb5_context context" "krb5_principal principal" "krb5_realm *realm"
94 .Ft krb5_error_code
95 .Fn krb5_build_principal "krb5_context context" "krb5_principal *principal" "int rlen" "krb5_const_realm realm" "..."
96 .Ft krb5_error_code
97 .Fn krb5_build_principal_va "krb5_context context" "krb5_principal *principal" "int rlen" "krb5_const_realm realm" "va_list ap"
98 .Ft krb5_error_code
99 .Fn "krb5_build_principal_ext" "krb5_context context" "krb5_principal *principal" "int rlen" "krb5_const_realm realm" "..."
100 .Ft krb5_error_code
101 .Fn krb5_build_principal_va_ext "krb5_context context" "krb5_principal *principal" "int rlen" "krb5_const_realm realm" "va_list ap"
102 .Ft krb5_error_code
103 .Fn krb5_make_principal "krb5_context context" "krb5_principal *principal" "krb5_const_realm realm" "..."
104 .Ft krb5_error_code
105 .Fn krb5_copy_principal "krb5_context context" "krb5_const_principal inprinc" "krb5_principal *outprinc"
106 .Ft krb5_boolean
107 .Fn krb5_principal_compare "krb5_context context" "krb5_const_principal princ1" "krb5_const_principal princ2"
108 .Ft krb5_boolean
109 .Fn krb5_principal_compare_any_realm "krb5_context context" "krb5_const_principal princ1" "krb5_const_principal princ2"
110 .Ft "const char *"
111 .Fn krb5_principal_get_comp_string "krb5_context context" "krb5_const_principal principal" "unsigned int component"
112 .Ft "const char *"
113 .Fn krb5_principal_get_realm "krb5_context context" "krb5_const_principal principal"
114 .Ft int
115 .Fn krb5_principal_get_type "krb5_context context" "krb5_const_principal principal"
116 .Ft krb5_boolean
117 .Fn krb5_principal_match "krb5_context context" "krb5_const_principal principal" "krb5_const_principal pattern"
118 .Ft void
119 .Fn krb5_principal_set_type "krb5_context context" "krb5_principal principal" "int type"
120 .Ft krb5_boolean
121 .Fn krb5_realm_compare "krb5_context context" "krb5_const_principal princ1" "krb5_const_principal princ2"
122 .Ft krb5_error_code
123 .Fn krb5_sname_to_principal  "krb5_context context" "const char *hostname" "const char *sname" "int32_t type" "krb5_principal *ret_princ"
124 .Ft krb5_error_code
125 .Fn krb5_sock_to_principal "krb5_context context" "int socket" "const char *sname" "int32_t type" "krb5_principal *principal"
126 .Ft krb5_error_code
127 .Fn krb5_get_default_principal "krb5_context context" "krb5_principal *princ"
128 .Ft krb5_error_code
129 .Fn krb5_parse_nametype "krb5_context context" "const char *str" "int32_t *type"
130 .Sh DESCRIPTION
131 .Li krb5_principal
132 holds the name of a user or service in Kerberos.
133 .Pp
134 A principal has two parts, a
135 .Li PrincipalName
136 and a
137 .Li realm .
138 The PrincipalName consists of one or more components. In printed form,
139 the components are separated by /.
140 The PrincipalName also has a name-type.
141 .Pp
142 Examples of a principal are
143 .Li nisse/root@EXAMPLE.COM
144 and
145 .Li host/datan.kth.se@KTH.SE .
146 .Fn krb5_parse_name
147 and
148 .Fn krb5_parse_name_flags
149 passes a principal name in
150 .Fa name
151 to the kerberos principal structure.
152 .Fn krb5_parse_name_flags
153 takes an extra
154 .Fa flags
155 argument the following flags can be passed in
156 .Bl -tag -width Ds
157 .It Dv KRB5_PRINCIPAL_PARSE_NO_REALM
158 requires the input string to be without a realm, and no realm is
159 stored in the
160 .Fa principal
161 return argument.
162 .It Dv KRB5_PRINCIPAL_PARSE_REQUIRE_REALM
163 requires the input string to with a realm.
164 .El
165 .Pp
166 .Fn krb5_unparse_name
167 and
168 .Fn krb5_unparse_name_flags
169 prints the principal
170 .Fa princ
171 to the string
172 .Fa name .
173 .Fa name
174 should be freed with
175 .Xr free 3 .
176 To the
177 .Fa flags
178 argument the following flags can be passed in
179 .Bl -tag -width Ds
180 .It Dv KRB5_PRINCIPAL_UNPARSE_SHORT
181 no realm if the realm is one of the local realms.
182 .It Dv KRB5_PRINCIPAL_UNPARSE_NO_REALM
183 never include any realm in the principal name.
184 .It Dv KRB5_PRINCIPAL_UNPARSE_DISPLAY
185 don't quote
186 .El
187 On failure
188 .Fa name
189 is set to
190 .Dv NULL .
191 .Fn krb5_unparse_name_fixed
192 and
193 .Fn krb5_unparse_name_fixed_flags
194 behaves just like
195 .Fn krb5_unparse ,
196 but instead unparses the principal into a fixed size buffer.
197 .Pp
198 .Fn krb5_unparse_name_short
199 just returns the principal without the realm if the principal is
200 in the default realm. If the principal isn't, the full name is
201 returned.
202 .Fn krb5_unparse_name_fixed_short
203 works just like
204 .Fn krb5_unparse_name_short
205 but on a fixed size buffer.
206 .Pp
207 .Fn krb5_build_principal
208 builds a principal from the realm
209 .Fa realm
210 that has the length
211 .Fa rlen .
212 The following arguments form the components of the principal.
213 The list of components is terminated with
214 .Dv NULL .
215 .Pp
216 .Fn krb5_build_principal_va
217 works like
218 .Fn krb5_build_principal
219 using vargs.
220 .Pp
221 .Fn krb5_build_principal_ext
222 and
223 .Fn krb5_build_principal_va_ext
224 take a list of length-value pairs, the list is terminated with a zero
225 length.
226 .Pp
227 .Fn krb5_make_principal
228 works the same way as
229 .Fn krb5_build_principal ,
230 except it figures out the length of the realm itself.
231 .Pp
232 .Fn krb5_copy_principal
233 makes a copy of a principal.
234 The copy needs to be freed with
235 .Fn krb5_free_principal .
236 .Pp
237 .Fn krb5_principal_compare
238 compares the two principals, including realm of the principals and returns
239 .Dv TRUE
240 if they are the same and
241 .Dv FALSE
242 if not.
243 .Pp
244 .Fn krb5_principal_compare_any_realm
245 works the same way as
246 .Fn krb5_principal_compare
247 but doesn't compare the realm component of the principal.
248 .Pp
249 .Fn krb5_realm_compare
250 compares the realms of the two principals and returns
251 .Dv TRUE
252 is they are the same, and
253 .Dv FALSE
254 if not.
255 .Pp
256 .Fn krb5_principal_match
257 matches a
258 .Fa principal
259 against a
260 .Fa pattern .
261 The pattern is a globbing expression, where each component (separated
262 by /) is matched against the corresponding component of the principal.
263 .Pp
264 The
265 .Fn krb5_principal_get_realm
266 and
267 .Fn krb5_principal_get_comp_string
268 functions return parts of the
269 .Fa principal ,
270 either the realm or a specific component.
271 Both functions return string pointers to data inside the principal, so
272 they are valid only as long as the principal exists.
273 .Pp
274 The
275 .Fa component
276 argument to
277 .Fn krb5_principal_get_comp_string
278 is the index of the component to return, from zero to the total number of
279 components minus one. If the index is out of range
280 .Dv NULL
281 is returned.
282 .Pp
283 .Fn krb5_principal_get_realm
284 and
285 .Fn krb5_principal_get_comp_string
286 are replacements for
287 .Fn krb5_princ_component
288 and related macros, described as internal in the MIT API
289 specification.
290 Unlike the macros, these functions return strings, not
291 .Dv krb5_data .
292 A reason to return
293 .Dv krb5_data
294 was that it was believed that principal components could contain
295 binary data, but this belief was unfounded, and it has been decided
296 that principal components are infact UTF8, so it's safe to use zero
297 terminated strings.
298 .Pp
299 It's generally not necessary to look at the components of a principal.
300 .Pp
301 .Fn krb5_principal_get_type
302 and
303 .Fn krb5_principal_set_type
304 get and sets the name type for a principal.
305 Name type handling is tricky and not often needed,
306 don't use this unless you know what you do.
307 .Pp
308 .Fn krb5_sname_to_principal
309 and
310 .Fn krb5_sock_to_principal
311 are for easy creation of
312 .Dq service
313 principals that can, for instance, be used to lookup a key in a keytab.
314 For both functions the
315 .Fa sname
316 parameter will be used for the first component of the created principal.
317 If
318 .Fa sname
319 is
320 .Dv NULL ,
321 .Dq host
322 will be used instead.
323 .Pp
324 .Fn krb5_sname_to_principal
325 will use the passed
326 .Fa hostname
327 for the second component.
328 If
329 .Fa type
330 is
331 .Dv KRB5_NT_SRV_HST
332 this name will be looked up with
333 .Fn gethostbyname .
334 If
335 .Fa hostname
336 is
337 .Dv NULL ,
338 the local hostname will be used.
339 .Pp
340 .Fn krb5_sock_to_principal
341 will use the
342 .Dq sockname
343 of the passed
344 .Fa socket ,
345 which should be a bound
346 .Dv AF_INET
347 or
348 .Dv AF_INET6
349 socket.
350 There must be a mapping between the address and
351 .Dq sockname .
352 The function may try to resolve the name in DNS.
353 .Pp
354 .Fn krb5_get_default_principal
355 tries to find out what's a reasonable default principal by looking at
356 the environment it is running in.
357 .Pp
358 .Fn krb5_parse_nametype
359 parses and returns the name type integer value in
360 .Fa type .
361 On failure the function returns an error code and set the error
362 string.
363 .\" .Sh EXAMPLES
364 .Sh SEE ALSO
365 .Xr krb5_425_conv_principal 3 ,
366 .Xr krb5_config 3 ,
367 .Xr krb5.conf 5
368 .Sh BUGS
369 You can not have a NUL in a component in some of the variable argument
370 functions above.
371 Until someone can give a good example of where it would be a good idea
372 to have NUL's in a component, this will not be fixed.