Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / kauth / kaserver.h
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
9
10 /*
11 * Revision 2.1 1990/08/07 19:11:33
12 * Start with clean version to sync test and dev trees.
13 *
14 * Revision 1.11 89/02/10 11:56:23
15 * Added union to kaentry structure which allows overloading several
16 * fields depending on which type of user it is.
17 *
18 * Revision 1.10 89/02/02 14:24:22
19 * Removed calls to gethostid() which doesn't return IP address on Suns.
20 *
21 * Revision 1.9 88/12/22 14:43:48
22 * COUNT_REQ remembers name of last operation.
23 *
24 * Revision 1.8 88/12/09 14:42:00
25 * Greatly improved the external key version number management code.
26 * Added new entry type called kaOldKeys.
27 *
28 * Revision 1.7 88/11/22 09:30:40
29 * Change RPC statistics to be more robust.
30 *
31 * Revision 1.6 88/11/18 09:21:09
32 * Conversion to Rx and the new RxGen.
33 * Key version number is now a long.
34 * Conversion to use of <afs/auth.h> include file.
35 * Changed macros for statistics code since opcode hacking was punted.
36 *
37 * Revision 1.5 88/10/12 16:26:34
38 * Added much better (working) support of key version number maintenance.
39 *
40 * Revision 1.4 88/09/20 11:53:12
41 * Added IBM Copyright
42 *
43 * Revision 1.3 88/08/29 12:46:39
44 * This checks in several new modules and many updates. The AuthServer
45 * at this point works more or less as described in the NAFS document
46 * released in at the Aug 23-24 1988 workshop.
47 * Tickets are as described in the kerberos.ticket file.
48 * Intergrated w/ MIT's des implementation and the Andrew one-way password
49 * encryption. Uses bcrypt for RSECURE connections. Uses R not Rx.
50 *
51 * Revision 1.2 88/07/19 16:20:33
52 * Added GetEntry and ListEntry; other internal changes.
53 * */
54
55 #ifndef KADBVERSION
56 #define KADBVERSION 5 /* the database version */
57 #endif /* KADBVERSION */
58
59 #define HASHSIZE 8191 /* pick a prime for the length */
60
61 #define NULLO 0
62
63 /* all fields are stored in network (sun or rt) byte order */
64 struct kaheader {
65 afs_int32 version; /* database version number */
66 afs_int32 headerSize; /* bytes in header, for skipping in bad times */
67 afs_int32 freePtr; /* first (if any) free entry in freelist */
68 afs_int32 eofPtr; /* first free byte in file */
69 afs_int32 kvnoPtr; /* first special name old keys entry */
70 struct kasstats stats; /* track interesting statistics */
71 afs_int32 admin_accounts; /* total number of users w/ admin flag set */
72 afs_int32 specialKeysVersion; /* inc if special name gets new key */
73 afs_int32 hashsize; /* allocated size of nameHash */
74 #if (KADBVERSION > 5)
75 afs_int32 spare[10]; /* allocate some spares next time */
76 #endif
77 afs_int32 nameHash[HASHSIZE]; /* hash table for names */
78 afs_int32 checkVersion; /* database version number, same as first field */
79 };
80
81 #define ENTRYSIZE 200
82 #define KA_NPWSUMS (ENTRYSIZE - sizeof(kaident) - sizeof(struct ktc_encryptionKey) - 11*4)
83
84 /* all fields are stored in network byte order */
85 struct kaentry {
86 afs_int32 flags; /* random flags */
87 afs_int32 next; /* next block same entry (or freelist) */
88 Date user_expiration; /* user registration good till then */
89 Date modification_time; /* time of last update */
90 afs_int32 modification_id; /* identity of user doing update */
91 Date change_password_time; /* time user last changed own password */
92 afs_int32 max_ticket_lifetime; /* maximum lifetime for tickets */
93 afs_int32 key_version; /* verson number of this key */
94 union { /* overload several miscellaneous fields */
95 struct {
96 afs_int32 nOldKeys; /* number of outstanding old keys */
97 afs_int32 oldKeys; /* block containing old keys */
98 } asServer; /* for principals that are part of the AuthServer itself */
99 struct {
100 afs_int32 maxAssociates; /* associates this user can create */
101 afs_int32 nInstances; /* number of instances user's created */
102 } assocRoot; /* for principals at root of associate tree */
103 struct {
104 afs_int32 root; /* identity of this instance's root */
105 afs_int32 spare;
106 } associate; /* associate instance */
107 } misc;
108 /* put the strings last to simplify alignment calculations */
109 struct kaident userID; /* user and instance names */
110 struct ktc_encryptionKey key; /* the key to use */
111 unsigned char misc_auth_bytes[4]; /* expires, spare, attempts, locktime */
112 unsigned char pwsums[KA_NPWSUMS]; /* pad to 200 bytes */
113 };
114 typedef struct kaentry kaentry;
115
116 #define EXPIRES 0
117 #define REUSEFLAGS 1
118 #define ATTEMPTS 2
119 #define LOCKTIME 3
120
121 struct kaOldKey { /* each old key still remembered */
122 Date superseded; /* time this key replaced, or zero */
123 afs_int32 version; /* key's version */
124 struct ktc_encryptionKey key;
125 };
126 #define NOLDKEYS ((ENTRYSIZE-3*sizeof(afs_int32))/sizeof(struct kaOldKey))
127
128 struct kaOldKeys {
129 afs_int32 flags; /* random flags */
130 afs_int32 next; /* next block of old keys for all entries (or freelist) */
131 afs_int32 entry; /* corresponding user entry */
132 struct kaOldKey keys[NOLDKEYS]; /* each old key */
133 char padding[ENTRYSIZE -
134 ((NOLDKEYS * sizeof(struct kaOldKey)) +
135 3 * sizeof(afs_int32))];
136 };
137
138 #define COUNT_REQ(op) int *this_op = &dynamic_statistics.op.aborts; dynamic_statistics.op.requests++; lastOperation = # op
139 #define COUNT_ABO (*this_op)++
140
141 /* given the disk offset of a structure, the memory address of the structure
142 and the address of an item within the structure, compute the disk address of
143 this last item. */
144 #define DOFFSET(abase,astr,aitem) ((abase)+(((char *)(aitem)) - ((char *)(astr))))
145
146 /* given an index for an entry return its disk address */
147 #define IOFFSET(idx) (sizeof(kaentry)*(idx) + sizeof(cheader))
148
149 extern struct kaheader cheader;
150 extern struct kadstats dynamic_statistics;
151 extern afs_uint32 myHost;
152
153 extern int kaux_opendb(char *path);
154
155 extern void kaux_closedb(void
156 );
157
158 extern int kaux_read(afs_int32 to, unsigned int *nfailures,
159 afs_uint32 * lasttime);
160
161 extern int kaux_write(afs_int32 to, unsigned int nfailures,
162 afs_uint32 lasttime);
163
164 extern void kaux_inc(afs_int32 to, afs_uint32 locktime);
165
166 extern int kaux_islocked(afs_int32 to, u_int attempts, u_int locktime);
167
168 extern afs_int32 krb4_cross;
169
170 extern afs_int32 es_Report(char *fmt, ...)
171 AFS_ATTRIBUTE_FORMAT(__printf__, 1, 2);
172
173 #define LOCKPW