-
Notifications
You must be signed in to change notification settings - Fork 0
/
Soal2.c
113 lines (95 loc) · 2.38 KB
/
Soal2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#define FUSE_USE_VERSION 28
#include <fuse.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <dirent.h>
#include <errno.h>
#include <sys/time.h>
#include <stdlib.h>
char *username = "rendoru";
static int xmp_getattr(const char *path, struct stat *stbuf)
{
int res;
res = lstat(path, stbuf);
if (res == -1)
return -errno;
return 0;
}
static int xmp_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi)
{
char myDocPath[1000];
sprintf(myDocPath,"/home/%s/Documents",username);
if(strcmp(myDocPath,path)==0){
printf("IN THE DOC! %s\n",path);
}
//printf("currernt Path : %s by %s\n",myDocPath,path);
DIR *dp;
struct dirent *de;
(void) offset;
(void) fi;
dp = opendir(path);
if (dp == NULL)
return -errno;
while ((de = readdir(dp)) != NULL) {
struct stat st;
memset(&st, 0, sizeof(st));
st.st_ino = de->d_ino;
st.st_mode = de->d_type << 12;
if (filler(buf, de->d_name, &st, 0))
break;
}
closedir(dp);
return 0;
}
static int xmp_read(const char *path, char *buf, size_t size, off_t offset,struct fuse_file_info *fi)
{
int fd;
int res;
(void) fi;
if(strstr(path,".pdf") || strstr(path,".txt") || strstr(path,".doc")){
system("zenity --error --text=\"Terjadi kesalahan! File berisi konten berbahaya.\"");
char tempName[1000];
sprintf(tempName,"%s.ditandai",path);
printf("renamed TO : %s\n",tempName);
char tempQuery[1000];
sprintf(tempQuery,"/home/%s/Documents/rahasia",username);
rename(path,tempName);
mkdir(tempQuery,0777);
char *point = strstr(tempName,"Documents/");
sprintf(tempQuery,"mv %s /home/%s/Documents/rahasia/%s",tempName,username,(point+10));
system(tempQuery);
sprintf(tempQuery,"chmod 000 /home/%s/Documents/rahasia/%s",username,(point+10));
system(tempQuery);
return 0;
}
fd = open(path, O_RDONLY);
if (fd == -1)
return -errno;
res = pread(fd, buf, size, offset);
if (res == -1)
res = -errno;
close(fd);
return res;
}
static int xmp_mkdir(const char *path, mode_t mode){
int res=1;
printf("mkdir path : %s\n",path);
res = mkdir(path, mode);
if (res == -1){
return -errno;
}
return 0;
}
static struct fuse_operations xmp_oper = {
.getattr = xmp_getattr,
.readdir = xmp_readdir,
.read = xmp_read,
.mkdir = xmp_mkdir
};
int main(int argc, char *argv[])
{
umask(0);
return fuse_main(argc, argv, &xmp_oper, NULL);
}