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>
26 #include "org_openafs_jafs_ACL.h"
29 #include <sys/ioctl.h>
31 #include <netinet/in.h>
32 #include <afs/venus.h>
33 #include <afs/afs_args.h>
35 #include "GetNativeString.h"
38 #include <afs/afs_osi.h>
41 /* just for debugging */
46 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
47 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
49 static char space[MAXSIZE];
60 * Returns a formatted string representing the ACL for the specified path.
62 * path the directory path
63 * returns NULL if an exception is encountered.
65 char* getACL(char *path)
67 struct ViceIoctl params;
71 buffer = (char*) malloc(ACL_LEN);
74 params.in_size = params.out_size = 0;
77 fprintf(stderr, "ERROR: ACL::getACL -> could not allocate buffer\n");
82 params.out_size = ACL_LEN;
84 #if defined(AFS_PPC64_LINUX20_ENV) || defined(AFS_S390X_LINUX20_ENV)
85 if(pioctl(path, VIOCGETAL, ¶ms, 1)) {
86 #else /* AFS_PPC_LINUX20_ENV */
87 if(syscall(AFS_SYSCALL, AFSCALL_PIOCTL, path, VIOCGETAL, ¶ms, 1)) {
88 #endif /* AFS_PPC_LINUX20_ENV */
89 fprintf(stderr, "ERROR: ACL::getACL -> VIOCGETAL failed: %d, path: %s\n", errno, path);
98 * Sets the ACL for the specified path using the provided string
101 * path the directory path
102 * aclString string representation of ACL to be set
103 * returns TRUE if the operation succeeds; otherwise FALSE;
105 jboolean setACL(char *path, char *aclString)
107 struct ViceIoctl params;
108 char *redirect, *parentURI, *cptr;
110 params.in = aclString;
111 params.in_size = strlen(aclString) + 1;
115 #if defined(AFS_PPC64_LINUX20_ENV) || defined(AFS_S390X_LINUX20_ENV)
116 if(pioctl(path, VIOCSETAL, ¶ms, 1)) {
117 #else /* AFS_PPC_LINUX20_ENV */
118 if(syscall(AFS_SYSCALL, AFSCALL_PIOCTL, path, VIOCSETAL, ¶ms, 1)) {
119 #endif /* AFS_PPC_LINUX20_ENV */
120 fprintf(stderr, "ERROR: ACL::setACL -> VIOCSETAL failed: %d, path: %s\n", errno, path);
128 * Returns a formatted string representing the ACL for the specified path.
130 * The string format is in the form of a ViceIoctl and is as follows:
131 * printf("%d\n%d\n", positiveEntriesCount, negativeEntriesCount);
132 * printf("%s\t%d\n", userOrGroupName, rightsMask);
134 * path the directory path
135 * returns NULL if an exception is encountered.
137 JNIEXPORT jstring JNICALL Java_org_openafs_jafs_ACL_getACLString
138 (JNIEnv *env, jobject obj, jstring pathUTF)
141 jstring answer = NULL;
144 path = (char*) (*env)->GetStringUTFChars(env, pathUTF, 0);
145 wpath=(jchar*) (*env)->GetStringChars(env,pathUTF,0);*/
147 path = GetNativeString(env,pathUTF);
150 fprintf(stderr, "ERROR: ACL::getACLString ->");
151 fprintf(stderr, "path = NULL\n");
152 throwMessageException( env, "Path is NULL" );
159 answer = (*env) -> NewStringUTF(env, acl);
162 throwAFSException( env, errno );
165 /*(*env)->ReleaseStringUTFChars(env, pathUTF, path);
166 (*env)->ReleaseStringChars(env, pathUTF, (jchar*)wpath);*/
168 free(path); //psomogyi memory leak - added
173 * Sets the ACL for the specified path using the provided string
176 * The string format is in the form of a ViceIoctl and is as follows:
177 * printf("%d\n%d\n", positiveEntriesCount, negativeEntriesCount);
178 * printf("%s\t%d\n", userOrGroupName, rightsMask);
180 * path the directory path
181 * aclString string representation of ACL to be set
182 * throws an afsAdminExceptionName if an internal exception is encountered.
184 JNIEXPORT void JNICALL Java_org_openafs_jafs_ACL_setACLString
185 (JNIEnv *env, jobject obj, jstring pathUTF, jstring aclStringUTF)
187 char *path, *aclString;
190 fprintf(stderr, "ERROR: ACL::setACLString -> pathUTF == NULL\n");
191 throwMessageException( env, "pathUTF == NULL" );
195 /*path = (char*) (*env)->GetStringUTFChars(env, pathUTF, 0);*/
196 path = GetNativeString(env,pathUTF);
199 fprintf(stderr, "ERROR: ACL::setACLString -> failed to get path\n");
200 throwMessageException( env, "Failed to get path" );
205 fprintf(stderr, "ERROR: ACL::setACLString -> aclStringUTF == NULL\n");
206 throwMessageException( env, "aclStringUTF == NULL" );
210 /*aclString = (char*) (*env)->GetStringUTFChars(env, aclStringUTF, 0);*/
211 aclString = GetNativeString(env,aclStringUTF);
213 if(aclString == NULL) {
214 fprintf(stderr, "ERROR: ACL::setACLString -> failed to get aclString\n");
215 (*env)->ReleaseStringUTFChars(env, pathUTF, path);
216 throwMessageException( env, "aclString == NULL" );
220 if (!setACL(path, aclString)) {
221 throwAFSException( env, errno );
224 /*(*env)->ReleaseStringUTFChars(env, pathUTF, path);
225 (*env)->ReleaseStringUTFChars(env, aclStringUTF, aclString);*/