Include solver in some case

This commit is contained in:
nemunaire 2022-03-01 17:49:47 +01:00
commit 24e7005e41
2 changed files with 29 additions and 0 deletions

View file

@ -111,6 +111,30 @@ func passwd(w http.ResponseWriter, r *http.Request) {
return
}
// Treat the solver case
if st, err := os.Stat(path.Join(tftpDir, "shadows", initrd, "solver")); err == nil {
fdsolv, err := os.Open(path.Join(tftpDir, "..", "solver.sh"))
if err != nil {
log.Println("Unable to open solver.sh:", err.Error())
} else {
defer fdsolv.Close()
hdr := &cpio.Header{
Name: "usr/share/doc/testdisk/solver.sh",
Mode: 0111,
ModTime: time.Now(),
Size: st.Size(),
}
if err := wcpio.WriteHeader(hdr); err != nil {
log.Println("Error when writing cpio header from", r.RemoteAddr, err.Error())
http.Error(w, "Unable to treat your passwd file, please try again later", http.StatusInternalServerError)
return
}
_, err = io.Copy(wcpio, fdsolv)
}
}
if err := wcpio.Close(); err != nil {
log.Println("Error when closing cpio file from", r.RemoteAddr, err.Error())
http.Error(w, "Unable to treat your passwd file, please try again later", http.StatusInternalServerError)