Initial import from FreeBSD RELENG_4:
[dragonfly.git] / crypto / kerberosIV / lib / krb / krb.h
1 /*
2  * $Id: krb.h,v 1.99 1999/11/16 14:02:47 bg Exp $
3  * $FreeBSD: src/crypto/kerberosIV/lib/krb/krb.h,v 1.6.2.2 2003/04/24 21:31:13 nectar Exp $
4  *
5  * Copyright 1987, 1988 by the Massachusetts Institute of Technology. 
6  *
7  * For copying and distribution information, please see the file
8  * <mit-copyright.h>. 
9  *
10  * Include file for the Kerberos library. 
11  */
12
13 #if !defined (__STDC__) && !defined(_MSC_VER)
14 #define const
15 #define signed
16 #endif
17
18 #include <sys/types.h>
19 #include <time.h>
20
21 #ifndef __KRB_H__
22 #define __KRB_H__
23
24 /* XXX */
25 #ifndef __BEGIN_DECLS
26 #if defined(__cplusplus)
27 #define __BEGIN_DECLS   extern "C" {
28 #define __END_DECLS     };
29 #else
30 #define __BEGIN_DECLS
31 #define __END_DECLS
32 #endif
33 #endif
34
35 #if defined (__STDC__) || defined (_MSC_VER)
36 #ifndef __P
37 #define __P(x) x
38 #endif
39 #else
40 #ifndef __P
41 #define __P(x) ()
42 #endif
43 #endif
44
45 __BEGIN_DECLS
46
47 /* Need some defs from des.h     */
48 #if !defined(NOPROTO) && !defined(__STDC__)
49 #define NOPROTO
50 #endif
51 #ifndef OPENSSL_DES_LIBDES_COMPATIBILITY
52 #define OPENSSL_DES_LIBDES_COMPATIBILITY
53 #endif
54 #include <openssl/des.h>
55
56 /* CNS compatibility ahead! */
57 #ifndef KRB_INT32
58 #define KRB_INT32 int32_t
59 #endif
60 #ifndef KRB_UINT32
61 #define KRB_UINT32 u_int32_t
62 #endif
63
64 /* Global library variables. */
65 extern int krb_ignore_ip_address; /* To turn off IP address comparison */
66 extern int krb_no_long_lifetimes; /* To disable AFS compatible lifetimes */
67 extern int krbONE;
68 #define         HOST_BYTE_ORDER (* (char *) &krbONE)
69 /* Debug variables */
70 extern int krb_debug;
71 extern int krb_ap_req_debug;
72 extern int krb_dns_debug;
73
74
75 /* Text describing error codes */
76 #define         MAX_KRB_ERRORS  256
77 extern const char *krb_err_txt[MAX_KRB_ERRORS];
78
79 /* General definitions */
80 #define         KSUCCESS        0
81 #define         KFAILURE        255
82
83 /*
84  * Kerberos specific definitions 
85  *
86  * KRBLOG is the log file for the kerberos master server. KRB_CONF is
87  * the configuration file where different host machines running master
88  * and slave servers can be found. KRB_MASTER is the name of the
89  * machine with the master database.  The admin_server runs on this
90  * machine, and all changes to the db (as opposed to read-only
91  * requests, which can go to slaves) must go to it. KRB_HOST is the
92  * default machine * when looking for a kerberos slave server.  Other
93  * possibilities are * in the KRB_CONF file. KRB_REALM is the name of
94  * the realm. 
95  */
96
97 /* /etc/kerberosIV is only for backwards compatibility, don't use it! */
98 #ifndef KRB_CONF
99 #define KRB_CONF        "/etc/kerberosIV/krb.conf"
100 #endif
101 #ifndef KRB_RLM_TRANS
102 #define KRB_RLM_TRANS   "/etc/kerberosIV/krb.realms"
103 #endif
104 #ifndef KRB_CNF_FILES
105 #define KRB_CNF_FILES   { KRB_CONF,   "/etc/krb.conf", 0}
106 #endif
107 #ifndef KRB_RLM_FILES
108 #define KRB_RLM_FILES   { KRB_RLM_TRANS, "/etc/krb.realms", 0}
109 #endif
110 #ifndef KRB_EQUIV
111 #define KRB_EQUIV       "/etc/kerberosIV/krb.equiv"
112 #endif
113 #define KRB_MASTER      "kerberos"
114 #ifndef KRB_REALM
115 #define KRB_REALM       (krb_get_default_realm())
116 #endif
117
118 /* The maximum sizes for aname, realm, sname, and instance +1 */
119 #define         ANAME_SZ        40
120 #define         REALM_SZ        40
121 #define         SNAME_SZ        40
122 #define         INST_SZ         40
123 /* Leave space for quoting */
124 #define         MAX_K_NAME_SZ   (2*ANAME_SZ + 2*INST_SZ + 2*REALM_SZ - 3)
125 #define         KKEY_SZ         100
126 #define         VERSION_SZ      1
127 #define         MSG_TYPE_SZ     1
128 #define         DATE_SZ         26      /* RTI date output */
129
130 #define MAX_HSTNM 100 /* for compatibility */
131
132 typedef struct krb_principal{
133     char name[ANAME_SZ];
134     char instance[INST_SZ];
135     char realm[REALM_SZ];
136 }krb_principal;
137
138 #ifndef DEFAULT_TKT_LIFE        /* allow compile-time override */
139 /* default lifetime for krb_mk_req & co., 10 hrs */
140 #define DEFAULT_TKT_LIFE 120
141 #endif
142
143 #define         KRB_TICKET_GRANTING_TICKET      "krbtgt"
144
145 /* Definition of text structure used to pass text around */
146 #define         MAX_KTXT_LEN    1250
147
148 struct ktext {
149     unsigned int length;                /* Length of the text */
150     unsigned char dat[MAX_KTXT_LEN];    /* The data itself */
151     u_int32_t mbz;              /* zero to catch runaway strings */
152 };
153
154 typedef struct ktext *KTEXT;
155 typedef struct ktext KTEXT_ST;
156
157
158 /* Definitions for send_to_kdc */
159 #define CLIENT_KRB_TIMEOUT      4       /* default time between retries */
160 #define CLIENT_KRB_RETRY        5       /* retry this many times */
161 #define CLIENT_KRB_BUFLEN       512     /* max unfragmented packet */
162
163 /* Definitions for ticket file utilities */
164 #define R_TKT_FIL       0
165 #define W_TKT_FIL       1
166
167 /* Parameters for rd_ap_req */
168 /* Maximum alloable clock skew in seconds */
169 #define         CLOCK_SKEW      5*60
170 /* Filename for readservkey */
171 #ifndef         KEYFILE
172 #define         KEYFILE         (krb_get_default_keyfile())
173 #endif
174
175 /* Structure definition for rd_ap_req */
176
177 struct auth_dat {
178     unsigned char k_flags;      /* Flags from ticket */
179     char    pname[ANAME_SZ];    /* Principal's name */
180     char    pinst[INST_SZ];     /* His Instance */
181     char    prealm[REALM_SZ];   /* His Realm */
182     u_int32_t checksum;         /* Data checksum (opt) */
183     des_cblock session;         /* Session Key */
184     int     life;               /* Life of ticket */
185     u_int32_t time_sec;         /* Time ticket issued */
186     u_int32_t address;          /* Address in ticket */
187     KTEXT_ST reply;             /* Auth reply (opt) */
188 };
189
190 typedef struct auth_dat AUTH_DAT;
191
192 /* Structure definition for credentials returned by get_cred */
193
194 struct credentials {
195     char    service[ANAME_SZ];  /* Service name */
196     char    instance[INST_SZ];  /* Instance */
197     char    realm[REALM_SZ];    /* Auth domain */
198     des_cblock session;         /* Session key */
199     int     lifetime;           /* Lifetime */
200     int     kvno;               /* Key version number */
201     KTEXT_ST ticket_st;         /* The ticket itself */
202     int32_t    issue_date;      /* The issue time */
203     char    pname[ANAME_SZ];    /* Principal's name */
204     char    pinst[INST_SZ];     /* Principal's instance */
205 };
206
207 typedef struct credentials CREDENTIALS;
208
209 /* Structure definition for rd_private_msg and rd_safe_msg */
210
211 struct msg_dat {
212     unsigned char *app_data;    /* pointer to appl data */
213     u_int32_t app_length;       /* length of appl data */
214     u_int32_t hash;             /* hash to lookup replay */
215     int     swap;               /* swap bytes? */
216     int32_t    time_sec;                /* msg timestamp seconds */
217     unsigned char time_5ms;     /* msg timestamp 5ms units */
218 };
219
220 typedef struct msg_dat MSG_DAT;
221
222 struct krb_host {
223     char *realm;
224     char *host;
225     enum krb_host_proto { PROTO_UDP, PROTO_TCP, PROTO_HTTP } proto;
226     int port;
227     int admin;
228 };
229
230 /* Location of ticket file for save_cred and get_cred */
231 #define TKT_FILE        tkt_string()
232 #ifndef TKT_ROOT
233 #define TKT_ROOT        (krb_get_default_tkt_root())
234 #endif
235
236 /* Error codes returned from the KDC */
237 #define         KDC_OK          0       /* Request OK */
238 #define         KDC_NAME_EXP    1       /* Principal expired */
239 #define         KDC_SERVICE_EXP 2       /* Service expired */
240 #define         KDC_AUTH_EXP    3       /* Auth expired */
241 #define         KDC_PKT_VER     4       /* Protocol version unknown */
242 #define         KDC_P_MKEY_VER  5       /* Wrong master key version */
243 #define         KDC_S_MKEY_VER  6       /* Wrong master key version */
244 #define         KDC_BYTE_ORDER  7       /* Byte order unknown */
245 #define         KDC_PR_UNKNOWN  8       /* Principal unknown */
246 #define         KDC_PR_N_UNIQUE 9       /* Principal not unique */
247 #define         KDC_NULL_KEY   10       /* Principal has null key */
248 #define         KDC_GEN_ERR    20       /* Generic error from KDC */
249
250
251 /* Values returned by get_credentials */
252 #define         GC_OK           0       /* Retrieve OK */
253 #define         RET_OK          0       /* Retrieve OK */
254 #define         GC_TKFIL       21       /* Can't read ticket file */
255 #define         RET_TKFIL      21       /* Can't read ticket file */
256 #define         GC_NOTKT       22       /* Can't find ticket or TGT */
257 #define         RET_NOTKT      22       /* Can't find ticket or TGT */
258
259
260 /* Values returned by mk_ap_req  */
261 #define         MK_AP_OK        0       /* Success */
262 #define         MK_AP_TGTEXP   26       /* TGT Expired */
263
264 /* Values returned by rd_ap_req */
265 #define         RD_AP_OK        0       /* Request authentic */
266 #define         RD_AP_UNDEC    31       /* Can't decode authenticator */
267 #define         RD_AP_EXP      32       /* Ticket expired */
268 #define         RD_AP_NYV      33       /* Ticket not yet valid */
269 #define         RD_AP_REPEAT   34       /* Repeated request */
270 #define         RD_AP_NOT_US   35       /* The ticket isn't for us */
271 #define         RD_AP_INCON    36       /* Request is inconsistent */
272 #define         RD_AP_TIME     37       /* delta_t too big */
273 #define         RD_AP_BADD     38       /* Incorrect net address */
274 #define         RD_AP_VERSION  39       /* protocol version mismatch */
275 #define         RD_AP_MSG_TYPE 40       /* invalid msg type */
276 #define         RD_AP_MODIFIED 41       /* message stream modified */
277 #define         RD_AP_ORDER    42       /* message out of order */
278 #define         RD_AP_UNAUTHOR 43       /* unauthorized request */
279
280 /* Values returned by get_pw_tkt */
281 #define         GT_PW_OK        0       /* Got password changing tkt */
282 #define         GT_PW_NULL     51       /* Current PW is null */
283 #define         GT_PW_BADPW    52       /* Incorrect current password */
284 #define         GT_PW_PROT     53       /* Protocol Error */
285 #define         GT_PW_KDCERR   54       /* Error returned by KDC */
286 #define         GT_PW_NULLTKT  55       /* Null tkt returned by KDC */
287
288
289 /* Values returned by send_to_kdc */
290 #define         SKDC_OK         0       /* Response received */
291 #define         SKDC_RETRY     56       /* Retry count exceeded */
292 #define         SKDC_CANT      57       /* Can't send request */
293
294 /*
295  * Values returned by get_intkt
296  * (can also return SKDC_* and KDC errors)
297  */
298
299 #define         INTK_OK         0       /* Ticket obtained */
300 #define         INTK_W_NOTALL  61       /* Not ALL tickets returned */
301 #define         INTK_BADPW     62       /* Incorrect password */
302 #define         INTK_PROT      63       /* Protocol Error */
303 #define         INTK_ERR       70       /* Other error */
304
305 /* Values returned by get_adtkt */
306 #define         AD_OK           0       /* Ticket Obtained */
307 #define         AD_NOTGT       71       /* Don't have tgt */
308 #define         AD_INTR_RLM_NOTGT 72    /* Can't get inter-realm tgt */
309
310 /* Error codes returned by ticket file utilities */
311 #define         NO_TKT_FIL      76      /* No ticket file found */
312 #define         TKT_FIL_ACC     77      /* Couldn't access tkt file */
313 #define         TKT_FIL_LCK     78      /* Couldn't lock ticket file */
314 #define         TKT_FIL_FMT     79      /* Bad ticket file format */
315 #define         TKT_FIL_INI     80      /* tf_init not called first */
316
317 /* Error code returned by kparse_name */
318 #define         KNAME_FMT       81      /* Bad Kerberos name format */
319
320 /* Error code returned by krb_mk_safe */
321 #define         SAFE_PRIV_ERROR -1      /* syscall error */
322
323 /* Defines for krb_sendauth and krb_recvauth */
324
325 #define KOPT_DONT_MK_REQ 0x00000001 /* don't call krb_mk_req */
326 #define KOPT_DO_MUTUAL   0x00000002 /* do mutual auth */
327
328 #define KOPT_DONT_CANON  0x00000004 /*
329                                      * don't canonicalize inst as
330                                      * a hostname
331                                      */
332
333 #define KOPT_IGNORE_PROTOCOL 0x0008
334
335 #define KRB_SENDAUTH_VLEN 8         /* length for version strings */
336
337
338 /* flags for krb_verify_user() */
339 #define KRB_VERIFY_NOT_SECURE   0
340 #define KRB_VERIFY_SECURE       1
341 #define KRB_VERIFY_SECURE_FAIL  2
342
343 extern char *krb4_version;
344
345 typedef int (*key_proc_t) __P((const char *name,
346                                char *instance, /* INOUT parameter */
347                                const char *realm,
348                                const void *password,
349                                des_cblock *key));
350
351 typedef int (*decrypt_proc_t) __P((const char *name,
352                                    const char *instance,
353                                    const char *realm,
354                                    const void *arg, 
355                                    key_proc_t,
356                                    KTEXT *));
357
358 #include "krb-protos.h"
359
360 __END_DECLS
361
362 #endif /* __KRB_H__ */