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>
36 * Static function used to initialize the client library and the
39 * env the Java environment
40 * obj the current Java object
42 JNIEXPORT
void JNICALL
43 Java_org_openafs_jafs_Token_initializeAdminClient(JNIEnv
*env
, jclass cls
)
46 if( !afsclient_Init( &ast
) ) {
47 throwAFSException( env
, ast
);
54 * Authenticates the given user and password in the cell. Returns
55 * a token that can be used to prove this authentication later.
57 * env the Java environment
58 * obj the current Java object
59 * jcellName the name of the cell in which to authenticate this user
60 * juserName the name of the user to authenticate
61 * jpassword the password of the user
62 * returns a token representing the authentication
64 JNIEXPORT jlong JNICALL
65 Java_org_openafs_jafs_Token_getToken
66 (JNIEnv
*env
, jobject obj
, jstring jcellName
, jstring juserName
,
77 // convert java strings
78 if( jcellName
!= NULL
) {
79 cellName
= (*env
)->GetStringUTFChars(env
, jcellName
, 0);
81 throwAFSException( env
, JAFSADMNOMEM
);
87 if( juserName
!= NULL
) {
88 userName
= (*env
)->GetStringUTFChars(env
, juserName
, 0);
90 throwAFSException( env
, JAFSADMNOMEM
);
96 if( jpassword
!= NULL
) {
97 password
= (*env
)->GetStringUTFChars(env
, jpassword
, 0);
99 throwAFSException( env
, JAFSADMNOMEM
);
106 err
= (password
==NULL
|| userName
==NULL
)
107 ? afsclient_TokenGetExisting( cellName
, &tokenHandle
, &ast
)
108 : afsclient_TokenGetNew( cellName
, userName
, password
, &tokenHandle
, &ast
);
111 // release converted strings
112 if( cellName
!= NULL
) {
113 (*env
)->ReleaseStringUTFChars(env
, jcellName
, cellName
);
115 if( userName
!= NULL
) {
116 (*env
)->ReleaseStringUTFChars(env
, juserName
, userName
);
118 if( password
!= NULL
) {
119 (*env
)->ReleaseStringUTFChars(env
, jpassword
, password
);
121 throwAFSException( env
, ast
);
125 // release converted strings
126 if( cellName
!= NULL
) {
127 (*env
)->ReleaseStringUTFChars(env
, jcellName
, cellName
);
129 if( userName
!= NULL
) {
130 (*env
)->ReleaseStringUTFChars(env
, juserName
, userName
);
132 if( password
!= NULL
) {
133 (*env
)->ReleaseStringUTFChars(env
, jpassword
, password
);
136 return (jlong
) tokenHandle
;
140 * Closes the given currently open token.
142 * env the Java environment
143 * obj the current Java object
144 * tokenHandle the token to close
146 JNIEXPORT
void JNICALL
147 Java_org_openafs_jafs_Token_close
148 (JNIEnv
*env
, jobject obj
, jlong tokenHandle
)
152 if( !afsclient_TokenClose( (void *) tokenHandle
, &ast
) ) {
153 throwAFSException( env
, ast
);
159 * Opens a cell for administrative use, based on the token provided.
160 * Returns a cell handle to be used by other methods as a means of
163 * env the Java environment
164 * obj the current Java object
165 * jcellName the name of the cell for which to get the handle
166 * tokenHandle a token handle previously returned by a call to getToken
167 * returns a handle to the open cell
169 JNIEXPORT jlong JNICALL
170 Java_org_openafs_jafs_Cell_getCellHandle
171 (JNIEnv
*env
, jobject obj
, jstring jcellName
, jlong tokenHandle
)
174 const char *cellName
;
177 if( jcellName
!= NULL
) {
178 cellName
= (*env
)->GetStringUTFChars(env
, jcellName
, 0);
180 throwAFSException( env
, JAFSADMNOMEM
);
187 if( !afsclient_CellOpen( cellName
, (void *) tokenHandle
,
188 &cellHandle
, &ast
) ) {
189 if( cellName
!= NULL
) {
190 (*env
)->ReleaseStringUTFChars(env
, jcellName
, cellName
);
192 throwAFSException( env
, ast
);
196 if( cellName
!= NULL
) {
197 (*env
)->ReleaseStringUTFChars(env
, jcellName
, cellName
);
200 return (jlong
) cellHandle
;
204 * Closes the given currently open cell handle.
206 * env the Java environment
207 * obj the current Java object
208 * cellHandle the cell handle to close
210 JNIEXPORT
void JNICALL
211 Java_org_openafs_jafs_Cell_closeCell (JNIEnv
*env
, jobject obj
,
217 if( !afsclient_CellClose( (void *) cellHandle
, &ast
) ) {
218 throwAFSException( env
, ast
);
225 * Opens a server for administrative vos use, based on the cell handle
226 * provided. Returns a vos server handle to be used by other
227 * methods as a means of identification.
229 * env the Java environment
230 * obj the current Java object
231 * cellHandle a cell handle previously returned by
232 * a call to getCellHandle
233 * jserverName the name of the server for which to retrieve
235 * returns a vos handle to the server
237 JNIEXPORT jlong JNICALL
238 Java_org_openafs_jafs_Server_getVosServerHandle
239 (JNIEnv
*env
, jobject obj
, jlong cellHandle
, jstring jserverName
)
243 // convert java string
244 const char *serverName
;
246 if( jserverName
!= NULL
) {
247 serverName
= (*env
)->GetStringUTFChars(env
, jserverName
, 0);
249 throwAFSException( env
, JAFSADMNOMEM
);
256 if( !vos_ServerOpen( (void *) cellHandle
, serverName
,
257 (void **) &serverHandle
, &ast
) ) {
258 if( serverName
!= NULL
) {
259 (*env
)->ReleaseStringUTFChars(env
, jserverName
, serverName
);
261 throwAFSException( env
, ast
);
265 // release converted string
266 if( serverName
!= NULL
) {
267 (*env
)->ReleaseStringUTFChars(env
, jserverName
, serverName
);
270 return (jlong
) serverHandle
;
274 * Closes the given currently open vos server handle.
276 * env the Java environment
277 * obj the current Java object
278 * vosServerHandle the vos server handle to close
280 JNIEXPORT
void JNICALL
281 Java_org_openafs_jafs_Server_closeVosServerHandle
282 (JNIEnv
*env
, jobject obj
, jlong vosServerHandle
)
286 if( !vos_ServerClose( (void *) vosServerHandle
, &ast
) ) {
287 throwAFSException( env
, ast
);
293 * Opens a server for administrative bos use, based on the cell handle
294 * provided. Returns a bos server handle to be used by other methods
295 * as a means of identification.
297 * env the Java environment
298 * obj the current Java object
299 * cellHandle a cell handle previously returned by a call
301 * jserverName the name of the server for which to retrieve
303 * returns a bos handle to the server
305 JNIEXPORT jlong JNICALL
306 Java_org_openafs_jafs_Server_getBosServerHandle
307 (JNIEnv
*env
, jobject obj
, jlong cellHandle
, jstring jserverName
)
311 // convert java string
312 const char *serverName
;
314 if( jserverName
!= NULL
) {
315 serverName
= (*env
)->GetStringUTFChars(env
, jserverName
, 0);
317 throwAFSException( env
, JAFSADMNOMEM
);
324 if( !bos_ServerOpen( (void *) cellHandle
, serverName
,
325 (void **) &serverHandle
, &ast
) ) {
326 if( serverName
!= NULL
) {
327 (*env
)->ReleaseStringUTFChars(env
, jserverName
, serverName
);
329 throwAFSException( env
, ast
);
333 // release converted string
334 if( serverName
!= NULL
) {
335 (*env
)->ReleaseStringUTFChars(env
, jserverName
, serverName
);
338 return (jlong
) serverHandle
;
342 * Closes the given currently open bos server handle.
344 * env the Java environment
345 * obj the current Java object
346 * bosServerHandle the bos server handle to close
348 JNIEXPORT
void JNICALL
349 Java_org_openafs_jafs_Server_closeBosServerHandle
350 (JNIEnv
*env
, jobject obj
, jlong bosServerHandle
)
354 if( !bos_ServerClose( (void *) bosServerHandle
, &ast
) ) {
355 throwAFSException( env
, ast
);
361 * Gets the expiration time for a given token.
363 * env the Java environment
364 * obj the current Java object
366 * tokenHandle a token handle previously returned by a call
368 * returns a long representing the UTC time for the token expiration
370 JNIEXPORT jlong JNICALL
371 Java_org_openafs_jafs_Token_getExpiration
372 (JNIEnv
*env
, jobject obj
, jlong tokenHandle
)
375 unsigned long expTime
;
376 char *prince
= malloc( sizeof(char)*KAS_MAX_NAME_LEN
);
377 char *inst
= malloc( sizeof(char)*KAS_MAX_NAME_LEN
);
378 char *cell
= malloc( sizeof(char)*AFS_MAX_SERVER_NAME_LEN
);
381 if( !prince
|| !inst
|| !cell
) {
391 throwAFSException( env
, JAFSADMNOMEM
);
395 if( !afsclient_TokenQuery( (void *) tokenHandle
, &expTime
, prince
, inst
,
396 cell
, &hkt
, &ast
) ) {
400 throwAFSException( env
, ast
);
408 return (jlong
) expTime
;
411 // reclaim global memory used by this portion
412 JNIEXPORT
void JNICALL
413 Java_org_openafs_jafs_Token_reclaimAuthMemory (JNIEnv
*env
, jclass cls
)