From f8253d31583eda45a763e93c88c6da00bdeabfba Mon Sep 17 00:00:00 2001 From: Davies Liu Date: Thu, 31 Dec 2020 10:35:33 +0800 Subject: [PATCH] add license header for hdfs_kerberos.go --- object/hdfs_kerberos.go | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 object/hdfs_kerberos.go diff --git a/object/hdfs_kerberos.go b/object/hdfs_kerberos.go new file mode 100644 index 00000000..79130058 --- /dev/null +++ b/object/hdfs_kerberos.go @@ -0,0 +1,57 @@ +// Copyright (c) 2014 Colin Marc (colinmarc@gmail.com) +// borrowed from https://github.com/colinmarc/hdfs/blob/master/cmd/hdfs/kerberos.go + +package object + +import ( + "fmt" + "os" + "os/user" + "strings" + + krb "github.com/jcmturner/gokrb5/v8/client" + "github.com/jcmturner/gokrb5/v8/config" + "github.com/jcmturner/gokrb5/v8/credentials" +) + +func getKerberosClient() (*krb.Client, error) { + configPath := os.Getenv("KRB5_CONFIG") + if configPath == "" { + configPath = "/etc/krb5.conf" + } + + cfg, err := config.Load(configPath) + if err != nil { + return nil, err + } + + // Determine the ccache location from the environment, falling back to the + // default location. + ccachePath := os.Getenv("KRB5CCNAME") + if strings.Contains(ccachePath, ":") { + if strings.HasPrefix(ccachePath, "FILE:") { + ccachePath = strings.SplitN(ccachePath, ":", 2)[1] + } else { + return nil, fmt.Errorf("unusable ccache: %s", ccachePath) + } + } else if ccachePath == "" { + u, err := user.Current() + if err != nil { + return nil, err + } + + ccachePath = fmt.Sprintf("/tmp/krb5cc_%s", u.Uid) + } + + ccache, err := credentials.LoadCCache(ccachePath) + if err != nil { + return nil, err + } + + client, err := krb.NewFromCCache(ccache, cfg) + if err != nil { + return nil, err + } + + return client, nil +} -- GitLab