summaryrefslogtreecommitdiffstats
path: root/doc/api/krb5.tex
blob: 3e347a47c5212f6c9028719cf80b756c34822ab3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
The main functions deal with the nitty-gritty details: verifying
tickets, creating authenticators, and the like.

\subsubsection{The krb5_context}
The \datatype{krb5_context} is designed to represent the per process
state. When the library is made thread-safe, the context will represent
the per-thread state. Global parameters which are ``context'' specific
are stored in this structure, including default realm, default
encryption type, default configuration files and the like. Functions
exist to provide full access to the data structures stored in the
context and should not be accessed directly by developers.

\begin{funcdecl}{krb5_init_context}{krb5_error_code}{\funcout}
\funcarg{krb5_context *}{context}
\end{funcdecl}

Initializes the context \funcparam{*context} for the
application. Currently the context contains the encryption types, a
pointer to operating specific data and the default realm. In the future,
the context may be also contain thread specific data.  The data in the
context should be freed with \funcname{krb5_free_context}.

Returns system errors.

\begin{funcdecl}{krb5_free_context}{void}{\funcinout}
\funcarg{krb5_context}{context}
\end{funcdecl}

Frees the context returned by \funcname{krb5_init_context}. Internally
calls \funcname{krb5_os_free_context}.

\begin{funcdecl}{krb5_set_default_in_tkt_etypes}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_enctype *}{etypes}
\end{funcdecl}

Sets the desired default encryption type \funcparam{etypes} for the context
if valid.

Returns {\sc enomem}, {\sc krb5_prog_etype_nosupp}.

\begin{funcdecl}{krb5_get_default_in_tkt_etypes}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcout
\funcarg{krb5_enctype **}{etypes}
\end{funcdecl}

Retrieves the default encryption types from the context and stores them
in \funcarg{etypes} which should be freed by the caller.

Returns {\sc enomem}.

\subsubsection{The krb5_auth_context}

While the \datatype{krb5_context} represents a per-process or per-thread
context, the \datatype{krb5_auth_context} represents a per-connection
context are are used by the various functions involved directly in
client/server authentication.  Some of the data stored in this context
include keyblocks, addresses, sequence numbers, authenticators, checksum
type, and replay cache pointer. 

\begin{funcdecl}{krb5_auth_con_init}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcout
\funcarg{krb5_auth_context *}{auth_context}
\end{funcdecl}

The auth_context may be described as a per connection context. This
context contains all data pertinent to the the various authentication
routines. This function initializes the auth_context. 

The default flags for the context are set to enable the use of the replay cache
(KRB5_AUTH_CONTEXT_DO_TIME) but no sequence numbers. The function
\funcname{krb5_auth_con_setflags} allows the flags to be changed.

The default checksum type is set to CKSUMTYPE_RSA_MD4_DES. This may be
changed with \funcname{krb5_auth_con_setcksumtype}.

The auth_context structure should be freed with
\funcname{krb5_auth_con_free}.

\begin{funcdecl}{krb5_auth_con_free}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\end{funcdecl}

Frees the auth_context \funcparam{auth_context} returned by
\funcname{krb5_auth_con_init}.

% perhaps some comment about which substructures are freed and which are not?

\begin{funcdecl}{krb5_auth_con_setflags}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\funcin
\funcarg{krb5_int32}{flags}
\end{funcdecl}

Sets the flags of \funcparam{auth_context} to funcparam{flags}. Valid
flags are:

\begin{tabular}{ll}
\multicolumn{1}{c}{Symbol} & Meaning \\
KRB5_AUTH_CONTEXT_DO_TIME & Use timestamps \\
KRB5_AUTH_CONTEXT_RET_TIME & Save timestamps\\ &\  to output structure\\
KRB5_AUTH_CONTEXT_DO_SEQUENCE   & Use sequence numbers \\
KRB5_AUTH_CONTEXT_RET_SEQUENCE  & Copy sequence numbers \\ &\ to output structure\\
\end{tabular}


\begin{funcdecl}{krb5_auth_con_getflags}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{krb5_auth_context}{auth_context}
\funcout
\funcarg{krb5_int32 *}{flags}
\end{funcdecl}

Retrievs the flags of \funcparam{auth_context}.

\begin{funcdecl}{krb5_auth_con_setaddrs}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\funcin
\funcarg{krb5_address *}{local_addr}
\funcarg{krb5_address *}{remote_addr}
\end{funcdecl}

Copies the \funcparam{local_addr} and \funcparam{remote_addr} into the
\funcparam{auth_context}. If either address is NULL, the previous
address remains in place.

\begin{funcdecl}{krb5_auth_con_getaddrs}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\funcout
\funcarg{krb5_address **}{local_addr}
\funcarg{krb5_address **}{remote_addr}
\end{funcdecl}

Retrieves  \funcparam{local_addr} and \funcparam{remote_addr} from the
\funcparam{auth_context}. If \funcparam{local_addr} or
\funcparam{remote_addr} is not NULL, the memory is first freed with
\funcname{krb5_free_address} and then newly allocated. It is the callers
responsibility to free the returned addresses in this way.


\begin{funcdecl}{krb5_auth_con_setports}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\funcin
\funcarg{krb5_address *}{local_port}
\funcarg{krb5_address *}{remote_port}
\end{funcdecl}

Copies the \funcparam{local_port} and \funcparam{remote_port} addresses
into the \funcparam{auth_context}. If either address is NULL, the previous
address remains in place. These addresses are set by
\funcname{krb5_auth_con_genaddrs}. 

\begin{funcdecl}{krb5_auth_con_setuserkey}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\funcin
\funcarg{krb5_keyblock *}{keyblock}
\end{funcdecl}

This function overloads the keyblock field. It is only useful prior to a
\funcname{krb5_rd_req_decode} call for user to user authentication where
the server has the key and needs to use it to decrypt the incoming
request.  Once decrypted this key is no longer necessary and is then
overwritten with the session key sent by the client. 

\begin{funcdecl}{krb5_auth_con_getkey}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\funcout
\funcarg{krb5_keyblock **}{keyblock}
\end{funcdecl}

Retrieves the keyblock stored in \funcparam{auth_context}. The memory
allocated in this function should be freed with a call to
\funcname{krb5_free_keyblock}. 

\begin{funcdecl}{krb5_auth_con_getrecvsubkey}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\funcout
\funcarg{krb5_keyblock **}{keyblock}
\end{funcdecl}

Retrieves the recv\_subkey keyblock stored in
\funcparam{auth_context}. The memory allocated in this function should
be freed with a call to \funcname{krb5_free_keyblock}.

\begin{funcdecl}{krb5_auth_con_getsendsubkey}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\funcout
\funcarg{krb5_keyblock **}{keyblock}
\end{funcdecl}

Retrieves the send\_subkey keyblock stored in
\funcparam{auth_context}. The memory allocated in this function should
be freed with a call to \funcname{krb5_free_keyblock}.

\begin{funcdecl}{krb5_auth_con_setrecvsubkey}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\funcout
\funcarg{krb5_keyblock *}{keyblock}
\end{funcdecl}

Sets the recv\_subkey keyblock stored in \funcparam{auth_context}.

\begin{funcdecl}{krb5_auth_con_setsendsubkey}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\funcout
\funcarg{krb5_keyblock *}{keyblock}
\end{funcdecl}

Sets the send\_subkey keyblock stored in \funcparam{auth_context}.

\begin{funcdecl}{krb5_auth_setcksumtype}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\funcin
\funcarg{krb5_cksumtype}{cksumtype}
\end{funcdecl}

Sets the checksum type used by the other functions in the library. 

\begin{funcdecl}{krb5_auth_getlocalseqnumber}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\funcin
\funcarg{krb5_int32 *}{seqnumber}
\end{funcdecl}

Retrieves the local sequence number that was used during authentication
and stores it in \funcparam{seqnumber}.

\begin{funcdecl}{krb5_auth_getremoteseqnumber}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\funcin
\funcarg{krb5_int32 *}{seqnumber}
\end{funcdecl}

Retrieves the remote sequence number that was used during authentication
and stores it in \funcparam{seqnumber}.

\begin{funcdecl}{krb5_auth_getauthenticator}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\funcout
\funcarg{krb5_authenticator **}{authenticator}
\end{funcdecl}

Retrieves the authenticator that was used during mutual
authentication. It is the callers responsibility to free the memory
allocated to \funcparam{authenticator} by calling
\funcname{krb5_free_authenticator}. 

\begin{funcdecl}{krb5_auth_con_initivector}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\end{funcdecl}

Allocates memory for and zeros the initial vector in the
\funcparam{auth_context} keyblock.

\begin{funcdecl}{krb5_auth_con_setivector}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context *}{auth_context}
\funcin
\funcarg{krb5_pointer}{ivector}
\end{funcdecl}

Sets the i_vector portion of \funcparam{auth_context} to
\funcparam{ivector}. 

\begin{funcdecl}{krb5_auth_con_setrcache}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\funcin
\funcarg{krb5_rcache}{rcache}
\end{funcdecl}

Sets the replay cache that is used by the authentication routines to \funcparam{rcache}.

%%
%% The following prototypes exist, but there is no code at this time
%% krb5_auth_con_getcksumtype, krb5_auth_con_getivector,
%% krb5_auth_con_getrcache. -- Ezra

\subsubsection{Principal access functions}

Principals define a uniquely named client or server instance that
participates in a network communication. The following functions allow
one to create, modify and access portions of the
\datatype{krb5_principal}. 

Other functions found in orther portions of the manual include
\funcname{krb5_sname_to_principal}, \funcname{krb5_free_principal}, 

While it is possible to directly access the data structure in the
structure, it is recommended that the functions be used. 

\begin{funcdecl}{krb5_parse_name}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const char *}{name}
\funcout
\funcarg{krb5_principal *}{principal}
\end{funcdecl}

Converts a single-string representation \funcparam{name} of the
principal name to the multi-part principal format used in the protocols.

A single-string representation of a Kerberos name consists of one or
more principal name components, separated by slashes, optionally
followed by the ``@'' character and a realm name.  If the realm name
is not specified, the local realm is used.

The slash and ``@'' characters may be quoted (i.e., included as part
of a component rather than as a component separator or realm prefix)
by preceding them with a backslash (``$\backslash$'') character.
Similarly, newline, tab, backspace, and null characters may be
included in a component by using $\backslash{}n$, $\backslash{}t$,
$\backslash{}b$ or $\backslash{}0$, respectively.

The realm in a Kerberos name may not contain the slash, colon or null
characters.

\funcparam{*principal} will point to allocated storage which should be freed by
the caller (using \funcname{krb5_free_principal}) after use.

\funcname{krb5_parse_name} returns KRB5_PARSE_MALFORMED if the string is
 badly formatted, or ENOMEM if space for the return value can't be
allocated.

\begin{funcdecl}{krb5_unparse_name}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{krb5_const_principal}{principal}
\funcout
\funcarg{char **}{name}
\end{funcdecl}

Converts the multi-part principal name \funcparam{principal} from the
format used in the protocols to a single-string representation of the
name.  The resulting single-string representation will use the format
and quoting conventions described for \funcname{krb5_parse_name}
above.

\funcparam{*name} points to allocated storage and should be freed by the caller
when finished.

\funcname{krb5_unparse_name} returns {\sc KRB_PARSE_MALFORMED} if the principal
does not contain at least 2 components, and system errors ({\sc ENOMEM} if
unable to allocate memory).

\begin{funcdecl}{krb5_unparse_name_ext}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{krb5_const_principal}{principal}
\funcinout
\funcarg{char **}{name}
\funcarg{unsigned int *}{size}
\end{funcdecl}

\funcname{krb5_unparse_name_ext} is designed for applications which
must unparse a large number of principals, and are concerned about the
speed impact of needing to do a lot of memory allocations and
deallocations.  It functions similarly to \funcname{krb5_unparse_name}
except if \funcparam{*name} is non-null, in which case, it is assumed
to contain an allocated buffer of size \funcparam{*size} and this
buffer will be resized with \funcname{realloc} to hold the unparsed
name.  Note that in this case,
\funcparam{size} must not be null.  

If \funcparam{size} is non-null (whether or not \funcparam{*name} is
null when the function is called), it will be filled in with the size
of the unparsed name upon successful return.

\begin{funcdecl}{krb5_princ_realm}{krb5_data *}{\funcinout}
\funcparam{krb5_context}{context}
\funcparam{krb5_principal}{principal}
\end{funcdecl}

A macro which returns the realm of \funcparam{principal}.

\begin{funcdecl}{krb5_princ_set_realm}{void}{\funcinout}
\funcparam{krb5_context}{context}
\funcparam{krb5_principal}{principal}
\funcparam{krb5_data *}{realm}
\end{funcdecl}

A macro which returns sets the realm of \funcparam{principal} to
\funcparam{realm}. 

\begin{funcdecl}{krb5_princ_set_realm_data}{void}{\funcinout}
\funcparam{krb5_context}{context}
\funcparam{krb5_principal}{principal}
\funcparam{char *}{data}
\end{funcdecl}

\internalfunc

A macro which returns sets the data portion of the realm of
\funcparam{principal} to \funcparam{data}. 

\begin{funcdecl}{krb5_princ_set_realm_length}{void}{\funcinout}
\funcparam{krb5_context}{context}
\funcparam{krb5_principal}{principal}
\funcparam{int}{length}
\end{funcdecl}

\internalfunc

A macro which returns sets the length \funcparam{principal} to
\funcparam{length}. 

\begin{funcdecl}{krb5_princ_size}{void}{\funcinout}
\funcparam{krb5_context}{context}
\funcparam{krb5_principal}{principal}
\end{funcdecl}

\internalfunc

A macro which gives the number of elements in the principal.
May also be used on the left size of an assignment.

\begin{funcdecl}{krb5_princ_type}{void}{\funcinout}
\funcparam{krb5_context}{context}
\funcparam{krb5_principal}{principal}
\end{funcdecl}

\internalfunc

A macro which gives the type of the principal.
May also be used on the left size of an assignment.

\begin{funcdecl}{krb5_princ_data}{}
\funcparam{krb5_context}{context}
\funcparam{krb5_principal}{principal}
\end{funcdecl}

\internalfunc

A macro which gives the pointer to data portion of the principal.
May also be used on the left size of an assignment.


\begin{funcdecl}{krb5_princ_component}{}
\funcparam{krb5_context}{context}
\funcparam{krb5_principal}{principal}
\funcparam{int}{i}
\end{funcdecl}

\internalfunc

A macro which gives the pointer to ith element of the principal.
May also be used on the left size of an assignment.

\begin{funcdecl}{krb5_build_principal}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcout
\funcarg{krb5_principal *}{princ}
\funcin
\funcarg{unsigned int}{rlen}
\funcarg{const char *}{realm}
\funcarg{char}{*s1, *s2, ..., 0}
\end{funcdecl}
\begin{funcdecl}{krb5_build_principal_va}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcout
\funcarg{krb5_principal *}{princ}
\funcin
\funcarg{unsigned int}{rlen}
\funcarg{const char *}{realm}
\funcarg{va_list}{ap}
\end{funcdecl}

\begin{sloppypar}
\funcname{krb5_build_principal} and
\funcname{krb5_build_principal_va} 
perform the same function; the former takes variadic arguments, while
the latter takes a pre-computed varargs pointer.
\end{sloppypar}

Both functions take a realm name \funcparam{realm}, realm name length
\funcparam{rlen}, and a list of null-terminated strings, and fill in a
pointer to a principal structure \funcparam{princ}, making it point to a
structure representing the named principal.
The last string must be followed in the argument list by a null pointer.


\begin{funcdecl}{krb5_build_principal_ext}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcout
\funcarg{krb5_principal *}{princ}
\funcin
\funcarg{unsigned int}{rlen}
\funcarg{const char *}{realm}
\funcarg{}{int len1, char *s1, int len2, char *s2, ..., 0}
\end{funcdecl}

\funcname{krb5_build_principal_ext} is similar to
\funcname{krb5_build_principal} but it takes its components as a list of
(length, contents) pairs rather than a list of null-terminated strings.
A length of zero indicates the end of the list.

\begin{funcdecl}{krb5_copy_principal}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{krb5_const_principal}{inprinc}
\funcout
\funcarg{krb5_principal *}{outprinc}
\end{funcdecl}

Copy a principal structure, filling in \funcparam{*outprinc} to point to
the newly allocated copy, which should be freed with
\funcname{krb5_free_principal}.

\begin{funcdecl}{krb5_principal_compare}{krb5_boolean}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{krb5_const_principal}{princ1}
\funcarg{krb5_const_principal}{princ2}
\end{funcdecl}

If the two principals are the same, return TRUE, else return FALSE.

\begin{funcdecl}{krb5_realm_compare}{krb5_boolean}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{krb5_const_principal}{princ1}
\funcarg{krb5_const_principal}{princ2}
\end{funcdecl}

If the realms of the two principals are the same, return TRUE, else
return FALSE. 


\begin{funcdecl}{krb5_425_conv_principal}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const char *}{name}
\funcarg{const char *}{instance}
\funcarg{const char *}{realm}
\funcout
\funcarg{krb5_principal *}{princ}
\end{funcdecl}

Build a principal \funcparam{princ} from a V4 specification made up of 
\funcparam{name}.\funcparam{instance}@\funcparam{realm}. The routine is
site-customized to convert the V4 naming scheme to a V5 one. For
instance, the V4 ``rcmd'' is changed to ``host''. 

The returned principal should be freed with
\funcname{krb5_free_principal}. 

\subsubsection{The application functions}

\begin{funcdecl}{krb5_encode_kdc_rep}{krb5_error_code}{\funcin}
\funcarg{const krb5_msgtype}{type}
\funcarg{const krb5_enc_kdc_rep_part *}{encpart}
\funcarg{krb5_encrypt_block *}{eblock}
\funcarg{const krb5_keyblock *}{client_key}
\funcinout
\funcarg{krb5_kdc_rep *}{dec_rep}
\funcout
\funcarg{krb5_data **}{enc_rep}
\end{funcdecl}

\internalfunc

Takes KDC rep parts in \funcparam{*rep} and \funcparam{*encpart}, and
formats it into \funcparam{*enc_rep}, using message type
\funcparam{type} and encryption key \funcparam{client_key} and
encryption block \funcparam{eblock}.

\funcparam{enc_rep{\ptsto}data} will point to  allocated storage upon
non-error return; the caller should free it when finished.

Returns system errors.

\begin{funcdecl}{krb5_decode_kdc_rep}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{krb5_data *}{enc_rep}
\funcarg{const krb5_keyblock *}{key}
\funcarg{const krb5_enctype}{etype}
\funcout
\funcarg{krb5_kdc_rep **}{dec_rep}
\end{funcdecl}

\internalfunc

Takes a KDC_REP message and decrypts encrypted part using
\funcparam{etype} and \funcparam{*key}, putting result in \funcparam{*dec_rep}.
The pointers in \funcparam{dec_rep}
are all set to allocated storage which should be freed by the caller
when finished with the response (by using \funcname{krb5_free_kdc_rep}).


If the response isn't a KDC_REP (tgs or as), it returns an error from
the decoding routines.

Returns errors from encryption routines, system errors.

\begin{funcdecl}{krb5_kdc_rep_decrypt_proc}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_keyblock *}{key}
\funcarg{krb5_const_pointer}{decryptarg}
\funcinout
\funcarg{krb5_kdc_rep *}{dec_rep}
\end{funcdecl}

Decrypt the encrypted portion of \funcparam{dec_rep}, using the
encryption key \funcparam{key}.  The parameter \funcparam{decryptarg} is
ignored.

The result is in allocated storage pointed to by
\funcparam{dec_rep{\ptsto}enc_part2}, unless some error occurs.

This function is suitable for use as the \funcparam{decrypt_proc}
argument to \funcname{krb5_get_in_tkt}.

\begin{funcdecl}{krb5_encrypt_tkt_part}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_keyblock *}{srv_key}
\funcinout
\funcarg{krb5_ticket *}{dec_ticket}
\end{funcdecl}

\internalfunc

\begin{sloppypar}
Encrypts the unecrypted part of the ticket found in 
\funcparam{dec_ticket{\ptsto}enc_part2} using
\funcparam{srv_key}, and places result in 
\funcparam{dec_ticket{\ptsto}enc_part}.
The \funcparam{dec_ticket{\ptsto}enc_part} will be allocated by this
function.
\end{sloppypar}

Returns errors from encryption routines, system errors

\funcparam{enc_part{\ptsto}data} is allocated and filled in with
encrypted stuff.

\begin{funcdecl}{krb5_decrypt_tkt_part}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_keyblock *}{srv_key}
\funcinout
\funcarg{krb5_ticket *}{dec_ticket}
\end{funcdecl}

\internalfunc

Takes encrypted \funcparam{dec_ticket{\ptsto}enc_part}, decrypts with
\funcparam{dec_ticket{\ptsto}etype}
using \funcparam{srv_key}, and places result in
\funcparam{dec_ticket{\ptsto}enc_part2}.  The storage of
\funcparam{dec_ticket{\ptsto}enc_part2} will be allocated before return.

Returns errors from encryption routines, system errors

\begin{funcdecl}{krb5_send_tgs}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_flags}{kdcoptions}
\funcarg{const krb5_ticket_times *}{timestruct}
\funcarg{const krb5_enctype *}{etypes}
\funcarg{const krb5_cksumtype}{sumtype}
\funcarg{krb5_const_principal}{sname}
\funcarg{krb5_address * const *}{addrs}
\funcarg{krb5_authdata * const *}{authorization_data}
\funcarg{krb5_pa_data * const *}{padata}
\funcarg{const krb5_data *}{second_ticket}
\funcinout
\funcarg{krb5_creds *}{in_cred}
\funcout
\funcarg{krb5_response *}{rep}
\end{funcdecl}

\internalfunc

Sends a request to the TGS and waits for a response.
\funcparam{kdcoptions} is used for the options in the KRB_TGS_REQ.
\funcparam{timestruct} values are used for from, till, and rtime in the
KRB_TGS_REQ.
\funcparam{etypes} is a list of etypes used in the KRB_TGS_REQ.
\funcparam{sumtype} is used for the checksum in the AP_REQ in the KRB_TGS_REQ.
\funcparam{sname} is used for sname in the KRB_TGS_REQ.
\funcparam{addrs}, if non-NULL, is used for addresses in the KRB_TGS_REQ.
\funcparam{authorization_data}, if non-NULL, is used for
\funcparam{authorization_data} in the KRB_TGS_REQ.  
\funcparam{padata}, if non-NULL, is combined with any other supplied
pre-authentication data for the KRB_TGS_REQ.
\funcparam{second_ticket}, if required by options, is used for the 2nd
ticket in the KRB_TGS_REQ.
\funcparam{in_cred} is used for the ticket and session key in the KRB_AP_REQ header in the KRB_TGS_REQ.

The KDC realm is extracted from \funcparam{in_cred{\ptsto}server}'s realm.

The response is placed into \funcparam{*rep}.
\funcparam{rep{\ptsto}response.data} is set to point at allocated storage
which should be freed by the caller when finished.

Returns system errors.

\begin{funcdecl}{krb5_get_cred_from_kdc}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{krb5_ccache}{ccache}
\funcarg{krb5_creds *}{in_cred}
\funcout                        
\funcarg{krb5_cred **}{out_cred}
\funcarg{krb5_creds ***}{tgts}
\end{funcdecl}


Retrieve credentials for principal \funcparam{in_cred{\ptsto}client},
server \funcparam{creds{\ptsto}server}, possibly
\funcparam{creds{\ptsto}second_ticket} if needed by the ticket flags.

\funcparam{ccache} is used to fetch initial TGT's to start the authentication
path to the server.

Credentials are requested from the KDC for the server's realm.  Any
TGT credentials obtained in the process of contacting the KDC are
returned in an array of credentials; \funcparam{tgts} is filled in to
point to an array of pointers to credential structures (if no TGT's were
used, the pointer is zeroed).  TGT's may be returned even if no useful
end ticket was obtained.

The returned credentials are NOT cached.

If credentials are obtained, \funcparam{creds} is filled in with the results;
\funcparam{creds{\ptsto}ticket} and
\funcparam{creds{\ptsto}keyblock{\ptsto}key} are set to allocated storage,
which should be freed by the caller when finished.

Returns errors, system errors.

\begin{funcdecl}{krb5_get_cred_via_tkt}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{krb5_creds *}{tkt}
\funcarg{const krb5_flags}{kdcoptions}
\funcarg{krb5_address *const *}{address}
\funcarg{krb5_creds *}{in_cred}
\funcout
\funcarg{krb5_creds **}{out_cred}
\end{funcdecl}

Takes a ticket \funcparam{tkt} and a target credential
\funcparam{in_cred}, attempts to fetch a TGS from the KDC. Upon
success the resulting is stored in \funcparam{out_cred}. The memory
allocated in \funcparam{out_cred} should be freed by the called when
finished by using \funcname{krb5_free_creds}. 

\funcparam{kdcoptions} refers to the options as listed in Table
\ref{KDCOptions}. The optional \funcparam{address} is used for addressed
in the KRB_TGS_REQ (see \funcname{krb5_send_tgs}).

Returns errors, system errors.


\begin{funcdecl}{krb5_get_credentials}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_flags}{options}
\funcarg{krb5_ccache}{ccache}
\funcarg{krb5_creds *}{in_creds}
\funcout
\funcarg{krb5_creds *}{out_creds}
\end{funcdecl}

This routine attempts to use the credentials cache \funcparam{ccache} or a TGS
exchange to get an additional ticket for the client identified by
\funcparam{in_creds{\ptsto}client}, with following information: 
\begin{itemize}
\item {\bf The server} identified by \funcparam{in_creds{\ptsto}server} 
\item {\bf The options} in \funcparam{options}.
Valid choices are KRB5_GC_USER_USER and KRB5_GC_GC_CACHED
\item {\bf The expiration date} specified in
\funcparam{in_creds{\ptsto}times.endtime}  
\item {\bf The session key type} specified in
\funcparam{in_creds{\ptsto}keyblock.keytype} if it is non-zero.
\end{itemize}

If \funcparam{options} specifies KRB5_GC_CACHED,
then \funcname{krb5_get_credentials} will only search the credentials cache
for a ticket.  

If \funcparam{options} specifies KRB5_GC_USER_USER, then
\funcname{krb5_get_credentials} will get credentials for a user to user
authentication.  In a user to user authentication, the secret key for
the server 
is the session key from the server's ticket-granting-ticket
(TGT).  The TGT is passed from the server to the client over the
network --- this is safe since the TGT is encrypted in a key
known only by the Kerberos server --- and the client must pass
this TGT to \funcname{krb5_get_credentials} in
\funcparam{in_creds{\ptsto}second_ticket}.  The Kerberos server will use
this TGT to construct a user to user ticket which can be verified by
the server by using the session key from its TGT.

The effective {\bf expiration date} is the minimum of the following:
\begin{itemize}
\item The expiration date as specified in
\funcparam{in_creds{\ptsto}times.endtime} 
\item The requested start time plus the maximum lifetime of the
server as specified by the server's entry in the
Kerberos database.
\item The requested start time plus the maximum lifetime of tickets
allowed in the local site, as specified by the KDC.
This is currently a compile-time option,
KRB5_KDB_MAX_LIFE in config.h, and is by default 1 day.
\end{itemize}

If any special authorization data needs to be included in the ticket,
--- for example, restrictions on how the ticket can be used --- 
they should be specified in \funcparam{in_creds{\ptsto}authdata}.   If there
is no special authorization data to be passed,
\funcparam{in_creds{\ptsto}authdata} should be NULL.

Any returned ticket and intermediate ticket-granting tickets are
stored in \funcparam{ccache}.

Returns errors from encryption routines, system errors.

\begin{funcdecl}{krb5_get_in_tkt}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_flags}{options}
\funcarg{krb5_address * const *}{addrs}
\funcarg{const krb5_enctype *}{etypes}
\funcarg{const krb5_preauthtype *}{ptypes}
\funcfuncarg{krb5_error_code}{(*key_proc)}
        \funcarg{krb5_context}{context}
        \funcarg{const krb5_keytype}{type}
        \funcarg{krb5_data *}{salt}
        \funcarg{krb5_const_pointer}{keyseed}
        \funcarg{krb5_keyblock **}{key}
\funcendfuncarg
\funcarg{krb5_const_pointer}{keyseed}
\funcfuncarg{krb5_error_code}{(*decrypt_proc)}
        \funcarg{krb5_context}{context}
        \funcarg{const krb5_keyblock *}{key}
        \funcarg{krb5_const_pointer}{decryptarg}
        \funcarg{krb5_kdc_rep *}{dec_rep}
\funcendfuncarg
\funcarg{krb5_const_pointer}{decryptarg}
\funcinout
\funcarg{krb5_creds *}{creds}
\funcarg{krb5_ccache}{ccache}
\funcarg{krb5_kdc_rep **}{ret_as_reply}
\end{funcdecl}

This all-purpose initial ticket routine, usually called via
\funcname{krb5_get_in_tkt_with_skey} or
\funcname{krb5_get_in_tkt_with_password} or
\funcname{krb5_get_in_tkt_with_keytab}.


Attempts to get an initial ticket for \funcparam{creds{\ptsto}client}
to use server \funcparam{creds{\ptsto}server}, using the following:
the realm from \funcparam{creds{\ptsto}client}; the options in
\funcparam{options} (listed in Table \ref{KDCOptions});
and \funcparam{ptypes}, the preauthentication
method (valid preauthentication methods are listed in Table
\ref{padata-types}).
\funcname{krb5_get_in_tkt} requests encryption type
\funcparam{etypes} (valid encryption types are ETYPE_DES_CBC_CRC and
ETYPE_RAW_DES_CBC),
using \funcparam{creds{\ptsto}times.starttime},
\funcparam{creds{\ptsto}times.endtime},
\funcparam{creds{\ptsto}times.renew_till} 
as from, till, and rtime.  \funcparam{creds{\ptsto}times.renew_till} is
ignored unless the RENEWABLE option is requested.

\funcparam{key_proc} is called, with \funcparam{context}, \funcparam{keytype},
\funcparam{keyseed} and\funcparam{padata} as arguments, to fill in \funcparam{key} to be used for
decryption.  The valid key types for \funcparam{keytype} are
KEYTYPE_NULL,\footnote{See RFC section 6.3.1} and
KEYTYPE_DES.\footnote{See RFC section 6.3.4}  However, KEYTYPE_DES is
the only key type supported by MIT kerberos.
The content of  \funcparam{keyseed} 
depends on the \funcparam{key_proc} being used. %nlg - need a ref here
The \funcparam{padata} passed
to \funcparam{key_proc} is the preauthentication data returned by the
KDC as part of the reply to the initial ticket request.  It may
contain an element of type KRB5_PADATA_PW_SALT, which
\funcparam{key_proc} should use to determine what salt to use when
generating the key.  \funcparam{key_proc} should fill in
\funcparam{key} with a key for the client, or return an error code.

\funcparam{decrypt_proc} is called to perform the decryption of the
response (the encrypted part is in
\funcparam{dec_rep{\ptsto}enc_part}; the decrypted part should be
allocated and filled into
\funcparam{dec_rep{\ptsto}enc_part2}.
\funcparam{decryptarg} is passed on to \funcparam{decrypt_proc}, and
its content depends on the \funcparam{decrypt_proc} being used.

If \funcparam{addrs} is non-NULL, it is used for the addresses
requested.  If it is null, the system standard addresses are used.

If \funcparam{ret_as_reply} is non-NULL, it is filled in with a
pointer to a structure containing the reply packet from the KDC.  Some
programs may find it useful to have direct access to this information.
For example, it can be used to obtain the pre-authentication data
passed back from the KDC.  The caller is responsible for freeing this
structure by using \funcname{krb5_free_kdc_rep}.

If \funcparam{etypes} is non-NULL, the it is used as for the list of
valid encyrption types. Otherwise, the context default is used (as
returned by \funcname{krb5_get_default_in_tkt_etypes}.

A succesful call will place the ticket in the credentials cache
\funcparam{ccache} and fill in \funcparam{creds} with the ticket
information used/returned.

Returns system errors, preauthentication errors, encryption errors.

% XXX Right now, uses creds->addresses before it's copied into from
% the reply -- it's passed to krb5_obtain_padata.  I think that's
% wrong, and it should be using either addrs or the result of
% krb5_os_localaddr instead.  If I'm wrong, then this spec has to be
% updated to document that creds->addresses is used.  On the other
% hand, if I'm right, then the bug in get_in_tkt needs to be fixed.
% See ov-cambridge PR 1525.

\begin{funcdecl}{krb5_get_in_tkt_with_password}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_flags}{options}
\funcarg{krb5_address * const *}{addrs}
\funcarg{const krb5_enctype *}{etypes}
\funcarg{const krb5_preauthtype *}{pre_auth_types}
\funcarg{const char *}{password}
\funcarg{krb5_ccache}{ccache}
\funcinout
\funcarg{krb5_creds *}{creds}
\funcarg{krb5_kdc_rep **}{ret_as_reply}
\end{funcdecl}

Attempts to get an initial ticket using the null-terminated string
\funcparam{password}.  If \funcparam{password} is NULL, the password
is read from the terminal using as a prompt the globalname
\globalname{krb5_default_pwd_prompt1}.  

The password is converted into a key using the appropriate
string-to-key conversion function for the specified
\funcparam{keytype}, and using any salt data returned by the KDC in
response to the authentication request.

See \funcname{krb5_get_in_tkt} for documentation of the
\funcparam{options}, \funcparam{addrs}, \funcparam{pre_auth_type},
\funcparam{etype}, \funcparam{keytype}, \funcparam{ccache},
\funcparam{creds} and \funcparam{ret_as_reply} arguments.

Returns system errors, preauthentication errors, encryption errors.

\begin{funcdecl}{krb5_get_in_tkt_with_keytab}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_flags}{options}
\funcarg{krb5_address * const *}{addrs}
\funcarg{const krb5_enctype *}{etypes}
\funcarg{const krb5_preauthtype *}{pre_auth_types}
\funcarg{const krb5_keytab *}{keytab}
\funcarg{krb5_ccache}{ccache}
\funcinout
\funcarg{krb5_creds *}{creds}
\funcarg{krb5_kdc_rep **}{ret_as_reply}
\end{funcdecl}

Attempts to get an initial ticket using \funcparam{keytab}.  If
\funcparam{keytab} is NULL, the default keytab is used 
(e.g., \filename{/etc/v5srvtab}).

See \funcname{krb5_get_in_tkt} for documentation of the
\funcparam{options}, \funcparam{addrs}, \funcparam{pre_auth_type},
\funcparam{etype}, \funcparam{ccache}, \funcparam{creds} and
\funcparam{ret_as_reply} arguments.

Returns system errors, preauthentication errors, encryption errors.

\begin{funcdecl}{krb5_get_in_tkt_with_skey}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_flags}{options}
\funcarg{krb5_address * const *}{addrs}
\funcarg{const krb5_enctype *}{etypes}
\funcarg{const krb5_preauthtype *}{pre_auth_types}
\funcarg{const krb5_keyblock *}{key}
\funcarg{krb5_ccache}{ccache}
\funcinout
\funcarg{krb5_creds *}{creds}
\funcarg{krb5_kdc_rep **}{ret_as_reply}
\end{funcdecl}

Attempts to get an initial ticket using \funcparam{key}.  If
\funcparam{key} is NULL, an appropriate key is retrieved from the
system key store (e.g., \filename{/etc/v5srvtab}).

See \funcname{krb5_get_in_tkt} for documentation of the
\funcparam{options}, \funcparam{addrs}, \funcparam{pre_auth_type},
\funcparam{etype}, \funcparam{ccache}, \funcparam{creds} and
\funcparam{ret_as_reply} arguments.

Returns system errors, preauthentication errors, encryption errors.

\begin{funcdecl}{krb5_mk_req}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context *}{auth_context}
\funcin
\funcarg{const krb5_flags}{ap_req_options}
\funcarg{char *}{service}
\funcarg{char *}{hostname}
\funcarg{krb5_data *}{in_data}
\funcinout
\funcarg{krb5_ccache}{ccache}
\funcout
\funcarg{krb5_data *}{outbuf}
\end{funcdecl}

Formats a KRB_AP_REQ message into \funcparam{outbuf}.

The server to receive the message is specified by
\funcparam{hostname}. The principal of the server to receive the message
is specified by \funcparam{hostname} and \funcparam{service}.
If credentials are not present in the credentials cache
\funcparam{ccache} for this server, the TGS request with default
parameters is used in an attempt to obtain such credentials, and they
are stored in \funcparam{ccache}.

\funcparam{ap_req_options} specifies the KRB_AP_REQ options desired.
Valid options are:

\begin{tabular}{ll}
AP_OPTS_USE_SESSION_KEY&\\
AP_OPTS_MUTUAL_REQUIRED&\\
\end{tabular}
\label{ap-req-options}

The checksum method to be used is as specified in \funcparam{auth_context}. 

% XXX Not sure if it's legal in the protocol for no checksum to be
% included, or if so, how the server reacts to a request with no
% checksum.

\funcparam{outbuf} should point to an existing \datatype{krb5_data}
structure.  \funcparam{outbuf{\ptsto}length} and
\funcparam{outbuf{\ptsto}data} will be filled in on success, and the latter
should be freed by the caller when it is no longer needed; if an error
is returned, however, no storage is allocated and {\tt
outbuf{\ptsto}data} does not need to be freed.

Returns system errors, error getting credentials for
\funcparam{server}.

\begin{funcdecl}{krb5_mk_req_extended}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context *}{auth_context}
\funcin
\funcarg{const krb5_flags}{ap_req_options}
\funcarg{krb5_data *}{in_data}
\funcarg{krb5_creds *}{in_creds}
\funcout
\funcarg{krb5_data *}{outbuf}
\end{funcdecl}

Formats a KRB_AP_REQ message into \funcparam{outbuf}, with more complete
options than \funcname{krb5_mk_req}.

\funcparam{outbuf}, \funcparam{ap_req_options}, \funcparam{auth_context},
and \funcparam{ccache} are used in the same fashion as for
\funcname{krb5_mk_req}.

\funcparam{in_creds} is used to supply the credentials (ticket and session
key) needed to form the request.

If \funcparam{in_creds{\ptsto}ticket} has no data (length == 0), then an
error is returned. 

During this call, the structure elements in \funcparam{in_creds} may be
freed and reallocated.  Hence all of the structure elements which are
pointers should point to allocated memory, and there should be no other
pointers aliased to the same memory, since it may be deallocated during
this procedure call.


If \funcparam{ap_req_options} specifies AP_OPTS_USE_SUBKEY, then a
subkey will be generated if need be by \funcname{krb5_generate_subkey}.

A copy of the authenticator will be stored in the
\funcparam{auth_context}, with the principal and checksum fields nulled
out, unless an error is returned.  (This is to prevent pointer sharing
problems; the caller shouldn't need these fields anyway, since the
caller supplied them.)

Returns system errors, errors contacting the KDC, KDC errors getting
a new ticket for the authenticator.

\begin{funcdecl}{krb5_generate_subkey}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_keyblock *}{key}
\funcout
\funcarg{krb5_keyblock **}{subkey}
\end{funcdecl}

Generates a pseudo-random sub-session key using the encryption system's
random key functions, based on the input \funcparam{key}.

\funcparam{subkey} is filled in to point to the generated subkey, unless
an error is returned.  The returned key (i.e., \funcparam{*subkey}) is
allocated and should be freed by the caller with
\funcname{krb5_free_keyblock} when it is no longer needed.

\begin{funcdecl}{krb5_rd_req}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context *}{auth_context}
\funcin
\funcarg{const krb5_data *}{inbuf}
\funcarg{krb5_const_principal}{server}
\funcarg{krb5_keytab}{keytab}
\funcinout
\funcarg{krb5_flags *}{ap_req_options}
\funcout
\funcarg{krb5_ticket **}{ticket}
\end{funcdecl}

Parses a KRB_AP_REQ message, returning its contents.  Upon successful
return, if \funcparam{ticket} is non-NULL, \funcparam{*ticket} will be
modified to point to allocated storage containing the ticket
information.  The caller is responsible for deallocating this space by
using \funcname{krb5_free_ticket}.

\funcparam{inbuf} should contain the KRB_AP_REQ message to be parsed.

If \funcparam{auth_context} is NULL, one will be generated and freed
internally by the function.

\funcparam{server} specifies the expected server's name for the ticket.
If \funcparam{server} is NULL, then any server name will be accepted if
the appropriate key can be found, and the caller should verify that the
server principal matches some trust criterion.

If \funcparam{server} is not NULL, and a replay detaction cache has not been
established with the \funcparam{auth_context}, one will be generated. 

\funcparam{keytab} specifies a keytab containing generate a decryption key. If
NULL, \funcparam{krb5_kt_default} will be used to find the default 
keytab and the key taken from there\footnote{i.e., srvtab file in
Kerberos V4 parlance}.


If a keyblock is present in the \funcparam{auth_context}, it will be
used to decrypt the ticket request and the keyblock freed with
\funcname{krb5_free_keyblock}. This is useful for user to user
authentication. If no keyblock is specified, the \funcparam{keytab} is
consulted for an entry matching the requested keytype, server and
version number and used instead.

The authentcator in the request is decrypted and stored in the
\funcparam{auth_context}. The client specified in the decrypted
authenticator is compared to the client specified in the decoded ticket
to ensure that the compare.

If the remote_addr portion of the \funcparam{auth_context} is set, 
then this routine checks if the request came from the right client.

\funcparam{sender_addr} specifies the address(es) expected to be present
in the ticket.

The replay cache is checked to see if the ticket and authenticator have
been seen and if so, returns an error. If not, the ticket and
authenticator are entered into the cache.

Various other checks are made of the decoded data, including,
cross-realm policy, clockskew and ticket validation times.

The keyblock, subkey, and sequence number of the request are all stored
in the \funcparam{auth_context} for future use.

If the request has the AP_OPTS_MUTUAL_REQUIRED bit set, the local
sequence number, which is stored in the auth_context, is XORed with the
remote sequence number in the request.

If \funcparam{ap_req_options} is non-NULL, it will be set to contain the
application request flags.

Returns system errors, encryption errors, replay errors.

\begin{funcdecl}{krb5_rd_req_decoded}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context *}{auth_context}
\funcin
\funcarg{const krb5_ap_req *}{req}
\funcarg{krb5_const_principal}{server}
\funcinout
\funcarg{krb5_keytab}{keytab}
\funcout
\funcarg{krb5_ticket **}{ticket}
\end{funcdecl}

Essentially the same as \funcname{krb5_rd_req}, but uses a decoded AP_REQ
as the input rather than an encoded input.

\begin{funcdecl}{krb5_mk_rep}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\funcout
\funcarg{krb5_data *}{outbuf}
\end{funcdecl}

Formats and encrypts an AP_REP message, including in it the data in the
authentp portion of \funcparam{auth_context}, encrypted using the
keyblock portion of \funcparam{auth_context}. 

When successful, \funcparam{outbuf{\ptsto}length} and
\funcparam{outbuf{\ptsto}data} are filled in with the length of the
AP_REQ message and allocated data holding it.
\funcparam{outbuf{\ptsto}data} should be freed by the
caller when it is no longer needed. 

If the flags in \funcparam{auth_context} indicate that a sequence number
should be used (either {\sc KRB5_AUTH_CONTEXT_DO_SEQUENCE} or
{\sc KRB5_AUTH_CONTEXT_RET_SEQUENCE}) and the local sequqnce number in the
\funcparam{auth_context} is 0, a new number will be generated with
\funcname{krb5_generate_seq_number}.

Returns system errors.

\begin{funcdecl}{krb5_rd_rep}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\funcin
\funcarg{const krb5_data *}{inbuf}
\funcout
\funcarg{krb5_ap_rep_enc_part **}{repl}
\end{funcdecl}

Parses and decrypts an AP_REP message from \funcparam{*inbuf}, filling in
\funcparam{*repl} with a pointer to  allocated storage containing the
values from the message.  The caller is responsible for freeing this
structure with \funcname{krb5_free_ap_rep_enc_part}.

The keyblock stored in \funcparam{auth_context} is used to decrypt the
message after establishing any key pre-processing with
\funcname{krb5_process_key}. 

Returns system errors, encryption errors, replay errors.

\begin{funcdecl}{krb5_mk_error}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_error *}{dec_err}
\funcout
\funcarg{krb5_data *}{enc_err}
\end{funcdecl}

Formats the error structure \funcparam{*dec_err} into an error buffer
\funcparam{*enc_err}.

The error buffer storage (\funcparam{enc_err{\ptsto}data}) is
allocated, and should be freed by the caller when finished.

Returns system errors.

\begin{funcdecl}{krb5_rd_error}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_data *}{enc_errbuf}
\funcout
\funcarg{krb5_error **}{dec_error}
\end{funcdecl}

Parses an error protocol message from \funcparam{enc_errbuf} and fills in 
\funcparam{*dec_error} with a pointer to allocated storage containing
the error message.  The caller is reponsible for freeing this structure by
using \funcname{krb5_free_error}.

Returns system errors.

\begin{funcdecl}{krb5_generate_seq_number}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_keyblock *}{key}
\funcout
\funcarg{krb5_int32 *}{seqno}
\end{funcdecl}

Generates a pseudo-random sequence number suitable for use as an initial
sequence number for the KRB_SAFE and KRB_PRIV message processing
routines.

\funcparam{key} parameterizes the choice of the random sequence number,
which is filled into \funcparam{*seqno} upon return.

\begin{funcdecl}{krb5_sendauth}{krb5_error_code}
\funcinout
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context *}{auth_context}
\funcin
\funcarg{krb5_pointer}{fd}
\funcarg{char *}{appl_version}
\funcarg{krb5_principal}{client}
\funcarg{krb5_principal}{server}
\funcarg{krb5_flags}{ap_req_options}
\funcarg{krb5_data *}{in_data}
\funcarg{krb5_creds *}{in_creds}
\funcinout
\funcarg{krb5_ccache}{ccache}
\funcout
\funcarg{krb5_error **}{error}
\funcarg{krb5_ap_rep_enc_part **}{rep_result}
\funcarg{krb5_creds **}{out_creds}
\end{funcdecl}

\funcname{krb5_sendauth} provides a convenient means for client and
server programs to send authenticated messages to one another through
network connections.  \funcname{krb5_sendauth} sends an authenticated
ticket from the client program to the server program using the network
connection specified by \funcparam{fd}.  In the MIT Unix implementation,
\funcparam{fd} should be a pointer to a file descriptor describing the
network socket.  This can be changed in other implementations, however,
if the routines \funcname{krb5_read_message},
\funcname{krb5_write_message}, \funcname{krb5_net_read}, and
\funcname{krb5_net_write} are changed.

The paramter \funcparam{appl_version} is a string describing the
application protocol version which the client is expecting to use for
this exchange.  If the server is using a different application protocol,
an error will be returned.

The parameters \funcparam{client} and \funcparam{server} specify the
kerberos principals for the client and the server.  They are
ignored if \funcparam{in_creds} is non-null.  Otherwise,
\funcparam{server} must be non-null, but \funcparam{client} may be
null, in which case the client principal used is the one in the
credential cache's default principal.

The \funcparam{ap_req_options} parameters specifies the options which
should be passed to \funcname{krb5_mk_req}.  Valid options are listed
in Table \ref{ap-req-options}.  If \funcparam{ap_req_options}
specifies MUTUAL_REQUIRED, then \funcname{krb5_sendauth} will perform
a mutual authentication exchange, and if \funcparam{rep_result} is
non-null, it will be filled in with the result of the mutual
authentication exchange; the caller should free
\funcparam{*rep_result} with
\funcname{krb5_free_ap_rep_enc_part} when done with it.

If \funcparam{in_creds} is non-null, then
\funcparam{in_creds{\ptsto}client} and 
\funcparam{in_creds{\ptsto}server} must be filled in, and either
the other structure fields should be filled in with valid credentials,
or \funcparam{in_creds{\ptsto}ticket.length} should be zero.  If
\funcparam{in_creds{\ptsto}ticket.length} is non-zero, then
\funcparam{in_creds} will be used as-is as the credentials to send to
the server, and \funcparam{ccache} is ignored; otherwise,
\funcparam{ccache} is used as described below, and \funcparam{out_creds}
, if not NULL, is filled in with the retrieved credentials.

\funcname{ccache} specifies the credential cache to use when one is
needed (i.e., when \funcname{in_creds} is null or
\funcparam{in_creds{\ptsto}ticket.length} is zero).  When a credential
cache is not needed, \funcname{ccache} is ignored.  When a credential
cache is needed and \funcname{ccache} is null, the default credential
cache is used.  Note that if the credential cache is needed and does
not contain the needed credentials, they will be retrieved from the
KDC and stored in the credential cache.

If mutual authentication is used and \funcparam{rep_result} is non-null,
the sequence number for the server is available to the caller in
\funcparam{*rep_result->seq_number}.  (If mutual authentication is not
used, there is no way to negotiate a sequence number for the server.)

If an error occurs during the authenticated ticket exchange and
\funcparam{error} is non-null, the error packet (if any) that was sent
from the server will be placed in it.  This error should be freed with
\funcname{krb5_free_error}.

\begin{funcdecl}{krb5_recvauth}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context *}{auth_context}
\funcin
\funcarg{krb5_pointer}{fd}
\funcarg{char *}{appl_version}
\funcarg{krb5_principal}{server}
\funcarg{char *}{rc_type}
\funcarg{krb5_int32}{flags}
\funcarg{krb5_keytab}{keytab}
\funcout
\funcarg{krb5_ticket **}{ticket}
\end{funcdecl}

\funcname{krb5_recvauth} provides a convenient means for client and
server programs to send authenticated messages to one another through
network connections.  \funcname{krb5_sendauth} is the matching routine
to \funcname{krb5_recvauth} for the server.  \funcname{krb5_recvauth}
will engage in an authentication dialogue with the
client program running \funcname{krb5_sendauth} to authenticate the
client to the server.  In addition, if requested by the client,
\funcname{krb5_recvauth} will provide mutual authentication to
prove to the client that the server represented by
\funcname{krb5_recvauth} is legitimate. 

\funcparam{fd} is a pointer to the network connection.  As in
\funcname{krb5_sendauth}, in the MIT Unix implementation
\funcparam{fd} is a pointer to a file descriptor.

The parameter \funcparam{appl_version} is a string describing the
application protocol version which the server is expecting to use for
this exchange.  If the client is using a different application protocol,
an error will be returned and the authentication exchange will be
aborted.

If \funcparam{server} is non-null, then \funcname{krb5_recvauth}
verifies that the server principal requested by the client matches
\funcparam{server}.  If not, an error will be returned and the
authentication exchange will be aborted.

The parameters \funcparam{server}, \funcparam{auth_context},
and \funcparam{keytab} are used by \funcname{krb5_rd_req} to obtain the
server's private key.

If \funcparam{server} is non-null, the princicpal component of it is
ysed to determine the replay cache to use. Otherwise,
\funcname{krb5_recvauth} will use a default replay cache.

The \funcparam{flags} argument allows the caller to modify the behavior of
\funcname{krb5_recvauth}.  For non-library callers, \funcparam{flags}
should be 0. 

% XXX Note that if the bug I submitted entitled ``"flags" argument
% should not have been added to krb5_recvauth'' (OpenVision Cambridge
% bug number 1585) causes code changes, this will have to be updated.

\funcparam{ticket} is optional and is only filled in if non-null. It is
filled with the data from the ticket sent by the client, and should be
freed with
\funcname{krb5_free_ticket} when it is no longer needed.

\begin{funcdecl}{krb5_mk_safe}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\funcin
\funcarg{const krb5_data *}{userdata}
\funcout
\funcarg{krb5_data *}{outbuf}
\funcinout
\funcarg{krb5_replay_data *}{outdata}
\end{funcdecl}

Formats a KRB_SAFE message into \funcparam{outbuf}.

\funcparam{userdata} is formatted as the user data in the message.
Portions of \funcparam{auth_context} specify the checksum type; the
keyblockm which might be used to seed the checksum;
full addresses (host and port) for the sender and receiver.
The \funcparam{local_addr} portion of \funcparam{*auth_context} 
is used to form the addresses usedin the KRB_SAFE message. The  \funcparam{remote_addr} is optional; if the
receiver's address is not known, it may be replaced by NULL.
\funcparam{local_addr}, however, is mandatory.

The \funcparam{auth_context} flags select whether sequence numbers or
timestamps should be used to identify the message.  Valid flags are
listed below.

\begin{tabular}{ll}
\multicolumn{1}{c}{Symbol} & Meaning \\
KRB5_AUTH_CONTEXT_DO_TIME               & Use timestamps\\
        &\  and replay cache\\
KRB5_AUTH_CONTEXT_RET_TIME      & Copy timestamp \\
        &\ to \funcparam{*outdata} \\
KRB5_AUTH_CONTEXT_DO_SEQUENCE   & Use sequence numbers \\
KRB5_AUTH_CONTEXT_RET_SEQUENCE  & Copy sequence numbers\\
        &\ to \funcparam{*outdata} \\
\end{tabular}

If timestamps are to be used (i.e., if KRB5_AUTH_CONTEXT_DO_TIME is
set), an entry describing the message will be entered in the replay
cache so that the caller may detect if this message is sent
back to him by an attacker.  If KRB5_AUTH_CONTEXT_DO_TIME is not set,
the \funcparam{auth_context} replay cache is not used.

If sequence numbers are to be used (i.e., if either
KRB5_AUTH_CONTEXT_DO_SEQUENCE or KRB5_AUTH_CONTEXT_RET_SEQUENCE is
set), then \funcparam{auth_context} local sequence number will be
placed in the protected message as its sequence number.  

The \funcparam{outbuf} buffer storage (i.e.,
\funcparam{outbuf{\ptsto}data}) is allocated, and should be freed by
the caller when finished.

Returns system errors, encryption errors.

\begin{funcdecl}{krb5_rd_safe}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\funcin
\funcarg{const krb5_data *}{inbuf}
\funcout
\funcarg{krb5_data *}{outbuf}
\funcinout
\funcarg{krb5_replay_data *}{outdata}
\end{funcdecl}

Parses a KRB_SAFE message from \funcparam{inbuf}, placing the
data in \funcparam{*outbuf} after verifying its integrity.

The keyblock used for verifying the integrity of the message is taken
from the \funcparam{auth_context} recv\_subkey or keyblock. The
keyblock is chosen in the above order by the first one which is not
NULL.
 
The remote_addr and localaddr portions of the \funcparam{*auth_context}
specify the full addresses (host and port) of the sender and receiver,
and must be of type \datatype{ADDRTYPE_ADDRPORT}.


The \funcparam{remote_addr} parameter is mandatory; it
specifies the address of the sender.  If the address of the sender in
the message does not match \funcparam{remote_addr}, the error
KRB5KRB_AP_ERR_BADADDR will be returned.

If \funcparam{local_addr} is non-NULL, then the address of the receiver
in the message much match it.  If it is null, the receiver address in
the message will be checked against the list of local addresses as
returned by \funcname{krb5_os_localaddr}. If the check fails,
KRB5KRB_AP_ERR_BADARRD is returned.

The \funcparam{outbuf} buffer storage (i.e.,
\funcparam{outbuf{\ptsto}data} is allocated storage which the caller
should free when it is no longer needed.

If auth_context_flags portion of \funcparam{auth_context} indicates
that sequence numbers are to be used (i.e., if KRB5_AUTH_CONTEXT_DOSEQUENCE is
set in it), The \funcparam{remote_seq_number} portion of
\funcparam{auth_context} is compared to the sequence number for the
message, and KRB5_KRB_AP_ERR_BADORDER is returned if it does not match.
Otherwise, the sequence number is not used.


If timestamps are to be used (i.e., if KRB5_AUTH_CONTEXT_DO_TIME is set
in the \funcparam{auth_context}), then two additional checks are performed:
\begin{itemize}
\item The timestamp in the message must be within the permitted clock
        skew (which is usually five minutes), or KRB5KRB_AP_ERR_SKEW
        is returned.
\item The message must not be a replayed message, according to
        \funcparam{rcache}.
\end{itemize}

Returns system errors, integrity errors.

\begin{funcdecl}{krb5_mk_priv}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\funcin
\funcarg{const krb5_data *}{userdata}
\funcout
\funcarg{krb5_data *}{outbuf}
\funcarg{krb5_replay_data *}{outdata}
\end{funcdecl}

Formats a KRB_PRIV message into \funcparam{outbuf}.  Behaves similarly
to \funcname{krb5_mk_safe}, but the message is encrypted and
integrity-protected rather than just integrity-protected.

\funcparam{inbuf}, \funcparam{auth_context}, 
\funcparam{outdata} and
\funcparam{outbuf} function as in \funcname{krb5_mk_safe}.

As in \funcname{krb5_mk_safe}, the remote_addr and remote_port part of
the \funcparam{auth_context} is optional; if the receiver's address is
not known, it may be replaced by NULL.  The local_addr, however, is
mandatory.

The encryption type is taken from the \funcparam{auth_context} keyblock
portion. If i_vector portion of the \funcparam{auth_context}
is non-null, it is used as an initialization vector for the encryption
(if the chosen encryption type supports initialization vectors)
and its contents are replaced with the last block of encrypted data
upon return.

The flags from the \funcparam{auth_context} selects whether sequence numbers or timestamps
should be used to identify the message.  Valid flags are listed below.

\begin{tabular}{ll}
\multicolumn{1}{c}{Symbol} & Meaning \\
KRB5_AUTH_CONTEXT_DO_TIME& Use timestamps in replay cache\\
KRB5_AUTH_CONTEXT_RET_TIME& Use timestamps in output data\\
KRB5_AUTH_CONTEXT_DO_SEQUENCE& Use sequence numbers\\
        &\ in replay cache\\
KRB5_AUTH_CONTEXT_RET_SEQUENCE& Use sequence numbers\\
        &\ in replay cache and output data \\
\end{tabular}

Returns system errors, encryption errors.

\begin{funcdecl}{krb5_rd_priv}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcarg{krb5_auth_context}{auth_context}
\funcin
\funcarg{const krb5_data *}{inbuf}
\funcout
\funcarg{krb5_data *}{outbuf}
\funcarg{krb5_data *}{outdata}
\end{funcdecl}

Parses a KRB_PRIV message from \funcparam{inbuf}, placing the data in
\funcparam{*outbuf} after decrypting it.  Behaves similarly to
\funcname{krb5_rd_safe}, but the message is decrypted rather than
integrity-checked.

\funcparam{inbuf}, \funcparam{auth_context}, 
\funcparam{outdata} and \funcparam{outbuf}
function as in \funcname{krb5_rd_safe}.


The remote_addr part of the \funcparam{auth_context} as set by
\funcname{krb5_auth_con_setaddrs} is mandatory;  it
specifies the address of the sender.  If the address of the sender in
the message does not match the remote_addr, the error
KRB5KRB_AP_ERR_BADADDR will be returned.

If local_addr portion of the auth_context is non-NULL, then the address
of the receiver in the message much match it.  If it is null, the
receiver address in the message will be checked against the list of
local addresses as returned by \funcname{krb5_os_localaddr}.

The \funcparam{keyblock} portion of \funcparam{auth_context} specifies
the key to be used for decryption of the message.  If the
\funcparam{i_vector} element, is non-null, it is used as an
initialization vector for the decryption (if the encryption type of the
message supports initialization vectors) and its contents are replaced
with the last block of encrypted data in the message.

The \funcparam{auth_context} flags specify whether timestamps
(KRB5_AUTH_CONTEXT_DO_TIME) and sequence numbers
(KRB5_AUTH_CONTEXT_DO_SEQUENCE) are to be used.

Returns system errors, integrity errors.

\subsubsection{Miscellaneous main functions}

\begin{funcdecl}{krb5_address_search}{krb5_boolean}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_address *}{addr}
\funcarg{krb5_address * const *}{addrlist}
\end{funcdecl}

If \funcparam{addr} is listed in \funcparam{addrlist}, or
\funcparam{addrlist} is null, return TRUE.  If not listed, return FALSE.

\begin{funcdecl}{krb5_address_compare}{krb5_boolean}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_address *}{addr1}
\funcarg{const krb5_address *}{addr2}
\end{funcdecl}

If the two addresses are the same, return TRUE, else return FALSE.

\begin{funcdecl}{krb5_fulladdr_order}{int}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_fulladdr *}{addr1}
\funcarg{const krb5_fulladdr *}{addr2}
\end{funcdecl}

Return an ordering on the two full addresses:  0 if the same,
$< 0$ if first is less than 2nd, $> 0$ if first is greater than 2nd.

\begin{funcdecl}{krb5_address_order}{int}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_address *}{addr1}
\funcarg{const krb5_address *}{addr2}
\end{funcdecl}

Return an ordering on the two addresses:  0 if the same,
$< 0$ if first is less than 2nd, $> 0$ if first is greater than 2nd.

\begin{funcdecl}{krb5_copy_addresses}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{krb5_address * const *}{inaddr}
\funcout
\funcarg{krb5_address ***}{outaddr}
\end{funcdecl}

Copy addresses in \funcparam{inaddr} to \funcparam{*outaddr} which is
allocated memory and should be freed with \funcname{krb5_free_addresses}.

\begin{funcdecl}{krb5_copy_authdata}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{krb5_authdata * const *}{inauthdat}
\funcout
\funcarg{krb5_authdata ***}{outauthdat}
\end{funcdecl}

Copy an authdata structure, filling in \funcparam{*outauthdat} to point to the
newly allocated copy, which should be freed with 
\funcname{krb5_free_authdata}.

\begin{funcdecl}{krb5_copy_authenticator}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_authenticator *}{authfrom}
\funcout
\funcarg{krb5_authenticator **}{authto}
\end{funcdecl}

Copy an authenticator structure, filling in \funcparam{*outauthdat} to
point to the newly allocated copy, which should be freed with 
\funcname{krb5_free_authenticator}.

\begin{funcdecl}{krb5_copy_keyblock}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_keyblock *}{from}
\funcout
\funcarg{krb5_keyblock **}{to}
\end{funcdecl}

Copy a keyblock, filling in \funcparam{*to} to point to the newly
allocated copy, which should be freed with
\funcname{krb5_free_keyblock}. 

\begin{funcdecl}{krb5_copy_keyblock_contents}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_keyblock *}{from}
\funcout
\funcarg{krb5_keyblock *}{to}
\end{funcdecl}

Copy keyblock contents from \funcparam{from} to \funcparam{to}, including
allocated storage.  The allocated storage in \funcparam{to} should be
freed by using {\bf free}(\funcparam{to->contents}).

\begin{funcdecl}{krb5_copy_checksum}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_checksum *}{ckfrom}
\funcout
\funcarg{krb5_checksum **}{ckto}
\end{funcdecl}

Copy a checksum structure, filling in \funcparam{*ckto} to point to
the newly allocated copy, which should be freed with
\funcname{krb5_free_checksum}.

\begin{funcdecl}{krb5_copy_creds}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_creds *}{incred}
\funcout
\funcarg{krb5_creds **}{outcred}
\end{funcdecl}

Copy a credentials structure, filling in \funcparam{*outcred} to point
to the newly allocated copy, which should be freed with
\funcname{krb5_free_creds}.

\begin{funcdecl}{krb5_copy_data}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_data *}{indata}
\funcout
\funcarg{krb5_data **}{outdata}
\end{funcdecl}

Copy a data structure, filling in \funcparam{*outdata} to point to the
newly allocated copy, which should be freed with \funcname{krb5_free_data}.

\begin{funcdecl}{krb5_copy_ticket}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_ticket *}{from}
\funcout
\funcarg{krb5_ticket **}{pto}
\end{funcdecl}

Copy a ticket structure, filling in \funcparam{*pto} to point to
the newly allocated copy, which should be freed with
\funcname{krb5_free_ticket}.


\begin{funcdecl}{krb5_get_server_rcache}{krb5_error_code}{\funcinout}
\funcarg{krb5_context}{context}
\funcin
\funcarg{const krb5_data *}{piece}
\funcout
\funcarg{krb5_rcache *}{ret_rcache}
\end{funcdecl}

Generate a replay cache name, allocate space for its handle, and open
it.  \funcparam{piece} is used to distinguish this replay cache from
others currently in use on the system.  Typically, \funcparam{piece}
is the first component of the principal name for the client or server
which is calling \funcname{krb5_get_server_rcache}.

Upon successful return, \funcparam{ret_rcache} is filled in to contain a
handle to an open rcache, which should be closed with
\funcname{krb5_rc_close}.