login-validator: Add gzip compression

This commit is contained in:
nemunaire 2022-02-26 21:34:26 +01:00
parent aa753b4075
commit f317d11fac

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"compress/gzip"
"fmt" "fmt"
"io" "io"
"log" "log"
@ -53,7 +54,8 @@ func passwd(w http.ResponseWriter, r *http.Request) {
defer fd.Close() defer fd.Close()
// Generate the new cpio archive // Generate the new cpio archive
wcpio := cpio.NewWriter(fd) zw := gzip.NewWriter(fd)
wcpio := cpio.NewWriter(zw)
hdr := &cpio.Header{ hdr := &cpio.Header{
Name: "etc/shadow", Name: "etc/shadow",
@ -83,6 +85,12 @@ func passwd(w http.ResponseWriter, r *http.Request) {
return return
} }
if err := zw.Close(); err != nil {
log.Println("Error when closing gzip file from", r.RemoteAddr, err.Error())
http.Error(w, "Unable to treat your passwd file, please try again later", http.StatusInternalServerError)
return
}
log.Println("Registered shadow from", r.RemoteAddr) log.Println("Registered shadow from", r.RemoteAddr)
http.Error(w, "Success", http.StatusOK) http.Error(w, "Success", http.StatusOK)
} }