Created attachment 16666 [details]
The pam_wrapper assumes that the PID is smaller than 0xFFFF, which is no longer the case (at least for several years in Linux).
This is very similar construct that used to be in libssh too  and caused pain there so I would suggest to fix it in very same manner (see attached patch).
Created attachment 16667 [details]
proposed patch (without unrelated changes)
Filled as a MR in https://gitlab.com/cwrap/pam_wrapper/-/merge_requests/13