Added the "Allow this time." option.
Now the user can choose the "Allow this time." option when prompted. `ask_access` will return 2 if this option is selected. So far, only the GUI for this feature is implemented.
This commit is contained in:
parent
13830ead87
commit
64289b2786
@ -28,12 +28,12 @@ int init_ui_socket(const char *filename) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* This function is called from the FUSE operations functions. Those are called
|
* @param filename: The file that the process is trying to access
|
||||||
* from separate threads. Therefore, there can be multiple threads that try to
|
* @pram pi: The process information
|
||||||
* ask for access at the same time, but we have to
|
* @return: 0 if access is denied, 1 if access is allowed, 2 if access is allwed
|
||||||
|
* for the runtime of the process
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int ask_access(const char *filename, struct process_info pi) {
|
int ask_access(const char *filename, struct process_info pi) {
|
||||||
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
@ -41,16 +41,31 @@ int ask_access(const char *filename, struct process_info pi) {
|
|||||||
139 + sizeof(pid_t) * 8 + strlen(pi.name) + strlen(filename);
|
139 + sizeof(pid_t) * 8 + strlen(pi.name) + strlen(filename);
|
||||||
char *command = (char *)malloc(command_len);
|
char *command = (char *)malloc(command_len);
|
||||||
snprintf(command, command_len,
|
snprintf(command, command_len,
|
||||||
"zenity --question --title \"Allow Access?\" --text \"Allow process "
|
"zenity --question --extra-button \"Allow this time\" --title "
|
||||||
|
"\"Allow Access?\" --text \"Allow process "
|
||||||
"<tt>%s</tt> with PID <tt>%d</tt> to access <tt>%s</tt>\"",
|
"<tt>%s</tt> with PID <tt>%d</tt> to access <tt>%s</tt>\"",
|
||||||
pi.name, pi.PID, filename);
|
pi.name, pi.PID, filename);
|
||||||
|
|
||||||
// Zenity Question Message Popup
|
// Zenity Question Message Popup
|
||||||
fp = popen(command, "r");
|
fp = popen(command, "r");
|
||||||
free(command);
|
free(command);
|
||||||
|
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
perror("Pipe returned a error");
|
perror("Pipe returned a error");
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
|
||||||
return WEXITSTATUS(pclose(fp));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if the user clicks the "Allow this time" button, `zenity` will only
|
||||||
|
// write it to `stdout`, but the exit code will still be `1`. So, we need
|
||||||
|
// to manually check the output.
|
||||||
|
char buffer[1024];
|
||||||
|
while (fgets(buffer, sizeof(buffer), fp)) {
|
||||||
|
if (strcmp(buffer, "Allow this time.\n") == 0) {
|
||||||
|
pclose(fp);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int zenity_exit_code = WEXITSTATUS(pclose(fp));
|
||||||
|
return zenity_exit_code;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user