How is Unix socket credential passing accomplished in Python?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Internet searches on this topic came up with surprisingly few results. I figured I’d post the question and answer here for others interested in this topic.
The following client and server applications demonstrate how to accomplish this on Linux with the standard python interpreter. No extensions are required but, due to the use of embedded constants, the code is Linux-specific.
Server:
Client:
Unfortunately, the SO_PEERCRED and SO_PASSCRED constants are not exported by python’s socket module so they must be entered by hand. Although these value are unlikely to change it is possible. This should be considered by any applications using this approach.