[comp.unix.i386] Unlinking files mimicing "rm -f"

cs223130@umbc5.umbc.edu (CMSC 223/01011) (03/02/90)

     The discussion regarding the efficency of unlink() -vs- chdir() has
reminded me of a problem I have encountered that maybe someone on the
net could help me with.  I had written a routine that a daemon process
uses to remove files from a directory based on certain criteria. The
problem I have run across concerns different ownerships of files in a
directory by another owner. For example...

    drwxrwx--- joeblow joesgrp  foodir

is owned by "joeblow", yet files in the directory are owned by most
anyone in "joesgrp". (i.e. janedoe or danquayl). The problem arises when
a process running as joeblow wants to remove entries in "foodir" that
are not owned by him. A regular call to unlink() prompts the user if
they really want to remove the file. How do I disable this feature in
a C program using UNIX system calls -vs- invoking "system("rm -f
filename)" which seems to be slower because of an additional call to
invoke the shell. It is also desirable for a daemon process that wants
no user interaction whatsoever. This process runs on System V version
2.2. (Yeah I know it's old but I have no say on upgrades) The machine
is an AT&T 3b15. Any help with this would be greatly appreciated.

              Thanks in advance,
                  Dan Brown

P.S. To clarify, The problem will only arise when the file owned by
janedoe does not give write permissions to joeblow or joesgrp.
I can't remember the exact wording of the question but I think is goes
something like this.

"rm filename mode?"

                  Again thanks.


 

cpcahil@virtech.uucp (Conor P. Cahill) (03/03/90)

In article <2885@umbc3.UMBC.EDU> cs223130@umbc5.umbc.edu.UUCP (CMSC 223/01011) writes:
>The problem arises when
>a process running as joeblow wants to remove entries in "foodir" that
>are not owned by him. A regular call to unlink() prompts the user if
>they really want to remove the file. How do I disable this feature in
>a C program using UNIX system calls -vs- invoking "system("rm -f

This is not true.  unlink(2) is a system call and it does not prompt the
user for anything.  rm(1) has some special code that stats a file (or calls
access(2), whatever) to see if the current user doesn't have write access
to the file.  If not rm(1) asks the user if it it ok to remove the file.

To unlink(2) a file, all you need is write permission in the directory
in which the file exists. The only exception that I know of is that in
some systems (namely system V.3+) if the sticky bit is set on a directory,
only those that own the file can remove them.  Normally this is only set
for directories like /tmp.

>no user interaction whatsoever. This process runs on System V version
>2.2. (Yeah I know it's old but I have no say on upgrades) The machine
>is an AT&T 3b15. Any help with this would be greatly appreciated.

This is true for any current version of unix. 


-- 
--
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.,
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170