I'm trying to pass two strings to a native method, the method doesn't execute while passing strings like this
String pathDir=request.getParameter("path");
String user=request.getParameter("user");
obj.modifyACL(pathDir, user, 'a', 1);
The same method executes well when passing strings as this
obj.modifyACL("C:/Users/margie/Desktop/tb.h", "SYSTEM", 'r', 2);
The value of pathDir and users are not empty while getting the HTML element value. I used
pw.println(user+pathDir);
and it shows like this
SYSTEM C:\Users\margie\Desktop\tb.h
This is native method
PACL SetPerm(LPCTSTR file, string user, char val, int perm, PACL pOldDACL)
{
EXPLICIT_ACCESS eas[1];
PACL pacl = 0;
DWORD rc;
long long int access_val;
LPSTR use = const_cast<char *>(user.c_str());
if(val=='R'||val=='r')
access_val=0x80000000; //GENERIC_READ
if(val=='W'||val=='w')
access_val=0x40000000; //GENERIC_WRITE
if(val=='A'||val=='a')
access_val=0x10000000; //GENERIC_ALL
if(perm==1)
{
eas[0].grfAccessPermissions = access_val;
eas[0].grfAccessMode = GRANT_ACCESS;
eas[0].grfInheritance = NO_INHERITANCE;
eas[0].Trustee.TrusteeForm = TRUSTEE_IS_NAME;
eas[0].Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
eas[0].Trustee.ptstrName = use;
}
else if(perm==2)
{
eas[0].grfAccessPermissions = access_val;
eas[0].grfAccessMode = DENY_ACCESS;
eas[0].grfInheritance = NO_INHERITANCE;
eas[0].Trustee.TrusteeForm = TRUSTEE_IS_NAME;
eas[0].Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
eas[0].Trustee.ptstrName = use;
}
rc = SetEntriesInAcl(1, eas, pOldDACL, &pacl);
if (rc != ERROR_SUCCESS)
{
printf("ERROR---------SetEntriesInAcl: %u\n", rc);
return NULL;
}
rc = SetNamedSecurityInfo((LPSTR)file, SE_FILE_OBJECT,
DACL_SECURITY_INFORMATION | PROTECTED_DACL_SECURITY_INFORMATION,
NULL, NULL, pacl, NULL);
if (rc != ERROR_SUCCESS)
{
printf("ERROR---------SetNamedSecurityInfo: %u\n", rc);
return NULL;
}
cout << "----------------PERMISSION GRANTED----------------\n";
return pacl;
}
JNIEXPORT void JNICALL Java_total_modifyACL(JNIEnv *env, jobject thisObj, jstring inJNIStr, jstring inStr, jchar chr, jint num)
{
cout<<"Inside modifyACL()\n";
PSID pSidOwner = NULL;
DWORD dwRtnCode = 0, dwAcctName = 1, dwDomainName = 1;
HANDLE hFile;
PSECURITY_DESCRIPTOR pSD = NULL;
PACL pOldDACL = NULL;
char ch;
char tp=(char)chr;
int val,i,aceNum;
int perm=(int)num;
const char *input = env->GetStringUTFChars(inJNIStr, NULL);
const char *user = env->GetStringUTFChars(inStr, NULL);
// Get the handle of the file object.
hFile = CreateFile(
input,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
// Check GetLastError for CreateFile error code.
if (hFile == INVALID_HANDLE_VALUE) {
DWORD dwErrorCode = 0;
dwErrorCode = GetLastError();
cout << "CreateFile error = " << dwErrorCode<<". Possibly NO file exist in the given path or READ Access denied.";
exit;
}
// Get the SID of the file.
dwRtnCode = GetSecurityInfo(
hFile,
SE_FILE_OBJECT,
DACL_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION,
&pSidOwner,
NULL,
&pOldDACL,
NULL,
&pSD);
// Check GetLastError for GetSecurityInfo error condition.
if (dwRtnCode != ERROR_SUCCESS) {
DWORD dwErrorCode = 0;
dwErrorCode = GetLastError();
cout << "GetSecurityInfo error = " << dwErrorCode;
}
pOldDACL = SetPerm(input,user,tp,perm,pOldDACL); //passing pOldDACL to add the ACE in exixting ACE.
}
What should I do to make modifyACL() work on passing user input string?
User contributions licensed under CC BY-SA 3.0