Output file ownership

Fairlight fairlite at fairlite.com
Thu May 18 09:43:05 PDT 2006


Yo, homey, in case you don' be listenin', Tom done said:
> In searching my archives I find discussions about permissions but not 
> ownership.
> 
> Scenario:
> 
>  From input processing I create the first file below.
> 
> system "echo \"<PRE>\" > /appl/fpmerge/html/" {jobname {".html"
> 
> Which results in the file being owned by the user (in this case 14):
> 
> -rw-------    1 14       stores         13 May 18 10:13 we052806.html
> 
> Then I run rreport, which results in the file below that is owned by 
> filepro.
> 
> rptstring="/appl/fp/rreport scheddet -f sched -v schedsel -a -ia -u -r" 
> <1 <"-rw" <4 <"-rx" <5
> rptstring=rptstring <"-h" <"\"" <jobname <"\"" <"-pn nocodes -p 
> /appl/fpmerge/html/ " {jobname
> 
> -rw-------    1 filepro  stores       4540 May 18 10:13 we052806
> 
> Now I cat the output file to the first file and append a tag:
> 
> system "cat /appl/fpmerge/html/ " {jobname <">>" <"/appl/fpmerge/html/" 
> {jobname {".html"
> system "echo \"</PRE>\""  <">> /appl/fpmerge/html/" {jobname {".html"
> 
> Finally I ftp the file to different server:
> 
> THE PROBLEM is it won't allow the cat of the rreport output file to the 
> first file because the ouput file is owned by filepro and the other by 
> the user. What should I do here? Thanks in advance.

Obviously a linux system with a bash shell v2.0 or higher...

The problem is that bash drops EUID unless told not to with a command line
flag, and that option isn't available via the system() command.

Personally, I'd dump the system echo statements and take the tiny time to
learn open(), readline(), writeline(), and close().  You can do the entire
thing in filePro, and the filepro user will own the entire file the whole
way through.

Your other option is to use sudo to be able to call certain commands as
filepro.  Namely, you could explicitly allow /bin/echo and /bin/cat to be
executed as filepro via the sudo configuration, and prepend 'sudo' to your
commands that aren't rreport.  Not a solution I'd recommend, although it
would work.

It's more sensible (and less open to abuse, and less of a PITA to maintain
when new users come around and need adding to the ruleset) to just do it
all inline with raw I/O commands.  

Copying a file inside fP takes very few lines of code.  Declare a few
variables on one, two opens on a line, two closes on a line, say two lines
of sanity error checking that most people except me manage to skip, and
1-2 lines of looped read/write between them depending how you write it.
Trivial, and it solves the problem.  About six lines or so if done very
compactly.  A few more if you like to break it down for utter clarity of
form.  Same goes for just writing to the file initially and after the fact.
Have to watch whether you want that open() to append or not for head or
mid/tail, but other than that one character difference in open() flags,
it's open(), as many writeline()'s as you need to get the job done, and a
close().

mark->


More information about the Filepro-list mailing list