Fixed invalid pi bug
This commit is contained in:
		@@ -11,6 +11,7 @@
 | 
				
			|||||||
  See the file LICENSE.
 | 
					  See the file LICENSE.
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "process_info.h"
 | 
				
			||||||
#include "real_filename.h"
 | 
					#include "real_filename.h"
 | 
				
			||||||
#include <assert.h>
 | 
					#include <assert.h>
 | 
				
			||||||
#include <stddef.h>
 | 
					#include <stddef.h>
 | 
				
			||||||
@@ -267,8 +268,7 @@ static int xmp_unlink(const char *path) {
 | 
				
			|||||||
  struct fuse_context *fc = fuse_get_context();
 | 
					  struct fuse_context *fc = fuse_get_context();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // ask the user for the permission for deleting the file
 | 
					  // ask the user for the permission for deleting the file
 | 
				
			||||||
  pi.PID = fc->pid;
 | 
					  pi = get_process_info(fc->pid);
 | 
				
			||||||
  pi.name = get_process_name_by_pid(pi.PID);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
 | 
					  // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -315,8 +315,7 @@ static int xmp_rename(const char *from, const char *to, unsigned int flags) {
 | 
				
			|||||||
  struct process_info pi;
 | 
					  struct process_info pi;
 | 
				
			||||||
  struct fuse_context *fc = fuse_get_context();
 | 
					  struct fuse_context *fc = fuse_get_context();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pi.PID = fc->pid;
 | 
					  pi = get_process_info(fc->pid);
 | 
				
			||||||
  pi.name = get_process_name_by_pid(pi.PID);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
 | 
					  // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -346,8 +345,7 @@ static int xmp_link(const char *from, const char *to) {
 | 
				
			|||||||
  struct process_info pi;
 | 
					  struct process_info pi;
 | 
				
			||||||
  struct fuse_context *fc = fuse_get_context();
 | 
					  struct fuse_context *fc = fuse_get_context();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pi.PID = fc->pid;
 | 
					  pi = get_process_info(fc->pid);
 | 
				
			||||||
  pi.name = get_process_name_by_pid(pi.PID);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
 | 
					  // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
 | 
				
			||||||
  if (!interactive_access(from, pi, 0)) {
 | 
					  if (!interactive_access(from, pi, 0)) {
 | 
				
			||||||
@@ -371,8 +369,7 @@ static int xmp_chmod(const char *path, mode_t mode, struct fuse_file_info *fi) {
 | 
				
			|||||||
  struct process_info pi;
 | 
					  struct process_info pi;
 | 
				
			||||||
  struct fuse_context *fc = fuse_get_context();
 | 
					  struct fuse_context *fc = fuse_get_context();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pi.PID = fc->pid;
 | 
					  pi = get_process_info(fc->pid);
 | 
				
			||||||
  pi.name = get_process_name_by_pid(pi.PID);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
 | 
					  // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
 | 
				
			||||||
  if (!interactive_access(path, pi, 0)) {
 | 
					  if (!interactive_access(path, pi, 0)) {
 | 
				
			||||||
@@ -402,8 +399,7 @@ static int xmp_chown(const char *path, uid_t uid, gid_t gid,
 | 
				
			|||||||
  struct process_info pi;
 | 
					  struct process_info pi;
 | 
				
			||||||
  struct fuse_context *fc = fuse_get_context();
 | 
					  struct fuse_context *fc = fuse_get_context();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pi.PID = fc->pid;
 | 
					  pi = get_process_info(fc->pid);
 | 
				
			||||||
  pi.name = get_process_name_by_pid(pi.PID);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
 | 
					  // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
 | 
				
			||||||
  if (!interactive_access(path, pi, 0)) {
 | 
					  if (!interactive_access(path, pi, 0)) {
 | 
				
			||||||
@@ -461,8 +457,7 @@ static int xmp_create(const char *path, mode_t mode,
 | 
				
			|||||||
  struct process_info pi;
 | 
					  struct process_info pi;
 | 
				
			||||||
  struct fuse_context *fc = fuse_get_context();
 | 
					  struct fuse_context *fc = fuse_get_context();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pi.PID = fc->pid;
 | 
					  pi = get_process_info(fc->pid);
 | 
				
			||||||
  pi.name = get_process_name_by_pid(pi.PID);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
 | 
					  // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -486,8 +481,7 @@ static int xmp_open(const char *path, struct fuse_file_info *fi) {
 | 
				
			|||||||
  struct process_info pi;
 | 
					  struct process_info pi;
 | 
				
			||||||
  struct fuse_context *fc = fuse_get_context();
 | 
					  struct fuse_context *fc = fuse_get_context();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pi.PID = fc->pid;
 | 
					  pi = get_process_info(fc->pid);
 | 
				
			||||||
  pi.name = get_process_name_by_pid(pi.PID);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
 | 
					  // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
 | 
				
			||||||
  if (!interactive_access(path, pi, 0)) {
 | 
					  if (!interactive_access(path, pi, 0)) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -258,7 +258,7 @@ access_t check_perm_access_noparent(const char *filename,
 | 
				
			|||||||
 * false negatives, though.
 | 
					 * false negatives, though.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
access_t check_perm_access(const char *filename, struct process_info pi) {
 | 
					access_t check_perm_access(const char *filename, struct process_info pi) {
 | 
				
			||||||
  if (pi.PID == 0) {
 | 
					  if (pi.PID == 0 || pi.name == NULL) {
 | 
				
			||||||
    return NDEF;
 | 
					    return NDEF;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,10 +9,21 @@
 | 
				
			|||||||
#ifndef PROCESS_INFO_H
 | 
					#ifndef PROCESS_INFO_H
 | 
				
			||||||
#define PROCESS_INFO_H
 | 
					#define PROCESS_INFO_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "proc_operations.h"
 | 
				
			||||||
#include <sys/types.h>
 | 
					#include <sys/types.h>
 | 
				
			||||||
struct process_info {
 | 
					struct process_info {
 | 
				
			||||||
  pid_t PID;
 | 
					  pid_t PID;
 | 
				
			||||||
  char *name;
 | 
					  char *name;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline struct process_info get_process_info(pid_t pid) {
 | 
				
			||||||
 | 
					  struct process_info pi;
 | 
				
			||||||
 | 
					  pi.PID = pid;
 | 
				
			||||||
 | 
					  pi.name = get_process_name_by_pid(pi.PID);
 | 
				
			||||||
 | 
					  if (pi.name == NULL) {
 | 
				
			||||||
 | 
					    pi.PID = 0;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return pi;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif // PROCESS_INFO_H
 | 
					#endif // PROCESS_INFO_H
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user