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.
23 #include "org_openafs_jafs_Cell.h"
24 #include "org_openafs_jafs_Token.h"
27 #include <afs_kasAdmin.h>
28 #include <afs_ptsAdmin.h>
29 #include <afs_clientAdmin.h>
31 #include <cellconfig.h>
32 #include <afs_AdminClientErrors.h>
35 * Static function used to initialize the client library and the
38 * env the Java environment
39 * obj the current Java object
41 JNIEXPORT void JNICALL
42 Java_org_openafs_jafs_Token_initializeAdminClient(JNIEnv * env, jclass cls)
45 if (!afsclient_Init(&ast)) {
46 throwAFSException(env, ast);
53 * Authenticates the given user and password in the cell. Returns
54 * a token that can be used to prove this authentication later.
56 * env the Java environment
57 * obj the current Java object
58 * jcellName the name of the cell in which to authenticate this user
59 * juserName the name of the user to authenticate
60 * jpassword the password of the user
61 * returns a token representing the authentication
63 JNIEXPORT jint JNICALL
64 Java_org_openafs_jafs_Token_getToken(JNIEnv * env, jobject obj,
65 jstring jcellName, jstring juserName,
75 // convert java strings
76 if (jcellName != NULL) {
77 cellName = getNativeString(env, jcellName);
79 throwAFSException(env, JAFSADMNOMEM);
86 if (juserName != NULL) {
87 userName = getNativeString(env, juserName);
91 throwAFSException(env, JAFSADMNOMEM);
97 throwAFSException(env, JAFSNULLUSER);
101 if (jpassword != NULL) {
102 password = getNativeString(env, jpassword);
104 if (cellName != NULL)
107 throwAFSException(env, JAFSADMNOMEM);
111 if (cellName != NULL)
114 throwAFSException(env, JAFSNULLPASS);
119 (afsclient_TokenGetNew
120 (cellName, userName, password, &tokenHandle, &ast))) {
121 throwAFSException(env, ast);
124 if (cellName != NULL)
129 return (jint) tokenHandle;
133 * Closes the given currently open token.
135 * env the Java environment
136 * obj the current Java object
137 * tokenHandle the token to close
139 JNIEXPORT void JNICALL
140 Java_org_openafs_jafs_Token_close(JNIEnv * env, jobject obj, jint tokenHandle)
144 if (!afsclient_TokenClose((void *)tokenHandle, &ast)) {
145 throwAFSException(env, ast);
151 * Opens a cell for administrative use, based on the token provided.
152 * Returns a cell handle to be used by other methods as a means of
155 * env the Java environment
156 * obj the current Java object
157 * jcellName the name of the cell for which to get the handle
158 * tokenHandle a token handle previously returned by a call to getToken
159 * returns a handle to the open cell
161 JNIEXPORT jint JNICALL
162 Java_org_openafs_jafs_Cell_getCellHandle(JNIEnv * env, jobject obj,
163 jstring jcellName, jint tokenHandle)
169 if (jcellName != NULL) {
170 cellName = getNativeString(env, jcellName);
172 throwAFSException(env, JAFSADMNOMEM);
176 throwAFSException(env, JAFSNULLCELL);
180 if (!afsclient_CellOpen(cellName, (void *)tokenHandle, &cellHandle, &ast)) {
181 throwAFSException(env, ast);
186 return (jint) cellHandle;
190 * Closes the given currently open cell handle.
192 * env the Java environment
193 * obj the current Java object
194 * cellHandle the cell handle to close
196 JNIEXPORT void JNICALL
197 Java_org_openafs_jafs_Cell_closeCell(JNIEnv * env, jobject obj,
202 if (!afsclient_CellClose((void *)cellHandle, &ast)) {
203 throwAFSException(env, ast);
209 * Opens a server for administrative vos use, based on the cell handle
210 * provided. Returns a vos server handle to be used by other
211 * methods as a means of identification.
213 * env the Java environment
214 * obj the current Java object
215 * cellHandle a cell handle previously returned by
216 * a call to getCellHandle
217 * jserverName the name of the server for which to retrieve
219 * returns a vos handle to the server
221 JNIEXPORT jint JNICALL
222 Java_org_openafs_jafs_Server_getVosServerHandle(JNIEnv * env, jobject obj,
230 if (jserverName != NULL) {
231 serverName = getNativeString(env, jserverName);
233 throwAFSException(env, JAFSADMNOMEM);
237 throwAFSException(env, JAFSNULLSERVER);
242 ((void *)cellHandle, serverName, (void **)&serverHandle, &ast)) {
243 throwAFSException(env, ast);
245 // release converted string
248 return (jint) serverHandle;
252 * Closes the given currently open vos server handle.
254 * env the Java environment
255 * obj the current Java object
256 * vosServerHandle the vos server handle to close
258 JNIEXPORT void JNICALL
259 Java_org_openafs_jafs_Server_closeVosServerHandle(JNIEnv * env, jobject obj,
260 jint vosServerHandle)
264 if (!vos_ServerClose((void *)vosServerHandle, &ast)) {
265 throwAFSException(env, ast);
271 * Opens a server for administrative bos use, based on the cell handle
272 * provided. Returns a bos server handle to be used by other methods
273 * as a means of identification.
275 * env the Java environment
276 * obj the current Java object
277 * cellHandle a cell handle previously returned by a call
279 * jserverName the name of the server for which to retrieve
281 * returns a bos handle to the server
283 JNIEXPORT jint JNICALL
284 Java_org_openafs_jafs_Server_getBosServerHandle(JNIEnv * env, jobject obj,
292 if (jserverName != NULL) {
293 serverName = getNativeString(env, jserverName);
295 throwAFSException(env, JAFSADMNOMEM);
299 throwAFSException(env, JAFSNULLSERVER);
304 ((void *)cellHandle, serverName, (void **)&serverHandle, &ast)) {
305 throwAFSException(env, ast);
307 // release converted string
310 return (jint) serverHandle;
314 * Closes the given currently open bos server handle.
316 * env the Java environment
317 * obj the current Java object
318 * bosServerHandle the bos server handle to close
320 JNIEXPORT void JNICALL
321 Java_org_openafs_jafs_Server_closeBosServerHandle(JNIEnv * env, jobject obj,
322 jint bosServerHandle)
326 if (!bos_ServerClose((void *)bosServerHandle, &ast)) {
327 throwAFSException(env, ast);
333 * Gets the expiration time for a given token.
335 * env the Java environment
336 * obj the current Java object
338 * tokenHandle a token handle previously returned by a call
340 * returns a long representing the UTC time for the token expiration
342 JNIEXPORT jlong JNICALL
343 Java_org_openafs_jafs_Token_getExpiration(JNIEnv * env, jobject obj,
347 unsigned long expTime;
348 char *prince = malloc(sizeof(char) * KAS_MAX_NAME_LEN);
349 char *inst = malloc(sizeof(char) * KAS_MAX_NAME_LEN);
350 char *cell = malloc(sizeof(char) * AFS_MAX_SERVER_NAME_LEN);
353 if (!prince || !inst || !cell) {
363 throwAFSException(env, JAFSADMNOMEM);
367 if (!afsclient_TokenQuery
368 ((void *)tokenHandle, &expTime, prince, inst, cell, &hkt, &ast)) {
369 throwAFSException(env, ast);
376 return (jlong) expTime;
379 // reclaim global memory used by this portion
380 JNIEXPORT void JNICALL
381 Java_org_openafs_jafs_Token_reclaimAuthMemory(JNIEnv * env, jclass cls)