7fe21ddc201ae0d6885890340986bbd48657ae2e
[openafs.git] / src / auth / cellconfig.p.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 cellconfig.h:
12
13     Interface to the routines used by the FileServer to manipulate the cell/server database
14     for the Cellular Andrew system, along with an operation to determine the name of the
15     local cell.  Included are a string variable used to hold the local cell name, definitions for
16     the database file format and routines for:
17         1) Acquiring the local cell name.
18         2) Reading in the cell/server database from disk.
19         3) Reporting the set of servers associated with a given cell name.
20         4) Printing out the contents of the cell/server database.
21         5) Reclaiming the space used by an in-memory database.
22
23 Creation date:
24     17 August 1987
25
26 --------------------------------------------------------------------------------------------------------------*/
27
28 #ifndef __CELLCONFIG_AFS_INCL_
29 #define __CELLCONFIG_AFS_INCL_  1
30
31 #ifndef IPPROTO_MAX
32         /* get sockaddr_in */
33 #ifdef AFS_NT40_ENV
34 #include <winsock2.h>
35 #else
36 #include <sys/types.h>
37 #include <netinet/in.h>
38 #endif
39 #endif
40 #include <rx/rx_opaque.h>
41 #include <opr/queue.h>
42
43 #include <rx/rxgk_types.h>
44
45 #define MAXCELLCHARS    64
46 #define MAXHOSTCHARS    64
47 #define MAXHOSTSPERCELL  8
48
49 /*
50  * Return codes.
51  */
52 #define AFSCONF_SUCCESS   0     /* worked */
53
54 /*
55  * Complete server info for one cell.
56  */
57 struct afsconf_cell {
58     char name[MAXCELLCHARS];    /*Cell name */
59     short numServers;           /*Num active servers for the cell */
60     short flags;                /* useful flags */
61     struct sockaddr_in hostAddr[MAXHOSTSPERCELL];       /*IP addresses for cell's servers */
62     char hostName[MAXHOSTSPERCELL][MAXHOSTCHARS];       /*Names for cell's servers */
63     char clone[MAXHOSTSPERCELL];                        /*Indicates which ones are clones */
64     char *linkedCell;           /* Linked cell name, if any */
65     int timeout;                /* Data timeout, if non-zero */
66 };
67
68 #define AFSCONF_CELL_FLAG_DNS_QUERIED   1
69
70 struct afsconf_cellalias {
71     char aliasName[MAXCELLCHARS];
72     char realName[MAXCELLCHARS];
73 };
74
75 struct afsconf_entry {
76     struct afsconf_entry *next; /* next guy in afsconf_dir */
77     struct afsconf_cell cellInfo;       /* info for this cell */
78 };
79
80 struct afsconf_aliasentry {
81     struct afsconf_aliasentry *next;
82     struct afsconf_cellalias aliasInfo;
83 };
84
85 /*!
86  * A set of bit flags to control the selection of a security object
87  */
88 #define AFSCONF_SECOPTS_NOAUTH        0x1
89 #define AFSCONF_SECOPTS_LOCALAUTH     0x2
90 #define AFSCONF_SECOPTS_ALWAYSENCRYPT 0x4
91 #define AFSCONF_SECOPTS_FALLBACK_NULL 0x8
92 typedef afs_uint32 afsconf_secflags;
93
94 struct afsconf_dir {
95     char *name;                 /* pointer to dir prefix */
96     char *cellName;             /* cell name, if any, we're in */
97     char *cellservDB;           /* pathname of the CellServDB file */
98     struct afsconf_entry *entries;      /* list of cell entries */
99     struct opr_queue keyList;           /* list of keys */
100     afs_int32 timeRead;         /* time stamp of file last read */
101     afs_int32 timeCheck;        /* time of last check for update */
102     struct afsconf_aliasentry *alias_entries;   /* cell aliases */
103     afsconf_secflags securityFlags;
104     struct afsconf_realms *local_realms;        /* local realms */
105     struct afsconf_realms *exclusions;          /* excluded principals */
106 };
107
108 extern afs_int32 afsconf_FindService(const char *aname);
109 extern const char *afsconf_FindIANAName(const char *aname);
110 extern struct afsconf_dir *afsconf_Open(const char *adir);
111 extern int afsconf_CellApply(struct afsconf_dir *adir,
112                              int (*aproc) (struct afsconf_cell * cell,
113                                            void *arock,
114                                            struct afsconf_dir * dir),
115                              void *arock);
116 extern int afsconf_CellAliasApply(struct afsconf_dir *adir,
117                                   int (*aproc) (struct afsconf_cellalias *
118                                                 alias, void *arock,
119                                                 struct afsconf_dir * dir),
120                                   void *arock);
121 extern int afsconf_GetExtendedCellInfo(struct afsconf_dir *adir,
122                                        char *acellName, char *aservice,
123                                        struct afsconf_cell *acellInfo,
124                                        char clones[]);
125 extern int afsconf_GetAfsdbInfo(char *acellName, char *aservice,
126                                 struct afsconf_cell *acellInfo);
127 extern int afsconf_GetCellInfo(struct afsconf_dir *adir, char *acellName,
128                                char *aservice,
129                                struct afsconf_cell *acellInfo);
130 extern int afsconf_GetLocalCell(struct afsconf_dir *adir,
131                                 char *aname, afs_int32 alen);
132 extern int afsconf_Close(struct afsconf_dir *adir);
133 extern int afsconf_UpToDate(void *rock);
134
135 struct afsconf_keys;
136 extern int afsconf_GetKeys(struct afsconf_dir *adir,
137                            struct afsconf_keys *astr);
138
139 struct ktc_encryptionKey;
140 extern afs_int32 afsconf_GetLatestKey(struct afsconf_dir *adir,
141                                       afs_int32 * avno,
142                                       struct ktc_encryptionKey *akey);
143 extern afs_int32 afsconf_GetLatestRXGKKey(struct afsconf_dir *adir,
144                                           afs_int32 *avno, afs_int32 *enctype,
145                                           rxgk_key *key);
146 extern int afsconf_GetKey(void *rock, int avno,
147                           struct ktc_encryptionKey *akey);
148 extern int afsconf_GetRXGKKey(void *rock, afs_int32 *avno, afs_int32 *enctype,
149                               rxgk_key *key);
150 extern int afsconf_AddKey(struct afsconf_dir *adir, afs_int32 akvno,
151                           char akey[8], afs_int32 overwrite);
152 extern int afsconf_DeleteKey(struct afsconf_dir *adir, afs_int32 akvno);
153
154 struct afsconf_typedKey;
155 struct afsconf_typedKeyList {
156     int nkeys;
157     struct afsconf_typedKey **keys;
158 };
159
160 typedef enum {
161     afsconf_rxkad = 0,
162     afsconf_rxgk  =1,
163     afsconf_rxkad_krb5  =2
164 } afsconf_keyType;
165
166 extern struct afsconf_typedKey *
167         afsconf_typedKey_get(struct afsconf_typedKey *);
168 extern void afsconf_typedKey_put(struct afsconf_typedKey **);
169 extern struct afsconf_typedKey *
170         afsconf_typedKey_new(afsconf_keyType type, int kvno,
171                              int subType, struct rx_opaque *key);
172 extern void afsconf_typedKey_free(struct afsconf_typedKey **);
173
174 extern void afsconf_typedKey_values(struct afsconf_typedKey *key,
175                                   afsconf_keyType *type,
176                                   int *kvno,
177                                   int *minorType,
178                                   struct rx_opaque **keyMaterial);
179
180 extern int afsconf_GetAllKeys(struct afsconf_dir *,
181                               struct afsconf_typedKeyList **);
182 extern int afsconf_GetKeysByType(struct afsconf_dir *dir,
183                                  afsconf_keyType type, int kvno,
184                                  struct afsconf_typedKeyList **);
185 extern int afsconf_GetKeyByTypes(struct afsconf_dir *dir,
186                                  afsconf_keyType type, int kvno, int subType,
187                                  struct afsconf_typedKey **);
188 extern int afsconf_GetLatestKeysByType(struct afsconf_dir *dir,
189                                        afsconf_keyType type,
190                                        struct afsconf_typedKeyList **);
191 extern int afsconf_GetLatestKeyByTypes(struct afsconf_dir *dir,
192                                        afsconf_keyType type, int subType,
193                                        struct afsconf_typedKey **);
194 extern void afsconf_PutTypedKeyList(struct afsconf_typedKeyList **keys);
195 extern int afsconf_AddTypedKey(struct afsconf_dir *dir,
196                                struct afsconf_typedKey *key,
197                                int overwrite);
198 extern int afsconf_DeleteKeyByType(struct afsconf_dir *dir,
199                                    afsconf_keyType type, int kvno);
200 extern int afsconf_DeleteKeyBySubType(struct afsconf_dir *dir,
201                                       afsconf_keyType type, int kvno,
202                                       int subType);
203
204 /* authcon.c */
205 struct rx_securityClass;
206 extern afs_int32 afsconf_ServerAuth(void *arock,
207                                     struct rx_securityClass **,
208                                     afs_int32 *);
209 extern afs_int32 afsconf_ClientAuth(void *arock,
210                                     struct rx_securityClass **astr,
211                                     afs_int32 * aindex);
212 extern afs_int32 afsconf_ClientAuthSecure(void *arock,
213                                           struct rx_securityClass **astr,
214                                           afs_int32 * aindex);
215
216
217 extern afs_int32 afsconf_ClientAuthToken(struct afsconf_cell *info,
218                                          afsconf_secflags flags,
219                                          struct rx_securityClass **sc,
220                                          afs_int32 *scIndex,
221                                          time_t *expires);
222
223
224 extern afs_int32 afsconf_PickClientSecObj(struct afsconf_dir *dir,
225                                           afsconf_secflags flags,
226                                           struct afsconf_cell *info,
227                                           char *cellName,
228                                           struct rx_securityClass **sc,
229                                           afs_int32 *scIndex,
230                                           time_t *expires);
231
232 extern void afsconf_SetSecurityFlags(struct afsconf_dir *dir,
233                                      afsconf_secflags flags);
234
235 extern void afsconf_BuildServerSecurityObjects(void *,
236                                                struct rx_securityClass ***,
237                                                afs_int32 *);
238
239 /* writeconfig.c */
240 int afsconf_SetExtendedCellInfo(struct afsconf_dir *adir, const char *apath,
241                                 struct afsconf_cell *acellInfo, char clones[]);
242 int afsconf_SetCellInfo(struct afsconf_dir *adir, const char *apath,
243                         struct afsconf_cell *acellInfo);
244
245
246 /* userok.c */
247
248 struct rx_call;
249 struct rx_identity;
250 extern int afsconf_CheckAuth(void *arock, struct rx_call *acall);
251 extern int afsconf_GetNoAuthFlag(struct afsconf_dir *adir);
252 extern void afsconf_SetNoAuthFlag(struct afsconf_dir *adir, int aflag);
253 extern int afsconf_DeleteUser(struct afsconf_dir *adir, char *auser);
254 extern int afsconf_DeleteIdentity(struct afsconf_dir *, struct rx_identity *);
255 extern int afsconf_GetNthUser(struct afsconf_dir *adir, afs_int32 an,
256                               char *abuffer, afs_int32 abufferLen);
257 extern int afsconf_GetNthIdentity(struct afsconf_dir *, int,
258                                   struct rx_identity **);
259 extern int afsconf_AddUser(struct afsconf_dir *adir, char *aname);
260 extern int afsconf_AddIdentity(struct afsconf_dir *adir, struct rx_identity *);
261 extern int afsconf_SuperUser(struct afsconf_dir *adir, struct rx_call *acall,
262                              char *namep);
263 extern int afsconf_SuperIdentity(struct afsconf_dir *, struct rx_call *,
264                                  struct rx_identity **);
265 extern int afsconf_IsSuperIdentity(struct afsconf_dir *, struct rx_identity *);
266 extern int afsconf_CheckRestrictedQuery(struct afsconf_dir *adir,
267                                         struct rx_call *acall,
268                                         int needed_level);
269
270 /*
271  * Level constants for the -restricted_query option used by vlserver
272  * and volser.  Once we have vlserver and volserver to ptserver
273  * connection, we can add more access levels, like AUTHUSER or
274  * AUTHANDFOREIGNUSER.
275  */
276 #define RESTRICTED_QUERY_ANYUSER  0
277 #define RESTRICTED_QUERY_ADMIN    1
278
279 /* realms.c */
280 extern int afsconf_SetLocalRealm(const char *realm);
281 extern int afsconf_IsLocalRealmMatch(struct afsconf_dir *dir, afs_int32 * local,
282                                 const char *name, const char *instance,
283                                 const char *cell);
284
285 /* netrestrict.c */
286
287 extern int afsconf_ParseNetRestrictFile(afs_uint32 outAddrs[],
288                                         afs_uint32 * mask, afs_uint32 * mtu,
289                                         afs_uint32 maxAddrs, afs_uint32 * nAddrs,
290                                         char reason[], const char *fileName);
291
292 extern int afsconf_ParseNetFiles(afs_uint32 addrbuf[], afs_uint32 maskbuf[],
293                                  afs_uint32 mtubuf[], afs_uint32 max,
294                                  char reason[], const char *niFileName,
295                                  const char *nrFileName);
296
297 /* some well-known ports and their names; new additions to table in cellconfig.c, too */
298 #define AFSCONF_FILESERVICE             "afs"
299 #define AFSCONF_FILEPORT                7000
300 #define AFSCONF_CALLBACKSERVICE         "afscb"
301 #define AFSCONF_CALLBACKPORT            7001
302 #define AFSCONF_PROTSERVICE             "afsprot"
303 #define AFSCONF_PROTPORT                7002
304 #define AFSCONF_VLDBSERVICE             "afsvldb"
305 #define AFSCONF_VLDBPORT                7003
306 #define AFSCONF_KAUTHSERVICE            "afskauth"
307 #define AFSCONF_KAUTHPORT               7004
308 #define AFSCONF_VOLUMESERVICE           "afsvol"
309 #define AFSCONF_VOLUMEPORT              7005
310 #define AFSCONF_ERRORSERVICE            "afserror"
311 #define AFSCONF_ERRORPORT               7006
312 #define AFSCONF_NANNYSERVICE            "afsnanny"
313 #define AFSCONF_NANNYPORT               7007
314 #define AFSCONF_UPDATESERVICE           "afsupdate"
315 #define AFSCONF_UPDATEPORT              7008
316 #define AFSCONF_RMTSYSSERVICE           "afsrmtsys"
317 #define AFSCONF_RMTSYSPORT              7009
318 #define AFSCONF_RSDBSERVICE             "afsres"
319 #define AFSCONF_RESPORT                 7010
320 #define AFSCONF_REMIODBSERVICE          "afsremio"
321 #define AFSCONF_REMIOPORT               7011
322
323 #endif /* __CELLCONFIG_AFS_INCL_ */