unified refs to authtoken file to a const string

This commit is contained in:
Russ Magee 2024-01-29 21:37:07 -08:00
parent 17d7bc01ef
commit 8827d67cc6
4 changed files with 8 additions and 5 deletions

View File

@ -23,6 +23,7 @@ import (
"runtime" "runtime"
"strings" "strings"
"blitter.com/go/xs/xsnet"
"github.com/jameskeane/bcrypt" "github.com/jameskeane/bcrypt"
passlib "gopkg.in/hlandau/passlib.v1" passlib "gopkg.in/hlandau/passlib.v1"
) )
@ -172,9 +173,9 @@ func AuthUserByToken(ctx *AuthCtx, username string, connhostname string, auth st
return false 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 { 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 return false
} }

View File

@ -887,7 +887,7 @@ func main() { //nolint: funlen, gocyclo
if !gopt { if !gopt {
// See if we can log in via an auth token // See if we can log in via an auth token
u, _ := user.Current() 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 { if aerr == nil {
for _, line := range strings.Split(string(ab), "\n") { for _, line := range strings.Split(string(ab), "\n") {
line += "\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]") _, _ = fmt.Fprintln(os.Stderr, "[no authtoken, use -g to request one from server]")
} }
} else { } 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() runtime.GC()

View File

@ -841,7 +841,7 @@ func main() { //nolint:funlen,gocyclo
hname := goutmp.GetHost(addr.String()) hname := goutmp.GetHost(addr.String())
logger.LogNotice(fmt.Sprintf("[Generating autologin token for [%s@%s]]\n", rec.Who(), hname)) //nolint:errcheck logger.LogNotice(fmt.Sprintf("[Generating autologin token for [%s@%s]]\n", rec.Who(), hname)) //nolint:errcheck
token := GenAuthToken(string(rec.Who()), string(rec.ConnHost())) 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) cmdStatus, runErr := runShellAs(string(rec.Who()), hname, string(rec.TermType()), tokenCmd, false, hc, chaffEnabled)
// Returned hopefully via an EOF or exit/logout; // Returned hopefully via an EOF or exit/logout;
// Clear current op so user can enter next, or EOF // Clear current op so user can enter next, or EOF

View File

@ -140,3 +140,5 @@ const (
CHAFF_FREQ_MSECS_MIN = 1 CHAFF_FREQ_MSECS_MIN = 1
CHAFF_FREQ_MSECS_MAX = 300000 // 5 minutes CHAFF_FREQ_MSECS_MAX = 300000 // 5 minutes
) )
const XS_ID_AUTHTOKFILE = ".config/xs/.xs_id"