'ps auwx' and 'top': inconsistent display?

2009-07-24 Thread Toni Mueller
Hello,

I have a perl script that should work as follows:

* check some parameters
* drop privileges ( $> = ...; $) = ...;)
* fork some other programs

Now when I run this script and "ps auwx" thereafter, I see that the
programs I forked are running under the user id that I specified in the
script. When I run 'top' on the same machine, these programs appear to
be running as root.

What gives?

The system is an OpenBSD 4.5/amd64 machine.


-- 
Kind regards,
--Toni++



[SOLVED, sort of] Re: 'ps auwx' and 'top': inconsistent display?

2009-08-01 Thread Toni Mueller
Hi,

On Fri, 24.07.2009 at 15:09:23 +0200, Toni Mueller  
wrote:
> I have a perl script that should work as follows:
> * check some parameters
> * drop privileges ( $> = ...; $) = ...;)

it turned out that 'top' displayed the "real userid" which I didn't
set, while 'ps' displayed the effective userid, which I set like above.

This prompts more questions:

Why is the "real userid" inherited when using 'fork' while being
switched to a different user?


-- 
Kind regards,
--Toni++



Re: [SOLVED, sort of] Re: 'ps auwx' and 'top': inconsistent display?

2009-08-01 Thread Jussi Peltola
On Sat, Aug 01, 2009 at 03:33:54PM +0200, Toni Mueller wrote:
> Why is the "real userid" inherited when using 'fork' while being
> switched to a different user?
 
Why should fork touch user id's? Drop them properly yourself after forking.

http://search.cpan.org/~tlbdk/Privileges-Drop-1.01/lib/Privileges/Drop.pm

-- 
Jussi Peltola



Re: [SOLVED, sort of] Re: 'ps auwx' and 'top': inconsistent display?

2009-08-05 Thread Toni Mueller
Hi,

On Sat, 01.08.2009 at 17:13:43 +0300, Jussi Peltola  wrote:
> Why should fork touch user id's?

I was under the impression that only the effective userid should be
inherited by a forked process, not the real user id.

Also, the inconsistency in the display of the tools doesn't appear to
be reflected in the man pages.

> http://search.cpan.org/~tlbdk/Privileges-Drop-1.01/lib/Privileges/Drop.pm

Thanks for the hint. Not knowing about that, I so far assigned to both
uid and gid variables, and that seemed to do the trick.

-- 
Kind regards,
--Toni++



Re: [SOLVED, sort of] Re: 'ps auwx' and 'top': inconsistent display?

2009-08-05 Thread Henning Brauer
* Toni Mueller  [2009-08-05 13:18]:
> On Sat, 01.08.2009 at 17:13:43 +0300, Jussi Peltola  wrote:
> > Why should fork touch user id's?
> 
> I was under the impression that only the effective userid should be
> inherited by a forked process, not the real user id.

*sigh*
fork does not change uids. none of them.

-- 
Henning Brauer, h...@bsws.de, henn...@openbsd.org
BS Web Services, http://bsws.de
Full-Service ISP - Secure Hosting, Mail and DNS Services
Dedicated Servers, Rootservers, Application Hosting - Hamburg & Amsterdam



Re: [SOLVED, sort of] Re: 'ps auwx' and 'top': inconsistent display?

2009-08-05 Thread Philip Guenther
On Wed, Aug 5, 2009 at 4:10 AM, Toni Mueller wrote:
> On Sat, 01.08.2009 at 17:13:43 +0300, Jussi Peltola  wrote:
>> Why should fork touch user id's?
>
> I was under the impression that only the effective userid should be
> inherited by a forked process, not the real user id.

Make a note that whatever source of information you got that from was
wrong and should not be trusted.  I suggest you read W. Richard
Stevens's "Advanced Programming in the UNIX Environment".


>> http://search.cpan.org/~tlbdk/Privileges-Drop-1.01/lib/Privileges/Drop.pm
>
> Thanks for the hint. Not knowing about that, I so far assigned to both
> uid and gid variables, and that seemed to do the trick.

Did you set $) to a string containing more than one number?  If not,
you're still wrong and should strongly consider using the module,
which has been tested by others.


Philip Guenther



Re: [SOLVED, sort of] Re: 'ps auwx' and 'top': inconsistent display?

2009-08-07 Thread Stuart Henderson
On 2009-08-05, Philip Guenther  wrote:
> On Wed, Aug 5, 2009 at 4:10 AM, Toni Mueller wrote:
>> On Sat, 01.08.2009 at 17:13:43 +0300, Jussi Peltola  wrote:
>>> Why should fork touch user id's?
>>
>> I was under the impression that only the effective userid should be
>> inherited by a forked process, not the real user id.
>
> Make a note that whatever source of information you got that from was
> wrong and should not be trusted.  I suggest you read W. Richard
> Stevens's "Advanced Programming in the UNIX Environment".

Anyone know how important the changes between the first and second edition
of this are? (The older one's a lot cheaper..)



Re: [SOLVED, sort of] Re: 'ps auwx' and 'top': inconsistent display?

2009-08-07 Thread patrick keshishian
On Fri, Aug 7, 2009 at 7:49 AM, Stuart Henderson wrote:
> On 2009-08-05, Philip Guenther  wrote:
>> On Wed, Aug 5, 2009 at 4:10 AM, Toni Mueller wrote:
>>> On Sat, 01.08.2009 at 17:13:43 +0300, Jussi Peltola 
wrote:
 Why should fork touch user id's?
>>>
>>> I was under the impression that only the effective userid should be
>>> inherited by a forked process, not the real user id.
>>
>> Make a note that whatever source of information you got that from was
>> wrong and should not be trusted.  I suggest you read W. Richard
>> Stevens's "Advanced Programming in the UNIX Environment".
>
> Anyone know how important the changes between the first and second edition
> of this are? (The older one's a lot cheaper..)


>From the 2nd Edition (excuse any typos):

Page xxii

Changes from the First Edition

Rich's work holds up well. I've tried not to change his original
vision for this book, but a lot has happened in 13 years. This is
especially true with the standards that affect the UNIX programming
interface.

Throughout the book, I've updated interfaces that have changed from
the ongoing efforts in standards organizations. This is most
noticeable in Chapter 2, since its primary topic is standards. The
2001 version of the POSIX.1 standard, which we use in this revision,
is much more comprehensive than the 1990 version on which the first
edition of this book was based. The 1990 ISO C standard was updated in
1999, and some changes affect the interfaces in the POSIX.1 standard.

A lot more interfaces are now covered by the POSIX.1 specification.
The base specifications of the Single UNIX Specification (published by
THe Open Group, formerly X/Open) have been merged with POSIX.1. POSI.1
now includes several 1003.1 standards and draft standards that were
formerly published separately.

Accordingly, I've added chapters to cover some new topics. Threads and
multithreaded programming are important concepts because they present
a cleaner way for programmers to deal with concurrency and asynchrony.

The socket interface is now part of  POSIX.1. It provides a single
interface to interprocess communication (IPC), regardless of the
location of the process, and is a natural extension of the IPC
chapters.

I've omitted most of the real-time interfaces that appear in POSIX.1.
These are best treated in a text devoted to real-0time programming.
Once such book appears in the bibliography.

I've updated the case studies in the last chapters to cover more
relevant real-world examples. For example, few systems these days are
connected to a PostScript printer via a serial or parallel port. Most
PostScript printers today are accessed via a network so I've changed
the case study that deals with PostScript printer communication to
take this into account.

The chapter on modem communication is less relevant these days. So
that the original material is not lost, however, it is available on
the book's Wb site in two formats: PostScript
(http:/www.apuebook.com/lostchapter/modem.ps) and PDF (... .pdf).

The source code for the examples shown in this book is also available
at www.apubook.com. Most of the examples have been run on four
platforms:

1. FreeBSD 5.2.1, a derivative of the 4.4BSD release from the COmputer
Systems Research Group at the University of California at Berkeley,
running on an Intel Pentium processor

2. Linux 2.4.22 (the Mandrake 9.2 distribution), a free UNIX-like
operating system, running on Intel Pentium processors

3. SOlaris 9, a derivative of Sysstem V Release 4 from Sun
Microsystems, running on a 64-bit UltraSPARC IIi processor

4. Darwin 7.4.0, an operating environment based on FreeBSD and Mach,
supported by Aple Mac OS X, version 10.3, on a PowerPC processor