@@ -14,6 +14,7 @@ import (
1414 "fmt"
1515 "io/ioutil"
1616 "regexp"
17+ "strings"
1718 "time"
1819
1920 "gopkg.in/yaml.v2"
@@ -170,9 +171,9 @@ func replace(src string, replacer *patternReplacer) string {
170171}
171172
172173// LoadConfig load configuration file and adapt it according to specified user.
173- func LoadConfig (filename , username , sid string , start time.Time , groups map [string ]bool ) (* Config , error ) {
174+ func LoadConfig (filename , currentUsername , sid string , start time.Time , groups map [string ]bool ) (* Config , error ) {
174175 patterns := map [string ]* patternReplacer {
175- "{user}" : {regexp .MustCompile (`{user}` ), username },
176+ "{user}" : {regexp .MustCompile (`{user}` ), currentUsername },
176177 "{sid}" : {regexp .MustCompile (`{sid}` ), sid },
177178 "{time}" : {regexp .MustCompile (`{time}` ), start .Format (time .RFC3339Nano )},
178179 }
@@ -198,17 +199,27 @@ func LoadConfig(filename, username, sid string, start time.Time, groups map[stri
198199 config .SSH .Args = defaultSSHArgs
199200 }
200201
201- for groupname , groupconfig := range config .Groups {
202- if groups [groupname ] {
203- if err := parseSubConfig (& config , & groupconfig ); err != nil {
204- return nil , err
202+ for groupnames , groupconfig := range config .Groups {
203+ for _ , groupname := range strings .Split (groupnames , "," ) {
204+ if groups [groupname ] {
205+ if err := parseSubConfig (& config , & groupconfig ); err != nil {
206+ return nil , err
207+ }
208+ // no need to to parse the same subconfig twice
209+ break
205210 }
206211 }
207212 }
208213
209- if userconfig , present := config .Users [username ]; present {
210- if err := parseSubConfig (& config , & userconfig ); err != nil {
211- return nil , err
214+ for usernames , userconfig := range config .Users {
215+ for _ , username := range strings .Split (usernames , "," ) {
216+ if username == currentUsername {
217+ if err := parseSubConfig (& config , & userconfig ); err != nil {
218+ return nil , err
219+ }
220+ // no need to to parse the same subconfig twice
221+ break
222+ }
212223 }
213224 }
214225
0 commit comments