~ubuntu-branches/ubuntu/raring/apparmor/raring

« back to all changes in this revision

Viewing changes to changehat/tomcat_apparmor/tomcat_5_0/src/jni_src/JNIChangeHat.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-03-23 16:42:01 UTC
  • Revision ID: james.westby@ubuntu.com-20070323164201-jkax6f0oku087b7l
Tags: upstream-2.0.1+510.dfsg
ImportĀ upstreamĀ versionĀ 2.0.1+510.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  ------------------------------------------------------------------
 
3
 
 
4
    Copyright (C) 2002-2005 Novell/SUSE
 
5
 
 
6
    This program is free software; you can redistribute it and/or
 
7
    modify it under the terms of version 2 of the GNU General Public
 
8
    License published by the Free Software Foundation.
 
9
 
 
10
  ------------------------------------------------------------------
 
11
 */
 
12
 
 
13
 
 
14
#include "jni.h"
 
15
#include <errno.h>
 
16
#include "sys/apparmor.h"
 
17
#include "com_novell_apparmor_JNIChangeHat.h"
 
18
 
 
19
/* c intermediate lib call for Java -> JNI -> c library execution of the change_hat call */
 
20
 
 
21
JNIEXPORT jint Java_com_novell_apparmor_JNIChangeHat_changehat_1in
 
22
  (JNIEnv *env, jobject obj, jstring hatnameUTF, jint token)
 
23
{
 
24
 
 
25
  int len;
 
26
  jint result = 0;
 
27
  
 
28
  if ( hatnameUTF == NULL ) {
 
29
                return ( EINVAL );
 
30
  } 
 
31
  len = (*env)->GetStringLength(env, hatnameUTF);
 
32
  if ( len > 0 ) {
 
33
     if ( len > 128 ) {
 
34
       len = 128;
 
35
     }
 
36
     char hatname[128];
 
37
     (*env)->GetStringUTFRegion(env, hatnameUTF, 0, len, hatname);
 
38
     result = (jint) change_hat(hatname, (unsigned int) token);
 
39
     if ( result ) {
 
40
       return errno;
 
41
     } else {
 
42
       return result;
 
43
     }
 
44
  } 
 
45
  
 
46
  return (jint) result;
 
47
 
 
48
}
 
49
 
 
50
JNIEXPORT jint JNICALL Java_com_novell_apparmor_JNIChangeHat_changehat_1out
 
51
  (JNIEnv *env, jobject obj, jint token)
 
52
{
 
53
  
 
54
  jint result = 0;
 
55
  result =  (jint) change_hat(NULL, (unsigned int) token);
 
56
  if ( result ) {
 
57
    return errno;
 
58
  } else {
 
59
    return result;
 
60
  }
 
61
 
 
62
}
 
63
 
 
64