| 1083 | } |
| 1084 | |
| 1085 | static enum protocol_allow_config get_protocol_config(const char *type) |
| 1086 | { |
| 1087 | char *key = xstrfmt("protocol.%s.allow", type); |
| 1088 | char *value; |
| 1089 | |
| 1090 | /* first check the per-protocol config */ |
| 1091 | if (!repo_config_get_string(the_repository, key, &value)) { |
| 1092 | enum protocol_allow_config ret = |
| 1093 | parse_protocol_config(key, value); |
| 1094 | free(key); |
| 1095 | free(value); |
| 1096 | return ret; |
| 1097 | } |
| 1098 | free(key); |
| 1099 | |
| 1100 | /* if defined, fallback to user-defined default for unknown protocols */ |
| 1101 | if (!repo_config_get_string(the_repository, "protocol.allow", &value)) { |
| 1102 | enum protocol_allow_config ret = |
| 1103 | parse_protocol_config("protocol.allow", value); |
| 1104 | free(value); |
| 1105 | return ret; |
| 1106 | } |
| 1107 | |
| 1108 | /* fallback to built-in defaults */ |
| 1109 | /* known safe */ |
| 1110 | if (!strcmp(type, "http") || |
| 1111 | !strcmp(type, "https") || |
| 1112 | !strcmp(type, "git") || |
| 1113 | !strcmp(type, "ssh")) |
| 1114 | return PROTOCOL_ALLOW_ALWAYS; |
| 1115 | |
| 1116 | /* known scary; err on the side of caution */ |
| 1117 | if (!strcmp(type, "ext")) |
| 1118 | return PROTOCOL_ALLOW_NEVER; |
| 1119 | |
| 1120 | /* unknown; by default let them be used only directly by the user */ |
| 1121 | return PROTOCOL_ALLOW_USER_ONLY; |
| 1122 | } |
| 1123 | |
| 1124 | int is_transport_allowed(const char *type, int from_user) |
| 1125 | { |
no test coverage detected