Ainfo getAccessNode(const char *file1, const char *file2, int mode, pid_t pid) { Ainfo node = createNewNode(); node->cwd = getCWDFromPid(pid); node->userName = getEUserFromPid(pid); node->groupName = getEGroupFromPid(pid); node->fileOwner = getFileOwner(file1); if (file1[0] == '/') { node->fileName1 = (char*) malloc((strlen(file1) + 1) * sizeof (char)); strcpy(node->fileName1, file1); } else { node->fileName1 = (char*) malloc((strlen(node->cwd) + strlen(file1) + 2) * sizeof (char)); strcpy(node->fileName1, node->cwd); strcat(node->fileName1, "/"); strcat(node->fileName1, file1); } //Not every access node has file2 if (file2) { if (file2[0] == '/') { node->fileName2 = (char*) malloc((strlen(file2) + 1) * sizeof (char)); strcpy(node->fileName2, file2); } else { node->fileName2 = (char*) malloc((strlen(node->cwd) + strlen(file2) + 2) * sizeof (char)); strcpy(node->fileName2, node->cwd); strcat(node->fileName2, "/"); strcat(node->fileName2, file2); } } node->mode = mode; node->pid = pid; return node; }
Status PlatformFile::isOwnerRoot() const { if (!isValid()) { return Status(-1, "Invalid handle_"); } uid_t owner_id = getFileOwner(handle_); if (owner_id == (uid_t)-1) { return Status(-1, "fstat error"); } if (owner_id == 0) { return Status(0, "OK"); } return Status(1, "Owner is not root"); }
Status PlatformFile::isOwnerCurrentUser() const { if (!isValid()) { return Status(-1, "Invalid handle_"); } uid_t owner_id = getFileOwner(handle_); if (owner_id == (uid_t)-1) { return Status(-1, "fstat error"); } if (owner_id == ::getuid()) { return Status(0, "OK"); } return Status(1, "Owner is not current user"); }
/* * Class: sun_management_FileSystemImpl * Method: isAccessUserOnly0 * Signature: (Ljava/lang/String;)Z */ JNIEXPORT jboolean JNICALL Java_sun_management_FileSystemImpl_isAccessUserOnly0 (JNIEnv *env, jclass ignored, jstring str) { jboolean res = JNI_FALSE; jboolean isCopy; const char* path; path = JNU_GetStringPlatformChars(env, str, &isCopy); if (path != NULL) { /* * From the security descriptor get the file owner and * DACL. Then check if anybody but the owner has access * to the file. */ SECURITY_DESCRIPTOR* sd = getFileSecurityDescriptor(env, path); if (sd != NULL) { SID *owner = getFileOwner(env, sd); if (owner != NULL) { ACL* acl = getFileDACL(env, sd); if (acl != NULL) { res = isAccessUserOnly(env, owner, acl); } else { /* * If acl is NULL it means that an exception was thrown * or there is "all acess" to the file. */ res = JNI_FALSE; } } free(sd); } if (isCopy) { JNU_ReleaseStringPlatformChars(env, str, path); } } return res; }