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