Sì, questo è possibile su Linux, ma non sarà molto portabile. È realizzato utilizzando i cosiddetti "dati ausiliari" con sendmsg
/recvmsg
.
- Usa
SO_PASSCRED
con setsockopt
- Usa
SCM_CREDENTIALS
e la struttura struct ucred
Tale struttura è definita in Linux:
struct ucred {
pid_t pid; /* process ID of the sending process */
uid_t uid; /* user ID of the sending process */
gid_t gid; /* group ID of the sending process */
};
Nota che devi compilare questi nella vostra msghdr.control
, e il kernel controllerà se sono corretti.
La portabilità principale ostacolo è che questa struttura si differenzia da altri sistemi Unix - per esempio su FreeBSD è:
struct cmsgcred {
pid_t cmcred_pid; /* PID of sending process */
uid_t cmcred_uid; /* real UID of sending process */
uid_t cmcred_euid; /* effective UID of sending process */
gid_t cmcred_gid; /* real GID of sending process */
short cmcred_ngroups; /* number or groups */
gid_t cmcred_groups[CMGROUP_MAX]; /* groups */
};
Grazie mille. Esattamente quello che stavo cercando. La portabilità non è un problema. Il codice verrà eseguito solo su Android come codice nativo comunque. –