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_consts.h>
35 #include <afs/afs_args.h>
37 #include "GetNativeString.h"
40 #include <afs/afs_osi.h>
43 /* just for debugging */
45 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
46 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
48 static char space[AFS_PIOCTL_MAXSIZE];
60 extern int error_intr;
61 extern int error_nomem;
64 * Returns a formatted string representing the ACL for the specified path.
66 * path the directory path
67 * returns NULL if an exception is encountered.
69 char* getACL(char *path)
71 struct ViceIoctl params;
75 buffer = (char*) malloc(ACL_LEN);
78 params.in_size = params.out_size = 0;
81 fprintf(stderr, "ERROR: ACL::getACL -> could not allocate buffer\n");
86 params.out_size = ACL_LEN;
88 #if defined(AFS_PPC64_LINUX20_ENV) || defined(AFS_S390X_LINUX20_ENV)
89 if(pioctl(path, VIOCGETAL, ¶ms, 1)) {
90 #else /* AFS_PPC_LINUX20_ENV */
91 if(syscall(AFS_SYSCALL, AFSCALL_PIOCTL, path, VIOCGETAL, ¶ms, 1)) {
92 #endif /* AFS_PPC_LINUX20_ENV */
93 fprintf(stderr, "ERROR: ACL::getACL -> VIOCGETAL failed: %d, path: %s\n", errno, path);
102 * Sets the ACL for the specified path using the provided string
105 * path the directory path
106 * aclString string representation of ACL to be set
107 * returns TRUE if the operation succeeds; otherwise FALSE;
109 jboolean setACL(char *path, char *aclString)
111 struct ViceIoctl params;
112 char *redirect, *parentURI, *cptr;
114 params.in = aclString;
115 params.in_size = strlen(aclString) + 1;
119 #if defined(AFS_PPC64_LINUX20_ENV) || defined(AFS_S390X_LINUX20_ENV)
120 if(pioctl(path, VIOCSETAL, ¶ms, 1)) {
121 #else /* AFS_PPC_LINUX20_ENV */
122 if(syscall(AFS_SYSCALL, AFSCALL_PIOCTL, path, VIOCSETAL, ¶ms, 1)) {
123 #endif /* AFS_PPC_LINUX20_ENV */
124 fprintf(stderr, "ERROR: ACL::setACL -> VIOCSETAL failed: %d, path: %s\n", errno, path);
132 * Returns a formatted string representing the ACL for the specified path.
134 * The string format is in the form of a ViceIoctl and is as follows:
135 * printf("%d\n%d\n", positiveEntriesCount, negativeEntriesCount);
136 * printf("%s\t%d\n", userOrGroupName, rightsMask);
138 * path the directory path
139 * returns NULL if an exception is encountered.
141 JNIEXPORT jstring JNICALL Java_org_openafs_jafs_ACL_getACLString
142 (JNIEnv *env, jobject obj, jstring pathUTF)
145 jstring answer = NULL;
148 path = (char*) (*env)->GetStringUTFChars(env, pathUTF, 0);
149 wpath=(jchar*) (*env)->GetStringChars(env,pathUTF,0);*/
151 path = GetNativeString(env,pathUTF);
154 fprintf(stderr, "ERROR: ACL::getACLString ->");
155 fprintf(stderr, "path = NULL\n");
156 throwMessageException( env, "Path is NULL" );
163 answer = (*env) -> NewStringUTF(env, acl);
166 throwAFSException( env, errno );
169 /*(*env)->ReleaseStringUTFChars(env, pathUTF, path);
170 (*env)->ReleaseStringChars(env, pathUTF, (jchar*)wpath);*/
172 free(path); //psomogyi memory leak - added
177 * Sets the ACL for the specified path using the provided string
180 * The string format is in the form of a ViceIoctl and is as follows:
181 * printf("%d\n%d\n", positiveEntriesCount, negativeEntriesCount);
182 * printf("%s\t%d\n", userOrGroupName, rightsMask);
184 * path the directory path
185 * aclString string representation of ACL to be set
186 * throws an afsAdminExceptionName if an internal exception is encountered.
188 JNIEXPORT void JNICALL Java_org_openafs_jafs_ACL_setACLString
189 (JNIEnv *env, jobject obj, jstring pathUTF, jstring aclStringUTF)
191 char *path, *aclString;
194 fprintf(stderr, "ERROR: ACL::setACLString -> pathUTF == NULL\n");
195 throwMessageException( env, "pathUTF == NULL" );
199 /*path = (char*) (*env)->GetStringUTFChars(env, pathUTF, 0);*/
200 path = GetNativeString(env,pathUTF);
203 fprintf(stderr, "ERROR: ACL::setACLString -> failed to get path\n");
204 throwMessageException( env, "Failed to get path" );
209 fprintf(stderr, "ERROR: ACL::setACLString -> aclStringUTF == NULL\n");
210 throwMessageException( env, "aclStringUTF == NULL" );
214 /*aclString = (char*) (*env)->GetStringUTFChars(env, aclStringUTF, 0);*/
215 aclString = GetNativeString(env,aclStringUTF);
217 if(aclString == NULL) {
218 fprintf(stderr, "ERROR: ACL::setACLString -> failed to get aclString\n");
219 (*env)->ReleaseStringUTFChars(env, pathUTF, path);
220 throwMessageException( env, "aclString == NULL" );
224 if (!setACL(path, aclString)) {
225 throwAFSException( env, errno );
228 /*(*env)->ReleaseStringUTFChars(env, pathUTF, path);
229 (*env)->ReleaseStringUTFChars(env, aclStringUTF, aclString);*/