aboutsummaryrefslogtreecommitdiffstats
path: root/src/firejail/fs_hostname.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/firejail/fs_hostname.c')
-rw-r--r--src/firejail/fs_hostname.c30
1 files changed, 9 insertions, 21 deletions
diff --git a/src/firejail/fs_hostname.c b/src/firejail/fs_hostname.c
index aa391c0cb..04197eb8f 100644
--- a/src/firejail/fs_hostname.c
+++ b/src/firejail/fs_hostname.c
@@ -27,7 +27,6 @@
27 27
28void fs_hostname(const char *hostname) { 28void fs_hostname(const char *hostname) {
29 struct stat s; 29 struct stat s;
30 fs_build_mnt_dir();
31 30
32 // create a new /etc/hostname 31 // create a new /etc/hostname
33 if (stat("/etc/hostname", &s) == 0) { 32 if (stat("/etc/hostname", &s) == 0) {
@@ -40,14 +39,10 @@ void fs_hostname(const char *hostname) {
40 exit(1); 39 exit(1);
41 } 40 }
42 fprintf(fp, "%s\n", hostname); 41 fprintf(fp, "%s\n", hostname);
43 fclose(fp);
44
45 // mode and owner 42 // mode and owner
46 if (chown(RUN_HOSTNAME_FILE, 0, 0) < 0) 43 SET_PERMS_STREAM(fp, 0, 0, S_IRUSR | S_IWRITE | S_IRGRP | S_IROTH);
47 errExit("chown"); 44 fclose(fp);
48 if (chmod(RUN_HOSTNAME_FILE, S_IRUSR | S_IWRITE | S_IRGRP | S_IROTH ) < 0) 45
49 errExit("chmod");
50
51 // bind-mount the file on top of /etc/hostname 46 // bind-mount the file on top of /etc/hostname
52 if (mount(RUN_HOSTNAME_FILE, "/etc/hostname", NULL, MS_BIND|MS_REC, NULL) < 0) 47 if (mount(RUN_HOSTNAME_FILE, "/etc/hostname", NULL, MS_BIND|MS_REC, NULL) < 0)
53 errExit("mount bind /etc/hostname"); 48 errExit("mount bind /etc/hostname");
@@ -88,13 +83,9 @@ void fs_hostname(const char *hostname) {
88 fprintf(fp2, "%s\n", buf); 83 fprintf(fp2, "%s\n", buf);
89 } 84 }
90 fclose(fp1); 85 fclose(fp1);
91 fclose(fp2);
92
93 // mode and owner 86 // mode and owner
94 if (chown(RUN_HOSTS_FILE, 0, 0) < 0) 87 SET_PERMS_STREAM(fp2, 0, 0, S_IRUSR | S_IWRITE | S_IRGRP | S_IROTH);
95 errExit("chown"); 88 fclose(fp2);
96 if (chmod(RUN_HOSTS_FILE, S_IRUSR | S_IWRITE | S_IRGRP | S_IROTH ) < 0)
97 errExit("chmod");
98 89
99 // bind-mount the file on top of /etc/hostname 90 // bind-mount the file on top of /etc/hostname
100 if (mount(RUN_HOSTS_FILE, "/etc/hosts", NULL, MS_BIND|MS_REC, NULL) < 0) 91 if (mount(RUN_HOSTS_FILE, "/etc/hosts", NULL, MS_BIND|MS_REC, NULL) < 0)
@@ -108,7 +99,6 @@ void fs_resolvconf(void) {
108 return; 99 return;
109 100
110 struct stat s; 101 struct stat s;
111 fs_build_mnt_dir();
112 102
113 // create a new /etc/hostname 103 // create a new /etc/hostname
114 if (stat("/etc/resolv.conf", &s) == 0) { 104 if (stat("/etc/resolv.conf", &s) == 0) {
@@ -126,13 +116,11 @@ void fs_resolvconf(void) {
126 fprintf(fp, "nameserver %d.%d.%d.%d\n", PRINT_IP(cfg.dns2)); 116 fprintf(fp, "nameserver %d.%d.%d.%d\n", PRINT_IP(cfg.dns2));
127 if (cfg.dns3) 117 if (cfg.dns3)
128 fprintf(fp, "nameserver %d.%d.%d.%d\n", PRINT_IP(cfg.dns3)); 118 fprintf(fp, "nameserver %d.%d.%d.%d\n", PRINT_IP(cfg.dns3));
129 fclose(fp); 119
130
131 // mode and owner 120 // mode and owner
132 if (chown(RUN_RESOLVCONF_FILE, 0, 0) < 0) 121 SET_PERMS_STREAM(fp, 0, 0, S_IRUSR | S_IWRITE | S_IRGRP | S_IROTH);
133 errExit("chown"); 122
134 if (chmod(RUN_RESOLVCONF_FILE, S_IRUSR | S_IWRITE | S_IRGRP | S_IROTH ) < 0) 123 fclose(fp);
135 errExit("chmod");
136 124
137 // bind-mount the file on top of /etc/hostname 125 // bind-mount the file on top of /etc/hostname
138 if (mount(RUN_RESOLVCONF_FILE, "/etc/resolv.conf", NULL, MS_BIND|MS_REC, NULL) < 0) 126 if (mount(RUN_RESOLVCONF_FILE, "/etc/resolv.conf", NULL, MS_BIND|MS_REC, NULL) < 0)