Commit f70ebb8c f70ebb8c1d67d70222768b34ce7568b78fe191de by Sergey Poznyakoff

Simplify mu_file_safety_check call.

* include/mailutils/util.h (mu_file_safety_check): Change type
of the 3rd argument to uid_t.
* libmailutils/base/filesafety.c: Likewise.  All uses updated.
1 parent 1e9173df
...@@ -220,10 +220,8 @@ int mu_onexit (mu_onexit_t func, void *data); ...@@ -220,10 +220,8 @@ int mu_onexit (mu_onexit_t func, void *data);
220 MU_FILE_SAFETY_DIR_IWOTH ) 220 MU_FILE_SAFETY_DIR_IWOTH )
221 221
222 222
223 struct mu_auth_data;
224
225 int mu_file_safety_check (const char *filename, int mode, 223 int mu_file_safety_check (const char *filename, int mode,
226 struct mu_auth_data *auth, 224 uid_t uid,
227 mu_list_t idlist); 225 mu_list_t idlist);
228 int mu_file_safety_name_to_code (const char *name, int *pcode); 226 int mu_file_safety_name_to_code (const char *name, int *pcode);
229 int mu_file_safety_name_to_error (const char *name, int *pcode); 227 int mu_file_safety_name_to_error (const char *name, int *pcode);
......
...@@ -191,7 +191,7 @@ mu_file_safety_name_to_error (const char *name, int *pcode) ...@@ -191,7 +191,7 @@ mu_file_safety_name_to_error (const char *name, int *pcode)
191 191
192 int 192 int
193 mu_file_safety_check (const char *filename, int mode, 193 mu_file_safety_check (const char *filename, int mode,
194 struct mu_auth_data *auth, 194 uid_t uid,
195 mu_list_t idlist) 195 mu_list_t idlist)
196 { 196 {
197 struct file_check_buffer buf; 197 struct file_check_buffer buf;
...@@ -209,9 +209,7 @@ mu_file_safety_check (const char *filename, int mode, ...@@ -209,9 +209,7 @@ mu_file_safety_check (const char *filename, int mode,
209 return MU_ERR_EXISTS; 209 return MU_ERR_EXISTS;
210 } 210 }
211 211
212 if ((mode & MU_FILE_SAFETY_OWNER_MISMATCH) && 212 if ((mode & MU_FILE_SAFETY_OWNER_MISMATCH) && uid != buf.filst.st_uid)
213 auth &&
214 auth->uid != buf.filst.st_uid)
215 return MU_ERR_PERM_OWNER_MISMATCH; 213 return MU_ERR_PERM_OWNER_MISMATCH;
216 214
217 for (pck = file_safety_check_tab; pck->flag; pck++) 215 for (pck = file_safety_check_tab; pck->flag; pck++)
......
...@@ -74,7 +74,7 @@ mu_check_tls_environment (void) ...@@ -74,7 +74,7 @@ mu_check_tls_environment (void)
74 { 74 {
75 int rc = mu_file_safety_check (mu_tls_module_config.ssl_cert, 75 int rc = mu_file_safety_check (mu_tls_module_config.ssl_cert,
76 mu_tls_module_config.ssl_cert_safety_checks, 76 mu_tls_module_config.ssl_cert_safety_checks,
77 NULL, NULL); 77 -1, NULL);
78 if (rc) 78 if (rc)
79 { 79 {
80 mu_error ("%s: %s", mu_tls_module_config.ssl_cert, 80 mu_error ("%s: %s", mu_tls_module_config.ssl_cert,
...@@ -83,7 +83,7 @@ mu_check_tls_environment (void) ...@@ -83,7 +83,7 @@ mu_check_tls_environment (void)
83 } 83 }
84 rc = mu_file_safety_check (mu_tls_module_config.ssl_key, 84 rc = mu_file_safety_check (mu_tls_module_config.ssl_key,
85 mu_tls_module_config.ssl_key_safety_checks, 85 mu_tls_module_config.ssl_key_safety_checks,
86 NULL, NULL); 86 -1, NULL);
87 if (rc) 87 if (rc)
88 { 88 {
89 mu_error ("%s: %s", mu_tls_module_config.ssl_key, 89 mu_error ("%s: %s", mu_tls_module_config.ssl_key,
...@@ -93,7 +93,7 @@ mu_check_tls_environment (void) ...@@ -93,7 +93,7 @@ mu_check_tls_environment (void)
93 93
94 rc = mu_file_safety_check (mu_tls_module_config.ssl_cafile, 94 rc = mu_file_safety_check (mu_tls_module_config.ssl_cafile,
95 mu_tls_module_config.ssl_cafile_safety_checks, 95 mu_tls_module_config.ssl_cafile_safety_checks,
96 NULL, NULL); 96 -1, NULL);
97 if (rc) 97 if (rc)
98 { 98 {
99 mu_error ("%s: %s", mu_tls_module_config.ssl_cafile, 99 mu_error ("%s: %s", mu_tls_module_config.ssl_cafile,
......
...@@ -213,7 +213,7 @@ maidag_forward (mu_message_t msg, struct mu_auth_data *auth, char *fwfile) ...@@ -213,7 +213,7 @@ maidag_forward (mu_message_t msg, struct mu_auth_data *auth, char *fwfile)
213 mu_list_create (&idlist); 213 mu_list_create (&idlist);
214 214
215 rc = mu_file_safety_check (filename, forward_file_checks, 215 rc = mu_file_safety_check (filename, forward_file_checks,
216 auth, idlist); 216 auth->uid, idlist);
217 if (rc == 0) 217 if (rc == 0)
218 result = process_forward (msg, filename, auth->name); 218 result = process_forward (msg, filename, auth->name);
219 else if (rc == MU_ERR_EXISTS) 219 else if (rc == MU_ERR_EXISTS)
......