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_ACL.h"
27 #include <sys/ioctl.h>
29 #include <afs/venus.h>
30 #include <afs/afs_args.h>
31 #include <afs/afs_osi.h>
42 * Returns a formatted string representing the ACL for the specified path.
44 * path the directory path
45 * returns NULL if an exception is encountered.
47 char* getACL(char *path)
49 struct ViceIoctl params;
54 buffer = (char*) malloc(ACL_LEN);
57 fprintf(stderr, "ERROR: ACL::getACL -> could not allocate buffer\n");
62 params.out_size = ACL_LEN;
64 if(call_syscall(AFSCALL_PIOCTL, path, VIOCGETAL, ¶ms, 1)) {
65 fprintf(stderr, "ERROR: ACL::getACL -> VIOCGETAL failed: %d\n", errno);
74 * Sets the ACL for the specified path using the provided string
77 * path the directory path
78 * aclString string representation of ACL to be set
79 * returns TRUE if the operation succeeds; otherwise FALSE;
81 jboolean setACL(char *path, char *aclString)
83 struct ViceIoctl params;
84 char *redirect, *parentURI, *cptr;
86 params.in = aclString;
87 params.in_size = strlen(aclString) + 1;
91 if(call_syscall(AFSCALL_PIOCTL, path, VIOCSETAL, ¶ms, 1)) {
92 fprintf(stderr, "ERROR: ACL::setACL -> VIOCSETAL failed: %d\n", errno);
100 * Returns a formatted string representing the ACL for the specified path.
102 * The string format is in the form of a ViceIoctl and is as follows:
103 * printf("%d\n%d\n", positiveEntriesCount, negativeEntriesCount);
104 * printf("%s\t%d\n", userOrGroupName, rightsMask);
106 * path the directory path
107 * returns NULL if an exception is encountered.
109 JNIEXPORT jstring JNICALL Java_org_openafs_jafs_ACL_getACLString
110 (JNIEnv *env, jobject obj, jstring pathUTF)
113 jstring answer = NULL;
115 path = (char*) (*env)->GetStringUTFChars(env, pathUTF, 0);
118 fprintf(stderr, "ERROR: ACL::getACLString ->");
119 fprintf(stderr, "GetStringUTFChars() returned path = NULL\n");
120 throwMessageException( env, "Path is NULL" );
125 (*env)->ReleaseStringUTFChars(env, pathUTF, path);
128 answer = (*env) -> NewStringUTF(env, acl);
131 throwAFSException( env, errno );
138 * Sets the ACL for the specified path using the provided string
141 * The string format is in the form of a ViceIoctl and is as follows:
142 * printf("%d\n%d\n", positiveEntriesCount, negativeEntriesCount);
143 * printf("%s\t%d\n", userOrGroupName, rightsMask);
145 * path the directory path
146 * aclString string representation of ACL to be set
147 * throws an afsAdminExceptionName if an internal exception is encountered.
149 JNIEXPORT void JNICALL Java_org_openafs_jafs_ACL_setACLString
150 (JNIEnv *env, jobject obj, jstring pathUTF, jstring aclStringUTF)
152 char *path, *aclString;
155 fprintf(stderr, "ERROR: ACL::setACLString -> pathUTF == NULL\n");
156 throwMessageException( env, "pathUTF == NULL" );
160 path = (char*) (*env)->GetStringUTFChars(env, pathUTF, 0);
163 fprintf(stderr, "ERROR: ACL::setACLString -> failed to get path\n");
164 throwMessageException( env, "Failed to get path" );
169 fprintf(stderr, "ERROR: ACL::setACLString -> aclStringUTF == NULL\n");
170 throwMessageException( env, "aclStringUTF == NULL" );
174 aclString = (char*) (*env)->GetStringUTFChars(env, aclStringUTF, 0);
176 if(aclString == NULL) {
177 fprintf(stderr, "ERROR: ACL::setACLString -> failed to get aclString\n");
178 (*env)->ReleaseStringUTFChars(env, pathUTF, path);
179 throwMessageException( env, "aclString == NULL" );
183 if (!setACL(path, aclString)) {
184 throwAFSException( env, errno );
187 (*env)->ReleaseStringUTFChars(env, pathUTF, path);
188 (*env)->ReleaseStringUTFChars(env, aclStringUTF, aclString);