From 8827d67cc6c415efbbe3208d05e254c27352ef4e Mon Sep 17 00:00:00 2001 From: Russ Magee Date: Mon, 29 Jan 2024 21:37:07 -0800 Subject: [PATCH] unified refs to authtoken file to a const string --- auth.go | 5 +++-- xs/xs.go | 4 ++-- xsd/xsd.go | 2 +- xsnet/consts.go | 2 ++ 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/auth.go b/auth.go index ecec371..ebca33e 100755 --- a/auth.go +++ b/auth.go @@ -23,6 +23,7 @@ import ( "runtime" "strings" + "blitter.com/go/xs/xsnet" "github.com/jameskeane/bcrypt" passlib "gopkg.in/hlandau/passlib.v1" ) @@ -172,9 +173,9 @@ func AuthUserByToken(ctx *AuthCtx, username string, connhostname string, auth st return false } - b, e := ctx.reader(fmt.Sprintf("%s/.config/xs/.xs_id", u.HomeDir)) + b, e := ctx.reader(fmt.Sprintf("%s/%s", u.HomeDir, xsnet.XS_ID_AUTHTOKFILE)) if e != nil { - log.Printf("INFO: Cannot read %s/.config/xs/.xs_id\n", u.HomeDir) + log.Printf("INFO: Cannot read %s/%s\n", u.HomeDir, xsnet.XS_ID_AUTHTOKFILE) return false } diff --git a/xs/xs.go b/xs/xs.go index dde5a66..83c89c1 100755 --- a/xs/xs.go +++ b/xs/xs.go @@ -887,7 +887,7 @@ func main() { //nolint: funlen, gocyclo if !gopt { // See if we can log in via an auth token u, _ := user.Current() - ab, aerr := os.ReadFile(fmt.Sprintf("%s/.config/xs/.xs_id", u.HomeDir)) + ab, aerr := os.ReadFile(fmt.Sprintf("%s/%s", u.HomeDir, xsnet.XS_ID_AUTHTOKFILE)) if aerr == nil { for _, line := range strings.Split(string(ab), "\n") { line += "\n" @@ -905,7 +905,7 @@ func main() { //nolint: funlen, gocyclo _, _ = fmt.Fprintln(os.Stderr, "[no authtoken, use -g to request one from server]") } } else { - log.Printf("[cannot read %s/.xs_id]\n", u.HomeDir) + log.Printf("[cannot read %s/%s]\n", u.HomeDir, xsnet.XS_ID_AUTHTOKFILE) } } runtime.GC() diff --git a/xsd/xsd.go b/xsd/xsd.go index 8139235..346274b 100755 --- a/xsd/xsd.go +++ b/xsd/xsd.go @@ -841,7 +841,7 @@ func main() { //nolint:funlen,gocyclo hname := goutmp.GetHost(addr.String()) logger.LogNotice(fmt.Sprintf("[Generating autologin token for [%s@%s]]\n", rec.Who(), hname)) //nolint:errcheck token := GenAuthToken(string(rec.Who()), string(rec.ConnHost())) - tokenCmd := fmt.Sprintf("echo %q | tee -a ~/.config/xs/.xs_id", token) + tokenCmd := fmt.Sprintf("echo %q | tee -a ~/%s", token, xsnet.XS_ID_AUTHTOKFILE) cmdStatus, runErr := runShellAs(string(rec.Who()), hname, string(rec.TermType()), tokenCmd, false, hc, chaffEnabled) // Returned hopefully via an EOF or exit/logout; // Clear current op so user can enter next, or EOF diff --git a/xsnet/consts.go b/xsnet/consts.go index 5c03c15..1d7e9c8 100644 --- a/xsnet/consts.go +++ b/xsnet/consts.go @@ -140,3 +140,5 @@ const ( CHAFF_FREQ_MSECS_MIN = 1 CHAFF_FREQ_MSECS_MAX = 300000 // 5 minutes ) + +const XS_ID_AUTHTOKFILE = ".config/xs/.xs_id"