2 * Copyright (c) 2001-2002 International Business Machines Corp.
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
9 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
10 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
11 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
12 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
13 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
14 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
15 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
16 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
17 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
18 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 #include <afs/param.h>
25 #include "org_openafs_jafs_Token.h"
28 #include <sys/ioctl.h>
30 #include <afs/venus.h>
31 #include <afs/afs_args.h>
32 /*#include <afs/afs_osi.h>
33 #include <afs/afs_usrops.h>*/
40 pthread_mutex_t jafs_init_lock;
42 extern pthread_mutex_t jafs_login_lock;
44 extern int readCacheParms(char *afsMountPoint, char *afsConfDir,
45 char *afsCacheDir, int *cacheBlocks,
46 int *cacheFiles, int *cacheStatEntries,
47 int *dCacheSize, int *vCacheSize, int *chunkSize,
48 int *closeSynch, int *debug, int *nDaemons,
49 int *cacheFlags, char *logFile);
52 * Be carefull with the memory management:
54 * - For every getNativeString call the corresponding free().
55 * - For every Get<type>ArrayElements call the corresponding
56 * Release<type>ArrayElements
57 * - For every malloc call the corresponding free.
66 JNIEXPORT void JNICALL
67 Java_org_openafs_jafs_Token_callDebugger(JNIEnv * env, jobject obj)
69 fprintf(stderr, "callDebugger called\n");
74 * Initialize the user space library.
76 * The user space client must be initialized prior to any
77 * user space related methods, including: klog, unlog, relog,
80 * env the Java environment
81 * cls the current Java class
85 JNIEXPORT void JNICALL
86 Java_org_openafs_jafs_Token_initUserSpace(JNIEnv * env, jclass cls)
88 char afsMountPoint[100], afsConfDir[100], afsCacheDir[100], logFile[100];
92 /* Initialize each init parameter with its associated default value */
93 int cacheBlocks = 100000;
94 int cacheFiles = 12500;
95 int cacheStatEntries = 8192;
96 int dCacheSize = 11398;
104 /* Initialize each init parameter with its associated default value */
105 strcpy(afsMountPoint, "/afs");
106 strcpy(afsConfDir, "/usr/afswsp/etc");
107 strcpy(afsCacheDir, "/usr/afswsp/cache");
108 strcpy(logFile, "/usr/afswsp/log/libjafs.log");
110 pthread_mutex_init(&jafs_init_lock, NULL);
111 pthread_mutex_lock(&jafs_init_lock);
113 readCacheParms(afsMountPoint, afsConfDir, afsCacheDir, &cacheBlocks,
114 &cacheFiles, &cacheStatEntries, &dCacheSize, &vCacheSize,
115 &chunkSize, &closeSynch, &debug, &nDaemons, &cacheFlags,
118 /* See cache.tune for configuration details */
120 fprintf(stderr, "uafs_Init(\"init_native\", \"%s\", \"%s\", \"%s\",
123 %d, %d, %d, %d, \"%s\");\n", afsMountPoint, afsConfDir, afsCacheDir, cacheBlocks, cacheFiles, cacheStatEntries, dCacheSize, vCacheSize, chunkSize, closeSynch, debug, nDaemons, cacheFlags, logFile);
125 uafs_Init("init_native", afsMountPoint, afsConfDir, afsCacheDir,
126 cacheBlocks, cacheFiles, cacheStatEntries, dCacheSize,
127 vCacheSize, chunkSize, closeSynch, debug, nDaemons, cacheFlags,
131 /* make the initial pag the unauthenticated pag */
134 pagval = afs_getpag_val();
136 fid = (*env)->GetStaticFieldID(env, cls, "ANYUSER_PAG_ID", "I");
139 "UserToken::init(): GetFieldID (ANYUSER_PAG_ID) failed\n");
143 (*env)->SetStaticIntField(env, cls, fid, pagval);
145 pthread_mutex_unlock(&jafs_init_lock);
149 * Authenticates a user in kas, and binds that authentication
150 * to the current process.
152 * env the Java environment
153 * obj the current Java class
154 * loginUTF the login to authenticate (expected as username@cellname)
155 * passwordUTF the password of the login
156 * id the existing pag (or 0)
158 * returns the assigned pag
160 * throws AFSException
162 JNIEXPORT jint JNICALL
163 Java_org_openafs_jafs_Token_klog(JNIEnv * env, jobject obj, jstring jusername,
164 jstring jpassword, jstring jcell, jint id)
174 cell = getNativeString(env, jcell);
176 fprintf(stderr, "UserToken::klog(): failed to get cell name\n");
177 throwMessageException(env,
178 "Internal error, failed to translate cell name.");
185 if (jusername != NULL) {
186 username = getNativeString(env, jusername);
190 fprintf(stderr, "UserToken::klog(): failed to get username\n");
191 throwMessageException(env,
192 "Internal error, failed to translate username.");
198 throwAFSException(env, JAFSNULLUSER);
202 if (jpassword != NULL) {
203 password = getNativeString(env, jpassword);
208 fprintf(stderr, "UserToken::klog(): failed to get password\n");
209 throwMessageException(env,
210 "Internal error, failed to translate password.");
217 throwAFSException(env, JAFSNULLPASS);
222 code = uafs_klog(username, cell, password, &reason);
224 /* Use existing PAG for this thread */
225 code = afs_setpag_val(id);
227 code = 180492L; /* KABADARGUMENT */
229 code = uafs_klog_nopag(username, cell, password, &reason);
235 if (username != NULL)
237 if (password != NULL)
240 "UserToken::klog(): uafs_klog failed to cell %s: %s\n", cell,
242 fprintf(stderr, "code = %d\n", code);
243 throwAFSException(env, code);
247 /* Get the PAG we were assigned as the return value */
248 rc = afs_getpag_val();
253 if (username != NULL)
255 if (password != NULL)
263 * Authenticates a user in KAS by a previously acquired PAG ID, and binds
264 * that authentication to the current thread or native process.
266 * <P> This method does not require the user's username and password to
267 * fully authenticate their request. Rather it utilizes the user's PAG ID
268 * to recapture the user's existing credentials.
270 * env the Java environment
271 * obj the current Java class
272 * id User's current PAG (process authentication group) ID
274 * throws AFSException
276 JNIEXPORT void JNICALL
277 Java_org_openafs_jafs_Token_relog(JNIEnv * env, jobject obj, jint id)
281 rc = afs_setpag_val(id);
284 throwAFSException(env, rc);
289 * Authenticates a user in KAS, and binds that authentication
290 * to the current process.
292 * env the Java environment
293 * obj the current Java class
295 * throws AFSException
297 JNIEXPORT void JNICALL
298 Java_org_openafs_jafs_Token_unlog(JNIEnv * env, jobject obj)
305 throwAFSException(env, rc);
310 * Inform the native library that the application is
311 * shutting down and will be unloading.
313 * <p> The library will make a call informing the file server that it will
314 * no longer be available for callbacks.
316 * env the Java environment
317 * obj the current Java class
319 * throws AFSException
321 JNIEXPORT void JNICALL
322 Java_org_openafs_jafs_Token_shutdown(JNIEnv * env, jobject obj)