Skeleton for the process tables implementation
Wrote a skeleton for the future process table implemntation. Aslo slightly edited the ui-socket interface.
This commit is contained in:
parent
2fcbf500f1
commit
0cc9140aa3
@ -264,7 +264,7 @@ static int xmp_unlink(const char *path) {
|
||||
|
||||
// fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
|
||||
|
||||
if (ask_access(real_filename(path), pi)) {
|
||||
if (interactive_access(real_filename(path), pi)) {
|
||||
free(pi.name);
|
||||
return -EACCES;
|
||||
}
|
||||
@ -392,7 +392,7 @@ static int xmp_create(const char *path, mode_t mode,
|
||||
|
||||
// fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
|
||||
|
||||
if (ask_access(real_filename(path), pi)) {
|
||||
if (interactive_access(real_filename(path), pi)) {
|
||||
free(pi.name);
|
||||
return -EACCES;
|
||||
}
|
||||
@ -417,7 +417,7 @@ static int xmp_open(const char *path, struct fuse_file_info *fi) {
|
||||
pi.name = get_process_name_by_pid(pi.PID);
|
||||
|
||||
// fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
|
||||
if (ask_access(real_filename(path), pi)) {
|
||||
if (interactive_access(real_filename(path), pi)) {
|
||||
free(pi.name);
|
||||
return -EACCES;
|
||||
}
|
||||
|
@ -37,6 +37,9 @@ int init_ui_socket(const char *filename) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks the user if the process should be allowed to access the file using the
|
||||
* GUI
|
||||
*
|
||||
* @param filename: The file that the process is trying to access
|
||||
* @pram pi: The process information
|
||||
* @return: 0 if access is denied, 1 if access is allowed, 2 if access is allwed
|
||||
@ -77,3 +80,66 @@ int ask_access(const char *filename, struct process_info pi) {
|
||||
int zenity_exit_code = WEXITSTATUS(pclose(fp));
|
||||
return zenity_exit_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the process has a temporary access to the file.
|
||||
*
|
||||
* @param filename: The file that the process is trying to access
|
||||
* @pram pi: The process information
|
||||
* @return: 0 if access is denied, 1 if access is allowed
|
||||
*/
|
||||
int check_temp_access(const char *filename, struct process_info pi) {
|
||||
perror("Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the process has a permanent access to the file.
|
||||
*
|
||||
* @param filename: The file that the process is trying to access
|
||||
* @pram pi: The process information
|
||||
* @return: 0 if access is denied, 1 if access is allowed
|
||||
*/
|
||||
int check_perm_access(const char *filename, struct process_info pi) {
|
||||
perror("Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void give_temp_access(const char *filename, struct process_info pi) {
|
||||
perror("Not implemented");
|
||||
}
|
||||
void give_perm_access(const char *filename, struct process_info pi) {
|
||||
perror("Not implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check access according to:
|
||||
* 1. temp permission table
|
||||
* 2. permanent permission table
|
||||
* 3. user descision
|
||||
*
|
||||
* @param filename: The file that the process is trying to access
|
||||
* @pram pi: The process information
|
||||
* @return: 0 if access is denied, 1 if access is allowed
|
||||
*/
|
||||
int interactive_access(const char *filename, struct process_info pi) {
|
||||
|
||||
if (check_temp_access(filename, pi) || check_perm_access(filename, pi)) {
|
||||
// access was already granted before
|
||||
return 1;
|
||||
}
|
||||
|
||||
int user_response = ask_access(filename, pi);
|
||||
if (user_response == 1) {
|
||||
// user said "yes"
|
||||
give_perm_access(filename, pi);
|
||||
return 1;
|
||||
} else if (user_response == 2) {
|
||||
// user said "yes, but only this time"
|
||||
give_temp_access(filename, pi);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// otherwise "no"
|
||||
return 0;
|
||||
}
|
||||
|
@ -24,6 +24,6 @@ struct process_info {
|
||||
// For default socket location, set socket_path = NULL.
|
||||
int init_ui_socket(const char *socket_path);
|
||||
|
||||
int ask_access(const char *filename, struct process_info pi);
|
||||
int interactive_access(const char *filename, struct process_info pi);
|
||||
|
||||
#endif // !UI_SOCKET_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user