0001
0002
0003
0004
0005
0006
0007
0008 #include "common.h"
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 static bool tomoyo_check_env_acl(struct tomoyo_request_info *r,
0019 const struct tomoyo_acl_info *ptr)
0020 {
0021 const struct tomoyo_env_acl *acl =
0022 container_of(ptr, typeof(*acl), head);
0023
0024 return tomoyo_path_matches_pattern(r->param.environ.name, acl->env);
0025 }
0026
0027
0028
0029
0030
0031
0032
0033
0034 static int tomoyo_audit_env_log(struct tomoyo_request_info *r)
0035 {
0036 return tomoyo_supervisor(r, "misc env %s\n",
0037 r->param.environ.name->name);
0038 }
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050 int tomoyo_env_perm(struct tomoyo_request_info *r, const char *env)
0051 {
0052 struct tomoyo_path_info environ;
0053 int error;
0054
0055 if (!env || !*env)
0056 return 0;
0057 environ.name = env;
0058 tomoyo_fill_path_info(&environ);
0059 r->param_type = TOMOYO_TYPE_ENV_ACL;
0060 r->param.environ.name = &environ;
0061 do {
0062 tomoyo_check_acl(r, tomoyo_check_env_acl);
0063 error = tomoyo_audit_env_log(r);
0064 } while (error == TOMOYO_RETRY_REQUEST);
0065 return error;
0066 }
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 static bool tomoyo_same_env_acl(const struct tomoyo_acl_info *a,
0077 const struct tomoyo_acl_info *b)
0078 {
0079 const struct tomoyo_env_acl *p1 = container_of(a, typeof(*p1), head);
0080 const struct tomoyo_env_acl *p2 = container_of(b, typeof(*p2), head);
0081
0082 return p1->env == p2->env;
0083 }
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094 static int tomoyo_write_env(struct tomoyo_acl_param *param)
0095 {
0096 struct tomoyo_env_acl e = { .head.type = TOMOYO_TYPE_ENV_ACL };
0097 int error = -ENOMEM;
0098 const char *data = tomoyo_read_token(param);
0099
0100 if (!tomoyo_correct_word(data) || strchr(data, '='))
0101 return -EINVAL;
0102 e.env = tomoyo_get_name(data);
0103 if (!e.env)
0104 return error;
0105 error = tomoyo_update_domain(&e.head, sizeof(e), param,
0106 tomoyo_same_env_acl, NULL);
0107 tomoyo_put_name(e.env);
0108 return error;
0109 }
0110
0111
0112
0113
0114
0115
0116
0117
0118 int tomoyo_write_misc(struct tomoyo_acl_param *param)
0119 {
0120 if (tomoyo_str_starts(¶m->data, "env "))
0121 return tomoyo_write_env(param);
0122 return -EINVAL;
0123 }