aboutsummaryrefslogtreecommitdiffstats
path: root/src/firejail/fs_mkdir.c
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@yahoo.com>2016-07-08 09:39:18 -0400
committerLibravatar netblue30 <netblue30@yahoo.com>2016-07-08 09:39:18 -0400
commit0838606e623fc11fac5fd8db8b197d63f3e21f32 (patch)
treeafbe78890c684230e5269ed49bf2aef1b757d73b /src/firejail/fs_mkdir.c
parentprivate-dev (diff)
downloadfirejail-0838606e623fc11fac5fd8db8b197d63f3e21f32.tar.gz
firejail-0838606e623fc11fac5fd8db8b197d63f3e21f32.tar.zst
firejail-0838606e623fc11fac5fd8db8b197d63f3e21f32.zip
added mkfile profile command
Diffstat (limited to 'src/firejail/fs_mkdir.c')
-rw-r--r--src/firejail/fs_mkdir.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/firejail/fs_mkdir.c b/src/firejail/fs_mkdir.c
index 398c534bf..c4ce52079 100644
--- a/src/firejail/fs_mkdir.c
+++ b/src/firejail/fs_mkdir.c
@@ -48,3 +48,36 @@ void fs_mkdir(const char *name) {
48doexit: 48doexit:
49 free(expanded); 49 free(expanded);
50} 50}
51
52void fs_mkfile(const char *name) {
53 EUID_ASSERT();
54
55 // check file name
56 invalid_filename(name);
57 char *expanded = expand_home(name, cfg.homedir);
58 if (strncmp(expanded, cfg.homedir, strlen(cfg.homedir)) != 0) {
59 fprintf(stderr, "Error: only files in user home are supported by mkfile\n");
60 exit(1);
61 }
62
63 struct stat s;
64 if (stat(expanded, &s) == 0) {
65 // file exists, do nothing
66 goto doexit;
67 }
68
69 // create file
70 FILE *fp = fopen(expanded, "w");
71 if (!fp)
72 fprintf(stderr, "Warning: cannot create %s file\n", expanded);
73 else {
74 fclose(fp);
75 int rv = chown(expanded, getuid(), getgid());
76 (void) rv;
77 rv = chmod(expanded, 0600);
78 (void) rv;
79 }
80
81doexit:
82 free(expanded);
83} \ No newline at end of file