Unix Technical Forum

/bin/su closes open file descriptors ?

This is a discussion on /bin/su closes open file descriptors ? within the AIX Operating System forums, part of the Unix Operating Systems category; --> It seems that an AIX open file descriptor is not preserved across /bin/su. I have a program that opens ...


Go Back   Unix Technical Forum > Unix Operating Systems > AIX Operating System

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-04-2008, 09:27 PM
Chris Breemer
 
Posts: n/a
Default /bin/su closes open file descriptors ?

It seems that an AIX open file descriptor is not preserved across /bin/su.

I have a program that opens a file, then passes that file's file
descriptor to an exec'ed program with a command line argument. The
exec'ed program reads directly from that fd. No problem here, as file
descriptors are kept open across exec() calls.

But when I put /bin/su in between the calling and called program,
the called program gets errno 9 (Bad file descriptor) when
attempting to read. I guess somebody along the way (either su or sh)
has closed the file. I thought that perhaps a range of low fd's are
being closed (stdout, stderr, ...) so I tried dup2()'ing the fd to a
higher value (16 instead of 6) and use that instead. Same problem.

This same setup works well on other OS'es, e.g. Solaris. As often, AIX
is the odd one out. Anyone knows what's up here ? Or how to avoid/solve
this ?

TIA
Chris
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-04-2008, 09:28 PM
Nicholas Dronen
 
Posts: n/a
Default Re: /bin/su closes open file descriptors ?

Chris Breemer <chris_breemer@nl.compuware.com> wrote:
CB> It seems that an AIX open file descriptor is not preserved across /bin/su.

CB> I have a program that opens a file, then passes that file's file
CB> descriptor to an exec'ed program with a command line argument. The
CB> exec'ed program reads directly from that fd. No problem here, as file
CB> descriptors are kept open across exec() calls.

CB> But when I put /bin/su in between the calling and called program,
CB> the called program gets errno 9 (Bad file descriptor) when
CB> attempting to read. I guess somebody along the way (either su or sh)
CB> has closed the file. I thought that perhaps a range of low fd's are
CB> being closed (stdout, stderr, ...) so I tried dup2()'ing the fd to a
CB> higher value (16 instead of 6) and use that instead. Same problem.

CB> This same setup works well on other OS'es, e.g. Solaris. As often, AIX
CB> is the odd one out. Anyone knows what's up here ? Or how to avoid/solve
CB> this ?

It sounds like AIX's su behaves just like sudo does.

http://www.sudo.ws/pipermail/sudo-us...ly/001673.html

There's a suggestion in that thread for how to get around the
problem, but it's not pretty.

Regards,

Nicholas

--
http://www.faqs.org/rfcs/rfc1855.html
3.1.1 General Guidelines for mailing lists and NetNews
3.1.3 NetNews Guidelines
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-04-2008, 09:28 PM
Chris Breemer
 
Posts: n/a
Default Re: /bin/su closes open file descriptors ?

Nicholas Dronen <ndronen@io.frii.com> wrote in message news:<4016bd4d$0$70307$75868355@news.frii.net>...
[snip]

> It sounds like AIX's su behaves just like sudo does.
>
> http://www.sudo.ws/pipermail/sudo-us...ly/001673.html
>
> There's a suggestion in that thread for how to get around the
> problem, but it's not pretty.
>

Yes it seems exactly the same problem. I do not see a solution
in that thread though, except for the suggestion of using
a named socket instead of a pipe. Which is not useful for
me. I used a pipe only in my testing, the actual life
situation is a listener program that must pass an open
socket to a worker program invoked over su.

Thanks for the reply !
Cheers
Chris
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-04-2008, 09:28 PM
Nicholas Dronen
 
Posts: n/a
Default Re: /bin/su closes open file descriptors ?

Chris Breemer <chris_breemer@nl.compuware.com> wrote:
CB> Nicholas Dronen <ndronen@io.frii.com> wrote in message news:<4016bd4d$0$70307$75868355@news.frii.net>...
CB> [snip]
CB>
>> It sounds like AIX's su behaves just like sudo does.
>>
>> http://www.sudo.ws/pipermail/sudo-us...ly/001673.html
>>
>> There's a suggestion in that thread for how to get around the
>> problem, but it's not pretty.
>>

CB> Yes it seems exactly the same problem. I do not see a solution
CB> in that thread though, except for the suggestion of using
CB> a named socket instead of a pipe. Which is not useful for
CB> me. I used a pipe only in my testing, the actual life
CB> situation is a listener program that must pass an open
CB> socket to a worker program invoked over su.

Can't you make the program suid [ whoever ]?

Regards,

Nicholas

--
http://www.faqs.org/rfcs/rfc1855.html
3.1.1 General Guidelines for mailing lists and NetNews
3.1.3 NetNews Guidelines
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-04-2008, 09:29 PM
Chris Breemer
 
Posts: n/a
Default Re: /bin/su closes open file descriptors ?

Hi Nicholas,

> Can't you make the program suid [ whoever ]?
>

Yes, we have the option not to use su. Then the
listener just does setuid() and setgid() before
fork/exec'ing the server. That works without problem.

The reason we want to use su is so that the target user's
full logon environment is available to the server. I guess
we could use a shell to execute the target user's .profile,
but that would become cumbersome and clumsy compared
to using su.

Thanks again,

Chris
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:16 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com