mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-08-27 20:36:29 -04:00
Consistently use "age" when referencing age files, not "aging"
This commit is contained in:
+3
-6
@@ -29,7 +29,7 @@ func AgeEntry(vanityPath string, timestamp int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AgeAllPasswordEntries adds aging data for all un-aged entries containing passwords.
|
||||
// AgeAllPasswordEntries adds age data for all un-aged entries containing passwords.
|
||||
// Each entry is aged with a random timestamp from within the last year to prevent
|
||||
// all entries having their passwords expire at the same time.
|
||||
func AgeAllPasswordEntries(forceReage bool) error {
|
||||
@@ -39,7 +39,7 @@ func AgeAllPasswordEntries(forceReage bool) error {
|
||||
}
|
||||
|
||||
for _, vanityPath := range allVanityPaths {
|
||||
// ensure entry is not already aged (unless forcing re-aging)
|
||||
// ensure entry is not already aged (unless forcing re-age)
|
||||
if !forceReage {
|
||||
// ignore error; we only care if we can access the path or not
|
||||
isAccessible, _ := back.TargetIsFile(global.AgeDir+global.PathSeparator+strings.ReplaceAll(vanityPath, "/", global.FSPath), true)
|
||||
@@ -68,7 +68,7 @@ func AgeAllPasswordEntries(forceReage bool) error {
|
||||
}
|
||||
|
||||
// TranslateAgeTimestamp returns a uint8 value indicating
|
||||
// the interpreted age status of an aging timestamp associated
|
||||
// the interpreted age status of an age timestamp associated
|
||||
// with an entry.
|
||||
// Magic number legend:
|
||||
// 0 -> no age, 1 -> fresh, 2 -> expiring soon (within a month), 3 -> expired
|
||||
@@ -86,6 +86,3 @@ func TranslateAgeTimestamp(timestamp int64) uint8 {
|
||||
return 1 // fresh
|
||||
}
|
||||
}
|
||||
|
||||
// TODO
|
||||
// 1. Add sync support for the aging directory
|
||||
|
||||
+6
-6
@@ -18,7 +18,7 @@ import (
|
||||
)
|
||||
|
||||
// WriteEntry writes entryData to an encrypted file at realPath.
|
||||
// If the entry contains an updated password, an aging file is also created.
|
||||
// If the entry contains an updated password, an age file is also created.
|
||||
func WriteEntry(realPath string, decSlice []string, passwordIsNew bool) error {
|
||||
err := os.WriteFile(realPath, crypt.EncryptBytes([]byte(strings.Join(decSlice, "\n"))), 0600)
|
||||
if err != nil {
|
||||
@@ -26,16 +26,16 @@ func WriteEntry(realPath string, decSlice []string, passwordIsNew bool) error {
|
||||
}
|
||||
|
||||
if decSlice != nil {
|
||||
if passwordIsNew { // update aging data when password changes
|
||||
if decSlice[0] != "" { // if the password change was NOT a removal, update the aging file
|
||||
if passwordIsNew { // update age data when password changes
|
||||
if decSlice[0] != "" { // if the password change was NOT a removal, update the age file
|
||||
err = age.AgeEntry(global.GetVanityPath(realPath), time.Now().Unix())
|
||||
if err != nil {
|
||||
return errors.New("unable to update aging data: " + err.Error())
|
||||
return errors.New("unable to update age data: " + err.Error())
|
||||
}
|
||||
} else { // if the password change was a removal, remove the associated aging file
|
||||
} else { // if the password change was a removal, remove the associated age file
|
||||
err = syncclient.ShearRemoteFromClient(global.GetVanityPath(realPath), true)
|
||||
if err != nil {
|
||||
return errors.New("unable to remove aging data: " + err.Error())
|
||||
return errors.New("unable to remove age data: " + err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ var (
|
||||
EntryRoot = back.Home + "/.local/share/libmutton" // Path to libmutton entry directory
|
||||
ConfigDir = back.Home + "/.config/libmutton" // Path to libmutton configuration directory
|
||||
ConfigPath = ConfigDir + "/libmutton.ini" // Path to libmutton configuration file
|
||||
AgeDir = ConfigDir + "/aging" // Path to libmutton password aging database
|
||||
AgeDir = ConfigDir + "/age" // Path to libmutton password age directory
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -8,7 +8,7 @@ var (
|
||||
EntryRoot = back.Home + "\\AppData\\Local\\libmutton\\entries" // Path to libmutton entry directory
|
||||
ConfigDir = back.Home + "\\AppData\\Local\\libmutton\\config" // Path to libmutton configuration directory
|
||||
ConfigPath = ConfigDir + "\\libmutton.ini" // Path to libmutton configuration file
|
||||
AgeDir = ConfigDir + "\\aging" // Path to libmutton password aging database
|
||||
AgeDir = ConfigDir + "\\age" // Path to libmutton password age directory
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ func DirInit(preserveOldConfigDir bool) (string, error) {
|
||||
return "", errors.New("unable to create \"" + ConfigDir + "\": " + err.Error())
|
||||
}
|
||||
|
||||
// create password aging directory
|
||||
// create password age directory
|
||||
err = os.MkdirAll(AgeDir, 0700)
|
||||
if err != nil {
|
||||
return "", errors.New("unable to create \"" + AgeDir + "\": " + err.Error())
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ func main() {
|
||||
// stdin[1] is expected to be the vanityPath with FSPath representing path separators - Always pass in UNIX format
|
||||
_, _, _ = synccommon.ShearLocal(strings.ReplaceAll(stdin[1], global.FSPath, "/"), stdin[0], false)
|
||||
case "shear-age":
|
||||
// shear ONLY the aging file associated with an entry from the server and add it to the deletions directory
|
||||
// shear ONLY the age file associated with an entry from the server and add it to the deletions directory
|
||||
// stdin[0] is expected to be the device ID
|
||||
// stdin[1] is expected to be the vanityPath with FSPath representing path separators - Always pass in UNIX format
|
||||
_, _, _ = synccommon.ShearLocal(strings.ReplaceAll(stdin[1], global.FSPath, "/"), stdin[0], true)
|
||||
|
||||
@@ -15,8 +15,8 @@ import (
|
||||
// It can safely be called in offline mode, as well, so this is
|
||||
// the intended interface for shearing (ShearLocal should only
|
||||
// be used directly by the server binary).
|
||||
func ShearRemoteFromClient(vanityPath string, onlyShearAgingFile bool) error {
|
||||
deviceID, isDir, err := synccommon.ShearLocal(vanityPath, "", onlyShearAgingFile) // remove the target from the local system and get the device ID of the client
|
||||
func ShearRemoteFromClient(vanityPath string, onlyShearAgeFile bool) error {
|
||||
deviceID, isDir, err := synccommon.ShearLocal(vanityPath, "", onlyShearAgeFile) // remove the target from the local system and get the device ID of the client
|
||||
if err != nil {
|
||||
return errors.New("unable to shear target locally: " + err.Error())
|
||||
}
|
||||
@@ -39,7 +39,7 @@ func ShearRemoteFromClient(vanityPath string, onlyShearAgingFile bool) error {
|
||||
}
|
||||
|
||||
// call the server to remotely shear the target and add it to the deletions list
|
||||
if onlyShearAgingFile {
|
||||
if onlyShearAgeFile {
|
||||
modifier = "-age"
|
||||
}
|
||||
_, err = GetSSHOutput(sshClient, "libmuttonserver shear"+modifier, deviceID+"\n"+strings.ReplaceAll(vanityPath, global.PathSeparator, global.FSPath))
|
||||
|
||||
@@ -32,7 +32,7 @@ func GetModTimes(entryList []string) []int64 {
|
||||
// isDir (only on client; for use in ShearRemoteFromClient).
|
||||
// If the local system is a server, it will also add the target to the deletions list for all clients (except the requesting client).
|
||||
// This function should only be used directly by the server binary.
|
||||
func ShearLocal(vanityPath, clientDeviceID string, onlyShearAgingFile bool) (string, bool, error) {
|
||||
func ShearLocal(vanityPath, clientDeviceID string, onlyShearAgeFile bool) (string, bool, error) {
|
||||
// determine if running on a server
|
||||
var onServer bool
|
||||
if clientDeviceID != "" {
|
||||
@@ -48,7 +48,7 @@ func ShearLocal(vanityPath, clientDeviceID string, onlyShearAgingFile bool) (str
|
||||
if onServer {
|
||||
for _, device := range deviceIDList {
|
||||
if device.Name() != clientDeviceID {
|
||||
if !onlyShearAgingFile {
|
||||
if !onlyShearAgeFile {
|
||||
f, err := os.OpenFile(global.ConfigDir+global.PathSeparator+"deletions"+global.PathSeparator+device.Name()+global.FSSpace+"entry"+global.FSSpace+strings.ReplaceAll(vanityPath, "/", global.FSPath), os.O_CREATE|os.O_WRONLY, 0600)
|
||||
if err != nil {
|
||||
// do not print error as there is currently no way of seeing server-side errors
|
||||
@@ -80,7 +80,7 @@ func ShearLocal(vanityPath, clientDeviceID string, onlyShearAgingFile bool) (str
|
||||
isFile = true
|
||||
}
|
||||
}
|
||||
if !onlyShearAgingFile {
|
||||
if !onlyShearAgeFile {
|
||||
err = os.RemoveAll(realPath)
|
||||
if err != nil {
|
||||
return "", false, errors.New("unable to remove local entry (" + vanityPath + "): " + err.Error())
|
||||
@@ -109,12 +109,12 @@ func ShearAgeFileLocal(vanityPath string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetEntryAges reads the aging directory and returns a
|
||||
// GetEntryAges reads the age directory and returns a
|
||||
// map of vanity paths to their corresponding age timestamps.
|
||||
func GetEntryAges() (map[string]int64, error) {
|
||||
contents, err := os.ReadDir(global.AgeDir)
|
||||
if err != nil {
|
||||
return nil, errors.New("unable to read aging directory contents: " + err.Error())
|
||||
return nil, errors.New("unable to read age directory contents: " + err.Error())
|
||||
}
|
||||
|
||||
var vanityPathsToTimestamps = make(map[string]int64)
|
||||
@@ -123,7 +123,7 @@ func GetEntryAges() (map[string]int64, error) {
|
||||
vanityPath := strings.ReplaceAll(dirEntry.Name(), global.FSPath, "/")
|
||||
info, err := dirEntry.Info()
|
||||
if err != nil {
|
||||
return nil, errors.New("unable to read aging file modtime for " + vanityPath + ": " + err.Error())
|
||||
return nil, errors.New("unable to read age file modtime for " + vanityPath + ": " + err.Error())
|
||||
}
|
||||
vanityPathsToTimestamps[vanityPath] = info.ModTime().Unix()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user