mirror of
https://github.com/rwinkhart/rcw.git
synced 2026-09-01 06:46:40 -04:00
Attempt to fix unexpected EOF on Solaris
This commit is contained in:
@@ -24,12 +24,16 @@ func Start(password []byte) {
|
||||
globalPassword = password
|
||||
|
||||
// register RCWService with the RPC package
|
||||
if err := rpc.Register(&RCWService{}); err != nil {
|
||||
err := rpc.Register(&RCWService{})
|
||||
if err != nil {
|
||||
log.Fatalf("Error registering RPC service: %v", err)
|
||||
}
|
||||
|
||||
// store the hash of the daemon binary
|
||||
daemonHash = getFileHash(binPath)
|
||||
daemonHash, err = getFileHash(binPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Error hashing daemon binary: %v", err)
|
||||
}
|
||||
|
||||
// listen on the Unix domain socket
|
||||
listener, err := net.Listen("unix", socketPath)
|
||||
@@ -80,7 +84,15 @@ func handleConn(conn net.Conn, sigChan chan os.Signal) {
|
||||
|
||||
// check if the RPC call is coming from an identical binary and from the same user
|
||||
callingBinPath := pidToPath(ucred.PID)
|
||||
if ucred.UID == strconv.Itoa(os.Getuid()) && bytes.Equal(getFileHash(callingBinPath), daemonHash) {
|
||||
callingBinHash, err := getFileHash(callingBinPath)
|
||||
if err != nil {
|
||||
// calling binary hash failure
|
||||
conn.Close()
|
||||
log.Printf("Failed to hash calling binary: PID(%d), UID(%s), Path(%s) - %v", ucred.PID, ucred.UID, callingBinPath, err)
|
||||
sigChan <- syscall.SIGTERM // this zeroizes globalPassword and triggers os.Exit(0)
|
||||
return // explicitly return to avoid race
|
||||
}
|
||||
if ucred.UID == strconv.Itoa(os.Getuid()) && bytes.Equal(callingBinHash, daemonHash) {
|
||||
// valid client; hand off the connection to the RPC server
|
||||
rpc.ServeConn(conn)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user