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 <afs/venus.h>
32 #include <afs/afs_args.h>
35 #include <afs/afs_osi.h>
38 /* just for debugging */
43 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
44 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
46 static char space[MAXSIZE];
57 * Returns a formatted string representing the ACL for the specified path.
59 * path the directory path
60 * returns NULL if an exception is encountered.
62 char* getACL(char *path)
64 struct ViceIoctl params;
72 buffer = (char*) malloc(ACL_LEN);
75 fprintf(stderr, "ERROR: ACL::getACL -> could not allocate buffer\n");
80 params.out_size = ACL_LEN;
82 if ( call_syscall(AFSCALL_PIOCTL, path, VIOCGETAL, ¶ms, 1, 0) ) {
83 fprintf(stderr, "ERROR: ACL::getACL -> VIOCGETAL failed: %d\n", errno);
92 * Sets the ACL for the specified path using the provided string
95 * path the directory path
96 * aclString string representation of ACL to be set
97 * returns TRUE if the operation succeeds; otherwise FALSE;
99 jboolean setACL(char *path, char *aclString)
101 struct ViceIoctl params;
102 char *redirect, *parentURI, *cptr;
104 params.in = aclString;
105 params.in_size = strlen(aclString) + 1;
109 if ( call_syscall(AFSCALL_PIOCTL, path, VIOCGETAL, ¶ms, 1) ) {
110 fprintf(stderr, "ERROR: ACL::setACL -> VIOCSETAL failed: %d\n", errno);
118 * Returns a formatted string representing the ACL for the specified path.
120 * The string format is in the form of a ViceIoctl and is as follows:
121 * printf("%d\n%d\n", positiveEntriesCount, negativeEntriesCount);
122 * printf("%s\t%d\n", userOrGroupName, rightsMask);
124 * path the directory path
125 * returns NULL if an exception is encountered.
127 JNIEXPORT jstring JNICALL Java_org_openafs_jafs_ACL_getACLString
128 (JNIEnv *env, jobject obj, jstring pathUTF)
131 jstring answer = NULL;
133 path = getNativeString(env, pathUTF);
134 if ( path == NULL ) {
135 fprintf(stderr, "ERROR: ACL::getACLString ->");
136 fprintf(stderr, "path = NULL\n");
137 throwAFSException( env, JAFSNULLPATH );
141 acl = getACL( path );
145 answer = (*env)->NewStringUTF( env, acl );
148 throwAFSException( env, errno );
155 * Sets the ACL for the specified path using the provided string
158 * The string format is in the form of a ViceIoctl and is as follows:
159 * printf("%d\n%d\n", positiveEntriesCount, negativeEntriesCount);
160 * printf("%s\t%d\n", userOrGroupName, rightsMask);
162 * path the directory path
163 * aclString string representation of ACL to be set
164 * throws an afsAdminExceptionName if an internal exception is encountered.
166 JNIEXPORT void JNICALL Java_org_openafs_jafs_ACL_setACLString
167 (JNIEnv *env, jobject obj, jstring pathUTF, jstring aclStringUTF)
169 char *path, *aclString;
171 if ( pathUTF == NULL ) {
172 fprintf(stderr, "ERROR: ACL::setACLString -> pathUTF == NULL\n");
173 throwAFSException( env, JAFSNULLPATH );
177 if ( aclStringUTF == NULL ) {
178 fprintf(stderr, "ERROR: ACL::setACLString -> aclStringUTF == NULL\n");
179 throwAFSException( env, JAFSNULLACL );
183 /* path = (char*) (*env)->GetStringUTFChars(env, pathUTF, 0); */
184 path = getNativeString( env, pathUTF );
185 if ( path == NULL ) {
186 fprintf(stderr, "ERROR: ACL::setACLString -> failed to get path\n");
187 throwMessageException( env, "Failed to get path." );
191 /* aclString = (char*) (*env)->GetStringUTFChars(env, aclStringUTF, 0); */
192 aclString = getNativeString( env, aclStringUTF );
193 if ( aclString == NULL ) {
195 fprintf(stderr, "ERROR: ACL::setACLString -> failed to get aclString\n");
196 throwMessageException( env, "Failed to get ACL string." );
200 if ( !setACL(path, aclString) ) {
201 throwAFSException( env, errno );
209 (*env)->ReleaseStringUTFChars(env, pathUTF, path);
210 (*env)->ReleaseStringUTFChars(env, aclStringUTF, aclString);