ipc_security.c 496 B

12345678910111213141516171819202122232425262728293031
  1. #define _GNU_SOURCE
  2. #include <stdio.h>
  3. #include "ipc.h"
  4. /*
  5. return
  6. 0 - socket secure
  7. else not
  8. */
  9. int checkSocketSecurity( int socket ){
  10. struct ucred peer;
  11. socklen_t peerSize;
  12. //get remote peer uid and gid
  13. peerSize = sizeof( peer );
  14. if( getsockopt(socket, SOL_SOCKET, SO_PEERCRED, &peer, &peerSize) ){
  15. perror( "getsockopt" );
  16. return -1;
  17. }
  18. //if remote peer user or group is root
  19. //if( !peer.uid || !peer.gid ) return 0;
  20. //only root
  21. if( !peer.uid ) return 0;
  22. return 1;
  23. }