( fileName string, inMatch bool, visited map[string]bool, directives *[]sshDirective, fileList *[]sshConfigFile, order *int, priority *int, )
| 859 | } |
| 860 | |
| 861 | func parseSSHConfigFile( |
| 862 | fileName string, |
| 863 | inMatch bool, |
| 864 | visited map[string]bool, |
| 865 | directives *[]sshDirective, |
| 866 | fileList *[]sshConfigFile, |
| 867 | order *int, |
| 868 | priority *int, |
| 869 | ) error { |
| 870 | absolutePath, err := filepath.Abs(fileName) |
| 871 | if err != nil { |
| 872 | return err |
| 873 | } |
| 874 | if visited[absolutePath] { |
| 875 | return nil |
| 876 | } |
| 877 | visited[absolutePath] = true |
| 878 | |
| 879 | content, err := os.ReadFile(absolutePath) |
| 880 | if err != nil { |
| 881 | return err |
| 882 | } |
| 883 | |
| 884 | lines := strings.Split(string(content), "\n") |
| 885 | currentMatch := inMatch |
| 886 | fileRegistered := false |
| 887 | for index, rawLine := range lines { |
| 888 | line := strings.TrimSpace(rawLine) |
| 889 | if line == "" || strings.HasPrefix(line, "#") { |
| 890 | continue |
| 891 | } |
| 892 | key, value, ok := parseSSHConfigLine(line) |
| 893 | if !ok { |
| 894 | continue |
| 895 | } |
| 896 | if strings.EqualFold(key, "Match") { |
| 897 | currentMatch = true |
| 898 | continue |
| 899 | } |
| 900 | if strings.EqualFold(key, "Include") { |
| 901 | for _, includePath := range expandSSHIncludePaths(absolutePath, value) { |
| 902 | if err := parseSSHConfigFile(includePath, currentMatch, visited, directives, fileList, order, priority); err != nil { |
| 903 | global.LOG.Warnf("parse ssh include %s failed, err: %v", includePath, err) |
| 904 | } |
| 905 | } |
| 906 | continue |
| 907 | } |
| 908 | if !fileRegistered { |
| 909 | registerSSHConfigFile(absolutePath, fileList, priority) |
| 910 | fileRegistered = true |
| 911 | } |
| 912 | *order++ |
| 913 | *directives = append(*directives, sshDirective{ |
| 914 | Key: key, |
| 915 | Value: normalizeSSHDirectiveValue(key, value), |
| 916 | File: absolutePath, |
| 917 | Line: index, |
| 918 | InMatch: currentMatch, |
no test coverage detected