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>
27 #include "org_openafs_jafs_ACL.h"
30 #include <sys/ioctl.h>
32 #include <netinet/in.h>
33 #include <afs/venus.h>
34 #include <afs/afs_args.h>
36 #include "GetNativeString.h"
39 #include <afs/afs_osi.h>
42 /* just for debugging */
47 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
48 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
50 static char space[MAXSIZE];
62 extern int error_intr;
63 extern int error_nomem;
66 * Returns a formatted string representing the ACL for the specified path.
68 * path the directory path
69 * returns NULL if an exception is encountered.
71 char* getACL(char *path)
73 struct ViceIoctl params;
77 buffer = (char*) malloc(ACL_LEN);
80 params.in_size = params.out_size = 0;
83 fprintf(stderr, "ERROR: ACL::getACL -> could not allocate buffer\n");
88 params.out_size = ACL_LEN;
90 #if defined(AFS_PPC64_LINUX20_ENV) || defined(AFS_S390X_LINUX20_ENV)
91 if(pioctl(path, VIOCGETAL, ¶ms, 1)) {
92 #else /* AFS_PPC_LINUX20_ENV */
93 if(syscall(AFS_SYSCALL, AFSCALL_PIOCTL, path, VIOCGETAL, ¶ms, 1)) {
94 #endif /* AFS_PPC_LINUX20_ENV */
95 fprintf(stderr, "ERROR: ACL::getACL -> VIOCGETAL failed: %d, path: %s\n", errno, path);
104 * Sets the ACL for the specified path using the provided string
107 * path the directory path
108 * aclString string representation of ACL to be set
109 * returns TRUE if the operation succeeds; otherwise FALSE;
111 jboolean setACL(char *path, char *aclString)
113 struct ViceIoctl params;
114 char *redirect, *parentURI, *cptr;
116 params.in = aclString;
117 params.in_size = strlen(aclString) + 1;
121 #if defined(AFS_PPC64_LINUX20_ENV) || defined(AFS_S390X_LINUX20_ENV)
122 if(pioctl(path, VIOCSETAL, ¶ms, 1)) {
123 #else /* AFS_PPC_LINUX20_ENV */
124 if(syscall(AFS_SYSCALL, AFSCALL_PIOCTL, path, VIOCSETAL, ¶ms, 1)) {
125 #endif /* AFS_PPC_LINUX20_ENV */
126 fprintf(stderr, "ERROR: ACL::setACL -> VIOCSETAL failed: %d, path: %s\n", errno, path);
134 * Returns a formatted string representing the ACL for the specified path.
136 * The string format is in the form of a ViceIoctl and is as follows:
137 * printf("%d\n%d\n", positiveEntriesCount, negativeEntriesCount);
138 * printf("%s\t%d\n", userOrGroupName, rightsMask);
140 * path the directory path
141 * returns NULL if an exception is encountered.
143 JNIEXPORT jstring JNICALL Java_org_openafs_jafs_ACL_getACLString
144 (JNIEnv *env, jobject obj, jstring pathUTF)
147 jstring answer = NULL;
150 path = (char*) (*env)->GetStringUTFChars(env, pathUTF, 0);
151 wpath=(jchar*) (*env)->GetStringChars(env,pathUTF,0);*/
153 path = GetNativeString(env,pathUTF);
156 fprintf(stderr, "ERROR: ACL::getACLString ->");
157 fprintf(stderr, "path = NULL\n");
158 throwMessageException( env, "Path is NULL" );
165 answer = (*env) -> NewStringUTF(env, acl);
168 throwAFSException( env, errno );
171 /*(*env)->ReleaseStringUTFChars(env, pathUTF, path);
172 (*env)->ReleaseStringChars(env, pathUTF, (jchar*)wpath);*/
174 free(path); //psomogyi memory leak - added
179 * Sets the ACL for the specified path using the provided string
182 * The string format is in the form of a ViceIoctl and is as follows:
183 * printf("%d\n%d\n", positiveEntriesCount, negativeEntriesCount);
184 * printf("%s\t%d\n", userOrGroupName, rightsMask);
186 * path the directory path
187 * aclString string representation of ACL to be set
188 * throws an afsAdminExceptionName if an internal exception is encountered.
190 JNIEXPORT void JNICALL Java_org_openafs_jafs_ACL_setACLString
191 (JNIEnv *env, jobject obj, jstring pathUTF, jstring aclStringUTF)
193 char *path, *aclString;
196 fprintf(stderr, "ERROR: ACL::setACLString -> pathUTF == NULL\n");
197 throwMessageException( env, "pathUTF == NULL" );
201 /*path = (char*) (*env)->GetStringUTFChars(env, pathUTF, 0);*/
202 path = GetNativeString(env,pathUTF);
205 fprintf(stderr, "ERROR: ACL::setACLString -> failed to get path\n");
206 throwMessageException( env, "Failed to get path" );
211 fprintf(stderr, "ERROR: ACL::setACLString -> aclStringUTF == NULL\n");
212 throwMessageException( env, "aclStringUTF == NULL" );
216 /*aclString = (char*) (*env)->GetStringUTFChars(env, aclStringUTF, 0);*/
217 aclString = GetNativeString(env,aclStringUTF);
219 if(aclString == NULL) {
220 fprintf(stderr, "ERROR: ACL::setACLString -> failed to get aclString\n");
221 (*env)->ReleaseStringUTFChars(env, pathUTF, path);
222 throwMessageException( env, "aclString == NULL" );
226 if (!setACL(path, aclString)) {
227 throwAFSException( env, errno );
230 /*(*env)->ReleaseStringUTFChars(env, pathUTF, path);
231 (*env)->ReleaseStringUTFChars(env, aclStringUTF, aclString);*/