472,989 Members | 3,064 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

Unix domain sockets / IPC - how to get remote process/user id?

Hi folks,

I am unable to solve the following problem, which should not be new,
but I cannot find an appropriate solution anywhere:

One python process ("daemon") waits for messages. Another python
program ("client"), which is NOT forked off the daemon (but is on the
same Linux machine), sends that message to the daemon.

This of course can be nicely done with Unix domain sockets (AF_UNIX),
but additionally I want the daemon to know the process or user id of
the client. The client could of course include this info in the
message, but then it also could fake it, which I want to prevent.
Therefore it must come somewhere from the kernel.

My hope was that the address returned from socket.recvfrom would help,
but with python 2.3.3 on Debian, the returned address is always None
(a bit odd, python 2.1? at least returned a (meaningless?)
int,emptystring-tupel). I know that Unix domain sockets can return
those info (in structure called credentials), but obviously python
does not handle them?

So, for my question: What are my options? I cannot believe I am the
first with this problem. Preferable, only standard python packages
should be used.

Thanks in advance, Fossie
Jul 18 '05 #1
5 3732
On Mon, Feb 09, 2004 at 03:39:34PM -0800, Fossie wrote:
So, for my question: What are my options? I cannot believe I am the
first with this problem. Preferable, only standard python packages
should be used.


My Linux manpage for unix(7) indicates that SCM_RIGHTS is not portable.
(I am not 100% sure this is what you're talking about, because it's
nothing I've ever done before) In any case, I looked but didn't find an
implementation of the needed sendmsg(2) .. I found only this:
https://sourceforge.net/tracker/?fun...&group_id=5470
Wrapping sendmsg with pyrex, ctypes, or even with a new C module might
be a good first project in extending Python. If you do your work in
the form of a patch to Python, I suspect it would easily gain approval.
Once you'd tested your patch and added tests for it, you'd submit the
patch to the bug I mentioned above or as a new item in the Patch area.

best of luck,
Jeff

Jul 18 '05 #2
go**@fossie.net (Fossie) writes:
So, for my question: What are my options? I cannot believe I am the
first with this problem. Preferable, only standard python packages
should be used.


Unfortunately that capability is missing from the sockets package. I
have a bug in sourceforge about it and was invited to contribute a
patch but haven't gotten around to it. Maybe you'd like to take a turn?

Jul 18 '05 #3
Jeff Epler <je****@unpythonic.net> writes:
On Mon, Feb 09, 2004 at 03:39:34PM -0800, Fossie wrote:
So, for my question: What are my options? I cannot believe I am the
first with this problem. Preferable, only standard python packages
should be used.


My Linux manpage for unix(7) indicates that SCM_RIGHTS is not portable.
(I am not 100% sure this is what you're talking about, because it's
nothing I've ever done before) In any case, I looked but didn't find an
implementation of the needed sendmsg(2) .. I found only this:
https://sourceforge.net/tracker/?fun...&group_id=5470


Yes, that is the right way to do it, with a patch as suggested in that
bug report.
Jul 18 '05 #4
On Mon, Feb 09, 2004 at 07:22:30PM -0600, Jeff Epler wrote:
On Mon, Feb 09, 2004 at 03:39:34PM -0800, Fossie wrote:
So, for my question: What are my options? I cannot believe I am the
first with this problem. Preferable, only standard python packages
should be used.


My Linux manpage for unix(7) indicates that SCM_RIGHTS is not portable.
(I am not 100% sure this is what you're talking about, because it's
nothing I've ever done before) In any case, I looked but didn't find an
implementation of the needed sendmsg(2) .. I found only this:
https://sourceforge.net/tracker/?fun...&group_id=5470
Wrapping sendmsg with pyrex, ctypes, or even with a new C module might
be a good first project in extending Python. If you do your work in
the form of a patch to Python, I suspect it would easily gain approval.
Once you'd tested your patch and added tests for it, you'd submit the
patch to the bug I mentioned above or as a new item in the Patch area.


There's a wrapper for sendmsg(2) in Twisted's sandbox:

http://cvs.twistedmatrix.com/cvs/sandbox/pahan/sendmsg/

This may be a good start. It'd be great to have this in the stdlib.

Jp

Jul 18 '05 #5
Thanks to all for your answers!

I had a look at the sendmsg wrapper from twistedmatrix, but without
any documentation (not even some short comments) it is a bit hard to
use. It seems to support file descriptor passing (SCM_RIGHTS) but
would need some extra coding to support the SCM_CREDENTIAL structure,
which seems to be system dependent anyway, as stated by Jeff (see unix
man page, I had another impression from a short glimpse into Richard
Stevens' networking books..)

All in all, since I am neither a linux nor a network/ipc nor a c
expert [thats why I am using Python ;) ], I was looking more for a
ready-to-use thing.

Therefore, I had a closer look at the system V shared memory (and
semaphore) module (shm), which I found at:
http://gigue.peabody.jhu.edu/~mdboom...ource/shm.html

Its another kind of interprocess communication than I originally
wanted, but does what I need (giving uid/pid) without any
modification. It should be portable (ok, maybe not to windows) and is
good documented (at least sufficiently for me). This looks like a
candidate (useful, portable, documented) for the standard python
library to me..

Thanks again, Fossie
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: afalanga | last post by:
Hi, I seem to be unable to connect to my PostgreSQL database over UNIX domain sockets, i.e. pg_connect("dbname=mydb"); No matter what I do to the pg_hba.conf file, or anything else, PHP...
5
by: Virgil Green | last post by:
An associate has asked me to take a look a problem he's having with starting mysql. I thought I'd give it a shot to learn some more about mySQL before having him turn it over to someone more...
4
by: Alex Martinoff | last post by:
Using the org.postgresql.Driver JDBC driver is it possible to connect to Postgres using a unix domain socket instead of a TCP socket (so you don't have to start the postmaster with -i)? Using a TCP...
3
by: David | last post by:
Hi, Ive been trying to work this out for the past 2 days now and im not getting anywhere fast. The problem i have is that i am using Asynchronous sockets to create a Socket Client library....
6
by: Laxmikant Rashinkar | last post by:
Is there any way to use a C# socket in promiscuous mode? Any sample code that shows how this is done? any assistance is much appreciated! thanks LK
15
by: Alpha | last post by:
I was told that Unix API can only be called using C++, ATL and MFC. However, I was also told that C# can do that through Pinvoke to a DLL that interfaces with the Unix API. Can someone direct me...
5
by: Tomas | last post by:
Hey all, I've worked with DB2 for a long time, but it looks like Windows and user management is getting the better of me. I'm trying to set up a DB2 9 Express-C system. It's installed and...
21
by: Tom Gur | last post by:
Hi, It's seems that csh and tcsh acts a bit different when handling special characters in quotes. i.e: if i'll supply my program with the following arguments: -winpath "c:\\temp\\" tcsh will...
1
by: Chris | last post by:
Hi, I am using PHP persistent sockets and have a problem with them. The problem is that PHP only sends the data when the socket is closed. In the code example below the counterparty process...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.