ICFS/src/ui-socket.c

57 lines
1.4 KiB
C
Raw Normal View History

#include <stddef.h>
#include <sys/types.h>
#define _GNU_SOURCE
#include "ui-socket.h"
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
int init_ui_socket(const char *filename) {
char line[256];
FILE *fp;
// Test if Zenity is installed (get version)
fp = popen("zenity --version", "r");
if (fp == NULL) {
perror("Pipe returned a error");
return 1;
} else {
while (fgets(line, sizeof(line), fp))
printf("%s", line);
pclose(fp);
return 0;
}
}
/*
* This function is called from the FUSE operations functions. Those are called
* from separate threads. Therefore, there can be multiple threads that try to
* ask for access at the same time, but we have to
*/
int ask_access(const char *filename, struct process_info pi) {
FILE *fp;
size_t command_len =
139 + sizeof(pid_t) * 8 + strlen(pi.name) + strlen(filename);
char *command = (char *)malloc(command_len);
snprintf(command, command_len,
"zenity --question --title \"Allow Access?\" --text \"Allow process "
"<tt>%s</tt> with PID <tt>%d</tt> to access <tt>%s</tt>\"",
pi.name, pi.PID, filename);
// Zenity Question Message Popup
fp = popen(command, "r");
free(command);
if (fp == NULL) {
perror("Pipe returned a error");
return -1;
} else {
return WEXITSTATUS(pclose(fp));
}
}