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