Remove the RCSID macro
[openafs.git] / src / kauth / kalocalcell.c
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 #include <afsconfig.h>
11 #if defined(UKERNEL)
12 #include "afs/param.h"
13 #else
14 #include <afs/param.h>
15 #endif
16
17
18 #if defined(UKERNEL)
19 #include "afs/pthread_glock.h"
20 #include "afs/sysincludes.h"
21 #include "afsincludes.h"
22 #include "afs_usrops.h"
23 #include "afs/cellconfig.h"
24 #include "afs/pthread_glock.h"
25 #include "rx/xdr.h"
26 #include "rx/rx.h"
27 #include "afs/kauth.h"
28 #include "afs/kautils.h"
29 #include "afs/afsutil.h"
30 #else /* defined(UKERNEL) */
31 #include <afs/pthread_glock.h>
32 #include <sys/types.h>
33 #ifdef AFS_NT40_ENV
34 #include <winsock2.h>
35 #else
36 #include <netinet/in.h>
37 #endif
38 #include <string.h>
39 #include <afs/cellconfig.h>
40 #include <rx/xdr.h>
41 #include <rx/rx.h>
42 #include "kauth.h"
43 #include "kautils.h"
44 #include <afs/afsutil.h>
45 #endif /* defined(UKERNEL) */
46
47 /* This is a utility routine that many parts of kauth use but it invokes the
48    afsconf package so its best to have it in a separate .o file to make the
49    linker happy. */
50
51 static struct afsconf_dir *conf = 0;
52 static char cell_name[MAXCELLCHARS];
53
54 int
55 ka_CellConfig(const char *dir)
56 {
57     int code;
58 #ifdef UKERNEL
59     conf = afs_cdir;
60     strcpy(cell_name, afs_LclCellName);
61     return 0;
62 #else /* UKERNEL */
63     LOCK_GLOBAL_MUTEX;
64     if (conf)
65         afsconf_Close(conf);
66     conf = afsconf_Open(dir);
67     if (!conf) {
68         UNLOCK_GLOBAL_MUTEX;
69         return KANOCELLS;
70     }
71     code = afsconf_GetLocalCell(conf, cell_name, sizeof(cell_name));
72     UNLOCK_GLOBAL_MUTEX;
73     return code;
74 #endif /* UKERNEL */
75 }
76
77 char *
78 ka_LocalCell(void)
79 {
80     int code = 0;
81
82     LOCK_GLOBAL_MUTEX;
83     if (conf) {
84         UNLOCK_GLOBAL_MUTEX;
85         return cell_name;
86     }
87 #ifdef UKERNEL
88     conf = afs_cdir;
89     strcpy(cell_name, afs_LclCellName);
90 #else /* UKERNEL */
91     if ((conf = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH))) {
92         code = afsconf_GetLocalCell(conf, cell_name, sizeof(cell_name));
93 /* leave conf open so we can lookup other cells */
94 /* afsconf_Close (conf); */
95     }
96     if (!conf || code) {
97         printf("** Can't determine local cell name!\n");
98         conf = 0;
99         UNLOCK_GLOBAL_MUTEX;
100         return 0;
101     }
102 #endif /* UKERNEL */
103     UNLOCK_GLOBAL_MUTEX;
104     return cell_name;
105 }
106
107 int
108 ka_ExpandCell(char *cell, char *fullCell, int *alocal)
109 {
110     int local = 0;
111     int code;
112     char cellname[MAXKTCREALMLEN];
113     struct afsconf_cell cellinfo;       /* storage for cell info */
114
115     LOCK_GLOBAL_MUTEX;
116     ka_LocalCell();             /* initialize things */
117     if (!conf) {
118         UNLOCK_GLOBAL_MUTEX;
119         return KANOCELLS;
120     }
121
122     if ((cell == 0) || (strlen(cell) == 0)) {
123         local = 1;
124         cell = cell_name;
125     } else {
126         cell = lcstring(cellname, cell, sizeof(cellname));
127         code = afsconf_GetCellInfo(conf, cell, 0, &cellinfo);
128         if (code) {
129             UNLOCK_GLOBAL_MUTEX;
130             return KANOCELL;
131         }
132         cell = cellinfo.name;
133     }
134     if (strcmp(cell, cell_name) == 0)
135         local = 1;
136
137     if (fullCell)
138         strcpy(fullCell, cell);
139     if (alocal)
140         *alocal = local;
141     UNLOCK_GLOBAL_MUTEX;
142     return 0;
143 }
144
145 int
146 ka_CellToRealm(char *cell, char *realm, int *local)
147 {
148     int code = 0;
149
150     LOCK_GLOBAL_MUTEX;
151     code = ka_ExpandCell(cell, realm, local);
152     ucstring(realm, realm, MAXKTCREALMLEN);
153     UNLOCK_GLOBAL_MUTEX;
154     return code;
155 }