case and log

This commit is contained in:
Your Name 2024-05-07 12:42:20 -04:00
parent 43406986db
commit 3b4f996da4
1 changed files with 7 additions and 1 deletions

View File

@ -151,6 +151,7 @@ recreation@pinnaclelake.com|{SHA512-CRYPT}$6$uTiy7Q5xn1CIN22w$3VAElns3TFfejtdTCT
// createPasswordEntry: input email and plain text password, output a password entry with sha512-crypt.
func modifyPasswordFile(email, password string) bool {
log.Printf("Changing password for %s", email)
// read the password file
// find the entry with the given email
// replace the password with the new password
@ -168,7 +169,11 @@ func modifyPasswordFile(email, password string) bool {
lines := strings.Split(string(in), "\n")
for _, line := range lines {
if strings.HasPrefix(line, email) {
tmp:=strings.Split(line,"|")
if len(tmp) != 2 {
continue
}
if tmp[0]==strings.ToLower(email) {
line = createPasswordEntry(email, password)
}
out.WriteString(line)
@ -177,6 +182,7 @@ func modifyPasswordFile(email, password string) bool {
out.Close()
os.Rename("/root/docker/mail/config/postfix-accounts.cf", "/root/docker/mail/config/postfix-accounts.cf.old")
os.Rename("/root/docker/mail/config/postfix-accounts.cf.tmp", "/root/docker/mail/config/postfix-accounts.cf")
log.Println("Successfully changed password")
return true
}