Skip to content

Error if no krb5.conf is found. #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions gss/gokrb5.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/bodgit/tsig"
"github.com/bodgit/tsig/internal/util"
"github.com/go-logr/logr"
multierror "github.com/hashicorp/go-multierror"
"github.com/jcmturner/gokrb5/v8/client"
"github.com/jcmturner/gokrb5/v8/config"
"github.com/jcmturner/gokrb5/v8/credentials"
Expand Down Expand Up @@ -345,25 +346,39 @@ func loadCache() (*credentials.CCache, error) {
return cache, nil
}

func findFile(env string, try []string) (string, error) {
path, ok := os.LookupEnv(env)
if ok {
if _, err := os.Stat(path); err != nil {
return "", err
}
return path, nil
}

var errs error
for _, t := range try {
_, err := os.Stat(t)
if err != nil {
errs = multierror.Append(errs, err)
if os.IsNotExist(err) {
continue
}
return "", errs
}
return t, nil
}

return "", errs
}

func (c *Client) loadConfig() (*config.Config, error) {
if c.config != "" {
return config.NewFromString(c.config)
}

path := os.Getenv("KRB5_CONFIG")
_, err := os.Stat(path)
path, err := findFile("KRB5_CONFIG", []string{"/etc/krb5.conf"})
if err != nil {

// List of candidates to try
try := []string{"/etc/krb5.conf"}

for _, t := range try {
_, err := os.Stat(t)
if err == nil {
path = t
break
}
}
return nil, err
}

return config.Load(path)
Expand Down